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 "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define SWIPESWITCH_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
65  cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
66 
72 #define SWIPESWITCH_RETVAL uint8_t
73 
74 #define SWIPESWITCH_OK 0x00
75 #define SWIPESWITCH_INIT_ERROR 0xFF
76 
82 #define SWIPESWITCH_REG_DEVICE_INFO 0x00
83 #define SWIPESWITCH_REG_SYS_FLAGS 0x01
84 #define SWIPESWITCH_REG_TP_FLAGS 0x02
85 #define SWIPESWITCH_REG_COORDINATES 0x03
86 #define SWIPESWITCH_REG_CHANNEL_BYTES 0x04
87 #define SWIPESWITCH_REG_ACF_CH0 0x05
88 #define SWIPESWITCH_REG_ACF_CH1 0x06
89 #define SWIPESWITCH_REG_ACF_CH2 0x07
90 #define SWIPESWITCH_REG_ACF_CH3 0x08
91 #define SWIPESWITCH_REG_ACF_CH4 0x09
92 #define SWIPESWITCH_REG_ACF_CH5 0x0A
93 #define SWIPESWITCH_REG_ACF_CH6 0x0B
94 #define SWIPESWITCH_REG_LTA_CH0 0x0C
95 #define SWIPESWITCH_REG_LTA_CH1 0x0D
96 #define SWIPESWITCH_REG_LTA_CH2 0x0E
97 #define SWIPESWITCH_REG_LTA_CH3 0x0F
98 #define SWIPESWITCH_REG_LTA_CH4 0x10
99 #define SWIPESWITCH_REG_LTA_CH5 0x11
100 #define SWIPESWITCH_REG_LTA_CH6 0x12
101 #define SWIPESWITCH_REG_DELTA_CH0 0x13
102 #define SWIPESWITCH_REG_DELTA_CH1 0x14
103 #define SWIPESWITCH_REG_DELTA_CH2 0x15
104 #define SWIPESWITCH_REG_DELTA_CH3 0x16
105 #define SWIPESWITCH_REG_DELTA_CH4 0x17
106 #define SWIPESWITCH_REG_DELTA_CH5 0x18
107 #define SWIPESWITCH_REG_DELTA_CH6 0x19
108 #define SWIPESWITCH_REG_PROXSETTINGS_01 0x80
109 #define SWIPESWITCH_REG_PROXSETTINGS_23 0x81
110 #define SWIPESWITCH_REG_EVENT_MASK 0x82
111 #define SWIPESWITCH_REG_TIMEOUT_PERIODS 0x83
112 #define SWIPESWITCH_REG_REPORT_RATES 0x84
113 #define SWIPESWITCH_REG_THRESHOLDS_CH0 0x85
114 #define SWIPESWITCH_REG_TOUCH_THR_CH1_CH2 0x86
115 #define SWIPESWITCH_REG_TOUCH_THR_CH3_CH4 0x87
116 #define SWIPESWITCH_REG_TOUCH_THR_CH5_CH6 0x88
117 #define SWIPESWITCH_REG_ATI_TARGETS 0x89
118 #define SWIPESWITCH_REG_CHANNEL_SETTINGS 0x8A
119 #define SWIPESWITCH_REG_TAP_SETTINGS 0x8B
120 #define SWIPESWITCH_REG_SWIPE_SETTINGS 0x8C
121 
127 #define SWIPESWITCH_EVENT_PROX 0x01
128 #define SWIPESWITCH_EVENT_TOUCH 0x02
129 #define SWIPESWITCH_EVENT_TP 0x04
130 #define SWIPESWITCH_EVENT_ATI 0x08
131 #define SWIPESWITCH_EVENT_TAP 0x10
132 #define SWIPESWITCH_EVENT_SWIPE 0x20
133 #define SWIPESWITCH_EVENT_LP 0x80
134 #define SWIPESWITCH_EVENTS_ALL 0xFF
135 
141 #define SWIPESWITCH_GESTURE_TP 0x01
142 #define SWIPESWITCH_GESTURE_TAP 0x02
143 #define SWIPESWITCH_GESTURE_SWIPE_UP 0x04
144 #define SWIPESWITCH_GESTURE_SWIPE_DOWN 0x08
145 #define SWIPESWITCH_GESTURE_SWIPE_LEFT 0x10
146 #define SWIPESWITCH_GESTURE_SWIPE_RIGHT 0x20
147 
153 #define SWIPESWITCH_CH0_PROX 0x01
154 #define SWIPESWITCH_SHOW_RESET 0x80
155 #define SWIPESWITCH_ACK_RESET 0x80
156 #define SWIPESWITCH_REDO_ATI 0x10
157 #define SWIPESWITCH_EVENT_MODE 0x40
158 
159 
164 #define SWIPESWITCH_CH0_TOUCH 0x01
165 #define SWIPESWITCH_CH1_TOUCH 0x02
166 #define SWIPESWITCH_CH2_TOUCH 0x04
167 #define SWIPESWITCH_CH3_TOUCH 0x08
168 #define SWIPESWITCH_CH4_TOUCH 0x10
169 #define SWIPESWITCH_CH5_TOUCH 0x20
170 #define SWIPESWITCH_CH6_TOUCH 0x40
171 
177 #define SWIPESWITCH_TPF_SEGMENT_0 0x00
178 #define SWIPESWITCH_TPF_SEGMENT_1 0x40
179 #define SWIPESWITCH_TPF_SEGMENT_2 0x80
180 #define SWIPESWITCH_TPF_SEGMENT_3 0xC0
181 #define SWIPESWITCH_TPF_SWIPE_RIGHT 0x20
182 #define SWIPESWITCH_TPF_SWIPE_LEFT 0x10
183 #define SWIPESWITCH_TPF_SWIPE_DOWN 0x08
184 #define SWIPESWITCH_TPF_SWIPE_UP 0x04
185 #define SWIPESWITCH_TPF_TAP 0x02
186 #define SWIPESWITCH_TPF_TP_ACTIVE 0x01
187 
193 #define SWIPESWITCH_PS0_AUTO_ATI_ON 0x00
194 #define SWIPESWITCH_PS0_AUTO_ATI_OFF 0x80
195 #define SWIPESWITCH_PS0_NORMAL_ATI_ACTIVE 0x00
196 #define SWIPESWITCH_PS0_PARTIAL_ATI_ACTIVE 0x40
197 #define SWIPESWITCH_PS0_NORMAL_ATI_BAND 0x00
198 #define SWIPESWITCH_PS0_LARGE_ATI_BAND 0x20
199 #define SWIPESWITCH_PS0_REDO_AN_ATI 0x10
200 #define SWIPESWITCH_PS0_DEBUG_ATI_DISABLE 0x00
201 #define SWIPESWITCH_PS0_DEBUG_ATI_ENABLE 0x04
202 #define SWIPESWITCH_PS0_NORMAL_ANALOGUE_TIME 0x00
203 #define SWIPESWITCH_PS0_INCREASED_ANALOGUE_TIME 0x02
204 #define SWIPESWITCH_PS0_NORMAL_HALTING 0x00
205 #define SWIPESWITCH_PS0_Force_halt 0x01
206 
212 #define SWIPESWITCH_PS1_COMMUNICATION_WATCH_DOG_ENABLED 0x00
213 #define SWIPESWITCH_PS1_COMMUNICATION_WATCH_DOG_DISABLED 0x80
214 #define SWIPESWITCH_PS1_STREAMING_MODE 0x00
215 #define SWIPESWITCH_PS1_EVENT_MODE 0x40
216 #define SWIPESWITCH_PS1_LTA_BETA_1_512 0x00
217 #define SWIPESWITCH_PS1_LTA_BETA_1_256 0x10
218 #define SWIPESWITCH_PS1_LTA_BETA_1_128 0x20
219 #define SWIPESWITCH_PS1_LTA_BETA_1_64 0x30
220 #define SWIPESWITCH_PS1_ACF_BETA_1 0x01
221 #define SWIPESWITCH_PS1_ACF_BETA_2 0x02
222 #define SWIPESWITCH_PS1_ACF_BETA_3 0x03
223 #define SWIPESWITCH_PS1_ACF_FILTER_OFF 0x00
224 
230 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_1 0x00
231 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_2 0x01
232 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_4 0x02
233 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_8 0x03
234 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_16 0x04
235 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_32 0x05
236 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_64 0x06
237 #define SWIPESWITCH_PS2_NP_SEGMENT_RATE_128 0x07
238 
244 #define SWIPESWITCH_PS3_ACKNOWLEDGE_RESET 0x80
245 #define SWIPESWITCH_PS3_IC_IN_ON_MODE 0x00
246 #define SWIPESWITCH_PS3_IC_IN_OFF_MODE 0x40
247 #define SWIPESWITCH_PS3_BIAS_CURRENT_5uA 0x00
248 #define SWIPESWITCH_PS3_BIAS_CURRENT_10uA 0x20
249 #define SWIPESWITCH_PS3_GROUND_Cx_PINS 0x00
250 #define SWIPESWITCH_PS3_FLOAT_Cx_PINS 0x10
251 #define SWIPESWITCH_PS3_NORMAL_CHARGING 0x00
252 #define SWIPESWITCH_PS3_HALT_CHARGING 0x08
253 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH123456_2MHz 0x00
254 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH123456_1MHz 0x02
255 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH0_1MHz 0x00
256 #define SWIPESWITCH_PS3_CHARGING_FREQ_CH0_500kHz 0x10
257 
263 #define SWIPESWITCH_CHANNEL_0 0x01
264 #define SWIPESWITCH_CHANNEL_1 0x02
265 #define SWIPESWITCH_CHANNEL_2 0x04
266 #define SWIPESWITCH_CHANNEL_3 0x08
267 #define SWIPESWITCH_CHANNEL_4 0x10
268 #define SWIPESWITCH_CHANNEL_5 0x20
269 #define SWIPESWITCH_CHANNEL_6 0x40
270 
273 #define SWIPESWITCH_DEVICE_SLAVE_ADDRESS 0x44
274  // End group macro
276 // --------------------------------------------------------------- PUBLIC TYPES
285 typedef struct
286 {
287  // Input pins
288 
289  digital_in_t rdy_in;
290 
291  // Modules
292 
293  i2c_master_t i2c;
294 
295  // ctx variable
296 
297  uint8_t slave_address;
298 
299 } swipeswitch_t;
300 
304 typedef struct
305 {
306  // Communication gpio pins
307 
308  pin_name_t scl;
309  pin_name_t sda;
310 
311  // Additional gpio pins
312 
313  pin_name_t rdy;
314 
315  // static variable
316 
317  uint32_t i2c_speed;
318  uint8_t i2c_address;
319 
321  // End types group
323 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
324 
330 #ifdef __cplusplus
331 extern "C"{
332 #endif
333 
343 
353 
364 void swipeswitch_generic_write ( swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
365 
376 void swipeswitch_generic_read ( swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
377 
388 
397 
405 void swipeswitch_disable_events ( swipeswitch_t *ctx, uint8_t event );
406 
414 void swipeswitch_enable_events ( swipeswitch_t *ctx, uint8_t event );
415 
424 
433 
443 
453 
463 
473 
483 
492 
501 
510 
518 void swipeswitch_set_touch_sensitivity ( swipeswitch_t *ctx, uint8_t sensitivity );
519 
527 void swipeswitch_set_prox_sensitivity ( swipeswitch_t *ctx, uint8_t sensitivity );
528 
536 void swipeswitch_set_event_mask ( swipeswitch_t *ctx, uint8_t event_mask );
537 
545 void swipeswitch_enable_channel ( swipeswitch_t *ctx, uint8_t channel );
546 
554 void swipeswitch_disable_channel ( swipeswitch_t *ctx, uint8_t channel );
555 
563 uint16_t swipeswitch_read_channel ( swipeswitch_t *ctx, uint8_t read_data, uint8_t channel );
564 
572 void swipeswitch_set_tap_timer_limit ( swipeswitch_t *ctx, uint8_t time_limit );
573 
581 void swipeswitch_set_tap_threshold ( swipeswitch_t *ctx, uint8_t threshold );
582 
590 void swipeswitch_set_swipe_timer_limit ( swipeswitch_t *ctx, uint8_t time_limit );
591 
599 void swipeswitch_set_swipe_threshold ( swipeswitch_t *ctx, uint8_t threshold );
600 
608 void swipeswitch_set_report_rate_nm ( swipeswitch_t *ctx, uint8_t report_rate );
609 
617 void swipeswitch_set_report_rate_lp ( swipeswitch_t *ctx, uint8_t report_rate );
618 
626 void swipeswitch_set_np_segment_rate ( swipeswitch_t *ctx, uint8_t segment_rate );
627 
635 void swipeswitch_set_zoom_timeout ( swipeswitch_t *ctx, uint8_t timeout_period );
636 
644 void swipeswitch_set_halt_timeout ( swipeswitch_t *ctx, uint8_t halt_time );
645 
646 
647 #ifdef __cplusplus
648 }
649 #endif
650 #endif // _SWIPESWITCH_H_
651  // End public_function group
654 
655 // ------------------------------------------------------------------------- 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:72
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:286
swipeswitch_cfg_t::i2c_address
uint8_t i2c_address
Definition: swipeswitch.h:318
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:297
swipeswitch_t::i2c
i2c_master_t i2c
Definition: swipeswitch.h:293
swipeswitch_cfg_t::scl
pin_name_t scl
Definition: swipeswitch.h:308
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:317
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:289
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:313
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:305
swipeswitch_cfg_t::sda
pin_name_t sda
Definition: swipeswitch.h:309