!106 AIR32F1_v0.1.0_1661411210299

Merge pull request !106 from 李昂/AIR32F1_v0.1.0_1661411210299
This commit is contained in:
李昂 2022-08-25 07:11:12 +00:00 committed by Gitee
commit 614b8f216b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 243 additions and 60 deletions

View File

@ -6,77 +6,77 @@ class GPIO(PikaStdDevice.GPIO):
def platformHigh(self): ...
def platformLow(self): ...
def platformEnable(self): ...
def platformDisable(self): ...
#def platformDisable(self): ...
def platformSetMode(self): ...
def platformRead(self): ...
def platformGetEventId(self): ...
#def platformGetEventId(self): ...
class Time(PikaStdDevice.Time):
# override
def sleep_s(self, s: int): ...
def sleep_ms(self, ms: int): ...
def platformGetTick(): ...
def platformGetEventId(self): ...
#def platformGetTick(): ...
#def platformGetEventId(self): ...
class ADC(PikaStdDevice.ADC):
# override
def platformEnable(self): ...
def platformRead(self): ...
def platformDisable(self): ...
def platformGetEventId(self): ...
#def platformEnable(self): ...
#def platformRead(self): ...
#def platformDisable(self): ...
#def platformGetEventId(self): ...
class UART(PikaStdDevice.UART):
# override
def platformEnable(self): ...
def platformWrite(self): ...
def platformWriteBytes(self): ...
def platformRead(self): ...
def platformReadBytes(self): ...
def platformDisable(self): ...
def platformGetEventId(self): ...
#def platformEnable(self): ...
#def platformWrite(self): ...
#def platformWriteBytes(self): ...
#def platformRead(self): ...
#def platformReadBytes(self): ...
#def platformDisable(self): ...
#def platformGetEventId(self): ...
class IIC(PikaStdDevice.IIC):
# override
def platformEnable(self): ...
def platformWrite(self): ...
def platformWriteBytes(self): ...
def platformRead(self): ...
def platformReadBytes(self): ...
def platformDisable(self): ...
def platformGetEventId(self): ...
#def platformEnable(self): ...
#def platformWrite(self): ...
#def platformWriteBytes(self): ...
#def platformRead(self): ...
#def platformReadBytes(self): ...
#def platformDisable(self): ...
#def platformGetEventId(self): ...
class PWM(PikaStdDevice.PWM):
# override
def platformEnable(self): ...
def platformSetFrequency(self): ...
def platformSetDuty(self): ...
def platformDisable(self): ...
def platformGetEventId(self): ...
#def platformEnable(self): ...
#def platformSetFrequency(self): ...
#def platformSetDuty(self): ...
#def platformDisable(self): ...
#def platformGetEventId(self): ...
class SPI(PikaStdDevice.SPI):
# override
def platformEnable(self): ...
def platformWrite(self): ...
def platformWriteBytes(self): ...
def platformRead(self): ...
def platformReadBytes(self): ...
def platformDisable(self): ...
def platformGetEventId(self): ...
#def platformEnable(self): ...
#def platformWrite(self): ...
#def platformWriteBytes(self): ...
#def platformRead(self): ...
#def platformReadBytes(self): ...
#def platformDisable(self): ...
#def platformGetEventId(self): ...
class CAN(PikaStdDevice.CAN):
# override
def platformEnable(self): ...
def platformWrite(self): ...
def platformWriteBytes(self): ...
def platformRead(self): ...
def platformReadBytes(self): ...
def platformDisable(self): ...
def platformGetEventId(self): ...
#def platformEnable(self): ...
#def platformWrite(self): ...
#def platformWriteBytes(self): ...
#def platformRead(self): ...
#def platformReadBytes(self): ...
#def platformDisable(self): ...
#def platformGetEventId(self): ...

View File

@ -1,13 +1,65 @@
#include "AIR32F1_GPIO.h"
#include "AIR32F1_common.h"
void AIR32F1_GPIO_platformDisable(PikaObj* self) {}
void AIR32F1_GPIO_platformEnable(PikaObj* self) {}
void AIR32F1_GPIO_platformHigh(PikaObj* self) {}
void AIR32F1_GPIO_platformLow(PikaObj* self) {}
void AIR32F1_GPIO_platformRead(PikaObj* self) {}
void AIR32F1_GPIO_platformSetMode(PikaObj* self) {}
const uint32_t GPIO_PA8_EVENT_ID = 0x08;
void AIR32F1_GPIO_platformGetEventId(PikaObj* self) {
void AIR32F1_GPIO_platformEnable(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
char* mode = obj_getStr(self, "mode");
GPIO_InitTypeDef GPIO_InitStructure;
if (0 != enableClk(pin)) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
return;
}
GPIO_TypeDef* gpioPort = getGpioPort(pin);
if (NULL == gpioPort) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio port.");
}
uint16_t gpioPin = getGpioPin(pin);
if (0 == gpioPin) {
obj_setErrorCode(self, 1);
obj_setSysOut(self, "[error] not match gpio pin.");
}
GPIOMode_TypeDef pinMode = getPinMode(mode);
GPIO_InitStructure.GPIO_Pin = gpioPin;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = pinMode;
GPIO_Init(gpioPort, &GPIO_InitStructure);
AIR32F1_GPIO_platformHigh(self);
}
void AIR32F1_GPIO_platformHigh(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = getGpioPort(pin);
uint16_t gpioPin = getGpioPin(pin);
GPIO_SetBits(gpioPort, gpioPin);
}
void AIR32F1_GPIO_platformLow(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = getGpioPort(pin);
uint16_t gpioPin = getGpioPin(pin);
GPIO_ResetBits(gpioPort, gpioPin);
}
void AIR32F1_GPIO_platformRead(PikaObj* self) {
char* pin = obj_getStr(self, "pin");
GPIO_TypeDef* gpioPort = getGpioPort(pin);
uint16_t gpioPin = getGpioPin(pin);
obj_setInt(self, "readBuff", GPIO_ReadOutputDataBit(gpioPort, gpioPin));
}
void AIR32F1_GPIO_platformSetMode(PikaObj* self) {
AIR32F1_GPIO_platformEnable(self);
}

