capsules_core

Module led

Source
Expand description

Provides userspace access to LEDs on a board.

This allows for much more cross platform controlling of LEDs without having to know which of the GPIO pins exposed across the syscall interface are LEDs.

This capsule takes an array of pins and the polarity of the LED (active high or active low). This allows the board to configure how the underlying GPIO must be controlled to turn on and off LEDs, such that the syscall driver interface can be agnostic to the LED polarity.

§Usage


let led_pins = static_init!(
    [(&'static sam4l::gpio::GPIOPin, kernel::hil::gpio::ActivationMode); 3],
    [(&sam4l::gpio::PA[13], kernel::hil::gpio::ActivationMode::ActiveLow),   // Red
     (&sam4l::gpio::PA[15], kernel::hil::gpio::ActivationMode::ActiveLow),   // Green
     (&sam4l::gpio::PA[14], kernel::hil::gpio::ActivationMode::ActiveLow)]); // Blue
let led = static_init!(
    capsules_core::led::LED<'static, sam4l::gpio::GPIOPin>,
    capsules_core::led::LED::new(led_pins));

§Syscall Interface

  • Stability: 2 - Stable

§Command

All LED operations are synchronous, so this capsule only uses the command syscall.

§command_num
  • 0: Return the number of LEDs on this platform.
    • data: Unused.
    • Return: Number of LEDs.
  • 1: Turn the LED on.
    • data: The index of the LED. Starts at 0.
    • Return: Ok(()) if the LED index was valid, INVAL otherwise.
  • 2: Turn the LED off.
    • data: The index of the LED. Starts at 0.
    • Return: Ok(()) if the LED index was valid, INVAL otherwise.
  • 3: Toggle the on/off state of the LED.
    • data: The index of the LED. Starts at 0.
    • Return: Ok(()) if the LED index was valid, INVAL otherwise.

Structs§

  • Holds the array of LEDs and implements a Driver interface to control them.

Constants§