uwb3  2.1.0.0
uwb3.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 UWB3_H
29 #define UWB3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
73 #define UWB3_CMD_HELP "help"
74 #define UWB3_CMD_STAT "stat"
75 #define UWB3_CMD_DECA "deca$"
76 #define UWB3_CMD_STOP "stop"
77 #define UWB3_CMD_SAVE "save"
78 #define UWB3_CMD_THREAD "thread"
79 
84 #define UWB3_CMD_LISTENER2 "listener2"
85 #define UWB3_CMD_TCFM "tcfm"
86 #define UWB3_CMD_TCWM "tcwm"
87 #define UWB3_CMD_RESPF "respf"
88 #define UWB3_CMD_INITF "initf"
89 
94 #define UWB3_CMD_LSTAT "lstat"
95 
100 #define UWB3_CMD_PAVRG "pavrg"
101 
106 #define UWB3_CMD_ANTTXA "anttxa"
107 #define UWB3_CMD_ANTRXA "antrxa"
108 #define UWB3_CMD_XTALTRIM "xtaltrim"
109 #define UWB3_CMD_PDOAOFF "pdoaoff"
110 #define UWB3_CMD_UART "uart"
111 
116 #define UWB3_CMD_RESTORE "restore"
117 #define UWB3_CMD_DIAG "diag"
118 #define UWB3_CMD_UWBCFG "uwbcfg"
119 #define UWB3_CMD_STSKEYIV "stskeyiv"
120 #define UWB3_CMD_TXPOWER "txpower"
121 #define UWB3_CMD_ANTENNA "antenna"
122 #define UWB3_CMD_DECAID "decaid"
123 #define UWB3_CMD_VERSION "version"
124 
129 #define UWB3_RSP_OK "ok"
130 #define UWB3_RSP_ERROR "error"
131 
137 #define UWB3_TX_DRV_BUFFER_SIZE 100
138 #define UWB3_RX_DRV_BUFFER_SIZE 1000
139  // uwb3_cmd
141 
156 #define UWB3_MAP_MIKROBUS( cfg, mikrobus ) \
157  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
158  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
159  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
160  // uwb3_map // uwb3
163 
168 typedef struct
169 {
170  // Output pins
171  digital_out_t rst;
173  // Modules
174  uart_t uart;
176  // Buffers
177  uint8_t uart_rx_buffer[ UWB3_RX_DRV_BUFFER_SIZE ];
178  uint8_t uart_tx_buffer[ UWB3_TX_DRV_BUFFER_SIZE ];
180 } uwb3_t;
181 
186 typedef struct
187 {
188  // Communication gpio pins
189  pin_name_t rx_pin;
190  pin_name_t tx_pin;
192  // Additional gpio pins
193  pin_name_t rst;
195  // Static variable
196  uint32_t baud_rate;
198  uart_data_bits_t data_bit;
199  uart_parity_t parity_bit;
200  uart_stop_bits_t stop_bit;
202 } uwb3_cfg_t;
203 
208 typedef enum
209 {
210  UWB3_OK = 0,
212  UWB3_ERROR_TIMEOUT = -2
213 
215 
232 
246 err_t uwb3_init ( uwb3_t *ctx, uwb3_cfg_t *cfg );
247 
260 err_t uwb3_generic_write ( uwb3_t *ctx, uint8_t *data_in, uint16_t len );
261 
274 err_t uwb3_generic_read ( uwb3_t *ctx, uint8_t *data_out, uint16_t len );
275 
285 void uwb3_send_cmd ( uwb3_t *ctx, uint8_t *cmd );
286 
297 void uwb3_send_cmd_with_parameter ( uwb3_t *ctx, uint8_t *cmd, uint8_t *param );
298 
308 void uwb3_set_rst_pin ( uwb3_t *ctx, uint8_t state );
309 
318 void uwb3_reset_device ( uwb3_t *ctx );
319 
320 #ifdef __cplusplus
321 }
322 #endif
323 #endif // UWB3_H
324  // uwb3
326 
327 // ------------------------------------------------------------------------ END
UWB3_TX_DRV_BUFFER_SIZE
#define UWB3_TX_DRV_BUFFER_SIZE
UWB 3 driver buffer size.
Definition: uwb3.h:137
uwb3_t::uart
uart_t uart
Definition: uwb3.h:174
uwb3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uwb3.h:200
uwb3_generic_write
err_t uwb3_generic_write(uwb3_t *ctx, uint8_t *data_in, uint16_t len)
UWB 3 data writing function.
UWB3_OK
@ UWB3_OK
Definition: uwb3.h:210
uwb3_return_value_t
uwb3_return_value_t
UWB 3 Click return value data.
Definition: uwb3.h:209
uwb3_cfg_t::baud_rate
uint32_t baud_rate
Definition: uwb3.h:196
UWB3_ERROR
@ UWB3_ERROR
Definition: uwb3.h:211
uwb3_send_cmd_with_parameter
void uwb3_send_cmd_with_parameter(uwb3_t *ctx, uint8_t *cmd, uint8_t *param)
UWB 3 send cmd with parameter function.
uwb3_t
UWB 3 Click context object.
Definition: uwb3.h:169
uwb3_set_rst_pin
void uwb3_set_rst_pin(uwb3_t *ctx, uint8_t state)
UWB 3 set rst pin function.
uwb3_t::rst
digital_out_t rst
Definition: uwb3.h:171
uwb3_init
err_t uwb3_init(uwb3_t *ctx, uwb3_cfg_t *cfg)
UWB 3 initialization function.
UWB3_RX_DRV_BUFFER_SIZE
#define UWB3_RX_DRV_BUFFER_SIZE
Definition: uwb3.h:138
uwb3_reset_device
void uwb3_reset_device(uwb3_t *ctx)
UWB 3 reset device function.
uwb3_generic_read
err_t uwb3_generic_read(uwb3_t *ctx, uint8_t *data_out, uint16_t len)
UWB 3 data reading function.
uwb3_send_cmd
void uwb3_send_cmd(uwb3_t *ctx, uint8_t *cmd)
UWB 3 send cmd function.
uwb3_cfg_setup
void uwb3_cfg_setup(uwb3_cfg_t *cfg)
UWB 3 configuration object setup function.
uwb3_cfg_t::uart_blocking
bool uart_blocking
Definition: uwb3.h:197
uwb3_cfg_t
UWB 3 Click configuration object.
Definition: uwb3.h:187
uwb3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uwb3.h:190
uwb3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uwb3.h:198
uwb3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uwb3.h:189
uwb3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uwb3.h:199
uwb3_cfg_t::rst
pin_name_t rst
Definition: uwb3.h:193
UWB3_ERROR_TIMEOUT
@ UWB3_ERROR_TIMEOUT
Definition: uwb3.h:212