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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define GNSS3_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.int_pin = MIKROBUS( mikrobus, MIKROBUS_CS )
58 
64 #define GNSS3_RSP_START "$"
65 #define GNSS3_RSP_DELIMITER ","
66 #define GNSS3_RSP_GNGGA "$GNGGA"
67 
72 #define GNSS3_GNGGA_ELEMENT_SIZE 15
73 #define GNSS3_GNGGA_TIME 1
74 #define GNSS3_GNGGA_LATITUDE 2
75 #define GNSS3_GNGGA_LATITUDE_SIDE 3
76 #define GNSS3_GNGGA_LONGITUDE 4
77 #define GNSS3_GNGGA_LONGITUDE_SIDE 5
78 #define GNSS3_GNGGA_QUALITY_INDICATOR 6
79 #define GNSS3_GNGGA_NUMBER_OF_SATELLITES 7
80 #define GNSS3_GNGGA_H_DILUTION_OF_POS 8
81 #define GNSS3_GNGGA_ALTITUDE 9
82 #define GNSS3_GNGGA_ALTITUDE_UNIT 10
83 #define GNSS3_GNGGA_GEOIDAL_SEPARATION 11
84 #define GNSS3_GNGGA_GEOIDAL_SEPARATION_UNIT 12
85 #define GNSS3_GNGGA_TIME_SINCE_LAST_DGPS 13
86 #define GNSS3_GNGGA_DGPS_REFERENCE_STATION_ID 14
87 
92 #define GNSS3_DRV_RX_BUFFER_SIZE 500
93  // End group macro
96 // --------------------------------------------------------------- PUBLIC TYPES
104 typedef struct
105 {
106  digital_out_t rst;
107  digital_in_t int_pin;
108 
109  uart_t uart;
110 
111  char uart_rx_buffer[ GNSS3_DRV_RX_BUFFER_SIZE ];
112  char uart_tx_buffer[ GNSS3_DRV_RX_BUFFER_SIZE ];
113 
114 } gnss3_t;
115 
119 typedef struct
120 {
121  // Communication gpio pins
122  pin_name_t rx_pin;
123  pin_name_t tx_pin;
124 
125  // Additional gpio pins
126  pin_name_t rst;
127  pin_name_t int_pin;
128 
129  // static variable
130  uint32_t baud_rate; // Clock speed.
132  uart_data_bits_t data_bit; // Data bits.
133  uart_parity_t parity_bit; // Parity bit.
134  uart_stop_bits_t stop_bit; // Stop bits.
135 
136 } gnss3_cfg_t;
137 
142 typedef enum
143 {
144  GNSS3_OK = 0,
145  GNSS3_ERROR = -1
146 
148  // End types group
150 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
151 
157 #ifdef __cplusplus
158 extern "C"{
159 #endif
160 
170 
178 err_t gnss3_init ( gnss3_t *ctx, gnss3_cfg_t *cfg );
179 
185 
191 void gnss3_set_rst_pin ( gnss3_t *ctx, uint8_t state );
192 
198 uint8_t gnss3_get_int_pin ( gnss3_t *ctx );
199 
206 void gnss3_generic_write ( gnss3_t *ctx, char *data_buf, uint16_t len );
207 
215 int32_t gnss3_generic_read ( gnss3_t *ctx, char *data_buf, uint16_t max_len );
216 
228 err_t gnss3_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
229 
230 #ifdef __cplusplus
231 }
232 #endif
233 #endif // _GNSS3_H_
234  // End public_function group
237 
238 // ------------------------------------------------------------------------- END
gnss3_cfg_t::rst
pin_name_t rst
Definition: gnss3.h:126
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:143
gnss3_t::rst
digital_out_t rst
Definition: gnss3.h:106
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:123
gnss3_cfg_t::baud_rate
uint32_t baud_rate
Definition: gnss3.h:130
gnss3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gnss3.h:134
gnss3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gnss3.h:133
gnss3_t
Click ctx object definition.
Definition: gnss3.h:105
gnss3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gnss3.h:132
GNSS3_OK
@ GNSS3_OK
Definition: gnss3.h:144
gnss3_module_wakeup
void gnss3_module_wakeup(gnss3_t *ctx)
Wake-up module.
GNSS3_ERROR
@ GNSS3_ERROR
Definition: gnss3.h:145
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:92
gnss3_cfg_t::uart_blocking
bool uart_blocking
Definition: gnss3.h:131
gnss3_t::int_pin
digital_in_t int_pin
Definition: gnss3.h:107
gnss3_cfg_t
Click configuration structure definition.
Definition: gnss3.h:120
gnss3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gnss3.h:122
gnss3_t::uart
uart_t uart
Definition: gnss3.h:109
gnss3_cfg_t::int_pin
pin_name_t int_pin
Definition: gnss3.h:127
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.