generated from hulk/gd32e23x_template_cmake_vscode
feature(actuator):添加推杆驱动函数新函数
This commit is contained in:
@@ -9,4 +9,6 @@ void actuator_init(void);
|
|||||||
|
|
||||||
void actuator_output(actuator_channel_t channel, uint16_t duty, actuator_direction_t direction);
|
void actuator_output(actuator_channel_t channel, uint16_t duty, actuator_direction_t direction);
|
||||||
|
|
||||||
|
void actuator_stop(actuator_channel_t channel);
|
||||||
|
|
||||||
#endif // ACTUATOR_H
|
#endif // ACTUATOR_H
|
||||||
+23
-2
@@ -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
|
// For example, setting the duty cycle to a specific value to activate the actuator
|
||||||
if (channel == ACTUATOR_CH1) {
|
if (channel == ACTUATOR_CH1) {
|
||||||
if (direction == DIRECTION_PUSH) {
|
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
|
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);
|
timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH1_PWM_TIMER_CH, duty);
|
||||||
} else if (direction == DIRECTION_PULL) {
|
} 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
|
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));
|
timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH1_PWM_TIMER_CH, (999 - duty));
|
||||||
}
|
}
|
||||||
} else if (channel == ACTUATOR_CH2) {
|
} else if (channel == ACTUATOR_CH2) {
|
||||||
if (direction == DIRECTION_PUSH) {
|
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
|
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);
|
timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH2_PWM_TIMER_CH, duty);
|
||||||
} else if (direction == DIRECTION_PULL) {
|
} 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
|
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));
|
timer_channel_output_pulse_value_config(ACTUATOR_PWM_TIMER, ACTUATOR_CH2_PWM_TIMER_CH, (999 - duty));
|
||||||
}
|
}
|
||||||
@@ -104,3 +106,22 @@ void actuator_output(actuator_channel_t channel, uint16_t duty, actuator_directi
|
|||||||
gpio_bit_reset(ACTUATOR_CH2_GPIO_PORT, ACTUATOR_CH2_GPIO_PIN); // Set CH2 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user