nanogps2 2.0.0.0
nanogps2.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4 * All rights reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef NANOGPS2_H
36#define NANOGPS2_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// -------------------------------------------------------------- PUBLIC MACROS
66#define NANOGPS2_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.fon = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
80#define NANOGPS2_RETVAL uint8_t
81
82#define NANOGPS2_OK 0x00
83#define NANOGPS2_INIT_ERROR 0xFF
90#define NANOGPS2_NEMA_GNGGA 1
91#define NANOGPS2_NEMA_GPGLL 3
92#define NANOGPS2_NEMA_GNGGA_NUM_ELEMENT 15
93#define NANOGPS2_NEMA_GPGLL_NUM_ELEMENT 5
100#define NANOGPS2_GNGGA_TIME 1
101#define NANOGPS2_GNGGA_LATITUDE 2
102#define NANOGPS2_GNGGA_LATITUDE_SIDE 3
103#define NANOGPS2_GNGGA_LONGITUDE 4
104#define NANOGPS2_GNGGA_LONGITUDE_SIDE 5
105#define NANOGPS2_GNGGA_QUALITY_INDICATOR 6
106#define NANOGPS2_GNGGA_NUMBER_OF_SATELLITES 7
107#define NANOGPS2_GNGGA_H_DILUTION_OF_POS 8
108#define NANOGPS2_GNGGA_ALTITUDE 9
109#define NANOGPS2_GNGGA_ALTITUDE_UNIT 10
110#define NANOGPS2_GNGGA_GEOIDAL_SEPARATION 11
111#define NANOGPS2_GNGGA_GEOIDAL_SEPARATION_UNIT 12
112#define NANOGPS2_GNGGA_TIME_SINCE_LAST_DGPS 13
113#define NANOGPS2_GNGGA_DGPS_REFERENCE_STATION_ID 14
120#define NANOGPS2_GPGLL_LATITUDE 1
121#define NANOGPS2_GPGLL_LATITUDE_SIDE 2
122#define NANOGPS2_GPGLL_LONGITUDE 3
123#define NANOGPS2_GPGLL_LONGITUDE_SIDE 4
130#define NANOGPS2_ERROR_COMMAND_OR_ELEMENT 0xFF
131#define NANOGPS2_ERROR_START_OR_END_COMMAND 0x8F
132#define NANOGPS2_ERROR_NEXT_ELEMENT 0x4F
133#define NANOGPS2_ERROR_CURRENT_ELEMENT 0x2F
134#define NANOGPS2_NO_ERROR 0x00
141#define DRV_RX_BUFFER_SIZE 600
142#define DRV_TX_BUFFER_SIZE 50
145 // End group macro
146// --------------------------------------------------------------- PUBLIC TYPES
154typedef struct
155{
156 // Output pins
157
158 digital_out_t en;
159 digital_out_t fon;
160 digital_out_t cts;
161
162 // Input pins
163
164 digital_in_t wkp;
165 digital_in_t rts;
166
167 // Modules
168
169 uart_t uart;
170
171 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
172 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
173
174} nanogps2_t;
175
179typedef struct
180{
181 // Communication gpio pins
182
183 pin_name_t rx_pin;
184 pin_name_t tx_pin;
185
186 // Additional gpio pins
187
188 pin_name_t wkp;
189 pin_name_t en;
190 pin_name_t fon;
191 pin_name_t cts;
192 pin_name_t rts;
193
194 // static variable
195
196 uint32_t baud_rate; // Clock speed.
198 uart_data_bits_t data_bit; // Data bits.
199 uart_parity_t parity_bit; // Parity bit.
200 uart_stop_bits_t stop_bit; // Stop bits.
201
203
207typedef uint8_t nanogps2_error_t;
208
209 // End types group
210// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
211
217#ifdef __cplusplus
218extern "C"{
219#endif
220
230
240
246
253void nanogps2_set_fon_pin_state ( nanogps2_t *ctx, uint8_t state );
254
261void nanogps2_set_cts_pin_state ( nanogps2_t *ctx, uint8_t state );
262
270
278
285void nanogps2_set_en_pin_state ( nanogps2_t *ctx, uint8_t state );
286
294void nanogps2_generic_write ( nanogps2_t *ctx, char *data_buf, uint16_t len );
295
305int32_t nanogps2_generic_read ( nanogps2_t *ctx, char *data_buf, uint16_t max_len );
306
318(
319 char *rsp, uint8_t command,
320 uint8_t element, char *parser_buf
321);
322
323#ifdef __cplusplus
324}
325#endif
326#endif // _NANOGPS2_H_
327
328 // End public_function group
330
331// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition nanogps2.h:141
#define DRV_TX_BUFFER_SIZE
Definition nanogps2.h:142
#define NANOGPS2_RETVAL
Definition nanogps2.h:80
void nanogps2_cfg_setup(nanogps2_cfg_t *cfg)
Config Object Initialization function.
void nanogps2_set_cts_pin_state(nanogps2_t *ctx, uint8_t state)
Generic function for setting cts pin status.
int32_t nanogps2_generic_read(nanogps2_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void nanogps2_generic_write(nanogps2_t *ctx, char *data_buf, uint16_t len)
Generic write function.
uint8_t nanogps2_get_rts_pin(nanogps2_t *ctx)
Get RTS pin state.
void nanogps2_set_fon_pin_state(nanogps2_t *ctx, uint8_t state)
Generic function for setting fon pin status.
nanogps2_error_t nanogps2_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
void nanogps2_module_wakeup(nanogps2_t *ctx)
Wake-up module.
NANOGPS2_RETVAL nanogps2_init(nanogps2_t *ctx, nanogps2_cfg_t *cfg)
Initialization function.
uint8_t nanogps2_get_wkp_pin(nanogps2_t *ctx)
Get WKP pin state.
void nanogps2_set_en_pin_state(nanogps2_t *ctx, uint8_t state)
Generic function for setting en pin status.
uint8_t nanogps2_error_t
Error type.
Definition nanogps2.h:207
Click configuration structure definition.
Definition nanogps2.h:180
pin_name_t rts
Definition nanogps2.h:192
pin_name_t fon
Definition nanogps2.h:190
uint32_t baud_rate
Definition nanogps2.h:196
pin_name_t wkp
Definition nanogps2.h:188
pin_name_t cts
Definition nanogps2.h:191
bool uart_blocking
Definition nanogps2.h:197
uart_data_bits_t data_bit
Definition nanogps2.h:198
pin_name_t tx_pin
Definition nanogps2.h:184
pin_name_t rx_pin
Definition nanogps2.h:183
uart_stop_bits_t stop_bit
Definition nanogps2.h:200
pin_name_t en
Definition nanogps2.h:189
uart_parity_t parity_bit
Definition nanogps2.h:199
Click ctx object definition.
Definition nanogps2.h:155
digital_in_t wkp
Definition nanogps2.h:164
uart_t uart
Definition nanogps2.h:169
digital_out_t fon
Definition nanogps2.h:159
digital_in_t rts
Definition nanogps2.h:165
digital_out_t en
Definition nanogps2.h:158
digital_out_t cts
Definition nanogps2.h:160