aparently working, more test is needed
This commit is contained in:
@@ -5,8 +5,7 @@
|
||||
#include <zephyr/logging/log.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/drivers/counter.h>
|
||||
|
||||
LOG_MODULE_REGISTER(actuator, LOG_LEVEL_INF);
|
||||
#include <stdlib.h>
|
||||
|
||||
/* === 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user