Data Structures | Macros | Functions | Variables
i2c_distance_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_distance.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 "distance_reg_protocol.h"`
`#include "i2c_application_system.h"`
`#include "i2c_distance_detector.h"`

Go to the source code of this file.

## Data Structures
struct | distance_detector_resources_t

## Macros
#define | SENSOR_ID (1U)
#define | SENSOR_TIMEOUT_MS (1000U)
#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 (distance_detector_resources_t *resources)
| Create sensor. More...
static void | apply_detector_config (distance_detector_resources_t *resources)
| Apply detector config. More...
static void | calibrate_sensor (distance_detector_resources_t *resources)
| Calibrate sensor. More...
static void | calibrate_detector (distance_detector_resources_t *resources, bool recalibrate)
| Calibrate detector. More...
static bool | is_detector_ready (void)
| Test if detector is ready. More...
static bool | detector_get_next (distance_detector_resources_t *resources)
| Get next distance measurement. More...
static void | print_distance_result (const acc_detector_distance_result_t *result)
| Print the distance detector result. More...
static void | uart_log (const char *format,...)
| UART logging function (can be enabled/disabled by command) More...
acc_detector_distance_config_t * | i2c_distance_detector_get_config (void)
| Get distance detector configuration handle. More...
bool | i2c_distance_detector_command (uint32_t command)
| Send command to be executed to i2c distance detector. More...
uint32_t | i2c_distance_detector_get_status (void)
| Get distance detector status. More...
uint32_t | i2c_distance_detector_get_result (void)
| Get distance detector result. More...
uint32_t | i2c_distance_detector_get_counter (void)
| Get distance detector measure counter. More...
float | i2c_distance_detector_get_peak_distance (uint16_t peak_id)
| Get the peak distance for a specific peak id. More...
float | i2c_distance_detector_get_peak_strength (uint16_t peak_id)
| Get the peak strength for a specific peak id. More...
void | i2c_distance_detector_measure_on_wakeup (bool enable)
| Enable/Disable measure on wake up. More...
bool | i2c_distance_detector_get_measure_on_wakeup (void)
| Get measure on wake up state. More...
int | acconeer_main (int argc, char *argv[])
| Assembly test example. More...

## Variables
static distance_detector_resources_t | detector_resources = { 0 }
static uint32_t | i2c_detector_command = 0U
static uint32_t | i2c_detector_status = 0U
static uint32_t | measure_distance_counter = 0U
static bool | measure_distance_error = false
static bool | measure_on_wakeup = false
static bool | uart_logs_enabed = false

## Macro Definition Documentation

## ◆ SENSOR_ID

#define SENSOR_ID (1U)

Definition at line 26 of file i2c_distance_detector.c.

## ◆ SENSOR_TIMEOUT_MS

#define SENSOR_TIMEOUT_MS (1000U)

Definition at line 27 of file i2c_distance_detector.c.

## ◆ UART_LOG_BUFFER_SIZE

#define UART_LOG_BUFFER_SIZE 100

Definition at line 50 of file i2c_distance_detector.c.

## Function Documentation

## ◆ acconeer_main()

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

Assembly test example.

Surface velocity example application.

Tank level reference application.

Smart presence reference application.

Breathing example application.

Service subsweeps example.

Service multple configurations example.

Low power service 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.

Detector presence example with multiple configurations.

Low power detector presence example.

Detector presence example.

Distance detector low power example.

Detector distance example.

Control helper example.

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)

Definition at line 322 of file i2c_distance_detector.c.

## ◆ apply_detector_config()

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

Apply detector config.

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

Parameters

  [in] | resources | distance detector resources struct

Definition at line 620 of file i2c_distance_detector.c.

## ◆ calibrate_detector()

static void calibrate_detector | ( | distance_detector_resources_t * | resources,
|  | bool | recalibrate
| ) |  |
| static

Calibrate detector.

Parameters

  [in] | resources | distance detector resources struct
  [in] | recalibrate | Set to false for first calibration, true for re-calibration

Definition at line 743 of file i2c_distance_detector.c.

## ◆ calibrate_sensor()

static void calibrate_sensor | ( | distance_detector_resources_t * | resources | ) |
| static

Calibrate sensor.

Parameters

  [in] | resources | distance detector resources struct

