From f6ba273aff95ec09cb44c5adc31025464ffb0ec4 Mon Sep 17 00:00:00 2001 From: yelvlab Date: Tue, 28 Jul 2026 19:45:00 +0800 Subject: [PATCH] =?UTF-8?q?feature(actuator):=E6=B7=BB=E5=8A=A0=E6=8E=A8?= =?UTF-8?q?=E6=9D=86=E9=A9=B1=E5=8A=A8=E5=87=BD=E6=95=B0=E6=96=B0=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Inc/actuator.h | 2 ++ Src/actuator.c | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Inc/actuator.h b/Inc/actuator.h index 5e40922..2ae0540 100644 --- a/Inc/actuator.h +++ b/Inc/actuator.h @@ -9,4 +9,6 @@ void actuator_init(void); void actuator_output(actuator_channel_t channel, uint16_t duty, actuator_direction_t direction); +void actuator_stop(actuator_channel_t channel); + #endif // ACTUATOR_H \ No newline at end of file diff --git a/Src/actuator.c b/Src/actuator.c index 3621baa..80329fc 100644 --- a/Src/actuator.c +++ b/Src/actuator.c @@ -80,19 +80,21 @@ void actuator_output(actuator_channel_t channel, uint16_t duty, actuator_directi // For example, setting the duty cycle to a specific value to activate the actuator if (channel == ACTUATOR_CH1) { if (direction == DIRECTION_PUSH) { - SEGGER_RTT_printf(0, "Actuator CH1 PUSH with duty %d\n", duty); + SEGGER_RTT_printf(0, "[ACTUATOR] Actuator CH1 PUSH with duty %d\n", duty); gpio_bit_reset(ACTUATOR_CH1_GPIO_PORT, ACTUATOR_CH1_GPIO_PIN); // Set direction LOW timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH1_PWM_TIMER_CH, duty); } else if (direction == DIRECTION_PULL) { - SEGGER_RTT_printf(0, "Actuator CH1 PULL with duty %d\n", duty); + SEGGER_RTT_printf(0, "[ACTUATOR] Actuator CH1 PULL with duty %d\n", duty); gpio_bit_set(ACTUATOR_CH1_GPIO_PORT, ACTUATOR_CH1_GPIO_PIN); // Set direction HIGH timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH1_PWM_TIMER_CH, (999 - duty)); } } else if (channel == ACTUATOR_CH2) { if (direction == DIRECTION_PUSH) { + SEGGER_RTT_printf(0, "[ACTUATOR] Actuator CH2 PUSH with duty %d\n", duty); gpio_bit_reset(ACTUATOR_CH2_GPIO_PORT, ACTUATOR_CH2_GPIO_PIN); // Set direction LOW timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH2_PWM_TIMER_CH, duty); } else if (direction == DIRECTION_PULL) { + SEGGER_RTT_printf(0, "[ACTUATOR] Actuator CH2 PULL with duty %d\n", duty); gpio_bit_set(ACTUATOR_CH2_GPIO_PORT, ACTUATOR_CH2_GPIO_PIN); // Set direction HIGH timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH2_PWM_TIMER_CH, (999 - duty)); } @@ -103,4 +105,23 @@ void actuator_output(actuator_channel_t channel, uint16_t duty, actuator_directi gpio_bit_reset(ACTUATOR_CH1_GPIO_PORT, ACTUATOR_CH1_GPIO_PIN); // Set CH1 direction LOW gpio_bit_reset(ACTUATOR_CH2_GPIO_PORT, ACTUATOR_CH2_GPIO_PIN); // Set CH2 direction LOW } +} + +void actuator_stop(actuator_channel_t channel) { + if(channel == ACTUATOR_CH1) { + SEGGER_RTT_printf(0, "[ACTUATOR] Stopping Actuator CH1\n"); + timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH1_PWM_TIMER_CH, 999); // Ensure CH1 is off + gpio_bit_set(ACTUATOR_CH1_GPIO_PORT, ACTUATOR_CH1_GPIO_PIN); // Set CH1 direction LOW + } else if(channel == ACTUATOR_CH2) { + SEGGER_RTT_printf(0, "[ACTUATOR] Stopping Actuator CH2\n"); + timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH2_PWM_TIMER_CH, 999); // Ensure CH2 is off + gpio_bit_set(ACTUATOR_CH2_GPIO_PORT, ACTUATOR_CH2_GPIO_PIN); // Set CH2 direction LOW + } else { + // Invalid channel, handle error if necessary + SEGGER_RTT_printf(0, "[ACTUATOR] Invalid channel specified for stop: %d\n", channel); + timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH1_PWM_TIMER_CH, 999); // Ensure CH1 is off + timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH2_PWM_TIMER_CH, 999); // Ensure CH2 is off + gpio_bit_set(ACTUATOR_CH1_GPIO_PORT, ACTUATOR_CH1_GPIO_PIN); // Set CH1 direction LOW + gpio_bit_set(ACTUATOR_CH2_GPIO_PORT, ACTUATOR_CH2_GPIO_PIN); // Set CH2 direction LOW + } } \ No newline at end of file