swipeswitch  2.0.0.0
swipeswitch.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef SWIPESWITCH_H
36 #define SWIPESWITCH_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define SWIPESWITCH_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
55  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
56 
62 #define SWIPESWITCH_RETVAL uint8_t
63 
64 #define SWIPESWITCH_OK 0x00
65 #define SWIPESWITCH_INIT_ERROR 0xFF
66 
72 #define SWIPESWITCH_REG_DEVICE_INFO 0x00
73 #define SWIPESWITCH_REG_SYS_FLAGS 0x01
74 #define SWIPESWITCH_REG_TP_FLAGS 0x02
75 #define SWIPESWITCH_REG_COORDINATES 0x03
76 #define SWIPESWITCH_REG_CHANNEL_BYTES 0x04
77 #define SWIPESWITCH_REG_ACF_CH0 0x05
78 #define SWIPESWITCH_REG_ACF_CH1 0x06
79 #define SWIPESWITCH_REG_ACF_CH2 0x07
80 #define SWIPESWITCH_REG_ACF_CH3 0x08
81 #define SWIPESWITCH_REG_ACF_CH4 0x09
82 #define SWIPESWITCH_REG_ACF_CH5 0x0A
83 #define SWIPESWITCH_REG_ACF_CH6 0x0B
84 #define SWIPESWITCH_REG_LTA_CH0 0x0C
85 #define SWIPESWITCH_REG_LTA_CH1 0x0D
86 #define SWIPESWITCH_REG_LTA_CH2 0x0E
87 #define SWIPESWITCH_REG_LTA_CH3 0x0F
88 #define SWIPESWITCH_REG_LTA_CH4 0x10
89 #define SWIPESWITCH_REG_LTA_CH5 0x11
90 #define SWIPESWITCH_REG_LTA_CH6 0x12
91 #define SWIPESWITCH_REG_DELTA_CH0 0x13
92 #define SWIPESWITCH_REG_DELTA_CH1 0x14
93 #define SWIPESWITCH_REG_DELTA_CH2 0x15
94 #define SWIPESWITCH_REG_DELTA_CH3 0x16
95 #define SWIPESWITCH_REG_DELTA_CH4 0x17
96 #define SWIPESWITCH_REG_DELTA_CH5 0x18
97 #define SWIPESWITCH_REG_DELTA_CH6 0x19
98 #define SWIPESWITCH_REG_PROXSETTINGS_01 0x80
99 #define SWIPESWITCH_REG_PROXSETTINGS_23 0x81
100 #define SWIPESWITCH_REG_EVENT_MASK 0x82
101 #define SWIPESWITCH_REG_TIMEOUT_PERIODS 0x83
102 #define SWIPESWITCH_REG_REPORT_RATES 0x84
103 #define SWIPESWITCH_REG_THRESHOLDS_CH0 0x85
104 #define SWIPESWITCH_REG_TOUCH_THR_CH1_CH2 0x86
105 #define SWIPESWITCH_REG_TOUCH_THR_CH3_CH4 0x87
106 #define SWIPESWITCH_REG_TOUCH_THR_CH5_CH6 0x88
107 #define SWIPESWITCH_REG_ATI_TARGETS 0x89
108 #define SWIPESWITCH_REG_CHANNEL_SETTINGS 0x8A
109 #define SWIPESWITCH_REG_TAP_SETTINGS 0x8B
110 #define SWIPESWITCH_REG_SWIPE_SETTINGS 0x8C
111 
117 #define SWIPESWITCH_EVENT_PROX 0x01
118 #define SWIPESWITCH_EVENT_TOUCH 0x02
119 #define SWIPESWITCH_EVENT_TP 0x04
120 #define SWIPESWITCH_EVENT_ATI 0x08
121 #define SWIPESWITCH_EVENT_TAP 0x10
122 #define SWIPESWITCH_EVENT_SWIPE 0x20
123 #define SWIPESWITCH_EVENT_LP 0x80
124 #define SWIPESWITCH_EVENTS_ALL 0xFF
125 
131 #define SWIPESWITCH_GESTURE_TP 0x01
132 #define SWIPESWITCH_GESTURE_TAP 0x02
133 #define SWIPESWITCH_GESTURE_SWIPE_UP 0x04
134 #define SWIPESWITCH_GESTURE_SWIPE_DOWN 0x08
135 #define SWIPESWITCH_GESTURE_SWIPE_LEFT 0x10
136 #define SWIPESWITCH_GESTURE_SWIPE_RIGHT 0x20
137 
143 #define SWIPESWITCH_CH0_PROX 0x01
144 #define SWIPESWITCH_SHOW_RESET 0x80
145 #define SWIPESWITCH_ACK_RESET 0x80
146 #define SWIPESWITCH_REDO_ATI 0x10
147 #define SWIPESWITCH_EVENT_MODE 0x40
148 
149 
154 #define SWIPESWITCH_CH0_TOUCH 0x01
155 #define SWIPESWITCH_CH1_TOUCH 0x02
156 #define SWIPESWITCH_CH2_TOUCH 0x04
157 #define SWIPESWITCH_CH3_TOUCH 0x08
158 #define SWIPESWITCH_CH4_TOUCH 0x10
159 #define SWIPESWITCH_CH5_TOUCH 0x20
160 #define SWIPESWITCH_CH6_TOUCH 0x40
161 
167 #define SWIPESWITCH_TPF_SEGMENT_0 0x00
168 #define SWIPESWITCH_TPF_SEGMENT_1 0x40
169 #define SWIPESWITCH_TPF_SEGMENT_2 0x80
170 #define SWIPESWITCH_TPF_SEGMENT_3 0xC0
171 #define SWIPESWITCH_TPF_SWIPE_RIGHT 0x20
172 #define SWIPESWITCH_TPF_SWIPE_LEFT 0x10
173 #define SWIPESWITCH_TPF_SWIPE_DOWN 0x08
174 #define SWIPESWITCH_TPF_SWIPE_UP 0x04
175 #define SWIPESWITCH_TPF_TAP 0x02
176 #define SWIPESWITCH_TPF_TP_ACTIVE 0x01
177 
183 #define SWIPESWITCH_PS0_AUTO_ATI_ON 0x00
184 #define SWIPESWITCH_PS0_AUTO_ATI_OFF 0x80
185 #define SWIPESWITCH_PS0_NORMAL_ATI_ACTIVE 0x00
186 #define SWIPESWITCH_PS0_PARTIAL_ATI_ACTIVE 0x40
187 #define SWIPESWITCH_PS0_NORMAL_ATI_BAND 0x00
188 #define SWIPESWITCH_PS0_LARGE_ATI_BAND 0x20
189 #define SWIPESWITCH_PS0_REDO_AN_ATI 0x10
190 #define SWIPESWITCH_PS0_DEBUG_ATI_DISABLE 0x00
191 #define SWIPESWITCH_PS0_DEBUG_ATI_ENABLE 0x04
192 #define SWIPESWITCH_PS0_NORMAL_ANALOGUE_TIME 0x00
193 #define SWIPESWITCH_PS0_INCREASED_ANALOGUE_TIME 0x02
194 #define SWIPESWITCH_PS0_NORMAL_HALTING 0x00
195 #define SWIPESWITCH_PS0_Force_halt 0x01
196 
202 #define SWIPESWITCH_PS1_COMMUNICATION_WATCH_DOG_ENABLED 0x00
203 #define SWIPESWITCH_PS1_COMMUNICATION_WATCH_DOG_DISABLED 0x80
204 #define SWIPESWITCH_PS1_STREAMING_MODE 0x00
205 #define SWIPESWITCH_PS1_EVENT_MODE 0x40
206 #define SWIPESWITCH_PS1_LTA_BETA_1_512 0x00
207 #define SWIPESWITCH_PS1_LTA_BETA_1_256 0x10
208 #define SWIPESWITCH_PS1_LTA_BETA_1_128 0x20
209 #define SWIPESWITCH_PS1_LTA_BETA_1_64 0x30
210 #define SWIPESWITCH_PS1_ACF_BETA_1 0x01
211 #define SWIPESWITCH_PS1_ACF_BETA_2 0x02
212 #define SWIPESWITCH_PS1_ACF_BETA_3 0x03
213 #define SWIPESWITCH_PS1_ACF_FILTER_OFF 0x00
214 
220 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_1 0x00
221 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_2 0x01
222 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_4 0x02
223 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_8 0x03
224 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_16 0x04
225 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_32 0x05
226 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_64 0x06
227 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_128 0x07
228 
234 #define SWIPESWITCH_PS3_ACKNOWLEDGE_RESET 0x80
235 #define SWIPESWITCH_PS3_IC_IN_ON_MODE 0x00
236 #define SWIPESWITCH_PS3_IC_IN_OFF_MODE 0x40
237 #define SWIPESWITCH_PS3_BIAS_CURRENT_5uA 0x00
238 #define SWIPESWITCH_PS3_BIAS_CURRENT_10uA 0x20
239 #define SWIPESWITCH_PS3_GROUND_Cx_PINS 0x00
240 #define SWIPESWITCH_PS3_FLOAT_Cx_PINS 0x10
241 #define SWIPESWITCH_PS3_NORMAL_CHARGING 0x00
242 #define SWIPESWITCH_PS3_HALT_CHARGING 0x08
243 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH123456_2MHz 0x00
244 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH123456_1MHz 0x02
245 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH0_1MHz 0x00
246 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH0_500kHz 0x10
247 
253 #define SWIPESWITCH_CHANNEL_0 0x01
254 #define SWIPESWITCH_CHANNEL_1 0x02
255 #define SWIPESWITCH_CHANNEL_2 0x04
256 #define SWIPESWITCH_CHANNEL_3 0x08
257 #define SWIPESWITCH_CHANNEL_4 0x10
258 #define SWIPESWITCH_CHANNEL_5 0x20
259 #define SWIPESWITCH_CHANNEL_6 0x40
260 
263 #define SWIPESWITCH_DEVICE_SLAVE_ADDRESS 0x44
264  // End group macro
266 // --------------------------------------------------------------- PUBLIC TYPES
275 typedef struct
276 {
277  // Input pins
278 
279  digital_in_t rdy_in;
280 
281  // Modules
282 
283  i2c_master_t i2c;
284 
285  // ctx variable
286 
287  uint8_t slave_address;
288 
289 } swipeswitch_t;
290 
294 typedef struct
295 {
296  // Communication gpio pins
297 
298  pin_name_t scl;
299  pin_name_t sda;
300 
301  // Additional gpio pins
302 
303  pin_name_t rdy;
304 
305  // static variable
306 
307  uint32_t i2c_speed;
308  uint8_t i2c_address;
309 
311  // End types group
313 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
314 
320 #ifdef __cplusplus
321 extern "C"{
322 #endif
323 
333 
343 
354 void swipeswitch_generic_write ( swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
355 
366 void swipeswitch_generic_read ( swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
367 
378 
387 
395 void swipeswitch_disable_events ( swipeswitch_t *ctx, uint8_t event );
396 
404 void swipeswitch_enable_events ( swipeswitch_t *ctx, uint8_t event );
405 
414 
423 
433 
442 uint8_t swipeswitch_read_events ( swipeswitch_t *ctx );
443 
453 
463 
473 
482 
491 
500 
508 void swipeswitch_set_touch_sensitivity ( swipeswitch_t *ctx, uint8_t sensitivity );
509 
517 void swipeswitch_set_prox_sensitivity ( swipeswitch_t *ctx, uint8_t sensitivity );
518 
526 void swipeswitch_set_event_mask ( swipeswitch_t *ctx, uint8_t event_mask );
527 
535 void swipeswitch_enable_channel ( swipeswitch_t *ctx, uint8_t channel );
536 
544 void swipeswitch_disable_channel ( swipeswitch_t *ctx, uint8_t channel );
545 
553 uint16_t swipeswitch_read_channel ( swipeswitch_t *ctx, uint8_t read_data, uint8_t channel );
554 
562 void swipeswitch_set_tap_timer_limit ( swipeswitch_t *ctx, uint8_t time_limit );
563 
571 void swipeswitch_set_tap_threshold ( swipeswitch_t *ctx, uint8_t threshold );
572 
580 void swipeswitch_set_swipe_timer_limit ( swipeswitch_t *ctx, uint8_t time_limit );
581 
589 void swipeswitch_set_swipe_threshold ( swipeswitch_t *ctx, uint8_t threshold );
590 
598 void swipeswitch_set_report_rate_nm ( swipeswitch_t *ctx, uint8_t report_rate );
599 
607 void swipeswitch_set_report_rate_lp ( swipeswitch_t *ctx, uint8_t report_rate );
608 
616 void swipeswitch_set_np_segment_rate ( swipeswitch_t *ctx, uint8_t segment_rate );
617 
625 void swipeswitch_set_zoom_timeout ( swipeswitch_t *ctx, uint8_t timeout_period );
626 
634 void swipeswitch_set_halt_timeout ( swipeswitch_t *ctx, uint8_t halt_time );
635 
636 
637 #ifdef __cplusplus
638 }
639 #endif
640 #endif // _SWIPESWITCH_H_
641  // End public_function group
644 
645 // ------------------------------------------------------------------------- END
swipeswitch_set_halt_timeout
void swipeswitch_set_halt_timeout(swipeswitch_t *ctx, uint8_t halt_time)
Function for setting halt timeout.
SWIPESWITCH_RETVAL
#define SWIPESWITCH_RETVAL
Definition: swipeswitch.h:62
swipeswitch_wait_for_ready
uint8_t swipeswitch_wait_for_ready(swipeswitch_t *ctx)
Function that waits for the module to be ready for operation.
swipeswitch_generic_read
void swipeswitch_generic_read(swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
swipeswitch_read_trackpad_flags
uint8_t swipeswitch_read_trackpad_flags(swipeswitch_t *ctx)
Function for reading Trackpad falgs.
swipeswitch_set_report_rate_lp
void swipeswitch_set_report_rate_lp(swipeswitch_t *ctx, uint8_t report_rate)
Function for setting report rate LP.
swipeswitch_set_tap_threshold
void swipeswitch_set_tap_threshold(swipeswitch_t *ctx, uint8_t threshold)
Function for setting tap threshold.
swipeswitch_t
Click ctx object definition.
Definition: swipeswitch.h:275
swipeswitch_cfg_t::i2c_address
uint8_t i2c_address
Definition: swipeswitch.h:308
swipeswitch_set_report_rate_nm
void swipeswitch_set_report_rate_nm(swipeswitch_t *ctx, uint8_t report_rate)
Function for setting report rate NM.
swipeswitch_enable_events
void swipeswitch_enable_events(swipeswitch_t *ctx, uint8_t event)
Function for enabled Event.
swipeswitch_read_touch_byte
uint8_t swipeswitch_read_touch_byte(swipeswitch_t *ctx)
Function for reading Touch byte.
swipeswitch_disable_halt_timeout
void swipeswitch_disable_halt_timeout(swipeswitch_t *ctx)
Function for disable halt time.
swipeswitch_disable_events
void swipeswitch_disable_events(swipeswitch_t *ctx, uint8_t event)
Function for disabled Event.
swipeswitch_read_x_coordinate
uint8_t swipeswitch_read_x_coordinate(swipeswitch_t *ctx)
Function for reading X coordinate.
swipeswitch_set_prox_sensitivity
void swipeswitch_set_prox_sensitivity(swipeswitch_t *ctx, uint8_t sensitivity)
Function for setting Prox Sensitivity.
swipeswitch_set_np_segment_rate
void swipeswitch_set_np_segment_rate(swipeswitch_t *ctx, uint8_t segment_rate)
Function for setting segment rate.
swipeswitch_enable_channel
void swipeswitch_enable_channel(swipeswitch_t *ctx, uint8_t channel)
Function for enabling channels.
swipeswitch_set_zoom_timeout
void swipeswitch_set_zoom_timeout(swipeswitch_t *ctx, uint8_t timeout_period)
Function for setting zoom timeout.
swipeswitch_go_to_stream_mode
void swipeswitch_go_to_stream_mode(swipeswitch_t *ctx)
Function for Stream mode.
swipeswitch_read_prox_byte
uint8_t swipeswitch_read_prox_byte(swipeswitch_t *ctx)
Function for reading Prox byte.
swipeswitch_go_to_event_mode
void swipeswitch_go_to_event_mode(swipeswitch_t *ctx)
Function for Event mode.
swipeswitch_t::slave_address
uint8_t slave_address
Definition: swipeswitch.h:287
swipeswitch_t::i2c
i2c_master_t i2c
Definition: swipeswitch.h:283
swipeswitch_cfg_t::scl
pin_name_t scl
Definition: swipeswitch.h:298
swipeswitch_set_event_mask
void swipeswitch_set_event_mask(swipeswitch_t *ctx, uint8_t event_mask)
Function for setting Event mask.
swipeswitch_read_events
uint8_t swipeswitch_read_events(swipeswitch_t *ctx)
Function for reading event.
swipeswitch_disable_channel
void swipeswitch_disable_channel(swipeswitch_t *ctx, uint8_t channel)
Function for disabling channels.
swipeswitch_read_y_coordinate
uint8_t swipeswitch_read_y_coordinate(swipeswitch_t *ctx)
Function for reading Y coordinate.
swipeswitch_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: swipeswitch.h:307
swipeswitch_set_swipe_timer_limit
void swipeswitch_set_swipe_timer_limit(swipeswitch_t *ctx, uint8_t time_limit)
Function for setting swipe timer limit.
swipeswitch_read_system_flags
uint8_t swipeswitch_read_system_flags(swipeswitch_t *ctx)
Function for reads system falgs.
swipeswitch_read_channel
uint16_t swipeswitch_read_channel(swipeswitch_t *ctx, uint8_t read_data, uint8_t channel)
Function for reading channel.
swipeswitch_init
SWIPESWITCH_RETVAL swipeswitch_init(swipeswitch_t *ctx, swipeswitch_cfg_t *cfg)
Initialization function.
swipeswitch_t::rdy_in
digital_in_t rdy_in
Definition: swipeswitch.h:279
swipeswitch_cfg_setup
void swipeswitch_cfg_setup(swipeswitch_cfg_t *cfg)
Config Object Initialization function.
swipeswitch_read_gestures
uint8_t swipeswitch_read_gestures(swipeswitch_t *ctx)
Function for reading Gestures.
swipeswitch_generic_write
void swipeswitch_generic_write(swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
swipeswitch_set_touch_sensitivity
void swipeswitch_set_touch_sensitivity(swipeswitch_t *ctx, uint8_t sensitivity)
Function for setting Touch Sensitivity.
swipeswitch_cfg_t::rdy
pin_name_t rdy
Definition: swipeswitch.h:303
swipeswitch_set_tap_timer_limit
void swipeswitch_set_tap_timer_limit(swipeswitch_t *ctx, uint8_t time_limit)
Function for setting tap timer limit.
swipeswitch_set_swipe_threshold
void swipeswitch_set_swipe_threshold(swipeswitch_t *ctx, uint8_t threshold)
Function for setting swipe threshold.
swipeswitch_cfg_t
Click configuration structure definition.
Definition: swipeswitch.h:294
swipeswitch_cfg_t::sda
pin_name_t sda
Definition: swipeswitch.h:299