LibDriver BUTTON
Loading...
Searching...
No Matches
driver_button_basic.c
Go to the documentation of this file.
1
36
37#include "driver_button_basic.h"
38
39static button_handle_t gs_handle;
40
50uint8_t button_basic_irq_handler(uint8_t press_release)
51{
52 if (button_irq_handler(&gs_handle, press_release) != 0)
53 {
54 return 1;
55 }
56 else
57 {
58 return 0;
59 }
60}
61
70{
71 if (button_period_handler(&gs_handle) != 0)
72 {
73 return 1;
74 }
75
76 return 0;
77}
78
87uint8_t button_basic_init(void (*callback)(button_t *data))
88{
89 uint8_t res;
90
91 /* link interface function */
96 DRIVER_BUTTON_LINK_RECEIVE_CALLBACK(&gs_handle, callback);
97
98 /* init */
99 res = button_init(&gs_handle);
100 if (res != 0)
101 {
102 button_interface_debug_print("button: init failed.\n");
103
104 return 1;
105 }
106
107 /* set default timeout */
109 if (res != 0)
110 {
111 button_interface_debug_print("button: set timeout failed.\n");
112 (void)button_deinit(&gs_handle);
113
114 return 1;
115 }
116
117 /* set default interval */
119 if (res != 0)
120 {
121 button_interface_debug_print("button: set interval failed.\n");
122 (void)button_deinit(&gs_handle);
123
124 return 1;
125 }
126
127 /* set default short time */
129 if (res != 0)
130 {
131 button_interface_debug_print("button: set short time failed.\n");
132 (void)button_deinit(&gs_handle);
133
134 return 1;
135 }
136
137 /* set default long time */
139 if (res != 0)
140 {
141 button_interface_debug_print("button: set long time failed.\n");
142 (void)button_deinit(&gs_handle);
143
144 return 1;
145 }
146
147 /* set default repeat time */
149 if (res != 0)
150 {
151 button_interface_debug_print("button: set repeat time failed.\n");
152 (void)button_deinit(&gs_handle);
153
154 return 1;
155 }
156
157 return 0;
158}
159
168{
169 if (button_deinit(&gs_handle) != 0)
170 {
171 return 1;
172 }
173
174 return 0;
175}
driver button basic header file
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
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_period_handler(button_handle_t *handle)
period handler
struct button_s button_t
button structure definition
uint8_t button_set_long_time(button_handle_t *handle, uint32_t us)
set long time
uint8_t button_set_interval(button_handle_t *handle, uint32_t us)
set interval
#define BUTTON_BASIC_DEFAULT_REPEAT_TIME
#define BUTTON_BASIC_DEFAULT_SHORT_TIME
uint8_t button_basic_init(void(*callback)(button_t *data))
basic example init
uint8_t button_basic_irq_handler(uint8_t press_release)
basic irq
#define BUTTON_BASIC_DEFAULT_TIMEOUT
button basic example default definition
uint8_t button_basic_period_handler(void)
basic period
#define BUTTON_BASIC_DEFAULT_LONG_TIME
uint8_t button_basic_deinit(void)
basic example deinit
#define BUTTON_BASIC_DEFAULT_INTERVAL
void button_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t button_interface_timestamp_read(button_time_t *t)
interface timestamp read
void button_interface_debug_print(const char *const fmt,...)
interface print format data