gps4  2.0.0.0
gps4.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef GPS4_H
36 #define GPS4_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define GPS4_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.fon = MIKROBUS( mikrobus, MIKROBUS_AN ); \
57  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
58  cfg.stb = MIKROBUS( mikrobus, MIKROBUS_PWM )
59 
65 #define GPS4_RETVAL uint8_t
66 
67 #define GPS4_OK 0x00
68 #define GPS4_INIT_ERROR 0xFF
69 
75 #define GPS4_NEMA_GPGGA 1
76 #define GPS4_NEMA_GPGLL 3
77 #define GPS4_NEMA_GPGGA_NUM_ELEMENT 15
78 #define GPS4_NEMA_GPGLL_NUM_ELEMENT 5
79 
85 #define GPS4_GPGGA_TIME 1
86 #define GPS4_GPGGA_LATITUDE 2
87 #define GPS4_GPGGA_LATITUDE_SIDE 3
88 #define GPS4_GPGGA_LONGITUDE 4
89 #define GPS4_GPGGA_LONGITUDE_SIDE 5
90 #define GPS4_GPGGA_QUALITY_INDICATOR 6
91 #define GPS4_GPGGA_NUMBER_OF_SATELLITES 7
92 #define GPS4_GPGGA_H_DILUTION_OF_POS 8
93 #define GPS4_GPGGA_ALTITUDE 9
94 #define GPS4_GPGGA_ALTITUDE_UNIT 10
95 #define GPS4_GPGGA_GEOIDAL_SEPARATION 11
96 #define GPS4_GPGGA_GEOIDAL_SEPARATION_UNIT 12
97 #define GPS4_GPGGA_TIME_SINCE_LAST_DGPS 13
98 #define GPS4_GPGGA_DGPS_REFERENCE_STATION_ID 14
99 
105 #define GPS4_GPGLL_LATITUDE 1
106 #define GPS4_GPGLL_LATITUDE_SIDE 2
107 #define GPS4_GPGLL_LONGITUDE 3
108 #define GPS4_GPGLL_LONGITUDE_SIDE 4
109 
115 #define GPS4_ERROR_COMMAND_OR_ELEMENT 0xFF
116 #define GPS4_ERROR_START_OR_END_COMMAND 0x8F
117 #define GPS4_ERROR_NEXT_ELEMENT 0x4F
118 #define GPS4_ERROR_CURRENT_ELEMENT 0x2F
119 #define GPS4_NO_ERROR 0x00
120 
126 #define DRV_RX_BUFFER_SIZE 500
127  // End group macro
130 // --------------------------------------------------------------- PUBLIC TYPES
138 typedef struct
139 {
140  // Output pins
141 
142  digital_out_t rst;
143 
144  // Input pins
145 
146  digital_in_t fon;
147  digital_in_t stb;
148 
149  // Modules
150 
151  uart_t uart;
152 
153  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
154  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
155 
156 } gps4_t;
157 
161 typedef struct
162 {
163  // Communication gpio pins
164 
165  pin_name_t rx_pin;
166  pin_name_t tx_pin;
167 
168  // Additional gpio pins
169 
170  pin_name_t fon;
171  pin_name_t rst;
172  pin_name_t stb;
173 
174  // static variable
175 
176  uint32_t baud_rate; // Clock speed.
178  uart_data_bits_t data_bit; // Data bits.
179  uart_parity_t parity_bit; // Parity bit.
180  uart_stop_bits_t stop_bit; // Stop bits.
181 
182 } gps4_cfg_t;
183 
187 typedef uint8_t gps4_error_t;
188  // End types group
190 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
191 
197 #ifdef __cplusplus
198 extern "C"{
199 #endif
200 
209 void gps4_cfg_setup ( gps4_cfg_t *cfg );
210 
218 GPS4_RETVAL gps4_init ( gps4_t *ctx, gps4_cfg_t *cfg );
219 
227 void gps4_default_cfg ( gps4_t *ctx );
228 
233 void gps4_module_wakeup ( gps4_t *ctx );
234 
239 void gps4_module_reset ( gps4_t *ctx );
240 
246 void gps4_set_wkp_pin ( gps4_t *ctx, uint8_t state );
247 
253 void gps4_set_rst_pin ( gps4_t *ctx, uint8_t state );
254 
260 uint8_t gps4_get_pps_pin ( gps4_t *ctx );
261 
268 void gps4_generic_write ( gps4_t *ctx, char *data_buf, uint16_t len );
269 
277 int16_t gps4_generic_read ( gps4_t *ctx, char *data_buf, uint16_t max_len );
278 
288 (
289  char *rsp, uint8_t command,
290  uint8_t element, char *parser_buf
291 );
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 #endif // _GPS4_H_
297  // End public_function group
300 
301 // ------------------------------------------------------------------------- END
void gps4_default_cfg(gps4_t *ctx)
Click Default Configuration function.
pin_name_t rx_pin
Definition: gps4.h:165
void gps4_set_wkp_pin(gps4_t *ctx, uint8_t state)
Set WKP ( wake-up ) pin state.
Click ctx object definition.
Definition: gps4.h:138
uart_t uart
Definition: gps4.h:151
uint32_t baud_rate
Definition: gps4.h:176
void gps4_module_reset(gps4_t *ctx)
Reset module.
void gps4_module_wakeup(gps4_t *ctx)
Wake-up module.
uart_data_bits_t data_bit
Definition: gps4.h:178
uart_stop_bits_t stop_bit
Definition: gps4.h:180
digital_in_t fon
Definition: gps4.h:146
uint8_t gps4_error_t
Error type.
Definition: gps4.h:187
#define GPS4_RETVAL
Definition: gps4.h:65
Click configuration structure definition.
Definition: gps4.h:161
#define DRV_RX_BUFFER_SIZE
Definition: gps4.h:126
void gps4_generic_write(gps4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
bool uart_blocking
Definition: gps4.h:177
pin_name_t tx_pin
Definition: gps4.h:166
GPS4_RETVAL gps4_init(gps4_t *ctx, gps4_cfg_t *cfg)
Initialization function.
digital_in_t stb
Definition: gps4.h:147
pin_name_t fon
Definition: gps4.h:170
int16_t gps4_generic_read(gps4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
digital_out_t rst
Definition: gps4.h:142
gps4_error_t gps4_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
uart_parity_t parity_bit
Definition: gps4.h:179
void gps4_cfg_setup(gps4_cfg_t *cfg)
Config Object Initialization function.
uint8_t gps4_get_pps_pin(gps4_t *ctx)
Get PPS pin state.
pin_name_t stb
Definition: gps4.h:172
void gps4_set_rst_pin(gps4_t *ctx, uint8_t state)
Set RST ( reset ) pin state.
pin_name_t rst
Definition: gps4.h:171