Chirp SonicLib  4.5.2
Classes | Macros | Typedefs | Functions
ch_driver.h File Reference

Internal driver functions for operation with the Chirp ultrasonic sensor. More...

#include <invn/soniclib/soniclib.h>
#include <stdint.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  chdrv_queue
 Queue structure, for non-blocking access. More...
 
struct  chdrv_transaction
 Transaction control structure. More...
 

Macros

#define CH_PROG_ADDR_DEV_I2C_ADDR_REG   (0x01C5)
 
#define CH_PROG_ADDR_IDLE_LOC   (CHX01_PROG_MEM_ADDR + CHX01_PROG_MEM_SIZE - 4)
 
#define CH_PROG_ADDR_PMUT_CNTRL4_REG   (0x01A6)
 
#define CH_PROG_ADDR_WDT_REG   (0x0120)
 
#define CH_PROG_REG_ADDR   0x05
 
#define CH_PROG_REG_CNT   0x07
 
#define CH_PROG_REG_CPU   0x42
 
#define CH_PROG_REG_CTL   0x44
 
#define CH_PROG_REG_DATA   0x06
 
#define CH_PROG_REG_PING   0x00
 
#define CH_PROG_REG_STAT   0x43
 
#define CH_PROG_SIZEOF(R)   ((R)&0x40 ? 1 : 2)
 
#define CH_PROG_XFER_SIZE   (256)
 
#define CHDRV_BANDWIDTH_INDEX_1   6
 
#define CHDRV_BANDWIDTH_INDEX_2    (CHDRV_BANDWIDTH_INDEX_1 + 1)
 
#define CHDRV_DEBUG_PIN_NUM   (0)
 
#define CHDRV_DELAY_EN_CHARGE_PUMP_MS   (5)
 
#define CHDRV_DELAY_OVERHEAD_US   (0)
 
#define CHDRV_EVENT_TIMEOUT_MS   (750)
 
#define CHDRV_FREQLOCK_TIMEOUT_MS    100
 
#define CHDRV_I2C_MAX_WRITE_BYTES   256
 
#define CHDRV_I2C_SPEED_DEFAULT_HZ   (400000)
 
#define CHDRV_MAX_QUEUE_LENGTH    CHIRP_MAX_NUM_SENSORS
 
#define CHDRV_NB_TRANS_TYPE_EXTERNAL   (2)
 
#define CHDRV_NB_TRANS_TYPE_PROG   (1)
 
#define CHDRV_NB_TRANS_TYPE_STD   (0)
 
#define CHDRV_POST_ALGO_INIT_DELAY_MS   3
 
#define CHDRV_POST_TRIG_IEN_DELAY_US    10
 
#define CHDRV_PRETRIGGER_DELAY_US   600
 
#define CHDRV_SCALEFACTOR_INDEX   4
 
#define CHDRV_TRIGGER_PULSE_US   5
 
#define PMUT_CNTRL4_HVVDD_FON   (0x0400)
 
#define PMUT_CNTRL4_HVVSS_FON   (0x0200)
 

Typedefs

typedef struct chdrv_queue chdrv_queue_t
 Queue structure, for non-blocking access.
 
typedef struct chdrv_transaction chdrv_transaction_t
 Transaction control structure.
 

Functions

uint8_t chdrv_algo_cfg_read (ch_dev_t *dev_ptr, void *algo_cfg_ptr)
 Read the algorithm configuration data from a sensor. More...
 
uint8_t chdrv_algo_cfg_write (ch_dev_t *dev_ptr, const void *algo_cfg_ptr)
 Write the algorithm configuration data to a sensor. More...
 
uint8_t chdrv_algo_info_read (ch_dev_t *dev_ptr, ICU_ALGO_SHASTA_INFO *algo_info_ptr)
 Read the algorithm information data from a sensor. More...
 
uint8_t chdrv_algo_init (ch_dev_t *dev_ptr)
 Initialize the measurement algorithm on a sensor. More...
 
uint8_t chdrv_algo_out_read (ch_dev_t *dev_ptr, void *algo_out_ptr)
 Read the algorithm output data from a sensor. More...
 
uint8_t chdrv_algo_state_read (ch_dev_t *dev_ptr, void *algo_state_ptr)
 Read the algorithm state data from a sensor. More...
 
int chdrv_burst_read (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t *data, uint16_t len)
 Read multiple bytes from a sensor application register location. More...
 
int chdrv_burst_write (ch_dev_t *dev_ptr, uint16_t mem_addr, const uint8_t *data, uint16_t num_bytes)
 Write multiple bytes to a sensor application register location. More...
 
uint8_t chdrv_check_reset_state (ch_dev_t *dev_ptr, uint8_t *reset_state)
 Check if sensor reset has occurred. More...
 
uint32_t chdrv_cpu_freq_adjust (ch_dev_t *dev_ptr, uint32_t pmut_freq)
 Adjust sensor micro-controller CPU frequency. More...
 
uint32_t chdrv_cpu_freq_calculate (ch_dev_t *dev_ptr)
 Calculate sensor micro-controller CPU frequency, in Hz. More...
 
uint8_t chdrv_dbg_reg_read (ch_dev_t *dev_ptr, uint8_t reg_id, uint16_t *reg_value_ptr)
 Read the debug register from a sensor. More...
 
uint8_t chdrv_dbg_reg_write (ch_dev_t *dev_ptr, uint8_t reg_id, uint16_t reg_value)
 Write the debug register in a sensor. More...
 
int chdrv_detect_and_program (ch_dev_t *dev_ptr)
 Detect, program, and start a sensor. More...
 
uint8_t chdrv_event_trigger (ch_dev_t *dev_ptr, uint16_t event)
 Trigger an event on a sensor and return immediately. More...
 
uint8_t chdrv_event_trigger_and_wait (ch_dev_t *dev_ptr, uint16_t event)
 Trigger an event on a sensor and wait for completion. More...
 
int chdrv_external_queue (ch_group_t *grp_ptr, ch_dev_t *instance, uint8_t rd_wrb, uint16_t addr, uint16_t nbytes, uint8_t *data)
 Add an I2C/SPI transaction for an external device to the non-blocking queue. More...
 
int chdrv_group_detect_and_program (ch_group_t *grp_ptr)
 Detect, program, and start all sensors in a group. More...
 
int chdrv_group_hard_reset (ch_group_t *grp_ptr)
 Perform a hard reset on a group of sensors. More...
 
int chdrv_group_hw_trigger (ch_group_t *grp_ptr)
 Start a measurement in hardware triggered mode. More...
 
void chdrv_group_irq_handler (ch_group_t *grp_ptr, uint8_t bus_index)
 Continue a non-blocking readout. More...
 
void chdrv_group_measure_pmut (ch_group_t *grp_ptr)
 Measure the ultrasonic transducer frequency & bandwidth. More...
 
void chdrv_group_measure_rtc (ch_group_t *grp_ptr)
 Calibrate the sensor real-time clock against the host microcontroller clock. More...
 
void chdrv_group_measure_rtc_no_pulse (ch_group_t *grp_ptr)
 Calibrate the sensor real-time clock without using a pulse. More...
 
int chdrv_group_prepare (ch_group_t *grp_ptr)
 Initialize data structures and hardware for sensor interaction and reset sensors. More...
 
int chdrv_group_queue (ch_group_t *grp_ptr, ch_dev_t *instance, uint8_t rd_wrb, uint8_t type, uint16_t addr, uint16_t nbytes, uint8_t *data)
 Add an I2C/SPI transaction to the non-blocking queue. More...
 
int chdrv_group_soft_reset (ch_group_t *grp_ptr)
 Perform a soft reset on a group of sensors. More...
 
uint8_t chdrv_group_start (ch_group_t *grp_ptr)
 Initialize and start a group of sensors. More...
 
void chdrv_group_start_nb (ch_group_t *grp_ptr)
 Start a non-blocking sensor readout. More...
 
int chdrv_group_wait_for_lock (ch_group_t *grp_ptr)
 Wait for all sensors to finish start-up procedure. More...
 
int chdrv_hw_trigger (ch_dev_t *dev_ptr)
 Start a measurement in hardware triggered mode on one sensor. More...
 
