Chirp SonicLib
4.5.2
|
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... | |
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... | |
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.
#define CH_PROG_ADDR_DEV_I2C_ADDR_REG (0x01C5) |
Device own I2C addr register address
#define CH_PROG_ADDR_IDLE_LOC (CHX01_PROG_MEM_ADDR + CHX01_PROG_MEM_SIZE - 4) |
IDLE loop location
#define CH_PROG_ADDR_PMUT_CNTRL4_REG (0x01A6) |
PMUT CNTRL4 register address
#define CH_PROG_ADDR_WDT_REG (0x0120) |
Watchdog register address
#define CH_PROG_REG_ADDR 0x05 |
Data transfer starting address register address.
#define CH_PROG_REG_CNT 0x07 |
Data transfer size register address.
#define CH_PROG_REG_CPU 0x42 |
Processor control register address.
#define CH_PROG_REG_CTL 0x44 |
Data transfer control register address.
#define CH_PROG_REG_DATA 0x06 |
Data transfer value register address.
#define CH_PROG_REG_PING 0x00 |
Read-only register used during device discovery.
#define CH_PROG_REG_STAT 0x43 |
Processor status register address.
#define CH_PROG_SIZEOF | ( | R | ) | ((R)&0x40 ? 1 : 2) |
Macro to determine programming register size.
#define CH_PROG_XFER_SIZE (256) |
max size of a read operation via programming interface
#define CHDRV_BANDWIDTH_INDEX_1 6 |
Index of first sample to use for calculating bandwidth.
#define CHDRV_BANDWIDTH_INDEX_2 (CHDRV_BANDWIDTH_INDEX_1 + 1) |
Index of second sample to \ use for calculating bandwidth.
#define CHDRV_DEBUG_PIN_NUM (0) |
debug pin number (index) to use for debug indication
#define CHDRV_DELAY_OVERHEAD_US (0) |
Tuning parameter to adjust pre-trigger timing
#define CHDRV_EVENT_TIMEOUT_MS (750) |
Max time to wait for sensor event, in ms
#define CHDRV_FREQLOCK_TIMEOUT_MS 100 |
Time to wait in chdrv_group_start() for sensor \ initialization, in milliseconds.
#define CHDRV_I2C_MAX_WRITE_BYTES 256 |
maximum number of bytes in a single I2C write
#define CHDRV_I2C_SPEED_DEFAULT_HZ (400000) |
Default I2C speed assumed if CHIRP_I2C_SPEED_HZ not defined in BSP
#define CHDRV_MAX_QUEUE_LENGTH CHIRP_MAX_NUM_SENSORS |
Max queued non-blocking I2C/SPI transactions - value from chirp_board_config.h
#define CHDRV_NB_TRANS_TYPE_EXTERNAL (2) |
externally requested non-blocking I/O transaction
#define CHDRV_NB_TRANS_TYPE_PROG (1) |
non-blocking I/O via low-level programming interface
#define CHDRV_NB_TRANS_TYPE_STD (0) |
standard non-blocking I/O transaction
#define CHDRV_POST_ALGO_INIT_DELAY_MS 3 |
Time to delay after triggering algorithm init on sensor, in ms
#define CHDRV_POST_TRIG_IEN_DELAY_US 10 |
Time to delay after triggering shared int/trig before re-enabling interrupt
#define CHDRV_PRETRIGGER_DELAY_US 600 |
Time to delay between triggering rx-only and tx/rx nodes, in us
#define CHDRV_SCALEFACTOR_INDEX 4 |
Index for calculating scalefactor.
#define CHDRV_TRIGGER_PULSE_US 5 |
Length of INT pulse to trigger sensor, in microseconds - minimum 800ns.
uint8_t chdrv_algo_cfg_read | ( | ch_dev_t * | dev_ptr, |
void * | algo_cfg_ptr | ||
) |
Read the algorithm configuration data from a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
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.
uint8_t chdrv_algo_cfg_write | ( | ch_dev_t * | dev_ptr, |
const void * | algo_cfg_ptr | ||
) |
Write the algorithm configuration data to a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
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.
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function reads the algorithm information data for an algorithm that has been programmed into an ICU sensor.
uint8_t chdrv_algo_init | ( | ch_dev_t * | dev_ptr | ) |
Initialize the measurement algorithm on a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function initializes a measurement algorithm that has already been programmed into an ICU sensor.
uint8_t chdrv_algo_out_read | ( | ch_dev_t * | dev_ptr, |
void * | algo_out_ptr | ||
) |
Read the algorithm output data from a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
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.
uint8_t chdrv_algo_state_read | ( | ch_dev_t * | dev_ptr, |
void * | algo_state_ptr | ||
) |
Read the algorithm state data from a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
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.
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.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
mem_addr | sensor memory/register address |
data | pointer to receive buffer |
len | number of bytes to read |
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | sensor memory/register address |
data_ptr | pointer to receive buffer |
num_bytes | number of bytes to read |
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.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
mem_addr | sensor memory/register address |
data | pointer to transmit buffer containing data to send |
num_bytes | number of bytes to write |
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | sensor memory/register address |
data_ptr | pointer to transmit buffer containing data to send |
len | number of bytes to write |
uint8_t chdrv_check_reset_state | ( | ch_dev_t * | dev_ptr, |
uint8_t * | reset_state_ptr | ||
) |
Check if sensor reset has occurred.
dev_ptr | pointer to the ch_dev_t descriptor structure |
reset_state_ptr | pointer to variable that will be updated with 0 = No Reset, 1 = Reset has occurred. |
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.
uint32_t chdrv_cpu_freq_adjust | ( | ch_dev_t * | dev_ptr, |
uint32_t | pmut_freq | ||
) |
Adjust sensor micro-controller CPU frequency.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
pmut_freq | PMUT transducer frequency, 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()
uint32_t chdrv_cpu_freq_calculate | ( | ch_dev_t * | dev_ptr | ) |
Calculate sensor micro-controller CPU frequency, in Hz.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function calculates and returns the processor frequency, in Hz, of the internal micro-controller in the sensor.
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
reg_value_ptr | pointer to location to receive register value |
This function reads the debug register from an ICU sensor and returns the value in the location specified by reg_value_ptr.
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
reg_value | register value to write |
This function writes reg_value to the debug register in an ICU sensor.
int chdrv_detect_and_program | ( | ch_dev_t * | dev_ptr | ) |
Detect, program, and start a sensor.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
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.
uint8_t chdrv_event_trigger | ( | ch_dev_t * | dev_ptr, |
uint16_t | event | ||
) |
Trigger an event on a sensor and return immediately.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
event | event 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()
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
event | event 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()
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.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
instance | pointer to the ch_dev_t descriptor structure for a sensor |
rd_wrb | read/write indicator: 0 if write operation, 1 if read operation |
addr | I2C address for transfer (for I2C devices only) |
nbytes | number of bytes to read/write |
data | pointer to buffer to receive data or containing data to send |
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.
int chdrv_group_detect_and_program | ( | ch_group_t * | grp_ptr | ) |
Detect, program, and start all sensors in a group.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
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.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
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.
int chdrv_group_hard_reset | ( | ch_group_t * | grp_ptr | ) |
Perform a hard reset on a group of sensors.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
This function performs a hardware reset on each device in a group of sensors by asserting each device's RESET_N pin.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
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.
int chdrv_group_hw_trigger | ( | ch_group_t * | grp_ptr | ) |
Start a measurement in hardware triggered mode.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
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.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
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.
void chdrv_group_irq_handler | ( | ch_group_t * | grp_ptr, |
uint8_t | bus_index | ||
) |
Continue a non-blocking readout.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
bus_index | index 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.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
bus_index | index 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.
void chdrv_group_measure_pmut | ( | ch_group_t * | grp_ptr | ) |
Measure the ultrasonic transducer frequency & bandwidth.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function initiates the calibration of the PMUT transducer to determine performance characteristics, including operating frequency and bandwidth.
void chdrv_group_measure_rtc | ( | ch_group_t * | grp_ptr | ) |
Calibrate the sensor real-time clock against the host microcontroller clock.
grp_ptr | pointer 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).
grp_ptr | pointer 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().
void chdrv_group_measure_rtc_no_pulse | ( | ch_group_t * | grp_ptr | ) |
Calibrate the sensor real-time clock without using a pulse.
grp_ptr | pointer 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.
int chdrv_group_prepare | ( | ch_group_t * | grp_ptr | ) |
Initialize data structures and hardware for sensor interaction and reset sensors.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
This function is called internally by chdrv_group_start().
Initialize data structures and hardware for sensor interaction and reset sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
num_ports | the total number of physical sensor ports available |
This function is called internally by chdrv_group_start().
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.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
instance | pointer to an individual descriptor structure for a sensor |
rd_wrb | read/write indicator: 0 if write operation, 1 if read operation |
type | transaction type: 0 = std, 1 = prog interface, 2 = external |
addr | I2C address for transfer |
nbytes | number of bytes to read/write |
data | pointer to buffer to receive data or containing data to send |
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
dev_ptr | pointer to an individual ch_dev_t config structure for a sensor |
rd_wrb | read/write indicator: 0 if write operation, 1 if read operation |
type | type of transaction (standard, program interface, or external) |
addr | I2C address |
nbytes | number of bytes to read/write |
data_ptr | pointer to buffer to receive data or containing data to send |
int chdrv_group_soft_reset | ( | ch_group_t * | grp_ptr | ) |
Perform a soft reset on a group of sensors.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
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.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function performs a soft reset on each device in a group of sensors by writing to a special control register.
uint8_t chdrv_group_start | ( | ch_group_t * | grp_ptr | ) |
Initialize and start a group of sensors.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
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()).
void chdrv_group_start_nb | ( | ch_group_t * | grp_ptr | ) |
Start a non-blocking sensor readout.
grp_ptr | pointer 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.
grp_ptr | pointer 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.
int chdrv_group_wait_for_lock | ( | ch_group_t * | grp_ptr | ) |
Wait for all sensors to finish start-up procedure.
grp_ptr | pointer to the ch_group_t descriptor structure for a group of sensors |
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.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
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.
int chdrv_hw_trigger | ( | ch_dev_t * | dev_ptr | ) |
Start a measurement in hardware triggered mode on one sensor.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
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.
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.
dev_ptr | pointer to the ch_dev_t descriptor structure to be initialized |
i2c_addr | For 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_index | index identifying this device. Each sensor in a group must have a unique io_index value. |
bus_index | index identifying the I2C/SPI interface (bus) to use with this device |
part_number | integer part number for sensor (e.g. 101 for CH101 device, or 20201 for ICU-20201)) |
This function initializes the ch_dev_t descriptor structure for the device with the specified values.
void chdrv_int_callback | ( | ch_group_t * | grp_ptr, |
uint8_t | dev_num | ||
) |
Driver callback routine for sensor interrupt.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
dev_num | interrupting 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.
void chdrv_int_callback_deferred | ( | ch_group_t * | grp_ptr, |
uint8_t | dev_num | ||
) |
Driver callback deferred routine for sensor interrupt.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
dev_num | interrupting 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()
void chdrv_int_group_assert | ( | ch_group_t * | grp_ptr | ) |
Assert the interrupt lines for all sensors in a group.
grp_ptr | pointer 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.
void chdrv_int_group_deassert | ( | ch_group_t * | grp_ptr | ) |
De-assert the interrupt lines for all sensors in a group.
grp_ptr | pointer 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.
void chdrv_int_group_interrupt_disable | ( | ch_group_t * | grp_ptr | ) |
Disable interrupts on the interrupt lines for all sensors in a group.
grp_ptr | pointer 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()
void chdrv_int_group_interrupt_enable | ( | ch_group_t * | grp_ptr | ) |
Enable interrupts on the interrupt lines for all sensors in a group.
grp_ptr | pointer 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()
void chdrv_int_group_set_dir_in | ( | ch_group_t * | grp_ptr | ) |
Configure the interrupt lines for all sensors in a group as inputs.
grp_ptr | pointer 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.
void chdrv_int_group_set_dir_out | ( | ch_group_t * | grp_ptr | ) |
Configure the interrupt lines for all sensors in a group as outputs.
grp_ptr | pointer 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.
void chdrv_int_interrupt_disable | ( | ch_dev_t * | dev_ptr | ) |
Disable interrupts on the interrupt line for a sensor.
dev_ptr | pointer 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()
void chdrv_int_interrupt_enable | ( | ch_dev_t * | dev_ptr | ) |
Enable interrupts on the interrupt line for a sensor.
dev_ptr | pointer 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()
uint8_t chdrv_int_notify | ( | ch_group_t * | grp_ptr, |
uint8_t | dev_num | ||
) |
Notify SonicLib that a sensor interrupt was received.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
dev_num | interrupting sensor's device number within group |
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():
void chdrv_int_set_dir_in | ( | ch_dev_t * | dev_ptr | ) |
Configure the interrupt line for a sensor as an input.
dev_ptr | pointer 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.
uint8_t chdrv_meas_queue_read | ( | ch_dev_t * | dev_ptr, |
measurement_queue_t * | q_buf_ptr | ||
) |
Read the measurement queue from a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
q_buf_ptr | pointer to the meas queue to write, NULL = update ch_dev_t copy |
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.
uint8_t chdrv_meas_queue_write | ( | ch_dev_t * | dev_ptr, |
measurement_queue_t * | q_buf_ptr | ||
) |
Write the measurement queue to a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
q_buf_ptr | pointer to the meas queue to write, NULL = use ch_dev_t copy |
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.
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.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
tof | value of TOF register |
tof_sf | value of TOF_SF register |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
tof | value of sensor TOF register |
tof_sf | value of sensor TOF_SF register |
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.
uint8_t chdrv_otpmem_copy | ( | ch_dev_t * | dev_ptr, |
otp_copy_t * | otp_copy_ptr | ||
) |
Copy OTP memory contents.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
otp_copy_ptr | address 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.
See also chdrv_otpmem_read()
uint8_t chdrv_otpmem_read | ( | ch_dev_t * | dev_ptr | ) |
Read OTP memory contents.
dev_ptr | pointer 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()
void chdrv_pretrigger_delay_set | ( | ch_group_t * | grp_ptr, |
uint16_t | delay_us | ||
) |
Set the pre-trigger delay for rx-only sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
delay_us | time 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.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
delay_us | time 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.
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
message | pointer to a buffer where read bytes will be placed |
len | number of bytes to read |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
message | pointer to a buffer where read bytes will be placed |
len | number of bytes to read |
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.
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
message | pointer to a buffer where read bytes will be placed |
len | number of bytes to read |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
message | pointer to a buffer where read bytes will be placed |
len | number of bytes to read |
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.
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
message | pointer to a buffer containing the bytes to write |
len | number of bytes to write |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
message | pointer to a buffer containing the bytes to write |
len | number of bytes to write |
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.
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
addr | sensor programming register start address |
message | pointer to data to transmit |
nbytes | number of bytes to write |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
addr | sensor programming register start address |
message | pointer to data to transmit |
nbytes | number of bytes to write |
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.
int chdrv_prog_ping | ( | ch_dev_t * | dev_ptr | ) |
Detect a connected sensor.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
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.
int chdrv_prog_write | ( | ch_dev_t * | dev_ptr, |
uint8_t | reg_addr, | ||
uint16_t | data | ||
) |
Write to a CHx01 programming register.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
reg_addr | sensor programming register address. |
data | 8-bit or 16-bit data to transmit. |
This function writes a value to a sensor programming register.
Write to a CHx01 programming register.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
reg_addr | sensor programming register address. |
data | 8-bit or 16-bit data to transmit. |
This local function writes a value to a sensor programming register.
int chdrv_read_buf_addr | ( | ch_dev_t * | dev_ptr | ) |
Read the IQ buffer address from the sensor and store in dev_ptr.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
int chdrv_read_byte | ( | ch_dev_t * | dev_ptr, |
uint16_t | mem_addr, | ||
uint8_t * | data_ptr | ||
) |
Read byte from a sensor application register.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
mem_addr | sensor memory/register address |
data | pointer to receive buffer |
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | sensor memory/register address |
data_ptr | pointer to receive buffer |
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.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
mem_addr | sensor memory/register address |
data | pointer to receive buffer |
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | sensor memory/register address |
data_ptr | pointer to receive buffer |
int chdrv_restart | ( | ch_dev_t * | dev_ptr | ) |
Restart a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function restarts a single sensor, using previously stored initialization values.
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.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
tof | value of TOF register |
tof_sf | value of TOF_SF register |
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.
uint8_t chdrv_run_bist | ( | ch_dev_t * | dev_ptr | ) |
Run built-in self test (BIST) on sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function initiates the build-in self test (BIST) on a sensor.
Run built-in self test (BIST) on sensor.
dev_ptr | pointer to the ch_dev_t device descriptor for a sensor |
int chdrv_set_idle | ( | ch_dev_t * | dev_ptr | ) |
Put CHx01 sensor(s) in idle state.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor, used to identify the target I2C bus |
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).
int chdrv_soft_reset | ( | ch_dev_t * | dev_ptr | ) |
Perform a soft reset on a sensor.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
mem_addr | sensor memory/register address |
This function performs a soft reset on an individual sensor by writing to a special control register.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function performs a soft reset on an individual sensor by writing to a special control register.
uint8_t chdrv_sys_ctrl_read | ( | ch_dev_t * | dev_ptr, |
uint8_t * | reg_value_ptr | ||
) |
Read the system control register from a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
reg_value_ptr | pointer to location to receive register value |
This function reads the system control register from an ICU sensor and returns the value in the location specified by reg_value_ptr.
uint8_t chdrv_sys_ctrl_write | ( | ch_dev_t * | dev_ptr, |
uint8_t | reg_value | ||
) |
Write the system control register in a sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
reg_value | register value to write |
This function writes reg_value to the system control register in an ICU sensor.
void chdrv_trig_assert | ( | ch_dev_t * | dev_ptr | ) |
Assert the hardware trigger line for a sensor.
dev_ptr | pointer 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()
void chdrv_trig_deassert | ( | ch_dev_t * | dev_ptr | ) |
De-assert the hardware trigger line for a sensor.
dev_ptr | pointer 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()
void chdrv_trig_group_assert | ( | ch_group_t * | grp_ptr | ) |
Assert the hardware trigger lines for all sensors in a group.
grp_ptr | pointer 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.
void chdrv_trig_group_deassert | ( | ch_group_t * | grp_ptr | ) |
De-assert the hardware trigger lines for all sensors in a group.
grp_ptr | pointer 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.
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.
grp_ptr | pointer 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.
void chdrv_trig_set_dir_out | ( | ch_dev_t * | dev_ptr | ) |
Configure the hardware trigger line for a sensor as an output.
dev_ptr | pointer 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.
int chdrv_wait_for_lock | ( | ch_dev_t * | dev_ptr, |
uint16_t | timeout_ms | ||
) |
Wait for an individual sensor to finish start-up procedure.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
timeout_ms | number of milliseconds to wait for sensor to finish start-up before returning failure |
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.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
timeout_ms | number of milliseconds to wait for sensor to finish start-up before returning failure |
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.
int chdrv_write_byte | ( | ch_dev_t * | dev_ptr, |
uint16_t | mem_addr, | ||
uint8_t | data_value | ||
) |
Write byte to a sensor application register.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
reg_addr | register address |
data | data value to transmit |
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | sensor memory/register address |
data_value | data value to transmit |
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.
dev_ptr | pointer to the ch_dev_t descriptor structure for a sensor |
mem_addr | sensor memory/register address |
data | data value to transmit |
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
reg_addr | sensor register address |
data_value | data value to transmit |