gps5  2.0.0.0
gps5.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 GPS5_H
29 #define GPS5_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 GPS5_RSP_START "$"
74 #define GPS5_RSP_DELIMITER ","
75 #define GPS5_RSP_GNGGA "$GNGGA"
76 
81 #define GPS5_GNGGA_ELEMENT_SIZE 15
82 #define GPS5_GNGGA_TIME 1
83 #define GPS5_GNGGA_LATITUDE 2
84 #define GPS5_GNGGA_LATITUDE_SIDE 3
85 #define GPS5_GNGGA_LONGITUDE 4
86 #define GPS5_GNGGA_LONGITUDE_SIDE 5
87 #define GPS5_GNGGA_QUALITY_INDICATOR 6
88 #define GPS5_GNGGA_NUMBER_OF_SATELLITES 7
89 #define GPS5_GNGGA_H_DILUTION_OF_POS 8
90 #define GPS5_GNGGA_ALTITUDE 9
91 #define GPS5_GNGGA_ALTITUDE_UNIT 10
92 #define GPS5_GNGGA_GEOIDAL_SEPARATION 11
93 #define GPS5_GNGGA_GEOIDAL_SEPARATION_UNIT 12
94 #define GPS5_GNGGA_TIME_SINCE_LAST_DGPS 13
95 #define GPS5_GNGGA_DGPS_REFERENCE_STATION_ID 14
96 
102 #define DRV_RX_BUFFER_SIZE 300
103 #define DRV_TX_BUFFER_SIZE 100
104  // gps5_cmd
106 
121 #define GPS5_MAP_MIKROBUS( cfg, mikrobus ) \
122  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
123  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
124  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
125  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
126  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
127  // gps5_map // gps5
130 
135 typedef struct
136 {
137  // Output pins
138  digital_out_t en;
139  digital_out_t rst;
140  digital_out_t stb;
142  // Modules
143  uart_t uart;
145  // Buffers
146  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
147  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
149 } gps5_t;
150 
155 typedef struct
156 {
157  // Communication gpio pins
158  pin_name_t rx_pin;
159  pin_name_t tx_pin;
161  // Additional gpio pins
162  pin_name_t en;
163  pin_name_t rst;
164  pin_name_t stb;
166  // Static variable
167  uint32_t baud_rate;
169  uart_data_bits_t data_bit;
170  uart_parity_t parity_bit;
171  uart_stop_bits_t stop_bit;
173 } gps5_cfg_t;
174 
179 typedef enum
180 {
181  GPS5_OK = 0,
182  GPS5_ERROR = -1
183 
185 
202 
216 err_t gps5_init ( gps5_t *ctx, gps5_cfg_t *cfg );
217 
230 err_t gps5_generic_write ( gps5_t *ctx, char *data_buf, uint16_t len );
231 
244 err_t gps5_generic_read ( gps5_t *ctx, char *data_buf, uint16_t max_len );
245 
255 void gps5_set_rst_pin ( gps5_t *ctx, uint8_t state );
256 
266 void gps5_set_stb_pin ( gps5_t *ctx, uint8_t state );
267 
277 void gps5_set_en_pin ( gps5_t *ctx, uint8_t state );
278 
290 err_t gps5_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
291 
292 #ifdef __cplusplus
293 }
294 #endif
295 #endif // GPS5_H
296  // gps5
298 
299 // ------------------------------------------------------------------------ END
gps5_generic_write
err_t gps5_generic_write(gps5_t *ctx, char *data_buf, uint16_t len)
GPS 5 data writing function.
GPS5_OK
@ GPS5_OK
Definition: gps5.h:181
gps5_cfg_setup
void gps5_cfg_setup(gps5_cfg_t *cfg)
GPS 5 configuration object setup function.
gps5_cfg_t::uart_blocking
bool uart_blocking
Definition: gps5.h:168
gps5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps5.h:167
gps5_parse_gngga
err_t gps5_parse_gngga(char *rsp_buf, uint8_t gngga_element, char *element_data)
GPS 5 parse GNGGA function.
gps5_set_rst_pin
void gps5_set_rst_pin(gps5_t *ctx, uint8_t state)
GPS 5 set RST pin function.
gps5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps5.h:159
gps5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps5.h:158
GPS5_ERROR
@ GPS5_ERROR
Definition: gps5.h:182
gps5_return_value_t
gps5_return_value_t
GPS 5 Click return value data.
Definition: gps5.h:180
gps5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps5.h:171
gps5_t
GPS 5 Click context object.
Definition: gps5.h:136
gps5_generic_read
err_t gps5_generic_read(gps5_t *ctx, char *data_buf, uint16_t max_len)
GPS 5 data reading function.
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
GPS 5 driver buffer size.
Definition: gps5.h:102
gps5_t::uart
uart_t uart
Definition: gps5.h:143
gps5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps5.h:170
gps5_set_en_pin
void gps5_set_en_pin(gps5_t *ctx, uint8_t state)
GPS 5 set EN pin function.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: gps5.h:103
gps5_cfg_t::en
pin_name_t en
Definition: gps5.h:162
gps5_init
err_t gps5_init(gps5_t *ctx, gps5_cfg_t *cfg)
GPS 5 initialization function.
gps5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps5.h:169
gps5_cfg_t::rst
pin_name_t rst
Definition: gps5.h:163
gps5_t::en
digital_out_t en
Definition: gps5.h:138
gps5_set_stb_pin
void gps5_set_stb_pin(gps5_t *ctx, uint8_t state)
GPS 5 set STB pin function.
gps5_t::rst
digital_out_t rst
Definition: gps5.h:139
gps5_t::stb
digital_out_t stb
Definition: gps5.h:140
gps5_cfg_t::stb
pin_name_t stb
Definition: gps5.h:164
gps5_cfg_t
GPS 5 Click configuration object.
Definition: gps5.h:156