-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve LCD test demo & Add RGB LED demo
This commit creates a new demo firmware target, `leds_and_lcd`, intended to do what the name implies - show the LEDs (GPIO & RGB LEDs) being used, and draw some stuff to the LCD. This updates the existing LCD test code to now print a "Running on Sonata" and "Protected by CHERI" message, with a little cherry bitmap. It also adds an additional compartment `rgbled_lerp` which just linearly interpolates between colours on the RGB LEDs to slowly cycle through different colours. Co-authored-by: Hugo McNally <[email protected]>
- Loading branch information
1 parent
3ec7e40
commit 2aa8838
Showing
4 changed files
with
121 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright lowRISC Contributors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
#include <compartment.h> | ||
#include <ctype.h> | ||
#include <platform-rgbctrl.hh> | ||
#include <thread.h> | ||
|
||
// The max brightness of the RGB LEDs | ||
static constexpr uint8_t MaxBrightness = 25; | ||
// The number of milliseconds per RGB LED update | ||
static constexpr uint32_t MsecPerUpdate = 150; | ||
|
||
[[noreturn]] void __cheri_compartment("rgbled_lerp") lerp_rgbleds() | ||
{ | ||
// Initialise the LED RGB driver. | ||
auto rgbled = MMIO_CAPABILITY(SonataRgbLedController, rgbled); | ||
|
||
bool increasing = true; | ||
uint8_t lerpT = 0; | ||
while (true) | ||
{ | ||
// Update the RGB values by linearly interpolating | ||
rgbled->rgb(SonataRgbLed::Led0, lerpT, MaxBrightness - lerpT, 0); | ||
rgbled->rgb(SonataRgbLed::Led1, 0, MaxBrightness - lerpT, lerpT); | ||
rgbled->update(); | ||
|
||
// Progress one timestep, increasing or decreasing the lerp variable. | ||
thread_millisecond_wait(MsecPerUpdate); | ||
if (increasing && lerpT == MaxBrightness) | ||
{ | ||
increasing = false; | ||
continue; | ||
} | ||
if (!increasing && lerpT == 0) | ||
{ | ||
increasing = true; | ||
continue; | ||
} | ||
lerpT = increasing ? ++lerpT : --lerpT; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters