Data Structures | Macros | Functions | Variables
i2c_presence_detector.c File Reference
`#include <stdarg.h>`
`#include <stdbool.h>`
`#include <stdint.h>`
`#include <stdio.h>`
`#include <string.h>`
`#include "acc_definitions_a121.h"`
`#include "acc_detector_presence.h"`
`#include "acc_hal_definitions_a121.h"`
`#include "acc_hal_integration_a121.h"`
`#include "acc_integration.h"`
`#include "acc_rss_a121.h"`
`#include "acc_version.h"`
`#include "acc_reg_protocol.h"`
`#include "i2c_application_system.h"`
`#include "i2c_presence_detector.h"`
`#include "presence_reg_protocol.h"`

Go to the source code of this file.

## Data Structures
struct | presence_detector_resources_t

## Macros
#define | SENSOR_ID (1U)
#define | SENSOR_TIMEOUT_MS (10000U)
#define | UART_LOG_BUFFER_SIZE 100

## Functions
static uint32_t | get_command (void)
| Get the i2c_detector_command values. More...
static void | command_handler (uint32_t command)
| Execute the command sent from the host. More...
static void | detector_status_set_bits (uint32_t bit_mask)
| Set bits in the i2c_detector_status. More...
static void | detector_status_clr_bits (uint32_t bit_mask)
| Clear bits in the i2c_detector_status. More...
static bool | detector_status_test_bits (uint32_t bit_mask)
| Test bits in the i2c_detector_status. More...
static void | create_sensor (presence_detector_resources_t *resources)
| Create sensor. More...
static bool | calibrate_sensor (presence_detector_resources_t *resources)
| Calibrate sensor. More...
static void | apply_detector_config (presence_detector_resources_t *resources)
| Apply detector config. More...
static bool | detector_activate (presence_detector_resources_t *resources, bool enable)
| Activate detector. More...
static bool | detector_get_next (presence_detector_resources_t *resources)
| Get next presence measurement. More...
static void | detector_gpio_output (void)
| Handle detector GPIO output. More...
static void | module_low_power (void)
| Try to set module in low power mode. More...
static bool | enter_hibernate (acc_sensor_t *sensor)
| Enter sensor hibernation state. More...
static bool | exit_hibernate (acc_sensor_t *sensor)
| Exit sensor hibernation state. More...
static void | print_presence_result (acc_detector_presence_result_t *result)
| Print the presence detector result. More...
static void | uart_log (const char *format,...)
| UART logging function (can be enabled/disabled by command) More...
acc_detector_presence_config_t * | i2c_presence_detector_get_config (void)
| Get presence detector configuration handle. More...
bool | i2c_presence_detector_command (uint32_t command)
| Send command to be executed to i2c presence detector. More...
uint32_t | i2c_presence_detector_get_status (void)
| Get presence detector status. More...
uint32_t | i2c_presence_detector_get_result (void)
| Get presence detector result. More...
float | i2c_presence_detector_get_distance (void)
| Get presence detector distance. More...
float | i2c_presence_detector_get_intra_presence_score (void)
| Get intra presence score. More...
float | i2c_presence_detector_get_inter_presence_score (void)
| Get inter presence score. More...
uint32_t | i2c_presence_detector_get_counter (void)
| Get presence detector measure counter. More...
void | i2c_presence_detector_presence_detected_gpio (bool enable)
| Enable/Disable gpio output for presence detected. More...
bool | i2c_presence_detector_get_presence_detected_gpio (void)
| Get gpio output for presence detected state. More...
uint32_t | i2c_presence_detector_get_presence_frame_rate_mhz (void)
| Get the actual frame rate for the current presence detector configuration. More...
int | acconeer_main (int argc, char *argv[])
| Assembly test example. More...

## Variables
static presence_detector_resources_t | detector_resources = {0}
static uint32_t | i2c_detector_command = 0U
static uint32_t | i2c_detector_status = 0U
static bool | presence_detector_active = false
static bool | presence_detected = false
static bool | presence_detected_sticky = false
static bool | presence_detection_gpio = false
static bool | presence_detector_error = false
static float | presence_distance = 0.0f
static uint32_t | presence_frame_counter = 0U
static uint32_t | presence_last_tick_ms = 0U
static uint32_t | presence_frame_rate_mhz = 0U
static float | intra_presence_score = 0.0f
static float | inter_presence_score = 0.0f
static bool | uart_logs_enabed = false

## Macro Definition Documentation

## ◆ SENSOR_ID

#define SENSOR_ID (1U)

Definition at line 26 of file i2c_presence_detector.c.

## ◆ SENSOR_TIMEOUT_MS

#define SENSOR_TIMEOUT_MS (10000U)

Definition at line 27 of file i2c_presence_detector.c.

## ◆ UART_LOG_BUFFER_SIZE

#define UART_LOG_BUFFER_SIZE 100

Definition at line 57 of file i2c_presence_detector.c.

## Function Documentation

## ◆ acconeer_main()

