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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define GPS5_RSP_START "$"
60 #define GPS5_RSP_DELIMITER ","
61 #define GPS5_RSP_GNGGA "$GNGGA"
62 
67 #define GPS5_GNGGA_ELEMENT_SIZE 15
68 #define GPS5_GNGGA_TIME 1
69 #define GPS5_GNGGA_LATITUDE 2
70 #define GPS5_GNGGA_LATITUDE_SIDE 3
71 #define GPS5_GNGGA_LONGITUDE 4
72 #define GPS5_GNGGA_LONGITUDE_SIDE 5
73 #define GPS5_GNGGA_QUALITY_INDICATOR 6
74 #define GPS5_GNGGA_NUMBER_OF_SATELLITES 7
75 #define GPS5_GNGGA_H_DILUTION_OF_POS 8
76 #define GPS5_GNGGA_ALTITUDE 9
77 #define GPS5_GNGGA_ALTITUDE_UNIT 10
78 #define GPS5_GNGGA_GEOIDAL_SEPARATION 11
79 #define GPS5_GNGGA_GEOIDAL_SEPARATION_UNIT 12
80 #define GPS5_GNGGA_TIME_SINCE_LAST_DGPS 13
81 #define GPS5_GNGGA_DGPS_REFERENCE_STATION_ID 14
82 
88 #define DRV_RX_BUFFER_SIZE 300
89 #define DRV_TX_BUFFER_SIZE 100
90  // gps5_cmd
92 
107 #define GPS5_MAP_MIKROBUS( cfg, mikrobus ) \
108  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
109  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
110  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
111  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
112  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
113  // gps5_map // gps5
116 
121 typedef struct
122 {
123  // Output pins
124  digital_out_t en;
125  digital_out_t rst;
126  digital_out_t stb;
128  // Modules
129  uart_t uart;
131  // Buffers
132  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
133  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
135 } gps5_t;
136 
141 typedef struct
142 {
143  // Communication gpio pins
144  pin_name_t rx_pin;
145  pin_name_t tx_pin;
147  // Additional gpio pins
148  pin_name_t en;
149  pin_name_t rst;
150  pin_name_t stb;
152  // Static variable
153  uint32_t baud_rate;
155  uart_data_bits_t data_bit;
156  uart_parity_t parity_bit;
157  uart_stop_bits_t stop_bit;
159 } gps5_cfg_t;
160 
165 typedef enum
166 {
167  GPS5_OK = 0,
168  GPS5_ERROR = -1
169 
171 
188 
202 err_t gps5_init ( gps5_t *ctx, gps5_cfg_t *cfg );
203 
216 err_t gps5_generic_write ( gps5_t *ctx, char *data_buf, uint16_t len );
217 
230 err_t gps5_generic_read ( gps5_t *ctx, char *data_buf, uint16_t max_len );
231 
241 void gps5_set_rst_pin ( gps5_t *ctx, uint8_t state );
242 
252 void gps5_set_stb_pin ( gps5_t *ctx, uint8_t state );
253 
263 void gps5_set_en_pin ( gps5_t *ctx, uint8_t state );
264 
276 err_t gps5_parse_gngga ( char *rsp_buf, uint8_t gngga_element, char *element_data );
277 
278 #ifdef __cplusplus
279 }
280 #endif
281 #endif // GPS5_H
282  // gps5
284 
285 // ------------------------------------------------------------------------ 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:167
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:154
gps5_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps5.h:153
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:145
gps5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps5.h:144
GPS5_ERROR
@ GPS5_ERROR
Definition: gps5.h:168
gps5_return_value_t
gps5_return_value_t
GPS 5 Click return value data.
Definition: gps5.h:166
gps5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps5.h:157
gps5_t
GPS 5 Click context object.
Definition: gps5.h:122
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:88
gps5_t::uart
uart_t uart
Definition: gps5.h:129
gps5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps5.h:156
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:89
gps5_cfg_t::en
pin_name_t en
Definition: gps5.h:148
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:155
gps5_cfg_t::rst
pin_name_t rst
Definition: gps5.h:149
gps5_t::en
digital_out_t en
Definition: gps5.h:124
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:125
gps5_t::stb
digital_out_t stb
Definition: gps5.h:126
gps5_cfg_t::stb
pin_name_t stb
Definition: gps5.h:150
gps5_cfg_t
GPS 5 Click configuration object.
Definition: gps5.h:142