gnss5  2.0.0.0
gnss5.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 GNSS5_H
29 #define GNSS5_H
30 
31 #ifdef __cplusplus
32 extern "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_uart.h"
52 
73 #define GNSS5_RSP_START "$"
74 #define GNSS5_RSP_DELIMITER ","
75 #define GNSS5_RSP_END_SEQ "\r\n"
76 #define GNSS5_RSP_GNGGA "$GNGGA"
77 
82 #define GNSS5_GNGGA_ELEMENT_SIZE 15
83 #define GNSS5_GNGGA_TIME 1
84 #define GNSS5_GNGGA_LATITUDE 2
85 #define GNSS5_GNGGA_LATITUDE_SIDE 3
86 #define GNSS5_GNGGA_LONGITUDE 4
87 #define GNSS5_GNGGA_LONGITUDE_SIDE 5
88 #define GNSS5_GNGGA_QUALITY_INDICATOR 6
89 #define GNSS5_GNGGA_NUMBER_OF_SATELLITES 7
90 #define GNSS5_GNGGA_H_DILUTION_OF_POS 8
91 #define GNSS5_GNGGA_ALTITUDE 9
92 #define GNSS5_GNGGA_ALTITUDE_UNIT 10
93 #define GNSS5_GNGGA_GEOIDAL_SEPARATION 11
94 #define GNSS5_GNGGA_GEOIDAL_SEPARATION_UNIT 12
95 #define GNSS5_GNGGA_TIME_SINCE_LAST_DGPS 13
96 #define GNSS5_GNGGA_DGPS_REFERENCE_STATION_ID 14
97 
103 #define GNSS5_DRV_TX_BUFFER_SIZE 100
104 #define GNSS5_DRV_RX_BUFFER_SIZE 1000
105  // gnss5_cmd
107 
122 #define GNSS5_MAP_MIKROBUS( cfg, mikrobus ) \
123  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
124  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
125  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
126  cfg.exi = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
127  cfg.pps = MIKROBUS( mikrobus, MIKROBUS_INT )
128  // gnss5_map // gnss5
131 
136 typedef struct
137 {
138  // Output pins
139  digital_out_t rst;
140 
141  // Input pins
142  digital_in_t exi;
143  digital_in_t pps;
144 
145  // Modules
146  uart_t uart;
148  // Buffers
149  char uart_rx_buffer[ GNSS5_DRV_RX_BUFFER_SIZE ];
150  char uart_tx_buffer[ GNSS5_DRV_TX_BUFFER_SIZE ];
152 } gnss5_t;
153 
158 typedef struct
159 {
160  // Communication gpio pins
161  pin_name_t rx_pin;
162  pin_name_t tx_pin;
164  // Additional gpio pins
165  pin_name_t rst;
166  pin_name_t exi;
167  pin_name_t pps;
168 
169  // Static variable
170  uint32_t baud_rate;
172  uart_data_bits_t data_bit;
173  uart_parity_t parity_bit;
174  uart_stop_bits_t stop_bit;
176 } gnss5_cfg_t;
177 
182 typedef enum
183 {
184  GNSS5_OK = 0,
185  GNSS5_ERROR = -1
186 
188 
205 
219 err_t gnss5_init ( gnss5_t *ctx, gnss5_cfg_t *cfg );
220 
233 err_t gnss5_generic_write ( gnss5_t *ctx, char *data_in, uint16_t len );
234 
247 err_t gnss5_generic_read ( gnss5_t *ctx, char *data_out, uint16_t len );
248 
258 
268 void gnss5_set_rst_pin ( gnss5_t *ctx, uint8_t state );
269 
278 uint8_t gnss5_get_exi_pin ( gnss5_t *ctx );
279 
288 uint8_t gnss5_get_pps_pin ( gnss5_t *ctx );
289 
301 err_t gnss5_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
302 
303 #ifdef __cplusplus
304 }
305 #endif
306 #endif // GNSS5_H
307  // gnss5
309 
310 // ------------------------------------------------------------------------ END
gnss5_parse_gngga
err_t gnss5_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
GNSS 5 parse GNGGA function.
gnss5_get_pps_pin
uint8_t gnss5_get_pps_pin(gnss5_t *ctx)
GNSS 5 get PPS pin function.
GNSS5_OK
@ GNSS5_OK
Definition: gnss5.h:184
GNSS5_DRV_TX_BUFFER_SIZE
#define GNSS5_DRV_TX_BUFFER_SIZE
GNSS 5 driver buffer size.
Definition: gnss5.h:103
gnss5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gnss5.h:174
gnss5_cfg_setup
void gnss5_cfg_setup(gnss5_cfg_t *cfg)
GNSS 5 configuration object setup function.
gnss5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gnss5.h:173
gnss5_t::rst
digital_out_t rst
Definition: gnss5.h:139
gnss5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gnss5.h:172
gnss5_generic_read
err_t gnss5_generic_read(gnss5_t *ctx, char *data_out, uint16_t len)
GNSS 5 data reading function.
GNSS5_DRV_RX_BUFFER_SIZE
#define GNSS5_DRV_RX_BUFFER_SIZE
Definition: gnss5.h:104
gnss5_init
err_t gnss5_init(gnss5_t *ctx, gnss5_cfg_t *cfg)
GNSS 5 initialization function.
gnss5_cfg_t::uart_blocking
bool uart_blocking
Definition: gnss5.h:171
GNSS5_ERROR
@ GNSS5_ERROR
Definition: gnss5.h:185
gnss5_t
GNSS 5 Click context object.
Definition: gnss5.h:137
gnss5_cfg_t::pps
pin_name_t pps
Definition: gnss5.h:167
gnss5_t::exi
digital_in_t exi
Definition: gnss5.h:142
gnss5_t::uart
uart_t uart
Definition: gnss5.h:146
gnss5_get_exi_pin
uint8_t gnss5_get_exi_pin(gnss5_t *ctx)
GNSS 5 get EXI pin function.
gnss5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gnss5.h:162
gnss5_cfg_t::rst
pin_name_t rst
Definition: gnss5.h:165
gnss5_clear_ring_buffers
void gnss5_clear_ring_buffers(gnss5_t *ctx)
GNSS 5 clear ring buffers function.
gnss5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gnss5.h:161
gnss5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gnss5.h:170
gnss5_cfg_t::exi
pin_name_t exi
Definition: gnss5.h:166
gnss5_cfg_t
GNSS 5 Click configuration object.
Definition: gnss5.h:159
gnss5_t::pps
digital_in_t pps
Definition: gnss5.h:143
gnss5_set_rst_pin
void gnss5_set_rst_pin(gnss5_t *ctx, uint8_t state)
GNSS 5 set RST pin function.
gnss5_return_value_t
gnss5_return_value_t
GNSS 5 Click return value data.
Definition: gnss5.h:183
gnss5_generic_write
err_t gnss5_generic_write(gnss5_t *ctx, char *data_in, uint16_t len)
GNSS 5 data writing function.