Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
nix build -L .?submodules=1#sonata-exercises
nix build -L .?submodules=1#sonata-examples
nix build -L .?submodules=1#sonata-automotive-demo-legacy-component
nix build -L .?submodules=1#sonata-heartbleed-demo-legacy-component
nix build -L .?submodules=1#sonata-tests

- name: Run Nix Checks
Expand Down
11 changes: 6 additions & 5 deletions examples/heartbleed/legacy/heartbleed.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include <gpio.h>
#include <lcd_st7735.h>
#include <m3x6_16pt.h>
#include <m5x7_16pt.h>
#include <pwm.h>
#include <sonata_system.h>
Expand All @@ -21,8 +20,8 @@

#define DEBUG_DEMO true
#define LENGTH_SCROLL_MILLIS 150u
#define BACKGROUND_COLOR BGRColorBlack
#define FOREGROUND_COLOR BGRColorWhite
#define BACKGROUND_COLOR RGBColorBlack
#define FOREGROUND_COLOR RGBColorWhite

// Define our own GPIO_IN_DBNC as the version from `sonata-system` uses void
// pointer arithmetic, which clang-tidy forbids.
Expand Down Expand Up @@ -233,8 +232,8 @@ void network_send(void *handle, const char *package, size_t len)
const uint32_t CharsPerLine = 29u;
St7735Context *lcd = (St7735Context *)handle;

const uint32_t TextAreaBgColor = BGRColorGrey;
const uint32_t TextAreaFgColor = BGRColorBlack;
const uint32_t TextAreaBgColor = RGBColorGrey;
const uint32_t TextAreaFgColor = RGBColorBlack;
// Clean the botton of the display.
lcd_fill_rect(
lcd, 0, 50, lcd->parent.width, lcd->parent.height - 50, TextAreaBgColor);
Expand Down Expand Up @@ -304,6 +303,8 @@ int main()
spi_init(&lcdSpi, LCD_SPI, LcdSpiSpeedHz);
lcd_init(&lcdSpi, lcd_bl, &lcd, &lcdInterface);
lcd_clean(&lcd, BACKGROUND_COLOR);
lcd_fill_rect(
&lcd, 0, 50, lcd.parent.width, lcd.parent.height - 50, RGBColorGrey);

size_t req_len = 8;
while (true)
Expand Down
10 changes: 7 additions & 3 deletions examples/heartbleed/legacy/lcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// pointer arithmetic, which clang-tidy forbids.
#define GPIO_OUT_LCD GPIO_FROM_BASE_ADDR((GPIO_BASE + GPIO_OUT_REG))

