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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define SWIPESWITCH_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
69 cfg.rdy = MIKROBUS( mikrobus, MIKROBUS_INT )
76#define SWIPESWITCH_RETVAL uint8_t
77
78#define SWIPESWITCH_OK 0x00
79#define SWIPESWITCH_INIT_ERROR 0xFF
86#define SWIPESWITCH_REG_DEVICE_INFO 0x00
87#define SWIPESWITCH_REG_SYS_FLAGS 0x01
88#define SWIPESWITCH_REG_TP_FLAGS 0x02
89#define SWIPESWITCH_REG_COORDINATES 0x03
90#define SWIPESWITCH_REG_CHANNEL_BYTES 0x04
91#define SWIPESWITCH_REG_ACF_CH0 0x05
92#define SWIPESWITCH_REG_ACF_CH1 0x06
93#define SWIPESWITCH_REG_ACF_CH2 0x07
94#define SWIPESWITCH_REG_ACF_CH3 0x08
95#define SWIPESWITCH_REG_ACF_CH4 0x09
96#define SWIPESWITCH_REG_ACF_CH5 0x0A
97#define SWIPESWITCH_REG_ACF_CH6 0x0B
98#define SWIPESWITCH_REG_LTA_CH0 0x0C
99#define SWIPESWITCH_REG_LTA_CH1 0x0D
100#define SWIPESWITCH_REG_LTA_CH2 0x0E
101#define SWIPESWITCH_REG_LTA_CH3 0x0F
102#define SWIPESWITCH_REG_LTA_CH4 0x10
103#define SWIPESWITCH_REG_LTA_CH5 0x11
104#define SWIPESWITCH_REG_LTA_CH6 0x12
105#define SWIPESWITCH_REG_DELTA_CH0 0x13
106#define SWIPESWITCH_REG_DELTA_CH1 0x14
107#define SWIPESWITCH_REG_DELTA_CH2 0x15
108#define SWIPESWITCH_REG_DELTA_CH3 0x16
109#define SWIPESWITCH_REG_DELTA_CH4 0x17
110#define SWIPESWITCH_REG_DELTA_CH5 0x18
111#define SWIPESWITCH_REG_DELTA_CH6 0x19
112#define SWIPESWITCH_REG_PROXSETTINGS_01 0x80
113#define SWIPESWITCH_REG_PROXSETTINGS_23 0x81
114#define SWIPESWITCH_REG_EVENT_MASK 0x82
115#define SWIPESWITCH_REG_TIMEOUT_PERIODS 0x83
116#define SWIPESWITCH_REG_REPORT_RATES 0x84
117#define SWIPESWITCH_REG_THRESHOLDS_CH0 0x85
118#define SWIPESWITCH_REG_TOUCH_THR_CH1_CH2 0x86
119#define SWIPESWITCH_REG_TOUCH_THR_CH3_CH4 0x87
120#define SWIPESWITCH_REG_TOUCH_THR_CH5_CH6 0x88
121#define SWIPESWITCH_REG_ATI_TARGETS 0x89
122#define SWIPESWITCH_REG_CHANNEL_SETTINGS 0x8A
123#define SWIPESWITCH_REG_TAP_SETTINGS 0x8B
124#define SWIPESWITCH_REG_SWIPE_SETTINGS 0x8C
131#define SWIPESWITCH_EVENT_PROX 0x01
132#define SWIPESWITCH_EVENT_TOUCH 0x02
133#define SWIPESWITCH_EVENT_TP 0x04
134#define SWIPESWITCH_EVENT_ATI 0x08
135#define SWIPESWITCH_EVENT_TAP 0x10
136#define SWIPESWITCH_EVENT_SWIPE 0x20
137#define SWIPESWITCH_EVENT_LP 0x80
138#define SWIPESWITCH_EVENTS_ALL 0xFF
145#define SWIPESWITCH_GESTURE_TP 0x01
146#define SWIPESWITCH_GESTURE_TAP 0x02
147#define SWIPESWITCH_GESTURE_SWIPE_UP 0x04
148#define SWIPESWITCH_GESTURE_SWIPE_DOWN 0x08
149#define SWIPESWITCH_GESTURE_SWIPE_LEFT 0x10
150#define SWIPESWITCH_GESTURE_SWIPE_RIGHT 0x20
157#define SWIPESWITCH_CH0_PROX 0x01
158#define SWIPESWITCH_SHOW_RESET 0x80
159#define SWIPESWITCH_ACK_RESET 0x80
160#define SWIPESWITCH_REDO_ATI 0x10
161#define SWIPESWITCH_EVENT_MODE 0x40
162
163
168#define SWIPESWITCH_CH0_TOUCH 0x01
169#define SWIPESWITCH_CH1_TOUCH 0x02
170#define SWIPESWITCH_CH2_TOUCH 0x04
171#define SWIPESWITCH_CH3_TOUCH 0x08
172#define SWIPESWITCH_CH4_TOUCH 0x10
173#define SWIPESWITCH_CH5_TOUCH 0x20
174#define SWIPESWITCH_CH6_TOUCH 0x40
181#define SWIPESWITCH_TPF_SEGMENT_0 0x00
182#define SWIPESWITCH_TPF_SEGMENT_1 0x40
183#define SWIPESWITCH_TPF_SEGMENT_2 0x80
184#define SWIPESWITCH_TPF_SEGMENT_3 0xC0
185#define SWIPESWITCH_TPF_SWIPE_RIGHT 0x20
186#define SWIPESWITCH_TPF_SWIPE_LEFT 0x10
187#define SWIPESWITCH_TPF_SWIPE_DOWN 0x08
188#define SWIPESWITCH_TPF_SWIPE_UP 0x04
189#define SWIPESWITCH_TPF_TAP 0x02
190#define SWIPESWITCH_TPF_TP_ACTIVE 0x01
197#define SWIPESWITCH_PS0_AUTO_ATI_ON 0x00
198#define SWIPESWITCH_PS0_AUTO_ATI_OFF 0x80
199#define SWIPESWITCH_PS0_NORMAL_ATI_ACTIVE 0x00
200#define SWIPESWITCH_PS0_PARTIAL_ATI_ACTIVE 0x40
201#define SWIPESWITCH_PS0_NORMAL_ATI_BAND 0x00
202#define SWIPESWITCH_PS0_LARGE_ATI_BAND 0x20
203#define SWIPESWITCH_PS0_REDO_AN_ATI 0x10
204#define SWIPESWITCH_PS0_DEBUG_ATI_DISABLE 0x00
205#define SWIPESWITCH_PS0_DEBUG_ATI_ENABLE 0x04
206#define SWIPESWITCH_PS0_NORMAL_ANALOGUE_TIME 0x00
207#define SWIPESWITCH_PS0_INCREASED_ANALOGUE_TIME 0x02
208#define SWIPESWITCH_PS0_NORMAL_HALTING 0x00
209#define SWIPESWITCH_PS0_Force_halt 0x01
216#define SWIPESWITCH_PS1_COMMUNICATION_WATCH_DOG_ENABLED 0x00
217#define SWIPESWITCH_PS1_COMMUNICATION_WATCH_DOG_DISABLED 0x80
218#define SWIPESWITCH_PS1_STREAMING_MODE 0x00
219#define SWIPESWITCH_PS1_EVENT_MODE 0x40
220#define SWIPESWITCH_PS1_LTA_BETA_1_512 0x00
221#define SWIPESWITCH_PS1_LTA_BETA_1_256 0x10
222#define SWIPESWITCH_PS1_LTA_BETA_1_128 0x20
223#define SWIPESWITCH_PS1_LTA_BETA_1_64 0x30
224#define SWIPESWITCH_PS1_ACF_BETA_1 0x01
225#define SWIPESWITCH_PS1_ACF_BETA_2 0x02
226#define SWIPESWITCH_PS1_ACF_BETA_3 0x03
227#define SWIPESWITCH_PS1_ACF_FILTER_OFF 0x00
234#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_1 0x00
235#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_2 0x01
236#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_4 0x02
237#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_8 0x03
238#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_16 0x04
239#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_32 0x05
240#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_64 0x06
241#define SWIPESWITCH_PS2_NP_SEGMENT_RATE_128 0x07
248#define SWIPESWITCH_PS3_ACKNOWLEDGE_RESET 0x80
249#define SWIPESWITCH_PS3_IC_IN_ON_MODE 0x00
250#define SWIPESWITCH_PS3_IC_IN_OFF_MODE 0x40
251#define SWIPESWITCH_PS3_BIAS_CURRENT_5uA 0x00
252#define SWIPESWITCH_PS3_BIAS_CURRENT_10uA 0x20
253#define SWIPESWITCH_PS3_GROUND_Cx_PINS 0x00
254#define SWIPESWITCH_PS3_FLOAT_Cx_PINS 0x10
255#define SWIPESWITCH_PS3_NORMAL_CHARGING 0x00
256#define SWIPESWITCH_PS3_HALT_CHARGING 0x08
257#define SWIPESWITCH_PS3_CHARGING_FREQ_CH123456_2MHz 0x00
258#define SWIPESWITCH_PS3_CHARGING_FREQ_CH123456_1MHz 0x02
259#define SWIPESWITCH_PS3_CHARGING_FREQ_CH0_1MHz 0x00
260#define SWIPESWITCH_PS3_CHARGING_FREQ_CH0_500kHz 0x10
267#define SWIPESWITCH_CHANNEL_0 0x01
268#define SWIPESWITCH_CHANNEL_1 0x02
269#define SWIPESWITCH_CHANNEL_2 0x04
270#define SWIPESWITCH_CHANNEL_3 0x08
271#define SWIPESWITCH_CHANNEL_4 0x10
272#define SWIPESWITCH_CHANNEL_5 0x20
273#define SWIPESWITCH_CHANNEL_6 0x40
277#define SWIPESWITCH_DEVICE_SLAVE_ADDRESS 0x44
278
279 // End group macro
280// --------------------------------------------------------------- PUBLIC TYPES
289typedef struct
290{
291 // Input pins
292
293 digital_in_t rdy_in;
294
295 // Modules
296
297 i2c_master_t i2c;
298
299 // ctx variable
300
302
304
308typedef struct
309{
310 // Communication gpio pins
311
312 pin_name_t scl;
313 pin_name_t sda;
314
315 // Additional gpio pins
316
317 pin_name_t rdy;
318
319 // static variable
320
321 uint32_t i2c_speed;
322 uint8_t i2c_address;
323
325
326 // End types group
327// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
328
334#ifdef __cplusplus
335extern "C"{
336#endif
337
347
357
368void swipeswitch_generic_write ( swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
369
380void swipeswitch_generic_read ( swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
381
392
401
409void swipeswitch_disable_events ( swipeswitch_t *ctx, uint8_t event );
410
418void swipeswitch_enable_events ( swipeswitch_t *ctx, uint8_t event );
419
428
437
447
457
467
477
487
496
505
514
522void swipeswitch_set_touch_sensitivity ( swipeswitch_t *ctx, uint8_t sensitivity );
523
531void swipeswitch_set_prox_sensitivity ( swipeswitch_t *ctx, uint8_t sensitivity );
532
540void swipeswitch_set_event_mask ( swipeswitch_t *ctx, uint8_t event_mask );
541
549void swipeswitch_enable_channel ( swipeswitch_t *ctx, uint8_t channel );
550
558void swipeswitch_disable_channel ( swipeswitch_t *ctx, uint8_t channel );
559
567uint16_t swipeswitch_read_channel ( swipeswitch_t *ctx, uint8_t read_data, uint8_t channel );
568
576void swipeswitch_set_tap_timer_limit ( swipeswitch_t *ctx, uint8_t time_limit );
577
585void swipeswitch_set_tap_threshold ( swipeswitch_t *ctx, uint8_t threshold );
586
594void swipeswitch_set_swipe_timer_limit ( swipeswitch_t *ctx, uint8_t time_limit );
595
603void swipeswitch_set_swipe_threshold ( swipeswitch_t *ctx, uint8_t threshold );
604
612void swipeswitch_set_report_rate_nm ( swipeswitch_t *ctx, uint8_t report_rate );
613
621void swipeswitch_set_report_rate_lp ( swipeswitch_t *ctx, uint8_t report_rate );
622
630void swipeswitch_set_np_segment_rate ( swipeswitch_t *ctx, uint8_t segment_rate );
631
639void swipeswitch_set_zoom_timeout ( swipeswitch_t *ctx, uint8_t timeout_period );
640
648void swipeswitch_set_halt_timeout ( swipeswitch_t *ctx, uint8_t halt_time );
649
650
651#ifdef __cplusplus
652}
653#endif
654#endif // _SWIPESWITCH_H_
655
656 // End public_function group
658
659// ------------------------------------------------------------------------- END
#define SWIPESWITCH_RETVAL
Definition swipeswitch.h:76
void swipeswitch_disable_halt_timeout(swipeswitch_t *ctx)
Function for disable halt time.
void swipeswitch_set_swipe_threshold(swipeswitch_t *ctx, uint8_t threshold)
Function for setting swipe threshold.
void swipeswitch_enable_events(swipeswitch_t *ctx, uint8_t event)
Function for enabled Event.
void swipeswitch_set_halt_timeout(swipeswitch_t *ctx, uint8_t halt_time)
Function for setting halt timeout.
void swipeswitch_cfg_setup(swipeswitch_cfg_t *cfg)
Config Object Initialization function.
void swipeswitch_go_to_event_mode(swipeswitch_t *ctx)
Function for Event mode.
void swipeswitch_disable_channel(swipeswitch_t *ctx, uint8_t channel)
Function for disabling channels.
uint8_t swipeswitch_read_gestures(swipeswitch_t *ctx)
Function for reading Gestures.
uint8_t swipeswitch_read_touch_byte(swipeswitch_t *ctx)
Function for reading Touch byte.
void swipeswitch_set_zoom_timeout(swipeswitch_t *ctx, uint8_t timeout_period)
Function for setting zoom timeout.
void swipeswitch_disable_events(swipeswitch_t *ctx, uint8_t event)
Function for disabled Event.
SWIPESWITCH_RETVAL swipeswitch_init(swipeswitch_t *ctx, swipeswitch_cfg_t *cfg)
Initialization function.
void swipeswitch_set_tap_timer_limit(swipeswitch_t *ctx, uint8_t time_limit)
Function for setting tap timer limit.
void swipeswitch_set_np_segment_rate(swipeswitch_t *ctx, uint8_t segment_rate)
Function for setting segment rate.
uint8_t swipeswitch_read_x_coordinate(swipeswitch_t *ctx)
Function for reading X coordinate.
void swipeswitch_generic_read(swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
uint8_t swipeswitch_wait_for_ready(swipeswitch_t *ctx)
Function that waits for the module to be ready for operation.
uint8_t swipeswitch_read_prox_byte(swipeswitch_t *ctx)
Function for reading Prox byte.
uint16_t swipeswitch_read_channel(swipeswitch_t *ctx, uint8_t read_data, uint8_t channel)
Function for reading channel.
void swipeswitch_set_swipe_timer_limit(swipeswitch_t *ctx, uint8_t time_limit)
Function for setting swipe timer limit.
void swipeswitch_set_report_rate_lp(swipeswitch_t *ctx, uint8_t report_rate)
Function for setting report rate LP.
uint8_t swipeswitch_read_events(swipeswitch_t *ctx)
Function for reading event.
void swipeswitch_generic_write(swipeswitch_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
uint8_t swipeswitch_read_system_flags(swipeswitch_t *ctx)
Function for reads system falgs.
void swipeswitch_set_prox_sensitivity(swipeswitch_t *ctx, uint8_t sensitivity)
Function for setting Prox Sensitivity.
void swipeswitch_go_to_stream_mode(swipeswitch_t *ctx)
Function for Stream mode.
void swipeswitch_set_report_rate_nm(swipeswitch_t *ctx, uint8_t report_rate)
Function for setting report rate NM.
void swipeswitch_enable_channel(swipeswitch_t *ctx, uint8_t channel)
Function for enabling channels.
uint8_t swipeswitch_read_y_coordinate(swipeswitch_t *ctx)
Function for reading Y coordinate.
uint8_t swipeswitch_read_trackpad_flags(swipeswitch_t *ctx)
Function for reading Trackpad falgs.
void swipeswitch_set_touch_sensitivity(swipeswitch_t *ctx, uint8_t sensitivity)
Function for setting Touch Sensitivity.
void swipeswitch_set_tap_threshold(swipeswitch_t *ctx, uint8_t threshold)
Function for setting tap threshold.
void swipeswitch_set_event_mask(swipeswitch_t *ctx, uint8_t event_mask)
Function for setting Event mask.
Click configuration structure definition.
Definition swipeswitch.h:309
uint32_t i2c_speed
Definition swipeswitch.h:321
pin_name_t scl
Definition swipeswitch.h:312
pin_name_t rdy
Definition swipeswitch.h:317
pin_name_t sda
Definition swipeswitch.h:313
uint8_t i2c_address
Definition swipeswitch.h:322
Click ctx object definition.
Definition swipeswitch.h:290
i2c_master_t i2c
Definition swipeswitch.h:297
digital_in_t rdy_in
Definition swipeswitch.h:293
uint8_t slave_address
Definition swipeswitch.h:301