Chirp SonicLib  2.1.0
ch_common.h
Go to the documentation of this file.
1 
15 /*
16  * Copyright © 2016-2020, Chirp Microsystems. All rights reserved.
17  *
18  * Chirp Microsystems CONFIDENTIAL
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23  * DISCLAIMED. IN NO EVENT SHALL CHIRP MICROSYSTEMS BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  * You can contact the authors of this program by email at support@chirpmicro.com
32  * or by mail at 2560 Ninth Street, Suite 220, Berkeley, CA 94710.
33  */
34 
35 #ifndef CH_COMMON_H_
36 #define CH_COMMON_H_
37 
38 #include "soniclib.h"
39 #include <stdint.h>
40 
41 /* CH-101 common definitions */
42 
43 #define CH101_COMMON_REG_OPMODE 0x01
44 #define CH101_COMMON_REG_TICK_INTERVAL 0x02
45 #define CH101_COMMON_REG_PERIOD 0x05
46 #define CH101_COMMON_REG_CAL_TRIG 0x06
47 #define CH101_COMMON_REG_MAX_RANGE 0x07
48 #define CH101_COMMON_REG_TIME_PLAN 0x09
49 #define CH101_COMMON_REG_CAL_RESULT 0x0A
50 #define CH101_COMMON_REG_RX_HOLDOFF 0x11
51 #define CH101_COMMON_REG_STAT_RANGE 0x12
52 #define CH101_COMMON_REG_STAT_COEFF 0x13
53 #define CH101_COMMON_REG_READY 0x14
54 #define CH101_COMMON_REG_TOF_SF 0x16
55 #define CH101_COMMON_REG_TOF 0x18
56 #define CH101_COMMON_REG_AMPLITUDE 0x1A
57 #define CH101_COMMON_REG_DATA 0x1C
58 
59 #define CH101_COMMON_I2CREGS_OFFSET 0
60 
61 #define CH101_COMMON_READY_FREQ_LOCKED (0x02) // XXX need more values (?)
62 
63 #define CH101_COMMON_FREQCOUNTERCYCLES (128)
64 
65 #define CH101_COMMON_STAT_COEFF_DEFAULT (6) // default value for stationary target coefficient
66 #define CH101_COMMON_NUM_THRESHOLDS (6) // total number of thresholds
67 
68 /* CH-201 common definitions */
69 
70 #define CH201_COMMON_REG_OPMODE 0x01
71 #define CH201_COMMON_REG_TICK_INTERVAL 0x02
72 #define CH201_COMMON_REG_PERIOD 0x05
73 #define CH201_COMMON_REG_CAL_TRIG 0x06
74 #define CH201_COMMON_REG_MAX_RANGE 0x07
75 #define CH201_COMMON_REG_THRESH_LEN_0 0x08
76 #define CH201_COMMON_REG_THRESH_LEN_1 0x09
77 #define CH201_COMMON_REG_CAL_RESULT 0x0A
78 #define CH201_COMMON_REG_THRESH_LEN_2 0x0C
79 #define CH201_COMMON_REG_THRESH_LEN_3 0x0D
80 #define CH201_COMMON_REG_RX_HOLDOFF 0x11
81 #define CH201_COMMON_REG_ST_RANGE 0x12
82 #define CH201_COMMON_REG_READY 0x14
83 #define CH201_COMMON_REG_THRESH_LEN_4 0x15
84 #define CH201_COMMON_REG_THRESHOLDS 0x16 // start of array of six 2-byte threshold levels
85 #define CH201_COMMON_REG_TOF_SF 0x22
86 #define CH201_COMMON_REG_TOF 0x24
87 #define CH201_COMMON_REG_AMPLITUDE 0x26
88 #define CH201_COMMON_REG_DATA 0x28
89 
90 #define CH201_COMMON_I2CREGS_OFFSET 0
91 
92 #define CH201_COMMON_READY_FREQ_LOCKED (0x02) // XXX need more values (?)
93 
94 #define CH201_COMMON_FREQCOUNTERCYCLES (128)
95 
96 #define CH201_COMMON_NUM_THRESHOLDS (6) // total number of thresholds
97 
98 
99 /* Function prototypes */
100 
101 uint8_t ch_common_set_mode(ch_dev_t *dev_ptr, ch_mode_t mode);
102 
103 uint8_t ch_common_fw_load(ch_dev_t *dev_ptr);
104 
105 uint8_t ch_common_set_sample_interval(ch_dev_t *dev_ptr, uint16_t interval_ms);
106 
107 uint8_t ch_common_set_num_samples( ch_dev_t* dev_ptr, uint16_t num_samples );
108 
109 uint8_t ch_common_set_max_range(ch_dev_t *dev_ptr, uint16_t max_range_mm);
110 
111 uint8_t ch_common_set_static_range(ch_dev_t *dev_ptr, uint16_t samples);
112 
113 uint32_t ch_common_get_range(ch_dev_t *dev_ptr, ch_range_t range_type);
114 
115 uint16_t ch_common_get_amplitude(ch_dev_t *dev_ptr);
116 
117 uint8_t ch_common_get_locked_state(ch_dev_t *dev_ptr);
118 
119 uint32_t ch_common_get_op_freq(ch_dev_t *dev_ptr);
120 
121 void ch_common_prepare_pulse_timer(ch_dev_t *dev_ptr);
122 
123 void ch_common_store_pt_result(ch_dev_t *dev_ptr);
124 
125 void ch_common_store_op_freq(ch_dev_t *dev_ptr);
126 
127 void ch_common_store_bandwidth(ch_dev_t *dev_ptr);
128 
129 void ch_common_store_scale_factor(ch_dev_t *dev_ptr);
130 
131 uint8_t ch_common_set_thresholds(ch_dev_t *dev_ptr, ch_thresholds_t *thresholds_ptr);
132 
133 uint8_t ch_common_get_thresholds(ch_dev_t *dev_ptr, ch_thresholds_t *thresholds_ptr);
134 
135 uint16_t ch_common_mm_to_samples(ch_dev_t *dev_ptr, uint16_t num_mm);
136 
137 uint16_t ch_common_samples_to_mm(ch_dev_t *dev_ptr, uint16_t num_samples);
138 
139 uint8_t ch_common_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 nonblock);
140 
141 uint8_t ch_common_set_sample_window(ch_dev_t *dev_ptr, uint16_t start_sample, uint16_t end_sample);
142 
143 uint8_t ch_common_set_time_plan(ch_dev_t *dev_ptr, ch_time_plan_t time_plan);
144 
145 ch_time_plan_t ch_common_get_time_plan(ch_dev_t *dev_ptr);
146 uint16_t ch_common_get_amplitude_avg(ch_dev_t *dev_ptr);
147 
148 uint8_t ch_common_get_amplitude_data(ch_dev_t *dev_ptr, uint16_t *buf_ptr, uint16_t start_sample, uint16_t num_samples,
149  ch_io_mode_t mode);
150 
151 uint8_t ch_common_set_rx_holdoff(ch_dev_t *dev_ptr, uint16_t rx_holdoff);
152 
153 uint16_t ch_common_get_rx_holdoff(ch_dev_t *dev_ptr);
154 #endif
155 
ch_mode_t
Sensor operating modes.
Definition: soniclib.h:158
ch_time_plan_t
Time plan.
Definition: soniclib.h:181
Chirp SonicLib public API and support functions for Chirp ultrasonic sensors.
Chirp sensor device structure.
Definition: soniclib.h:349
Sensor I/Q data value.
Definition: soniclib.h:201
ch_io_mode_t
I/O blocking mode flags.
Definition: soniclib.h:175
ch_range_t
Range data types.
Definition: soniclib.h:151
Multiple detection threshold structure (CH201 only).
Definition: soniclib.h:215