LibDriver MULTI_BUTTON
Loading...
Searching...
No Matches
driver_multi_button.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_MULTI_BUTTON_H
38#define DRIVER_MULTI_BUTTON_H
39
40#include <stdio.h>
41#include <stdint.h>
42#include <string.h>
43
44#ifdef __cplusplus
45extern "C"{
46#endif
47
53
58
62#ifndef MULTI_BUTTON_NUMBER
63 #define MULTI_BUTTON_NUMBER 128
64#endif
65
69#ifndef MULTI_BUTTON_EACH_LENGTH
70 #define MULTI_BUTTON_EACH_LENGTH 16
71#endif
72
76#if (MULTI_BUTTON_EACH_LENGTH < 8)
77 #error "MULTI_BUTTON_EACH_LENGTH < 8"
78#endif
79
97
101typedef struct multi_button_s
102{
103 uint16_t status;
104 uint16_t times;
106
111{
112 uint64_t s;
113 uint32_t us;
115
124
138
143{
144 uint8_t (*matrix_init)(void);
145 uint8_t (*matrix_deinit)(void);
146 uint8_t (*matrix_write_row)(uint16_t num, uint8_t level);
147 uint8_t (*matrix_read_row)(uint32_t *col_array);
149 void (*delay_ms)(uint32_t ms);
150 void (*debug_print)(const char *const fmt, ...);
151 void (*receive_callback)(uint16_t row, uint16_t col, multi_button_t *data);
154 uint8_t inited;
155 uint8_t row;
156 uint8_t col;
157 uint32_t short_time;
158 uint32_t long_time;
159 uint32_t repeat_time;
160 uint32_t interval;
161 uint32_t timeout;
162 uint32_t repeat_cnt;
163 uint32_t period;
165
181
185
192
199#define DRIVER_MULTI_BUTTON_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
200
207#define DRIVER_MULTI_BUTTON_LINK_MATRIX_INIT(HANDLE, FUC) (HANDLE)->matrix_init = FUC
208
215#define DRIVER_MULTI_BUTTON_LINK_MATRIX_DEINIT(HANDLE, FUC) (HANDLE)->matrix_deinit = FUC
216
223#define DRIVER_MULTI_BUTTON_LINK_MATRIX_WRITE_ROW(HANDLE, FUC) (HANDLE)->matrix_write_row = FUC
224
231#define DRIVER_MULTI_BUTTON_LINK_MATRIX_READ_ROW(HANDLE, FUC) (HANDLE)->matrix_read_row = FUC
232
239#define DRIVER_MULTI_BUTTON_LINK_TIMESTAMP_READ(HANDLE, FUC) (HANDLE)->timestamp_read = FUC
240
247#define DRIVER_MULTI_BUTTON_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
248
255#define DRIVER_MULTI_BUTTON_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
256
263#define DRIVER_MULTI_BUTTON_LINK_RECEIVE_CALLBACK(HANDLE, FUC) (HANDLE)->receive_callback = FUC
264
268
275
285
300uint8_t multi_button_init(multi_button_handle_t *handle, uint8_t row, uint8_t col);
301
312
324
335uint8_t multi_button_set_timeout(multi_button_handle_t *handle, uint32_t us);
336
347uint8_t multi_button_get_timeout(multi_button_handle_t *handle, uint32_t *us);
348
359uint8_t multi_button_set_interval(multi_button_handle_t *handle, uint32_t us);
360
371uint8_t multi_button_get_interval(multi_button_handle_t *handle, uint32_t *us);
372
383uint8_t multi_button_set_short_time(multi_button_handle_t *handle, uint32_t us);
384
395uint8_t multi_button_get_short_time(multi_button_handle_t *handle, uint32_t *us);
396
407uint8_t multi_button_set_long_time(multi_button_handle_t *handle, uint32_t us);
408
419uint8_t multi_button_get_long_time(multi_button_handle_t *handle, uint32_t *us);
420
431uint8_t multi_button_set_repeat_time(multi_button_handle_t *handle, uint32_t us);
432
443uint8_t multi_button_get_repeat_time(multi_button_handle_t *handle, uint32_t *us);
444
455uint8_t multi_button_set_repeat_cnt(multi_button_handle_t *handle, uint32_t cnt);
456
467uint8_t multi_button_get_repeat_cnt(multi_button_handle_t *handle, uint32_t *cnt);
468
479uint8_t multi_button_set_period(multi_button_handle_t *handle, uint32_t period);
480
491uint8_t multi_button_get_period(multi_button_handle_t *handle, uint32_t *period);
492
496
500
501#ifdef __cplusplus
502}
503#endif
504
505#endif
#define MULTI_BUTTON_NUMBER
multi_button max number definition
uint8_t multi_button_get_repeat_time(multi_button_handle_t *handle, uint32_t *us)
get repeat time
uint8_t multi_button_get_interval(multi_button_handle_t *handle, uint32_t *us)
get interval
uint8_t multi_button_init(multi_button_handle_t *handle, uint8_t row, uint8_t col)
initialize the chip
uint8_t multi_button_process(multi_button_handle_t *handle)
process
uint8_t multi_button_deinit(multi_button_handle_t *handle)
close the chip
struct multi_button_handle_s multi_button_handle_t
multi_button handle structure definition
uint8_t multi_button_get_repeat_cnt(multi_button_handle_t *handle, uint32_t *cnt)
get repeat cnt
#define MULTI_BUTTON_EACH_LENGTH
multi_button each length definition
uint8_t multi_button_get_short_time(multi_button_handle_t *handle, uint32_t *us)
get short time
multi_button_status_t
check range
uint8_t multi_button_set_short_time(multi_button_handle_t *handle, uint32_t us)
set short time
struct multi_button_single_s multi_button_single_t
multi_button single structure definition
uint8_t multi_button_get_timeout(multi_button_handle_t *handle, uint32_t *us)
get timeout
uint8_t multi_button_get_long_time(multi_button_handle_t *handle, uint32_t *us)
get long time
uint8_t multi_button_info(multi_button_info_t *info)
get chip's information
uint8_t multi_button_set_long_time(multi_button_handle_t *handle, uint32_t us)
set long time
uint8_t multi_button_set_repeat_time(multi_button_handle_t *handle, uint32_t us)
set repeat time
struct multi_button_decode_s multi_button_decode_t
multi_button decode structure definition
uint8_t multi_button_set_repeat_cnt(multi_button_handle_t *handle, uint32_t cnt)
set repeat cnt
uint8_t multi_button_get_period(multi_button_handle_t *handle, uint32_t *period)
get period
struct multi_button_time_s multi_button_time_t
multi_button time structure definition
uint8_t multi_button_set_period(multi_button_handle_t *handle, uint32_t period)
set period
struct multi_button_s multi_button_t
multi_button structure definition
uint8_t multi_button_set_timeout(multi_button_handle_t *handle, uint32_t us)
set timeout
uint8_t multi_button_set_interval(multi_button_handle_t *handle, uint32_t us)
set interval
struct multi_button_info_s multi_button_info_t
multi_button information structure definition
@ MULTI_BUTTON_STATUS_SHORT_PRESS_END
@ MULTI_BUTTON_STATUS_REPEAT_CLICK
@ MULTI_BUTTON_STATUS_DOUBLE_CLICK
@ MULTI_BUTTON_STATUS_LONG_PRESS_END
@ MULTI_BUTTON_STATUS_SINGLE_CLICK
@ MULTI_BUTTON_STATUS_LONG_PRESS_HOLD
@ MULTI_BUTTON_STATUS_TRIPLE_CLICK
@ MULTI_BUTTON_STATUS_PRESS
@ MULTI_BUTTON_STATUS_SHORT_PRESS_START
@ MULTI_BUTTON_STATUS_RELEASE
@ MULTI_BUTTON_STATUS_LONG_PRESS_START
multi_button decode structure definition
multi_button handle structure definition
uint8_t(* matrix_deinit)(void)
multi_button_time_t check_time
void(* delay_ms)(uint32_t ms)
multi_button_single_t button[MULTI_BUTTON_NUMBER]
uint8_t(* matrix_read_row)(uint32_t *col_array)
uint8_t(* timestamp_read)(multi_button_time_t *t)
void(* debug_print)(const char *const fmt,...)
void(* receive_callback)(uint16_t row, uint16_t col, multi_button_t *data)
uint8_t(* matrix_write_row)(uint16_t num, uint8_t level)
multi_button information structure definition
multi_button structure definition
multi_button single structure definition
multi_button_time_t last_time
multi_button_decode_t decode[MULTI_BUTTON_EACH_LENGTH]
multi_button time structure definition