108 #include "chirp_board_config.h" 121 #define SONICLIB_VER_MAJOR (2) 122 #define SONICLIB_VER_MINOR (1) 123 #define SONICLIB_VER_REV (0) 126 #define CH101_PART_NUMBER (101) 127 #define CH201_PART_NUMBER (201) 130 #define CH101_MAX_NUM_SAMPLES (150) 131 #define CH201_MAX_NUM_SAMPLES (450) 134 #define CH_NO_TARGET (0xFFFFFFFF) 135 #define CH_MIN_RANGE_VAL (0x0001) 137 #define CH_I2C_ADDR_PROG (0x45) 138 #define CH_SIG_BYTE_0 (0x0a) 139 #define CH_SIG_BYTE_1 (0x02) 141 #define CH_NUM_THRESHOLDS (6) 142 #define CH_SPEEDOFSOUND_MPS (343) 185 CH_TIME_PLAN_NONE = 255
196 #define I2C_DRV_FLAG_RESET_AFTER_NB (0x00000001) 197 #define I2C_DRV_FLAG_USE_PROG_NB (0x00000002) 209 uint16_t start_sample;
233 uint8_t dev_num, uint8_t i2c_bus_index);
240 typedef uint8_t (*ch_set_sample_interval_func_t)(
ch_dev_t *dev_ptr, uint16_t sample_interval);
241 typedef uint8_t (*ch_set_num_samples_func_t)(
ch_dev_t *dev_ptr, uint16_t num_samples);
242 typedef uint8_t (*ch_set_max_range_func_t)(
ch_dev_t *dev_ptr, uint16_t max_range);
243 typedef uint8_t (*ch_set_sample_window_func_t)(
ch_dev_t *dev_ptr, uint16_t start_sample,
244 uint16_t end_sample);
246 typedef uint32_t (*ch_get_tof_tick_func_t)(
ch_dev_t *dev_ptr, uint32_t timer_freq);
247 typedef uint16_t (*ch_get_amplitude_func_t)(
ch_dev_t *dev_ptr);
248 typedef uint16_t (*ch_get_amplitude_avg_func_t)(
ch_dev_t *dev_ptr);
249 typedef uint8_t (*ch_set_frequency_func_t)(
ch_dev_t *dev_ptr, uint32_t target_freq_Hz);
250 typedef uint32_t (*ch_get_frequency_func_t)(
ch_dev_t *dev_ptr);
252 uint16_t start_sample, uint16_t num_samples,
254 typedef uint8_t (*ch_get_amplitude_data_func_t)(
ch_dev_t *dev_ptr, uint16_t *buf_ptr,
255 uint16_t start_sample, uint16_t num_samples,
257 typedef uint16_t (*ch_samples_to_mm_func_t)(
ch_dev_t *dev_ptr, uint16_t num_samples);
258 typedef uint16_t (*ch_mm_to_samples_func_t)(
ch_dev_t *dev_ptr, uint16_t num_mm);
259 typedef uint8_t (*ch_set_threshold_func_t)(
ch_dev_t *dev_ptr, uint8_t threshold_index, uint16_t amplitude);
260 typedef uint16_t (*ch_get_threshold_func_t)(
ch_dev_t *dev_ptr, uint8_t threshold_index);
263 typedef uint8_t (*ch_set_target_interrupt_func_t)(
ch_dev_t *dev_ptr, uint8_t enable);
264 typedef uint8_t (*ch_get_target_interrupt_func_t)(
ch_dev_t *dev_ptr);
265 typedef uint8_t (*ch_set_static_range_func_t)(
ch_dev_t *dev_ptr, uint16_t static_range);
266 typedef uint8_t (*ch_set_static_coeff_func_t)(
ch_dev_t *dev_ptr, uint8_t static_coeff);
267 typedef uint8_t (*ch_get_static_coeff_func_t)(
ch_dev_t *dev_ptr);
268 typedef uint8_t (*ch_set_rx_holdoff_func_t)(
ch_dev_t *dev_ptr, uint16_t rx_holdoff);
269 typedef uint16_t (*ch_get_rx_holdoff_func_t)(
ch_dev_t *dev_ptr);
270 typedef uint8_t (*ch_set_tx_length_func_t)(
ch_dev_t *dev_ptr, uint8_t tx_length);
271 typedef uint8_t (*ch_get_tx_length_func_t)(
ch_dev_t *dev_ptr);
272 typedef uint8_t (*ch_get_rx_pulse_length_func_t)(
ch_dev_t *dev_ptr);
279 ch_set_mode_func_t set_mode;
280 ch_set_sample_interval_func_t set_sample_interval;
281 ch_set_num_samples_func_t set_num_samples;
282 ch_set_max_range_func_t set_max_range;
283 ch_set_sample_window_func_t set_sample_window;
284 ch_get_range_func_t get_range;
285 ch_get_tof_tick_func_t get_tof_tick;
286 ch_get_amplitude_func_t get_amplitude;
287 ch_get_amplitude_avg_func_t get_amplitude_avg;
288 ch_set_frequency_func_t set_frequency;
289 ch_get_frequency_func_t get_frequency;
290 ch_get_iq_data_func_t get_iq_data;
291 ch_get_amplitude_data_func_t get_amplitude_data;
292 ch_samples_to_mm_func_t samples_to_mm;
293 ch_mm_to_samples_func_t mm_to_samples;
294 ch_set_threshold_func_t set_threshold;
295 ch_get_threshold_func_t get_threshold;
296 ch_set_thresholds_func_t set_thresholds;
297 ch_get_thresholds_func_t get_thresholds;
298 ch_set_target_interrupt_func_t set_target_interrupt;
299 ch_get_target_interrupt_func_t get_target_interrupt;
300 ch_set_static_range_func_t set_static_range;
301 ch_set_static_coeff_func_t set_static_coeff;
302 ch_get_static_coeff_func_t get_static_coeff;
303 ch_set_rx_holdoff_func_t set_rx_holdoff;
304 ch_get_rx_holdoff_func_t get_rx_holdoff;
305 ch_set_tx_length_func_t set_tx_length;
306 ch_get_tx_length_func_t get_tx_length;
307 ch_get_rx_pulse_length_func_t get_rx_pulse_length;
308 ch_set_time_plan_func_t set_time_plan;
309 ch_get_time_plan_func_t get_time_plan;
ch_io_complete_callback_t io_complete_callback
Definition: soniclib.h:339
API function pointer structure (internal use).
Definition: soniclib.h:277
Internal definitions for the Chirp CH101 GPR Short-range Open sensor firmware.
void ch_io_notify(ch_group_t *grp_ptr, uint8_t i2c_bus_index)
Notify SonicLib that a non-blocking I/O operation has completed.
uint8_t(* ch_fw_init_func_t)(ch_dev_t *dev_ptr, ch_group_t *grp_ptr, uint8_t i2c_addr, uint8_t dev_num, uint8_t i2c_bus_index)
ASIC firmware init function pointer typedef.
Definition: soniclib.h:232
chdrv_discovery_hook_t disco_hook
Definition: soniclib.h:337
Internal driver functions for operation with the Chirp ultrasonic sensor.
ch_mode_t
Sensor operating modes.
Definition: soniclib.h:158
uint8_t address
Definition: soniclib.h:190
uint8_t ch_get_sample_window(ch_dev_t *dev_ptr, uint16_t *start_sample_ptr, uint16_t *num_samples_ptr)
Get the sample window for amplitude averaging.
Definition: soniclib.h:153
ch_dev_t * device[CHIRP_MAX_NUM_SENSORS]
Definition: soniclib.h:341
uint16_t ch_get_static_range(ch_dev_t *dev_ptr)
Get static target rejection range setting.
uint8_t bus_num
Definition: soniclib.h:191
uint8_t ch_sensor_is_connected(ch_dev_t *dev_ptr)
Indicate if a sensor is connected.
uint8_t ch_set_thresholds(ch_dev_t *dev_ptr, ch_thresholds_t *thresh_ptr)
Set detection thresholds (CH201 only).
uint8_t ch_get_i2c_bus(ch_dev_t *dev_ptr)
Get the active I2C bus for a sensor.
void ch_io_complete_callback_set(ch_group_t *grp_ptr, ch_io_complete_callback_t callback_func_ptr)
Register non-blocking I/O complete callback routine for a group of sensors.
uint16_t ch_get_sample_interval(ch_dev_t *dev_ptr)
Get the internal sample timing interval for a sensor.
Functions for performing fixed point arithmetic. https://github.com/dmoulding/log2fix https://github...
uint8_t ch_get_tx_length(ch_dev_t *dev_ptr)
Get the TX length.
void(* prepare_pulse_timer)(ch_dev_t *dev_ptr)
Definition: soniclib.h:379
uint8_t freqLockValue
Definition: soniclib.h:352
uint16_t ch_get_rx_holdoff(ch_dev_t *dev_ptr)
Get the receive holdoff sample count.
uint8_t ch_get_static_coeff(ch_dev_t *dev_ptr)
Get the static coefficient for IIR filter.
uint8_t ch_set_static_range(ch_dev_t *dev_ptr, uint16_t num_samples)
Configure static target rejection.
void(* store_bandwidth)(ch_dev_t *dev_ptr)
Definition: soniclib.h:388
ch_mode_t mode
Definition: soniclib.h:351
uint8_t ch_get_num_ports(ch_group_t *grp_ptr)
Get the total number of sensor ports (possible sensors) in a sensor group.
uint16_t ch_get_max_samples(ch_dev_t *dev_ptr)
Get the maximum possible sample count per measurement.
ch_time_plan_t
Time plan.
Definition: soniclib.h:181
uint16_t i2c_drv_flags
Definition: soniclib.h:363
uint8_t ch_set_config(ch_dev_t *dev_ptr, ch_config_t *config_ptr)
Set multiple configuration settings for a sensor.
uint8_t ch_get_amplitude_data(ch_dev_t *dev_ptr, uint16_t *buf_ptr, uint16_t start_sample, uint16_t num_samples, ch_io_mode_t mode)
Get the raw amplitude measurement data from a sensor.
uint16_t(* get_fw_ram_init_addr)(void)
Definition: soniclib.h:396
uint32_t ch_get_frequency(ch_dev_t *dev_ptr)
Get the operating frequency of a sensor.
void(* ch_timer_callback_t)(void)
Periodic timer callback routine pointer.
Definition: soniclib.h:320
Internal definitions for the Chirp CH101 Floor Detection enabled firmware.
const uint8_t * ram_init
Definition: soniclib.h:378
void ch_set_rx_pretrigger(ch_group_t *grp_ptr, uint8_t enable)
Enable/disable receive-only sensor pre-triggering.
ch_dev_t * ch_get_dev_ptr(ch_group_t *grp_ptr, uint8_t dev_num)
Get device descriptor pointer for a sensor.
const char * ch_get_fw_version_string(ch_dev_t *dev_ptr)
Get the firmware version description string for a sensor.
Definition: soniclib.h:176
chdrv_i2c_queue_t i2c_queue[CHIRP_NUM_I2C_BUSES]
Definition: soniclib.h:344
uint16_t ch_get_rtc_cal_pulselength(ch_dev_t *dev_ptr)
Get the real-time clock calibration pulse length.
uint8_t ch_get_thresholds(ch_dev_t *dev_ptr, ch_thresholds_t *thresh_ptr)
Get detection thresholds (CH201 only).
uint8_t app_i2c_address
Definition: soniclib.h:362
uint16_t max_range
Definition: soniclib.h:354
uint32_t ch_get_tof_tick(ch_dev_t *dev_ptr, uint32_t timer_freq)
Get the measured Time-of-flight from a sensor in the ultrasound periodic timer tick.
uint8_t sensor_count
Definition: soniclib.h:332
Chirp sensor device structure.
Definition: soniclib.h:349
Definition: soniclib.h:171
uint8_t ch_io_start_nb(ch_group_t *grp_ptr)
Start non-blocking I/O operation(s) for a group of sensors.
uint8_t enable_target_int
Definition: soniclib.h:227
uint16_t ch_get_rtc_cal_result(ch_dev_t *dev_ptr)
Get the real-time clock calibration value.
Definition: soniclib.h:159
void(* store_pt_result)(ch_dev_t *dev_ptr)
Definition: soniclib.h:382
uint8_t ch_set_frequency(ch_dev_t *dev_ptr, uint32_t target_freq_Hz)
Set the operating frequency of a sensor.
uint16_t bandwidth
Definition: soniclib.h:359
uint8_t num_i2c_buses
Definition: soniclib.h:331
Internal definitions for the Chirp CH101 GPR Open sensor firmware.
uint8_t sensor_connected
Definition: soniclib.h:366
uint16_t ch_get_scale_factor(ch_dev_t *dev_ptr)
Get the calibration scale factor of a sensor.
uint8_t ch_get_rx_pulse_length(ch_dev_t *dev_ptr)
Get the detected length of the received pulse.
uint8_t ch_init(ch_dev_t *dev_ptr, ch_group_t *grp_ptr, uint8_t dev_num, ch_fw_init_func_t fw_init_func)
Initialize the device descriptor for a sensor.
uint8_t ch_set_target_interrupt(ch_dev_t *dev_ptr, uint8_t enable)
Set target detection interrupt mode.
int8_t oversample
Definition: soniclib.h:365
int16_t q
Definition: soniclib.h:202
uint8_t i2c_address
Definition: soniclib.h:361
uint8_t ch_set_max_range(ch_dev_t *dev_ptr, uint16_t max_range)
Set the maximum range for a sensor.
uint16_t sample_interval
Definition: soniclib.h:224
uint16_t ch_get_threshold(ch_dev_t *dev_ptr, uint8_t threshold_index)
Get the detection threshold.
uint16_t static_range
Definition: soniclib.h:223
Internal definitions for the Chirp CH101 GPPC sensor firmware.
Sensor I/Q data value.
Definition: soniclib.h:201
ch_io_mode_t
I/O blocking mode flags.
Definition: soniclib.h:175
uint8_t ch_set_tx_length(ch_dev_t *dev_ptr, uint8_t tx_length)
Set the TX length.
uint16_t rtc_cal_result
Definition: soniclib.h:357
uint8_t ch_group_start(ch_group_t *grp_ptr)
Program and start a group of sensors.
uint8_t ch_set_time_plan(ch_dev_t *dev_ptr, ch_time_plan_t time_plan)
Configure sonicsync timing plan.
uint16_t ch_get_max_range(ch_dev_t *dev_ptr)
Get the maximum range setting for a sensor.
uint32_t op_frequency
Definition: soniclib.h:358
uint8_t(* get_locked_state)(ch_dev_t *dev_ptr)
Definition: soniclib.h:392
uint16_t scale_factor
Definition: soniclib.h:360
Chirp sensor group configuration structure.
Definition: soniclib.h:329
uint16_t ch_samples_to_mm(ch_dev_t *dev_ptr, uint16_t num_samples)
Convert sample count to millimeters for a sensor.
uint16_t ch_iq_to_amplitude(ch_iq_sample_t *iq_sample_ptr)
Calculate amplitude from sample I/Q values.
Definition: soniclib.h:164
uint8_t ch_set_sample_window(ch_dev_t *dev_ptr, uint16_t start_sample, uint16_t num_samples)
Set the sample window for amplitude averaging.
Internal definitions for the Chirp CH201 GPR Multi-threshold sensor firmware.
uint16_t num_rx_samples
Definition: soniclib.h:371
uint16_t static_range
Definition: soniclib.h:355
I2C info structure.
Definition: soniclib.h:189
ch_mode_t mode
Definition: soniclib.h:221
uint16_t freqCounterCycles
Definition: soniclib.h:353
uint8_t i2c_bus_index
Definition: soniclib.h:369
uint16_t sample_interval
Definition: soniclib.h:356
uint16_t i2c_drv_flags
Definition: soniclib.h:333
uint16_t drv_flags
Definition: soniclib.h:192
Definition: soniclib.h:160
I2C queue structure, for non-blocking access.
Definition: ch_driver.h:114
uint16_t(* get_fw_ram_init_size)(void)
Definition: soniclib.h:394
ch_io_int_callback_t io_int_callback
Definition: soniclib.h:338
void ch_group_reset(ch_group_t *grp_ptr, ch_reset_t reset_type)
Reset a group of sensors.
uint8_t ch_set_rx_holdoff(ch_dev_t *dev_ptr, uint16_t num_samples)
Set the receive holdoff sample count.
int16_t i
Definition: soniclib.h:203
uint16_t win_start_sample
Definition: soniclib.h:372
uint8_t ch_get_dev_num(ch_dev_t *dev_ptr)
Get device number (I/O index values) for a sensor.
Definition: soniclib.h:152
uint16_t pretrig_delay_us
Definition: soniclib.h:336
uint8_t ch_set_static_coeff(ch_dev_t *dev_ptr, uint8_t static_coeff)
Set the static coefficient for IIR filter.
Definition: soniclib.h:154
uint8_t ch_set_threshold(ch_dev_t *dev_ptr, uint8_t threshold_index, uint16_t amplitude)
Set the detection threshold.
uint8_t ch_get_target_interrupt(ch_dev_t *dev_ptr)
Get the target detection interrupt mode setting.
ch_thresholds_t * thresh_ptr
Definition: soniclib.h:225
uint8_t ch_get_iq_data(ch_dev_t *dev_ptr, ch_iq_sample_t *buf_ptr, uint16_t start_sample, uint16_t num_samples, ch_io_mode_t mode)
Get the raw I/Q measurement data from a sensor.
const char * fw_version_string
Definition: soniclib.h:376
void ch_reset(ch_dev_t *dev_ptr, ch_reset_t reset_type)
Reset a sensor.
uint16_t num_win_samples
Definition: soniclib.h:373
uint16_t max_samples
Definition: soniclib.h:370
uint8_t num_ports
Definition: soniclib.h:330
Definition: soniclib.h:170
uint16_t max_range
Definition: soniclib.h:222
Combined configuration structure.
Definition: soniclib.h:220
uint16_t rtc_cal_pulse_ms
Definition: soniclib.h:335
uint8_t(* ch_fw_load_func_t)(ch_dev_t *dev_ptr)
API function pointer typedefs.
Definition: soniclib.h:236
void(* ch_io_int_callback_t)(ch_group_t *grp_ptr, uint8_t io_index)
Data-ready interrupt callback routine pointer.
Definition: soniclib.h:314
uint32_t ch_get_range(ch_dev_t *dev_ptr, ch_range_t range_type)
Get the measured range from a sensor.
uint16_t ch_get_amplitude_avg(ch_dev_t *dev_ptr)
Get the averaged measured amplitude over the sample window.
uint8_t ch_get_i2c_address(ch_dev_t *dev_ptr)
Get the active I2C address for a sensor.
void(* store_op_freq)(ch_dev_t *dev_ptr)
Definition: soniclib.h:385
uint16_t ch_get_amplitude(ch_dev_t *dev_ptr)
Get the measured amplitude from a sensor.
void ch_trigger(ch_dev_t *dev_ptr)
Trigger a measurement on one sensor.
#define CH_NUM_THRESHOLDS
Definition: soniclib.h:141
uint8_t ch_set_num_samples(ch_dev_t *dev_ptr, uint16_t num_samples)
Set the sensor sample count directly.
uint8_t ch_set_mode(ch_dev_t *dev_ptr, ch_mode_t mode)
Configure a sensor for the specified operating mode.
uint8_t ch_set_sample_interval(ch_dev_t *dev_ptr, uint16_t interval_ms)
Configure the internal sample interval for a sensor in freerunning mode.
uint16_t ch_mm_to_samples(ch_dev_t *dev_ptr, uint16_t num_mm)
Convert millimeters to sample count for a sensor.
void ch_io_int_callback_set(ch_group_t *grp_ptr, ch_io_int_callback_t callback_func_ptr)
Register sensor interrupt callback routine for a group of sensors.
ch_range_t
Range data types.
Definition: soniclib.h:151
Definition: soniclib.h:177
uint8_t num_connected[CHIRP_NUM_I2C_BUSES]
Definition: soniclib.h:343
uint16_t part_number
Definition: soniclib.h:364
ch_mode_t ch_get_mode(ch_dev_t *dev_ptr)
Get the current operating mode for a sensor.
Internal definitions for the Chirp CH201 presence detection sensor firmware.
ch_group_t * group
Definition: soniclib.h:350
Detection threshold value (CH201 only).
Definition: soniclib.h:208
ch_reset_t
Sensor reset types.
Definition: soniclib.h:169
ch_time_plan_t time_plan
Definition: soniclib.h:226
uint16_t ch_get_part_number(ch_dev_t *dev_ptr)
Get part number for a sensor.
Internal definitions for the Chirp CH101 SonicSync sensor firmware.
uint16_t ch_get_num_samples(ch_dev_t *dev_ptr)
Get the number of samples per measurement cycle.
Definition: soniclib.h:162
uint16_t ch_get_bandwidth(ch_dev_t *dev_ptr)
Get the bandwidth of a sensor.
void(* ch_io_complete_callback_t)(ch_group_t *grp_ptr)
Non-blocking I/O complete callback routine pointer.
Definition: soniclib.h:317
const uint8_t * firmware
Definition: soniclib.h:377
Multiple detection threshold structure (CH201 only).
Definition: soniclib.h:215
ch_time_plan_t ch_get_time_plan(ch_dev_t *dev_ptr)
Read sonicsync timing plan.
uint8_t ch_get_config(ch_dev_t *dev_ptr, ch_config_t *config_ptr)
Get current configuration settings for a sensor.
void ch_group_trigger(ch_group_t *grp_ptr)
Trigger a measurement on a group of sensors.
Internal definitions for the Chirp CH201 GPR Static Target Rejection sensor firmware.
uint8_t io_index
Definition: soniclib.h:368
uint8_t(* chdrv_discovery_hook_t)(ch_dev_t *dev_ptr)
Hook routine pointer typedefs.
Definition: ch_driver.h:98
ch_retval
Return value codes.
Definition: soniclib.h:145
ch_api_funcs_t api_funcs
Definition: soniclib.h:400
void(* store_scalefactor)(ch_dev_t *dev_ptr)
Definition: soniclib.h:390