mirror of
https://github.com/No-Chicken/Power-Pico.git
synced 2026-04-03 13:02:36 +08:00
update mos drive
This commit is contained in:
61
Power_Pico/BSP/GATE/gate.c
Normal file
61
Power_Pico/BSP/GATE/gate.c
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#include "gate.h"
|
||||||
|
|
||||||
|
static uint8_t status = HIGH_CUR; // Default status
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Invalid selection
|
||||||
|
HAL_GPIO_WritePin(EN1_PORT, EN1_PIN, GPIO_PIN_SET);
|
||||||
|
HAL_GPIO_WritePin(EN2_PORT, EN2_PIN, GPIO_PIN_SET);
|
||||||
|
}
|
||||||
|
status = selection; // Update the status
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t Gate_get_status(void)
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
31
Power_Pico/BSP/GATE/gate.h
Normal file
31
Power_Pico/BSP/GATE/gate.h
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#ifndef __GATE_H__
|
||||||
|
#define __GATE_H__
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
// EN1
|
||||||
|
#define EN1_PORT GPIOB
|
||||||
|
#define EN1_PIN GPIO_PIN_3
|
||||||
|
|
||||||
|
// EN2
|
||||||
|
#define EN2_PORT GPIOA
|
||||||
|
#define EN2_PIN GPIO_PIN_15
|
||||||
|
|
||||||
|
//
|
||||||
|
#define HIGH_CUR 0
|
||||||
|
#define MID_CUR 1
|
||||||
|
#define LOW_CUR 2
|
||||||
|
|
||||||
|
void Gate_Port_Init(void);
|
||||||
|
void flow_route_selection(uint8_t selection);
|
||||||
|
uint8_t Gate_get_status(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
Reference in New Issue
Block a user