int chdrv_init (ch_dev_t *dev_ptr, uint8_t i2c_addr, uint8_t io_index, uint8_t bus_index, uint16_t part_number)
 Initialize the sensor device configuration. More...
 
void chdrv_int_callback (ch_group_t *grp_ptr, uint8_t dev_num)
 Driver callback routine for sensor interrupt. More...
 
void chdrv_int_callback_deferred (ch_group_t *grp_ptr, uint8_t dev_num)
 Driver callback deferred routine for sensor interrupt. More...
 
void chdrv_int_group_assert (ch_group_t *grp_ptr)
 Assert the interrupt lines for all sensors in a group. More...
 
void chdrv_int_group_deassert (ch_group_t *grp_ptr)
 De-assert the interrupt lines for all sensors in a group. More...
 
void chdrv_int_group_interrupt_disable (ch_group_t *grp_ptr)
 Disable interrupts on the interrupt lines for all sensors in a group. More...
 
void chdrv_int_group_interrupt_enable (ch_group_t *grp_ptr)
 Enable interrupts on the interrupt lines for all sensors in a group. More...
 
void chdrv_int_group_set_dir_in (ch_group_t *grp_ptr)
 Configure the interrupt lines for all sensors in a group as inputs. More...
 
void chdrv_int_group_set_dir_out (ch_group_t *grp_ptr)
 Configure the interrupt lines for all sensors in a group as outputs. More...
 
void chdrv_int_interrupt_disable (ch_dev_t *dev_ptr)
 Disable interrupts on the interrupt line for a sensor. More...
 
void chdrv_int_interrupt_enable (ch_dev_t *dev_ptr)
 Enable interrupts on the interrupt line for a sensor. More...
 
uint8_t chdrv_int_notify (ch_group_t *grp_ptr, uint8_t dev_num)
 Notify SonicLib that a sensor interrupt was received. More...
 
void chdrv_int_set_dir_in (ch_dev_t *dev_ptr)
 Configure the interrupt line for a sensor as an input. More...
 
uint8_t chdrv_meas_queue_read (ch_dev_t *dev_ptr, measurement_queue_t *q_buf_ptr)
 Read the measurement queue from a sensor. More...
 
uint8_t chdrv_meas_queue_write (ch_dev_t *dev_ptr, measurement_queue_t *q_buf_ptr)
 Write the measurement queue to a sensor. More...
 
uint32_t chdrv_one_way_range (ch_dev_t *dev_ptr, uint16_t tof, uint16_t tof_sf)
 Convert the sensor register values to a range using the calibration data in the ch_dev_t struct. More...
 
uint8_t chdrv_otpmem_copy (ch_dev_t *dev_ptr, otp_copy_t *otp_copy_ptr)
 Copy OTP memory contents. More...
 
uint8_t chdrv_otpmem_read (ch_dev_t *dev_ptr)
 Read OTP memory contents. More...
 
void chdrv_pretrigger_delay_set (ch_group_t *grp_ptr, uint16_t delay_us)
 Set the pre-trigger delay for rx-only sensors. More...
 
int chdrv_prog_i2c_read (ch_dev_t *dev_ptr, uint8_t *message, uint16_t len)
 Read bytes from a CHx01 device in programming mode. More...
 
int chdrv_prog_i2c_read_nb (ch_dev_t *dev_ptr, uint8_t *message, uint16_t len)
 Read bytes from a CHx01 device in programming mode, non-blocking. More...
 
int chdrv_prog_i2c_write (ch_dev_t *dev_ptr, const uint8_t *message, uint16_t len)
 Write bytes to a CHx01 device in programming mode. More...
 
int chdrv_prog_mem_write (ch_dev_t *dev_ptr, uint16_t addr, const uint8_t *message, uint16_t nbytes)
 Write to CHx01 sensor memory. More...
 
int chdrv_prog_ping (ch_dev_t *dev_ptr)
 Detect a connected sensor. More...
 
int chdrv_prog_write (ch_dev_t *dev_ptr, uint8_t reg_addr, uint16_t data)
 Write to a CHx01 programming register. More...
 
int chdrv_read_buf_addr (ch_dev_t *dev_ptr)
 Read the IQ buffer address from the sensor and store in dev_ptr. More...
 
int chdrv_read_byte (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t *data)
 Read byte from a sensor application register. More...
 
int chdrv_read_word (ch_dev_t *dev_ptr, uint16_t mem_addr, uint16_t *data)
 Read 16 bits from a sensor application register. More...
 
int chdrv_restart (ch_dev_t *dev_ptr)
 Restart a sensor. More...
 
uint32_t chdrv_round_trip_range (ch_dev_t *dev_ptr, uint16_t tof, uint16_t tof_sf)
 Convert the sensor register values to a round-trip range using the calibration data in the ch_dev_t struct. More...
 
uint8_t chdrv_run_bist (ch_dev_t *dev_ptr)
 Run built-in self test (BIST) on sensor. More...
 
int chdrv_set_idle (ch_dev_t *dev_ptr)
 Put CHx01 sensor(s) in idle state. More...
 
int chdrv_soft_reset (ch_dev_t *dev_ptr)
 Perform a soft reset on a sensor. More...
 
uint8_t chdrv_sys_ctrl_read (ch_dev_t *dev_ptr, uint8_t *reg_value_ptr)
 Read the system control register from a sensor. More...
 
uint8_t chdrv_sys_ctrl_write (ch_dev_t *dev_ptr, uint8_t reg_value)
 Write the system control register in a sensor. More...
 
void chdrv_trig_assert (ch_dev_t *dev_ptr)
 Assert the hardware trigger line for a sensor. More...
 
void chdrv_trig_deassert (ch_dev_t *dev_ptr)
 De-assert the hardware trigger line for a sensor. More...
 
void chdrv_trig_group_assert (ch_group_t *grp_ptr)
 Assert the hardware trigger lines for all sensors in a group. More...
 
void chdrv_trig_group_deassert (ch_group_t *grp_ptr)
 De-assert the hardware trigger lines for all sensors in a group. More...
 
void chdrv_trig_group_set_dir_out (ch_group_t *grp_ptr)
 Configure the hardware trigger lines for all sensors in a group as outputs. More...
 
void chdrv_trig_set_dir_out (ch_dev_t *dev_ptr)
 Configure the hardware trigger line for a sensor as an output. More...
 
int chdrv_wait_for_lock (ch_dev_t *dev_ptr, uint16_t timeout_ms)
 Wait for an individual sensor to finish start-up procedure. More...
 
int chdrv_write_byte (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t data)
 Write byte to a sensor application register. More...
 
int chdrv_write_word (ch_dev_t *dev_ptr, uint16_t mem_addr, uint16_t data)
 Write 16 bits to a sensor application register. More...
 

Detailed Description

Internal driver functions for operation with the Chirp ultrasonic sensor.

This file contains definitions for the internal Chirp sensor driver functions and structures within SonicLib. These functions are provided in source code form to simplify integration with an embedded application and for reference only.

The Chirp driver functions provide an interface between the SonicLib public API layer and the actual sensor devices. The driver manages all software-defined aspects of the Chirp sensor, including the register set.

You should not need to edit this file or call the driver functions directly. Doing so will reduce your ability to benefit from future enhancements and releases from Chirp.

Macro Definition Documentation

◆ CH_PROG_ADDR_DEV_I2C_ADDR_REG

#define CH_PROG_ADDR_DEV_I2C_ADDR_REG   (0x01C5)

Device own I2C addr register address

◆ CH_PROG_ADDR_IDLE_LOC

#define CH_PROG_ADDR_IDLE_LOC   (CHX01_PROG_MEM_ADDR + CHX01_PROG_MEM_SIZE - 4)

IDLE loop location

◆ CH_PROG_ADDR_PMUT_CNTRL4_REG

#define CH_PROG_ADDR_PMUT_CNTRL4_REG   (0x01A6)

PMUT CNTRL4 register address

◆ CH_PROG_ADDR_WDT_REG

#define CH_PROG_ADDR_WDT_REG   (0x0120)

Watchdog register address

◆ CH_PROG_REG_ADDR