int acconeer_main | ( | int | argc,
|  | char * | argv[]
| ) |  |

Assembly test example.

Touchless button application.

Tank level reference application.

Smart presence reference application.

Parking application.

Breathing example application.

Waste level application.

Vibration example.

Surface velocity example application.

Service subsweeps example.

Service multple configurations example.

Low power service example.

Service sensor calibration caching example.

Service example.

Processing subtract adaptive background example.

Processing static presence example.

Processing peak interpolation example.

Processing noncoherent mean example.

Processing coherent mean example.

Processing amplitude example.

hand motion application

Detector presence example with multiple configurations.

Low power detector presence example.

Detector presence example.

Detector distance example with iq data print.

Distance detector low power example.

Detector distance with calibration caching example.

Detector distance example.

Control helper example.

Cargo application.

Returns
  Returns EXIT_SUCCESS if successful, otherwise EXIT_FAILURE

Test if measure on wake up is enable Do a measurement if the the detector is ready (configured and calibrated)

Test if measure on wake up is enable Do a measurement if the the detector is ready (configured and calibrated)

Definition at line 344 of file i2c_presence_detector.c.

## ◆ apply_detector_config()

static void apply_detector_config | ( | presence_detector_resources_t * | resources | ) |
| static

Apply detector config.

This function will create the presence detector and allocate the needed memory

Parameters

  [in] | resources | presence detector resources struct

Definition at line 654 of file i2c_presence_detector.c.

## ◆ calibrate_sensor()

static bool calibrate_sensor | ( | presence_detector_resources_t * | resources | ) |
| static

Calibrate sensor.

Parameters

  [in] | resources | presence detector resources struct

Returns
  true if successful

Definition at line 613 of file i2c_presence_detector.c.

## ◆ command_handler()

static void command_handler | ( | uint32_t | command | ) |
| static

Execute the command sent from the host.

Parameters

  [in] | command | The command to execute

Definition at line 493 of file i2c_presence_detector.c.

## ◆ create_sensor()

static void create_sensor | ( | presence_detector_resources_t * | resources | ) |
| static

Create sensor.

Parameters

  [in] | resources | presence detector resources struct

Definition at line 593 of file i2c_presence_detector.c.

## ◆ detector_activate()

static bool detector_activate | ( | presence_detector_resources_t * | resources,
|  | bool | enable
| ) |  |
| static

Activate detector.

This function will activate the detector

Parameters

  [in] | resources | presence detector resources struct
  [in] | enable | set to true to enable the detector

Returns
  true if successful

Definition at line 723 of file i2c_presence_detector.c.

## ◆ detector_get_next()

static bool detector_get_next | ( | presence_detector_resources_t * | resources | ) |
| static

Get next presence measurement.

Parameters

  [in] | resources | presence detector resources struct

Returns
  true if successful

Definition at line 767 of file i2c_presence_detector.c.

## ◆ detector_gpio_output()

static void detector_gpio_output | ( | void |  | ) |
| static

Handle detector GPIO output.

Definition at line 863 of file i2c_presence_detector.c.

## ◆ detector_status_clr_bits()

static void detector_status_clr_bits | ( | uint32_t | bit_mask | ) |
| static

Clear bits in the i2c_detector_status.

The i2c_detector_status is protected by a critical section

Parameters

  [in] | bit_mask | The bit_mask to clear

Definition at line 568 of file i2c_presence_detector.c.

## ◆ detector_status_set_bits()

static void detector_status_set_bits | ( | uint32_t | bit_mask | ) |
| static

Set bits in the i2c_detector_status.

The i2c_detector_status is protected by a critical section

Parameters

  [in] | bit_mask | The bit_mask to set

Definition at line 555 of file i2c_presence_detector.c.

## ◆ detector_status_test_bits()

static bool detector_status_test_bits | ( | uint32_t | bit_mask | ) |
| static

Test bits in the i2c_detector_status.

The i2c_detector_status is protected by a critical section

Parameters

  [in] | bit_mask | The bit_mask to test

Returns
  true if all the bits in bit_mask is set in i2c_detector_status

Definition at line 581 of file i2c_presence_detector.c.

## ◆ enter_hibernate()

static bool enter_hibernate | ( | acc_sensor_t * | sensor | ) |
| static

Enter sensor hibernation state.

Definition at line 916 of file i2c_presence_detector.c.

## ◆ exit_hibernate()

static bool exit_hibernate | ( | acc_sensor_t * | sensor | ) |
| static

Exit sensor hibernation state.

Definition at line 930 of file i2c_presence_detector.c.

## ◆ get_command()

static uint32_t get_command | ( | void |  | ) |
| static

Get the i2c_detector_command values.

The i2c_detector_command is cleared during this read The read and clear are protected by a critical section

Returns
  The command sent from the host

Definition at line 479 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_command()

bool i2c_presence_detector_command | ( | uint32_t | command | ) |

Send command to be executed to i2c presence detector.

Parameters

  [in] | command | The command to be executed

Returns
  true if successful

Definition at line 191 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_config()

