add comments to PikaStdDevice

This commit is contained in:
pikastech 2022-08-14 23:55:24 +08:00
parent addc7160e1
commit 8fff0950a0
4 changed files with 498 additions and 484 deletions

View File

@ -1,456 +1,451 @@
"""
PikaStdDevice is a standard and abstract device module for PikaScript.
PikaStdDevice supplies the standard device API for users.
Users need inherit from PikaStdDevice and override the abstract methods, witch is with `@abstractmethod` decorator.
For example, the STM32F1 device module: https://gitee.com/Lyon1998/pikascript/blob/master/package/STM32F1/STM32F1.pyi
And for convinience, make a machine.pyi to inhert from STM32F1 device module for alias perpose.
For example:
- The machine.pyi for STM32F1:https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32f103c8/pikascript/machine.pyi
- The machine.pyi for STM32G0: https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32g070cb/pikascript/machine.pyi
"""
from PikaObj import *
class BaseDev(TinyObj):
def addEventCallBack(self, eventCallback: any): ...
# need override
def platformGetEventId(self): ...
class GPIO(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setPin(self, pinName: str):
pass
"""
Use the name of the pin to select the GPIO pin.
example: `"PA0"`, `"PA1"` ...
"""
def setId(self, id: int):
pass
"""
Use the id of the pin to select the GPIO pin.
example: 0, 1 ...
"""
def getId(self) -> int:
pass
"""
Get the id of the pin.
"""
def getPin(self) -> str:
pass
"""
Get the name of the pin.
"""
def setMode(self, mode: str):
pass
"""
Set the mode of the pin.
example: "in", "out" ...
"""
def getMode(self) -> str:
pass
"""
Get the mode of the pin.
"""
def setPull(self, pull: str):
pass
"""
Set the pull of the pin.
example: `"up"`, `"down"`, `"none"` ...
"""
def enable(self):
pass
"""Enable the pin."""
def disable(self):
pass
"""Disable the pin."""
def high(self):
pass
"""Set the pin to high."""
def low(self):
pass
"""Set the pin to low."""
def read(self) -> int:
pass
"""Read the pin value."""
# need be overrid
def platformHigh(self):
pass
@abstractmethod
def platformHigh(self): ...
# need override
def platformLow(self):
pass
@abstractmethod
def platformLow(self): ...
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
# need override
def platformSetMode(self):
pass
@abstractmethod
def platformSetMode(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
class Time(BaseDev):
def __init__(self):
pass
def __init__(self): ...
def sleep(self, s: float):
pass
"""Sleep for s seconds."""
def time(self) -> float:
pass
"""Get the current time."""
def time_ns(self) -> int:
pass
"""Get the current time in nanoseconds."""
def gmtime(self, unix_time: float):
pass
"""Convert unix time to struct_time."""
def localtime(self, unix_time: float):
pass
"""Convert unix time to struct_time."""
def mktime(self) -> int:
pass
"""Convert struct_time to unix time."""
def asctime(self):
pass
"""Convert struct_time to string."""
def ctime(self, unix_time: float):
pass
"""Convert unix time to string."""
# need override
def sleep_s(self, s: int):
pass
@abstractmethod
def sleep_s(self, s: int): ...
# need override
def sleep_ms(self, ms: int):
pass
@abstractmethod
def sleep_ms(self, ms: int): ...
# need override
def platformGetTick():
pass
@abstractmethod
def platformGetTick(): ...
class ADC(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setPin(self, pin: str):
pass
"""
Use the name of the pin to select the ADC pin.
example: `"PA0"`, `"PA1"` ...
"""
def enable(self):
pass
"""Enable the ADC."""
def disable(self):
pass
"""Disable the ADC."""
def read(self) -> float:
pass
"""Read the ADC value."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class UART(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setBaudRate(self, baudRate: int):
pass
"""Set the baud rate."""
def setId(self, id: int):
pass
"""Set the id of the UART."""
def enable(self):
pass
"""Enable the UART."""
def disable(self):
pass
"""Disable the UART."""
def write(self, data: str):
pass
"""Write string to the UART."""
def writeBytes(self, data: bytes, length: int):
pass
"""Write bytes to the UART."""
def read(self, length: int) -> str:
pass
"""Read string from the UART."""
def readBytes(self, length: int) -> bytes:
pass
"""Read bytes from the UART."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class IIC(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setPinSCL(self, pin: str):
pass
"""Set the SCL pin."""
def setPinSDA(self, pin: str):
pass
"""Set the SDA pin."""
def setDeviceAddr(self, addr: int):
pass
"""Set the device address."""
def enable(self):
pass
"""Enable the IIC."""
def disable(self):
pass
"""Disable the IIC."""
def write(self, addr: int, data: str):
pass
"""Write string to the IIC."""
def writeBytes(self, addr: int, data: bytes, length: int):
pass
"""Write bytes to the IIC."""
def read(self, addr: int, length: int) -> str:
pass
"""Read string from the IIC."""
def readBytes(self, addr: int, length: int) -> bytes:
pass
"""Read bytes from the IIC."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
# need override
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class PWM(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setName(self, name: str):
pass
"""Use the device name to select the PWM pin.
exmpale: `"PWM0"`, `"PWM1"` ...
"""
def getName(self) -> str:
pass
"""Get the device name."""
def setChannel(self, ch: int):
pass
"""Set the channel."""
def getChannel(self) -> int:
pass
"""Get the channel."""
def setPin(self, pin: str):
pass
"""Use the name of the pin to select the PWM pin.
example: `"PA0"`, `"PA1"` ...
"""
def setFrequency(self, freq: int):
pass
"""Set the frequency."""
def setFreq(self, freq: int):
pass
"""Set the frequency."""
def setDuty(self, duty: float):
pass
"""Set the duty."""
def enable(self):
pass
"""Enable the PWM."""
def disable(self):
pass
"""Disable the PWM."""
def getFrequency(self) -> int:
pass
"""Get the frequency."""
def getDuty(self) -> float:
pass
"""Get the duty."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformSetFrequency(self):
pass
@abstractmethod
def platformSetFrequency(self): ...
# need override
def platformSetDuty(self):
pass
@abstractmethod
def platformSetDuty(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class SPI(BaseDev):
def __init__(self):
pass
def __init__(self): ...
def setPinSCK(self, pin: str):
pass
"""Set the SCK pin."""
def setPinMOSI(self, pin: str):
pass
"""Set the MOSI pin."""
def setPinMISO(self, pin: str):
pass
"""Set the MISO pin."""
def setName(self, name: str):
pass
"""Use the device name to select the SPI pin.
exmpale: `"SPI0"`, `"SPI1"` ...
"""
def setId(self, id: int):
pass
"""Set the id of the SPI.
example: `0`, `1` ...
"""
def setPolarity(self, polarity: int):
pass
"""Set the polarity."""
def setPhase(self, phase: int):
pass
"""Set the phase."""
def setBaudRate(self, baudRate: int):
pass
"""Set the baud rate."""
def enable(self):
pass
"""Enable the SPI."""
def disable(self):
pass
"""Disable the SPI."""
def write(self, data: str):
pass
"""Write string to the SPI."""
def writeBytes(self, data: bytes, length: int):
pass
"""Write bytes to the SPI."""
def read(self, length: int) -> str:
pass
"""Read string from the SPI."""
def readBytes(self, length: int) -> bytes:
pass
"""Read bytes from the SPI."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
# need override
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class CAN(BaseDev):
def __init__(self):
pass
def __init__(self): ...
def setName(self, name: str):
pass
"""Use the device name to select the CAN pin.
exmpale: `"CAN0"`, `"CAN1"` ...
"""
def setId(self, id: int):
pass
"""Use the id to select the CAN pin.
example: `0`, `1` ...
"""
def setBaudRate(self, baudRate: int):
pass
"""Set the baud rate."""
def setMode(self, mode: str):
pass
"""Set the mode.
example: `"normal"`, `"loopback"`, `"silent"`, `"silent_loopback"`
"""
def enable(self):
pass
"""Enable the CAN."""
def disable(self):
pass
"""Disable the CAN."""
def write(self, data: str):
pass
"""Write string to the CAN."""
def writeBytes(self, data: bytes, length: int):
pass
"""Write bytes to the CAN."""
def read(self, length: int) -> str:
pass
"""Read string from the CAN."""
def readBytes(self, length: int) -> bytes:
pass
"""Read bytes from the CAN."""
def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
pass
def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
"""Add a filter."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
# need override
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class BaseDev:
def addEventCallBack(self, eventCallback: any):
""" Add an event callback. """
@abstractmethod
def platformGetEventId(self): ...

View File

@ -1,6 +1,18 @@
class TinyObj:...
class BaseObj(TinyObj):...
class pointer:...
class any:...
def printNoEnd(val: any):
pass
class TinyObj:
...
class BaseObj(TinyObj):
...
class pointer:
...
class any:
...
def printNoEnd(val: any): ...
def abstractmethod(funcobj): ...

View File

@ -1,456 +1,451 @@
"""
PikaStdDevice is a standard and abstract device module for PikaScript.
PikaStdDevice supplies the standard device API for users.
Users need inherit from PikaStdDevice and override the abstract methods, witch is with `@abstractmethod` decorator.
For example, the STM32F1 device module: https://gitee.com/Lyon1998/pikascript/blob/master/package/STM32F1/STM32F1.pyi
And for convinience, make a machine.pyi to inhert from STM32F1 device module for alias perpose.
For example:
- The machine.pyi for STM32F1:https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32f103c8/pikascript/machine.pyi
- The machine.pyi for STM32G0: https://gitee.com/Lyon1998/pikascript/blob/master/bsp/stm32g070cb/pikascript/machine.pyi
"""
from PikaObj import *
class BaseDev(TinyObj):
def addEventCallBack(self, eventCallback: any): ...
# need override
def platformGetEventId(self): ...
class GPIO(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setPin(self, pinName: str):
pass
"""
Use the name of the pin to select the GPIO pin.
example: `"PA0"`, `"PA1"` ...
"""
def setId(self, id: int):
pass
"""
Use the id of the pin to select the GPIO pin.
example: 0, 1 ...
"""
def getId(self) -> int:
pass
"""
Get the id of the pin.
"""
def getPin(self) -> str:
pass
"""
Get the name of the pin.
"""
def setMode(self, mode: str):
pass
"""
Set the mode of the pin.
example: "in", "out" ...
"""
def getMode(self) -> str:
pass
"""
Get the mode of the pin.
"""
def setPull(self, pull: str):
pass
"""
Set the pull of the pin.
example: `"up"`, `"down"`, `"none"` ...
"""
def enable(self):
pass
"""Enable the pin."""
def disable(self):
pass
"""Disable the pin."""
def high(self):
pass
"""Set the pin to high."""
def low(self):
pass
"""Set the pin to low."""
def read(self) -> int:
pass
"""Read the pin value."""
# need be overrid
def platformHigh(self):
pass
@abstractmethod
def platformHigh(self): ...
# need override
def platformLow(self):
pass
@abstractmethod
def platformLow(self): ...
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
# need override
def platformSetMode(self):
pass
@abstractmethod
def platformSetMode(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
class Time(BaseDev):
def __init__(self):
pass
def __init__(self): ...
def sleep(self, s: float):
pass
"""Sleep for s seconds."""
def time(self) -> float:
pass
"""Get the current time."""
def time_ns(self) -> int:
pass
"""Get the current time in nanoseconds."""
def gmtime(self, unix_time: float):
pass
"""Convert unix time to struct_time."""
def localtime(self, unix_time: float):
pass
"""Convert unix time to struct_time."""
def mktime(self) -> int:
pass
"""Convert struct_time to unix time."""
def asctime(self):
pass
"""Convert struct_time to string."""
def ctime(self, unix_time: float):
pass
"""Convert unix time to string."""
# need override
def sleep_s(self, s: int):
pass
@abstractmethod
def sleep_s(self, s: int): ...
# need override
def sleep_ms(self, ms: int):
pass
@abstractmethod
def sleep_ms(self, ms: int): ...
# need override
def platformGetTick():
pass
@abstractmethod
def platformGetTick(): ...
class ADC(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setPin(self, pin: str):
pass
"""
Use the name of the pin to select the ADC pin.
example: `"PA0"`, `"PA1"` ...
"""
def enable(self):
pass
"""Enable the ADC."""
def disable(self):
pass
"""Disable the ADC."""
def read(self) -> float:
pass
"""Read the ADC value."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class UART(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setBaudRate(self, baudRate: int):
pass
"""Set the baud rate."""
def setId(self, id: int):
pass
"""Set the id of the UART."""
def enable(self):
pass
"""Enable the UART."""
def disable(self):
pass
"""Disable the UART."""
def write(self, data: str):
pass
"""Write string to the UART."""
def writeBytes(self, data: bytes, length: int):
pass
"""Write bytes to the UART."""
def read(self, length: int) -> str:
pass
"""Read string from the UART."""
def readBytes(self, length: int) -> bytes:
pass
"""Read bytes from the UART."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class IIC(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setPinSCL(self, pin: str):
pass
"""Set the SCL pin."""
def setPinSDA(self, pin: str):
pass
"""Set the SDA pin."""
def setDeviceAddr(self, addr: int):
pass
"""Set the device address."""
def enable(self):
pass
"""Enable the IIC."""
def disable(self):
pass
"""Disable the IIC."""
def write(self, addr: int, data: str):
pass
"""Write string to the IIC."""
def writeBytes(self, addr: int, data: bytes, length: int):
pass
"""Write bytes to the IIC."""
def read(self, addr: int, length: int) -> str:
pass
"""Read string from the IIC."""
def readBytes(self, addr: int, length: int) -> bytes:
pass
"""Read bytes from the IIC."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
# need override
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class PWM(BaseDev):
def __init__(self):
pass
def init(self):
pass
def __init__(self): ...
def setName(self, name: str):
pass
"""Use the device name to select the PWM pin.
exmpale: `"PWM0"`, `"PWM1"` ...
"""
def getName(self) -> str:
pass
"""Get the device name."""
def setChannel(self, ch: int):
pass
"""Set the channel."""
def getChannel(self) -> int:
pass
"""Get the channel."""
def setPin(self, pin: str):
pass
"""Use the name of the pin to select the PWM pin.
example: `"PA0"`, `"PA1"` ...
"""
def setFrequency(self, freq: int):
pass
"""Set the frequency."""
def setFreq(self, freq: int):
pass
"""Set the frequency."""
def setDuty(self, duty: float):
pass
"""Set the duty."""
def enable(self):
pass
"""Enable the PWM."""
def disable(self):
pass
"""Disable the PWM."""
def getFrequency(self) -> int:
pass
"""Get the frequency."""
def getDuty(self) -> float:
pass
"""Get the duty."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformSetFrequency(self):
pass
@abstractmethod
def platformSetFrequency(self): ...
# need override
def platformSetDuty(self):
pass
@abstractmethod
def platformSetDuty(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class SPI(BaseDev):
def __init__(self):
pass
def __init__(self): ...
def setPinSCK(self, pin: str):
pass
"""Set the SCK pin."""
def setPinMOSI(self, pin: str):
pass
"""Set the MOSI pin."""
def setPinMISO(self, pin: str):
pass
"""Set the MISO pin."""
def setName(self, name: str):
pass
"""Use the device name to select the SPI pin.
exmpale: `"SPI0"`, `"SPI1"` ...
"""
def setId(self, id: int):
pass
"""Set the id of the SPI.
example: `0`, `1` ...
"""
def setPolarity(self, polarity: int):
pass
"""Set the polarity."""
def setPhase(self, phase: int):
pass
"""Set the phase."""
def setBaudRate(self, baudRate: int):
pass
"""Set the baud rate."""
def enable(self):
pass
"""Enable the SPI."""
def disable(self):
pass
"""Disable the SPI."""
def write(self, data: str):
pass
"""Write string to the SPI."""
def writeBytes(self, data: bytes, length: int):
pass
"""Write bytes to the SPI."""
def read(self, length: int) -> str:
pass
"""Read string from the SPI."""
def readBytes(self, length: int) -> bytes:
pass
"""Read bytes from the SPI."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
# need override
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class CAN(BaseDev):
def __init__(self):
pass
def __init__(self): ...
def setName(self, name: str):
pass
"""Use the device name to select the CAN pin.
exmpale: `"CAN0"`, `"CAN1"` ...
"""
def setId(self, id: int):
pass
"""Use the id to select the CAN pin.
example: `0`, `1` ...
"""
def setBaudRate(self, baudRate: int):
pass
"""Set the baud rate."""
def setMode(self, mode: str):
pass
"""Set the mode.
example: `"normal"`, `"loopback"`, `"silent"`, `"silent_loopback"`
"""
def enable(self):
pass
"""Enable the CAN."""
def disable(self):
pass
"""Disable the CAN."""
def write(self, data: str):
pass
"""Write string to the CAN."""
def writeBytes(self, data: bytes, length: int):
pass
"""Write bytes to the CAN."""
def read(self, length: int) -> str:
pass
"""Read string from the CAN."""
def readBytes(self, length: int) -> bytes:
pass
"""Read bytes from the CAN."""
def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
pass
def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
"""Add a filter."""
# need override
def platformEnable(self):
pass
@abstractmethod
def platformEnable(self): ...
# need override
def platformWrite(self):
pass
@abstractmethod
def platformWrite(self): ...
# need override
def platformWriteBytes(self):
pass
@abstractmethod
def platformWriteBytes(self): ...
# need override
def platformRead(self):
pass
@abstractmethod
def platformRead(self): ...
# need override
def platformReadBytes(self):
pass
@abstractmethod
def platformReadBytes(self): ...
# need override
def platformDisable(self):
pass
@abstractmethod
def platformDisable(self): ...
class BaseDev:
def addEventCallBack(self, eventCallback: any):
""" Add an event callback. """
@abstractmethod
def platformGetEventId(self): ...

View File

@ -1,6 +1,18 @@
class TinyObj:...
class BaseObj(TinyObj):...
class pointer:...
class any:...
def printNoEnd(val: any):
pass
class TinyObj:
...
class BaseObj(TinyObj):
...
class pointer:
...
class any:
...
def printNoEnd(val: any): ...
def abstractmethod(funcobj): ...