static void timer_delay(uint32_t ms)
static void timer_delay(void *handle, uint32_t ms)
{
uint32_t timeout = get_elapsed_time() + ms;
while (get_elapsed_time() < timeout)
Expand Down Expand Up @@ -55,7 +55,7 @@ int lcd_init(spi_t *spi,

// Reset the LCD
set_output_bit(GPIO_OUT_LCD, LcdRstPin, 0x0);
timer_delay(150);
timer_delay(NULL, 150);
set_output_bit(GPIO_OUT_LCD, LcdRstPin, 0x1);

// Init LCD Driver, and set the SPI driver
Expand All @@ -64,13 +64,14 @@ int lcd_init(spi_t *spi,
interface->gpio_write = gpio_write; // GPIO write callback.
interface->timer_delay = timer_delay; // Timer delay callback.
lcd_st7735_init(lcd, interface);
lcd_st7735_startup(lcd);

// Set the LCD orientation
lcd_st7735_set_orientation(lcd, LCD_Rotate180);

// Setup text font bitmaps to be used and the colors.
lcd_st7735_set_font(lcd, &m3x6_16ptFont);
lcd_st7735_set_font_colors(lcd, BGRColorWhite, BGRColorBlack);
lcd_st7735_set_font_colors(lcd, RGBColorWhite, RGBColorBlack);

// Clean display with a white rectangle.
lcd_st7735_clean(lcd);
Expand Down Expand Up @@ -104,6 +105,9 @@ void lcd_draw_str(St7735Context *lcd,
case LcdFontLucidaConsole_12pt:
stringFont = lucidaConsole_12ptFont;
break;
case LcdFontM5x7_16pt:
stringFont = m5x7_16ptFont;
break;
default:
stringFont = m3x6_16ptFont;
}
Expand Down
12 changes: 7 additions & 5 deletions examples/heartbleed/legacy/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ extern "C"

enum
{
BGRColorBlack = 0x000000,
BGRColorWhite = 0xFFFFFF,
BGRColorBlue = 0xFF0000,
BGRColorGreen = 0x00FF00,
BGRColorRed = 0x0000FF,
RGBColorBlack = 0x000000,
RGBColorWhite = 0xFFFFFF,
RGBColorBlue = 0xFF0000,
RGBColorGreen = 0x00FF00,
RGBColorRed = 0x0000FF,
RGBColorGrey = 0xAAAAAA,
};

// Fonts available for LCD rendering
typedef enum LcdFont
{
LcdFontM3x6_16pt, // NOLINT
LcdFontM5x7_16pt, // NOLINT
LcdFontLucidaConsole_10pt, // NOLINT
LcdFontLucidaConsole_12pt, // NOLINT
} LcdFont;
Expand Down
16 changes: 8 additions & 8 deletions examples/heartbleed/legacy/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,27 @@ set_toolchains("legacy-gcc")
-- Legacy-specific LCD library for using the display drivers
target("lcd_st7735_lib_am")
set_kind("static")
local lcd_dir = path.join(rootdir, "third_party/display_drivers")
local lcd_dir = path.join(rootdir, "third_party/display_drivers/src")
add_files(
path.join(lcd_dir, "core/lcd_base.c"),
path.join(lcd_dir, "core/lucida_console_10pt.c"),
path.join(lcd_dir, "core/lucida_console_12pt.c"),
path.join(lcd_dir, "core/m3x6_16pt.c"),
path.join(lcd_dir, "core/m5x7_16pt.c"),
path.join(lcd_dir, "st7735/lcd_st7735.c")
)

-- Heartbleed demo: Sending Firmware (non-CHERIoT version)
legacy_firmware("heartbleed_demo_legacy")
add_deps("lcd_st7735_lib_am")
add_includedirs(
"../../../third_party/display_drivers/core/",
"../../../third_party/display_drivers/st7735/",
"../../../third_party/sonata-system/sw/legacy/common/",
"../../../libraries/"
"../../../third_party/display_drivers/src/core/",
"../../../third_party/display_drivers/src/st7735/",
"../../../third_party/sonata-system/sw/legacy/common/"
)
add_ldflags("-specs=nosys.specs", {force = true})
add_files(
"../../../third_party/sonata-system/vendor/cheriot_debug_module/tb/prog/syscalls.c",
"../../../libraries/m5x7_16pt.c"
"../../../third_party/sonata-system/vendor/cheriot_debug_module/tb/prog/syscalls.c"
)
add_files("heartbleed.c", "../common.c", "lcd.c")
-- Keep the "-g3 -O0" flags as an example of a legacy flow that supports using a debugger
add_files("heartbleed.c", "../common.c", "lcd.c", {force = {cxflags = {"-g3", "-O0"}}})
16 changes: 16 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@
dontFixup = true;
};

sonata-heartbleed-demo-legacy-component = pkgs.stdenvNoCC.mkDerivation {
name = "sonata-heartbleed-demo-legacy-component";
src = fileset.toSource {
root = ./.;
fileset = fileset.unions [./examples/heartbleed ./common.lua ./third_party];
};
buildInputs = [pkgs.srecord] ++ (with lrPkgs; [xmake lowrisc-toolchain-gcc-rv32imcb uf2conv]);
buildPhase = "xmake -P ./examples/heartbleed/legacy/";
installPhase = ''
mkdir -p $out/share/
cp build/ilp32/rv32imc/release/heartbleed_demo_legacy $out/share
'';
dontFixup = true;
};

sonata-software-documentation = lrDoc.buildMdbookSite {
version = "";
pname = "sonata-software-documentation";
Expand Down Expand Up @@ -204,6 +219,7 @@
sonata-tests
sonata-software-documentation
sonata-automotive-demo-legacy-component
sonata-heartbleed-demo-legacy-component
;
};
checks = {inherit tests-simulator;};
Expand Down
Loading