Go to the documentation of this file.
26 #define SENSOR_ID (1U)
27 #define SENSOR_TIMEOUT_MS (10000U)
51 #define UART_LOG_BUFFER_SIZE 100
155 static void uart_log(
const char *format, ...);
248 float peak_distance = 0.0f;
255 return peak_distance;
260 float peak_strength = 0.0f;
267 return peak_strength;
303 bool setup_status =
true;
305 printf(
"I2C Distance Detector\n");
316 printf(
"ERROR: acc_rss_hal_register() failed\n\n");
318 setup_status =
false;
335 printf(
"ERROR: acc_detector_distance_config_create() failed\n\n");
336 setup_status =
false;
370 uart_log(
"Enter low power state\n");
443 bool do_apply_config =
false;
444 bool do_calibrate =
false;
445 bool do_recalibrate =
false;
452 do_apply_config =
true;
466 do_recalibrate =
true;
473 do_apply_config =
true;
493 printf(
"ERROR: Could not get next result\n");
511 printf(
"ERROR: Unknown command: %" PRIu32
"", command);
521 if (do_calibrate || do_recalibrate)
538 uart_log(
"Detector Status = 0x%" PRIx32
"\n", temp_detector_status);
551 uart_log(
"Detector Status = 0x%" PRIx32
"\n", temp_detector_status);
574 if (resources->
sensor != NULL)
582 printf(
"ERROR: acc_sensor_create() failed\n");
591 if (resources->
handle != NULL)
599 printf(
"ERROR: acc_detector_distance_create() failed\n");
613 printf(
"ERROR: acc_detector_distance_get_sizes() failed\n");
621 if (resources->
buffer != NULL)
629 printf(
"ERROR: sensor buffer allocation failed\n");
645 printf(
"ERROR: calibration buffer allocation failed\n");
656 printf(
"ERROR: apply detector config failed\n");
669 bool cal_complete =
false;
693 printf(
"ERROR: acc_sensor_calibrate() failed\n");
712 if (update_calibration)
752 if (update_calibration)
754 printf(
"ERROR: acc_detector_distance_update_calibration() failed\n");
758 printf(
"ERROR: acc_detector_distance_calibrate() failed\n");
776 bool result_available =
false;
790 printf(
"ERROR: acc_detector_distance_prepare() failed\n");
797 printf(
"ERROR: acc_sensor_measure() failed\n");
804 printf(
"ERROR: Sensor interrupt timeout\n");
811 printf(
"ERROR: acc_sensor_read() failed\n");
823 printf(
"ERROR: acc_detector_distance_process() failed\n");
827 }
while (!result_available);
838 if (
result->num_distances > 0)
841 for (uint8_t i = 0; i <
result->num_distances; i++)
843 uint32_t distance_mm = (uint32_t)(1000 *
result->distances[i]);
844 uart_log(
"%" PRIu32
"mm, ", distance_mm);
857 va_start(ap, format);
static void uart_log(const char *format,...)
UART logging function (can be enabled/disabled by command)
bool acc_detector_distance_get_sizes(const acc_detector_distance_handle_t *handle, uint32_t *buffer_size, uint32_t *detector_cal_result_static_size)
Get the memory size needed to use the Distance Detector API functions.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
void i2c_distance_detector_measure_on_wakeup(bool enable)
Enable/Disable measure on wake up.
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
static uint32_t i2c_detector_status
uint32_t detector_cal_result_static_size
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
#define UART_LOG_BUFFER_SIZE
void i2c_application_system_reset(void)
Reset the system.
static uint32_t get_command(void)
Get the i2c_detector_command values.
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_NEAR_START_EDGE_MASK
static uint32_t i2c_detector_command
uint32_t i2c_distance_detector_get_status(void)
Get distance detector status.
acc_detector_distance_result_t result
bool i2c_distance_detector_get_measure_on_wakeup(void)
Get measure on wake up state.
The result from a completed calibration.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_OK_MASK
int acconeer_main(int argc, char *argv[])
Assembly test example.
void acc_integration_critical_section_exit(void)
#define DISTANCE_REG_COMMAND_ENUM_MEASURE_DISTANCE
acc_cal_result_t sensor_cal_result
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
acc_detector_distance_handle_t * acc_detector_distance_create(const acc_detector_distance_config_t *config)
Create Distance Detector handle using the provided Distance Detector configuration.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
static void detector_status_set_bits(uint32_t bit_mask)
Set bits in the i2c_detector_status.
static bool detector_get_next(distance_detector_resources_t *resources)
Get next distance measurement.
bool acc_detector_distance_calibrate(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, uint8_t *detector_cal_result_static, uint32_t detector_cal_result_static_size, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *calibration_complete)
Calibrate detector.
acc_detector_cal_result_dynamic_t detector_cal_result_dynamic
bool acc_detector_distance_process(acc_detector_distance_handle_t *handle, void *buffer, uint8_t *detector_cal_result_static, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *result_available, acc_detector_distance_result_t *result)
Process sensor data into a Detector result.
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
#define DISTANCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
void distance_reg_protocol_write_default(void)
void i2c_application_system_wait_for_interrupt(void)
Wait for interrupt to occur.
static bool is_detector_ready(void)
Test if detector is ready.
uint32_t i2c_distance_detector_get_result(void)
Get distance detector result.
The result from a completed calibration update.
uint8_t * detector_cal_result_static
static void detector_status_clr_bits(uint32_t bit_mask)
Clear bits in the i2c_detector_status.
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_TEMPERATURE_POS
static bool measure_distance_error
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
uint32_t i2c_distance_detector_get_counter(void)
Get distance detector measure counter.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK
static distance_detector_resources_t detector_resources
const char * acc_version_get(void)
Get the version of the Acconeer software.
static void create_sensor(distance_detector_resources_t *resources)
Create sensor.
void i2c_application_enter_low_power_state(void)
Make the MCU enter its low power state.
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
#define DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIG_AND_CALIBRATE
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_POS
void acc_detector_distance_config_log(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config)
Log Distance configuration, typically through printf.
static bool detector_status_test_bits(uint32_t bit_mask)
Test bits in the i2c_detector_status.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
bool acc_detector_distance_prepare(const acc_detector_distance_handle_t *handle, const acc_detector_distance_config_t *config, acc_sensor_t *sensor, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size)
Prepare the Detector for measurements.
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_NUM_DISTANCES_MASK
Distance Detector result returned from acc_detector_distance_process.
#define DISTANCE_REG_COMMAND_ENUM_RECALIBRATE
void distance_reg_protocol_setup(void)
void i2c_application_system_set_ready_pin(bool enable)
Set the ready pin state.
acc_detector_distance_config_t * config
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
struct acc_detector_distance_handle acc_detector_distance_handle_t
Distance Detector handle.
#define DISTANCE_REG_COMMAND_ENUM_CALIBRATE
void i2c_application_system_init(void)
Init the system.
float i2c_distance_detector_get_peak_distance(uint16_t peak_id)
Get the peak distance for a specific peak id.
static bool measure_on_wakeup
float i2c_distance_detector_get_peak_strength(uint16_t peak_id)
Get the peak strength for a specific peak id.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
bool acc_detector_distance_update_calibration(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, acc_detector_cal_result_dynamic_t *detector_cal_result_dynamic, bool *calibration_complete)
Perform a subset of the full Detector calibration.
#define DISTANCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
bool near_start_edge_status
static void command_handler(uint32_t command)
Execute the command sent from the host.
#define ACC_DETECTOR_DISTANCE_RESULT_MAX_NUM_DISTANCES
The maximum number of estimated distances that is returned in the Detector result.
#define DISTANCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
#define DISTANCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
#define DISTANCE_REG_COMMAND_ENUM_RESET_MODULE
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_ERROR_MASK
static void apply_detector_config(distance_detector_resources_t *resources)
Apply detector config.
static uint32_t measure_distance_counter
void acc_integration_critical_section_enter(void)
bool i2c_distance_detector_command(uint32_t command)
Send command to be executed to i2c distance detector.
acc_detector_distance_config_t * acc_detector_distance_config_create(void)
Create a Distance Detector configuration.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_ERROR_MASK
#define SENSOR_TIMEOUT_MS
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_CALIBRATION_BUFFER_OK_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK
bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Calibrate a sensor.
static void calibrate_sensor(distance_detector_resources_t *resources)
Calibrate sensor.
acc_detector_distance_handle_t * handle
acc_detector_distance_config_t * i2c_distance_detector_get_config(void)
Get distance detector configuration handle.
struct acc_detector_distance_config acc_detector_distance_config_t
Distance Detector configuration.
static void calibrate_detector(distance_detector_resources_t *resources, bool update_calibration)
Calibrate detector.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_MEASURE_DISTANCE_ERROR_MASK
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
bool i2c_application_system_test_wakeup_pin(void)
Check if wakeup pin is high.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CALIBRATE_ERROR_MASK
struct acc_sensor acc_sensor_t
static void print_distance_result(const acc_detector_distance_result_t *result)
Print the distance detector result.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
#define DISTANCE_REG_DISTANCE_RESULT_FIELD_CALIBRATION_NEEDED_MASK
static bool uart_logs_enabed
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.