Go to the documentation of this file.
26 #define SENSOR_ID (1U)
27 #define SENSOR_TIMEOUT_MS (1000U)
50 #define UART_LOG_BUFFER_SIZE 100
166 static void uart_log(
const char *format, ...);
266 float peak_distance = 0.0f;
273 return peak_distance;
279 float peak_strength = 0.0f;
286 return peak_strength;
327 bool setup_status =
true;
329 printf(
"I2C Distance Detector\n");
340 printf(
"ERROR: acc_rss_hal_register() failed\n\n");
343 setup_status =
false;
360 printf(
"ERROR: acc_detector_distance_config_create() failed\n\n");
361 setup_status =
false;
394 uart_log(
"Enter low power state\n");
470 bool do_apply_config =
false;
471 bool do_calibrate =
false;
472 bool do_recalibrate =
false;
479 do_apply_config =
true;
493 do_recalibrate =
true;
500 do_apply_config =
true;
520 printf(
"ERROR: Could not get next result\n");
538 printf(
"ERROR: Unknown command: %" PRIu32
"", command);
548 if (do_calibrate || do_recalibrate)
566 uart_log(
"Detector Status = 0x%" PRIx32
"\n", temp_detector_status);
580 uart_log(
"Detector Status = 0x%" PRIx32
"\n", temp_detector_status);
605 if (resources->
sensor != NULL)
615 printf(
"ERROR: acc_sensor_create() failed\n");
625 if (resources->
handle != NULL)
635 printf(
"ERROR: acc_detector_distance_create() failed\n");
651 printf(
"ERROR: acc_detector_distance_get_buffer_sizes() failed\n");
659 if (resources->
buffer != NULL)
669 printf(
"ERROR: sensor buffer allocation failed\n");
687 printf(
"ERROR: calibration buffer allocation failed\n");
698 printf(
"ERROR: apply detector config failed\n");
717 bool cal_complete =
false;
735 printf(
"ERROR: acc_sensor_calibrate() failed\n");
789 printf(
"ERROR: acc_detector_distance_recalibrate() failed\n");
793 printf(
"ERROR: acc_detector_distance_calibrate() failed\n");
815 bool result_available =
false;
829 printf(
"ERROR: acc_detector_distance_prepare() failed\n");
836 printf(
"ERROR: acc_sensor_measure() failed\n");
843 printf(
"ERROR: Sensor interrupt timeout\n");
852 printf(
"ERROR: acc_sensor_read() failed\n");
863 printf(
"ERROR: acc_detector_distance_process() failed\n");
867 }
while (!result_available);
884 uint32_t distance_mm = (uint32_t)(1000 * result->
distances[i]);
885 uart_log(
"%" PRIu32
"mm, ", distance_mm);
899 va_start(ap, format);
static void uart_log(const char *format,...)
UART logging function (can be enabled/disabled by command)
#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
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 void calibrate_detector(distance_detector_resources_t *resources, bool recalibrate)
Calibrate detector.
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.
#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
bool acc_detector_distance_get_buffer_sizes(const acc_detector_distance_handle_t *handle, uint32_t *buffer_size, uint32_t *calibration_buffer_size)
Get the buffer sizes needed given the provided detector handle.
#define DISTANCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
bool acc_detector_distance_recalibrate(acc_sensor_t *sensor, acc_detector_distance_handle_t *handle, const acc_cal_result_t *sensor_cal_result, void *buffer, uint32_t buffer_size, void *calibration_buffer, uint32_t calibration_buffer_size, bool *calibration_complete)
Do a detector recalibration.
acc_detector_distance_handle_t * acc_detector_distance_create(const acc_detector_distance_config_t *config)
Create a distance detector with the provided 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_process(acc_detector_distance_handle_t *handle, void *buffer, void *calibration_buffer, bool *result_available, acc_detector_distance_result_t *result)
Process the data according to the configuration used in acc_detector_distance_config_create.
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
#define DISTANCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
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, void *calibration_buffer, uint32_t calibration_buffer_size, bool *calibration_complete)
Do a detector calibration.
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.
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.
void * calibration_buffer
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)
Print a configuration to the log.
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.
#define DISTANCE_REG_COMMAND_ENUM_RECALIBRATE
uint32_t calibration_buffer_size
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.
bool sensor_calibration_needed
struct acc_detector_distance_handle acc_detector_distance_handle_t
#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
#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
#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 configuration for a distance detector.
#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
#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.