PikaStdDevice.pyi 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. """
  2. ## PikaStdDevice
  3. PikaStdDevice is a standard and abstract device module for PikaScript.
  4. PikaStdDevice supplies the standard device API for users.
  5. Document: https://pikadoc-en.readthedocs.io/en/latest/PikaStdDevice%20%E6%A0%87%E5%87%86%E8%AE%BE%E5%A4%87.html
  6. """
  7. from PikaObj import *
  8. class GPIO(BaseDev):
  9. def __init__(self): ...
  10. def setPin(self, pinName: str):
  11. """
  12. Use the name of the pin to select the GPIO pin.
  13. example: `"PA0"`, `"PA1"` ...
  14. """
  15. def setId(self, id: int):
  16. """
  17. Use the id of the pin to select the GPIO pin.
  18. example: 0, 1 ...
  19. """
  20. def getId(self) -> int:
  21. """
  22. Get the id of the pin.
  23. """
  24. def getPin(self) -> str:
  25. """
  26. Get the name of the pin.
  27. """
  28. def setMode(self, mode: str):
  29. """
  30. Set the mode of the pin.
  31. example: "in", "out" ...
  32. """
  33. def getMode(self) -> str:
  34. """
  35. Get the mode of the pin.
  36. """
  37. def setPull(self, pull: str):
  38. """
  39. Set the pull of the pin.
  40. example: `"up"`, `"down"`, `"none"` ...
  41. """
  42. def enable(self):
  43. """Enable the pin."""
  44. def disable(self):
  45. """Disable the pin."""
  46. def high(self):
  47. """Set the pin to high."""
  48. def low(self):
  49. """Set the pin to low."""
  50. def read(self) -> int:
  51. """Read the pin value."""
  52. SIGNAL_RISING: int
  53. SIGNAL_FALLING: int
  54. SIGNAL_ANY: int
  55. def setCallback(self, eventCallBack: any, filter: int):
  56. """
  57. Add a callback function to the pin.
  58. Example:
  59. ``` python
  60. def cb1(signal):
  61. print("cb1", signal)
  62. io.setCallBack(cb1, io.SIGNAL_RISING)
  63. ```
  64. The `signal` parameter is the signal type.
  65. The callback function will be called when the signal is triggered.
  66. """
  67. def setCallBack(self, eventCallBack: any, filter: int):
  68. """
  69. deprecated, you can use `setCallback` instead.
  70. """
  71. def close(self): ...
  72. def Time() -> time:
  73. """ deprecated use time module instead """
  74. class Timer:
  75. def __init__(self): ...
  76. def setPeriod(self, period_ms: int):
  77. """Set the period of the timer."""
  78. def setMode(self, mode: str):
  79. """
  80. Set the mode of the timer.
  81. Example: `"continuous"`, `"oneshot"` ...
  82. """
  83. SIGNAL_TIMEOUT: int
  84. SIGNAL_ANY: int
  85. def setCallback(self, callback: any, filter: int):
  86. """
  87. Add a callback function to the timer.
  88. The callback function will be called when the timer is triggered.
  89. """
  90. def enable(self):
  91. """Enable the timer."""
  92. def disable(self):
  93. """Disable the timer."""
  94. def setName(self, name: str):
  95. """Set the name of the timer."""
  96. def setId(self, id: int):
  97. """Set the id of the timer."""
  98. def getName(self) -> str:
  99. """Get the name of the timer."""
  100. def getId(self) -> int:
  101. """Get the id of the timer."""
  102. def close(self):
  103. """Close the timer."""
  104. class ADC(BaseDev):
  105. def __init__(self): ...
  106. def setPin(self, pin: str):
  107. """
  108. Use the name of the pin to select the ADC pin.
  109. example: `"PA0"`, `"PA1"` ...
  110. """
  111. def enable(self):
  112. """Enable the ADC."""
  113. def disable(self):
  114. """Disable the ADC."""
  115. def read(self) -> float:
  116. """Read the ADC value."""
  117. def close(self): ...
  118. class DAC(BaseDev):
  119. def __init__(self): ...
  120. def setPin(self, pin: str):
  121. """
  122. Use the name of the pin to select the DAC pin.
  123. example: `"PA0"`, `"PA1"` ...
  124. """
  125. def enable(self):
  126. """Enable the DAC."""
  127. def disable(self):
  128. """Disable the DAC."""
  129. def write(self, val: float):
  130. """write the DAC value."""
  131. def close(self): ...
  132. class UART:
  133. def __init__(self): ...
  134. def setBaudRate(self, baudRate: int):
  135. """Set the baud rate."""
  136. def setId(self, id: int):
  137. """Set the id of the UART."""
  138. STOP_BITS_1: int
  139. STOP_BITS_2: int
  140. STOP_BITS_1_5: int
  141. def setStopBits(self, stopBits: int):
  142. """Set the stop bits of the UART."""
  143. PARITY_NONE: int
  144. PARITY_EVEN: int
  145. PARITY_ODD: int
  146. def setParity(self, parity: int):
  147. """Set the parity of the UART."""
  148. FLOW_CONTROL_NONE: int
  149. FLOW_CONTROL_RTS: int
  150. FLOW_CONTROL_CTS: int
  151. FLOW_CONTROL_RTS_CTS: int
  152. def setFlowControl(self, flowControl: int):
  153. """Set the flow control of the UART."""
  154. def setDataBits(self, dataBits: int):
  155. """Set the data bits of the UART."""
  156. def enable(self):
  157. """Enable the UART."""
  158. def disable(self):
  159. """Disable the UART."""
  160. def write(self, data: str):
  161. """Write string to the UART."""
  162. def writeBytes(self, data: bytes, length: int):
  163. """Write bytes to the UART."""
  164. def read(self, length: int) -> str:
  165. """Read string from the UART."""
  166. def readBytes(self, length: int) -> bytes:
  167. """Read bytes from the UART."""
  168. def setPinTX(self, pin: str):
  169. """
  170. Remap the TX pin.
  171. """
  172. def setPinRX(self, pin: str):
  173. """
  174. Remap the RX pin.
  175. """
  176. def setPinCTS(self, pin: str):
  177. """
  178. Remap the CTS pin.
  179. """
  180. def setPinRTS(self, pin: str):
  181. """
  182. Remap the RTS pin.
  183. """
  184. def close(self): ...
  185. SIGNAL_RX: int
  186. SIGNAL_TX: int
  187. def setCallback(self, eventCallBack: any, filter: int):
  188. """
  189. Add a callback function to the pin.
  190. Example:
  191. ``` python
  192. def cb1(signal):
  193. print(uart.read(-1))
  194. io.setCallBack(cb1, uart.SIGNAL_RX)
  195. ```
  196. """
  197. def setCallBack(self, eventCallBack: any, filter: int):
  198. """
  199. deprecated, you can use `setCallback` instead.
  200. """
  201. class IIC(BaseDev):
  202. def __init__(self): ...
  203. def setPinSCL(self, pin: str):
  204. """Set the SCL pin."""
  205. def setPinSDA(self, pin: str):
  206. """Set the SDA pin."""
  207. def setDeviceAddr(self, addr: int):
  208. """Set the device address."""
  209. def enable(self):
  210. """Enable the IIC."""
  211. def disable(self):
  212. """Disable the IIC."""
  213. def write(self, addr: int, data: str):
  214. """Write string to the IIC."""
  215. def writeBytes(self, addr: int, data: bytes, length: int):
  216. """Write bytes to the IIC."""
  217. def read(self, addr: int, length: int) -> str:
  218. """Read string from the IIC."""
  219. def readBytes(self, addr: int, length: int) -> bytes:
  220. """Read bytes from the IIC."""
  221. class PWM(BaseDev):
  222. def __init__(self): ...
  223. def setName(self, name: str):
  224. """Use the device name to select the PWM pin.
  225. exmpale: `"PWM0"`, `"PWM1"` ...
  226. """
  227. def getName(self) -> str:
  228. """Get the device name."""
  229. def setChannel(self, ch: int):
  230. """Set the channel."""
  231. def getChannel(self) -> int:
  232. """Get the channel."""
  233. def setPin(self, pin: str):
  234. """Use the name of the pin to select the PWM pin.
  235. example: `"PA0"`, `"PA1"` ...
  236. """
  237. def setFrequency(self, freq: int):
  238. """Set the frequency."""
  239. def setFreq(self, freq: int):
  240. """Set the frequency."""
  241. def setDuty(self, duty: float):
  242. """Set the duty."""
  243. def enable(self):
  244. """Enable the PWM."""
  245. def disable(self):
  246. """Disable the PWM."""
  247. def getFrequency(self) -> int:
  248. """Get the frequency."""
  249. def getDuty(self) -> float:
  250. """Get the duty."""
  251. def close(self): ...
  252. class SPI(BaseDev):
  253. def __init__(self): ...
  254. def setPinSCK(self, pin: str):
  255. """Set the SCK pin."""
  256. def setPinMOSI(self, pin: str):
  257. """Set the MOSI pin."""
  258. def setPinMISO(self, pin: str):
  259. """Set the MISO pin."""
  260. def setPinCS(self, pin: str):
  261. """Set the CS pin."""
  262. def setName(self, name: str):
  263. """Use the device name to select the SPI pin.
  264. exmpale: `"SPI0"`, `"SPI1"` ...
  265. """
  266. def setId(self, id: int):
  267. """Set the id of the SPI.
  268. example: `0`, `1` ...
  269. """
  270. def setPolarity(self, polarity: int):
  271. """Set the polarity."""
  272. def setPhase(self, phase: int):
  273. """Set the phase."""
  274. def setBaudRate(self, baudRate: int):
  275. """Set the baud rate."""
  276. def enable(self):
  277. """Enable the SPI."""
  278. def disable(self):
  279. """Disable the SPI."""
  280. def write(self, data: str):
  281. """Write string to the SPI."""
  282. def writeBytes(self, data: bytes, length: int):
  283. """Write bytes to the SPI."""
  284. def read(self, length: int) -> str:
  285. """Read string from the SPI."""
  286. def readBytes(self, length: int) -> bytes:
  287. """Read bytes from the SPI."""
  288. class CAN(BaseDev):
  289. def __init__(self): ...
  290. def setName(self, name: str):
  291. """Use the device name to select the CAN pin.
  292. exmpale: `"CAN0"`, `"CAN1"` ...
  293. """
  294. def setId(self, id: int):
  295. """Use the id to select the CAN pin.
  296. example: `0`, `1` ...
  297. """
  298. def setBaudRate(self, baudRate: int):
  299. """Set the baud rate."""
  300. def setMode(self, mode: str):
  301. """Set the mode.
  302. example: `"normal"`, `"loopback"`, `"silent"`, `"silent_loopback"`
  303. """
  304. def enable(self):
  305. """Enable the CAN."""
  306. def disable(self):
  307. """Disable the CAN."""
  308. def write(self, data: str):
  309. """Write string to the CAN."""
  310. def writeBytes(self, data: bytes, length: int):
  311. """Write bytes to the CAN."""
  312. def read(self, length: int) -> str:
  313. """Read string from the CAN."""
  314. def readBytes(self, length: int) -> bytes:
  315. """Read bytes from the CAN."""
  316. def addFilter(self, id: int, ide: int, rtr: int, mode: int, mask: int, hdr: int):
  317. """Add a filter."""
  318. class BaseDev:
  319. @PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
  320. def addEventCallback(self, eventCallback: any):
  321. """ Add an event callback. """
  322. def addEventCallBack(self, eventCallback: any):
  323. """ deprecated, use addEventCallback instead. """
  324. @abstractmethod
  325. @PIKA_C_MACRO_IF("PIKA_EVENT_ENABLE")
  326. def platformGetEventId(self): ...