#define CH_PROG_REG_ADDR   0x05

Data transfer starting address register address.

◆ CH_PROG_REG_CNT

#define CH_PROG_REG_CNT   0x07

Data transfer size register address.

◆ CH_PROG_REG_CPU

#define CH_PROG_REG_CPU   0x42

Processor control register address.

◆ CH_PROG_REG_CTL

#define CH_PROG_REG_CTL   0x44

Data transfer control register address.

◆ CH_PROG_REG_DATA

#define CH_PROG_REG_DATA   0x06

Data transfer value register address.

◆ CH_PROG_REG_PING

#define CH_PROG_REG_PING   0x00

Read-only register used during device discovery.

◆ CH_PROG_REG_STAT

#define CH_PROG_REG_STAT   0x43

Processor status register address.

◆ CH_PROG_SIZEOF

#define CH_PROG_SIZEOF (   R)    ((R)&0x40 ? 1 : 2)

Macro to determine programming register size.

◆ CH_PROG_XFER_SIZE

#define CH_PROG_XFER_SIZE   (256)

max size of a read operation via programming interface

◆ CHDRV_BANDWIDTH_INDEX_1

#define CHDRV_BANDWIDTH_INDEX_1   6

Index of first sample to use for calculating bandwidth.

◆ CHDRV_BANDWIDTH_INDEX_2

#define CHDRV_BANDWIDTH_INDEX_2    (CHDRV_BANDWIDTH_INDEX_1 + 1)

Index of second sample to \ use for calculating bandwidth.

◆ CHDRV_DEBUG_PIN_NUM

#define CHDRV_DEBUG_PIN_NUM   (0)

debug pin number (index) to use for debug indication

◆ CHDRV_DELAY_OVERHEAD_US

#define CHDRV_DELAY_OVERHEAD_US   (0)

Tuning parameter to adjust pre-trigger timing

◆ CHDRV_EVENT_TIMEOUT_MS

#define CHDRV_EVENT_TIMEOUT_MS   (750)

Max time to wait for sensor event, in ms

◆ CHDRV_FREQLOCK_TIMEOUT_MS

#define CHDRV_FREQLOCK_TIMEOUT_MS    100

Time to wait in chdrv_group_start() for sensor \ initialization, in milliseconds.

◆ CHDRV_I2C_MAX_WRITE_BYTES

#define CHDRV_I2C_MAX_WRITE_BYTES   256

maximum number of bytes in a single I2C write

◆ CHDRV_I2C_SPEED_DEFAULT_HZ

#define CHDRV_I2C_SPEED_DEFAULT_HZ   (400000)

Default I2C speed assumed if CHIRP_I2C_SPEED_HZ not defined in BSP

◆ CHDRV_MAX_QUEUE_LENGTH

#define CHDRV_MAX_QUEUE_LENGTH    CHIRP_MAX_NUM_SENSORS

Max queued non-blocking I2C/SPI transactions - value from chirp_board_config.h

◆ CHDRV_NB_TRANS_TYPE_EXTERNAL

#define CHDRV_NB_TRANS_TYPE_EXTERNAL   (2)

externally requested non-blocking I/O transaction

◆ CHDRV_NB_TRANS_TYPE_PROG

#define CHDRV_NB_TRANS_TYPE_PROG   (1)

non-blocking I/O via low-level programming interface

◆ CHDRV_NB_TRANS_TYPE_STD

#define CHDRV_NB_TRANS_TYPE_STD   (0)

standard non-blocking I/O transaction

◆ CHDRV_POST_ALGO_INIT_DELAY_MS

#define CHDRV_POST_ALGO_INIT_DELAY_MS   3

Time to delay after triggering algorithm init on sensor, in ms

◆ CHDRV_POST_TRIG_IEN_DELAY_US

#define CHDRV_POST_TRIG_IEN_DELAY_US    10

Time to delay after triggering shared int/trig before re-enabling interrupt

◆ CHDRV_PRETRIGGER_DELAY_US

#define CHDRV_PRETRIGGER_DELAY_US   600

Time to delay between triggering rx-only and tx/rx nodes, in us

◆ CHDRV_SCALEFACTOR_INDEX

#define CHDRV_SCALEFACTOR_INDEX   4

Index for calculating scalefactor.

◆ CHDRV_TRIGGER_PULSE_US

#define CHDRV_TRIGGER_PULSE_US   5

Length of INT pulse to trigger sensor, in microseconds - minimum 800ns.

Function Documentation

◆ chdrv_algo_cfg_read()

uint8_t chdrv_algo_cfg_read ( ch_dev_t dev_ptr,
void *  algo_cfg_ptr 
)

Read the algorithm configuration data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if failure detected

This function reads the algorithm configuration data for an algorithm that has been programmed into an ICU sensor. The format of the configuration data is defined by the specific algorithm being used.

◆ chdrv_algo_cfg_write()

uint8_t chdrv_algo_cfg_write ( ch_dev_t dev_ptr,
const void *  algo_cfg_ptr 
)

Write the algorithm configuration data to a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if failure detected

This function write the algorithm configuration data for an algorithm that has been programmed into an ICU sensor. The format of the configuration data is defined by the specific algorithm being used.

◆ chdrv_algo_info_read()

uint8_t chdrv_algo_info_read ( ch_dev_t dev_ptr,
ICU_ALGO_SHASTA_INFO algo_info_ptr 
)

Read the algorithm information data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if failure detected

This function reads the algorithm information data for an algorithm that has been programmed into an ICU sensor.

◆ chdrv_algo_init()

uint8_t chdrv_algo_init ( ch_dev_t dev_ptr)

Initialize the measurement algorithm on a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if failure detected

This function initializes a measurement algorithm that has already been programmed into an ICU sensor.

◆ chdrv_algo_out_read()

uint8_t chdrv_algo_out_read ( ch_dev_t dev_ptr,
void *  algo_out_ptr 
)

Read the algorithm output data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if failure detected

This function reads the algorithm output data for an algorithm that has been programmed into an ICU sensor. The format of the output data is defined by the specific algorithm being used.

◆ chdrv_algo_state_read()

uint8_t chdrv_algo_state_read ( ch_dev_t dev_ptr,
void *  algo_state_ptr 
)

Read the algorithm state data from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if failure detected

This function reads the algorithm state data for an algorithm that has been programmed into an ICU sensor. The format of the state data is defined by the specific algorithm being used.

◆ chdrv_burst_read()

int chdrv_burst_read ( ch_dev_t dev_ptr,
uint16_t  mem_addr,
uint8_t *  data_ptr,
uint16_t  num_bytes 
)

Read multiple bytes from a sensor application register location.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
mem_addrsensor memory/register address
datapointer to receive buffer
lennumber of bytes to read
Returns
0 if successful, non-zero otherwise
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
mem_addrsensor memory/register address
data_ptrpointer to receive buffer
num_bytesnumber of bytes to read
Returns
0 if successful, non-zero otherwise

◆ chdrv_burst_write()

int chdrv_burst_write ( ch_dev_t dev_ptr,
uint16_t  mem_addr,
const uint8_t *  data_ptr,
uint16_t  num_bytes 
)

Write multiple bytes to a sensor application register location.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
mem_addrsensor memory/register address
datapointer to transmit buffer containing data to send
num_bytesnumber of bytes to write
Returns
0 if successful, non-zero otherwise
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
mem_addrsensor memory/register address
data_ptrpointer to transmit buffer containing data to send
lennumber of bytes to write
Returns
0 if successful, non-zero otherwise

◆ chdrv_check_reset_state()

uint8_t chdrv_check_reset_state ( ch_dev_t dev_ptr,
uint8_t *  reset_state_ptr 
)

Check if sensor reset has occurred.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure
reset_state_ptrpointer to variable that will be updated with 0 = No Reset, 1 = Reset has occurred.
Returns
0 if successful, non-zero otherwise

This function checks if an PUC (Power Up Clear) main reset event has occurred by checking the PUC_PND status bit in CPU_STAT debug register. The function updates the "reset_state_ptr is set to 1 if the sensor was reset, otherwise it is set to zero. Note this will continue to return a reset state as set until the PUC_PND bit is cleared by writing a 1 to it, which is done in reset_and_run function.

