gnss12 2.0.0.0
gnss12.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 GNSS12_H
29#define GNSS12_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_spi_master.h"
53#include "drv_uart.h"
54#include "spi_specifics.h"
55
76#define GNSS12_RSP_START "$"
77#define GNSS12_RSP_DELIMITER ","
78#define GNSS12_RSP_GNGGA "$GNGGA"
79
84#define GNSS12_GNGGA_ELEMENT_SIZE 15
85#define GNSS12_GNGGA_TIME 1
86#define GNSS12_GNGGA_LATITUDE 2
87#define GNSS12_GNGGA_LATITUDE_SIDE 3
88#define GNSS12_GNGGA_LONGITUDE 4
89#define GNSS12_GNGGA_LONGITUDE_SIDE 5
90#define GNSS12_GNGGA_QUALITY_INDICATOR 6
91#define GNSS12_GNGGA_NUMBER_OF_SATELLITES 7
92#define GNSS12_GNGGA_H_DILUTION_OF_POS 8
93#define GNSS12_GNGGA_ALTITUDE 9
94#define GNSS12_GNGGA_ALTITUDE_UNIT 10
95#define GNSS12_GNGGA_GEOIDAL_SEPARATION 11
96#define GNSS12_GNGGA_GEOIDAL_SEPARATION_UNIT 12
97#define GNSS12_GNGGA_TIME_SINCE_LAST_DGPS 13
98#define GNSS12_GNGGA_DGPS_REFERENCE_STATION_ID 14
99
104#define GNSS12_DUMMY 0xFF
105
111#define GNSS12_SET_DEV_ADDR 0x42
112
118#define GNSS12_DRV_BUFFER_SIZE 200
119
128#define GNSS12_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
129#define GNSS12_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
130
131 // gnss12_set
132
147#define GNSS12_MAP_MIKROBUS( cfg, mikrobus ) \
148 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
149 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
150 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
151 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
152 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
153 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
154 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
155 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
156 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
157 cfg.lna_en = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
158 cfg.eint = MIKROBUS( mikrobus, MIKROBUS_INT )
159
160 // gnss12_map
161 // gnss12
162
174
179typedef err_t ( *gnss12_master_io_t )( struct gnss12_s*, uint8_t*, uint8_t );
185typedef struct gnss12_s
186{
187 digital_out_t rst;
189 digital_in_t eint;
190 digital_in_t lna_en;
192 i2c_master_t i2c;
193 spi_master_t spi;
194 uart_t uart;
196 // Buffers
201 pin_name_t chip_select;
208
213typedef struct
214{
215 pin_name_t scl;
216 pin_name_t sda;
217 pin_name_t miso;
218 pin_name_t mosi;
219 pin_name_t sck;
220 pin_name_t cs;
221 pin_name_t rx_pin;
222 pin_name_t tx_pin;
223 pin_name_t rst;
224 pin_name_t lna_en;
225 pin_name_t eint;
227 uint32_t i2c_speed;
228 uint8_t i2c_address;
230 uint32_t spi_speed;
231 spi_master_mode_t spi_mode;
232 spi_master_chip_select_polarity_t cs_polarity;
234 uint32_t baud_rate;
236 uart_data_bits_t data_bit;
237 uart_parity_t parity_bit;
238 uart_stop_bits_t stop_bit;
243
248typedef enum
249{
251 GNSS12_ERROR = -1
252
254
271
287
301err_t gnss12_init ( gnss12_t *ctx, gnss12_cfg_t *cfg );
302
315err_t gnss12_generic_write ( gnss12_t *ctx, uint8_t *data_in, uint8_t len );
316
329err_t gnss12_generic_read ( gnss12_t *ctx, uint8_t *data_out, uint8_t len );
330
340void gnss12_set_rst_pin ( gnss12_t *ctx, uint8_t state );
341
351
361
371
383err_t gnss12_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
384
385#ifdef __cplusplus
386}
387#endif
388#endif // GNSS12_H
389
390 // gnss12
391
392// ------------------------------------------------------------------------ END
err_t(* gnss12_master_io_t)(struct gnss12_s *, uint8_t *, uint8_t)
GNSS 12 Click driver interface.
Definition gnss12.h:179
gnss12_drv_t
GNSS 12 Click driver selector.
Definition gnss12.h:168
@ GNSS12_DRV_SEL_UART
Definition gnss12.h:169
@ GNSS12_DRV_SEL_SPI
Definition gnss12.h:170
@ GNSS12_DRV_SEL_I2C
Definition gnss12.h:171
struct gnss12_s gnss12_t
GNSS 12 Click context object.
gnss12_return_value_t
GNSS 12 Click return value data.
Definition gnss12.h:249
@ GNSS12_OK
Definition gnss12.h:250
@ GNSS12_ERROR
Definition gnss12.h:251
#define GNSS12_DRV_BUFFER_SIZE
GNSS 12 driver buffer size.
Definition gnss12.h:118
void gnss12_set_rst_pin(gnss12_t *ctx, uint8_t state)
GNSS 12 set RST pin function.
uint8_t gnss12_get_eint_pin(gnss12_t *ctx)
GNSS 12 get Ext INT pin function.
err_t gnss12_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
GNSS 12 parse GNGGA function.
err_t gnss12_init(gnss12_t *ctx, gnss12_cfg_t *cfg)
GNSS 12 initialization function.
uint8_t gnss12_get_lna_en_pin(gnss12_t *ctx)
GNSS 12 get LNA EN pin function.
err_t gnss12_generic_write(gnss12_t *ctx, uint8_t *data_in, uint8_t len)
GNSS 12 data writing function.
void gnss12_drv_interface_selection(gnss12_cfg_t *cfg, gnss12_drv_t drv_sel)
GNSS 12 driver interface setup function.
err_t gnss12_generic_read(gnss12_t *ctx, uint8_t *data_out, uint8_t len)
GNSS 12 data reading function.
void gnss12_reset_device(gnss12_t *ctx)
GNSS 12 reset device function.
void gnss12_cfg_setup(gnss12_cfg_t *cfg)
GNSS 12 configuration object setup function.
This file contains SPI specific macros, functions, etc.
GNSS 12 Click configuration object.
Definition gnss12.h:214
uint32_t baud_rate
Definition gnss12.h:234
gnss12_drv_t drv_sel
Definition gnss12.h:240
uint32_t i2c_speed
Definition gnss12.h:227
spi_master_chip_select_polarity_t cs_polarity
Definition gnss12.h:232
bool uart_blocking
Definition gnss12.h:235
pin_name_t sck
Definition gnss12.h:219
uart_data_bits_t data_bit
Definition gnss12.h:236
spi_master_mode_t spi_mode
Definition gnss12.h:231
pin_name_t lna_en
Definition gnss12.h:224
pin_name_t tx_pin
Definition gnss12.h:222
pin_name_t mosi
Definition gnss12.h:218
uint32_t spi_speed
Definition gnss12.h:230
pin_name_t eint
Definition gnss12.h:225
pin_name_t rx_pin
Definition gnss12.h:221
uart_stop_bits_t stop_bit
Definition gnss12.h:238
pin_name_t scl
Definition gnss12.h:215
pin_name_t miso
Definition gnss12.h:217
uart_parity_t parity_bit
Definition gnss12.h:237
pin_name_t sda
Definition gnss12.h:216
pin_name_t rst
Definition gnss12.h:223
pin_name_t cs
Definition gnss12.h:220
uint8_t i2c_address
Definition gnss12.h:228
GNSS 12 Click context object.
Definition gnss12.h:186
spi_master_t spi
Definition gnss12.h:193
gnss12_drv_t drv_sel
Definition gnss12.h:202
gnss12_master_io_t read_f
Definition gnss12.h:205
char uart_tx_buffer[GNSS12_DRV_BUFFER_SIZE]
Definition gnss12.h:198
char uart_rx_buffer[GNSS12_DRV_BUFFER_SIZE]
Definition gnss12.h:197
uart_t uart
Definition gnss12.h:194
i2c_master_t i2c
Definition gnss12.h:192
digital_in_t lna_en
Definition gnss12.h:190
digital_out_t rst
Definition gnss12.h:187
digital_in_t eint
Definition gnss12.h:189
uint8_t slave_address
Definition gnss12.h:200
gnss12_master_io_t write_f
Definition gnss12.h:204
pin_name_t chip_select
Definition gnss12.h:201