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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define UWB3_CMD_HELP "help"
60 #define UWB3_CMD_STAT "stat"
61 #define UWB3_CMD_DECA "deca$"
62 #define UWB3_CMD_STOP "stop"
63 #define UWB3_CMD_SAVE "save"
64 #define UWB3_CMD_THREAD "thread"
65 
70 #define UWB3_CMD_LISTENER2 "listener2"
71 #define UWB3_CMD_TCFM "tcfm"
72 #define UWB3_CMD_TCWM "tcwm"
73 #define UWB3_CMD_RESPF "respf"
74 #define UWB3_CMD_INITF "initf"
75 
80 #define UWB3_CMD_LSTAT "lstat"
81 
86 #define UWB3_CMD_PAVRG "pavrg"
87 
92 #define UWB3_CMD_ANTTXA "anttxa"
93 #define UWB3_CMD_ANTRXA "antrxa"
94 #define UWB3_CMD_XTALTRIM "xtaltrim"
95 #define UWB3_CMD_PDOAOFF "pdoaoff"
96 #define UWB3_CMD_UART "uart"
97 
102 #define UWB3_CMD_RESTORE "restore"
103 #define UWB3_CMD_DIAG "diag"
104 #define UWB3_CMD_UWBCFG "uwbcfg"
105 #define UWB3_CMD_STSKEYIV "stskeyiv"
106 #define UWB3_CMD_TXPOWER "txpower"
107 #define UWB3_CMD_ANTENNA "antenna"
108 #define UWB3_CMD_DECAID "decaid"
109 #define UWB3_CMD_VERSION "version"
110 
115 #define UWB3_RSP_OK "ok"
116 #define UWB3_RSP_ERROR "error"
117 
123 #define UWB3_TX_DRV_BUFFER_SIZE 100
124 #define UWB3_RX_DRV_BUFFER_SIZE 1000
125  // uwb3_cmd
127 
142 #define UWB3_MAP_MIKROBUS( cfg, mikrobus ) \
143  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
144  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
145  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST );
146  // uwb3_map // uwb3
149 
154 typedef struct
155 {
156  // Output pins
157  digital_out_t rst;
159  // Modules
160  uart_t uart;
162  // Buffers
163  uint8_t uart_rx_buffer[ UWB3_RX_DRV_BUFFER_SIZE ];
164  uint8_t uart_tx_buffer[ UWB3_TX_DRV_BUFFER_SIZE ];
166 } uwb3_t;
167 
172 typedef struct
173 {
174  // Communication gpio pins
175  pin_name_t rx_pin;
176  pin_name_t tx_pin;
178  // Additional gpio pins
179  pin_name_t rst;
181  // Static variable
182  uint32_t baud_rate;
184  uart_data_bits_t data_bit;
185  uart_parity_t parity_bit;
186  uart_stop_bits_t stop_bit;
188 } uwb3_cfg_t;
189 
194 typedef enum
195 {
196  UWB3_OK = 0,
198  UWB3_ERROR_TIMEOUT = -2
199 
201 
218 
232 err_t uwb3_init ( uwb3_t *ctx, uwb3_cfg_t *cfg );
233 
246 err_t uwb3_generic_write ( uwb3_t *ctx, uint8_t *data_in, uint16_t len );
247 
260 err_t uwb3_generic_read ( uwb3_t *ctx, uint8_t *data_out, uint16_t len );
261 
271 void uwb3_send_cmd ( uwb3_t *ctx, uint8_t *cmd );
272 
283 void uwb3_send_cmd_with_parameter ( uwb3_t *ctx, uint8_t *cmd, uint8_t *param );
284 
294 void uwb3_set_rst_pin ( uwb3_t *ctx, uint8_t state );
295 
304 void uwb3_reset_device ( uwb3_t *ctx );
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 #endif // UWB3_H
310  // uwb3
312 
313 // ------------------------------------------------------------------------ END
UWB3_TX_DRV_BUFFER_SIZE
#define UWB3_TX_DRV_BUFFER_SIZE
UWB 3 driver buffer size.
Definition: uwb3.h:123
uwb3_t::uart
uart_t uart
Definition: uwb3.h:160
uwb3_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uwb3.h:186
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:196
uwb3_return_value_t
uwb3_return_value_t
UWB 3 Click return value data.
Definition: uwb3.h:195
uwb3_cfg_t::baud_rate
uint32_t baud_rate
Definition: uwb3.h:182
UWB3_ERROR
@ UWB3_ERROR
Definition: uwb3.h:197
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:155
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:157
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:124
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:183
uwb3_cfg_t
UWB 3 Click configuration object.
Definition: uwb3.h:173
uwb3_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uwb3.h:176
uwb3_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uwb3.h:184
uwb3_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uwb3.h:175
uwb3_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uwb3.h:185
uwb3_cfg_t::rst
pin_name_t rst
Definition: uwb3.h:179
UWB3_ERROR_TIMEOUT
@ UWB3_ERROR_TIMEOUT
Definition: uwb3.h:198