◆ chdrv_cpu_freq_adjust()

uint32_t chdrv_cpu_freq_adjust ( ch_dev_t dev_ptr,
uint32_t  pmut_freq 
)

Adjust sensor micro-controller CPU frequency.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
pmut_freqPMUT transducer frequency, in Hz
Returns
Sensor CPU frequency after adjustment, in Hz

This function fine tunes the internal micro-controller processor frequency to avoid harmonic relationships with the PMUT transducer frequency.

See also chdrv_cpu_freq_calculate()

◆ chdrv_cpu_freq_calculate()

uint32_t chdrv_cpu_freq_calculate ( ch_dev_t dev_ptr)

Calculate sensor micro-controller CPU frequency, in Hz.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
Sensor CPU frequency, in Hz

This function calculates and returns the processor frequency, in Hz, of the internal micro-controller in the sensor.

◆ chdrv_dbg_reg_read()

uint8_t chdrv_dbg_reg_read ( ch_dev_t dev_ptr,
uint8_t  reg_id,
uint16_t *  reg_value_ptr 
)

Read the debug register from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
reg_value_ptrpointer to location to receive register value
Returns
0 if register read succeeded, non-zero otherwise

This function reads the debug register from an ICU sensor and returns the value in the location specified by reg_value_ptr.

◆ chdrv_dbg_reg_write()

uint8_t chdrv_dbg_reg_write ( ch_dev_t dev_ptr,
uint8_t  reg_id,
uint16_t  reg_value 
)

Write the debug register in a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
reg_valueregister value to write
Returns
0 if register write succeeded, non-zero otherwise

This function writes reg_value to the debug register in an ICU sensor.

Returns
0 if register write succeeded, non-zero otherwise

◆ chdrv_detect_and_program()

int chdrv_detect_and_program ( ch_dev_t dev_ptr)

Detect, program, and start a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
Returns
0 if write to sensor succeeded, non-zero otherwise

This function probes the I2C bus for the device. If it is found, the sensor firmware is programmed into the device, and the application I2C address is set. Then the sensor is reset and execution starts.

Once started, the sensor device will begin an internal initialization and self-test sequence.

The chdrv_wait_for_lock() function may be used to wait for this sequence to complete.

Note
This routine will leave the PROG pin de-asserted when it completes.
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if write to sensor succeeded, non-zero otherwise

This function probes the I2C bus for the device. If it is found, the sensor firmware is programmed into the device, and the application I2C address is set. Then the sensor is reset and execution starts.

Once started, the sensor device will begin an internal initialization and self-test sequence. The chdrv_wait_for_lock() function may be used to wait for this sequence to complete.

Note
This routine will leave the PROG pin de-asserted when it completes.

◆ chdrv_event_trigger()

uint8_t chdrv_event_trigger ( ch_dev_t dev_ptr,
uint16_t  event 
)

Trigger an event on a sensor and return immediately.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
eventevent type to trigger

This function will trigger the event specified by event on an ICU sensor. The routine will return immediately, without waiting for any completion notification from the sensor.

See also chdrv_event_trigger_and_wait()

◆ chdrv_event_trigger_and_wait()

uint8_t chdrv_event_trigger_and_wait ( ch_dev_t dev_ptr,
uint16_t  event 
)

Trigger an event on a sensor and wait for completion.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
eventevent type to trigger

This function will trigger the event specified by event on an ICU sensor. The routine will wait for the sensor to indicate the event has completed by generating a pulse on the interrupt line.

See also chdrv_event_trigger()

◆ chdrv_external_queue()

int chdrv_external_queue ( ch_group_t grp_ptr,
ch_dev_t instance,
uint8_t  rd_wrb,
uint16_t  addr,
uint16_t  nbytes,
uint8_t *  data 
)

Add an I2C/SPI transaction for an external device to the non-blocking queue.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
instancepointer to the ch_dev_t descriptor structure for a sensor
rd_wrbread/write indicator: 0 if write operation, 1 if read operation
addrI2C address for transfer (for I2C devices only)
nbytesnumber of bytes to read/write
datapointer to buffer to receive data or containing data to send
Returns
0 if successful, non-zero otherwise

This function queues an I2C/SPI transaction for an "external" device (i.e. not a Chirp sensor). It is used when the I2C/SPI bus is shared between the Chirp sensor(s) and other devices.

The transaction is flagged for special handling when the I/O operation completes. Specifically, the chbsp_external_irq_handler() will be called by the driver to allow the board support package (BSP) to perform any necessary operations.

◆ chdrv_group_detect_and_program()

int chdrv_group_detect_and_program ( ch_group_t grp_ptr)

Detect, program, and start all sensors in a group.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
Returns
0 for success, non-zero if write(s) failed to any sensor initially detected as present

This function probes the SPI or I2C bus for each device in the group. For each detected sensor, the firmware is programmed into the device, and in CHx01 sensors the application I2C address is set. Then the sensor is reset and execution starts.

Once started, each device will begin an internal initialization and self-test sequence.

Note
For CHx01 sensors, this routine will leave the PROG pin de-asserted for all devices in the group when it completes.
Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
Returns
0 for success, non-zero if write(s) failed to any sensor initially detected as present

This function probes the I2C bus for each device in the group. For each detected sensor, the sensor firmware is programmed into the device, and the application I2C address is set. Then the sensor is reset and execution starts.

Once started, each sensor device will begin an internal initialization and self-test sequence. The chdrv_group_wait_for_lock() function may be used to wait for this sequence to complete on all devices in the group.

Note
This routine will leave the PROG pin de-asserted for all devices in the group when it completes.

◆ chdrv_group_hard_reset()

int chdrv_group_hard_reset ( ch_group_t grp_ptr)

Perform a hard reset on a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
Returns
0 if successful, non-zero otherwise

This function performs a hardware reset on each device in a group of sensors by asserting each device's RESET_N pin.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
Returns
0 if successful, non-zero otherwise

This function performs a hardware reset on each device in a group of sensors. For CH101 and CH201 sensors, each device's RESET_N pin is asserted and then a soft reset is performed.

ICU sensors do not have a hardware reset pin, so only a soft reset is performed.

◆ chdrv_group_hw_trigger()

int chdrv_group_hw_trigger ( ch_group_t grp_ptr)

Start a measurement in hardware triggered mode.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
Returns
0 if success, non-zero if grp_ptr pointer is invalid

This function starts a triggered measurement on each sensor in a group, by briefly asserting the INT line to each device. Each sensor must have already been placed in hardware triggered mode before this function is called.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
Returns
0 if success, non-zero if grp_ptr pointer is invalid

This function starts a triggered measurement on each sensor in a group, by briefly asserting the INT line to each device. Each sensor must have already been placed in hardware triggered mode before this function is called.

◆ chdrv_group_irq_handler()

void chdrv_group_irq_handler ( ch_group_t grp_ptr,
uint8_t  bus_index 
)

Continue a non-blocking readout.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
bus_indexindex value identifying I2C/SPI bus within group

Call this function once from your I2C/SPI interrupt handler each time it executes. It will call chdrv_group_complete_callback() when all transactions are complete.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
bus_indexindex value identifying I2C/SPI bus within group

Call this function once from your I2C interrupt handler each time it executes. It will call the user's callback routine (grp_ptr->io_complete_callback) when all transactions are complete.

◆ chdrv_group_measure_pmut()

void chdrv_group_measure_pmut ( ch_group_t grp_ptr)

Measure the ultrasonic transducer frequency & bandwidth.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if error

This function initiates the calibration of the PMUT transducer to determine performance characteristics, including operating frequency and bandwidth.

◆ chdrv_group_measure_rtc()

void chdrv_group_measure_rtc ( ch_group_t grp_ptr)

Calibrate the sensor real-time clock against the host microcontroller clock.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors

This function sends a pulse (timed by the host MCU) on the INT line to each device in the group, then reads back the count of sensor RTC cycles that elapsed during that pulse on each individual device. The result is stored in the ch_dev_t descriptor structure for each device and is subsequently used during range calculations.

The length of the pulse is grp_ptr->rtc_cal_pulse_ms milliseconds (typically 100ms).