acc_detector_presence_config_t* i2c_presence_detector_get_config | ( | void |  | ) |

Get presence detector configuration handle.

Returns
  presence detector configuration handle

Definition at line 186 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_counter()

uint32_t i2c_presence_detector_get_counter | ( | void |  | ) |

Get presence detector measure counter.

The counter will be increased every time the presence detector completes a measure

Returns
  measure counter from presence detector

Definition at line 296 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_distance()

float i2c_presence_detector_get_distance | ( | void |  | ) |

Get presence detector distance.

Returns
  The distance of the detected presence

Definition at line 260 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_inter_presence_score()

float i2c_presence_detector_get_inter_presence_score | ( | void |  | ) |

Get inter presence score.

Returns
  A measure of the amount of slow motion detected.

Definition at line 284 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_intra_presence_score()

float i2c_presence_detector_get_intra_presence_score | ( | void |  | ) |

Get intra presence score.

Returns
  A measure of the amount of fast motion detected.

Definition at line 272 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_presence_detected_gpio()

bool i2c_presence_detector_get_presence_detected_gpio | ( | void |  | ) |

Get gpio output for presence detected state.

Returns
  true if gpio output for presence detected is enabled

Definition at line 318 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_presence_frame_rate_mhz()

uint32_t i2c_presence_detector_get_presence_frame_rate_mhz | ( | void |  | ) |

Get the actual frame rate for the current presence detector configuration.

Returns
  The frame rate in mHz

Definition at line 330 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_result()

uint32_t i2c_presence_detector_get_result | ( | void |  | ) |

Get presence detector result.

Returns
  result from presence detector

Definition at line 225 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_get_status()

uint32_t i2c_presence_detector_get_status | ( | void |  | ) |

Get presence detector status.

Returns
  status from presence detector

Definition at line 213 of file i2c_presence_detector.c.

## ◆ i2c_presence_detector_presence_detected_gpio()

void i2c_presence_detector_presence_detected_gpio | ( | bool | enable | ) |

Enable/Disable gpio output for presence detected.

Parameters

  [in] | enable | Enable gpio output for presence detected if set to true

Definition at line 308 of file i2c_presence_detector.c.

## ◆ module_low_power()

static void module_low_power | ( | void |  | ) |
| static

Try to set module in low power mode.

Definition at line 893 of file i2c_presence_detector.c.

## ◆ print_presence_result()

static void print_presence_result | ( | acc_detector_presence_result_t * | result | ) |
| static

Print the presence detector result.

Only available when the UART logs have been enabled with ENABLE_UART_LOGS

Parameters

  [in] | result | The presence detector result

Definition at line 944 of file i2c_presence_detector.c.

## ◆ uart_log()

static void uart_log | ( | const char * | format,
|  |  | ...
| ) |  |
| static

UART logging function (can be enabled/disabled by command)

Definition at line 958 of file i2c_presence_detector.c.

## Variable Documentation

## ◆ detector_resources

presence_detector_resources_t detector_resources = {0}
| static

Definition at line 41 of file i2c_presence_detector.c.

## ◆ i2c_detector_command

uint32_t i2c_detector_command = 0U
| static

Definition at line 42 of file i2c_presence_detector.c.

## ◆ i2c_detector_status

uint32_t i2c_detector_status = 0U
| static

Definition at line 43 of file i2c_presence_detector.c.

## ◆ inter_presence_score

float inter_presence_score = 0.0f
| static

Definition at line 54 of file i2c_presence_detector.c.

## ◆ intra_presence_score

float intra_presence_score = 0.0f
| static

Definition at line 53 of file i2c_presence_detector.c.

## ◆ presence_detected

bool presence_detected = false
| static

Definition at line 45 of file i2c_presence_detector.c.

## ◆ presence_detected_sticky

bool presence_detected_sticky = false
| static

Definition at line 46 of file i2c_presence_detector.c.

## ◆ presence_detection_gpio

bool presence_detection_gpio = false
| static

Definition at line 47 of file i2c_presence_detector.c.

## ◆ presence_detector_active

bool presence_detector_active = false
| static

Definition at line 44 of file i2c_presence_detector.c.

## ◆ presence_detector_error

bool presence_detector_error = false
| static

Definition at line 48 of file i2c_presence_detector.c.

## ◆ presence_distance

float presence_distance = 0.0f
| static

Definition at line 49 of file i2c_presence_detector.c.

## ◆ presence_frame_counter

uint32_t presence_frame_counter = 0U
| static

Definition at line 50 of file i2c_presence_detector.c.

## ◆ presence_frame_rate_mhz

uint32_t presence_frame_rate_mhz = 0U
| static

Definition at line 52 of file i2c_presence_detector.c.

## ◆ presence_last_tick_ms

uint32_t presence_last_tick_ms = 0U
| static

Definition at line 51 of file i2c_presence_detector.c.

## ◆ uart_logs_enabed

bool uart_logs_enabed = false
| static

Definition at line 55 of file i2c_presence_detector.c.