From ac9e564d6ac6f434e90c4673f8e758ce54612a15 Mon Sep 17 00:00:00 2001 From: "Miguel I." Date: Mon, 8 Sep 2025 22:07:54 +0200 Subject: [PATCH] aparently working, more test is needed --- drivers/actuator/actuator.c | 22 +++++++++++++--------- src/main.c | 5 +++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/actuator/actuator.c b/drivers/actuator/actuator.c index cd0114c..6d5a929 100644 --- a/drivers/actuator/actuator.c +++ b/drivers/actuator/actuator.c @@ -5,8 +5,7 @@ #include #include #include - -LOG_MODULE_REGISTER(actuator, LOG_LEVEL_INF); +#include /* === GPIOs from devicetree === */ #define USER_NODE DT_PATH(zephyr_user) @@ -48,7 +47,7 @@ static void pwm_isr(const struct device *dev, static int configure_gpio(void) { if (!device_is_ready(do1.port) || !device_is_ready(do2.port) || !device_is_ready(do_en.port)) { - LOG_ERR("GPIO device not ready"); + printk("GPIO device not ready"); return -ENODEV; } @@ -64,7 +63,7 @@ static void start_counter(uint32_t us) int err = counter_get_value(counter_dev, &now_ticks); if (err) { - LOG_ERR("Failed to get counter value (%d)", err); + printk("Failed to get counter value (%d)", err); return; } @@ -76,7 +75,12 @@ static void start_counter(uint32_t us) alarm_cfg.callback = pwm_isr; alarm_cfg.user_data = NULL; - counter_set_channel_alarm(counter_dev, 0, &alarm_cfg); + err = counter_set_channel_alarm(counter_dev, 0, &alarm_cfg); + if (err) + { + printk("Failed to set channel alarm (%d)", err); + return; + } } /* === ISR callback === */ @@ -146,7 +150,7 @@ int actuator_init(enum actuator_mode mode) if (ret) return ret; if (!device_is_ready(counter_dev)) { - LOG_ERR("Counter device not ready"); + printk("Counter device not ready"); return -ENODEV; } @@ -155,7 +159,7 @@ int actuator_init(enum actuator_mode mode) current_mode = mode; initialized = true; active_phase = false; - LOG_INF("Actuator initialized in mode %d", mode); + printk("Actuator initialized in mode %d", mode); return 0; } @@ -174,7 +178,7 @@ int actuator_motor_set_speed(int speed_percent) motor_speed = speed_percent; active_phase = false; - start_counter(1); /* trigger ISR soon */ + start_counter(100); /* trigger ISR soon */ return 0; } @@ -186,6 +190,6 @@ int actuator_servo_set_angle(int angle_deg) servo_angle = angle_deg; active_phase = false; - start_counter(1); /* trigger ISR soon */ + start_counter(100); /* trigger ISR soon */ return 0; } diff --git a/src/main.c b/src/main.c index 84e7261..44917ab 100644 --- a/src/main.c +++ b/src/main.c @@ -27,10 +27,11 @@ int main(void) return 0; } - actuator_init(ACTUATOR_MODE_MOTOR); + actuator_init(ACTUATOR_MODE_SERVO); actuator_enable(1); - actuator_motor_set_speed(50); // -100..100 % + actuator_servo_set_angle(100); + //actuator_motor_set_speed(-50); // -100..100 % /* Init modules */ led_init(); button_init();