5.2. PikaStdDevice standard device
- Add PikaStdDevice dependency in requestment.txt.
What is a standard equipment module? Let’s start with other scripting technologies, such as MicroPython, there is no unified peripheral calling API, which makes users need to re-learn the API when using different platforms. For example, the following is the code for MicroPython to drive GPIO on the STM32F4 platform .
This is for ESP8266
It can be clearly seen that when selecting the pin of the pin, one uses a string, while the other uses an integer number. When controlling the level, one uses the , low()
methods, while the other uses the and low()
methods. An API standard driven by , off()
methods, in short, is confusing. Is there any way to unify the APIs of peripherals, so that users only need to be familiar with a set of APIs and can be used on any platform? There is a method, that is, the PikaStdDevice standard device driver module.
PikaStdDevice is an abstract device driver module that defines all user APIs. As long as the driver modules of each platform inherit from PikaStdDevice, they can obtain the same user API, and PikaStdDevice will indirectly call the platform driver and rewrite the underlying layer through polymorphism. The platform driver can work on different platforms.
The following are the platform drivers that PikaStdDevice needs to rewrite
And the GPIO module of CH32V103 we want to make is inherited from the standard driver module.
Through this method, we can make the STM32 driver module, CH32 driver module, and ESP32 driver module have the same user API. As long as users are familiar with a set of APIs, they can easily use all platforms that support the PikaScript standard driver module. The following are some of the C native driver functions that are registered in the driver module