LibDriver BUTTON
Loading...
Searching...
No Matches
driver_button.h
Go to the documentation of this file.
1
36
37#ifndef DRIVER_BUTTON_H
38#define DRIVER_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 BUTTON_LENGTH
63 #define BUTTON_LENGTH 16
64#endif
65
69#if (BUTTON_LENGTH < 8)
70 #error "BUTTON_LENGTH < 8"
71#endif
72
90
94typedef struct button_s
95{
96 uint16_t status;
97 uint16_t times;
99
103typedef struct button_time_s
104{
105 uint64_t s;
106 uint32_t us;
108
117
121typedef struct button_handle_s
122{
124 void (*delay_ms)(uint32_t ms);
125 void (*debug_print)(const char *const fmt, ...);
126 void (*receive_callback)(button_t *data);
129 uint16_t decode_len;
132 uint8_t inited;
133 uint32_t short_time;
134 uint32_t long_time;
135 uint32_t repeat_time;
136 uint32_t interval;
137 uint32_t timeout;
139
155
159
166
173#define DRIVER_BUTTON_LINK_INIT(HANDLE, STRUCTURE) memset(HANDLE, 0, sizeof(STRUCTURE))
174
181#define DRIVER_BUTTON_LINK_TIMESTAMP_READ(HANDLE, FUC) (HANDLE)->timestamp_read = FUC
182
189#define DRIVER_BUTTON_LINK_DELAY_MS(HANDLE, FUC) (HANDLE)->delay_ms = FUC
190
197#define DRIVER_BUTTON_LINK_DEBUG_PRINT(HANDLE, FUC) (HANDLE)->debug_print = FUC
198
205#define DRIVER_BUTTON_LINK_RECEIVE_CALLBACK(HANDLE, FUC) (HANDLE)->receive_callback = FUC
206
210
217
226uint8_t button_info(button_info_t *info);
227
242uint8_t button_irq_handler(button_handle_t *handle, uint8_t press_release);
243
256
267uint8_t button_init(button_handle_t *handle);
268
278uint8_t button_deinit(button_handle_t *handle);
279
290uint8_t button_set_timeout(button_handle_t *handle, uint32_t us);
291
302uint8_t button_get_timeout(button_handle_t *handle, uint32_t *us);
303
314uint8_t button_set_interval(button_handle_t *handle, uint32_t us);
315
326uint8_t button_get_interval(button_handle_t *handle, uint32_t *us);
327
338uint8_t button_set_short_time(button_handle_t *handle, uint32_t us);
339
350uint8_t button_get_short_time(button_handle_t *handle, uint32_t *us);
351
362uint8_t button_set_long_time(button_handle_t *handle, uint32_t us);
363
374uint8_t button_get_long_time(button_handle_t *handle, uint32_t *us);
375
386uint8_t button_set_repeat_time(button_handle_t *handle, uint32_t us);
387
398uint8_t button_get_repeat_time(button_handle_t *handle, uint32_t *us);
399
403
407
408#ifdef __cplusplus
409}
410#endif
411
412#endif
uint8_t button_get_timeout(button_handle_t *handle, uint32_t *us)
get timeout
uint8_t button_info(button_info_t *info)
get chip's information
struct button_info_s button_info_t
button information structure definition
uint8_t button_get_interval(button_handle_t *handle, uint32_t *us)
get interval
uint8_t button_deinit(button_handle_t *handle)
close the chip
uint8_t button_set_repeat_time(button_handle_t *handle, uint32_t us)
set repeat time
#define BUTTON_LENGTH
button length definition
uint8_t button_irq_handler(button_handle_t *handle, uint8_t press_release)
irq handler
struct button_handle_s button_handle_t
button handle structure definition
uint8_t button_init(button_handle_t *handle)
initialize the chip
uint8_t button_set_timeout(button_handle_t *handle, uint32_t us)
set timeout
uint8_t button_set_short_time(button_handle_t *handle, uint32_t us)
set short time
uint8_t button_get_repeat_time(button_handle_t *handle, uint32_t *us)
get repeat time
uint8_t button_period_handler(button_handle_t *handle)
period handler
struct button_decode_s button_decode_t
button decode structure definition
button_status_t
check range
struct button_s button_t
button structure definition
uint8_t button_set_long_time(button_handle_t *handle, uint32_t us)
set long time
struct button_time_s button_time_t
button time structure definition
uint8_t button_set_interval(button_handle_t *handle, uint32_t us)
set interval
uint8_t button_get_long_time(button_handle_t *handle, uint32_t *us)
get long time
uint8_t button_get_short_time(button_handle_t *handle, uint32_t *us)
get short time
@ BUTTON_STATUS_DOUBLE_CLICK
@ BUTTON_STATUS_SHORT_PRESS_START
@ BUTTON_STATUS_PRESS
@ BUTTON_STATUS_LONG_PRESS_START
@ BUTTON_STATUS_TRIPLE_CLICK
@ BUTTON_STATUS_SHORT_PRESS_END
@ BUTTON_STATUS_REPEAT_CLICK
@ BUTTON_STATUS_LONG_PRESS_HOLD
@ BUTTON_STATUS_SINGLE_CLICK
@ BUTTON_STATUS_RELEASE
@ BUTTON_STATUS_LONG_PRESS_END
button decode structure definition
button_time_t t
button handle structure definition
button_decode_t decode[BUTTON_LENGTH]
void(* delay_ms)(uint32_t ms)
button_time_t last_time
void(* receive_callback)(button_t *data)
void(* debug_print)(const char *const fmt,...)
uint8_t(* timestamp_read)(button_time_t *t)
uint8_t short_triggered
button information structure definition
float supply_voltage_max_v
uint32_t driver_version
char manufacturer_name[32]
float supply_voltage_min_v
char chip_name[32]
button structure definition
uint16_t status
uint16_t times
button time structure definition