capsules_extra

Module seven_segment

Source
Expand description

Provides userspace access to 7 segment digit displays.

This capsule was developed using the following components:

  • Microbit_v2
  • Edge Connector Breakout Board for Microbit (PPMB00126)
  • 7 segment display with 4 digits (3461BS-1)
  • breadboard, 220 ohms resistances and jump wires

§Usage

Example of use for a display with 4 digits and the Microbit: Microbit Pins: https://tech.microbit.org/hardware/schematic/ 4 digit 7 segment display pinout: https://www.dotnetlovers.com/images/4digit7segmentdisplay85202024001AM.jpg

const NUM_DIGITS: usize = 4;
const DIGITS: [Pin; 4] = [Pin::P1_02, Pin::P0_12, Pin::P0_30, Pin::P0_09]; // [D1, D2, D3, D4]
const SEGMENTS: [Pin; 7] = [
    Pin::P0_02, // A
    Pin::P0_03, // B
    Pin::P0_04, // C
    Pin::P0_31, // D
    Pin::P0_28, // E
    Pin::P0_10, // F
    Pin::P1_05, // G
];
const DOT: Pin = Pin::P0_11;

let segment_array = static_init!(
    [&'static nrf52::gpio::GPIOPin<'static>; 8],
    [
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[SEGMENTS[0]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[SEGMENTS[1]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[SEGMENTS[2]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[SEGMENTS[3]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[SEGMENTS[4]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[SEGMENTS[5]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[SEGMENTS[6]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[DOT]
        ),
    ]
);

let digit_array = static_init!(
    [&'static nrf52::gpio::GPIOPin<'static>; 4],
    [
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[DIGITS[0]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[DIGITS[1]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[DIGITS[2]]
        ),
        static_init!(
            &'static nrf52::gpio::GPIOPin<'static>,
            &nrf52833_peripherals.gpio_port[DIGITS[3]]
        ),
    ]
);

let buffer = static_init!([u8; 4], [0; 4]);

let digit_display = static_init!(
    capsules::digits::DigitsDriver<
        'static,
        nrf52::gpio::GPIOPin<'static>,
        capsules::virtual_alarm::VirtualMuxAlarm<'static, nrf52::rtc::Rtc<'static>>,
    >,
    capsules::digits::DigitsDriver::new(
        segment_array,
        digit_array,
        buffer,
        virtual_alarm_digit,
        kernel::hil::gpio::ActivationMode::ActiveLow,
        kernel::hil::gpio::ActivationMode::ActiveHigh,
        60
    ),
);

virtual_alarm_digit.set_alarm_client(digit_display);

digit_display.init();

§Syscall Interface

§Command

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

§command_num
  • 0: Driver Check.
    • data1: Unused.
    • data2: Unused.
    • Return: Number of digits.
  • 1: Prints one digit at the requested position.
    • data1: The position of the digit. Starts at 1.
    • data2: The digit to be represented, from 0 to 9.
    • Return: Ok(()) if the digit index was valid, INVAL otherwise.
  • 2: Clears all digits currently being displayed.
    • data1: Unused.
    • data2: Unused.
  • 3: Print a dot at the requested digit position.
    • data1: The position of the dot. Starts at 1.
    • Return: Ok(()) if the index was valid, INVAL otherwise.
  • 4: Print a custom pattern for a digit on a certain position.
    • data1: The position of the digit. Starts at 1.
    • data2: The custom pattern to be represented.
    • Return: Ok(()) if the index was valid, INVAL otherwise.
  • 5: Return the number of digits on the display being used.
    • data1: Unused.
    • data2: Unused.

Structs§

Constants§