radar 2.0.0.0
radar.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 RADAR_H
29#define RADAR_H
30
31#ifdef __cplusplus
32extern "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 RADAR_CMD_HEADER 0xD9
74#define RADAR_CMD_ID_VERSION 0x00
75#define RADAR_CMD_ID_ACK 0x02
76#define RADAR_CMD_ID_MAX_DETECT_RANGE 0x03
77#define RADAR_CMD_ID_SENSITIVITY 0x04
78#define RADAR_CMD_ID_DETECT_OUT 0x05
79#define RADAR_CMD_ID_DETECT_IN_EVT 0x06
80#define RADAR_CMD_ID_DETECT_OUT_EVT 0x07
81#define RADAR_CMD_ID_RESET_CONFIG 0x08
82#define RADAR_CMD_ID_GET_DETECT_STATUS 0x09
83#define RADAR_CMD_ID_DETECT_ENABLE 0x0A
84#define RADAR_CMD_ID_RFCW_MODE 0x0B
85#define RADAR_CMD_ID_CHIP_TEMPERATURE 0x0D
86#define RADAR_CMD_ID_SLEEP_MODE 0x0E
87#define RADAR_CMD_ID_CALIB_MODE 0x0F
88#define RADAR_CMD_ID_CALIB_MSG 0x10
89#define RADAR_CMD_ID_CALIB_MSG_RATE 0x11
90#define RADAR_CMD_ID_MIN_DETECT_RANGE 0x30
91#define RADAR_CMD_ID_MACRO_THRESHOLD 0x31
92#define RADAR_CMD_ID_MICRO_THRESHOLD 0x32
93#define RADAR_CMD_ID_MACRO_VALID 0x33
94#define RADAR_CMD_ID_MICRO_VALID 0x34
95#define RADAR_CMD_ID_DETECT_MODE 0x35
96#define RADAR_CMD_ID_MACRO_DETECT_RANGE 0x36
97#define RADAR_CMD_ID_MACRO_DETECT_DELAY 0x37
98#define RADAR_CMD_ID_CHIRP_PER_FRAME 0x38
99#define RADAR_CMD_ID_UNIQUE_ID 0xF7
100
105#define RADAR_SET_CMD_FAIL 0x00
106#define RADAR_SET_CMD_SUCCESS 0x01
107
112#define RADAR_TIMEOUT 1000
113
118#define RADAR_DEFAULT_MIN_RANGE 0.0
119#define RADAR_DEFAULT_MAX_RANGE 3.0
120
126#define DRV_BUFFER_SIZE 256
127
128 // radar_cmd
129
144#define RADAR_MAP_MIKROBUS( cfg, mikrobus ) \
145 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
146 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
147 cfg.gp2 = MIKROBUS( mikrobus, MIKROBUS_AN ); \
148 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
149 cfg.gp1 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
150 cfg.gp0 = MIKROBUS( mikrobus, MIKROBUS_INT );
151
152 // radar_map
153 // radar
154
159typedef union
160{
161 uint8_t b_data[ 4 ];
162 float f_data;
163
165
170typedef struct
171{
172 // Output pins
173 digital_out_t rst;
175 // Input pins
176 digital_in_t gp2;
177 digital_in_t gp1;
178 digital_in_t gp0;
180 // Modules
181 uart_t uart;
183 // Buffers
184 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
185 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
187} radar_t;
188
193typedef struct
194{
195 // Communication gpio pins
196 pin_name_t rx_pin;
197 pin_name_t tx_pin;
199 // Additional gpio pins
200 pin_name_t rst;
201 pin_name_t gp2;
202 pin_name_t gp1;
203 pin_name_t gp0;
205 // Static variable
206 uint32_t baud_rate;
208 uart_data_bits_t data_bit;
209 uart_parity_t parity_bit;
210 uart_stop_bits_t stop_bit;
213
218typedef enum
219{
221 RADAR_ERROR = -1
222
224
241
255err_t radar_init ( radar_t *ctx, radar_cfg_t *cfg );
256
270
283err_t radar_generic_write ( radar_t *ctx, uint8_t *data_buf, uint16_t len );
284
297err_t radar_generic_read ( radar_t *ctx, uint8_t *data_buf, uint16_t max_len );
298
308
318
328
338
348
363err_t radar_set_command ( radar_t *ctx, uint8_t cmd_id, uint8_t *payload, uint8_t payload_size );
364
378err_t radar_get_command ( radar_t *ctx, uint8_t cmd_id, uint8_t *payload, uint8_t *payload_size );
379
393err_t radar_get_event ( radar_t *ctx, uint8_t *evt_id, uint8_t *payload, uint8_t *payload_size );
394
406err_t radar_get_temperature ( radar_t *ctx, float *temperature );
407
420err_t radar_set_detection_range ( radar_t *ctx, float min, float max );
421
433
440void radar_float_ieee_to_mchip ( float *f_data );
441
448void radar_float_mchip_to_ieee ( float *f_data );
449
450#ifdef __cplusplus
451}
452#endif
453#endif // RADAR_H
454
455 // radar
456
457// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
Radar driver buffer size.
Definition radar.h:126
err_t radar_set_detection_range(radar_t *ctx, float min, float max)
Radar set detection range function.
err_t radar_get_command(radar_t *ctx, uint8_t cmd_id, uint8_t *payload, uint8_t *payload_size)
Radar get command function.
uint8_t radar_get_gpio2_pin(radar_t *ctx)
Radar get gpio 2 pin function.
err_t radar_default_cfg(radar_t *ctx)
Radar default configuration function.
err_t radar_init(radar_t *ctx, radar_cfg_t *cfg)
Radar initialization function.
void radar_enable_device(radar_t *ctx)
Radar enable device function.
void radar_cfg_setup(radar_cfg_t *cfg)
Radar configuration object setup function.
err_t radar_generic_read(radar_t *ctx, uint8_t *data_buf, uint16_t max_len)
Radar data reading function.
err_t radar_get_temperature(radar_t *ctx, float *temperature)
Radar get temperature function.
err_t radar_set_command(radar_t *ctx, uint8_t cmd_id, uint8_t *payload, uint8_t payload_size)
Radar set command function.
void radar_float_mchip_to_ieee(float *f_data)
Radar float ieee to mchip function.
err_t radar_reset_config(radar_t *ctx)
Radar reset config function.
err_t radar_generic_write(radar_t *ctx, uint8_t *data_buf, uint16_t len)
Radar data writing function.
err_t radar_get_event(radar_t *ctx, uint8_t *evt_id, uint8_t *payload, uint8_t *payload_size)
Radar get event function.
void radar_float_ieee_to_mchip(float *f_data)
Radar float ieee to mchip function.
uint8_t radar_get_gpio1_pin(radar_t *ctx)
Radar get gpio 1 pin function.
void radar_disable_device(radar_t *ctx)
Radar disable device function.
uint8_t radar_get_gpio0_pin(radar_t *ctx)
Radar get gpio 0 pin function.
radar_return_value_t
Radar Click return value data.
Definition radar.h:219
@ RADAR_ERROR
Definition radar.h:221
@ RADAR_OK
Definition radar.h:220
Radar Click configuration object.
Definition radar.h:194
uint32_t baud_rate
Definition radar.h:206
pin_name_t gp0
Definition radar.h:203
pin_name_t gp2
Definition radar.h:201
bool uart_blocking
Definition radar.h:207
uart_data_bits_t data_bit
Definition radar.h:208
pin_name_t tx_pin
Definition radar.h:197
pin_name_t rx_pin
Definition radar.h:196
uart_stop_bits_t stop_bit
Definition radar.h:210
pin_name_t gp1
Definition radar.h:202
uart_parity_t parity_bit
Definition radar.h:209
pin_name_t rst
Definition radar.h:200
Radar Click context object.
Definition radar.h:171
digital_in_t gp1
Definition radar.h:177
digital_in_t gp2
Definition radar.h:176
uart_t uart
Definition radar.h:181
digital_in_t gp0
Definition radar.h:178
digital_out_t rst
Definition radar.h:173
Radar Click float bytes type object.
Definition radar.h:160
float f_data
Definition radar.h:162