CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Loading...
Searching...
No Matches
platform-rgbctrl.hh
1#pragma once
2#include <cdefs.h>
3#include <stdint.h>
4#include <utils.hh>
5
6/**
7 * An enum representing each of the Sonata's RGB LEDs.
8 */
9enum class SonataRgbLed
10{
11 Led0 = 0,
12 Led1 = 1,
13};
14
15/**
16 * A driver for the Sonata's RGB LED Controller
17 */
19{
20 /**
21 * Registers for setting the 8-bit red, green, and blue values
22 * for the two RGB Leds.
23 */
24 uint32_t ledColors[2];
25 /**
26 * Control Register. See `SonataRgbLedController::ControlFields` for the
27 * fields.
28 */
29 uint32_t control;
30 /**
31 * Status Register See `SonataRgbLedController::StatusFields` for the
32 * fields.
33 */
34 uint32_t status;
35
36 /// Control Register Fields
37 enum [[clang::flag_enum]] ControlFields : uint32_t
38 {
39 /// Write 1 to set RGB LEDs to specified colours.
40 ControlSet = 1 << 0,
41 /**
42 * Write 1 to turn off RGB LEDs.
43 * Write to ControlSet to turn on again.
44 */
45 ControlOff = 1 << 1,
46 };
47
48 /// Status Register Fields
49 enum [[clang::flag_enum]] StatusFields : uint32_t
50 {
51 /**
52 * When asserted controller is idle and new colours can be set,
53 * otherwise writes to regLed0, regLed1, and control are ignored.
54 */
55 StatusIdle = 1 << 0,
56 };
57
58 /**
59 * Blocks until the controller is not busy.
60 *
61 * The controller can be busy when it is in the process of updating the
62 * LEDs. While busy, register writes will be ignored.
63 */
64 void wait_for_idle() volatile
65 {
66 while ((status & StatusIdle) == 0)
67 {
68 }
69 }
70
71 /**
72 * Set the desired Red, Green, and Blue value of an LED. To apply these
73 * changes, one needs to run `SonataRgbLedController::update()`.
74 */
75 void
76 rgb(SonataRgbLed led, uint8_t red, uint8_t green, uint8_t blue) volatile
77 {
79 ledColors[static_cast<uint32_t>(led)] =
80 (static_cast<uint32_t>(blue) << 16) |
81 (static_cast<uint32_t>(green) << 8) | static_cast<uint32_t>(red);
82 }
83
84 /// Update the colours of the LEDs.
85 void update() volatile
86 {
89 }
90
91 /// Switch all of the RGB LEDs off.
92 void off() volatile
93 {
96 }
97};
98
99static_assert(sizeof(SonataRgbLedController) == 16,
100 "The SonataRgbLedController structure is the wrong size.");
Utility class to delete copy and move contructors.
Definition utils.hh:53
A driver for the Sonata's RGB LED Controller.
ControlFields
Control Register Fields.
@ ControlOff
Write 1 to turn off RGB LEDs.
@ ControlSet
Write 1 to set RGB LEDs to specified colours.
uint32_t control
Control Register.
uint32_t status
Status Register See SonataRgbLedController::StatusFields for the fields.
void rgb(SonataRgbLed led, uint8_t red, uint8_t green, uint8_t blue) volatile
Set the desired Red, Green, and Blue value of an LED.
void off() volatile
Switch all of the RGB LEDs off.
void wait_for_idle() volatile
Blocks until the controller is not busy.
StatusFields
Status Register Fields.
@ StatusIdle
When asserted controller is idle and new colours can be set, otherwise writes to regLed0,...
void update() volatile
Update the colours of the LEDs.
uint32_t ledColors[2]
Registers for setting the 8-bit red, green, and blue values for the two RGB Leds.
Miscellaneous utility functions and classes.