-
Notifications
You must be signed in to change notification settings - Fork 16
[automotive] Update the legacy drivers to align with hardware #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
engdoreis
wants to merge
3
commits into
lowRISC:main
Choose a base branch
from
engdoreis:hackday
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -8,24 +8,25 @@ | |
| #include <stdint.h> | ||
| #include <stdio.h> | ||
|
|
||
| #include "../../../third_party/display_drivers/src/core/lucida_console_10pt.h" | ||
| #include "../../../third_party/display_drivers/src/core/lucida_console_12pt.h" | ||
| #include "../../../third_party/display_drivers/src/core/m3x6_16pt.h" | ||
| #include "../../../third_party/display_drivers/src/st7735/lcd_st7735.h" | ||
| #include "../../../third_party/sonata-system/sw/legacy/common/gpio.h" | ||
| #include "../../../third_party/sonata-system/sw/legacy/common/rv_plic.h" | ||
| #include "../../../third_party/sonata-system/sw/legacy/common/sonata_system.h" | ||
| #include "../../../third_party/sonata-system/sw/legacy/common/spi.h" | ||
| #include "../../../third_party/sonata-system/sw/legacy/common/timer.h" | ||
| #include "../lib/analogue_pedal.h" | ||
| #include "../lib/automotive_common.h" | ||
| #include "../lib/automotive_menu.h" | ||
| #include "../lib/digital_pedal.h" | ||
| #include "../lib/joystick_pedal.h" | ||
| #include "../lib/no_pedal.h" | ||
| #include "adc.h" | ||
| #include "gpio.h" | ||
| #include "ksz8851.h" | ||
| #include "lcd.h" | ||
| #include "lcd_st7735.h" | ||
| #include "lucida_console_10pt.h" | ||
| #include "lucida_console_12pt.h" | ||
| #include "m3x6_16pt.h" | ||
| #include "pwm.h" | ||
| #include "rv_plic.h" | ||
| #include "sonata_system.h" | ||
| #include "spi.h" | ||
| #include "timer.h" | ||
|
|
||
| // When using our model pedal, these are the maximum and minimum values that | ||
| // are measured through the ADC from the pedal's full range of motion. We | ||
|
|
@@ -34,8 +35,8 @@ | |
| #define PEDAL_MIN_ANALOGUE 310 | ||
| #define PEDAL_MAX_ANALOGUE 1700 | ||
|
|
||
| #define BACKGROUND_COLOUR ColorBlack | ||
| #define TEXT_COLOUR ColorWhite | ||
| #define BACKGROUND_COLOUR RGBColorBlack | ||
| #define TEXT_COLOUR RGBColorWhite | ||
|
|
||
| #define ADC_BASE 0x8000B000 | ||
|
|
||
|
|
@@ -85,104 +86,6 @@ uint64_t wait(const uint64_t EndTime) | |
| return currentTime; | ||
| } | ||
|
|
||
| /** | ||
| * Formats and draws a string to the LCD display based upon the provided | ||
| * formatting and display information. The string can use formatting | ||
| * specifiers as defined by `vsnprintf(3)`. | ||
| * | ||
| * `x` is the X-coordinate on the LCD of the top left of the string. | ||
| * `y` is the Y-coordinate on the LCD of the top left of the string. | ||
| * `font` is the font to render the string with. | ||
| * `format` is the formatting string to write. | ||
| * `backgroundColour` is the colour to use for the string's background. | ||
| * `textColour` is the colour to render the text in. | ||
| * The remaining variable arguments are unsigned integers used to fill in the | ||
| * formatiting specifiers in the format string. | ||
| */ | ||
| void lcd_draw_str(uint32_t x, | ||
| uint32_t y, | ||
| LcdFont font, | ||
| const char *format, | ||
| uint32_t backgroundColour, | ||
| uint32_t textColour, | ||
| ...) | ||
| { | ||
| // Format the provided string | ||
| char buffer[1024]; | ||
| va_list args; | ||
| va_start(args, textColour); | ||
| vsnprintf(buffer, 1024, format, args); | ||
| va_end(args); | ||
|
|
||
| Font stringFont; | ||
| switch (font) | ||
| { | ||
| case LucidaConsole_10pt: | ||
| stringFont = lucidaConsole_10ptFont; | ||
| break; | ||
| case LucidaConsole_12pt: | ||
| stringFont = lucidaConsole_12ptFont; | ||
| break; | ||
| default: | ||
| stringFont = m3x6_16ptFont; | ||
| } | ||
| lcd_st7735_set_font(&lcd, &stringFont); | ||
| lcd_st7735_set_font_colors(&lcd, backgroundColour, textColour); | ||
| lcd_st7735_puts(&lcd, (LCD_Point){x, y}, buffer); | ||
| } | ||
|
|
||
| /** | ||
| * A callback function used to clean the LCD display with a given colour. | ||
| * | ||
| * `color` is the 32-bit colour to display. | ||
| */ | ||
| void lcd_clean(uint32_t color) | ||
| { | ||
| size_t w, h; | ||
| lcd_st7735_get_resolution(&lcd, &h, &w); | ||
| LCD_rectangle rect = {(LCD_Point){0, 0}, w, h}; | ||
| lcd_st7735_fill_rectangle(&lcd, rect, color); | ||
| } | ||
|
|
||
| /** | ||
| * A callback function used to draw a rectangle on the LCD. | ||
| * | ||
| * `x` is the X-position of the top-left corner of the rectangle on the LCD. | ||
| * `y` is the Y-position of the top-left corner of the rectangle on the LCD. | ||
| * `w` is the width of the rectangle. | ||
| * `h` is the height of the rectangle. | ||
| * `color` is the 32-bit colour to fill the rectangle with. | ||
| */ | ||
| void lcd_fill_rect(uint32_t x, | ||
| uint32_t y, | ||
| uint32_t w, | ||
| uint32_t h, | ||
| uint32_t color) | ||
| { | ||
| LCD_rectangle rect = {(LCD_Point){x, y}, w, h}; | ||
| lcd_st7735_fill_rectangle(&lcd, rect, color); | ||
| } | ||
|
|
||
| /** | ||
| * A callback function used to draw an image to the LCD. | ||
| * | ||
| * `x` is the X-position of the top-left corner of the image on the LCD. | ||
| * `y` is the Y-position of the top-left corner of the image on the LCD. | ||
| * `w` is the width of the image. | ||
| * `h` is the height of the image. | ||
| * `data` is the byte array containing the image data, of size at least | ||
| * of `w` * `h`, where each value is a RGB565 colour value. | ||
| */ | ||
| void lcd_draw_img(uint32_t x, | ||
| uint32_t y, | ||
| uint32_t w, | ||
| uint32_t h, | ||
| const uint8_t *data) | ||
| { | ||
| LCD_rectangle rect = {(LCD_Point){x, y}, w, h}; | ||
| lcd_st7735_draw_rgb565(&lcd, rect, data); | ||
| } | ||
|
|
||
| /** | ||
| * A callback function used to read the GPIO joystick state. | ||
| * | ||
|
|
@@ -191,7 +94,7 @@ void lcd_draw_img(uint32_t x, | |
| */ | ||
| uint8_t read_joystick() | ||
| { | ||
| return ((uint8_t)read_gpio(GPIO_IN_DBNC_AM)) & 0x1f; | ||
| return ((uint8_t)(read_gpio(GPIO_IN_DBNC_AM) >> 8u) & 0x1f); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -361,37 +264,44 @@ int main() | |
| timer_init(); | ||
| timer_enable(SYSCLK_FREQ / 1000); | ||
|
|
||
| pwm_t lcd_bl = PWM_FROM_ADDR_AND_INDEX(PWM_BASE, PWM_LCD); | ||
|
|
||
| // Initialise LCD display driver | ||
| LCD_Interface lcdInterface; | ||
| spi_t lcdSpi; | ||
| spi_init(&lcdSpi, LCD_SPI, LcdSpiSpeedHz); | ||
| lcd_init(&lcdSpi, &lcd, &lcdInterface); | ||
| lcd_clean(BACKGROUND_COLOUR); | ||
| lcd_init(&lcdSpi, lcd_bl, &lcd, &lcdInterface); | ||
| lcd_clean(&lcd, BACKGROUND_COLOUR); | ||
| const LCD_Point Centre = {lcd.parent.width / 2, lcd.parent.height / 2}; | ||
| write_to_uart("%s:%d\n", __func__, __LINE__); | ||
|
|
||
| // Initialise Ethernet support for use via callback | ||
| rv_plic_init(); | ||
| spi_t ethernetSpi; | ||
| spi_init(ðernetSpi, ETH_SPI, /*speed=*/0); | ||
| spi_init(ðernetSpi, ETH_SPI, 1 * 1000 * 1000); | ||
| ethernetInterface.spi = ðernetSpi; | ||
| uint8_t macSource[6]; | ||
| for (uint8_t i = 0; i < 6; i++) | ||
| { | ||
| macSource[i] = FixedDemoHeader.macSource[i]; | ||
| } | ||
| write_to_uart("%s:%d\n", __func__, __LINE__); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove debug logs? (several times in this file) |
||
| ksz8851_init(ðernetInterface, macSource); | ||
| write_to_uart("%s:%d\n", __func__, __LINE__); | ||
|
|
||
| // Wait until a good physical ethernet link to start the demo | ||
| if (!ksz8851_get_phy_status(ðernetInterface)) | ||
| { | ||
| write_to_uart("Waiting for a good physical ethernet link...\n"); | ||
| lcd_draw_str(Centre.x - 55, | ||
| lcd_draw_str(&lcd, | ||
| Centre.x - 55, | ||
| Centre.y - 5, | ||
| M3x6_16pt, | ||
| "Waiting for a good physical", | ||
| BACKGROUND_COLOUR, | ||
| TEXT_COLOUR); | ||
| lcd_draw_str(Centre.x - 30, | ||
| lcd_draw_str(&lcd, | ||
| Centre.x - 30, | ||
| Centre.y + 5, | ||
| M3x6_16pt, | ||
| "ethernet link...", | ||
|
|
@@ -425,6 +335,7 @@ int main() | |
| .ethernet_transmit = send_ethernet_frame, | ||
| .lcd = | ||
| { | ||
| .lcd = &lcd, | ||
| .draw_str = lcd_draw_str, | ||
| .clean = lcd_clean, | ||
| .fill_rect = lcd_fill_rect, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.