View File

@ -1,16 +1,10 @@
#include "AIR32F1_Time.h"
#include "AIR32F1_common.h"
void AIR32F1_Time_sleep_ms(PikaObj *self, int ms){
Delay_Ms(ms);
}
void AIR32F1_Time_sleep_s(PikaObj *self, int s){
Delay_Ms(s*1000);
}
void AIR32F1_Time_platformGetTick(PikaObj *self){
}
void AIR32F1_Time_platformGetEventId(PikaObj *self){
}

View File

@ -0,0 +1,123 @@
#include "AIR32F1_common.h"
#include "pikaScript.h"
uint8_t enableClk(char* pin) {
if (strIsStartWith(pin, "PA")) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
return 0;
}
if (strIsStartWith(pin, "PB")) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
return 0;
}
if (strIsStartWith(pin, "PC")) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
return 0;
}
if (strIsStartWith(pin, "PD")) {
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
return 0;
}
return 1;
}
GPIO_TypeDef* getGpioPort(char* pin) {
if (strIsStartWith(pin, "PA")) {
return GPIOA;
}
if (strIsStartWith(pin, "PB")) {
return GPIOB;
}
if (strIsStartWith(pin, "PC")) {
return GPIOC;
}
if (strIsStartWith(pin, "PD")) {
return GPIOD;
}
return NULL;
}
uint16_t getGpioPin(char* pin) {
Args* buffs = New_strBuff();
uint16_t gpioPin = 0;
pin = strsCopy(buffs, pin + 2);
if (strEqu(pin, "0")) {
gpioPin = GPIO_Pin_0;
goto exit;
}
if (strEqu(pin, "1")) {
gpioPin = GPIO_Pin_1;
goto exit;
}
if (strEqu(pin, "2")) {
gpioPin = GPIO_Pin_2;
goto exit;
}
if (strEqu(pin, "3")) {
gpioPin = GPIO_Pin_3;
goto exit;
}
if (strEqu(pin, "4")) {
gpioPin = GPIO_Pin_4;
goto exit;
}
if (strEqu(pin, "5")) {
gpioPin = GPIO_Pin_5;
goto exit;
}
if (strEqu(pin, "6")) {
gpioPin = GPIO_Pin_6;
goto exit;
}
if (strEqu(pin, "7")) {
gpioPin = GPIO_Pin_7;
goto exit;
}
if (strEqu(pin, "8")) {
gpioPin = GPIO_Pin_8;
goto exit;
}
if (strEqu(pin, "9")) {
gpioPin = GPIO_Pin_9;
goto exit;
}
if (strEqu(pin, "10")) {
gpioPin = GPIO_Pin_10;
goto exit;
}
if (strEqu(pin, "11")) {
gpioPin = GPIO_Pin_11;
goto exit;
}
if (strEqu(pin, "12")) {
gpioPin = GPIO_Pin_12;
goto exit;
}
if (strEqu(pin, "13")) {
gpioPin = GPIO_Pin_13;
goto exit;
}
if (strEqu(pin, "14")) {
gpioPin = GPIO_Pin_14;
goto exit;
}
if (strEqu(pin, "15")) {
gpioPin = GPIO_Pin_15;
goto exit;
}
exit:
args_deinit(buffs);
return gpioPin;
}
GPIOMode_TypeDef getPinMode(char* mode) {
if (strEqu(mode, "out")) {
return GPIO_Mode_Out_PP;
}
if (strEqu(mode, "in")) {
return GPIO_Mode_AIN;
}
return GPIO_Mode_AIN;
}

View File

@ -0,0 +1,11 @@
#ifndef __AIR32F1_COMMON_H
#define __AIR32F1_COMMON_H
#include "air32f10x.h"
#include "delay.h"
uint8_t enableClk(char* pin);
GPIO_TypeDef* getGpioPort(char* pin);
uint16_t getGpioPin(char* pin);
GPIOMode_TypeDef getPinMode(char* mode);
#endif

View File

@ -328,4 +328,7 @@ releases = [ "v0.0.1 176232225939eccfaedfea412699a2e53c38ace1" ]
[[packages]]
name = "AIR32F1"
releases = [ "v0.0.1 9f9579c54ebddb12c66afc8da64a987767ff512f" ]
releases = [
"v0.0.1 9f9579c54ebddb12c66afc8da64a987767ff512f",
"v0.1.0 faa9c6230149d09188114af7af822e5d34af6b55"
]