nanogps3 2.1.0.0
nanogps3.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
28#ifndef NANOGPS3_H
29#define NANOGPS3_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52#include "drv_uart.h"
53
76 // nanogps3_reg
77
98#define NANOGPS3_RSP_START "$"
99#define NANOGPS3_RSP_DELIMITER ","
100#define NANOGPS3_RSP_GNGGA "$GNGGA"
101#define NANOGPS3_RSP_GPGLL "$GPGLL"
102
107#define NANOGPS3_NMEA_GNGGA 1
108#define NANOGPS3_NMEA_GPGLL 3
109#define NANOGPS3_NMEA_GNGGA_NUM_ELEMENT 15
110#define NANOGPS3_NMEA_GPGLL_NUM_ELEMENT 5
111
116#define NANOGPS3_GNGGA_TIME 1
117#define NANOGPS3_GNGGA_LATITUDE 2
118#define NANOGPS3_GNGGA_LATITUDE_SIDE 3
119#define NANOGPS3_GNGGA_LONGITUDE 4
120#define NANOGPS3_GNGGA_LONGITUDE_SIDE 5
121#define NANOGPS3_GNGGA_QUALITY_INDICATOR 6
122#define NANOGPS3_GNGGA_NUMBER_OF_SATELLITES 7
123#define NANOGPS3_GNGGA_H_DILUTION_OF_POS 8
124#define NANOGPS3_GNGGA_ALTITUDE 9
125#define NANOGPS3_GNGGA_ALTITUDE_UNIT 10
126#define NANOGPS3_GNGGA_GEOIDAL_SEPARATION 11
127#define NANOGPS3_GNGGA_GEOIDAL_SEPARATION_UNIT 12
128#define NANOGPS3_GNGGA_TIME_SINCE_LAST_DGPS 13
129#define NANOGPS3_GNGGA_DGPS_REFERENCE_STATION_ID 14
130
135#define NANOGPS3_DUMMY 0xFF
136
141#define NANOGPS3_PIN_STATE_LOW 0
142#define NANOGPS3_PIN_STATE_HIGH 1
143
149#define NANOGPS3_TX_DRV_BUFFER_SIZE 100
150#define NANOGPS3_RX_DRV_BUFFER_SIZE 600
151
157#define NANOGPS3_DEVICE_ADDRESS 0x10
158
159 // nanogps3_set
160
175#define NANOGPS3_MAP_MIKROBUS( cfg, mikrobus ) \
176 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
177 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
178 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
179 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_AN ); \
180 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
181 cfg.fon = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
182 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
183 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
184 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT )
185
186 // nanogps3_map
187 // nanogps3
188
199
204typedef err_t ( *nanogps3_master_io_t )( struct nanogps3_s*, uint8_t*, uint8_t );
210typedef struct nanogps3_s
211{
212 // Output pins
213 digital_out_t rts;
214 digital_out_t rst;
215 digital_out_t fon;
217 // Input pins
218 digital_in_t wup;
219 digital_in_t cts;
221 // Modules
222 i2c_master_t i2c;
223 uart_t uart;
225 // I2C slave address
228 // Buffers
237
242typedef struct
243{
244 // Communication gpio pins
245 pin_name_t scl;
246 pin_name_t sda;
248 pin_name_t rx_pin;
249 pin_name_t tx_pin;
251 pin_name_t rts;
252 pin_name_t wup;
253 pin_name_t rst;
254 pin_name_t fon;
255 pin_name_t cts;
257 uint32_t i2c_speed;
258 uint8_t i2c_address;
260 // Static variable
261 uint32_t baud_rate;
263 uart_data_bits_t data_bit;
264 uart_parity_t parity_bit;
265 uart_stop_bits_t stop_bit;
270
275typedef enum
276{
278 NANOGPS3_ERROR = -1
279
281
298
313
325
338err_t nanogps3_generic_write ( nanogps3_t *ctx, uint8_t *data_in, uint8_t len );
339
352err_t nanogps3_generic_read ( nanogps3_t *ctx, uint8_t *data_out, uint8_t len );
353
364void nanogps3_request_to_send ( nanogps3_t *ctx, uint8_t rts );
365
376
387void nanogps3_set_reset_state ( nanogps3_t *ctx, uint8_t rst_state );
388
399void nanogps3_set_force_on_state ( nanogps3_t *ctx, uint8_t pwr_state );
400
411
423err_t nanogps3_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
424
425#ifdef __cplusplus
426}
427#endif
428#endif // NANOGPS3_H
429
430 // nanogps3
431
432// ------------------------------------------------------------------------ END
#define NANOGPS3_RX_DRV_BUFFER_SIZE
Definition nanogps3.h:150
#define NANOGPS3_TX_DRV_BUFFER_SIZE
Nano GPS 3 driver buffer size.
Definition nanogps3.h:149
err_t nanogps3_init(nanogps3_t *ctx, nanogps3_cfg_t *cfg)
Nano GPS 3 initialization function.
uint8_t nanogps3_get_wup_pin(nanogps3_t *ctx)
Nano GPS 3 get wakeup pin function.
void nanogps3_default_cfg(nanogps3_t *ctx)
Nano GPS 3 default configuration function.
err_t nanogps3_generic_write(nanogps3_t *ctx, uint8_t *data_in, uint8_t len)
Nano GPS 3 data writing function.
err_t nanogps3_generic_read(nanogps3_t *ctx, uint8_t *data_out, uint8_t len)
Nano GPS 3 data reading function.
void nanogps3_set_force_on_state(nanogps3_t *ctx, uint8_t pwr_state)
Nano GPS 3 set force on state function.
void nanogps3_set_reset_state(nanogps3_t *ctx, uint8_t rst_state)
Nano GPS 3 set reset state function.
void nanogps3_cfg_setup(nanogps3_cfg_t *cfg)
Nano GPS 3 configuration object setup function.
void nanogps3_request_to_send(nanogps3_t *ctx, uint8_t rts)
Nano GPS 3 request to send function.
err_t nanogps3_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
Nano GPS 3 parse GNGGA function.
uint8_t nanogps3_clear_to_send(nanogps3_t *ctx)
Nano GPS 3 clear to send function.
struct nanogps3_s nanogps3_t
Nano GPS 3 Click context object.
nanogps3_drv_t
Nano GPS 3 Click driver selector.
Definition nanogps3.h:194
@ NANOGPS3_DRV_SEL_UART
Definition nanogps3.h:196
@ NANOGPS3_DRV_SEL_I2C
Definition nanogps3.h:195
err_t(* nanogps3_master_io_t)(struct nanogps3_s *, uint8_t *, uint8_t)
Nano GPS 3 Click driver interface.
Definition nanogps3.h:204
nanogps3_return_value_t
Nano GPS 3 Click return value data.
Definition nanogps3.h:276
@ NANOGPS3_ERROR
Definition nanogps3.h:278
@ NANOGPS3_OK
Definition nanogps3.h:277
Nano GPS 3 Click configuration object.
Definition nanogps3.h:243
pin_name_t rts
Definition nanogps3.h:251
pin_name_t fon
Definition nanogps3.h:254
uint32_t baud_rate
Definition nanogps3.h:261
pin_name_t wup
Definition nanogps3.h:252
nanogps3_drv_t drv_sel
Definition nanogps3.h:267
pin_name_t cts
Definition nanogps3.h:255
uint32_t i2c_speed
Definition nanogps3.h:257
bool uart_blocking
Definition nanogps3.h:262
uart_data_bits_t data_bit
Definition nanogps3.h:263
pin_name_t tx_pin
Definition nanogps3.h:249
pin_name_t rx_pin
Definition nanogps3.h:248
uart_stop_bits_t stop_bit
Definition nanogps3.h:265
pin_name_t scl
Definition nanogps3.h:245
uart_parity_t parity_bit
Definition nanogps3.h:264
pin_name_t sda
Definition nanogps3.h:246
pin_name_t rst
Definition nanogps3.h:253
uint8_t i2c_address
Definition nanogps3.h:258
Nano GPS 3 Click context object.
Definition nanogps3.h:211
nanogps3_drv_t drv_sel
Definition nanogps3.h:232
nanogps3_master_io_t read_f
Definition nanogps3.h:234
digital_out_t rts
Definition nanogps3.h:213
uart_t uart
Definition nanogps3.h:223
digital_in_t wup
Definition nanogps3.h:218
digital_out_t fon
Definition nanogps3.h:215
i2c_master_t i2c
Definition nanogps3.h:222
char uart_tx_buffer[NANOGPS3_TX_DRV_BUFFER_SIZE]
Definition nanogps3.h:230
digital_in_t cts
Definition nanogps3.h:219
digital_out_t rst
Definition nanogps3.h:214
uint8_t slave_address
Definition nanogps3.h:226
nanogps3_master_io_t write_f
Definition nanogps3.h:233
char uart_rx_buffer[NANOGPS3_RX_DRV_BUFFER_SIZE]
Definition nanogps3.h:229