proximity6  2.0.0.0
proximity6.h
Go to the documentation of this file.
1 
2 /*
3  * MikroSDK - MikroE Software Development Kit
4  * Copyright© 2020 MikroElektronika d.o.o.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated documentation
8  * files (the "Software"), to deal in the Software without restriction,
9  * including without limitation the rights to use, copy, modify, merge,
10  * publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so,
12  * subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be
15  * included in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
23  * OR OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
34 // ----------------------------------------------------------------------------
35 
36 #ifndef PROXIMITY6_H
37 #define PROXIMITY6_H
38 
43 #ifdef PREINIT_SUPPORTED
44 #include "preinit.h"
45 #endif
46 
47 #ifdef MikroCCoreVersion
48  #if MikroCCoreVersion >= 1
49  #include "delays.h"
50  #endif
51 #endif
52 
53 #include "drv_digital_out.h"
54 #include "drv_digital_in.h"
55 #include "drv_i2c_master.h"
56 
57 
58 // -------------------------------------------------------------- PUBLIC MACROS
68 #define PROXIMITY6_MAP_MIKROBUS( cfg, mikrobus ) \
69  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
70  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
71  cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
72 
78 #define PROXIMITY6_OK 0
79 #define PROXIMITY6_ERROR -1
80 
86 #define PROXIMITY6_REG_DATA_REGISTER_X1 0x00
87 #define PROXIMITY6_REG_DATA_REGISTER_X2 0x01
88 #define PROXIMITY6_REG_DATA_REGISTER_Y1 0x02
89 #define PROXIMITY6_REG_DATA_REGISTER_Y2 0x03
90 #define PROXIMITY6_REG_DATA_REGISTER_SAMPLE_I 0x04
91 #define PROXIMITY6_REG_DATA_REGISTER_SAMPLE_X 0x05
92 #define PROXIMITY6_REG_DATA_REGISTER_SAMPLE_Y 0x06
93 #define PROXIMITY6_REG_RESERVED1 0x07
94 #define PROXIMITY6_REG_ID_VERSION 0x08
95 #define PROXIMITY6_REG_SLAVE_ADDRESS 0x09
96 #define PROXIMITY6_REG_OSC_CAL_OUT 0x0A
97 #define PROXIMITY6_REG_RESERVED2 0x0C
98 #define PROXIMITY6_REG_SW_RESET 0x0F
99 #define PROXIMITY6_REG_ADC_CONTROL_RESERVED1 0x10
100 #define PROXIMITY6_REG_ADC_CONTROL_RESERVED2 0x11
101 #define PROXIMITY6_REG_AFE_TRIM 0x12
102 #define PROXIMITY6_REG_AFE_MUX_TEST 0x13
103 #define PROXIMITY6_REG_RESERVED3 0x14
104 #define PROXIMITY6_REG_LED_TRIM 0x16
105 #define PROXIMITY6_REG_OS32K 0x18
106 #define PROXIMITY6_REG_OS32M_BYPASS 0x19
107 #define PROXIMITY6_REG_OS32M_TRIM 0x1A
108 #define PROXIMITY6_REG_ADC_SPACING 0x1B
109 #define PROXIMITY6_REG_INT_PIN 0x1C
110 #define PROXIMITY6_REG_INT_PIN_POL 0x1D
111 #define PROXIMITY6_REG_I2C 0x1E
112 #define PROXIMITY6_REG_FIFO_TH 0x1F
113 #define PROXIMITY6_REG_LED_OFFSET_WIDTH_GEST 0x20
114 #define PROXIMITY6_REG_LED_PERIOD_PULSES_GEST 0x21
115 #define PROXIMITY6_REG_LED_OFFSET_WIDTH_PROX 0x22
116 #define PROXIMITY6_REG_LED_PERIOD_PULSES_PROX 0x23
117 #define PROXIMITY6_REG_LED_MASK 0x24
118 #define PROXIMITY6_REG_AFE_CONT_GEST 0x25
119 #define PROXIMITY6_REG_AFE_CONT_PROX 0x26
120 #define PROXIMITY6_REG_AFE_MASK 0x27
121 #define PROXIMITY6_REG_GEST_DI_TH 0x28
122 #define PROXIMITY6_REG_ORIENTATION 0x29
123 #define PROXIMITY6_REG_PROX_TH_ON1 0x2A
124 #define PROXIMITY6_REG_PROX_TH_OFF1 0x2B
125 #define PROXIMITY6_REG_PROX_TH_ON2 0x2C
126 #define PROXIMITY6_REG_PROX_TH_OFF2 0x2D
127 #define PROXIMITY6_REG_PROX_TH_ON1_OFF1_HIGH 0x2E
128 #define PROXIMITY6_REG_PROX_TH_ON2_OFF2_HIGH 0x2F
129 #define PROXIMITY6_REG_TEST_MODE 0x30
130 #define PROXIMITY6_REG_POWER_DOWN_CONT 0x32
131 #define PROXIMITY6_REG_GAIN_CONT1 0x38
132 #define PROXIMITY6_REG_GAIN_CONT2 0x39
133 #define PROXIMITY6_REG_CH1_OFFSET 0x3A
134 #define PROXIMITY6_REG_CH2_OFFSET 0x3B
135 #define PROXIMITY6_REG_CH3_OFFSET 0x3C
136 #define PROXIMITY6_REG_CH4_OFFSET 0x3D
137 #define PROXIMITY6_REG_SLOPE_TH 0x3E
138 #define PROXIMITY6_REG_FREQ 0x40
139 #define PROXIMITY6_REG_LED_REF 0x41
140 #define PROXIMITY6_REG_OP_TIME 0x42
141 #define PROXIMITY6_REG_AFE_TIME 0x43
142 #define PROXIMITY6_REG_DSAMPLE_TIME 0x44
143 #define PROXIMITY6_REG_OPERATION_CONTROL 0x45
144 #define PROXIMITY6_REG_DEC_MODE 0x46
145 #define PROXIMITY6_REG_INT_MASK 0x48
146 #define PROXIMITY6_REG_INT_STATUS 0x49
147 #define PROXIMITY6_REG_I2C_STATUS 0x4A
148 #define PROXIMITY6_REG_DATA_BUFFER_OUT 0x60
149 #define PROXIMITY6_REG_DEBUG_X1L 0x68
150 #define PROXIMITY6_REG_DEBUG_X2L 0x69
151 #define PROXIMITY6_REG_DEBUG_Y1L 0x6A
152 #define PROXIMITY6_REG_DEBUG_Y2L 0x6B
153 #define PROXIMITY6_REG_DEBUG_X1H 0x6C
154 #define PROXIMITY6_REG_DEBUG_X2H 0x6D
155 #define PROXIMITY6_REG_DEBUG_Y1H 0x6E
156 #define PROXIMITY6_REG_DEBUG_Y2H 0x6F
157 
163 #define PROXIMITY6_STANDBY_MODE 0
164 #define PROXIMITY6_PROXIMITY_MODE 1
165 #define PROXIMITY6_SAMPLE_MODE 2
166 #define PROXIMITY6_IDLE_MODE 3
167  // End group macro
170 // --------------------------------------------------------------- PUBLIC TYPES
179 typedef struct
180 {
181  // Input pins
182  digital_in_t int_pin;
183 
184  // Modules
185  i2c_master_t i2c;
186 
187  // ctx variable
188  uint8_t slave_address;
189  uint8_t mode_sel;
190 
191 } proximity6_t;
192 
196 typedef struct
197 {
198  // Communication gpio pins
199  pin_name_t scl;
200  pin_name_t sda;
201 
202  // Additional gpio pins
203  pin_name_t int_pin;
204 
205  // static variable
206  uint32_t i2c_speed;
207  uint8_t i2c_address;
208 
210 
214 typedef struct
215 {
216  uint16_t val_x1;
217  uint16_t val_x2;
218  uint16_t val_y1;
219  uint16_t val_y2;
220 
222 
223 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
224 
230 #ifdef __cplusplus
231 extern "C"{
232 #endif
233 
243 
256 
268 
282 err_t proximity6_generic_write ( proximity6_t *ctx, uint8_t reg, uint16_t *data_buf, uint8_t len );
283 
297 err_t proximity6_generic_read ( proximity6_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t len );
298 
310 err_t proximity6_set_mode( proximity6_t *ctx, uint8_t select_mode );
311 
324 
336 
337 #ifdef __cplusplus
338 }
339 #endif
340 #endif // _PROXIMITY6_H_
341  // End public_function group
344 
345 // ------------------------------------------------------------------------- END
proximity6_cfg_t::int_pin
pin_name_t int_pin
Definition: proximity6.h:203
proximity6_t::slave_address
uint8_t slave_address
Definition: proximity6.h:188
proximity6_default_cfg
err_t proximity6_default_cfg(proximity6_t *ctx)
Click Default Configuration function.
proximity6_check_interrupt
uint8_t proximity6_check_interrupt(proximity6_t *ctx)
Interrupt Check function.
proximity6_cfg_t
Click configuration structure definition.
Definition: proximity6.h:197
proximity6_data_t::val_x1
uint16_t val_x1
Definition: proximity6.h:216
proximity6_t::mode_sel
uint8_t mode_sel
Definition: proximity6.h:189
proximity6_init
err_t proximity6_init(proximity6_t *ctx, proximity6_cfg_t *cfg)
Initialization function.
proximity6_t
Click ctx object definition.
Definition: proximity6.h:180
proximity6_data_t::val_y1
uint16_t val_y1
Definition: proximity6.h:218
proximity6_set_mode
err_t proximity6_set_mode(proximity6_t *ctx, uint8_t select_mode)
Mode Set function.
proximity6_t::int_pin
digital_in_t int_pin
Definition: proximity6.h:182
proximity6_cfg_setup
void proximity6_cfg_setup(proximity6_cfg_t *cfg)
Config Object Initialization function.
proximity6_data_t
Click axis data structure definition.
Definition: proximity6.h:215
proximity6_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: proximity6.h:206
proximity6_data_t::val_x2
uint16_t val_x2
Definition: proximity6.h:217
proximity6_t::i2c
i2c_master_t i2c
Definition: proximity6.h:185
proximity6_cfg_t::sda
pin_name_t sda
Definition: proximity6.h:200
proximity6_generic_read
err_t proximity6_generic_read(proximity6_t *ctx, uint8_t reg, uint16_t *data_out, uint8_t len)
Generic read function.
proximity6_data_t::val_y2
uint16_t val_y2
Definition: proximity6.h:219
proximity6_cfg_t::i2c_address
uint8_t i2c_address
Definition: proximity6.h:207
proximity6_generic_write
err_t proximity6_generic_write(proximity6_t *ctx, uint8_t reg, uint16_t *data_buf, uint8_t len)
Generic write function.
proximity6_read_data
err_t proximity6_read_data(proximity6_t *ctx, proximity6_data_t *axis_out)
Data Read function.
proximity6_cfg_t::scl
pin_name_t scl
Definition: proximity6.h:199