Skip to content
php-baremetal REGISTRY
Publish a package

php-baremetal/led-sk6812

bm-lib MIT

SK6812 addressable RGBW LED driver for ext-led (Baremetal\Led\Driver\Sk6812).

bus: led

IDE stubs @ 1.1.0

The PHP declarations of the functions, classes and constants this package adds, with their docblocks, so PhpStorm and Intelephense can complete and type-check your firmware code.

You don't need to download them: on every composer install and composer update, conductor copies them into vendor/php-baremetal/ide-stubs/, which IDEs index without configuration. They are never loaded at runtime.

php ide/led-sk6812.stub
<?php
// php-baremetal/led-sk6812 1.1.0 — IDE helper, not loaded at runtime.

namespace Baremetal\Led\Driver {
    /**
     * A strip of SK6812 addressable LEDs: four channels (RGBW), GRBW byte order by default. Extends
     * Baremetal\Led\Device, which implements Baremetal\Output\Led.
     *
     * The buffer methods (pixel(), fill(), hsv(), set(), show(), off(), count()) and onboard() come from
     * Baremetal\Led\Device; they set red, green and blue, and the white channel is always written as 0. Use GRBW
     * (the default) or RGBW for RGBW chips, and GRB or RGB for SK6812 chips without a white LED.
     */
    class Sk6812 extends \Baremetal\Led\Device
    {
        /** Colour order on the wire: green, red, blue; three bytes per pixel. */
        public const GRB = 0;

        /** Colour order on the wire: red, green, blue; three bytes per pixel. */
        public const RGB = 1;

        /** Colour order on the wire: green, red, blue, white; four bytes per pixel (the default). */
        public const GRBW = 2;

        /** Colour order on the wire: red, green, blue, white; four bytes per pixel. */
        public const RGBW = 3;

        /**
         * Creates the strip on one data pin, then clears it: every pixel is sent as off.
         *
         * While serving an HTTP request (web-server runtime) the strip is not cleared, so the LEDs keep what the
         * previous request showed; the buffer starts at off either way. To replace a strip, set the old variable
         * to null first. A strip object cannot be cloned.
         *
         * @param int $pin GPIO number of the data line.
         * @param int $count Number of pixels, at least 1; 1 for a single on-board LED.
         * @param int|null $order Byte order on the wire, one of Sk6812::GRB, RGB, GRBW or RGBW; null uses GRBW.
         * @throws \ValueError "...: Argument #1 ($pin) must be a valid GPIO" for a negative $pin, "...: Argument #2
         *                     ($count) must be at least 1", or "...: Argument #3 ($order) must be one of the GRB,
         *                     RGB, GRBW, RGBW constants".
         * @throws \Exception "cannot init sk6812 on GPIO N" (the pin is not usable, no free transmit channel, or no
         *                    memory), "cannot init sk6812: GPIO N is already used by another LED strip", "cannot
         *                    init sk6812 on GPIO N: 16 LED strips are already open", or "LED refresh failed on
         *                    GPIO N (error E)".
         */
        public function __construct(int $pin, int $count = 1, ?int $order = null) {}
    }
}
Download led-sk6812.php