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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
69 #define GPS5_RSP_START "$"
70 #define GPS5_RSP_DELIMITER ","
71 #define GPS5_RSP_GNGGA "$GNGGA"
72 
77 #define GPS5_GNGGA_ELEMENT_SIZE 15
78 #define GPS5_GNGGA_TIME 1
79 #define GPS5_GNGGA_LATITUDE 2
80 #define GPS5_GNGGA_LATITUDE_SIDE 3
81 #define GPS5_GNGGA_LONGITUDE 4
82 #define GPS5_GNGGA_LONGITUDE_SIDE 5
83 #define GPS5_GNGGA_QUALITY_INDICATOR 6
84 #define GPS5_GNGGA_NUMBER_OF_SATELLITES 7
85 #define GPS5_GNGGA_H_DILUTION_OF_POS 8
86 #define GPS5_GNGGA_ALTITUDE 9
87 #define GPS5_GNGGA_ALTITUDE_UNIT 10
88 #define GPS5_GNGGA_GEOIDAL_SEPARATION 11
89 #define GPS5_GNGGA_GEOIDAL_SEPARATION_UNIT 12
90 #define GPS5_GNGGA_TIME_SINCE_LAST_DGPS 13
91 #define GPS5_GNGGA_DGPS_REFERENCE_STATION_ID 14
92 
98 #define DRV_RX_BUFFER_SIZE 300
99 #define DRV_TX_BUFFER_SIZE 100
100  // gps5_cmd
102 
117 #define GPS5_MAP_MIKROBUS( cfg, mikrobus ) \
118  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
119  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
120  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
121  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
122  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
123  // gps5_map // gps5
126 
131 typedef struct
132 {
133  // Output pins
134  digital_out_t en;
135  digital_out_t rst;
136  digital_out_t stb;
138  // Modules
139  uart_t uart;
141  // Buffers
142  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
143  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
145 } gps5_t;
146 
151 typedef struct
152 {
153  // Communication gpio pins
154  pin_name_t rx_pin;
155  pin_name_t tx_pin;
157  // Additional gpio pins
158  pin_name_t en;
159  pin_name_t rst;
160  pin_name_t stb;
162  // Static variable
163  uint32_t baud_rate;
165  uart_data_bits_t data_bit;
166  uart_parity_t parity_bit;
167  uart_stop_bits_t stop_bit;
169 } gps5_cfg_t;
170 
175 typedef enum
176 {
177  GPS5_OK = 0,
178  GPS5_ERROR = -1
179 
181 
198 
212 err_t gps5_init ( gps5_t *ctx, gps5_cfg_t *cfg );
213 
226 err_t gps5_generic_write ( gps5_t *ctx, char *data_buf, uint16_t len );
227 
240 err_t gps5_generic_read ( gps5_t *ctx, char *data_buf, uint16_t max_len );
241 
251 void gps5_set_rst_pin ( gps5_t *ctx, uint8_t state );
252 
262 void gps5_set_stb_pin ( gps5_t *ctx, uint8_t state );
263 
273 void gps5_set_en_pin ( gps5_t *ctx, uint8_t state );
274 
286 err_t gps5_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
287 
288 #ifdef __cplusplus
289 }
290 #endif
291 #endif // GPS5_H
292  // gps5
294 
295 // ------------------------------------------------------------------------ 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:177
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:164
gps5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps5.h:163
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:155
gps5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps5.h:154
GPS5_ERROR
@ GPS5_ERROR
Definition: gps5.h:178
gps5_return_value_t
gps5_return_value_t
GPS 5 Click return value data.
Definition: gps5.h:176
gps5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps5.h:167
gps5_t
GPS 5 Click context object.
Definition: gps5.h:132
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:98
gps5_t::uart
uart_t uart
Definition: gps5.h:139
gps5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps5.h:166
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:99
gps5_cfg_t::en
pin_name_t en
Definition: gps5.h:158
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:165
gps5_cfg_t::rst
pin_name_t rst
Definition: gps5.h:159
gps5_t::en
digital_out_t en
Definition: gps5.h:134
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:135
gps5_t::stb
digital_out_t stb
Definition: gps5.h:136
gps5_cfg_t::stb
pin_name_t stb
Definition: gps5.h:160
gps5_cfg_t
GPS 5 Click configuration object.
Definition: gps5.h:152