Note
The calibration pulse is sent to all devices in the group at the same time. Therefore all connected devices will see the same reference pulse length.
Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function sends a pulse (timed by the host MCU) on the INT line to each sensor device in the group, then reads back the counts of sensor RTC cycles that elapsed during that pulse on each individual device. The result is stored in the ch_dev_t config structure for each device and is subsequently used during range calculations.

The length of the pulse is dev_ptr->rtc_cal_pulse_ms milliseconds (typically 100). This value is set during ch_init().

Note
The calibration pulse is sent to all devices in the group at the same time. Therefore all connected devices will see the same reference pulse length.

◆ chdrv_group_measure_rtc_no_pulse()

void chdrv_group_measure_rtc_no_pulse ( ch_group_t grp_ptr)

Calibrate the sensor real-time clock without using a pulse.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors

This function is used when special RTC calibration using the I/O bus clock signal is used instead of a normal pulse on the INT line. So, this routine only places the sensor in calibration mode and then reads the result when complete.

A special opcode command is written to the normal pre-calibration "trigger" register, followed by a long dummy write transfer. During the dummy transfer, the sensor will perform its RTC calibration based on the I/O bus clock. The result is then read as in a normal calibration, except special handling is required to calculate the RTC frequency based on the result.

Note
This method is only supported in select sensor firmware variants.

◆ chdrv_group_prepare()

int chdrv_group_prepare ( ch_group_t grp_ptr)

Initialize data structures and hardware for sensor interaction and reset sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
Returns
0 if hardware initialization is successful, non-zero otherwise

This function is called internally by chdrv_group_start().

Initialize data structures and hardware for sensor interaction and reset sensors.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
num_portsthe total number of physical sensor ports available
Returns
0 if hardware initialization is successful, non-zero otherwise

This function is called internally by chdrv_group_start().

◆ chdrv_group_queue()

int chdrv_group_queue ( ch_group_t grp_ptr,
ch_dev_t dev_ptr,
uint8_t  rd_wrb,
uint8_t  type,
uint16_t  addr,
uint16_t  nbytes,
uint8_t *  data_ptr 
)

Add an I2C/SPI transaction to the non-blocking queue.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
instancepointer to an individual descriptor structure for a sensor
rd_wrbread/write indicator: 0 if write operation, 1 if read operation
typetransaction type: 0 = std, 1 = prog interface, 2 = external
addrI2C address for transfer
nbytesnumber of bytes to read/write
datapointer to buffer to receive data or containing data to send
Returns
0 if successful, non-zero otherwise
Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
dev_ptrpointer to an individual ch_dev_t config structure for a sensor
rd_wrbread/write indicator: 0 if write operation, 1 if read operation
typetype of transaction (standard, program interface, or external)
addrI2C address
nbytesnumber of bytes to read/write
data_ptrpointer to buffer to receive data or containing data to send
Returns
0 if successful, non-zero otherwise

◆ chdrv_group_soft_reset()

int chdrv_group_soft_reset ( ch_group_t grp_ptr)

Perform a soft reset on a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
Returns
0 if successful, non-zero otherwise

This function performs a soft reset on each device in a group of sensors by writing to a special control register.

Perform a soft reset on a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
Returns
0 if successful, non-zero otherwise

This function performs a soft reset on each device in a group of sensors by writing to a special control register.

◆ chdrv_group_start()

uint8_t chdrv_group_start ( ch_group_t grp_ptr)

Initialize and start a group of sensors.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
Returns
0 if successful, 1 if device doesn't respond

This function resets each sensor in programming mode, transfers the firmware image to the sensor's on-chip memory, and starts the sensor. For CH101 and CH201 sensors, the I2C address is changed from the default value.

In a normal startup, a timed pulse is sent on the INT line for real-time clock calibration. This may be over-ridden by specifying that default (factory) values should be used, or by supplying custom clock calibration values. Either of these options may be enabled by calling the ch_set_clock_cal() function before ch_group_start().

This function assumes firmware-specific initialization has already been performed for each ch_dev_t descriptor in the sensor group. (See ch_init()).

◆ chdrv_group_start_nb()

void chdrv_group_start_nb ( ch_group_t grp_ptr)

Start a non-blocking sensor readout.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors

This function starts a non-blocking I/O operation on the specified group of sensors.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function starts a non-blocking I/O operation on the specified group of sensors.

◆ chdrv_group_wait_for_lock()

int chdrv_group_wait_for_lock ( ch_group_t grp_ptr)

Wait for all sensors to finish start-up procedure.

Parameters
grp_ptrpointer to the ch_group_t descriptor structure for a group of sensors
Returns
0 if startup sequence finished on all detected sensors, non-zero if startup sequence timed out on any sensor(s).

After each sensor is programmed, it executes an internal start-up and self-test sequence. This function waits for all sensor devices to finish this sequence. For each device, the maximum time to wait is CHDRV_FREQLOCK_TIMEOUT_MS milliseconds.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
Returns
0 if startup sequence finished on all detected sensors, non-zero if startup sequence timed out on any sensor(s).

After each sensor is programmed, it executes an internal start-up and self-test sequence. This function waits for all sensor devices to finish this sequence. For each device, the maximum time to wait is CHDRV_FREQLOCK_TIMEOUT_MS milliseconds.

◆ chdrv_hw_trigger()

int chdrv_hw_trigger ( ch_dev_t dev_ptr)

Start a measurement in hardware triggered mode on one sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
Returns
0 if success, non-zero if dev_ptr pointer is invalid

This function starts a triggered measurement on a single sensor, by briefly asserting the INT line to the device. The sensor must have already been placed in hardware triggered mode before this function is called.

Note
This function requires implementing the optional chirp_bsp.h functions to control the INT pin direction and level for individual sensors (chbsp_set_int1_dir_in(), chbsp_set_int1_dir_out(), chbsp_int1_set(), and chbsp_int1_clear()).
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if dev_ptr pointer is invalid

This function starts a triggered measurement on a single sensor, by briefly asserting the INT line to the device. The sensor must have already been placed in hardware triggered mode before this function is called.

Note
This function requires implementing the optional BSP functions to control the INT pin direction and level for individual sensors (chbsp_set_int1_dir_in(), chbsp_set_int1_dir_out(), chbsp_int1_set(), and chbsp_int1_clear()).

◆ chdrv_init()

int chdrv_init ( ch_dev_t dev_ptr,
uint8_t  i2c_addr,
uint8_t  io_index,
uint8_t  bus_index,
uint16_t  part_number 
)

Initialize the sensor device configuration.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure to be initialized
i2c_addrFor CHx01 sensors, the I2C address to assign to this device. This will be the "application I2C address" used to access the device after it is initialized. Each sensor on an I2C interface must use a unique application I2C address. For ICU sensors, this field is ignored.
io_indexindex identifying this device. Each sensor in a group must have a unique io_index value.
bus_indexindex identifying the I2C/SPI interface (bus) to use with this device
part_numberinteger part number for sensor (e.g. 101 for CH101 device, or 20201 for ICU-20201))
Returns
0 (always)

This function initializes the ch_dev_t descriptor structure for the device with the specified values.

◆ chdrv_int_callback()

void chdrv_int_callback ( ch_group_t grp_ptr,
uint8_t  dev_num 
)

Driver callback routine for sensor interrupt.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
dev_numinterrupting sensor's device number within group

This function is called from ch_interrupt() when an interrupt from the sensor is received. The dev_num parameter indicates which sensor interrupted.

◆ chdrv_int_callback_deferred()

void chdrv_int_callback_deferred ( ch_group_t grp_ptr,
uint8_t  dev_num 
)

Driver callback deferred routine for sensor interrupt.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
dev_numinterrupting sensor's device number within group

This function is called from ch_interrupt() when an interrupt from the sensor is received. Or shall be called in app context if USE_DEFERRED_INTERRUPT_PROCESSING is defined. The dev_num parameter indicates which sensor interrupted.

For sensor data-ready interrupts, this routine will in turn call the application's callback routine which was set using ch_io_int_callback_set().

See also ch_io_int_callback_set()

◆ chdrv_int_group_assert()

