| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- """
- ## PikaStdDevice
- PikaStdDevice is a standard and abstract device module for PikaScript.
- PikaStdDevice supplies the standard device API for users.
- Document: https://pikadoc-en.readthedocs.io/en/latest/PikaStdDevice%20%E6%A0%87%E5%87%86%E8%AE%BE%E5%A4%87.html
- """
- from PikaObj import *
- class GPIO(BaseDev):
- def __init__(self): ...
- def setPin(self, pinName: str):
- """
- Use the name of the pin to select the GPIO pin.
- example: `"PA0"`, `"PA1"` ...
- """
- def setId(self, id: int):
- """
- Use the id of the pin to select the GPIO pin.
- example: 0, 1 ...
- """
- def getId(self) -> int:
- """
- Get the id of the pin.
- """
- def getPin(self) -> str:
- """
- Get the name of the pin.
- """
- def setMode(self, mode: str):
- """
- Set the mode of the pin.
- example: "in", "out" ...
- """
- def getMode(self) -> str:
- """
- Get the mode of the pin.
- """
- def setPull(self, pull: str):
- """
- Set the pull of the pin.
- example: `"up"`, `"down"`, `"none"` ...
- """
- def enable(self):
- """Enable the pin."""
- def disable(self):
- """Disable the pin."""
- def high(self):
- """Set the pin to high."""
- def low(self):
- """Set the pin to low."""
- def read(self) -> int:
- """Read the pin value."""
- 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)
- ```
- The `signal` parameter is the signal type.
- The callback function will be called when the signal is triggered.
- """
- def setCallBack(self, eventCallBack: any, filter: int):
- """
- deprecated, you can use `setCallback` instead.
- """
- def close(self): ...
- def Time() -> time:
- """ deprecated use time module instead """
- class Timer:
- def __init__(self): ...
- def setPeriod(self, period_ms: int):
- """Set the period of the timer."""
- def setMode(self, mode: str):
- """
- Set the mode of the timer.
- Example: `"continuous"`, `"oneshot"` ...
- """
- SIGNAL_TIMEOUT: int
- SIGNAL_ANY: int
- def setCallback(self, callback: any, filter: int):
- """
- Add a callback function to the timer.
- The callback function will be called when the timer is triggered.
- """
- def enable(self):
- """Enable the timer."""
- def disable(self):
- """Disable the timer."""
- def setName(self, name: str):
- """Set the name of the timer."""
- def setId(self, id: int):
- """Set the id of the timer."""
- def getName(self) -> str:
- """Get the name of the timer."""
- def getId(self) -> int:
- """Get the id of the timer."""
- def close(self):
- """Close the timer."""
- class ADC(BaseDev):
- def __init__(self): ...
- def setPin(self, pin: str):
- """
- Use the name of the pin to select the ADC pin.
- example: `"PA0"`, `"PA1"` ...
- """
- def enable(self):
- """Enable the ADC."""
- def disable(self):
- """Disable the ADC."""
- def read(self) -> float:
- """Read the ADC value."""
- def close(self): ...
- 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):
- """write the DAC value."""
- def close(self): ...
- class UART:
- def __init__(self): ...
- def setBaudRate(self, baudRate: int):
- """Set the baud rate."""
- def setId(self, id: int):
- """Set the id of the UART."""
- STOP_BITS_1: int
- STOP_BITS_2: int
- STOP_BITS_1_5: int
- def setStopBits(self, stopBits: int):
- """Set the stop bits of the UART."""
- PARITY_NONE: int
- PARITY_EVEN: int
- PARITY_ODD: int
- def setParity(self, parity: int):
- """Set the parity of the UART."""
- FLOW_CONTROL_NONE: int
- FLOW_CONTROL_RTS: int
- FLOW_CONTROL_CTS: int
- FLOW_CONTROL_RTS_CTS: int
- def setFlowControl(self, flowControl: int):
- """Set the flow control of the UART."""
- def setDataBits(self, dataBits: int):
- """Set the data bits of the UART."""
- def enable(self):
- """Enable the UART."""
- def disable(self):
- """Disable the UART."""
- def write(self, data: str):
- """Write string to the UART."""
- def writeBytes(self, data: bytes, length: int):
- """Write bytes to the UART."""
- def read(self, length: int) -> str:
- """Read string from the UART."""
- def readBytes(self, length: int) -> bytes:
- """Read bytes from the UART."""
- 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.
- """
- 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)
- ```
- """
- def setCallBack(self, eventCallBack: any, filter: int):
- """
- deprecated, you can use `setCallback` instead.
- """
- class IIC(BaseDev):
- def __init__(self): ...
- def setPinSCL(self, pin: str):
- """Set the SCL pin."""
- def setPinSDA(self, pin: str):
- """Set the SDA pin."""
- def setDeviceAddr(self, addr: int):
- """Set the device address."""
- def enable(self):
- """Enable the IIC."""
- def disable(self):
- """Disable the IIC."""
- def write(self, addr: int, data: str):
- """Write string to the IIC."""
- def writeBytes(self, addr: int, data: bytes, length: int):
- """Write bytes to the IIC."""
- def read(self, addr: int, length: int) -> str:
- """Read string from the IIC."""
- def readBytes(self, addr: int, length: int) -> bytes:
- """Read bytes from the IIC."""
- class PWM(BaseDev):
- def __init__(self): ...
- def setName(self, name: str):
- """Use the device name to select the PWM pin.
- exmpale: `"PWM0"`, `"PWM1"` ...
- """
- def getName(self) -> str:
- """Get the device name."""
- def setChannel(self, ch: int):
- """Set the channel."""
- def getChannel(self) -> int:
- """Get the channel."""
- def setPin(self, pin: str):
- """Use the name of the pin to select the PWM pin.
- example: `"PA0"`, `"PA1"` ...
- """
- def setFrequency(self, freq: int):
- """Set the frequency."""
- def setFreq(self, freq: int):
- """Set the frequency."""
- def setDuty(self, duty: float):
- """Set the duty."""
- def enable(self):
- """Enable the PWM."""
- def disable(self):
- """Disable the PWM."""
- def getFrequency(self) -> int:
- """Get the frequency."""
- def getDuty(self) -> float:
- """Get the duty."""
- def close(self): ...
- class SPI(BaseDev):
- def __init__(self): ...
- def setPinSCK(self, pin: str):
- """Set the SCK pin."""
- def setPinMOSI(self, pin: str):
- """Set the MOSI pin."""
- def setPinMISO(self, pin: str):
- """Set the MISO pin."""
-
- def setPinCS(self, pin: str):
- """Set the CS pin."""
- def setName(self, name: str):
- """Use the device name to select the SPI pin.
- exmpale: `"SPI0"`, `"SPI1"` ...
- """
- def setId(self, id: int):
- """Set the id of the SPI.
- example: `0`, `1` ...
- """
- def setPolarity(self, polarity: int):
- """Set the polarity."""
- def setPhase(self, phase: int):
- """Set the phase."""
- def setBaudRate(self, baudRate: int):
- """Set the baud rate."""
- def enable(self):
- """Enable the SPI."""
- def disable(self):
- """Disable the SPI."""
- def write(self, data: str):
- """Write string to the SPI."""
- def writeBytes(self, data: bytes, length: int):
- """Write bytes to the SPI."""
- def read(self, length: int) -> str:
- """Read string from the SPI."""
- def readBytes(self, length: int) -> bytes:
- """Read bytes from the SPI."""
- class CAN(BaseDev):
- def __init__(self): ...
- def setName(self, name: str):
- """Use the device name to select the CAN pin.
- exmpale: `"CAN0"`, `"CAN1"` ...
- """
- def setId(self, id: int):
- """Use the id to select the CAN pin.
- example: `0`, `1` ...
- """
- def setBaudRate(self, baudRate: int):
- """Set the baud rate."""
- def setMode(self, mode: str):
- """Set the mode.
- example: `"normal"`, `"loopback"`, `"silent"`, `"silent_loopback"`
- """
- def enable(self):
- """Enable the CAN."""
- def disable(self):
- """Disable the CAN."""
- def write(self, data: str):
- """Write string to the CAN."""
- def writeBytes(self, data: bytes, length: int):
- """Write bytes to the CAN."""
- def read(self, length: int) -> str:
- """Read string from the CAN."""
- def readBytes(self, length: int) -> bytes:
- """Read bytes from the CAN."""
- def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
- """Add a filter."""
- class BaseDev:
- @PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
- def addEventCallback(self, eventCallback: any):
- """ Add an event callback. """
- def addEventCallBack(self, eventCallback: any):
- """ deprecated, use addEventCallback instead. """
- @abstractmethod
- @PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
- def platformGetEventId(self): ...
|