From 1878ea884f1cb0a2965ef7a95bb92ba96e7326f1 Mon Sep 17 00:00:00 2001 From: lyon Date: Mon, 7 Mar 2022 14:58:21 +0800 Subject: [PATCH] add disable api for adc iic pwm and uart in std device --- package/PikaStdDevice/PikaStdDevice.py | 26 ++++++++++++++++++++++ package/PikaStdDevice/PikaStdDevice_ADC.c | 9 ++++++++ package/PikaStdDevice/PikaStdDevice_IIC.c | 9 ++++++++ package/PikaStdDevice/PikaStdDevice_PWM.c | 11 ++++++++- package/PikaStdDevice/PikaStdDevice_UART.c | 11 +++++++++ 5 files changed, 65 insertions(+), 1 deletion(-) diff --git a/package/PikaStdDevice/PikaStdDevice.py b/package/PikaStdDevice/PikaStdDevice.py index b9ec43e05..eef40e631 100644 --- a/package/PikaStdDevice/PikaStdDevice.py +++ b/package/PikaStdDevice/PikaStdDevice.py @@ -92,6 +92,9 @@ class ADC(TinyObj): def enable(): pass + def disable(): + pass + def read() -> float: pass @@ -103,6 +106,10 @@ class ADC(TinyObj): def platformRead(): pass + # need override + def platformDisable(): + pass + class UART(TinyObj): def __init__(): @@ -120,6 +127,9 @@ class UART(TinyObj): def enable(): pass + def disable(): + pass + def write(data: str): pass @@ -138,6 +148,9 @@ class UART(TinyObj): def platformRead(): pass + # need override + def platformDisable(): + pass class IIC(TinyObj): def __init__(): @@ -158,6 +171,9 @@ class IIC(TinyObj): def enable(): pass + def disable(): + pass + def write(addr: int, data: str): pass @@ -176,6 +192,9 @@ class IIC(TinyObj): def platformRead(): pass + # need override + def platformDisable(): + pass class PWM(TinyObj): def __init__(): @@ -211,6 +230,9 @@ class PWM(TinyObj): def enable(): pass + def disable(): + pass + def getFrequency() -> int: pass @@ -228,3 +250,7 @@ class PWM(TinyObj): # need override def platformSetDuty(): pass + + # need override + def platformDisable(): + pass diff --git a/package/PikaStdDevice/PikaStdDevice_ADC.c b/package/PikaStdDevice/PikaStdDevice_ADC.c index 49359f478..38ef4b00d 100644 --- a/package/PikaStdDevice/PikaStdDevice_ADC.c +++ b/package/PikaStdDevice/PikaStdDevice_ADC.c @@ -5,6 +5,10 @@ void PikaStdDevice_ADC_enable(PikaObj* self) { obj_run(self, "platformEnable()"); } +void PikaStdDevice_ADC_disable(PikaObj *self){ + obj_run(self, "platformDisable()"); +} + void PikaStdDevice_ADC_init(PikaObj* self) { obj_setStr(self, "pin", "PA0"); } @@ -27,6 +31,11 @@ void PikaStdDevice_ADC_platformEnable(PikaObj* self) { obj_setSysOut(self, "[error] platform method need to be override."); } +void PikaStdDevice_ADC_platformDisable(PikaObj *self){ + obj_setErrorCode(self, 1); + obj_setSysOut(self, "[error] platform method need to be override."); +} + void PikaStdDevice_ADC_platformRead(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); diff --git a/package/PikaStdDevice/PikaStdDevice_IIC.c b/package/PikaStdDevice/PikaStdDevice_IIC.c index ed8210138..dcdef6a06 100644 --- a/package/PikaStdDevice/PikaStdDevice_IIC.c +++ b/package/PikaStdDevice/PikaStdDevice_IIC.c @@ -15,6 +15,10 @@ void PikaStdDevice_IIC_enable(PikaObj *self){ obj_run(self, "platformEnable()"); } +void PikaStdDevice_IIC_disable(PikaObj *self){ + obj_run(self, "platformDisable()"); +} + void PikaStdDevice_IIC_setDeviceAddr(PikaObj *self, int addr){ obj_setInt(self, "deviceAddr", addr); } @@ -50,6 +54,11 @@ void PikaStdDevice_IIC_platformEnable(PikaObj *self){ obj_setSysOut(self, "[error] platform method need to be override."); } +void PikaStdDevice_IIC_platformDisable(PikaObj *self){ + obj_setErrorCode(self, 1); + obj_setSysOut(self, "[error] platform method need to be override."); +} + void PikaStdDevice_IIC_platformRead(PikaObj *self){ obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); diff --git a/package/PikaStdDevice/PikaStdDevice_PWM.c b/package/PikaStdDevice/PikaStdDevice_PWM.c index a1bbea58c..94f6f0ef1 100644 --- a/package/PikaStdDevice/PikaStdDevice_PWM.c +++ b/package/PikaStdDevice/PikaStdDevice_PWM.c @@ -31,6 +31,10 @@ void PikaStdDevice_PWM_enable(PikaObj* self) { obj_run(self, "platformEnable()"); } +void PikaStdDevice_PWM_disable(PikaObj *self){ + obj_run(self, "platformDisable()"); +} + float PikaStdDevice_PWM_getDuty(PikaObj* self) { return obj_getFloat(self, "duty"); } @@ -52,6 +56,11 @@ void PikaStdDevice_PWM_platformSetFrequency(PikaObj* self) { obj_setSysOut(self, "[error] platform method need to be override."); } +void PikaStdDevice_PWM_platformDisable(PikaObj *self){ + obj_setErrorCode(self, 1); + obj_setSysOut(self, "[error] platform method need to be override."); +} + char* PikaStdDevice_PWM_getName(PikaObj* self) { return obj_getStr(self, "name"); } @@ -70,4 +79,4 @@ int PikaStdDevice_PWM_getChannel(PikaObj* self) { void PikaStdDevice_PWM_setFreq(PikaObj* self, int freq) { PikaStdDevice_PWM_setFrequency(self, freq); -} \ No newline at end of file +} diff --git a/package/PikaStdDevice/PikaStdDevice_UART.c b/package/PikaStdDevice/PikaStdDevice_UART.c index bac6e5a64..e61f25786 100644 --- a/package/PikaStdDevice/PikaStdDevice_UART.c +++ b/package/PikaStdDevice/PikaStdDevice_UART.c @@ -4,6 +4,11 @@ void PikaStdDevice_UART_enable(PikaObj* self) { obj_run(self, "platformEnable()"); } + +void PikaStdDevice_UART_disable(PikaObj *self){ + obj_run(self, "platformDisable()"); +} + void PikaStdDevice_UART_init(PikaObj* self) { obj_setInt(self, "baudRate", 115200); obj_setInt(self, "id", 1); @@ -42,3 +47,9 @@ void PikaStdDevice_UART_platformWrite(PikaObj* self) { obj_setErrorCode(self, 1); obj_setSysOut(self, "[error] platform method need to be override."); } + +void PikaStdDevice_UART_platformDisable(PikaObj *self){ + obj_setErrorCode(self, 1); + obj_setSysOut(self, "[error] platform method need to be override."); +} +