void chdrv_int_group_assert ( ch_group_t grp_ptr)

Assert the interrupt lines for all sensors in a group.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function asserts the interrupt lines for all sensors in a group. For ICU sensors, the lines indicated by the current measurement configuration for interrupt pin (INT1 or INT2) will be set to a low (active) level. For CH101/CH201 sensors, the sensors' INT lines will be set to a high level.

This function calls the appropriate routine(s) in the the board support package to manipulate the line levels.

See also chdrv_trig_deassert(), chdrv_trig_group_assert()

◆ chdrv_int_group_deassert()

void chdrv_int_group_deassert ( ch_group_t grp_ptr)

De-assert the interrupt lines for all sensors in a group.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function de-asserts the interrupt lines for all sensors in a group. For ICU sensors, the lines indicated by the current measurement configuration for interrupt pin (INT1 or INT2) will be reset to a high (inactive) level. For CH101/CH201 sensors, the sensors' INT lines will be reset to a low level.

This function calls the appropriate routine(s) in the the board support package to manipulate the line levels.

See also chdrv_trig_deassert(), chdrv_trig_group_assert()

◆ chdrv_int_group_interrupt_disable()

void chdrv_int_group_interrupt_disable ( ch_group_t grp_ptr)

Disable interrupts on the interrupt lines for all sensors in a group.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function disables host micro-controller interrupts from being generated by all interrupt lines for sensors in the specified sensor group.

For ICU sensors, the lines indicated by the current measurement configuration for interrupt pin (INT1 or INT2) will have interrupts disabled. For CH101/CH201 sensors, the single INT lines will have interrupts disabled.

This function calls the appropriate routine(s) in the the board support package to disable interrupts.

See also chdrv_int_interrupt_disable, chdrv_int_group_interrupt_enable()

◆ chdrv_int_group_interrupt_enable()

void chdrv_int_group_interrupt_enable ( ch_group_t grp_ptr)

Enable interrupts on the interrupt lines for all sensors in a group.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function enables host micro-controller interrupts to be generated by all interrupt lines for sensors in the specified sensor group.

For ICU sensors, the lines indicated by the current measurement configuration for interrupt pin (INT1 or INT2) will have interrupts enabled. For CH101/CH201 sensors, the single INT lines will have interrupts enabled.

This function calls the appropriate routine(s) in the the board support package to enable interrupts.

See also chdrv_int_interrupt_enable, chdrv_int_group_interrupt_disable()

◆ chdrv_int_group_set_dir_in()

void chdrv_int_group_set_dir_in ( ch_group_t grp_ptr)

Configure the interrupt lines for all sensors in a group as inputs.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function configures the interrupt lines for all sensors in a group as input pins. For ICU sensors, the current measurement configuration for interrupt pin (INT1 or INT2) is used. For CH101/CH201 sensors, the single INT line is used.

This function calls the appropriate routine(s) in the the board support package to set the pin direction.

◆ chdrv_int_group_set_dir_out()

void chdrv_int_group_set_dir_out ( ch_group_t grp_ptr)

Configure the interrupt lines for all sensors in a group as outputs.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function configures the interrupt lines for all sensors in a group as output pins. For ICU sensors, the current measurement configuration for interrupt pin (INT1 or INT2) is used. For CH101/CH201 sensors, the single INT line is used.

This function calls the appropriate routine(s) in the the board support package to set the pin direction.

◆ chdrv_int_interrupt_disable()

void chdrv_int_interrupt_disable ( ch_dev_t dev_ptr)

Disable interrupts on the interrupt line for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor

This function disables host micro-controller interrupts from being generated by the specified sensor's interrupt line.

For ICU sensors, the line indicated by the current measurement configuration for interrupt pin (INT1 or INT2) will have interrupts disabled. For CH101/CH201 sensors, the single INT line will have interrupts disabled.

This function calls the appropriate routine(s) in the the board support package to disable interrupts.

See also chdrv_int_interrupt_enable(), chdrv_int_group_interrupt_disable()

◆ chdrv_int_interrupt_enable()

void chdrv_int_interrupt_enable ( ch_dev_t dev_ptr)

Enable interrupts on the interrupt line for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor

This function enables host micro-controller interrupts to be generated by the specified sensor's interrupt line.

For ICU sensors, the line indicated by the current measurement configuration for interrupt pin (INT1 or INT2) will have interrupts enabled. For CH101/CH201 sensors, the single INT line will have interrupts enabled.

This function calls the appropriate routine(s) in the the board support package to enable interrupts.

See also chdrv_int_interrupt_disable(), chdrv_int_group_interrupt_enable()

◆ chdrv_int_notify()

uint8_t chdrv_int_notify ( ch_group_t grp_ptr,
uint8_t  dev_num 
)

Notify SonicLib that a sensor interrupt was received.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
dev_numinterrupting sensor's device number within group
Returns
0 for success, non-zero otherwise.

This function should be called from the board support package when an interrupt from the sensor is received. The dev_num parameter indicates which sensor interrupted.

Unlike chdrv_int_callback(), this function does not call the user supplied callback. It is intended to be used when the user would like more control of exactly what happens when an interrupt is received from the sensor.

Other differences from chdrv_int_callback():

  • This function does not disable interrupt handling. This must be done in user code if needed.
  • This function does not read any metadata from the sensor, with one exception. During sensor programming, this funciton performs one SPI read in order to cause the ASIC to release the interrupt line.
  • This function does not update state of the dev_ptr

◆ chdrv_int_set_dir_in()

void chdrv_int_set_dir_in ( ch_dev_t dev_ptr)

Configure the interrupt line for a sensor as an input.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor

This function configures the specified sensor's interrupt line an an input pin. For ICU sensors, the current measurement configuration for interrupt pin (INT1 or INT2) is used. For CH101/CH201 sensors, the single INT line is used.

This function calls the appropriate routine(s) in the the board support package to set the pin direction.

◆ chdrv_meas_queue_read()

uint8_t chdrv_meas_queue_read ( ch_dev_t dev_ptr,
measurement_queue_t *  q_buf_ptr 
)

Read the measurement queue from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
q_buf_ptrpointer to the meas queue to write, NULL = update ch_dev_t copy
Returns
0 if success, non-zero if error

This function reads the measurement queue structure from the sensor and copies it to the location indiciated by q_buf_ptr.

If q_buf_ptr is NULL, the measurement queue copy in the ch_dev_t descriptor will be updated with the values read from the sensor. If q_buf_ptr is not NULL, the measurement queue values read from the device will be copied to the specified location.

◆ chdrv_meas_queue_write()

uint8_t chdrv_meas_queue_write ( ch_dev_t dev_ptr,
measurement_queue_t *  q_buf_ptr 
)

Write the measurement queue to a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
q_buf_ptrpointer to the meas queue to write, NULL = use ch_dev_t copy
Returns
0 if success, non-zero if error

This function writes a measurement queue structure to a sensor.

If q_buf_ptr is NULL, this function writes the local copy of the measurement queue structure in ch_dev_t to the sensor shared memory. It is typically used after some measurement settings have been modified. If q_buf_ptr is not NULL, the measurement queue values from the specified location will be written to the sensor. The copy in the ch_dev_t structure is not modified.

◆ chdrv_one_way_range()

uint32_t chdrv_one_way_range ( ch_dev_t dev_ptr,
uint16_t  tof,
uint16_t  tof_sf 
)

Convert the sensor register values to a range using the calibration data in the ch_dev_t struct.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
tofvalue of TOF register
tof_sfvalue of TOF_SF register
Returns
range in millimeters, or CH_NO_TARGET (0xFFFFFFFF) if no object is detected. The range result format is fixed point with 5 binary fractional digits (divide by 32 to convert to mm).

This function takes the time-of-flight and scale factor values from the sensor, and computes the actual one-way range based on the formulas given in the sensor datasheet.

Convert the sensor register values to a range using the calibration data in the ch_dev_t struct.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
tofvalue of sensor TOF register
tof_sfvalue of sensor TOF_SF register
Returns
range in millimeters, or CH_NO_TARGET (0xFFFFFFFF) if no object is detected.

The range result format is fixed point with 5 binary fractional digits (divide by 32 to convert to mm).

