gnss5  2.0.0.0
gnss5.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 GNSS5_H
36 #define GNSS5_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 GNSS5_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.exi = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
58  cfg.pps = MIKROBUS( mikrobus, MIKROBUS_INT )
59 
65 #define GNSS5_RETVAL uint8_t
66 
67 #define GNSS5_OK 0x00
68 #define GNSS5_INIT_ERROR 0xFF
69 
75 #define GNSS5_NEMA_GNGGA 1
76 #define GNSS5_NEMA_GNGLL 3
77 #define GNSS5_NEMA_GNGGA_NUM_ELEMENT 15
78 #define GNSS5_NEMA_GNGLL_NUM_ELEMENT 5
79 
85 #define GNSS5_GNGGA_TIME 1
86 #define GNSS5_GNGGA_LATITUDE 2
87 #define GNSS5_GNGGA_LATITUDE_SIDE 3
88 #define GNSS5_GNGGA_LONGITUDE 4
89 #define GNSS5_GNGGA_LONGITUDE_SIDE 5
90 #define GNSS5_GNGGA_QUALITY_INDICATOR 6
91 #define GNSS5_GNGGA_NUMBER_OF_SATELLITES 7
92 #define GNSS5_GNGGA_H_DILUTION_OF_POS 8
93 #define GNSS5_GNGGA_ALTITUDE 9
94 #define GNSS5_GNGGA_ALTITUDE_UNIT 10
95 #define GNSS5_GNGGA_GEOIDAL_SEPARATION 11
96 #define GNSS5_GNGGA_GEOIDAL_SEPARATION_UNIT 12
97 #define GNSS5_GNGGA_TIME_SINCE_LAST_DGPS 13
98 #define GNSS5_GNGGA_DGPS_REFERENCE_STATION_ID 14
99 
105 #define GNSS5_GNGLL_LATITUDE 1
106 #define GNSS5_GNGLL_LATITUDE_SIDE 2
107 #define GNSS5_GNGLL_LONGITUDE 3
108 #define GNSS5_GNGLL_LONGITUDE_SIDE 4
109 
115 #define GNSS5_ERROR_COMMAND_OR_ELEMENT 0xFF
116 #define GNSS5_ERROR_START_OR_END_COMMAND 0x8F
117 #define GNSS5_ERROR_NEXT_ELEMENT 0x4F
118 #define GNSS5_ERROR_CURRENT_ELEMENT 0x2F
119 #define GNSS5_NO_ERROR 0x00
120 
126 #define DRV_RX_BUFFER_SIZE 500
127  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
138 typedef struct
139 {
140  // Output pins
141 
142  digital_out_t rst;
143 
144  // Input pins
145 
146  digital_in_t exi;
147  digital_in_t pps;
148 
149  // Modules
150 
151  uart_t uart;
152 
153  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
154  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
155 
156 } gnss5_t;
157 
161 typedef struct
162 {
163  // Communication gpio pins
164 
165  pin_name_t rx_pin;
166  pin_name_t tx_pin;
167 
168  // Additional gpio pins
169 
170  pin_name_t rst;
171  pin_name_t exi;
172  pin_name_t pps;
173 
174  // static variable
175 
176  uint32_t baud_rate; // Clock speed.
178  uart_data_bits_t data_bit; // Data bits.
179  uart_parity_t parity_bit; // Parity bit.
180  uart_stop_bits_t stop_bit; // Stop bits.
181 
182 } gnss5_cfg_t;
183 
187 typedef uint8_t gnss5_error_t;
188  // End types group
190 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
191 
197 #ifdef __cplusplus
198 extern "C"{
199 #endif
200 
209 void gnss5_cfg_setup ( gnss5_cfg_t *cfg );
210 
219 
224 void gnss5_module_wakeup ( gnss5_t *ctx );
225 
231 uint8_t gnss5_get_exi_pin ( gnss5_t *ctx );
232 
238 void gnss5_set_rst_pin ( gnss5_t *ctx, uint8_t state );
239 
245 uint8_t gnss5_get_pps_pin ( gnss5_t *ctx );
246 
253 void gnss5_generic_write ( gnss5_t *ctx, char *data_buf, uint16_t len );
254 
262 int32_t gnss5_generic_read ( gnss5_t *ctx, char *data_buf, uint16_t max_len );
263 
273 (
274  char *rsp, uint8_t command,
275  uint8_t element, char *parser_buf
276 );
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // _GNSS5_H_
282  // End public_function group
285 
286 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gnss5.h:126
gnss5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gnss5.h:180
gnss5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gnss5.h:179
gnss5_t::rst
digital_out_t rst
Definition: gnss5.h:142
gnss5_init
GNSS5_RETVAL gnss5_init(gnss5_t *ctx, gnss5_cfg_t *cfg)
Initialization function.
gnss5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gnss5.h:178
GNSS5_RETVAL
#define GNSS5_RETVAL
Definition: gnss5.h:65
gnss5_cfg_t::uart_blocking
bool uart_blocking
Definition: gnss5.h:177
gnss5_t
Click ctx object definition.
Definition: gnss5.h:138
gnss5_get_pps_pin
uint8_t gnss5_get_pps_pin(gnss5_t *ctx)
Get PPS pin state.
gnss5_cfg_t::pps
pin_name_t pps
Definition: gnss5.h:172
gnss5_generic_write
void gnss5_generic_write(gnss5_t *ctx, char *data_buf, uint16_t len)
Generic write function.
gnss5_cfg_setup
void gnss5_cfg_setup(gnss5_cfg_t *cfg)
Config Object Initialization function.
gnss5_error_t
uint8_t gnss5_error_t
Error type.
Definition: gnss5.h:187
gnss5_t::exi
digital_in_t exi
Definition: gnss5.h:146
gnss5_t::uart
uart_t uart
Definition: gnss5.h:151
gnss5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gnss5.h:166
gnss5_cfg_t::rst
pin_name_t rst
Definition: gnss5.h:170
gnss5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gnss5.h:165
gnss5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gnss5.h:176
gnss5_module_wakeup
void gnss5_module_wakeup(gnss5_t *ctx)
Wake-up module.
gnss5_set_rst_pin
void gnss5_set_rst_pin(gnss5_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
gnss5_cfg_t::exi
pin_name_t exi
Definition: gnss5.h:171
gnss5_cfg_t
Click configuration structure definition.
Definition: gnss5.h:161
gnss5_generic_parser
gnss5_error_t gnss5_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
gnss5_get_exi_pin
uint8_t gnss5_get_exi_pin(gnss5_t *ctx)
Set WKP ( wake-up ) pin state.
gnss5_generic_read
int32_t gnss5_generic_read(gnss5_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gnss5_t::pps
digital_in_t pps
Definition: gnss5.h:147