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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_uart.h"
55
56
57// -------------------------------------------------------------- PUBLIC MACROS
67#define GPS_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.reset = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.tmpls = MIKROBUS( mikrobus, MIKROBUS_INT )
78#define GPS_RETVAL uint8_t
79
80#define GPS_OK 0x00
81#define GPS_INIT_ERROR 0xFF
88#define GPS_NEMA_GPGGA 1
89#define GPS_NEMA_GPGLL 3
90#define GPS_NEMA_GPGGA_NUM_ELEMENT 15
91#define GPS_NEMA_GPGLL_NUM_ELEMENT 5
98#define GPS_GPGGA_TIME 1
99#define GPS_GPGGA_LATITUDE 2
100#define GPS_GPGGA_LATITUDE_SIDE 3
101#define GPS_GPGGA_LONGITUDE 4
102#define GPS_GPGGA_LONGITUDE_SIDE 5
103#define GPS_GPGGA_QUALITY_INDICATOR 6
104#define GPS_GPGGA_NUMBER_OF_SATELLITES 7
105#define GPS_GPGGA_H_DILUTION_OF_POS 8
106#define GPS_GPGGA_ALTITUDE 9
107#define GPS_GPGGA_ALTITUDE_UNIT 10
108#define GPS_GPGGA_GEOIDAL_SEPARATION 11
109#define GPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
110#define GPS_GPGGA_TIME_SINCE_LAST_DGPS 13
111#define GPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
118#define GPS_GPGLL_LATITUDE 1
119#define GPS_GPGLL_LATITUDE_SIDE 2
120#define GPS_GPGLL_LONGITUDE 3
121#define GPS_GPGLL_LONGITUDE_SIDE 4
128#define GPS_ERROR_COMMAND_OR_ELEMENT 0xFF
129#define GPS_ERROR_START_OR_END_COMMAND 0x8F
130#define GPS_ERROR_NEXT_ELEMENT 0x4F
131#define GPS_ERROR_CURRENT_ELEMENT 0x2F
132#define GPS_NO_ERROR 0x00
139#define DRV_RX_BUFFER_SIZE 600
140#define DRV_TX_BUFFER_SIZE 100
143 // End group macro
144// --------------------------------------------------------------- PUBLIC TYPES
152typedef struct
153{
154 // Output pins
155
156 digital_out_t reset;
157
158 // Input pins
159
160 digital_in_t tmpls;
161
162 // Modules
163
164 uart_t uart;
165
166 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
167 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
168
169} gps_t;
170
174typedef struct
175{
176 // Communication gpio pins
177
178 pin_name_t rx_pin;
179 pin_name_t tx_pin;
180
181 // Additional gpio pins
182
183 pin_name_t reset;
184 pin_name_t tmpls;
185
186 // static variable
187
188 uint32_t baud_rate; // Clock speed.
190 uart_data_bits_t data_bit; // Data bits.
191 uart_parity_t parity_bit; // Parity bit.
192 uart_stop_bits_t stop_bit; // Stop bits.
193
194} gps_cfg_t;
195
199typedef uint8_t gps_error_t;
200
201 // End types group
202// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
203
209#ifdef __cplusplus
210extern "C"{
211#endif
212
222
231
237
243void gps_set_rst_pin ( gps_t *ctx, uint8_t state );
244
250uint8_t gps_get_tmpls_pin ( gps_t *ctx );
251
258void gps_generic_write ( gps_t *ctx, char *data_buf, uint16_t len );
259
267int32_t gps_generic_read ( gps_t *ctx, char *data_buf, uint16_t max_len );
268
278(
279 char *rsp, uint8_t command,
280 uint8_t element, char *parser_buf
281);
282
283#ifdef __cplusplus
284}
285#endif
286#endif // _GPS_H_
287
288 // End public_function group
290
291// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition gps.h:139
#define DRV_TX_BUFFER_SIZE
Definition gps.h:140
#define GPS_RETVAL
Definition gps.h:78
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:199
Click configuration structure definition.
Definition gps.h:175
uint32_t baud_rate
Definition gps.h:188
pin_name_t reset
Definition gps.h:183
bool uart_blocking
Definition gps.h:189
pin_name_t tmpls
Definition gps.h:184
uart_data_bits_t data_bit
Definition gps.h:190
pin_name_t tx_pin
Definition gps.h:179
pin_name_t rx_pin
Definition gps.h:178
uart_stop_bits_t stop_bit
Definition gps.h:192
uart_parity_t parity_bit
Definition gps.h:191
Click ctx object definition.
Definition gps.h:153
digital_in_t tmpls
Definition gps.h:160
digital_out_t reset
Definition gps.h:156
uart_t uart
Definition gps.h:164