This function takes the time-of-flight and scale factor values from the sensor, and computes the actual one-way range based on the formulas given in the sensor datasheet.

◆ chdrv_otpmem_copy()

uint8_t chdrv_otpmem_copy ( ch_dev_t dev_ptr,
otp_copy_t *  otp_copy_ptr 
)

Copy OTP memory contents.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
otp_copy_ptraddress of otp_copy_t structure to receive OTP contents

This function reads the contents of the one-time programmable (OTP) memory in the sensor and copies the values to the structure specified by otp_copy_ptr.

Note
Before this function may be used the first time, the sensor must be instructed to copy the internal OTP values to a shared memory location accessible via SPI. The EVENT_COPY_OTP_TO_RAM event must be issued to the sensor to perform this operation.

See also chdrv_otpmem_read()

◆ chdrv_otpmem_read()

uint8_t chdrv_otpmem_read ( ch_dev_t dev_ptr)

Read OTP memory contents.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor

This function reads and processes the contents of the one-time programmable (OTP) memory in the sensor. The OTP memory contains unique information about the sensor device, such as the sensor lot and serial number, production date and location, and specific part and packaging information.

This function instructs the sensor to copy its internal OTP values to an SPI accessible location and reads the values using chdrv_otpmem_copy(). It then examines the contents to set various tracking values (sensor type, ID string, etc.).

See also chdrv_otpmem_copy(), ch_get_sensor_id(), ch_get_mfg_info()

◆ chdrv_pretrigger_delay_set()

void chdrv_pretrigger_delay_set ( ch_group_t grp_ptr,
uint16_t  delay_us 
)

Set the pre-trigger delay for rx-only sensors.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
delay_ustime to delay between triggering rx-only and tx/rx nodes, in microseconds

This function sets a delay interval that will be inserted between triggering rx-only sensors and tx/rx sensors. This delay allows the rx-only sensor(s) to settle from any startup disruption (e.g. PMUT "ringdown") before the ultrasound pulse is generated by the tx node.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors
delay_ustime to delay between triggering rx-only and tx/rx nodes, in microseconds

This function sets a delay interval that will be inserted between triggering rx-only sensor and tx/rx sensors. This delay allows the rx-only sensor(s) to settle from any startup disruption (e.g. PMUT "ringdown") before the ultrasound pulse is generated by the tx node.

◆ chdrv_prog_i2c_read()

int chdrv_prog_i2c_read ( ch_dev_t dev_ptr,
uint8_t *  message,
uint16_t  len 
)

Read bytes from a CHx01 device in programming mode.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
messagepointer to a buffer where read bytes will be placed
lennumber of bytes to read
Returns
0 if successful, non-zero otherwise

This function reads bytes from the device using the programming I2C address. The PROG line for the device must have been asserted before this function is called.

Read bytes from a CHx01 device in programming mode.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
messagepointer to a buffer where read bytes will be placed
lennumber of bytes to read
Returns
0 if successful, non-zero otherwise

This function reads bytes from the device using the programming I2C address. The PROG line for the device must have been asserted before this function is called.

◆ chdrv_prog_i2c_read_nb()

int chdrv_prog_i2c_read_nb ( ch_dev_t dev_ptr,
uint8_t *  message,
uint16_t  len 
)

Read bytes from a CHx01 device in programming mode, non-blocking.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
messagepointer to a buffer where read bytes will be placed
lennumber of bytes to read
Returns
0 if successful, non-zero otherwise

This function temporarily changes the device I2C address to the low-level programming interface, and issues a non-blocking read request. The PROG line for the device must have been asserted before this function is called.

Read bytes from a CHx01 device in programming mode, non-blocking.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
messagepointer to a buffer where read bytes will be placed
lennumber of bytes to read
Returns
0 if successful, non-zero otherwise

This function temporarily changes the device I2C address to the low-level programming interface, and issues a non-blocking read request. The PROG line for the device must have been asserted before this function is called.

◆ chdrv_prog_i2c_write()

int chdrv_prog_i2c_write ( ch_dev_t dev_ptr,
const uint8_t *  message,
uint16_t  len 
)

Write bytes to a CHx01 device in programming mode.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
messagepointer to a buffer containing the bytes to write
lennumber of bytes to write
Returns
0 if successful, non-zero otherwise

This function writes bytes to the device using the programming I2C address. The PROG line for the device must have been asserted before this function is called.

Write bytes to a CHx01 device in programming mode.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
messagepointer to a buffer containing the bytes to write
lennumber of bytes to write
Returns
0 if successful, non-zero otherwise

This function writes bytes to the device using the programming I2C address. The PROG line for the device must have been asserted before this function is called.

◆ chdrv_prog_mem_write()

int chdrv_prog_mem_write ( ch_dev_t dev_ptr,
uint16_t  addr,
const uint8_t *  message,
uint16_t  nbytes 
)

Write to CHx01 sensor memory.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
addrsensor programming register start address
messagepointer to data to transmit
nbytesnumber of bytes to write
Returns
0 if write to sensor succeeded, non-zero otherwise

This function writes to sensor memory using the low-level programming interface. The type of write is automatically determined based on data length and target address alignment.

Write to CHx01 sensor memory.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
addrsensor programming register start address
messagepointer to data to transmit
nbytesnumber of bytes to write
Returns
0 if write to sensor succeeded, non-zero otherwise

This function writes to sensor memory using the low-level programming interface. The type of write is automatically determined based on data length and target address alignment.

◆ chdrv_prog_ping()

int chdrv_prog_ping ( ch_dev_t dev_ptr)

Detect a connected sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
Returns
1 if sensor is found, 0 if no sensor is found

This function checks for a sensor on the I2C bus by attempting to reset, halt, and read from the device using the programming interface I2C address (0x45).

In order for the device to respond, the PROG pin for the device must be asserted before this function is called. If there are multiple sensors in an application, only one device's PROG pin should be active at any time.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
1 if sensor is found, 0 if no sensor is found

This function checks for a sensor sensor on the I2C bus by attempting to reset, halt, and read from the device using the programming interface I2C address (0x45).

In order for the device to respond, the PROG pin for the device must be asserted before this function is called.

◆ chdrv_prog_write()

int chdrv_prog_write ( ch_dev_t dev_ptr,
uint8_t  reg_addr,
uint16_t  data 
)

Write to a CHx01 programming register.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
reg_addrsensor programming register address.
data8-bit or 16-bit data to transmit.
Returns
0 if write to sensor succeeded, non-zero otherwise

This function writes a value to a sensor programming register.

Write to a CHx01 programming register.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
reg_addrsensor programming register address.
data8-bit or 16-bit data to transmit.
Returns
0 if write to sensor succeeded, non-zero otherwise

This local function writes a value to a sensor programming register.

◆ chdrv_read_buf_addr()

int chdrv_read_buf_addr ( ch_dev_t dev_ptr)

Read the IQ buffer address from the sensor and store in dev_ptr.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
Returns
0 if successful, non-zero otherwise

◆ chdrv_read_byte()

int chdrv_read_byte ( ch_dev_t dev_ptr,
uint16_t  mem_addr,
uint8_t *  data_ptr 
)

Read byte from a sensor application register.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
mem_addrsensor memory/register address
datapointer to receive buffer
Returns
0 if successful, non-zero otherwise
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
mem_addrsensor memory/register address
data_ptrpointer to receive buffer
Returns
0 if successful, non-zero otherwise

◆ chdrv_read_word()

int chdrv_read_word ( ch_dev_t dev_ptr,
uint16_t  mem_addr,
uint16_t *  data_ptr 
)

Read 16 bits from a sensor application register.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
mem_addrsensor memory/register address
datapointer to receive buffer
Returns
0 if successful, non-zero otherwise
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
mem_addrsensor memory/register address
data_ptrpointer to receive buffer
Returns
0 if successful, non-zero otherwise

◆ chdrv_restart()

int chdrv_restart ( ch_dev_t dev_ptr)

Restart a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if successful, non-zero otherwise

This function restarts a single sensor, using previously stored initialization values.

◆ chdrv_round_trip_range()

