Skip to content

Commit 68e8272

Browse files
committed
[automotive] Refactor build and create a legacy driver lib
1 parent 4f7fd0f commit 68e8272

22 files changed

Lines changed: 442 additions & 659 deletions

File tree

examples/automotive/cheri/send.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ void update_cheri_error_handling()
222222
* The remaining variable arguments are unsigned integers used to fill
223223
* in the formatting specifiers in the format string.
224224
*/
225-
void lcd_draw_str(uint32_t x,
225+
void lcd_draw_str(void *handle,
226+
uint32_t x,
226227
uint32_t y,
227228
LcdFont font,
228229
const char *format,
@@ -259,7 +260,7 @@ void lcd_draw_str(uint32_t x,
259260
*
260261
* `color` is the 32-bit colour to display.
261262
*/
262-
void lcd_clean(uint32_t color)
263+
void lcd_clean(void *handle, uint32_t color)
263264
{
264265
lcd->clean(static_cast<Color>(color));
265266
}
@@ -273,7 +274,8 @@ void lcd_clean(uint32_t color)
273274
* `h` is the height of the rectangle.
274275
* `color` is the 32-bit colour to fill the rectangle with.
275276
*/
276-
void lcd_fill_rect(uint32_t x,
277+
void lcd_fill_rect(void *handle,
278+
uint32_t x,
277279
uint32_t y,
278280
uint32_t w,
279281
uint32_t h,
@@ -293,7 +295,8 @@ void lcd_fill_rect(uint32_t x,
293295
* `data` is the byte array containing the image data, of size at least
294296
* of `w` * `h`, where each value is a RGB565 colour value.
295297
*/
296-
void lcd_draw_img(uint32_t x,
298+
void lcd_draw_img(void *handle,
299+
uint32_t x,
297300
uint32_t y,
298301
uint32_t w,
299302
uint32_t h,
@@ -571,6 +574,7 @@ void __cheri_compartment("automotive_send") entry()
571574
.ethernet_transmit = send_ethernet_frame,
572575
.lcd =
573576
{
577+
lcd = lcd,
574578
.draw_str = lcd_draw_str,
575579
.clean = lcd_clean,
576580
.fill_rect = lcd_fill_rect,

examples/automotive/legacy/lcd.c

Lines changed: 0 additions & 77 deletions
This file was deleted.

examples/automotive/legacy/lcd.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

examples/automotive/legacy/send.c

Lines changed: 18 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@
88
#include <stdint.h>
99
#include <stdio.h>
1010

11-
#include "../../../third_party/display_drivers/src/core/lucida_console_10pt.h"
12-
#include "../../../third_party/display_drivers/src/core/lucida_console_12pt.h"
13-
#include "../../../third_party/display_drivers/src/core/m3x6_16pt.h"
14-
#include "../../../third_party/display_drivers/src/st7735/lcd_st7735.h"
15-
#include "../../../third_party/sonata-system/sw/legacy/common/gpio.h"
16-
#include "../../../third_party/sonata-system/sw/legacy/common/pwm.h"
17-
#include "../../../third_party/sonata-system/sw/legacy/common/rv_plic.h"
18-
#include "../../../third_party/sonata-system/sw/legacy/common/sonata_system.h"
19-
#include "../../../third_party/sonata-system/sw/legacy/common/spi.h"
20-
#include "../../../third_party/sonata-system/sw/legacy/common/timer.h"
2111
#include "../lib/analogue_pedal.h"
2212
#include "../lib/automotive_common.h"
2313
#include "../lib/automotive_menu.h"
2414
#include "../lib/digital_pedal.h"
2515
#include "../lib/joystick_pedal.h"
2616
#include "../lib/no_pedal.h"
2717
#include "adc.h"
18+
#include "gpio.h"
2819
#include "ksz8851.h"
2920
#include "lcd.h"
21+
#include "lcd_st7735.h"
22+
#include "lucida_console_10pt.h"
23+
#include "lucida_console_12pt.h"
24+
#include "m3x6_16pt.h"
25+
#include "pwm.h"
26+
#include "rv_plic.h"
27+
#include "sonata_system.h"
28+
#include "spi.h"
29+
#include "timer.h"
3030

3131
// When using our model pedal, these are the maximum and minimum values that
3232
// are measured through the ADC from the pedal's full range of motion. We
@@ -35,8 +35,8 @@
3535
#define PEDAL_MIN_ANALOGUE 310
3636
#define PEDAL_MAX_ANALOGUE 1700
3737

38-
#define BACKGROUND_COLOUR ColorBlack
39-
#define TEXT_COLOUR ColorWhite
38+
#define BACKGROUND_COLOUR RGBColorBlack
39+
#define TEXT_COLOUR RGBColorWhite
4040

4141
#define ADC_BASE 0x8000B000
4242

@@ -86,104 +86,6 @@ uint64_t wait(const uint64_t EndTime)
8686
return currentTime;
8787
}
8888

89-
/**
90-
* Formats and draws a string to the LCD display based upon the provided
91-
* formatting and display information. The string can use formatting
92-
* specifiers as defined by `vsnprintf(3)`.
93-
*
94-
* `x` is the X-coordinate on the LCD of the top left of the string.
95-
* `y` is the Y-coordinate on the LCD of the top left of the string.
96-
* `font` is the font to render the string with.
97-
* `format` is the formatting string to write.
98-
* `backgroundColour` is the colour to use for the string's background.
99-
* `textColour` is the colour to render the text in.
100-
* The remaining variable arguments are unsigned integers used to fill in the
101-
* formatiting specifiers in the format string.
102-
*/
103-
void lcd_draw_str(uint32_t x,
104-
uint32_t y,
105-
LcdFont font,
106-
const char *format,
107-
uint32_t backgroundColour,
108-
uint32_t textColour,
109-
...)
110-
{
111-
// Format the provided string
112-
char buffer[1024];
113-
va_list args;
114-
va_start(args, textColour);
115-
vsnprintf(buffer, 1024, format, args);
116-
va_end(args);
117-
118-
Font stringFont;
119-
switch (font)
120-
{
121-
case LucidaConsole_10pt:
122-
stringFont = lucidaConsole_10ptFont;
123-
break;
124-
case LucidaConsole_12pt:
125-
stringFont = lucidaConsole_12ptFont;
126-
break;
127-
default:
128-
stringFont = m3x6_16ptFont;
129-
}
130-
lcd_st7735_set_font(&lcd, &stringFont);
131-
lcd_st7735_set_font_colors(&lcd, backgroundColour, textColour);
132-
lcd_st7735_puts(&lcd, (LCD_Point){x, y}, buffer);
133-
}
134-
135-
/**
136-
* A callback function used to clean the LCD display with a given colour.
137-
*
138-
* `color` is the 32-bit colour to display.
139-
*/
140-
void lcd_clean(uint32_t color)
141-
{
142-
size_t w, h;
143-
lcd_st7735_get_resolution(&lcd, &h, &w);
144-
LCD_rectangle rect = {(LCD_Point){0, 0}, w, h};
145-
lcd_st7735_fill_rectangle(&lcd, rect, color);
146-
}
147-
148-
/**
149-
* A callback function used to draw a rectangle on the LCD.
150-
*
151-
* `x` is the X-position of the top-left corner of the rectangle on the LCD.
152-
* `y` is the Y-position of the top-left corner of the rectangle on the LCD.
153-
* `w` is the width of the rectangle.
154-
* `h` is the height of the rectangle.
155-
* `color` is the 32-bit colour to fill the rectangle with.
156-
*/
157-
void lcd_fill_rect(uint32_t x,
158-
uint32_t y,
159-
uint32_t w,
160-
uint32_t h,
161-
uint32_t color)
162-
{
163-
LCD_rectangle rect = {(LCD_Point){x, y}, w, h};
164-
lcd_st7735_fill_rectangle(&lcd, rect, color);
165-
}
166-
167-
/**
168-
* A callback function used to draw an image to the LCD.
169-
*
170-
* `x` is the X-position of the top-left corner of the image on the LCD.
171-
* `y` is the Y-position of the top-left corner of the image on the LCD.
172-
* `w` is the width of the image.
173-
* `h` is the height of the image.
174-
* `data` is the byte array containing the image data, of size at least
175-
* of `w` * `h`, where each value is a RGB565 colour value.
176-
*/
177-
void lcd_draw_img(uint32_t x,
178-
uint32_t y,
179-
uint32_t w,
180-
uint32_t h,
181-
const uint8_t *data)
182-
{
183-
LCD_rectangle rect = {(LCD_Point){x, y}, w, h};
184-
lcd_st7735_draw_rgb565(&lcd, rect, data);
185-
}
186-
18789
/**
18890
* A callback function used to read the GPIO joystick state.
18991
*
@@ -369,7 +271,7 @@ int main()
369271
spi_t lcdSpi;
370272
spi_init(&lcdSpi, LCD_SPI, LcdSpiSpeedHz);
371273
lcd_init(&lcdSpi, lcd_bl, &lcd, &lcdInterface);
372-
lcd_clean(BACKGROUND_COLOUR);
274+
lcd_clean(&lcd, BACKGROUND_COLOUR);
373275
const LCD_Point Centre = {lcd.parent.width / 2, lcd.parent.height / 2};
374276
write_to_uart("%s:%d\n", __func__, __LINE__);
375277

@@ -391,13 +293,15 @@ int main()
391293
if (!ksz8851_get_phy_status(&ethernetInterface))
392294
{
393295
write_to_uart("Waiting for a good physical ethernet link...\n");
394-
lcd_draw_str(Centre.x - 55,
296+
lcd_draw_str(&lcd,
297+
Centre.x - 55,
395298
Centre.y - 5,
396299
M3x6_16pt,
397300
"Waiting for a good physical",
398301
BACKGROUND_COLOUR,
399302
TEXT_COLOUR);
400-
lcd_draw_str(Centre.x - 30,
303+
lcd_draw_str(&lcd,
304+
Centre.x - 30,
401305
Centre.y + 5,
402306
M3x6_16pt,
403307
"ethernet link...",
@@ -431,6 +335,7 @@ int main()
431335
.ethernet_transmit = send_ethernet_frame,
432336
.lcd =
433337
{
338+
.lcd = &lcd,
434339
.draw_str = lcd_draw_str,
435340
.clean = lcd_clean,
436341
.fill_rect = lcd_fill_rect,

0 commit comments

Comments
 (0)