CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
sdk
include
platform
sunburst
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
*/
9
enum class
SonataRgbLed
10
{
11
Led0 = 0,
12
Led1 = 1,
13
};
14
15
/**
16
* A driver for the Sonata's RGB LED Controller
17
*/
18
struct
SonataRgbLedController
:
private
utils::NoCopyNoMove
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
{
78
wait_for_idle
();
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
{
87
wait_for_idle
();
88
control
=
ControlSet
;
89
}
90
91
/// Switch all of the RGB LEDs off.
92
void
off
()
volatile
93
{
94
wait_for_idle
();
95
control
=
ControlOff
;
96
}
97
};
98
99
static_assert
(
sizeof
(
SonataRgbLedController
) == 16,
100
"The SonataRgbLedController structure is the wrong size."
);
utils::NoCopyNoMove
Utility class to delete copy and move contructors.
Definition
utils.hh:53
SonataRgbLedController
A driver for the Sonata's RGB LED Controller.
Definition
platform-rgbctrl.hh:19
SonataRgbLedController::ControlFields
ControlFields
Control Register Fields.
Definition
platform-rgbctrl.hh:38
SonataRgbLedController::ControlOff
@ ControlOff
Write 1 to turn off RGB LEDs.
Definition
platform-rgbctrl.hh:45
SonataRgbLedController::ControlSet
@ ControlSet
Write 1 to set RGB LEDs to specified colours.
Definition
platform-rgbctrl.hh:40
SonataRgbLedController::control
uint32_t control
Control Register.
Definition
platform-rgbctrl.hh:29
SonataRgbLedController::status
uint32_t status
Status Register See SonataRgbLedController::StatusFields for the fields.
Definition
platform-rgbctrl.hh:34
SonataRgbLedController::rgb
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.
Definition
platform-rgbctrl.hh:76
SonataRgbLedController::off
void off() volatile
Switch all of the RGB LEDs off.
Definition
platform-rgbctrl.hh:92
SonataRgbLedController::wait_for_idle
void wait_for_idle() volatile
Blocks until the controller is not busy.
Definition
platform-rgbctrl.hh:64
SonataRgbLedController::StatusFields
StatusFields
Status Register Fields.
Definition
platform-rgbctrl.hh:50
SonataRgbLedController::StatusIdle
@ StatusIdle
When asserted controller is idle and new colours can be set, otherwise writes to regLed0,...
Definition
platform-rgbctrl.hh:55
SonataRgbLedController::update
void update() volatile
Update the colours of the LEDs.
Definition
platform-rgbctrl.hh:85
SonataRgbLedController::ledColors
uint32_t ledColors[2]
Registers for setting the 8-bit red, green, and blue values for the two RGB Leds.
Definition
platform-rgbctrl.hh:24
utils.hh
Miscellaneous utility functions and classes.
Generated by
1.18.0