43#define CHIP_NAME "JieShenna HCSR04"
44#define MANUFACTURER_NAME "JieShenna"
45#define SUPPLY_VOLTAGE_MIN 4.8f
46#define SUPPLY_VOLTAGE_MAX 5.0f
47#define MAX_CURRENT 15.0f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 85.0f
50#define DRIVER_VERSION 2000
74 handle->
debug_print(
"hcsr04: trig_init is null.\n");
80 handle->
debug_print(
"hcsr04: trig_deinit is null.\n");
86 handle->
debug_print(
"hcsr04: trig_write is null.\n");
92 handle->
debug_print(
"hcsr04: echo_init is null.\n");
98 handle->
debug_print(
"hcsr04: echo_deinit is null.\n");
104 handle->
debug_print(
"hcsr04: echo_read is null.\n");
110 handle->
debug_print(
"hcsr04: delay_us is null.\n");
116 handle->
debug_print(
"hcsr04: delay_ms is null.\n");
122 handle->
debug_print(
"hcsr04: timestamp_read is null.\n");
129 handle->
debug_print(
"hcsr04: trig init failed.\n");
168 handle->
debug_print(
"hcsr04: echo deinit failed.\n");
174 handle->
debug_print(
"hcsr04: trig deinit failed.\n");
217 handle->
debug_print(
"hcsr04: trig write failed.\n");
225 handle->
debug_print(
"hcsr04: trig write failed.\n");
230 timeout = 1000 * 5000;
233 res = handle->
echo_read((uint8_t *)&value);
236 handle->
debug_print(
"hcsr04: echo read failed.\n");
252 handle->
debug_print(
"hcsr04: read timestamp failed.\n");
257 timeout = 1000 * 5000;
260 res = handle->
echo_read((uint8_t *)&value);
263 handle->
debug_print(
"hcsr04: echo read failed.\n");
279 handle->
debug_print(
"hcsr04: read timestamp failed.\n");
285 handle->
debug_print(
"hcsr04: millisecond timestamp invalid.\n");
289 *time_us = (uint32_t)((int64_t)(((int64_t)time_stop.
millisecond -
293 if ((*time_us) > 150 * 1000)
298 handle->
delay_ms(150 + rand() % 100);
302 handle->
debug_print(
"hcsr04: no remain retry times.\n");
312 *m = 340.0f / 2.0f * (float)(*time_us) / 1000000.0f;
#define SUPPLY_VOLTAGE_MAX
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define CHIP_NAME
chip information definition
driver hcsr04 header file
uint8_t hcsr04_init(hcsr04_handle_t *handle)
initialize the chip
struct hcsr04_handle_s hcsr04_handle_t
hcsr04 handle structure definition
#define HCSR04_READ_RETRY_TIMES
hcsr04 read retry times definition
uint8_t hcsr04_read(hcsr04_handle_t *handle, uint32_t *time_us, float *m)
read the distance
uint8_t hcsr04_info(hcsr04_info_t *info)
get chip's information
uint8_t hcsr04_deinit(hcsr04_handle_t *handle)
close the chip
struct hcsr04_time_s hcsr04_time_t
hcsr04 time structure definition
struct hcsr04_info_s hcsr04_info_t
hcsr04 information structure definition
void(* delay_ms)(uint32_t ms)
uint8_t(* echo_read)(uint8_t *value)
void(* delay_us)(uint32_t ms)
uint8_t(* echo_deinit)(void)
void(* debug_print)(const char *const fmt,...)
uint8_t(* trig_write)(uint8_t value)
uint8_t(* trig_deinit)(void)
uint8_t(* trig_init)(void)
uint8_t(* timestamp_read)(hcsr04_time_t *time)
uint8_t(* echo_init)(void)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v