gnss3  2.0.0.0
gnss3.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 GNSS3_H
36 #define GNSS3_H
37 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define GNSS3_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_CS )
72 
78 #define GNSS3_RSP_START "$"
79 #define GNSS3_RSP_DELIMITER ","
80 #define GNSS3_RSP_GNGGA "$GNGGA"
81 
86 #define GNSS3_GNGGA_ELEMENT_SIZE 15
87 #define GNSS3_GNGGA_TIME 1
88 #define GNSS3_GNGGA_LATITUDE 2
89 #define GNSS3_GNGGA_LATITUDE_SIDE 3
90 #define GNSS3_GNGGA_LONGITUDE 4
91 #define GNSS3_GNGGA_LONGITUDE_SIDE 5
92 #define GNSS3_GNGGA_QUALITY_INDICATOR 6
93 #define GNSS3_GNGGA_NUMBER_OF_SATELLITES 7
94 #define GNSS3_GNGGA_H_DILUTION_OF_POS 8
95 #define GNSS3_GNGGA_ALTITUDE 9
96 #define GNSS3_GNGGA_ALTITUDE_UNIT 10
97 #define GNSS3_GNGGA_GEOIDAL_SEPARATION 11
98 #define GNSS3_GNGGA_GEOIDAL_SEPARATION_UNIT 12
99 #define GNSS3_GNGGA_TIME_SINCE_LAST_DGPS 13
100 #define GNSS3_GNGGA_DGPS_REFERENCE_STATION_ID 14
101 
106 #define GNSS3_DRV_RX_BUFFER_SIZE 500
107  // End group macro
110 // --------------------------------------------------------------- PUBLIC TYPES
118 typedef struct
119 {
120  digital_out_t rst;
121  digital_in_t int_pin;
122 
123  uart_t uart;
124 
125  char uart_rx_buffer[ GNSS3_DRV_RX_BUFFER_SIZE ];
126  char uart_tx_buffer[ GNSS3_DRV_RX_BUFFER_SIZE ];
127 
128 } gnss3_t;
129 
133 typedef struct
134 {
135  // Communication gpio pins
136  pin_name_t rx_pin;
137  pin_name_t tx_pin;
138 
139  // Additional gpio pins
140  pin_name_t rst;
141  pin_name_t int_pin;
142 
143  // static variable
144  uint32_t baud_rate; // Clock speed.
146  uart_data_bits_t data_bit; // Data bits.
147  uart_parity_t parity_bit; // Parity bit.
148  uart_stop_bits_t stop_bit; // Stop bits.
149 
150 } gnss3_cfg_t;
151 
156 typedef enum
157 {
158  GNSS3_OK = 0,
159  GNSS3_ERROR = -1
160 
162  // End types group
164 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
165 
171 #ifdef __cplusplus
172 extern "C"{
173 #endif
174 
184 
192 err_t gnss3_init ( gnss3_t *ctx, gnss3_cfg_t *cfg );
193 
199 
205 void gnss3_set_rst_pin ( gnss3_t *ctx, uint8_t state );
206 
212 uint8_t gnss3_get_int_pin ( gnss3_t *ctx );
213 
220 void gnss3_generic_write ( gnss3_t *ctx, char *data_buf, uint16_t len );
221 
229 int32_t gnss3_generic_read ( gnss3_t *ctx, char *data_buf, uint16_t max_len );
230 
242 err_t gnss3_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
243 
244 #ifdef __cplusplus
245 }
246 #endif
247 #endif // _GNSS3_H_
248  // End public_function group
251 
252 // ------------------------------------------------------------------------- END
gnss3_cfg_t::rst
pin_name_t rst
Definition: gnss3.h:140
gnss3_get_int_pin
uint8_t gnss3_get_int_pin(gnss3_t *ctx)
Get PPS pin state.
gnss3_return_value_t
gnss3_return_value_t
GNSS 3 Click return value data.
Definition: gnss3.h:157
gnss3_t::rst
digital_out_t rst
Definition: gnss3.h:120
gnss3_init
err_t gnss3_init(gnss3_t *ctx, gnss3_cfg_t *cfg)
Initialization function.
gnss3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gnss3.h:137
gnss3_cfg_t::baud_rate
uint32_t baud_rate
Definition: gnss3.h:144
gnss3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gnss3.h:148
gnss3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gnss3.h:147
gnss3_t
Click ctx object definition.
Definition: gnss3.h:119
gnss3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gnss3.h:146
GNSS3_OK
@ GNSS3_OK
Definition: gnss3.h:158
gnss3_module_wakeup
void gnss3_module_wakeup(gnss3_t *ctx)
Wake-up module.
GNSS3_ERROR
@ GNSS3_ERROR
Definition: gnss3.h:159
gnss3_generic_read
int32_t gnss3_generic_read(gnss3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gnss3_generic_write
void gnss3_generic_write(gnss3_t *ctx, char *data_buf, uint16_t len)
Generic write function.
GNSS3_DRV_RX_BUFFER_SIZE
#define GNSS3_DRV_RX_BUFFER_SIZE
Definition: gnss3.h:106
gnss3_cfg_t::uart_blocking
bool uart_blocking
Definition: gnss3.h:145
gnss3_t::int_pin
digital_in_t int_pin
Definition: gnss3.h:121
gnss3_cfg_t
Click configuration structure definition.
Definition: gnss3.h:134
gnss3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gnss3.h:136
gnss3_t::uart
uart_t uart
Definition: gnss3.h:123
gnss3_cfg_t::int_pin
pin_name_t int_pin
Definition: gnss3.h:141
gnss3_cfg_setup
void gnss3_cfg_setup(gnss3_cfg_t *cfg)
Config Object Initialization function.
gnss3_parse_gngga
err_t gnss3_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
GNSS 3 parse GNGGA function.
gnss3_set_rst_pin
void gnss3_set_rst_pin(gnss3_t *ctx, uint8_t state)
Set RST ( reset ) pin state.