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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define NANOGPS_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM )
59 
65 #define NANOGPS_RETVAL uint8_t
66 
67 #define NANOGPS_OK 0x00
68 #define NANOGPS_INIT_ERROR 0xFF
69 
75 #define NANOGPS_NEMA_GPGGA 1
76 #define NANOGPS_NEMA_GPGLL 3
77 #define NANOGPS_NEMA_GPGGA_NUM_ELEMENT 15
78 #define NANOGPS_NEMA_GPGLL_NUM_ELEMENT 5
79 
85 #define NANOGPS_GPGGA_TIME 1
86 #define NANOGPS_GPGGA_LATITUDE 2
87 #define NANOGPS_GPGGA_LATITUDE_SIDE 3
88 #define NANOGPS_GPGGA_LONGITUDE 4
89 #define NANOGPS_GPGGA_LONGITUDE_SIDE 5
90 #define NANOGPS_GPGGA_QUALITY_INDICATOR 6
91 #define NANOGPS_GPGGA_NUMBER_OF_SATELLITES 7
92 #define NANOGPS_GPGGA_H_DILUTION_OF_POS 8
93 #define NANOGPS_GPGGA_ALTITUDE 9
94 #define NANOGPS_GPGGA_ALTITUDE_UNIT 10
95 #define NANOGPS_GPGGA_GEOIDAL_SEPARATION 11
96 #define NANOGPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
97 #define NANOGPS_GPGGA_TIME_SINCE_LAST_DGPS 13
98 #define NANOGPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
99 
105 #define NANOGPS_GPGLL_LATITUDE 1
106 #define NANOGPS_GPGLL_LATITUDE_SIDE 2
107 #define NANOGPS_GPGLL_LONGITUDE 3
108 #define NANOGPS_GPGLL_LONGITUDE_SIDE 4
109 
115 #define NANOGPS_ERROR_COMMAND_OR_ELEMENT 0xFF
116 #define NANOGPS_ERROR_START_OR_END_COMMAND 0x8F
117 #define NANOGPS_ERROR_NEXT_ELEMENT 0x4F
118 #define NANOGPS_ERROR_CURRENT_ELEMENT 0x2F
119 #define NANOGPS_NO_ERROR 0x00
120 
126 #define DRV_RX_BUFFER_SIZE 500
127 #define DRV_TX_BUFFER_SIZE 500
128  // End group macro
131 // --------------------------------------------------------------- PUBLIC TYPES
139 typedef struct
140 {
141  // Output pins
142 
143  digital_out_t rst;
144  digital_out_t pwr;
145 
146  // Input pins
147 
148  digital_in_t wkp;
149 
150  // Modules
151 
152  uart_t uart;
153 
154  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
155  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
156 
157 } nanogps_t;
158 
162 typedef struct
163 {
164  // Communication gpio pins
165 
166  pin_name_t rx_pin;
167  pin_name_t tx_pin;
168 
169  // Additional gpio pins
170 
171  pin_name_t wkp;
172  pin_name_t rst;
173  pin_name_t pwr;
174 
175  // static variable
176 
177  uint32_t baud_rate; // Clock speed.
179  uart_data_bits_t data_bit; // Data bits.
180  uart_parity_t parity_bit; // Parity bit.
181  uart_stop_bits_t stop_bit; // Stop bits.
182 
183 } nanogps_cfg_t;
184 
188 typedef uint8_t nanogps_error_t;
189  // End types group
191 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
192 
198 #ifdef __cplusplus
199 extern "C"{
200 #endif
201 
210 void nanogps_cfg_setup ( nanogps_cfg_t *cfg );
211 
220 
225 void nanogps_module_wakeup ( nanogps_t *ctx );
226 
232 void nanogps_set_pwr_pin ( nanogps_t *ctx, uint8_t state );
233 
239 void nanogps_set_rst_pin ( nanogps_t *ctx, uint8_t state );
240 
246 uint8_t nanogps_get_wkp_pin ( nanogps_t *ctx );
247 
254 void nanogps_generic_write ( nanogps_t *ctx, char *data_buf, uint16_t len );
255 
263 int32_t nanogps_generic_read ( nanogps_t *ctx, char *data_buf, uint16_t max_len );
264 
274 (
275  char *rsp, uint8_t command,
276  uint8_t element, char *parser_buf
277 );
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 #endif // _NANOGPS_H_
283  // End public_function group
286 
287 // ------------------------------------------------------------------------- END
nanogps_t::wkp
digital_in_t wkp
Definition: nanogps.h:148
nanogps_generic_parser
nanogps_error_t nanogps_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: nanogps.h:126
nanogps_cfg_t::rst
pin_name_t rst
Definition: nanogps.h:172
nanogps_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nanogps.h:179
nanogps_get_wkp_pin
uint8_t nanogps_get_wkp_pin(nanogps_t *ctx)
Get WKP pin state.
nanogps_generic_read
int32_t nanogps_generic_read(nanogps_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
nanogps_init
NANOGPS_RETVAL nanogps_init(nanogps_t *ctx, nanogps_cfg_t *cfg)
Initialization function.
nanogps_cfg_setup
void nanogps_cfg_setup(nanogps_cfg_t *cfg)
Config Object Initialization function.
nanogps_set_rst_pin
void nanogps_set_rst_pin(nanogps_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
nanogps_cfg_t::wkp
pin_name_t wkp
Definition: nanogps.h:171
nanogps_cfg_t::baud_rate
uint32_t baud_rate
Definition: nanogps.h:177
nanogps_t::pwr
digital_out_t pwr
Definition: nanogps.h:144
nanogps_cfg_t::uart_blocking
bool uart_blocking
Definition: nanogps.h:178
nanogps_cfg_t::rx_pin
pin_name_t rx_pin
Definition: nanogps.h:166
nanogps_generic_write
void nanogps_generic_write(nanogps_t *ctx, char *data_buf, uint16_t len)
Generic write function.
nanogps_t
Click ctx object definition.
Definition: nanogps.h:139
nanogps_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: nanogps.h:181
nanogps_cfg_t
Click configuration structure definition.
Definition: nanogps.h:162
nanogps_error_t
uint8_t nanogps_error_t
Error type.
Definition: nanogps.h:188
nanogps_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: nanogps.h:180
nanogps_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nanogps.h:167
nanogps_set_pwr_pin
void nanogps_set_pwr_pin(nanogps_t *ctx, uint8_t state)
Set PWR ( powerS ) pin state.
nanogps_cfg_t::pwr
pin_name_t pwr
Definition: nanogps.h:173
nanogps_module_wakeup
void nanogps_module_wakeup(nanogps_t *ctx)
Wake-up module.
nanogps_t::uart
uart_t uart
Definition: nanogps.h:152
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: nanogps.h:127
nanogps_t::rst
digital_out_t rst
Definition: nanogps.h:143
NANOGPS_RETVAL
#define NANOGPS_RETVAL
Definition: nanogps.h:65