AI cleanup

This commit is contained in:
Your Name
2026-05-21 11:43:09 +03:00
parent 3a5e91c4bf
commit cb6266b312
20 changed files with 383 additions and 506 deletions
+14 -8
View File
@@ -4,23 +4,28 @@
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(buttons, CONFIG_LOG_MAX_LEVEL);
K_WORK_DELAYABLE_DEFINE(debounce_work_btn, debounce_cb);
#define DEBOUNCE_TIME_MS 100
/* Forward declarations for internal callbacks */
static void debounce_cb(struct k_work *work);
static void buttons_cb(const struct device *dev, struct gpio_callback *cb, uint32_t pins);
K_WORK_DELAYABLE_DEFINE(debounce_work_btn, debounce_cb);
static const struct gpio_dt_spec buttons[NR_BUTTONS] = {
GPIO_DT_SPEC_GET_OR(DT_ALIAS(int_btn_1), gpios, {0}),
GPIO_DT_SPEC_GET_OR(DT_ALIAS(int_btn_2), gpios, {0}),
};
static struct gpio_callback buttons_cb_data[NR_BUTTONS];
int buttons_init(void) {
// BUTTON 1
int buttons_init(void)
{
gpio_pin_configure_dt(&buttons[BUTTON1], GPIO_INPUT);
gpio_pin_interrupt_configure_dt(&buttons[BUTTON1], GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&buttons_cb_data[0], buttons_cb, BIT(buttons[BUTTON1].pin));
gpio_add_callback(buttons[BUTTON1].port, &buttons_cb_data[0]);
// BUTTON 2
gpio_pin_configure_dt(&buttons[BUTTON2], GPIO_INPUT);
gpio_pin_interrupt_configure_dt(&buttons[BUTTON2], GPIO_INT_EDGE_TO_ACTIVE);
gpio_init_callback(&buttons_cb_data[1], buttons_cb, BIT(buttons[BUTTON2].pin));
@@ -29,15 +34,16 @@ int buttons_init(void) {
return 0;
}
void debounce_cb(struct k_work *work) {
static void debounce_cb(struct k_work *work)
{
if (gpio_pin_get_dt(&buttons[BUTTON1]) == GPIO_ACTIVE_HIGH ||
gpio_pin_get_dt(&buttons[BUTTON2]) == GPIO_ACTIVE_HIGH) {
LOG_DBG("Callback");
LOG_DBG("Button active after debounce");
}
}
void buttons_cb(const struct device *dev, struct gpio_callback *cb, uint32_t pins) {
LOG_DBG("Button:");
static void buttons_cb(const struct device *dev, struct gpio_callback *cb, uint32_t pins)
{
if (!k_work_delayable_is_pending(&debounce_work_btn)) {
k_work_schedule(&debounce_work_btn, K_MSEC(DEBOUNCE_TIME_MS));
}