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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define NANOGPS_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
67  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
68  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM )
69 
75 #define NANOGPS_RETVAL uint8_t
76 
77 #define NANOGPS_OK 0x00
78 #define NANOGPS_INIT_ERROR 0xFF
79 
85 #define NANOGPS_NEMA_GPGGA 1
86 #define NANOGPS_NEMA_GPGLL 3
87 #define NANOGPS_NEMA_GPGGA_NUM_ELEMENT 15
88 #define NANOGPS_NEMA_GPGLL_NUM_ELEMENT 5
89 
95 #define NANOGPS_GPGGA_TIME 1
96 #define NANOGPS_GPGGA_LATITUDE 2
97 #define NANOGPS_GPGGA_LATITUDE_SIDE 3
98 #define NANOGPS_GPGGA_LONGITUDE 4
99 #define NANOGPS_GPGGA_LONGITUDE_SIDE 5
100 #define NANOGPS_GPGGA_QUALITY_INDICATOR 6
101 #define NANOGPS_GPGGA_NUMBER_OF_SATELLITES 7
102 #define NANOGPS_GPGGA_H_DILUTION_OF_POS 8
103 #define NANOGPS_GPGGA_ALTITUDE 9
104 #define NANOGPS_GPGGA_ALTITUDE_UNIT 10
105 #define NANOGPS_GPGGA_GEOIDAL_SEPARATION 11
106 #define NANOGPS_GPGGA_GEOIDAL_SEPARATION_UNIT 12
107 #define NANOGPS_GPGGA_TIME_SINCE_LAST_DGPS 13
108 #define NANOGPS_GPGGA_DGPS_REFERENCE_STATION_ID 14
109 
115 #define NANOGPS_GPGLL_LATITUDE 1
116 #define NANOGPS_GPGLL_LATITUDE_SIDE 2
117 #define NANOGPS_GPGLL_LONGITUDE 3
118 #define NANOGPS_GPGLL_LONGITUDE_SIDE 4
119 
125 #define NANOGPS_ERROR_COMMAND_OR_ELEMENT 0xFF
126 #define NANOGPS_ERROR_START_OR_END_COMMAND 0x8F
127 #define NANOGPS_ERROR_NEXT_ELEMENT 0x4F
128 #define NANOGPS_ERROR_CURRENT_ELEMENT 0x2F
129 #define NANOGPS_NO_ERROR 0x00
130 
136 #define DRV_RX_BUFFER_SIZE 500
137 #define DRV_TX_BUFFER_SIZE 500
138  // End group macro
141 // --------------------------------------------------------------- PUBLIC TYPES
149 typedef struct
150 {
151  // Output pins
152 
153  digital_out_t rst;
154  digital_out_t pwr;
155 
156  // Input pins
157 
158  digital_in_t wkp;
159 
160  // Modules
161 
162  uart_t uart;
163 
164  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
165  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
166 
167 } nanogps_t;
168 
172 typedef struct
173 {
174  // Communication gpio pins
175 
176  pin_name_t rx_pin;
177  pin_name_t tx_pin;
178 
179  // Additional gpio pins
180 
181  pin_name_t wkp;
182  pin_name_t rst;
183  pin_name_t pwr;
184 
185  // static variable
186 
187  uint32_t baud_rate; // Clock speed.
189  uart_data_bits_t data_bit; // Data bits.
190  uart_parity_t parity_bit; // Parity bit.
191  uart_stop_bits_t stop_bit; // Stop bits.
192 
193 } nanogps_cfg_t;
194 
198 typedef uint8_t nanogps_error_t;
199  // End types group
201 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
202 
208 #ifdef __cplusplus
209 extern "C"{
210 #endif
211 
221 
230 
236 
242 void nanogps_set_pwr_pin ( nanogps_t *ctx, uint8_t state );
243 
249 void nanogps_set_rst_pin ( nanogps_t *ctx, uint8_t state );
250 
257 
264 void nanogps_generic_write ( nanogps_t *ctx, char *data_buf, uint16_t len );
265 
273 int32_t nanogps_generic_read ( nanogps_t *ctx, char *data_buf, uint16_t max_len );
274 
284 (
285  char *rsp, uint8_t command,
286  uint8_t element, char *parser_buf
287 );
288 
289 #ifdef __cplusplus
290 }
291 #endif
292 #endif // _NANOGPS_H_
293  // End public_function group
296 
297 // ------------------------------------------------------------------------- END
nanogps_t::wkp
digital_in_t wkp
Definition: nanogps.h:158
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:136
nanogps_cfg_t::rst
pin_name_t rst
Definition: nanogps.h:182
nanogps_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: nanogps.h:189
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:181
nanogps_cfg_t::baud_rate
uint32_t baud_rate
Definition: nanogps.h:187
nanogps_t::pwr
digital_out_t pwr
Definition: nanogps.h:154
nanogps_cfg_t::uart_blocking
bool uart_blocking
Definition: nanogps.h:188
nanogps_cfg_t::rx_pin
pin_name_t rx_pin
Definition: nanogps.h:176
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:150
nanogps_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: nanogps.h:191
nanogps_cfg_t
Click configuration structure definition.
Definition: nanogps.h:173
nanogps_error_t
uint8_t nanogps_error_t
Error type.
Definition: nanogps.h:198
nanogps_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: nanogps.h:190
nanogps_cfg_t::tx_pin
pin_name_t tx_pin
Definition: nanogps.h:177
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:183
nanogps_module_wakeup
void nanogps_module_wakeup(nanogps_t *ctx)
Wake-up module.
nanogps_t::uart
uart_t uart
Definition: nanogps.h:162
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: nanogps.h:137
nanogps_t::rst
digital_out_t rst
Definition: nanogps.h:153
NANOGPS_RETVAL
#define NANOGPS_RETVAL
Definition: nanogps.h:75