ext-led · Drivers
The led_drivers registry
ext-led owns the led_drivers registry. A chip package registers a descriptor into it, and each descriptor becomes a PHP class under Baremetal\Led\Driver.
ext-led declares one registry in its composer.json:
{
"module": "led",
"priority": 100,
"registries": {
"led_drivers": { "type": "led_driver_desc_t", "header": "led_driver_desc.h" }
}
}
A chip package registers into it by naming its descriptor symbol:
{ "register": { "led_drivers": ["ws2812_driver_desc"] } }
What happens at build and startup
-
The build collects the entries
The SDK driver generates a table from every package in the project that registers into
led_drivers, ordered by package and then symbol, NULL-terminated, with a count. With no chip package installed the table is empty and ext-led still builds. -
ext-led registers the classes
At module startup, for each descriptor ext-led registers
Baremetal\Led\Driver\<php_class>as a subclass ofBaremetal\Led\Device, with the descriptor's method table, and declares the order constantsGRBandRGBon it, plusGRBWandRGBWwhen the descriptor has 4 channels. -
PHP uses the class
new Ws2812($pin, $count)creates the strip with the descriptor's LED model, channel count and default order, then clears it (not while serving an HTTP request).
So a project gets a chip class just by requiring the chip package. Classes of chips that are not installed do
not exist; class_exists(Baremetal\Led\Driver\Ws2812::class) tells at runtime.
Drivers available today
| Package | Class | LED model | Channels | Default order |
|---|---|---|---|---|
| led-ws2812 | Ws2812 |
WS2812 | 3 | GRB |
| led-sk6812 | Sk6812 |
SK6812 | 4 | GRBW |
Both constructors are (int $pin, int $count = 1, ?int $order = null), and both classes have every Device
method.
Rules the build enforces
- Only ext-led may declare
led_drivers; a second package declaring it is a build error. - A symbol registered twice, an invalid C name, or a registry that no installed package declares is a build error that names the package.
- The header
led_driver_desc.hcomes from ext-led'sinclude/, so a driver needs no include path of its own.
Related
- Writing a driver Drivers
- led-ws2812 Driver
- led-sk6812 Driver