gps3  2.0.0.0
gps3.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 GPS3_H
29 #define GPS3_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 GPS3_RSP_START "$"
70 #define GPS3_RSP_DELIMITER ","
71 #define GPS3_RSP_END_SEQ "\r\n"
72 #define GPS3_RSP_GPGGA "$GPGGA"
73 
78 #define GPS3_GPGGA_ELEMENT_SIZE 15
79 #define GPS3_GPGGA_TIME 1
80 #define GPS3_GPGGA_LATITUDE 2
81 #define GPS3_GPGGA_LATITUDE_SIDE 3
82 #define GPS3_GPGGA_LONGITUDE 4
83 #define GPS3_GPGGA_LONGITUDE_SIDE 5
84 #define GPS3_GPGGA_QUALITY_INDICATOR 6
85 #define GPS3_GPGGA_NUMBER_OF_SATELLITES 7
86 #define GPS3_GPGGA_H_DILUTION_OF_POS 8
87 #define GPS3_GPGGA_ALTITUDE 9
88 #define GPS3_GPGGA_ALTITUDE_UNIT 10
89 #define GPS3_GPGGA_GEOIDAL_SEPARATION 11
90 #define GPS3_GPGGA_GEOIDAL_SEPARATION_UNIT 12
91 #define GPS3_GPGGA_TIME_SINCE_LAST_DGPS 13
92 #define GPS3_GPGGA_DGPS_REFERENCE_STATION_ID 14
93 
99 #define GPS3_DRV_TX_BUFFER_SIZE 100
100 #define GPS3_DRV_RX_BUFFER_SIZE 1000
101  // gps3_cmd
103 
118 #define GPS3_MAP_MIKROBUS( cfg, mikrobus ) \
119  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
120  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
121  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
122  // gps3_map // gps3
125 
130 typedef struct
131 {
132  // Output pins
133  digital_out_t rst;
134 
135  // Modules
136  uart_t uart;
138  // Buffers
139  char uart_rx_buffer[ GPS3_DRV_RX_BUFFER_SIZE ];
140  char uart_tx_buffer[ GPS3_DRV_TX_BUFFER_SIZE ];
142 } gps3_t;
143 
148 typedef struct
149 {
150  // Communication gpio pins
151  pin_name_t rx_pin;
152  pin_name_t tx_pin;
154  // Additional gpio pins
155  pin_name_t rst;
156 
157  // Static variable
158  uint32_t baud_rate;
160  uart_data_bits_t data_bit;
161  uart_parity_t parity_bit;
162  uart_stop_bits_t stop_bit;
164 } gps3_cfg_t;
165 
170 typedef enum
171 {
172  GPS3_OK = 0,
173  GPS3_ERROR = -1
174 
176 
193 
207 err_t gps3_init ( gps3_t *ctx, gps3_cfg_t *cfg );
208 
221 err_t gps3_generic_write ( gps3_t *ctx, char *data_in, uint16_t len );
222 
235 err_t gps3_generic_read ( gps3_t *ctx, char *data_out, uint16_t len );
236 
246 
256 void gps3_set_rst_pin ( gps3_t *ctx, uint8_t state );
257 
269 err_t gps3_parse_gpgga ( char *rsp_buf, uint8_t gpgga_element, char *element_data );
270 
271 #ifdef __cplusplus
272 }
273 #endif
274 #endif // GPS3_H
275  // gps3
277 
278 // ------------------------------------------------------------------------ END
gps3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps3.h:162
gps3_cfg_setup
void gps3_cfg_setup(gps3_cfg_t *cfg)
GPS 3 configuration object setup function.
gps3_t::rst
digital_out_t rst
Definition: gps3.h:133
gps3_generic_read
err_t gps3_generic_read(gps3_t *ctx, char *data_out, uint16_t len)
GPS 3 data reading function.
gps3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps3.h:161
gps3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps3.h:160
gps3_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps3.h:158
gps3_clear_ring_buffers
void gps3_clear_ring_buffers(gps3_t *ctx)
GPS 3 clear ring buffers function.
gps3_set_rst_pin
void gps3_set_rst_pin(gps3_t *ctx, uint8_t state)
GPS 3 set RST pin function.
gps3_cfg_t::rst
pin_name_t rst
Definition: gps3.h:155
gps3_generic_write
err_t gps3_generic_write(gps3_t *ctx, char *data_in, uint16_t len)
GPS 3 data writing function.
gps3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps3.h:152
gps3_init
err_t gps3_init(gps3_t *ctx, gps3_cfg_t *cfg)
GPS 3 initialization function.
gps3_t
GPS 3 Click context object.
Definition: gps3.h:131
gps3_return_value_t
gps3_return_value_t
GPS 3 Click return value data.
Definition: gps3.h:171
GPS3_DRV_TX_BUFFER_SIZE
#define GPS3_DRV_TX_BUFFER_SIZE
GPS 3 driver buffer size.
Definition: gps3.h:99
GPS3_OK
@ GPS3_OK
Definition: gps3.h:172
gps3_parse_gpgga
err_t gps3_parse_gpgga(char *rsp_buf, uint8_t gpgga_element, char *element_data)
GPS 3 parse GPGGA function.
gps3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps3.h:151
gps3_cfg_t::uart_blocking
bool uart_blocking
Definition: gps3.h:159
GPS3_DRV_RX_BUFFER_SIZE
#define GPS3_DRV_RX_BUFFER_SIZE
Definition: gps3.h:100
gps3_t::uart
uart_t uart
Definition: gps3.h:136
GPS3_ERROR
@ GPS3_ERROR
Definition: gps3.h:173
gps3_cfg_t
GPS 3 Click configuration object.
Definition: gps3.h:149