!227 pikaRTDevice_v1.1.1_1682086904291

Merge pull request !227 from pikabot/pikaRTDevice_v1.1.1_1682086904291
This commit is contained in:
李昂 2023-04-21 14:26:52 +00:00 committed by Gitee
commit 95903f6815
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 32 additions and 193 deletions

View File

@ -1,36 +0,0 @@
#api
import PikaStdDevice
class GPIO(PikaStdDevice.GPIO):
def platformHigh():
pass
def platformLow():
pass
def platformEnable():
pass
def platformDisable():
pass
def platformSetMode():
pass
def platformRead():
pass
class PWM(PikaStdDevice.PWM):
# override
def platformEnable():
pass
# override
def platformSetFrequency():
pass
# override
def platformSetDuty():
pass

View File

@ -1,104 +0,0 @@
#include "pikaRTDevice_GPIO.h"
#include <rtdevice.h>
#include <rtthread.h>
rt_base_t pika_get_rt_mode_num(char* mode, char* pull);
rt_base_t GPIO_get_pin_num(PikaObj* self) {
#ifdef RT_USING_PIN
char* pin = obj_getStr(self, "pin");
int id = obj_getInt(self, "id");
if (!strEqu("none", pin)) {
/* pin name exist */
return rt_pin_get(pin);
} else {
return id;
}
#else
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PIN macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_GPIO_platformEnable(PikaObj* self) {
#ifdef RT_USING_PIN
char* pin = obj_getStr(self, "pin");
char* mode = obj_getStr(self, "mode");
char* pull = obj_getStr(self, "pull");
int id = obj_getInt(self, "id");
rt_base_t pin_num = GPIO_get_pin_num(self);
if (pin_num < 0) {
obj_setSysOut(self,
"[error]: gpio hardware fault, can not get pin number.");
obj_setErrorCode(self, 1);
}
rt_base_t mode_num = pika_get_rt_mode_num(mode, pull);
rt_pin_mode(pin_num, mode_num);
#else
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PIN macro. \r\n");
while(1);
#endif
}
rt_base_t pika_get_rt_mode_num(char* mode, char* pull) {
#ifdef RT_USING_PIN
if (strEqu(mode, "out")) {
return PIN_MODE_OUTPUT;
}
if (strEqu(mode, "in")) {
if (strEqu(pull, "none")) {
return PIN_MODE_INPUT;
}
if (strEqu(pull, "up")) {
return PIN_MODE_INPUT_PULLUP;
}
if (strEqu(pull, "down")) {
return PIN_MODE_INPUT_PULLDOWN;
}
}
/* default */
return PIN_MODE_OUTPUT;
#else
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PIN macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_GPIO_platformDisable(PikaObj* self) {}
void pikaRTDevice_GPIO_platformHigh(PikaObj* self) {
#ifdef RT_USING_PIN
char* pin = obj_getStr(self, "pin");
rt_base_t pin_num = GPIO_get_pin_num(self);
rt_pin_write(pin_num, PIN_HIGH);
#else
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PIN macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_GPIO_platformLow(PikaObj* self) {
#ifdef RT_USING_PIN
char* pin = obj_getStr(self, "pin");
rt_base_t pin_num = GPIO_get_pin_num(self);
rt_pin_write(pin_num, PIN_LOW);
#else
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PIN macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_GPIO_platformRead(PikaObj* self) {
#ifdef RT_USING_PIN
char* pin = obj_getStr(self, "pin");
rt_base_t pin_num = GPIO_get_pin_num(self);
obj_setInt(self, "readBuff", rt_pin_read(pin_num));
#else
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PIN macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_GPIO_platformSetMode(PikaObj* self) {
#ifdef RT_USING_PIN
pikaRTDevice_GPIO_platformEnable(self);
#else
__platform_printf("[error]: gpio driver is no enable, please check the RT_USING_PIN macro. \r\n");
while(1);
#endif
}

View File

@ -1,52 +0,0 @@
#include "pikaRTDevice_PWM.h"
#include <rtdevice.h>
#include <rtthread.h>
struct rt_device_pwm* PWM_getDevice(PikaObj* self) {
#ifdef RT_USING_PWM
char* name = obj_getStr(self, "name");
rt_device_t pwm_device = rt_device_find(name);
if(NULL == pwm_device){
printf("[error] PWM: device \"%s\" no found.\r\n", name);
}
return (struct rt_device_pwm*)pwm_device;
#else
__platform_printf("[error]: PWM driver is no enable, please check the RT_USING_PWM macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_PWM_platformEnable(PikaObj* self) {
#ifdef RT_USING_PWM
struct rt_device_pwm* pwm_dev = PWM_getDevice(self);
int ch = obj_getInt(self, "ch");
rt_pwm_enable(pwm_dev, ch);
#else
__platform_printf("[error]: PWM driver is no enable, please check the RT_USING_PWM macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_PWM_platformSetDuty(PikaObj* self) {
#ifdef RT_USING_PWM
struct rt_device_pwm* pwm_dev = PWM_getDevice(self);
int ch = obj_getInt(self, "ch");
int freq = obj_getInt(self, "freq");
float duty = obj_getFloat(self, "duty");
int period = (int)((1.0 / (float)freq) * 1000 * 1000);
int pulse = (int)((float)period * duty);
rt_pwm_set(pwm_dev, ch, period, pulse);
#else
__platform_printf("[error]: PWM driver is no enable, please check the RT_USING_PWM macro. \r\n");
while(1);
#endif
}
void pikaRTDevice_PWM_platformSetFrequency(PikaObj* self) {
#ifdef RT_USING_PWM
pikaRTDevice_PWM_platformSetDuty(self);
#else
__platform_printf("[error]: PWM driver is no enable, please check the RT_USING_PWM macro. \r\n");
while(1);
#endif
}

View File

@ -0,0 +1,30 @@
#include "../PikaStdDevice/pika_hal.h"
int pika_hal_platform_GPIO_open(pika_dev* dev, char* name) {
return -1;
}
int pika_hal_platform_GPIO_close(pika_dev* dev) {
return -1;
}
int pika_hal_platform_GPIO_read(pika_dev* dev, void* buf, size_t count) {
return -1;
}
int pika_hal_platform_GPIO_write(pika_dev* dev, void* buf, size_t count) {
return -1;
}
int pika_hal_platform_GPIO_ioctl_enable(pika_dev* dev) {
return -1;
}
int pika_hal_platform_GPIO_ioctl_disable(pika_dev* dev) {
return -1;
}
int pika_hal_platform_GPIO_ioctl_config(pika_dev* dev,
pika_hal_GPIO_config* cfg) {
return -1;
}

View File

@ -356,7 +356,8 @@ releases = [
"v0.0.1 fe900b79d8d1075bb7e4e3dd9d4e1e187e0c9195",
"v1.0.0 ac4247e5fd3e221eb110a1b41276849c623049ec",
"v1.0.1 61e6a7352b65adbce0f2ad82ea1fc992dcbb603",
"v1.1.0 9f3a52558338503571b37c034a12219566f27aa2"
"v1.1.0 9f3a52558338503571b37c034a12219566f27aa2",
"v1.1.1 6f3a7dc59e89d9f48f2bb3a55966d34551047894"
]
[[packages]]