Chirp SonicLib
4.5.2
|
User-supplied board support package functions to interface Chirp SonicLib to a specific hardware platform. More...
Go to the source code of this file.
Functions | |
void | chbsp_debug_off (uint8_t dbg_pin_num) |
Turn off a debug indicator pin. More... | |
void | chbsp_debug_on (uint8_t dbg_pin_num) |
Turn on a debug indicator pin. More... | |
void | chbsp_debug_toggle (uint8_t dbg_pin_num) |
Toggle a debug indicator pin. More... | |
void | chbsp_delay_ms (uint32_t ms) |
Delay for specified number of milliseconds. More... | |
void | chbsp_delay_us (uint32_t us) |
Delay for specified number of microseconds. More... | |
void | chbsp_event_notify (uint32_t event_mask) |
Notify an interrupt event for the selected device. More... | |
uint8_t | chbsp_event_wait (uint16_t time_out_ms, uint32_t event_mask) |
Wait for any interrupt event. More... | |
void | chbsp_event_wait_setup (uint32_t event_mask) |
Prepare the mechanism to wait for an event. More... | |
void | chbsp_external_irq_handler (chdrv_transaction_t *trans) |
Interrupt handler callout for external devices sharing the SPI/I2C bus. More... | |
void | chbsp_group_int1_clear (ch_group_t *grp_ptr) |
Set the INT1 pins low for a group of sensors. More... | |
void | chbsp_group_int1_interrupt_disable (ch_group_t *grp_ptr) |
Disable INT1 interrupts for a group of sensors. More... | |
void | chbsp_group_int1_interrupt_enable (ch_group_t *grp_ptr) |
Enable INT1 interrupts for a group of sensors. More... | |
void | chbsp_group_int1_set (ch_group_t *grp_ptr) |
Set the INT1 pins high for a group of sensors. More... | |
void | chbsp_group_int2_clear (ch_group_t *grp_ptr) |
Set the INT2 pins as inactive for a group of sensors. More... | |
void | chbsp_group_int2_interrupt_disable (ch_group_t *grp_ptr) |
Disable INT2 interrupts for a group of sensors. More... | |
void | chbsp_group_int2_interrupt_enable (ch_group_t *grp_ptr) |
Enable INT2 interrupts for a group of sensors. More... | |
void | chbsp_group_int2_set (ch_group_t *grp_ptr) |
Set the INT2 pins high for a group of sensors. More... | |
void | chbsp_group_set_int1_dir_in (ch_group_t *grp_ptr) |
Configure the Chirp sensor INT1 pins as inputs for a group of sensors. More... | |
void | chbsp_group_set_int1_dir_out (ch_group_t *grp_ptr) |
Configure the Chirp sensor INT1 pin as an output for a group of sensors. More... | |
void | chbsp_group_set_int2_dir_in (ch_group_t *grp_ptr) |
Configure the Chirp sensor INT2 pins as inputs for a group of sensors. More... | |
void | chbsp_group_set_int2_dir_out (ch_group_t *grp_ptr) |
Configure the Chirp sensor INT2 pin as an output for a group of sensors. More... | |
uint8_t | chbsp_i2c_get_info (ch_group_t *grp_ptr, uint8_t dev_num, ch_i2c_info_t *info_ptr) |
Return I2C information for a sensor port on the board. More... | |
int | chbsp_i2c_init (void) |
Initialize the host's I2C hardware. More... | |
int | chbsp_i2c_mem_read (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t *data, uint16_t num_bytes) |
Read bytes from an I2C slave using memory addressing. More... | |
int | chbsp_i2c_mem_read_nb (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t *data, uint16_t num_bytes) |
Read bytes from an I2C slave using memory addressing, non-blocking. More... | |
int | chbsp_i2c_mem_write (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t *data, uint16_t num_bytes) |
Write bytes to an I2C slave using memory addressing. More... | |
int | chbsp_i2c_mem_write_nb (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t *data, uint16_t num_bytes) |
Write bytes to an I2C slave using memory addressing, non-blocking. More... | |
int | chbsp_i2c_read (ch_dev_t *dev_ptr, uint8_t *data, uint16_t num_bytes) |
Read bytes from an I2C slave. More... | |
int | chbsp_i2c_read_nb (ch_dev_t *dev_ptr, uint8_t *data, uint16_t num_bytes) |
Read bytes from an I2C slave, non-blocking. More... | |
void | chbsp_i2c_reset (ch_dev_t *dev_ptr) |
Reset I2C bus associated with device. More... | |
int | chbsp_i2c_write (ch_dev_t *dev_ptr, const uint8_t *data, uint16_t num_bytes) |
Write bytes to an I2C slave. More... | |
void | chbsp_int1_clear (ch_dev_t *dev_ptr) |
Set the INT1 pin low for one sensor. More... | |
void | chbsp_int1_interrupt_disable (ch_dev_t *dev_ptr) |
Disable the INT1 interrupt for one sensor. More... | |
void | chbsp_int1_interrupt_enable (ch_dev_t *dev_ptr) |
Enable the INT1 interrupt for one sensor. More... | |
void | chbsp_int1_set (ch_dev_t *dev_ptr) |
Set the INT1 pin high for one sensor. More... | |
void | chbsp_int2_clear (ch_dev_t *dev_ptr) |
Set the INT2 pin as inactive for one sensor. More... | |
void | chbsp_int2_interrupt_disable (ch_dev_t *dev_ptr) |
Disable the INT2 interrupt for one sensor. More... | |
void | chbsp_int2_interrupt_enable (ch_dev_t *dev_ptr) |
Enable the INT2 interrupt for one sensor. More... | |
void | chbsp_int2_set (ch_dev_t *dev_ptr) |
Set the INT2 pin high for one sensor. More... | |
void | chbsp_print_str (const char *str) |
Output a text string via serial interface. More... | |
void | chbsp_program_disable (ch_dev_t *dev_ptr) |
Deassert the PROG pin. More... | |
void | chbsp_program_enable (ch_dev_t *dev_ptr) |
Assert the PROG pin. More... | |
void | chbsp_reset_assert (void) |
Assert the reset pin for all sensors. More... | |
void | chbsp_reset_release (void) |
Deassert the reset pin for all sensors. More... | |
void | chbsp_set_int1_dir_in (ch_dev_t *dev_ptr) |
Configure the Chirp sensor INT1 pin as an input for one sensor. More... | |
void | chbsp_set_int1_dir_out (ch_dev_t *dev_ptr) |
Configure the Chirp sensor INT1 pin as an output for one sensor. More... | |
void | chbsp_set_int2_dir_in (ch_dev_t *dev_ptr) |
Configure the Chirp sensor INT2 pin as an input for one sensor. More... | |
void | chbsp_set_int2_dir_out (ch_dev_t *dev_ptr) |
Configure the Chirp sensor INT2 pin as an output for one sensor. More... | |
void | chbsp_spi_cs_off (ch_dev_t *dev_ptr) |
De-assert the SPI chip select line for a device. More... | |
void | chbsp_spi_cs_on (ch_dev_t *dev_ptr) |
Assert the SPI chip select line for a device. More... | |
int | chbsp_spi_mem_read_nb (ch_dev_t *dev_ptr, uint16_t mem_addr, uint8_t *data, uint16_t num_bytes) |
Read bytes from an SPI slave using memory addressing, non-blocking. More... | |
int | chbsp_spi_read (ch_dev_t *dev_ptr, uint8_t *data, uint16_t num_bytes) |
Read bytes from an SPI slave. More... | |
int | chbsp_spi_write (ch_dev_t *dev_ptr, const uint8_t *data, uint16_t num_bytes) |
Write bytes to an SPI slave. More... | |
uint32_t | chbsp_timestamp_ms (void) |
Return a free-running counter value in milliseconds. More... | |
User-supplied board support package functions to interface Chirp SonicLib to a specific hardware platform.
This file defines the I/O interfaces that allow the standard Chirp SonicLib sensor driver functions to manage one or more sensors on a specific hardware platform. These include functions to initialize and control the various I/O pins connecting the sensor to the host system, the SPI or I2C communications interface, timer functions, etc.
Typically, most of the functions in the BSP are implemented as "wrapper functions" for operations that are provided in the MCU vendor's I/O library. So, the BSP largely serves as a translation layer for most functions.
The board support package developer should not need to modify this header file. However, that developer is responsible for implementing these support functions for the hardware platform, using the interfaces defined here. Note that some functions are optional, depending on the specific runtime requirements (e.g. is non-blocking I/O required?) or development needs (e.g. is debugging support needed?).
The file organization for a BSP is intentionally very flexible, so that you may efficiently use existing code that supports your hardware or otherwise use your own organizing preferences.
Typically, the required BSP functions are placed in a file called chbsp_NNNN.c, where NNNN is the board name. For example, in the Chirp BSP for the Nucleo144 development board the main file is called chbsp_nucleo144.c, and in the BSP for the Chirp SmartSonic evaluation, it is called chbsp_chirp_smartsonic.c.
In addition to providing the required chbsp_xxx() functions as described above, the BSP must also provide a routine to handle interrupts from the sensor. Because the handler routine is not referenced by SonicLib, it can have any name that fits your conventions.
All Chirp sensors use a level change on an interrupt line to indicate the completion of a measurement (data ready).
ICU family sensors have two different lines that may be used as the interrupt indicator, INT1 and INT2. Interrupt and trigger lines for ICU sensors are high when inactive, so the interrupt is indicated by a transition to a low level.
ICU sensors may be configured for either pulse mode or latching mode by calling the ch_set_interrupt_mode() function from the application. In pulse mode, the sensor will indicate an interrupt by briefly (~800ns) bringing the line low then returning it to a high level. In latching mode, the sensor will bring the line low and the interrupt handler in the BSP is responsible for resetting the line to a high (inactive) level. By default, ICU sensors use latching mode.
ICU sensors also use the interrupt line for various other events in addition to data ready. The interrupt type will be passed to the application's callback routine when an interrupt occurs.
CH101 and CH201 sensors have a single interrupt line that is normally used only for data ready interrupts. The line is low when inactive, so the interrupt consists of a brief high pulse. CH101/CH201 sensors always use "INT1" routines and interfaces.
The BSP's handler routine that detects that a sensor interrupt has occurred (typically to indicate completion of a measurement) must notify SonicLib by calling ch_interrupt(). The ch_interrupt() function takes two parameters, a pointer to the ch_group_t descriptor for the group containing the interrupting sensor, and the device number within the group.
The sensor will be examined by SonicLib to determine the interrupt type. Then, the application's callback routine that was registered using ch_io_int_callback_set() will be called to notify the application. The interrupt type will be passed to the appliction callback routine.
All this processing takes place in the context of the BSP interrupt handler.
If non-blocking I/O is used, the BSP's handler functions which processes the completion of an I/O operation must notify SonicLib that the I/O has completed by calling the ch_io_notify() function. The group pointer and SPI/I2C bus number must be passed as parameters to identify which I/O channel has finished.
The board support package must supply a header file called chirp_board_config.h containing definitions of two symbols used in the SonicLib driver functions.
The chirp_board_config.h file must be in the C pre-processor include path when you build your application with SonicLib.
The following symbols must be defined in chirp_board_config.h:
The following symbols are optional and normally not required. If defined, they allow special handling in SonicLib for certain hardware configurations or limitations.
MAX_PROG_XFER_SIZE = maximum SPI/I2C transfer size when programming sensor
The sensor is programmed during the ch_group_start() function. Normally, the entire sensor firmware image (6144 bytes for ICU sensors, or 2048 bytes for CH101/CH201 sensors)) is written in a single SPI or I2C write operation. For hardware platforms that cannot support such a large transfer, the MAX_PROG_XFER_SIZE symbol can be defined to specify the maximum size, in bytes, for a single transfer. The sensor programming will be divided into multiple transfers as necessary.
For example, to limit the maximum transfer size to 256 bytes, add the following line in your chirp_board_config.h file:
#define MAX_PROG_XFER_SIZE 256
USE_STD_I2C_FOR_IQ = disable optimized low-level I/Q data readout (CH101/CH201)
This optional symbol is only used with CH101 and CH201 sensors (it has no effect with ICU sensors). When this symbol is defined, SonicLib will use standard I2C addressing to read I/Q data from the sensor. Otherwise, an optimized low-level interface is used, with improved performance.
Most of the required functions take a pointer to a ch_dev_t device descriptor structure as a handle to identify the sensor being controlled. The ch_dev_t structure contains various fields with configuration and operating state information for the device. In general, these values may be obtained using various ch_get_XXX() functions provided by the SonicLib API, so it should not be necessary to access fields directly.
Some functions take a pointer to a ch_group_t (sensor group descriptor) structure as a parameter but must operate on individual sensors. These functions can be implemented using the ch_get_dev_ptr() function to access the ch_dev_t structure describing each individual sensor in the group, based on its device number (I/O index value). The total number of possible sensor devices in a group may be obtained by using the ch_get_num_ports() function.
Similarly, each sensor's ch_dev_t structure contains a dev_num field that may be used to manage the pin assignments for the various sensors, by using it as an index into individual arrays which list the pins assigned to the PROG, INT, and RESET_N lines. The dev_num value for a sensor may be obtained using the ch_get_dev_num() function.
Often, an action should only be taken on a sensor port if a sensor is present and has been successfully initialized and connected. The ch_sensor_is_connected() function can be used to obtain the connection status.
These functions are often used together to implement a board support routine, as in the following pseudo-code which shows how to perform an action on all connected devices in a group. This snippet assumes that a sensor group pointer (ch_group_t *) called grp_ptr is an input parameter to the function:
ch_dev_t *dev_ptr; uint8_t dev_num; for (dev_num = 0; dev_num < ch_get_num_ports(grp_ptr); dev_num++ { dev_ptr = ch_get_dev_ptr(grp_ptr, dev_num); if (ch_sensor_is_connected(dev_ptr)) { DO WHAT NEEDS DOING FOR THIS CONNECTED DEVICE } }
The dev_num value for each device is specified by the user application as a parameter to ch_init().
void chbsp_debug_off | ( | uint8_t | dbg_pin_num | ) |
Turn off a debug indicator pin.
dbg_pin_num | index value for debug pin to turn off |
This function should drive the the specified debug indicator pin low. The dbg_pin_num parameter is an index value that specifies which debug pin should be controlled.
This function is OPTIONAL.
void chbsp_debug_on | ( | uint8_t | dbg_pin_num | ) |
Turn on a debug indicator pin.
dbg_pin_num | index value for debug pin to turn on |
This function should drive the specified debug indicator pin high. The dbg_pin_num parameter is an index value that specifies which debug pin should be controlled.
This function is OPTIONAL.
void chbsp_debug_toggle | ( | uint8_t | dbg_pin_num | ) |
Toggle a debug indicator pin.
dbg_pin_num | index value for debug pin to toggle |
This function should change the state (high/low) of the specified debug indicator pin. The dbg_pin_num parameter is an index value that specifies which debug pin should be controlled.
This function is OPTIONAL.
void chbsp_delay_ms | ( | uint32_t | ms | ) |
Delay for specified number of milliseconds.
ms | number of milliseconds to delay before returning |
This function should wait for the specified number of milliseconds before returning to the caller.
This function is REQUIRED.
void chbsp_delay_us | ( | uint32_t | us | ) |
Delay for specified number of microseconds.
us | number of microseconds to delay before returning |
This function should wait for the specified number of microseconds before returning to the caller.
This function is REQUIRED.
void chbsp_event_notify | ( | uint32_t | event_mask | ) |
Notify an interrupt event for the selected device.
event_mask | Each bit of the mask represents a device |
This function is called from ch_interrupt , in interrupt context
uint8_t chbsp_event_wait | ( | uint16_t | time_out_ms, |
uint32_t | event_mask | ||
) |
Wait for any interrupt event.
time_out_ms | time-out of the wait loop |
This function is called during initialization when an event is triggered on sensor and we wait the the result. This event is called in "application" context
void chbsp_event_wait_setup | ( | uint32_t | event_mask | ) |
Prepare the mechanism to wait for an event.
This function is called before chbsp_event_wait
void chbsp_external_irq_handler | ( | chdrv_transaction_t * | trans | ) |
Interrupt handler callout for external devices sharing the SPI/I2C bus.
trans | pointer to Chirp sensor transaction control structure |
This function is called when a non-blocking SPI/I2C operation completes on an "external" (non Chirp sensor) device. The chbsp_external_queue() function should be called to add such a transaction to the SPI/I2C queue.
This function is OPTIONAL.
void chbsp_group_int1_clear | ( | ch_group_t * | grp_ptr | ) |
Set the INT1 pins low for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should drive the INT1 line low for each sensor in the group.
This function is REQUIRED.
void chbsp_group_int1_interrupt_disable | ( | ch_group_t * | grp_ptr | ) |
Disable INT1 interrupts for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
For each sensor in the group, this function should disable the host interrupt associated with the Chirp sensor device's INT1 line.
void chbsp_group_int1_interrupt_enable | ( | ch_group_t * | grp_ptr | ) |
Enable INT1 interrupts for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
For each sensor in the group, this function should enable the host interrupt associated with the Chirp sensor device's INT1 line.
This function is REQUIRED.
void chbsp_group_int1_set | ( | ch_group_t * | grp_ptr | ) |
Set the INT1 pins high for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should drive the INT1 line high for each sensor in the group.
This function is REQUIRED.
void chbsp_group_int2_clear | ( | ch_group_t * | grp_ptr | ) |
Set the INT2 pins as inactive for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should drive the INT2 line low for each sensor in the group.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_group_int2_interrupt_disable | ( | ch_group_t * | grp_ptr | ) |
Disable INT2 interrupts for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
For each sensor in the group, this function should disable the host interrupt associated with the Chirp sensor device's INT2 line.
void chbsp_group_int2_interrupt_enable | ( | ch_group_t * | grp_ptr | ) |
Enable INT2 interrupts for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
For each sensor in the group, this function should enable the host interrupt associated with the Chirp sensor device's INT2 line.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_group_int2_set | ( | ch_group_t * | grp_ptr | ) |
Set the INT2 pins high for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should drive the INT2 line high for each sensor in the group.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_group_set_int1_dir_in | ( | ch_group_t * | grp_ptr | ) |
Configure the Chirp sensor INT1 pins as inputs for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should configure each Chirp sensor's INT1 pin as an input (from the perspective of the host system).
This function is REQUIRED.
void chbsp_group_set_int1_dir_out | ( | ch_group_t * | grp_ptr | ) |
Configure the Chirp sensor INT1 pin as an output for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should configure each Chirp sensor's INT1 pin as an output (from the perspective of the host system).
This function is REQUIRED.
void chbsp_group_set_int2_dir_in | ( | ch_group_t * | grp_ptr | ) |
Configure the Chirp sensor INT2 pins as inputs for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should configure each Chirp sensor's INT2 pin as an input (from the perspective of the host system).
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_group_set_int2_dir_out | ( | ch_group_t * | grp_ptr | ) |
Configure the Chirp sensor INT2 pin as an output for a group of sensors.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
This function should configure each Chirp sensor's INT2 pin as an output (from the perspective of the host system).
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
uint8_t chbsp_i2c_get_info | ( | ch_group_t * | grp_ptr, |
uint8_t | dev_num, | ||
ch_i2c_info_t * | info_ptr | ||
) |
Return I2C information for a sensor port on the board.
grp_ptr | pointer to the ch_group_t config structure for a group of sensors |
dev_num | device number within sensor group |
info_ptr | pointer to structure to be filled with I2C config values |
This function is called by SonicLib functions to obtain I2C operating parameters for a specific device on the board.
This function returns I2C values in the ch_i2c_info_t structure specified by info_ptr. The structure includes three fields.
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_init | ( | void | ) |
Initialize the host's I2C hardware.
This function should perform general I2C initialization on the host system. This includes both hardware initialization and setting up any necessary software structures. Upon successful return from this routine, the system should be ready to perform I/O operations such as chbsp_i2c_read() and chbsp_i2c_write().
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_mem_read | ( | ch_dev_t * | dev_ptr, |
uint16_t | mem_addr, | ||
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Read bytes from an I2C slave using memory addressing.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | internal memory or register address within device |
data | pointer to receive data buffer |
num_bytes | number of bytes to read |
This function should read the specified number of bytes from an I2C slave device, using an internal memory or register address. The remote device will return num_bytes bytes starting at internal memory/register address mem_addr.
The I2C interface must have already been initialized using chbsp_i2c_init().
There are two distinct phases to the transfer. First, the register address must be written to the sensor, then a read operation must be done to obtain the data. (Note that the byte count does not have to be sent to the device during a read operation, unlike in chbsp_i2c_mem_write()).)
The preferred way to do this is with a repeated-start operation, in which the write phase is followed by another I2C Start condition (rather than a Stop) and then the read operation begins immediately. This prevents another device on the bus from getting control between the write and read phases. Many micro-controller I/O libraries include dedicated I2C functions to perform just such an operation for writing registers.
When using the repeated start, the overall sequence looks like this:
Write phase | | | Read Phase | | | ||||||
---|---|---|---|---|---|---|---|---|---|
I2C START | I2C Addr | mem_addr | I2C START | I2C Addr + read bit | *data | *(data + 1) | *(data + 2) | etc... | I2C STOP |
If the repeated-start technique is not used, it is possible to read from the sensor using separate, sequential I2C write and read operations. In this case, the sequence is much the same, except that the write phase is ended by an I2C Stop condition, then an I2C Start is issued to begin the read phase. However, this may be a problem if more than one bus master is present, because the bus is not held between the two phases.
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_mem_read_nb | ( | ch_dev_t * | dev_ptr, |
uint16_t | mem_addr, | ||
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Read bytes from an I2C slave using memory addressing, non-blocking.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | internal memory or register address within device |
data | pointer to receive data buffer |
num_bytes | number of bytes to read |
This function should initiate a non-blocking read of the specified number of bytes from an I2C slave. The I2C interface must have already been initialized using chbsp_i2c_init().
This function is OPTIONAL for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_mem_write | ( | ch_dev_t * | dev_ptr, |
uint16_t | mem_addr, | ||
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Write bytes to an I2C slave using memory addressing.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | internal memory or register address within device |
data | data to be transmitted |
num_bytes | length of data to be transmitted |
This function should write one or more bytes of data to an I2C slave device using an internal memory or register address. The remote device will write num_bytes bytes of data starting at internal memory/register address mem_addr. The I2C interface will have already been initialized using chbsp_i2c_init().
The chbsp_i2c_mem_write() function is basically a standard I2C data write, except that the destination register address and the number of bytes being written must be included, like a header.
The byte sequence being sent should look like the following:
0 | 1 | 2 | 3 | 4 | etc... |
---|---|---|---|---|---|
I2C Addr | mem_addr | *data | *(data + 1) | *(data + 2) | ... |
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_mem_write_nb | ( | ch_dev_t * | dev_ptr, |
uint16_t | mem_addr, | ||
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Write bytes to an I2C slave using memory addressing, non-blocking.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | internal memory or register address within device |
data | pointer to the start of data to be transmitted |
num_bytes | length of data to be transmitted |
This function should initiate a non-blocking write of the specified number of bytes to an I2C slave device, using an internal memory or register address. The remote device will write num_bytes bytes of data starting at internal memory/register address mem_addr.
The I2C interface must have already been initialized using chbsp_i2c_init().
The byte sequence being sent should look like the following:
0 | 1 | 2 | 3 | 4 | etc... |
---|---|---|---|---|---|
I2C Addr | mem_addr | *data | *(data + 1) | *(data + 2) | ... |
This function is OPTIONAL for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_read | ( | ch_dev_t * | dev_ptr, |
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Read bytes from an I2C slave.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
data | pointer to receive data buffer |
num_bytes | number of bytes to read |
This function should read the specified number of bytes from an I2C slave device. The I2C interface must have already been initialized using chbsp_i2c_init().
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_read_nb | ( | ch_dev_t * | dev_ptr, |
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Read bytes from an I2C slave, non-blocking.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
data | pointer to receive data buffer |
num_bytes | number of bytes to read |
This function should initiate a non-blocking read of the specified number of bytes from an I2C slave.
The I2C interface must have already been initialized using chbsp_i2c_init().
This function is OPTIONAL for CH101 and CH201 sensors. It is not used for ICU sensors.
void chbsp_i2c_reset | ( | ch_dev_t * | dev_ptr | ) |
Reset I2C bus associated with device.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should perform a reset of the I2C interface for the specified device.
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
int chbsp_i2c_write | ( | ch_dev_t * | dev_ptr, |
const uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Write bytes to an I2C slave.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
data | data to be transmitted |
num_bytes | length of data to be transmitted |
This function should write one or more bytes of data to an I2C slave device. The I2C interface will have already been initialized using chbsp_i2c_init().
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
void chbsp_int1_clear | ( | ch_dev_t * | dev_ptr | ) |
Set the INT1 pin low for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should drive the INT1 line low for the specified sensor.
void chbsp_int1_interrupt_disable | ( | ch_dev_t * | dev_ptr | ) |
Disable the INT1 interrupt for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should disable the host interrupt associated with the Chirp sensor device's INT1 line.
This function is REQUIRED.
void chbsp_int1_interrupt_enable | ( | ch_dev_t * | dev_ptr | ) |
Enable the INT1 interrupt for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should enable the host interrupt associated with the Chirp sensor device's INT1 line.
This function is REQUIRED.
void chbsp_int1_set | ( | ch_dev_t * | dev_ptr | ) |
Set the INT1 pin high for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should drive the INT1 line high for the specified sensor.
This function is OPTIONAL.
void chbsp_int2_clear | ( | ch_dev_t * | dev_ptr | ) |
Set the INT2 pin as inactive for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should drive the INT2 line low for the specified sensor.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_int2_interrupt_disable | ( | ch_dev_t * | dev_ptr | ) |
Disable the INT2 interrupt for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should disable the host interrupt associated with the Chirp sensor device's INT2 line.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_int2_interrupt_enable | ( | ch_dev_t * | dev_ptr | ) |
Enable the INT2 interrupt for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should enable the host interrupt associated with the Chirp sensor device's INT2 line.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_int2_set | ( | ch_dev_t * | dev_ptr | ) |
Set the INT2 pin high for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should drive the INT2 line high for the specified sensor.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_print_str | ( | const char * | str | ) |
Output a text string via serial interface.
str | pointer to a string of characters to be output |
This function should print debug information to the console. The user can implement this function to print characters over a serial port, for example.
In the Chirp SonicLib sensor driver, debug message output may be enabled by defining CH_LOG_MODULE_LEVEL.
void chbsp_program_disable | ( | ch_dev_t * | dev_ptr | ) |
Deassert the PROG pin.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should drive the Chirp sensor PROG pin low for the specified device.
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
void chbsp_program_enable | ( | ch_dev_t * | dev_ptr | ) |
Assert the PROG pin.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should drive the Chirp sensor PROG pin high for the specified device. It is used by the driver to initiate I2C communication with a specific Chirp sensor device before a unique I2C address is assigned to the device or when the programming interface is used.
When the PROG pin is asserted, the device will respond to the standard programming I2C address (0x45).
This function is REQUIRED for CH101 and CH201 sensors. It is not used for ICU sensors.
void chbsp_reset_assert | ( | void | ) |
Assert the reset pin for all sensors.
This function should drive the Chirp sensor reset pin low (assert RESET_N) on all sensors.
This function is REQUIRED for CH101 and CH201 sensors. It is not used with ICU sensors, which do not have a reset pin.
void chbsp_reset_release | ( | void | ) |
Deassert the reset pin for all sensors.
This function should drive the Chirp sensor reset pin high (or open drain if there is a pull-up) on all sensors.
This function is REQUIRED for CH101 and CH201 sensors. It is not used with ICU sensors, which do not have a reset pin.
void chbsp_set_int1_dir_in | ( | ch_dev_t * | dev_ptr | ) |
Configure the Chirp sensor INT1 pin as an input for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should configure the Chirp sensor INT1 pin as an input (from the perspective of the host system).
This function is RECOMMENDED.
void chbsp_set_int1_dir_out | ( | ch_dev_t * | dev_ptr | ) |
Configure the Chirp sensor INT1 pin as an output for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should configure the Chirp sensor INT1 pin as an output (from the perspective of the host system).
This function is RECOMMENDED.
void chbsp_set_int2_dir_in | ( | ch_dev_t * | dev_ptr | ) |
Configure the Chirp sensor INT2 pin as an input for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should configure the Chirp sensor INT2 pin as an input (from the perspective of the host system).
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_set_int2_dir_out | ( | ch_dev_t * | dev_ptr | ) |
Configure the Chirp sensor INT2 pin as an output for one sensor.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function should configure the Chirp sensor INT2 pin as an output (from the perspective of the host system).
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_spi_cs_off | ( | ch_dev_t * | dev_ptr | ) |
De-assert the SPI chip select line for a device.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function is REQUIRED for ICU sensors. It is not used for CH101 or CH201 sensors.
void chbsp_spi_cs_on | ( | ch_dev_t * | dev_ptr | ) |
Assert the SPI chip select line for a device.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
This function is REQUIRED for ICU sensors. It is not used for CH101 or CH201 sensors.
int chbsp_spi_mem_read_nb | ( | ch_dev_t * | dev_ptr, |
uint16_t | mem_addr, | ||
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Read bytes from an SPI slave using memory addressing, non-blocking.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
mem_addr | internal memory or register address within device |
data | pointer to receive data buffer |
num_bytes | number of bytes to read |
This function should initiate a non-blocking read of the specified number of bytes from an SPI slave.
This function is OPTIONAL for ICU sensors. It is not used for CH101 or CH201 sensors.
int chbsp_spi_read | ( | ch_dev_t * | dev_ptr, |
uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Read bytes from an SPI slave.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
data | pointer to receive data buffer |
num_bytes | number of bytes to read |
This function should read the specified number of bytes from an SPI slave device.
This function is REQUIRED for ICU sensors. It is not used for CH101 or CH201 sensors.
int chbsp_spi_write | ( | ch_dev_t * | dev_ptr, |
const uint8_t * | data, | ||
uint16_t | num_bytes | ||
) |
Write bytes to an SPI slave.
dev_ptr | pointer to the ch_dev_t config structure for a sensor |
data | data to be transmitted |
num_bytes | length of data to be transmitted |
This function should write one or more bytes of data to an SPI slave device.
This function is REQUIRED for ICU sensors. It is not used for CH101 or CH201 sensors.
uint32_t chbsp_timestamp_ms | ( | void | ) |
Return a free-running counter value in milliseconds.
This function should use a running timer to provide an updated timestamp, in milliseconds, when called.
This function is REQUIRED for ICU and CH101/CH201 sensors.