Files
Power-Pico/Power_Pico/BSP/GATE/gate.c

62 lines
1.6 KiB
C
Raw Normal View History

2025-08-12 18:43:52 +08:00
#include "gate.h"
2025-09-14 18:47:02 +08:00
#include "math.h"
2025-08-12 18:43:52 +08:00
2025-09-14 18:47:02 +08:00
uint8_t gate_status = HIGH_CUR; // Default status
2025-08-12 18:43:52 +08:00
void Gate_Port_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(EN1_PORT, EN1_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(EN2_PORT, EN2_PIN, GPIO_PIN_RESET);
/*Configure GPIO pin : PB3 */
GPIO_InitStruct.Pin = EN1_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(EN1_PORT, &GPIO_InitStruct);
/*Configure GPIO pin : PB3 */
GPIO_InitStruct.Pin = EN2_PIN;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(EN2_PORT, &GPIO_InitStruct);
}
void flow_route_selection(uint8_t selection)
{
2025-09-14 18:47:02 +08:00
if(selection > HIGH_CUR)
selection = HIGH_CUR; // Invalid selection
if(selection < LOW_CUR)
selection = LOW_CUR;
2025-08-12 18:43:52 +08:00
if(selection == HIGH_CUR)
{
HAL_GPIO_WritePin(EN1_PORT, EN1_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(EN2_PORT, EN2_PIN, GPIO_PIN_RESET);
}
else if(selection == MID_CUR)
{
HAL_GPIO_WritePin(EN1_PORT, EN1_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(EN2_PORT, EN2_PIN, GPIO_PIN_SET);
}
else if(selection == LOW_CUR)
{
HAL_GPIO_WritePin(EN1_PORT, EN1_PIN, GPIO_PIN_RESET);
HAL_GPIO_WritePin(EN2_PORT, EN2_PIN, GPIO_PIN_RESET);
}
2025-09-14 18:47:02 +08:00
gate_status = selection; // Update the status
2025-08-12 18:43:52 +08:00
}
uint8_t Gate_get_status(void)
{
2025-09-14 18:47:02 +08:00
return gate_status;
}