gnssrtk3 2.1.0.0
gnssrtk3.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 GNSSRTK3_H
29#define GNSSRTK3_H
30
31#ifdef __cplusplus
32extern "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_i2c_master.h"
52#include "drv_uart.h"
53
74#define GNSSRTK3_RSP_START "$"
75#define GNSSRTK3_RSP_DELIMITER ","
76#define GNSSRTK3_RSP_END "\r\n"
77#define GNSSRTK3_RSP_GGA "GGA"
78
83#define GNSSRTK3_GGA_ELEMENT_SIZE 15
84#define GNSSRTK3_GGA_TIME 1
85#define GNSSRTK3_GGA_LATITUDE 2
86#define GNSSRTK3_GGA_LATITUDE_SIDE 3
87#define GNSSRTK3_GGA_LONGITUDE 4
88#define GNSSRTK3_GGA_LONGITUDE_SIDE 5
89#define GNSSRTK3_GGA_QUALITY_INDICATOR 6
90#define GNSSRTK3_GGA_NUMBER_OF_SATELLITES 7
91#define GNSSRTK3_GGA_H_DILUTION_OF_POS 8
92#define GNSSRTK3_GGA_ALTITUDE 9
93#define GNSSRTK3_GGA_ALTITUDE_UNIT 10
94#define GNSSRTK3_GGA_GEOIDAL_SEPARATION 11
95#define GNSSRTK3_GGA_GEOIDAL_SEPARATION_UNIT 12
96#define GNSSRTK3_GGA_TIME_SINCE_LAST_DGPS 13
97#define GNSSRTK3_GGA_DGPS_REFERENCE_STATION_ID 14
98
103#define GNSSRTK3_I2C_SLAVE_CR_CMD 0xAA51u
104#define GNSSRTK3_I2C_SLAVE_CW_CMD 0xAA53u
105#define GNSSRTK3_I2C_SLAVE_CMD_LEN 8
106#define GNSSRTK3_I2C_SLAVE_RX_LEN 4
107#define GNSSRTK3_I2C_SLAVE_TX_LEN_REG_OFFSET 0x0008u
108#define GNSSRTK3_I2C_SLAVE_TX_BUF_REG_OFFSET 0x2000u
109#define GNSSRTK3_I2C_SLAVE_RX_LEN_REG_OFFSET 0x0004u
110#define GNSSRTK3_I2C_SLAVE_RX_BUF_REG_OFFSET 0x1000u
111#define GNSSRTK3_I2C_SLAVE_ADDRESS_CR_OR_CW 0x50
112#define GNSSRTK3_I2C_SLAVE_ADDRESS_R 0x54
113#define GNSSRTK3_I2C_SLAVE_ADDRESS_W 0x58
114#define GNSSRTK3_I2C_SLAVE_MAX_ERRORS 10
115
121#define GNSSRTK3_TX_DRV_BUFFER_SIZE 100
122#define GNSSRTK3_RX_DRV_BUFFER_SIZE 1000u
123
124 // gnssrtk3_cmd
125
140#define GNSSRTK3_MAP_MIKROBUS( cfg, mikrobus ) \
141 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
142 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
143 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
144 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
145 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
146 cfg.cen = MIKROBUS( mikrobus, MIKROBUS_CS ); \
147 cfg.wup = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
148 cfg.pps = MIKROBUS( mikrobus, MIKROBUS_INT );
149
150 // gnssrtk3_map
151 // gnssrtk3
152
163
168struct gnssrtk3_s;
169typedef err_t ( *gnssrtk3_master_io_t )( struct gnssrtk3_s*, uint8_t*, uint16_t );
194
199typedef struct
200{
201 pin_name_t scl;
202 pin_name_t sda;
203 pin_name_t rx_pin;
204 pin_name_t tx_pin;
205 pin_name_t rst;
206 pin_name_t cen;
207 pin_name_t wup;
208 pin_name_t pps;
210 uint32_t i2c_speed;
211 uint8_t i2c_address;
213 uint32_t baud_rate;
215 uart_data_bits_t data_bit;
216 uart_parity_t parity_bit;
217 uart_stop_bits_t stop_bit;
222
227typedef enum
228{
230 GNSSRTK3_ERROR = -1
231
233
250
266
281
294err_t gnssrtk3_generic_write ( gnssrtk3_t *ctx, uint8_t *data_in, uint16_t len );
295
308err_t gnssrtk3_generic_read ( gnssrtk3_t *ctx, uint8_t *data_out, uint16_t len );
309
319void gnssrtk3_set_rst_pin ( gnssrtk3_t *ctx, uint8_t state );
320
330void gnssrtk3_set_cen_pin ( gnssrtk3_t *ctx, uint8_t state );
331
341void gnssrtk3_set_wup_pin ( gnssrtk3_t *ctx, uint8_t state );
342
352
362
372
382
394err_t gnssrtk3_parse_gga ( uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data );
395
396#ifdef __cplusplus
397}
398#endif
399#endif // GNSSRTK3_H
400
401 // gnssrtk3
402
403// ------------------------------------------------------------------------ END
gnssrtk3_return_value_t
GNSS RTK 3 Click return value data.
Definition gnssrtk3.h:228
@ GNSSRTK3_ERROR
Definition gnssrtk3.h:230
@ GNSSRTK3_OK
Definition gnssrtk3.h:229
gnssrtk3_drv_t
GNSS RTK 3 Click driver selector.
Definition gnssrtk3.h:158
@ GNSSRTK3_DRV_SEL_UART
Definition gnssrtk3.h:159
@ GNSSRTK3_DRV_SEL_I2C
Definition gnssrtk3.h:160
err_t(* gnssrtk3_master_io_t)(struct gnssrtk3_s *, uint8_t *, uint16_t)
Definition gnssrtk3.h:169
struct gnssrtk3_s gnssrtk3_t
GNSS RTK 3 Click context object.
#define GNSSRTK3_TX_DRV_BUFFER_SIZE
GNSS RTK 3 driver buffer size.
Definition gnssrtk3.h:121
#define GNSSRTK3_RX_DRV_BUFFER_SIZE
Definition gnssrtk3.h:122
void gnssrtk3_set_wup_pin(gnssrtk3_t *ctx, uint8_t state)
GNSS RTK 3 set WUP pin function.
err_t gnssrtk3_generic_write(gnssrtk3_t *ctx, uint8_t *data_in, uint16_t len)
GNSS RTK 3 data writing function.
void gnssrtk3_cfg_setup(gnssrtk3_cfg_t *cfg)
GNSS RTK 3 configuration object setup function.
void gnssrtk3_set_cen_pin(gnssrtk3_t *ctx, uint8_t state)
GNSS RTK 3 set CEN pin function.
err_t gnssrtk3_init(gnssrtk3_t *ctx, gnssrtk3_cfg_t *cfg)
GNSS RTK 3 initialization function.
void gnssrtk3_reset_device(gnssrtk3_t *ctx)
GNSS RTK 3 reset device function.
err_t gnssrtk3_generic_read(gnssrtk3_t *ctx, uint8_t *data_out, uint16_t len)
GNSS RTK 3 data reading function.
void gnssrtk3_disable_device(gnssrtk3_t *ctx)
GNSS RTK 3 disable device function.
void gnssrtk3_drv_interface_sel(gnssrtk3_cfg_t *cfg, gnssrtk3_drv_t drv_sel)
GNSS RTK 3 driver interface setup function.
void gnssrtk3_enable_device(gnssrtk3_t *ctx)
GNSS RTK 3 enable device function.
err_t gnssrtk3_parse_gga(uint8_t *rsp_buf, uint8_t gga_element, uint8_t *element_data)
GNSS RTK 3 parse GGA function.
void gnssrtk3_set_rst_pin(gnssrtk3_t *ctx, uint8_t state)
GNSS RTK 3 set RST pin function.
uint8_t gnssrtk3_get_pps_pin(gnssrtk3_t *ctx)
GNSS RTK 3 get PPS pin function.
GNSS RTK 3 Click configuration object.
Definition gnssrtk3.h:200
uint32_t baud_rate
Definition gnssrtk3.h:213
pin_name_t wup
Definition gnssrtk3.h:207
pin_name_t pps
Definition gnssrtk3.h:208
uint32_t i2c_speed
Definition gnssrtk3.h:210
pin_name_t cen
Definition gnssrtk3.h:206
bool uart_blocking
Definition gnssrtk3.h:214
uart_data_bits_t data_bit
Definition gnssrtk3.h:215
gnssrtk3_drv_t drv_sel
Definition gnssrtk3.h:219
pin_name_t tx_pin
Definition gnssrtk3.h:204
pin_name_t rx_pin
Definition gnssrtk3.h:203
uart_stop_bits_t stop_bit
Definition gnssrtk3.h:217
pin_name_t scl
Definition gnssrtk3.h:201
uart_parity_t parity_bit
Definition gnssrtk3.h:216
pin_name_t sda
Definition gnssrtk3.h:202
pin_name_t rst
Definition gnssrtk3.h:205
uint8_t i2c_address
Definition gnssrtk3.h:211
GNSS RTK 3 Click context object.
Definition gnssrtk3.h:176
uint8_t uart_rx_buffer[GNSSRTK3_RX_DRV_BUFFER_SIZE]
Definition gnssrtk3.h:185
gnssrtk3_master_io_t write_f
Definition gnssrtk3.h:190
digital_in_t pps
Definition gnssrtk3.h:180
uint8_t uart_tx_buffer[GNSSRTK3_TX_DRV_BUFFER_SIZE]
Definition gnssrtk3.h:186
uart_t uart
Definition gnssrtk3.h:182
gnssrtk3_drv_t drv_sel
Definition gnssrtk3.h:188
digital_out_t cen
Definition gnssrtk3.h:178
i2c_master_t i2c
Definition gnssrtk3.h:183
digital_out_t wup
Definition gnssrtk3.h:179
digital_out_t rst
Definition gnssrtk3.h:177
gnssrtk3_master_io_t read_f
Definition gnssrtk3.h:191