Skip to content

Commit 73370fa

Browse files
committed
[automotive] Refactor build and create a legacy driver lib
1 parent e41b363 commit 73370fa

22 files changed

Lines changed: 407 additions & 616 deletions

File tree

examples/automotive/cheri/send.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ void lcd_display_cheri_message()
196196
* The remaining variable arguments are unsigned integers used to fill
197197
* in the formatting specifiers in the format string.
198198
*/
199-
void lcd_draw_str(uint32_t x,
199+
void lcd_draw_str(void *handle,
200+
uint32_t x,
200201
uint32_t y,
201202
LcdFont font,
202203
const char *format,
@@ -233,7 +234,7 @@ void lcd_draw_str(uint32_t x,
233234
*
234235
* `color` is the 32-bit colour to display.
235236
*/
236-
void lcd_clean(uint32_t color)
237+
void lcd_clean(void *handle, uint32_t color)
237238
{
238239
lcd->clean(static_cast<Color>(color));
239240
}
@@ -247,7 +248,8 @@ void lcd_clean(uint32_t color)
247248
* `h` is the height of the rectangle.
248249
* `color` is the 32-bit colour to fill the rectangle with.
249250
*/
250-
void lcd_fill_rect(uint32_t x,
251+
void lcd_fill_rect(void *handle,
252+
uint32_t x,
251253
uint32_t y,
252254
uint32_t w,
253255
uint32_t h,
@@ -267,7 +269,8 @@ void lcd_fill_rect(uint32_t x,
267269
* `data` is the byte array containing the image data, of size at least
268270
* of `w` * `h`, where each value is a RGB565 colour value.
269271
*/
270-
void lcd_draw_img(uint32_t x,
272+
void lcd_draw_img(void *handle,
273+
uint32_t x,
271274
uint32_t y,
272275
uint32_t w,
273276
uint32_t h,
@@ -545,6 +548,7 @@ void __cheri_compartment("automotive_send") entry()
545548
.ethernet_transmit = send_ethernet_frame,
546549
.lcd =
547550
{
551+
lcd = lcd,
548552
.draw_str = lcd_draw_str,
549553
.clean = lcd_clean,
550554
.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: 16 additions & 111 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
@@ -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)