2021-09-08 21:25:52 +08:00
|
|
|
#include "BaseObj.h"
|
|
|
|
#include "STM32_GPIO.h"
|
|
|
|
#include "dataStrs.h"
|
|
|
|
#include <stdint.h>
|
2021-09-09 08:40:13 +08:00
|
|
|
#include "STM32_common.h"
|
2021-09-08 21:25:52 +08:00
|
|
|
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
void STM32_GPIO_platformDisable(PikaObj *self){
|
2021-09-08 21:25:52 +08:00
|
|
|
char *pin = obj_getStr(self, "pin");
|
|
|
|
char *mode = obj_getStr(self, "mode");
|
|
|
|
|
|
|
|
GPIO_TypeDef *gpioPort = getGpioPort(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (NULL == gpioPort){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio port.");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t gpioPin = getGpioPin(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (0 == gpioPin){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio pin.");
|
|
|
|
}
|
|
|
|
|
|
|
|
HAL_GPIO_DeInit(gpioPort, gpioPin);
|
|
|
|
}
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
void STM32_GPIO_platformEnable(PikaObj *self){
|
2021-09-08 21:25:52 +08:00
|
|
|
char *pin = obj_getStr(self, "pin");
|
|
|
|
char *mode = obj_getStr(self, "mode");
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (0 != enableClk(pin)){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio port.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPIO_TypeDef *gpioPort = getGpioPort(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (NULL == gpioPort){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio port.");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t gpioPin = getGpioPin(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (0 == gpioPin){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio pin.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
|
|
|
|
|
|
|
uint32_t pinMode = getPinMode(mode);
|
2021-09-09 08:40:13 +08:00
|
|
|
if (NULL == pinMode){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio mode.");
|
|
|
|
}
|
|
|
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
/*Configure GPIO*/
|
|
|
|
GPIO_InitStruct.Pin = gpioPin;
|
|
|
|
GPIO_InitStruct.Mode = pinMode;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
|
|
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
|
|
|
|
}
|
2021-09-09 08:40:13 +08:00
|
|
|
void STM32_GPIO_platformLow(PikaObj *self){
|
2021-09-08 21:25:52 +08:00
|
|
|
char *pin = obj_getStr(self, "pin");
|
|
|
|
GPIO_TypeDef *gpioPort = getGpioPort(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (NULL == gpioPort){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio port.");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t gpioPin = getGpioPin(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (0 == gpioPin){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio pin.");
|
|
|
|
}
|
|
|
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
|
|
|
}
|
|
|
|
void STM32_GPIO_platformHigh(PikaObj *self)
|
|
|
|
{
|
|
|
|
char *pin = obj_getStr(self, "pin");
|
|
|
|
GPIO_TypeDef *gpioPort = getGpioPort(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (NULL == gpioPort){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio port.");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t gpioPin = getGpioPin(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (0 == gpioPin){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio pin.");
|
|
|
|
}
|
|
|
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_SET);
|
|
|
|
}
|
|
|
|
void STM32_GPIO_platformSetMode(PikaObj *self, char *mode)
|
|
|
|
{
|
|
|
|
char *pin = obj_getStr(self, "pin");
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (0 != enableClk(pin)){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio port.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GPIO_TypeDef *gpioPort = getGpioPort(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (NULL == gpioPort){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio port.");
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t gpioPin = getGpioPin(pin);
|
|
|
|
|
2021-09-09 08:40:13 +08:00
|
|
|
if (0 == gpioPin){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio pin.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
|
|
HAL_GPIO_WritePin(gpioPort, gpioPin, GPIO_PIN_RESET);
|
|
|
|
|
|
|
|
uint32_t pinMode = getPinMode(mode);
|
2021-09-09 08:40:13 +08:00
|
|
|
if (NULL == pinMode){
|
2021-09-08 21:25:52 +08:00
|
|
|
obj_setErrorCode(self, 1);
|
|
|
|
obj_setSysOut(self, "[error] not match gpio mode.");
|
|
|
|
}
|
|
|
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
|
|
|
/*Configure GPIO*/
|
|
|
|
GPIO_InitStruct.Pin = gpioPin;
|
|
|
|
GPIO_InitStruct.Mode = pinMode;
|
|
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
|
|
HAL_GPIO_Init(gpioPort, &GPIO_InitStruct);
|
|
|
|
}
|