uwb4  2.1.0.0
uwb4.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 UWB4_H
29 #define UWB4_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 UWB4_CMD_AT "AT"
74 #define UWB4_CMD_DISABLE_ECHO "ATE0"
75 #define UWB4_CMD_ENABLE_ECHO "ATE1"
76 #define UWB4_CMD_GET_MODULE_NAME "ATI0"
77 #define UWB4_CMD_GET_FIRMWARE_VERSION "ATI3"
78 #define UWB4_CMD_GET_BLE_ADDRESS "ATI4"
79 #define UWB4_CMD_GET_UNIQUE_ID "ATI5"
80 #define UWB4_CMD_GET_LAST_RESET_REASON "ATI2001"
81 #define UWB4_CMD_GET_FREE_MEMORY "ATI2002"
82 #define UWB4_CMD_GET_ALLOCATED_MEMORY "ATI2003"
83 #define UWB4_CMD_RESET_MODULE "ATZ"
84 #define UWB4_CMD_CREATE_SESSION "AT+UWBS"
85 #define UWB4_CMD_DELETE_SESSION "AT+UWBSD"
86 #define UWB4_CMD_SET_ADDRESS "AT+UWBSA"
87 #define UWB4_CMD_ADD_PEER "AT+UWBSAM"
88 #define UWB4_CMD_REMOVE_PEER "AT+UWBSAMX"
89 #define UWB4_CMD_SET_RANGING_INTERVAL "AT+UWBSI"
90 #define UWB4_CMD_SET_SESSION_CONFIG "AT+UWBSC"
91 #define UWB4_CMD_START_SESSION "AT+UWBSS"
92 
97 #define UWB4_RSP_OK "OK"
98 #define UWB4_RSP_ERROR "ERROR"
99 #define UWB4_RSP_RANGE "RANGE:"
100 
106 #define UWB4_TX_DRV_BUFFER_SIZE 256
107 #define UWB4_RX_DRV_BUFFER_SIZE 256
108  // uwb4_cmd
110 
125 #define UWB4_MAP_MIKROBUS( cfg, mikrobus ) \
126  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
127  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
128  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
129  cfg.btn = MIKROBUS( mikrobus, MIKROBUS_INT );
130  // uwb4_map // uwb4
133 
138 typedef struct
139 {
140  // Output pins
141  digital_out_t rst;
143  // Input pins
144  digital_in_t btn;
146  // Modules
147  uart_t uart;
149  // Buffers
150  uint8_t uart_rx_buffer[ UWB4_RX_DRV_BUFFER_SIZE ];
151  uint8_t uart_tx_buffer[ UWB4_TX_DRV_BUFFER_SIZE ];
152  uint8_t cmd_buffer[ UWB4_TX_DRV_BUFFER_SIZE ];
154 } uwb4_t;
155 
160 typedef struct
161 {
162  // Communication gpio pins
163  pin_name_t rx_pin;
164  pin_name_t tx_pin;
166  // Additional gpio pins
167  pin_name_t rst;
168  pin_name_t btn;
170  // Static variable
171  uint32_t baud_rate;
173  uart_data_bits_t data_bit;
174  uart_parity_t parity_bit;
175  uart_stop_bits_t stop_bit;
177 } uwb4_cfg_t;
178 
183 typedef enum
184 {
185  UWB4_OK = 0,
188  UWB4_ERROR_CMD = -3
189 
191 
208 
222 err_t uwb4_init ( uwb4_t *ctx, uwb4_cfg_t *cfg );
223 
236 err_t uwb4_generic_write ( uwb4_t *ctx, uint8_t *data_in, uint16_t len );
237 
250 err_t uwb4_generic_read ( uwb4_t *ctx, uint8_t *data_out, uint16_t len );
251 
261 void uwb4_set_rst_pin ( uwb4_t *ctx, uint8_t state );
262 
271 void uwb4_reset_device ( uwb4_t *ctx );
272 
281 uint8_t uwb4_get_btn_pin ( uwb4_t *ctx );
282 
292 void uwb4_cmd_run ( uwb4_t *ctx, uint8_t *cmd );
293 
304 void uwb4_cmd_set ( uwb4_t *ctx, uint8_t *cmd, uint8_t *value );
305 
306 #ifdef __cplusplus
307 }
308 #endif
309 #endif // UWB4_H
310  // uwb4
312 
313 // ------------------------------------------------------------------------ END
uwb4_cmd_set
void uwb4_cmd_set(uwb4_t *ctx, uint8_t *cmd, uint8_t *value)
UWB 4 cmd set function.
UWB4_OK
@ UWB4_OK
Definition: uwb4.h:185
uwb4_get_btn_pin
uint8_t uwb4_get_btn_pin(uwb4_t *ctx)
UWB 4 get BTN pin function.
uwb4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uwb4.h:175
uwb4_generic_write
err_t uwb4_generic_write(uwb4_t *ctx, uint8_t *data_in, uint16_t len)
UWB 4 data writing function.
uwb4_set_rst_pin
void uwb4_set_rst_pin(uwb4_t *ctx, uint8_t state)
UWB 4 set RST pin function.
uwb4_cfg_t::uart_blocking
bool uart_blocking
Definition: uwb4.h:172
uwb4_t::btn
digital_in_t btn
Definition: uwb4.h:144
uwb4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uwb4.h:174
UWB4_ERROR_CMD
@ UWB4_ERROR_CMD
Definition: uwb4.h:188
uwb4_generic_read
err_t uwb4_generic_read(uwb4_t *ctx, uint8_t *data_out, uint16_t len)
UWB 4 data reading function.
uwb4_t
UWB 4 Click context object.
Definition: uwb4.h:139
UWB4_ERROR
@ UWB4_ERROR
Definition: uwb4.h:186
UWB4_RX_DRV_BUFFER_SIZE
#define UWB4_RX_DRV_BUFFER_SIZE
Definition: uwb4.h:107
uwb4_cfg_t::rst
pin_name_t rst
Definition: uwb4.h:167
uwb4_t::uart
uart_t uart
Definition: uwb4.h:147
uwb4_cfg_t::btn
pin_name_t btn
Definition: uwb4.h:168
UWB4_TX_DRV_BUFFER_SIZE
#define UWB4_TX_DRV_BUFFER_SIZE
UWB 4 driver buffer size.
Definition: uwb4.h:106
uwb4_reset_device
void uwb4_reset_device(uwb4_t *ctx)
UWB 4 reset device function.
uwb4_cfg_setup
void uwb4_cfg_setup(uwb4_cfg_t *cfg)
UWB 4 configuration object setup function.
uwb4_cmd_run
void uwb4_cmd_run(uwb4_t *ctx, uint8_t *cmd)
UWB 4 cmd run function.
uwb4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uwb4.h:164
uwb4_cfg_t
UWB 4 Click configuration object.
Definition: uwb4.h:161
uwb4_t::rst
digital_out_t rst
Definition: uwb4.h:141
uwb4_return_value_t
uwb4_return_value_t
UWB 4 Click return value data.
Definition: uwb4.h:184
uwb4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uwb4.h:173
uwb4_cfg_t::baud_rate
uint32_t baud_rate
Definition: uwb4.h:171
UWB4_ERROR_TIMEOUT
@ UWB4_ERROR_TIMEOUT
Definition: uwb4.h:187
uwb4_init
err_t uwb4_init(uwb4_t *ctx, uwb4_cfg_t *cfg)
UWB 4 initialization function.
uwb4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uwb4.h:163