uint32_t chdrv_round_trip_range ( ch_dev_t dev_ptr,
uint16_t  tof,
uint16_t  tof_sf 
)

Convert the sensor register values to a round-trip range using the calibration data in the ch_dev_t struct.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
tofvalue of TOF register
tof_sfvalue of TOF_SF register
Returns
range in millimeters, or CH_NO_TARGET (0xFFFFFFFF) if no object is detected. The range result format is fixed point with 5 binary fractional digits (divide by 32 to convert to mm).

This function takes the time-of-flight and scale factor values from the sensor, and computes the actual round-trip range based on the formulas given in the sensor datasheet.

◆ chdrv_run_bist()

uint8_t chdrv_run_bist ( ch_dev_t dev_ptr)

Run built-in self test (BIST) on sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if success, non-zero if error

This function initiates the build-in self test (BIST) on a sensor.

Run built-in self test (BIST) on sensor.

Parameters
dev_ptrpointer to the ch_dev_t device descriptor for a sensor

◆ chdrv_set_idle()

int chdrv_set_idle ( ch_dev_t dev_ptr)

Put CHx01 sensor(s) in idle state.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
Returns
0 if successful, non-zero otherwise

This function places the sensor processor in a known state by loading an idle loop instruction sequence. This is used only during early initialization of the device. This is NOT the same as putting a running device into "idle mode" (CH_MODE_IDLE) by using the ch_set_mode() function.

Put CHx01 sensor(s) in idle state.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor, used to identify the target I2C bus
Returns
0 if successful, non-zero on error

This function loads a tiny idle loop program to all ASICs on a given i2c bus. This function assumes that all of the devices on the given bus are halted in programming mode (i.e. PROG line is asserted).

Note
This routine writes to all devices simultaneously, so I2C signalling (i.e. ack's) on the bus may be driven by multiple slaves at once.

◆ chdrv_soft_reset()

int chdrv_soft_reset ( ch_dev_t dev_ptr)

Perform a soft reset on a sensor.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
mem_addrsensor memory/register address
Returns
0 if successful, non-zero otherwise

This function performs a soft reset on an individual sensor by writing to a special control register.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
Returns
0 if successful, non-zero otherwise

This function performs a soft reset on an individual sensor by writing to a special control register.

◆ chdrv_sys_ctrl_read()

uint8_t chdrv_sys_ctrl_read ( ch_dev_t dev_ptr,
uint8_t *  reg_value_ptr 
)

Read the system control register from a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
reg_value_ptrpointer to location to receive register value
Returns
0 if register read succeeded, non-zero otherwise

This function reads the system control register from an ICU sensor and returns the value in the location specified by reg_value_ptr.

◆ chdrv_sys_ctrl_write()

uint8_t chdrv_sys_ctrl_write ( ch_dev_t dev_ptr,
uint8_t  reg_value 
)

Write the system control register in a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
reg_valueregister value to write
Returns
0 if register write succeeded, non-zero otherwise

This function writes reg_value to the system control register in an ICU sensor.

Returns
0 if register write succeeded, non-zero otherwise

◆ chdrv_trig_assert()

void chdrv_trig_assert ( ch_dev_t dev_ptr)

Assert the hardware trigger line for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor

This function asserts the specified sensor's h/w trigger line to initiate a measurement. For ICU sensors, the line indicated by the current measurement configuration for trigger pin (INT1 or INT2) will be set to a low (active) level. For CH101/CH201 sensors, the single INT line will be set to a high level.

This function calls the appropriate routine(s) in the the board support package to manipulate the line levels.

See also chdrv_group_trig_assert(), chdrv_trig_deassert()

◆ chdrv_trig_deassert()

void chdrv_trig_deassert ( ch_dev_t dev_ptr)

De-assert the hardware trigger line for a sensor.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor

This function de-asserts the specified sensor's h/w trigger line used to initiate a measurement. For ICU sensors, the line indicated by the current measurement configuration for trigger pin (INT1 or INT2) will be reset to a high (inactive) level. For CH101/CH201 sensors, the single INT line will be reset to a low level.

This function calls the appropriate routine(s) in the the board support package to manipulate the line levels.

See also chdrv_group_trig_assert(), chdrv_trig_assert()

◆ chdrv_trig_group_assert()

void chdrv_trig_group_assert ( ch_group_t grp_ptr)

Assert the hardware trigger lines for all sensors in a group.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function asserts the h/w trigger lines for all sensors in a group to initiate a measurement. For ICU sensors, the line indicated by the current measurement configuration for trigger pin (INT1 or INT2) will be set to a low (active) level. For CH101/CH201 sensors, the sensors' INT lines will be set to a high level.

This function calls the appropriate routine(s) in the the board support package to manipulate the line levels.

See also chdrv_trig_assert(), chdrv_trig_group_deassert()

◆ chdrv_trig_group_deassert()

void chdrv_trig_group_deassert ( ch_group_t grp_ptr)

De-assert the hardware trigger lines for all sensors in a group.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function de-asserts the h/w trigger lines for all sensors in a group. For ICU sensors, the lines indicated by the current measurement configuration for trigger pin (INT1 or INT2) will be reset to a high (inactive) level. For CH101/CH201 sensors, the sensors' INT lines will be reset to a low level.

This function calls the appropriate routine(s) in the the board support package to manipulate the line levels.

See also chdrv_trig_deassert(), chdrv_trig_group_assert()

◆ chdrv_trig_group_set_dir_out()

void chdrv_trig_group_set_dir_out ( ch_group_t grp_ptr)

Configure the hardware trigger lines for all sensors in a group as outputs.

Parameters
grp_ptrpointer to the ch_group_t config structure for a group of sensors

This function configures the h/w trigger lines for all sensors in a group as output pins. For ICU sensors, the current measurement configuration for trigger pin (INT1 or INT2) is used. For CH101/CH201 sensors, the single INT line is used.

This function calls the appropriate routine(s) in the the board support package to set the pin direction.

◆ chdrv_trig_set_dir_out()

void chdrv_trig_set_dir_out ( ch_dev_t dev_ptr)

Configure the hardware trigger line for a sensor as an output.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor

This function configures the specified sensor's h/w trigger line an an output pin. For ICU sensors, the current measurement configuration for trigger pin (INT1 or INT2) is used. For CH101/CH201 sensors, the single INT line is used.

This function calls the appropriate routine(s) in the the board support package to set the pin direction.

◆ chdrv_wait_for_lock()

int chdrv_wait_for_lock ( ch_dev_t dev_ptr,
uint16_t  timeout_ms 
)

Wait for an individual sensor to finish start-up procedure.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
timeout_msnumber of milliseconds to wait for sensor to finish start-up before returning failure
Returns
0 if startup sequence finished, non-zero if startup sequence timed out or sensor is not connected

After the sensor is programmed, it executes an internal start-up and self-test sequence. This function waits the specified time in milliseconds for the sensor to finish this sequence.

Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
timeout_msnumber of milliseconds to wait for sensor to finish start-up before returning failure
Returns
0 if startup sequence finished, non-zero if startup sequence timed out or sensor is not connected

After the sensor is programmed, it executes an internal start-up and self-test sequence. This function waits the specified time in milliseconds for the sensor to finish this sequence.

◆ chdrv_write_byte()

int chdrv_write_byte ( ch_dev_t dev_ptr,
uint16_t  mem_addr,
uint8_t  data_value 
)

Write byte to a sensor application register.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
reg_addrregister address
datadata value to transmit
Returns
0 if successful, non-zero otherwise
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
mem_addrsensor memory/register address
data_valuedata value to transmit
Returns
0 if successful, non-zero otherwise

◆ chdrv_write_word()

int chdrv_write_word ( ch_dev_t dev_ptr,
uint16_t  mem_addr,
uint16_t  data_value 
)

Write 16 bits to a sensor application register.

Parameters
dev_ptrpointer to the ch_dev_t descriptor structure for a sensor
mem_addrsensor memory/register address
datadata value to transmit
Returns
0 if successful, non-zero otherwise
Parameters
dev_ptrpointer to the ch_dev_t config structure for a sensor
reg_addrsensor register address
data_valuedata value to transmit
Returns
0 if successful, non-zero otherwise