Definition at line 707 of file i2c_distance_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 468 of file i2c_distance_detector.c.

## ◆ create_sensor()

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

Create sensor.

Parameters

  [in] | resources | distance detector resources struct

Definition at line 597 of file i2c_distance_detector.c.

## ◆ detector_get_next()

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

Get next distance measurement.

Parameters

  [in] | resources | distance detector resources struct

Definition at line 813 of file i2c_distance_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 570 of file i2c_distance_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 556 of file i2c_distance_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 584 of file i2c_distance_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 453 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_command()

bool i2c_distance_detector_command | ( | uint32_t | command | ) |

Send command to be executed to i2c distance detector.

Parameters

  [in] | command | The command to be executed

Returns
  true if successful

Definition at line 180 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_get_config()

acc_detector_distance_config_t* i2c_distance_detector_get_config | ( | void |  | ) |

Get distance detector configuration handle.

Returns
  distance detector configuration handle

Definition at line 174 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_get_counter()

uint32_t i2c_distance_detector_get_counter | ( | void |  | ) |

Get distance detector measure counter.

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

Returns
  measure counter from distance detector

Definition at line 251 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_get_measure_on_wakeup()

bool i2c_distance_detector_get_measure_on_wakeup | ( | void |  | ) |

Get measure on wake up state.

Returns
  true if measure on wake up is enabled

Definition at line 301 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_get_peak_distance()

float i2c_distance_detector_get_peak_distance | ( | uint16_t | peak_id | ) |

Get the peak distance for a specific peak id.

Parameters

  [in] | peak_id | The id of the peak

Returns
  The distance to the peak

Definition at line 264 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_get_peak_strength()

float i2c_distance_detector_get_peak_strength | ( | uint16_t | peak_id | ) |

Get the peak strength for a specific peak id.

Parameters

  [in] | peak_id | The id of the peak

Returns
  The strength of the peak

Definition at line 277 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_get_result()

uint32_t i2c_distance_detector_get_result | ( | void |  | ) |

Get distance detector result.

Returns
  result from distance detector

Definition at line 216 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_get_status()

uint32_t i2c_distance_detector_get_status | ( | void |  | ) |

Get distance detector status.

Returns
  status from distance detector

Definition at line 203 of file i2c_distance_detector.c.

## ◆ i2c_distance_detector_measure_on_wakeup()

void i2c_distance_detector_measure_on_wakeup | ( | bool | enable | ) |

Enable/Disable measure on wake up.

Parameters

  [in] | enable | Enable measure on wake up if set to true

Definition at line 290 of file i2c_distance_detector.c.

## ◆ is_detector_ready()

static bool is_detector_ready | ( | void |  | ) |
| static

Test if detector is ready.

Returns
  true if detector is ready to do distance mesaurments

Definition at line 803 of file i2c_distance_detector.c.

## ◆ print_distance_result()

static void print_distance_result | ( | const acc_detector_distance_result_t * | result | ) |
| static

Print the distance detector result.

Only available when the UART logs have been enabled with ENABLE_UART_LOGS

Parameters

  [in] | result | The distance detector result

Definition at line 876 of file i2c_distance_detector.c.

## ◆ uart_log()

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

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

Definition at line 893 of file i2c_distance_detector.c.

## Variable Documentation

## ◆ detector_resources

distance_detector_resources_t detector_resources = { 0 }
| static

Definition at line 42 of file i2c_distance_detector.c.

## ◆ i2c_detector_command

uint32_t i2c_detector_command = 0U
| static

Definition at line 43 of file i2c_distance_detector.c.

## ◆ i2c_detector_status

uint32_t i2c_detector_status = 0U
| static

Definition at line 44 of file i2c_distance_detector.c.

## ◆ measure_distance_counter

uint32_t measure_distance_counter = 0U
| static

Definition at line 45 of file i2c_distance_detector.c.

## ◆ measure_distance_error

bool measure_distance_error = false
| static

Definition at line 46 of file i2c_distance_detector.c.

## ◆ measure_on_wakeup

bool measure_on_wakeup = false
| static

Definition at line 47 of file i2c_distance_detector.c.

## ◆ uart_logs_enabed

bool uart_logs_enabed = false
| static

Definition at line 48 of file i2c_distance_detector.c.