nanogps 2.0.0.0
nanogps.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 NANOGPS_H
36#define NANOGPS_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 NANOGPS_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
71 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
72 cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM )
79#define NANOGPS_RETVAL uint8_t
80
81#define NANOGPS_OK 0x00
82#define NANOGPS_INIT_ERROR 0xFF
89#define NANOGPS_NEMA_GPGGA 1
90#define NANOGPS_NEMA_GPGLL 3
91#define NANOGPS_NEMA_GPGGA_NUM_ELEMENT 15
92#define NANOGPS_NEMA_GPGLL_NUM_ELEMENT 5
99#define NANOGPS_GPGGA_TIME 1
100#define NANOGPS_GPGGA_LATITUDE 2
101#define NANOGPS_GPGGA_LATITUDE_SIDE 3
102#define NANOGPS_GPGGA_LONGITUDE 4
103#define NANOGPS_GPGGA_LONGITUDE_SIDE 5
104#define NANOGPS_GPGGA_QUALITY_INDICATOR 6
105#define NANOGPS_GPGGA_NUMBER_OF_SATELLITES 7
106#define NANOGPS_GPGGA_H_DILUTION_OF_POS 8
107#define NANOGPS_GPGGA_ALTITUDE 9
108#define NANOGPS_GPGGA_ALTITUDE_UNIT 10
109#define NANOGPS_GPGGA_GEOIDAL_SEPARATION 11
110#define NANOGPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
111#define NANOGPS_GPGGA_TIME_SINCE_LAST_DGPS 13
112#define NANOGPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
119#define NANOGPS_GPGLL_LATITUDE 1
120#define NANOGPS_GPGLL_LATITUDE_SIDE 2
121#define NANOGPS_GPGLL_LONGITUDE 3
122#define NANOGPS_GPGLL_LONGITUDE_SIDE 4
129#define NANOGPS_ERROR_COMMAND_OR_ELEMENT 0xFF
130#define NANOGPS_ERROR_START_OR_END_COMMAND 0x8F
131#define NANOGPS_ERROR_NEXT_ELEMENT 0x4F
132#define NANOGPS_ERROR_CURRENT_ELEMENT 0x2F
133#define NANOGPS_NO_ERROR 0x00
140#define NANOGPS_DRV_RX_BUFFER_SIZE 500
141#define NANOGPS_DRV_TX_BUFFER_SIZE 100
144 // End group macro
145// --------------------------------------------------------------- PUBLIC TYPES
153typedef struct
154{
155 // Output pins
156
157 digital_out_t rst;
158 digital_out_t pwr;
159
160 // Input pins
161
162 digital_in_t wkp;
163
164 // Modules
165
166 uart_t uart;
167
168 char uart_rx_buffer[ NANOGPS_DRV_RX_BUFFER_SIZE ];
169 char uart_tx_buffer[ NANOGPS_DRV_TX_BUFFER_SIZE ];
170
171} nanogps_t;
172
176typedef struct
177{
178 // Communication gpio pins
179
180 pin_name_t rx_pin;
181 pin_name_t tx_pin;
182
183 // Additional gpio pins
184
185 pin_name_t wkp;
186 pin_name_t rst;
187 pin_name_t pwr;
188
189 // static variable
190
191 uint32_t baud_rate; // Clock speed.
193 uart_data_bits_t data_bit; // Data bits.
194 uart_parity_t parity_bit; // Parity bit.
195 uart_stop_bits_t stop_bit; // Stop bits.
196
198
202typedef uint8_t nanogps_error_t;
203
204 // End types group
205// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
206
212#ifdef __cplusplus
213extern "C"{
214#endif
215
225
234
240
246void nanogps_set_pwr_pin ( nanogps_t *ctx, uint8_t state );
247
253void nanogps_set_rst_pin ( nanogps_t *ctx, uint8_t state );
254
261
268void nanogps_generic_write ( nanogps_t *ctx, char *data_buf, uint16_t len );
269
277int32_t nanogps_generic_read ( nanogps_t *ctx, char *data_buf, uint16_t max_len );
278
288(
289 char *rsp, uint8_t command,
290 uint8_t element, char *parser_buf
291);
292
293#ifdef __cplusplus
294}
295#endif
296#endif // _NANOGPS_H_
297
298 // End public_function group
300
301// ------------------------------------------------------------------------- END
#define NANOGPS_DRV_RX_BUFFER_SIZE
Definition nanogps.h:140
#define NANOGPS_DRV_TX_BUFFER_SIZE
Definition nanogps.h:141
#define NANOGPS_RETVAL
Definition nanogps.h:79
uint8_t nanogps_get_wkp_pin(nanogps_t *ctx)
Get WKP pin state.
nanogps_error_t nanogps_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
void nanogps_module_wakeup(nanogps_t *ctx)
Wake-up module.
void nanogps_generic_write(nanogps_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void nanogps_set_pwr_pin(nanogps_t *ctx, uint8_t state)
Set PWR ( powerS ) pin state.
void nanogps_cfg_setup(nanogps_cfg_t *cfg)
Config Object Initialization function.
NANOGPS_RETVAL nanogps_init(nanogps_t *ctx, nanogps_cfg_t *cfg)
Initialization function.
int32_t nanogps_generic_read(nanogps_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void nanogps_set_rst_pin(nanogps_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
uint8_t nanogps_error_t
Error type.
Definition nanogps.h:202
Click configuration structure definition.
Definition nanogps.h:177
uint32_t baud_rate
Definition nanogps.h:191
pin_name_t wkp
Definition nanogps.h:185
bool uart_blocking
Definition nanogps.h:192
uart_data_bits_t data_bit
Definition nanogps.h:193
pin_name_t tx_pin
Definition nanogps.h:181
pin_name_t pwr
Definition nanogps.h:187
pin_name_t rx_pin
Definition nanogps.h:180
uart_stop_bits_t stop_bit
Definition nanogps.h:195
uart_parity_t parity_bit
Definition nanogps.h:194
pin_name_t rst
Definition nanogps.h:186
Click ctx object definition.
Definition nanogps.h:154
digital_in_t wkp
Definition nanogps.h:162
digital_out_t pwr
Definition nanogps.h:158
uart_t uart
Definition nanogps.h:166
digital_out_t rst
Definition nanogps.h:157