pikapython/port/linux/package/pikascript/PikaStdDevice.pyi

493 lines
10 KiB
Python
Raw Normal View History

2022-08-14 23:55:24 +08:00
"""
## PikaStdDevice
2022-08-14 23:55:24 +08:00
PikaStdDevice is a standard and abstract device module for PikaScript.
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
PikaStdDevice supplies the standard device API for users.
2022-05-24 13:55:39 +08:00
2022-12-07 18:24:00 +08:00
Document: https://pikadoc.readthedocs.io/en/latest/PikaStdDevice%20%E6%A0%87%E5%87%86%E8%AE%BE%E5%A4%87.html
2022-08-14 23:55:24 +08:00
"""
from PikaObj import *
class GPIO(BaseDev):
def __init__(self): ...
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setPin(self, pinName: str):
2022-08-14 23:55:24 +08:00
"""
Use the name of the pin to select the GPIO pin.
example: `"PA0"`, `"PA1"` ...
"""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setId(self, id: int):
2022-08-14 23:55:24 +08:00
"""
Use the id of the pin to select the GPIO pin.
example: 0, 1 ...
"""
2022-02-26 14:40:56 +08:00
2022-04-07 22:57:59 +08:00
def getId(self) -> int:
2022-08-14 23:55:24 +08:00
"""
Get the id of the pin.
"""
2022-02-26 14:40:56 +08:00
2022-04-07 22:57:59 +08:00
def getPin(self) -> str:
2022-08-14 23:55:24 +08:00
"""
Get the name of the pin.
"""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setMode(self, mode: str):
2022-08-14 23:55:24 +08:00
"""
Set the mode of the pin.
example: "in", "out" ...
"""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def getMode(self) -> str:
2022-08-14 23:55:24 +08:00
"""
Get the mode of the pin.
"""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setPull(self, pull: str):
2022-08-14 23:55:24 +08:00
"""
Set the pull of the pin.
example: `"up"`, `"down"`, `"none"` ...
"""
2021-10-25 20:16:08 +08:00
2022-04-07 22:57:59 +08:00
def enable(self):
2022-08-14 23:55:24 +08:00
"""Enable the pin."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def disable(self):
2022-08-14 23:55:24 +08:00
"""Disable the pin."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def high(self):
2022-08-14 23:55:24 +08:00
"""Set the pin to high."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def low(self):
2022-08-14 23:55:24 +08:00
"""Set the pin to low."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def read(self) -> int:
2022-08-14 23:55:24 +08:00
"""Read the pin value."""
2023-01-18 12:23:30 +08:00
2021-10-25 20:16:08 +08:00
SIGNAL_RISING: int
SIGNAL_FALLING: int
SIGNAL_ANY: int
def setCallBack(self, eventCallBack: any, filter: int):
"""
Add a callback function to the pin.
Example:
``` python
def cb1(signal):
print("cb1", signal)
io.setCallBack(cb1, io.SIGNAL_RISING)
```
"""
2022-12-28 06:41:36 +08:00
def close(self): ...
2022-08-14 23:55:24 +08:00
def platformHigh(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
def platformLow(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
def platformEnable(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
def platformDisable(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
def platformSetMode(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
def platformRead(self): ...
2021-10-25 20:16:08 +08:00
2021-10-01 20:00:15 +08:00
def Time() -> time:
""" use time module instead """
2021-10-01 20:00:15 +08:00
class ADC(BaseDev):
2022-08-14 23:55:24 +08:00
def __init__(self): ...
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setPin(self, pin: str):
2022-08-14 23:55:24 +08:00
"""
Use the name of the pin to select the ADC pin.
example: `"PA0"`, `"PA1"` ...
"""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def enable(self):
2022-08-14 23:55:24 +08:00
"""Enable the ADC."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def disable(self):
2022-08-14 23:55:24 +08:00
"""Disable the ADC."""
2022-04-07 22:57:59 +08:00
def read(self) -> float:
2022-08-14 23:55:24 +08:00
"""Read the ADC value."""
2021-10-01 20:00:15 +08:00
2022-12-28 06:41:36 +08:00
def close(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformEnable(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformRead(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformDisable(self): ...
2021-10-01 20:00:15 +08:00
2022-12-07 19:25:28 +08:00
class DAC(BaseDev):
def __init__(self): ...
def setPin(self, pin: str):
"""
Use the name of the pin to select the DAC pin.
example: `"PA0"`, `"PA1"` ...
"""
def enable(self):
"""Enable the DAC."""
def disable(self):
"""Disable the DAC."""
def write(self, val: float):
2022-12-07 19:25:28 +08:00
"""write the DAC value."""
2022-12-28 06:41:36 +08:00
def close(self): ...
class UART:
2022-08-14 23:55:24 +08:00
def __init__(self): ...
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setBaudRate(self, baudRate: int):
2022-08-14 23:55:24 +08:00
"""Set the baud rate."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setId(self, id: int):
2022-08-14 23:55:24 +08:00
"""Set the id of the UART."""
2022-12-28 06:41:36 +08:00
FLOW_CONTROL_NONE: int
FLOW_CONTROL_RTS: int
FLOW_CONTROL_CTS: int
FLOW_CONTROL_RTS_CTS: int
2022-12-28 06:41:36 +08:00
def setFlowControl(self, flowControl: int):
"""Set the flow control of the UART."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def enable(self):
2022-08-14 23:55:24 +08:00
"""Enable the UART."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def disable(self):
2022-08-14 23:55:24 +08:00
"""Disable the UART."""
2022-04-07 22:57:59 +08:00
def write(self, data: str):
2022-08-14 23:55:24 +08:00
"""Write string to the UART."""
2021-10-01 20:00:15 +08:00
def writeBytes(self, data: bytes, length: int):
2022-08-14 23:55:24 +08:00
"""Write bytes to the UART."""
2022-04-07 22:57:59 +08:00
def read(self, length: int) -> str:
2022-08-14 23:55:24 +08:00
"""Read string from the UART."""
2021-10-01 20:00:15 +08:00
def readBytes(self, length: int) -> bytes:
2022-08-14 23:55:24 +08:00
"""Read bytes from the UART."""
2023-01-18 12:23:30 +08:00
def setPinTX(self, pin: str):
"""
Remap the TX pin.
"""
def setPinRX(self, pin: str):
"""
Remap the RX pin.
"""
def setPinCTS(self, pin: str):
"""
Remap the CTS pin.
"""
def setPinRTS(self, pin: str):
"""
Remap the RTS pin.
"""
2022-12-28 06:41:36 +08:00
def close(self): ...
SIGNAL_RX: int
SIGNAL_TX: int
def setCallBack(self, eventCallBack: any, filter: int):
"""
Add a callback function to the pin.
Example:
``` python
def cb1(signal):
print(uart.read(-1))
io.setCallBack(cb1, uart.SIGNAL_RX)
```
"""
2023-01-18 12:23:30 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformEnable(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWrite(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWriteBytes(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformRead(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformReadBytes(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformDisable(self): ...
2021-10-01 20:00:15 +08:00
2022-05-24 13:55:39 +08:00
class IIC(BaseDev):
2022-08-14 23:55:24 +08:00
def __init__(self): ...
2022-04-07 22:57:59 +08:00
def setPinSCL(self, pin: str):
2022-08-14 23:55:24 +08:00
"""Set the SCL pin."""
2022-04-07 22:57:59 +08:00
def setPinSDA(self, pin: str):
2022-08-14 23:55:24 +08:00
"""Set the SDA pin."""
2022-04-07 22:57:59 +08:00
def setDeviceAddr(self, addr: int):
2022-08-14 23:55:24 +08:00
"""Set the device address."""
2022-04-07 22:57:59 +08:00
def enable(self):
2022-08-14 23:55:24 +08:00
"""Enable the IIC."""
2022-04-07 22:57:59 +08:00
def disable(self):
2022-08-14 23:55:24 +08:00
"""Disable the IIC."""
2022-04-07 22:57:59 +08:00
def write(self, addr: int, data: str):
2022-08-14 23:55:24 +08:00
"""Write string to the IIC."""
def writeBytes(self, addr: int, data: bytes, length: int):
2022-08-14 23:55:24 +08:00
"""Write bytes to the IIC."""
2022-04-07 22:57:59 +08:00
def read(self, addr: int, length: int) -> str:
2022-08-14 23:55:24 +08:00
"""Read string from the IIC."""
def readBytes(self, addr: int, length: int) -> bytes:
2022-08-14 23:55:24 +08:00
"""Read bytes from the IIC."""
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformEnable(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWrite(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWriteBytes(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformRead(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformReadBytes(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformDisable(self): ...
2022-05-24 13:55:39 +08:00
class PWM(BaseDev):
2022-08-14 23:55:24 +08:00
def __init__(self): ...
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setName(self, name: str):
2022-08-14 23:55:24 +08:00
"""Use the device name to select the PWM pin.
exmpale: `"PWM0"`, `"PWM1"` ...
"""
2022-04-07 22:57:59 +08:00
def getName(self) -> str:
2022-08-14 23:55:24 +08:00
"""Get the device name."""
2022-04-07 22:57:59 +08:00
def setChannel(self, ch: int):
2022-08-14 23:55:24 +08:00
"""Set the channel."""
2022-04-07 22:57:59 +08:00
def getChannel(self) -> int:
2022-08-14 23:55:24 +08:00
"""Get the channel."""
2022-04-07 22:57:59 +08:00
def setPin(self, pin: str):
2022-08-14 23:55:24 +08:00
"""Use the name of the pin to select the PWM pin.
example: `"PA0"`, `"PA1"` ...
"""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setFrequency(self, freq: int):
2022-08-14 23:55:24 +08:00
"""Set the frequency."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def setFreq(self, freq: int):
2022-08-14 23:55:24 +08:00
"""Set the frequency."""
2022-04-07 22:57:59 +08:00
def setDuty(self, duty: float):
2022-08-14 23:55:24 +08:00
"""Set the duty."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def enable(self):
2022-08-14 23:55:24 +08:00
"""Enable the PWM."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def disable(self):
2022-08-14 23:55:24 +08:00
"""Disable the PWM."""
2022-04-07 22:57:59 +08:00
def getFrequency(self) -> int:
2022-08-14 23:55:24 +08:00
"""Get the frequency."""
2021-10-01 20:00:15 +08:00
2022-04-07 22:57:59 +08:00
def getDuty(self) -> float:
2022-08-14 23:55:24 +08:00
"""Get the duty."""
2021-10-01 20:00:15 +08:00
2022-12-28 06:41:36 +08:00
def close(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformEnable(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformSetFrequency(self): ...
2021-10-01 20:00:15 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformSetDuty(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformDisable(self): ...
2022-04-14 23:13:17 +08:00
class SPI(BaseDev):
2022-08-14 23:55:24 +08:00
def __init__(self): ...
2022-04-14 23:13:17 +08:00
def setPinSCK(self, pin: str):
2022-08-14 23:55:24 +08:00
"""Set the SCK pin."""
2022-04-14 23:13:17 +08:00
def setPinMOSI(self, pin: str):
2022-08-14 23:55:24 +08:00
"""Set the MOSI pin."""
2022-04-14 23:13:17 +08:00
def setPinMISO(self, pin: str):
2022-08-14 23:55:24 +08:00
"""Set the MISO pin."""
2022-04-14 23:13:17 +08:00
def setName(self, name: str):
2022-08-14 23:55:24 +08:00
"""Use the device name to select the SPI pin.
exmpale: `"SPI0"`, `"SPI1"` ...
"""
2022-04-14 23:13:17 +08:00
def setId(self, id: int):
2022-08-14 23:55:24 +08:00
"""Set the id of the SPI.
example: `0`, `1` ...
"""
2022-04-14 23:13:17 +08:00
def setPolarity(self, polarity: int):
2022-08-14 23:55:24 +08:00
"""Set the polarity."""
2022-04-14 23:13:17 +08:00
def setPhase(self, phase: int):
2022-08-14 23:55:24 +08:00
"""Set the phase."""
2022-04-14 23:13:17 +08:00
def setBaudRate(self, baudRate: int):
2022-08-14 23:55:24 +08:00
"""Set the baud rate."""
2022-04-14 23:13:17 +08:00
def enable(self):
2022-08-14 23:55:24 +08:00
"""Enable the SPI."""
2022-04-14 23:13:17 +08:00
def disable(self):
2022-08-14 23:55:24 +08:00
"""Disable the SPI."""
2022-04-14 23:13:17 +08:00
def write(self, data: str):
2022-08-14 23:55:24 +08:00
"""Write string to the SPI."""
2022-04-14 23:13:17 +08:00
def writeBytes(self, data: bytes, length: int):
2022-08-14 23:55:24 +08:00
"""Write bytes to the SPI."""
2022-04-14 23:13:17 +08:00
def read(self, length: int) -> str:
2022-08-14 23:55:24 +08:00
"""Read string from the SPI."""
2022-04-14 23:13:17 +08:00
def readBytes(self, length: int) -> bytes:
2022-08-14 23:55:24 +08:00
"""Read bytes from the SPI."""
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformEnable(self): ...
2022-04-14 23:13:17 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWrite(self): ...
2022-04-14 23:13:17 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWriteBytes(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformRead(self): ...
2022-04-14 23:13:17 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformReadBytes(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformDisable(self): ...
2022-04-15 14:50:27 +08:00
class CAN(BaseDev):
2022-08-14 23:55:24 +08:00
def __init__(self): ...
2022-04-15 14:50:27 +08:00
def setName(self, name: str):
2022-08-14 23:55:24 +08:00
"""Use the device name to select the CAN pin.
exmpale: `"CAN0"`, `"CAN1"` ...
"""
2022-04-15 14:50:27 +08:00
def setId(self, id: int):
2022-08-14 23:55:24 +08:00
"""Use the id to select the CAN pin.
example: `0`, `1` ...
"""
2022-04-15 14:50:27 +08:00
def setBaudRate(self, baudRate: int):
2022-08-14 23:55:24 +08:00
"""Set the baud rate."""
2022-04-15 14:50:27 +08:00
def setMode(self, mode: str):
2022-08-14 23:55:24 +08:00
"""Set the mode.
example: `"normal"`, `"loopback"`, `"silent"`, `"silent_loopback"`
"""
2022-04-15 14:50:27 +08:00
def enable(self):
2022-08-14 23:55:24 +08:00
"""Enable the CAN."""
2022-04-15 14:50:27 +08:00
def disable(self):
2022-08-14 23:55:24 +08:00
"""Disable the CAN."""
2022-04-15 14:50:27 +08:00
def write(self, data: str):
2022-08-14 23:55:24 +08:00
"""Write string to the CAN."""
2022-04-15 14:50:27 +08:00
def writeBytes(self, data: bytes, length: int):
2022-08-14 23:55:24 +08:00
"""Write bytes to the CAN."""
2022-04-15 14:50:27 +08:00
def read(self, length: int) -> str:
2022-08-14 23:55:24 +08:00
"""Read string from the CAN."""
2022-04-15 14:50:27 +08:00
def readBytes(self, length: int) -> bytes:
2022-08-14 23:55:24 +08:00
"""Read bytes from the CAN."""
def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
2022-08-14 23:55:24 +08:00
"""Add a filter."""
@abstractmethod
def platformEnable(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWrite(self): ...
2022-04-15 14:53:25 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformWriteBytes(self): ...
2022-04-15 14:50:27 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformRead(self): ...
2022-04-15 14:50:27 +08:00
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformReadBytes(self): ...
2022-08-14 23:55:24 +08:00
@abstractmethod
def platformDisable(self): ...
2022-04-15 14:50:27 +08:00
2022-08-14 23:55:24 +08:00
class BaseDev:
2022-08-24 13:18:38 +08:00
@PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
def addEventCallBack(self, eventCallback: any):
2022-08-14 23:55:24 +08:00
""" Add an event callback. """
@abstractmethod
2022-08-24 13:18:38 +08:00
@PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
2022-08-14 23:55:24 +08:00
def platformGetEventId(self): ...