speedradar 2.1.0.0
speedradar.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 SPEEDRADAR_H
29#define SPEEDRADAR_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 SPEEDRADAR_CMD_PREFIX "$"
74#define SPEEDRADAR_CMD_ENTER "\r\n"
75#define SPEEDRADAR_CMD_RSP_PREFIX_VAL 0x40
76#define SPEEDRADAR_ASCII_CHAR_0 48
77#define SPEEDRADAR_NO_DET 0
78#define SPEEDRADAR_MLP_TENS 10
79#define SPEEDRADAR_MLP_HUNDREDS 100
80
86#define SPEEDRADAR_CMD_SAMPLING_RATE "S04"
87#define SPEEDRADAR_CMD_START_UP_LEARN "S05"
88#define SPEEDRADAR_CMD_FUN_MISC_OUT "S06"
89#define SPEEDRADAR_CMD_THOLD_OFFSET_MIN "S07"
90#define SPEEDRADAR_CMD_THOLD_OFFSET_MAX "S08"
91#define SPEEDRADAR_CMD_THOLD_NOISE "S09"
92#define SPEEDRADAR_CMD_FFT_AVERAGE "S0A"
93#define SPEEDRADAR_CMD_SENS_POT "S0B"
94#define SPEEDRADAR_CMD_HOLD_TIME_POT "S0C"
95#define SPEEDRADAR_CMD_MICRO_DETECTION "S0D"
96
102#define SPEEDRADAR_CMD_HOLD_TIME "D00"
103#define SPEEDRADAR_CMD_SENSITIVITY "D01"
104#define SPEEDRADAR_CMD_IMMUNITY "D02"
105#define SPEEDRADAR_CMD_DIR_DETECT "D03"
106#define SPEEDRADAR_CMD_SPEED_LIM_LOW "D04"
107#define SPEEDRADAR_CMD_SPEED_LIM_HIGH "D05"
108#define SPEEDRADAR_CMD_THOLD_SPEED_RANGE "D06"
109#define SPEEDRADAR_CMD_THOLD_MICRO_DET "D07"
110#define SPEEDRADAR_CMD_FFT_FILTER_WIDTH "D08"
111
117#define SPEEDRADAR_CMD_HOLD_TIME_0 "A00"
118#define SPEEDRADAR_CMD_HOLD_TIME_1 "A01"
119#define SPEEDRADAR_CMD_HOLD_TIME_2 "A02"
120#define SPEEDRADAR_CMD_HOLD_TIME_3 "A03"
121#define SPEEDRADAR_CMD_HOLD_TIME_4 "A04"
122#define SPEEDRADAR_CMD_HOLD_TIME_5 "A05"
123#define SPEEDRADAR_CMD_HOLD_TIME_6 "A06"
124#define SPEEDRADAR_CMD_HOLD_TIME_7 "A07"
125#define SPEEDRADAR_CMD_HOLD_TIME_8 "A08"
126#define SPEEDRADAR_CMD_HOLD_TIME_9 "A09"
127#define SPEEDRADAR_CMD_HOLD_TIME_10 "A10"
128#define SPEEDRADAR_CMD_HOLD_TIME_11 "A11"
129#define SPEEDRADAR_CMD_HOLD_TIME_12 "A12"
130#define SPEEDRADAR_CMD_HOLD_TIME_13 "A13"
131#define SPEEDRADAR_CMD_HOLD_TIME_14 "A14"
132#define SPEEDRADAR_CMD_HOLD_TIME_15 "A15"
133#define SPEEDRADAR_CMD_HOLD_TIME_16 "A16"
134#define SPEEDRADAR_CMD_HOLD_TIME_17 "A17"
135#define SPEEDRADAR_CMD_HOLD_TIME_18 "A18"
136#define SPEEDRADAR_CMD_HOLD_TIME_19 "A19"
137#define SPEEDRADAR_CMD_HOLD_TIME_20 "A20"
138#define SPEEDRADAR_CMD_HOLD_TIME_21 "A21"
139#define SPEEDRADAR_CMD_HOLD_TIME_22 "A22"
140#define SPEEDRADAR_CMD_HOLD_TIME_23 "A23"
141#define SPEEDRADAR_CMD_HOLD_TIME_24 "A24"
142#define SPEEDRADAR_CMD_HOLD_TIME_25 "A25"
143#define SPEEDRADAR_CMD_HOLD_TIME_26 "A26"
144#define SPEEDRADAR_CMD_HOLD_TIME_27 "A27"
145#define SPEEDRADAR_CMD_HOLD_TIME_28 "A28"
146#define SPEEDRADAR_CMD_HOLD_TIME_29 "A29"
147
153#define SPEEDRADAR_CMD_GET_SW_VERSION "F00"
154#define SPEEDRADAR_CMD_GET_TYPE_OF_DEVICE "F01"
155
161#define SPEEDRADAR_CMD_GET_DET_REG "R00"
162#define SPEEDRADAR_CMD_GET_DET_SPEED "R01"
163#define SPEEDRADAR_CMD_GET_DET_MAG "R02"
164#define SPEEDRADAR_CMD_GET_NOISE_LVL "R03"
165#define SPEEDRADAR_CMD_GET_OP_STATE "R04"
166#define SPEEDRADAR_CMD_GET_H_TIME_POT_IDX "R05"
167#define SPEEDRADAR_CMD_GET_SENS_POT_IDX "R06"
168
174#define SPEEDRADAR_CMD_RESET_PROCESSOR "W00"
175#define SPEEDRADAR_CMD_RST_FAC_STG "W01"
176#define SPEEDRADAR_CMD_SET_UART_BAUD_RATE "W02"
177
183#define SPEEDRADAR_CMD_GET_DETECTION_STR "C00"
184#define SPEEDRADAR_CMD_GET_TARGET_STR "C01"
185#define SPEEDRADAR_CMD_GET_EEPROM "C02"
186#define SPEEDRADAR_CMD_GET_FFT_SPECTRUM "C03"
187#define SPEEDRADAR_CMD_GET_ADC_IQ "C04"
188#define SPEEDRADAR_CMD_GET_ADC_IQ_ADD_PARAM "C05"
189#define SPEEDRADAR_CMD_GET_ALL_DATA "C06"
190
196#define SPEEDRADAR_CMD_ACT_TEST_MODE "T00"
197#define SPEEDRADAR_CMD_FORCE_DET_OUT "T01"
198#define SPEEDRADAR_CMD_FORCE_MISC_OUT "T02"
199
204#define SPEEDRADAR_SET_SAMPLING_RATE_X1 "01"
205#define SPEEDRADAR_SET_SAMPLING_RATE_X2 "02"
206#define SPEEDRADAR_SET_SAMPLING_RATE_X3 "03"
207#define SPEEDRADAR_SET_SAMPLING_RATE_X4 "04"
208#define SPEEDRADAR_SET_SAMPLING_RATE_X5 "05"
209#define SPEEDRADAR_SET_SAMPLING_RATE_X6 "06"
210#define SPEEDRADAR_SET_SAMPLING_RATE_X7 "07"
211#define SPEEDRADAR_SET_SAMPLING_RATE_X8 "08"
212#define SPEEDRADAR_SET_SAMPLING_RATE_X9 "09"
213#define SPEEDRADAR_SET_SAMPLING_RATE_X10 "0A"
214
219#define SPEEDRADAR_SAMPLING_RATE_1280_HZ 1280.0f
220#define SPEEDRADAR_SAMPLING_RATE_2560_HZ 2560.0f
221#define SPEEDRADAR_SAMPLING_RATE_3840_HZ 3840.0f
222#define SPEEDRADAR_SAMPLING_RATE_5120_HZ 5120.0f
223#define SPEEDRADAR_SAMPLING_RATE_6400_HZ 6400.0f
224#define SPEEDRADAR_SAMPLING_RATE_7680_HZ 7680.0f
225#define SPEEDRADAR_SAMPLING_RATE_8960_HZ 8960.0f
226#define SPEEDRADAR_SAMPLING_RATE_10240_HZ 10240.0f
227#define SPEEDRADAR_SAMPLING_RATE_11520_HZ 11520.0f
228#define SPEEDRADAR_SAMPLING_RATE_12800_HZ 12800.0f
229
234#define SPEEDRADAR_SET_MISC_OUT_DET "00"
235#define SPEEDRADAR_SET_MISC_OUT_DIR "01"
236#define SPEEDRADAR_SET_MISC_OUT_RNG "02"
237#define SPEEDRADAR_SET_MISC_OUT_MDET "03"
238
243#define SPEEDRADAR_R00_DET_NO 0x00
244#define SPEEDRADAR_R00_DET_VALID 0x01
245#define SPEEDRADAR_R00_DIR_BACKWARD 0x00
246#define SPEEDRADAR_R00_DIR_FORWARD 0x02
247#define SPEEDRADAR_R00_RANGE_LOW_SPEED 0x00
248#define SPEEDRADAR_R00_RANGE_HIGH_SPEED 0x04
249#define SPEEDRADAR_R00_MICRO_DET_NO 0x00
250#define SPEEDRADAR_R00_MICRO_DET_VALID 0x08
251
256#define SPEEDRADAR_ERR_MSG "@E0"
257#define SPEEDRADAR_ERR_VAL_OUT_LIM "@E01"
258#define SPEEDRADAR_ERR_PAR_NUM_NOT_EXIST "@E02"
259#define SPEEDRADAR_ERR_CMD_NOT_EXIST "@E03"
260#define SPEEDRADAR_ERR_WR_EEPROM "@E04"
261#define SPEEDRADAR_ERR_CMD_FORMAT "@E05"
262#define SPEEDRADAR_ERR_UART_COMM "@E06"
263
269#define SPEEDRADAR_TX_DRV_BUFFER_SIZE 100
270#define SPEEDRADAR_RX_DRV_BUFFER_SIZE 200
271
272 // speedradar_cmd
273
288#define SPEEDRADAR_MAP_MIKROBUS( cfg, mikrobus ) \
289 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
290 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
291 cfg.dir = MIKROBUS( mikrobus, MIKROBUS_AN ); \
292 cfg.det = MIKROBUS( mikrobus, MIKROBUS_INT );
293
294 // speedradar_map
295 // speedradar
296
301typedef struct
302{
303 // Input pins
304 digital_in_t dir;
305 digital_in_t det;
307 // Modules
308 uart_t uart;
310 // Buffers
311 uint8_t uart_rx_buffer[ SPEEDRADAR_RX_DRV_BUFFER_SIZE ];
312 uint8_t uart_tx_buffer[ SPEEDRADAR_TX_DRV_BUFFER_SIZE ];
315
320typedef struct
321{
322 // Communication gpio pins
323 pin_name_t rx_pin;
324 pin_name_t tx_pin;
326 // Additional gpio pins
327 pin_name_t dir;
328 pin_name_t det;
330 // Static variable
331 uint32_t baud_rate;
333 uart_data_bits_t data_bit;
334 uart_parity_t parity_bit;
335 uart_stop_bits_t stop_bit;
338
349
366
381
395
408err_t speedradar_generic_write ( speedradar_t *ctx, uint8_t *data_in, uint16_t len );
409
422err_t speedradar_generic_read ( speedradar_t *ctx, uint8_t *data_out, uint16_t len );
423
437err_t speedradar_send_command ( speedradar_t *ctx, uint8_t *cmd );
438
453err_t speedradar_send_command_value ( speedradar_t *ctx, uint8_t *cmd, uint8_t *cmd_value );
454
472
484
485#ifdef __cplusplus
486}
487#endif
488#endif // SPEEDRADAR_H
489
490 // speedradar
491
492// ------------------------------------------------------------------------ END
#define SPEEDRADAR_TX_DRV_BUFFER_SIZE
Speed Radar driver buffer size.
Definition speedradar.h:269
#define SPEEDRADAR_RX_DRV_BUFFER_SIZE
Definition speedradar.h:270
err_t speedradar_send_command_value(speedradar_t *ctx, uint8_t *cmd, uint8_t *cmd_value)
Speed Radar send command function.
uint8_t speedradar_get_direction(speedradar_t *ctx)
Speed Radar get direction function.
uint8_t speedradar_get_detection(speedradar_t *ctx)
Speed Radar get detection function.
err_t speedradar_generic_read(speedradar_t *ctx, uint8_t *data_out, uint16_t len)
Speed Radar data reading function.
err_t speedradar_send_command(speedradar_t *ctx, uint8_t *cmd)
Speed Radar send command function.
err_t speedradar_init(speedradar_t *ctx, speedradar_cfg_t *cfg)
Speed Radar initialization function.
err_t speedradar_generic_write(speedradar_t *ctx, uint8_t *data_in, uint16_t len)
Speed Radar data writing function.
void speedradar_cfg_setup(speedradar_cfg_t *cfg)
Speed Radar configuration object setup function.
err_t speedradar_default_cfg(speedradar_t *ctx)
Speed Radar default configuration function.
speedradar_return_value_t
Speed Radar Click return value data.
Definition speedradar.h:344
@ SPEEDRADAR_ERROR
Definition speedradar.h:346
@ SPEEDRADAR_OK
Definition speedradar.h:345
Speed Radar Click configuration object.
Definition speedradar.h:321
pin_name_t det
Definition speedradar.h:328
uint32_t baud_rate
Definition speedradar.h:331
bool uart_blocking
Definition speedradar.h:332
uart_data_bits_t data_bit
Definition speedradar.h:333
pin_name_t tx_pin
Definition speedradar.h:324
pin_name_t rx_pin
Definition speedradar.h:323
uart_stop_bits_t stop_bit
Definition speedradar.h:335
pin_name_t dir
Definition speedradar.h:327
uart_parity_t parity_bit
Definition speedradar.h:334
Speed Radar Click context object.
Definition speedradar.h:302
uart_t uart
Definition speedradar.h:308
digital_in_t dir
Definition speedradar.h:304
digital_in_t det
Definition speedradar.h:305