Go to the documentation of this file.
26 #define SENSOR_ID (1U)
27 #define SENSOR_TIMEOUT_MS (1000U)
55 #define UART_LOG_BUFFER_SIZE 100
193 static void uart_log(
const char *format, ...);
368 bool setup_status =
true;
369 bool get_next_frame =
false;
371 printf(
"I2C Presence Detector\n");
382 printf(
"ERROR: acc_rss_hal_register() failed\n\n");
385 setup_status =
false;
402 printf(
"ERROR: acc_detector_presence_config_create() failed\n\n");
403 setup_status =
false;
428 get_next_frame =
false;
435 printf(
"ERROR: Could not get next result\n");
528 printf(
"ERROR: Could not start detector\n");
544 printf(
"ERROR: Could not stop detector\n");
564 printf(
"ERROR: Unknown command: %" PRIu32
"", command);
580 uart_log(
"Detector Status = 0x%" PRIx32
"\n", temp_detector_status);
594 uart_log(
"Detector Status = 0x%" PRIx32
"\n", temp_detector_status);
619 if (resources->
sensor != NULL)
629 printf(
"ERROR: acc_sensor_create() failed\n");
644 bool cal_complete =
false;
662 printf(
"ERROR: acc_sensor_calibrate() failed\n");
682 if (resources->
handle != NULL)
692 printf(
"ERROR: acc_detector_presence_create() failed\n");
708 printf(
"ERROR: acc_detector_presence_get_buffer_size() failed\n");
716 if (resources->
buffer != NULL)
726 printf(
"ERROR: sensor buffer allocation failed\n");
742 printf(
"ERROR: apply detector config failed\n");
757 uart_log(
"Start presence detector\n");
768 printf(
"ERROR: acc_detector_presence_prepare() failed\n");
784 uart_log(
"Stop presence detector\n");
807 printf(
"ERROR: acc_sensor_measure() failed\n");
816 printf(
"ERROR: Sensor interrupt timeout\n");
827 printf(
"ERROR: acc_sensor_read() failed\n");
844 printf(
"ERROR: acc_detector_presence_process() failed\n");
939 uart_log(
"Enter low power state\n");
958 printf(
"ERROR: acc_sensor_hibernate_on failed\n");
974 printf(
"ERROR: acc_sensor_hibernate_off failed\n");
988 uart_log(
"(%" PRIu32
"mm)\n", distance_mm);
1003 va_start(ap, format);
1017 printf(
"%s", log_buffer);
float inter_presence_score
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_ERROR_MASK
static void uart_log(const char *format,...)
UART logging function (can be enabled/disabled by command)
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_DETECTOR_ERROR_MASK
static float inter_presence_score
#define PRESENCE_REG_COMMAND_ENUM_ENABLE_UART_LOGS
bool acc_detector_presence_prepare(acc_detector_presence_handle_t *presence_handle, acc_detector_presence_config_t *presence_config, acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Prepare the detector to do a measurement.
uint32_t i2c_presence_detector_get_counter(void)
Get presence detector measure counter.
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
void i2c_application_system_set_generic_gpio_pin(bool enable)
Set the generic gpio pin output state.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_OK_MASK
void acc_detector_presence_config_log(const acc_detector_presence_config_t *presence_config)
Print a configuration to the log.
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_OK_MASK
void i2c_application_system_reset(void)
Reset the system.
static float presence_distance
#define SENSOR_TIMEOUT_MS
acc_processing_result_t processing_result
#define PRESENCE_REG_COMMAND_ENUM_APPLY_CONFIGURATION
void acc_integration_critical_section_exit(void)
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_ERROR_MASK
static uint32_t get_command(void)
Get the i2c_detector_command values.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_OK_MASK
static void detector_gpio_output(void)
Handle detector GPIO output.
uint32_t i2c_presence_detector_get_status(void)
Get presence detector status.
static bool presence_detected
static bool presence_detection_gpio
uint32_t i2c_presence_detector_get_result(void)
Get presence detector result.
bool acc_detector_presence_get_buffer_size(const acc_detector_presence_handle_t *presence_handle, uint32_t *buffer_size)
Get the buffer size needed for the provided presence detector handle.
#define PRESENCE_REG_COMMAND_ENUM_RESET_MODULE
static uint32_t i2c_detector_command
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
#define PRESENCE_REG_COMMAND_ENUM_STOP_DETECTOR
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
static void print_presence_result(acc_detector_presence_result_t *result)
Print the presence detector result.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_CREATE_OK_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_BUSY_MASK
void i2c_application_system_wait_for_interrupt(void)
Wait for interrupt to occur.
Presence detector results container.
static bool detector_get_next(presence_detector_resources_t *resources)
Get next presence measurement.
static bool detector_activate(presence_detector_resources_t *resources, bool enable)
Activate detector.
#define PRESENCE_REG_COMMAND_ENUM_START_DETECTOR
static bool uart_logs_enabed
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_CREATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_OK_MASK
#define PRESENCE_REG_COMMAND_ENUM_DISABLE_UART_LOGS
acc_cal_result_t sensor_cal_result
static bool calibrate_sensor(presence_detector_resources_t *resources)
Calibrate sensor.
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
void i2c_presence_detector_presence_detected_gpio(bool enable)
Enable/Disable gpio output for presence detected.
float i2c_presence_detector_get_distance(void)
Get presence detector distance.
static bool exit_hibernate(acc_sensor_t *sensor)
Exit sensor hibernation state.
bool acc_sensor_hibernate_off(const acc_sensor_t *sensor)
Restore sensor after exiting hibernation.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_OK_MASK
const char * acc_version_get(void)
Get the version of the Acconeer software.
float intra_presence_score
acc_detector_presence_handle_t * handle
static bool detector_status_test_bits(uint32_t bit_mask)
Test bits in the i2c_detector_status.
bool i2c_presence_detector_command(uint32_t command)
Send command to be executed to i2c presence detector.
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.
void acc_detector_presence_config_inter_frame_idle_state_set(acc_detector_presence_config_t *presence_config, acc_config_idle_state_t idle_state)
Set inter frame idle state.
static void command_handler(uint32_t command)
Execute the command sent from the host.
static presence_detector_resources_t detector_resources
acc_detector_presence_config_t * config
bool acc_detector_presence_process(acc_detector_presence_handle_t *presence_handle, void *buffer, acc_detector_presence_result_t *result)
Process the data according to the configuration used in acc_detector_presence_config_create.
static void detector_status_set_bits(uint32_t bit_mask)
Set bits in the i2c_detector_status.
#define UART_LOG_BUFFER_SIZE
static uint32_t presence_frame_counter
static void apply_detector_config(presence_detector_resources_t *resources)
Apply detector config.
@ ACC_CONFIG_IDLE_STATE_DEEP_SLEEP
void i2c_application_system_setup_generic_gpio_pin(bool enable)
Setup the generic gpio pin.
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_MASK
static bool enter_hibernate(acc_sensor_t *sensor)
Enter sensor hibernation state.
void i2c_application_system_set_ready_pin(bool enable)
Set the ready pin state.
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_PRESENCE_DETECTED_STICKY_MASK
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_OK_MASK
struct acc_detector_presence_config acc_detector_presence_config_t
void presence_reg_protocol_write_default(void)
static float intra_presence_score
void i2c_application_set_periodic_wakeup(uint32_t period_ms)
Set up a periodic timer used to wake up the system from sleep.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_OK_MASK
bool acc_sensor_hibernate_on(acc_sensor_t *sensor)
Prepare sensor for entering hibernation.
void i2c_application_system_init(void)
Init the system.
static bool presence_detector_error
static bool presence_detected_sticky
bool i2c_application_is_periodic_wakeup(void)
Test if a periodic wake up has occurred.
int acconeer_main(int argc, char *argv[])
Assembly test example.
float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config)
Get the frame rate.
float i2c_presence_detector_get_intra_presence_score(void)
Get intra presence score.
float i2c_presence_detector_get_inter_presence_score(void)
Get inter presence score.
acc_detector_presence_metadata_t metadata
static bool presence_detector_active
void acc_integration_critical_section_enter(void)
acc_detector_presence_config_t * i2c_presence_detector_get_config(void)
Get presence detector configuration handle.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_CONFIG_APPLY_ERROR_MASK
acc_detector_presence_handle_t * acc_detector_presence_create(acc_detector_presence_config_t *presence_config, acc_detector_presence_metadata_t *metadata)
Create a presence detector with the provided configuration.
static void module_low_power(void)
Try to set module in low power mode.
acc_detector_presence_result_t result
bool i2c_presence_detector_get_presence_detected_gpio(void)
Get gpio output for presence detected state.
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_POS
static void detector_status_clr_bits(uint32_t bit_mask)
Clear bits in the i2c_detector_status.
#define PRESENCE_REG_COMMAND_ENUM_LOG_CONFIGURATION
struct acc_detector_presence_handle acc_detector_presence_handle_t
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.
acc_detector_presence_config_t * acc_detector_presence_config_create(void)
Create a configuration for a presence detector.
#define PRESENCE_REG_PRESENCE_RESULT_FIELD_TEMPERATURE_MASK
static void create_sensor(presence_detector_resources_t *resources)
Create sensor.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CREATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_CALIBRATE_ERROR_MASK
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_SENSOR_BUFFER_ERROR_MASK
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
static uint32_t i2c_detector_status
bool i2c_application_system_test_wakeup_pin(void)
Check if wakeup pin is high.
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_DETECTOR_BUFFER_ERROR_MASK
struct acc_sensor acc_sensor_t
void presence_reg_protocol_setup(void)
#define PRESENCE_REG_DETECTOR_STATUS_FIELD_RSS_REGISTER_ERROR_MASK
void acc_detector_presence_config_frame_rate_app_driven_set(acc_detector_presence_config_t *presence_config, bool enable)
Set if the application should maintain the requested frame rate.
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.