Skip to content

Software drivers API #3453

Open
Open
@aykevl

Description

@aykevl

Some sensors and actuators need drivers written in C. Examples are: WS2812 (NeoPixel), APA102, DHT family, Dallas 1-wire protocol. There are probably many others. The protocols for these devices have tight timing requirements or have other requirements which make it difficult or impossible to implement them in Python.

On the ESP8266 these are implemented in the esp module and are not documented. Instead, most programming should be done using the relevant high-level Python wrapper classes.

Unfortunately, this makes these wrapper classes device dependent. It would be nice to make them universal. So here is a proposal for a drivers module. It can be named e.g. drivers or _drivers to indicate it's a low level API. The functions inside should be as minimal as possible, only exposing the bare minimum required in C.

_drivers.ws2812_write(pin, buffer) # may need flag for 800kHz/400kHz
_drivers.apa102_write(clock, data, buffer)
_drivers.dht_read(pin, buffer)

The pin in this case is a pin as defined in the machine module and the buffer can be anything following the buffer protocol (?), for example a bytearray or array.array. Note that I have used ws2812_write instead of neopixel_write as the latter is a brand name (from Adafruit) and the protocol is not constrained to these LED strips. Otherwise it is mostly identical to the functions found in the esp module.

Another consideration: what about bitbanged implementations of common peripherals like UART? These might be useful and possibly more suited for this module than the machine module. In case there is a desire to implement such protocols in software.

The motivation for this API is that I'm contributing to the nrf port of MicroPython and am wondering where to put these drivers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementFeature requests, new feature implementations

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions