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 600
127 #define DRV_TX_BUFFER_SIZE 100
128  // End group macro
131 // --------------------------------------------------------------- PUBLIC TYPES
139 typedef struct
140 {
141  // Output pins
142 
143  digital_out_t rst;
144 
145  // Input pins
146 
147  digital_in_t fon;
148  digital_in_t stb;
149 
150  // Modules
151 
152  uart_t uart;
153 
154  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
155  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
156 
157 } gps4_t;
158 
162 typedef struct
163 {
164  // Communication gpio pins
165 
166  pin_name_t rx_pin;
167  pin_name_t tx_pin;
168 
169  // Additional gpio pins
170 
171  pin_name_t fon;
172  pin_name_t rst;
173  pin_name_t stb;
174 
175  // static variable
176 
177  uint32_t baud_rate; // Clock speed.
179  uart_data_bits_t data_bit; // Data bits.
180  uart_parity_t parity_bit; // Parity bit.
181  uart_stop_bits_t stop_bit; // Stop bits.
182 
183 } gps4_cfg_t;
184 
188 typedef uint8_t gps4_error_t;
189  // End types group
191 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
192 
198 #ifdef __cplusplus
199 extern "C"{
200 #endif
201 
211 
220 
226 
231 void gps4_module_reset ( gps4_t *ctx );
232 
238 void gps4_set_wkp_pin ( gps4_t *ctx, uint8_t state );
239 
245 void gps4_set_rst_pin ( gps4_t *ctx, uint8_t state );
246 
252 uint8_t gps4_get_pps_pin ( gps4_t *ctx );
253 
260 void gps4_generic_write ( gps4_t *ctx, char *data_buf, uint16_t len );
261 
269 int32_t gps4_generic_read ( gps4_t *ctx, char *data_buf, uint16_t max_len );
270 
280 (
281  char *rsp, uint8_t command,
282  uint8_t element, char *parser_buf
283 );
284 
285 #ifdef __cplusplus
286 }
287 #endif
288 #endif // _GPS4_H_
289  // End public_function group
292 
293 // ------------------------------------------------------------------------- END
gps4_cfg_t::baud_rate
uint32_t baud_rate
Definition: gps4.h:177
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: gps4.h:126
gps4_t::stb
digital_in_t stb
Definition: gps4.h:148
gps4_init
GPS4_RETVAL gps4_init(gps4_t *ctx, gps4_cfg_t *cfg)
Initialization function.
gps4_cfg_t::uart_blocking
bool uart_blocking
Definition: gps4.h:178
gps4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: gps4.h:179
gps4_t::uart
uart_t uart
Definition: gps4.h:152
gps4_generic_write
void gps4_generic_write(gps4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
gps4_module_reset
void gps4_module_reset(gps4_t *ctx)
Reset module.
gps4_get_pps_pin
uint8_t gps4_get_pps_pin(gps4_t *ctx)
Get PPS pin state.
gps4_cfg_t::stb
pin_name_t stb
Definition: gps4.h:173
gps4_t::rst
digital_out_t rst
Definition: gps4.h:143
gps4_t
Click ctx object definition.
Definition: gps4.h:140
gps4_cfg_t::fon
pin_name_t fon
Definition: gps4.h:171
GPS4_RETVAL
#define GPS4_RETVAL
Definition: gps4.h:65
gps4_generic_read
int32_t gps4_generic_read(gps4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
gps4_error_t
uint8_t gps4_error_t
Error type.
Definition: gps4.h:188
gps4_module_wakeup
void gps4_module_wakeup(gps4_t *ctx)
Wake-up module.
gps4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: gps4.h:180
gps4_t::fon
digital_in_t fon
Definition: gps4.h:147
gps4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: gps4.h:166
gps4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: gps4.h:167
gps4_cfg_t::rst
pin_name_t rst
Definition: gps4.h:172
gps4_set_wkp_pin
void gps4_set_wkp_pin(gps4_t *ctx, uint8_t state)
Set WKP ( wake-up ) pin state.
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: gps4.h:127
gps4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: gps4.h:181
gps4_cfg_setup
void gps4_cfg_setup(gps4_cfg_t *cfg)
Config Object Initialization function.
gps4_cfg_t
Click configuration structure definition.
Definition: gps4.h:163
gps4_generic_parser
gps4_error_t gps4_generic_parser(char *rsp, uint8_t command, uint8_t element, char *parser_buf)
Generic parser function.
gps4_set_rst_pin
void gps4_set_rst_pin(gps4_t *ctx, uint8_t state)
Set RST ( reset ) pin state.