gps 2.0.0.0
gps.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef GPS_H
36#define GPS_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_uart.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
53#define GPS_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56 cfg.reset = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57 cfg.tmpls = MIKROBUS( mikrobus, MIKROBUS_INT )
64#define GPS_RETVAL uint8_t
65
66#define GPS_OK 0x00
67#define GPS_INIT_ERROR 0xFF
74#define GPS_NEMA_GPGGA 1
75#define GPS_NEMA_GPGLL 3
76#define GPS_NEMA_GPGGA_NUM_ELEMENT 15
77#define GPS_NEMA_GPGLL_NUM_ELEMENT 5
84#define GPS_GPGGA_TIME 1
85#define GPS_GPGGA_LATITUDE 2
86#define GPS_GPGGA_LATITUDE_SIDE 3
87#define GPS_GPGGA_LONGITUDE 4
88#define GPS_GPGGA_LONGITUDE_SIDE 5
89#define GPS_GPGGA_QUALITY_INDICATOR 6
90#define GPS_GPGGA_NUMBER_OF_SATELLITES 7
91#define GPS_GPGGA_H_DILUTION_OF_POS 8
92#define GPS_GPGGA_ALTITUDE 9
93#define GPS_GPGGA_ALTITUDE_UNIT 10
94#define GPS_GPGGA_GEOIDAL_SEPARATION 11
95#define GPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
96#define GPS_GPGGA_TIME_SINCE_LAST_DGPS 13
97#define GPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
104#define GPS_GPGLL_LATITUDE 1
105#define GPS_GPGLL_LATITUDE_SIDE 2
106#define GPS_GPGLL_LONGITUDE 3
107#define GPS_GPGLL_LONGITUDE_SIDE 4
114#define GPS_ERROR_COMMAND_OR_ELEMENT 0xFF
115#define GPS_ERROR_START_OR_END_COMMAND 0x8F
116#define GPS_ERROR_NEXT_ELEMENT 0x4F
117#define GPS_ERROR_CURRENT_ELEMENT 0x2F
118#define GPS_NO_ERROR 0x00
125#define DRV_RX_BUFFER_SIZE 600
126#define DRV_TX_BUFFER_SIZE 100 // End group macro
130// --------------------------------------------------------------- PUBLIC TYPES
138typedef struct
139{
140 // Output pins
141
142 digital_out_t reset;
143
144 // Input pins
145
146 digital_in_t tmpls;
147
148 // Modules
149
150 uart_t uart;
151
152 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
153 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
154
155} gps_t;
156
160typedef struct
161{
162 // Communication gpio pins
163
164 pin_name_t rx_pin;
165 pin_name_t tx_pin;
166
167 // Additional gpio pins
168
169 pin_name_t reset;
170 pin_name_t tmpls;
171
172 // static variable
173
174 uint32_t baud_rate; // Clock speed.
176 uart_data_bits_t data_bit; // Data bits.
177 uart_parity_t parity_bit; // Parity bit.
178 uart_stop_bits_t stop_bit; // Stop bits.
179
180} gps_cfg_t;
181
185typedef uint8_t gps_error_t;
186 // End types group
188// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
189
195#ifdef __cplusplus
196extern "C"{
197#endif
198
208
217
223
229void gps_set_rst_pin ( gps_t *ctx, uint8_t state );
230
236uint8_t gps_get_tmpls_pin ( gps_t *ctx );
237
244void gps_generic_write ( gps_t *ctx, char *data_buf, uint16_t len );
245
253int32_t gps_generic_read ( gps_t *ctx, char *data_buf, uint16_t max_len );
254
264(
265 char *rsp, uint8_t command,
266 uint8_t element, char *parser_buf
267);
268
269#ifdef __cplusplus
270}
271#endif
272#endif // _GPS_H_
273 // End public_function group
276
277// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: gps.h:125
#define DRV_TX_BUFFER_SIZE
Definition: gps.h:126
#define GPS_RETVAL
Definition: gps.h:64
void gps_set_rst_pin(gps_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
uint8_t gps_get_tmpls_pin(gps_t *ctx)
uint8_t gps_get_tmpls_pin ( gps_t *ctx );
void gps_module_wakeup(gps_t *ctx)
Wake-up module.
gps_error_t gps_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
void gps_cfg_setup(gps_cfg_t *cfg)
Config Object Initialization function.
void gps_generic_write(gps_t *ctx, char *data_buf, uint16_t len)
Generic write function.
GPS_RETVAL gps_init(gps_t *ctx, gps_cfg_t *cfg)
Initialization function.
int32_t gps_generic_read(gps_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
uint8_t gps_error_t
Error type.
Definition: gps.h:185
Click configuration structure definition.
Definition: gps.h:161
uint32_t baud_rate
Definition: gps.h:174
pin_name_t reset
Definition: gps.h:169
bool uart_blocking
Definition: gps.h:175
pin_name_t tmpls
Definition: gps.h:170
uart_data_bits_t data_bit
Definition: gps.h:176
pin_name_t tx_pin
Definition: gps.h:165
pin_name_t rx_pin
Definition: gps.h:164
uart_stop_bits_t stop_bit
Definition: gps.h:178
uart_parity_t parity_bit
Definition: gps.h:177
Click ctx object definition.
Definition: gps.h:139
digital_in_t tmpls
Definition: gps.h:146
digital_out_t reset
Definition: gps.h:142
uart_t uart
Definition: gps.h:150