Skip to content

Commit

Permalink
lib: add SPI aliases (use HSPI in S3)
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Feb 9, 2024
1 parent 486c092 commit 9b9ea86
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 30 deletions.
32 changes: 4 additions & 28 deletions firmware-demo/src/nes/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,18 @@ extern "C" void display_init() {
}

extern "C" void display_write_frame(const uint8_t *data[]) {
// nofrendo_log_printf("display_write_frame\n");
// gfx->fillScreen(gfx->color565(0, 0, 255));
// gfx->drawPixel(120, 140, gfx->color565(255, 255, 255));
// Arduino_TFT *gfx = lilka_display_get();

last_frame_duration = micros() - last_render;
last_render = micros();

// gfx->drawLine(0, 0, 280, 240, gfx->color565(255, 0, 0));
// bus = new Arduino_ESP32SPI(3 /* DC */, 21 /* CS */, 0 /* SCK */, 1 /* MOSI */, -1);
lilka::display.startWrite();
if (w < 480) {
// for (int32_t y = 0; y < frame_height; y++)
// {
// for (int32_t x = 0; x < frame_line_pixels; x++)
// {
// // uint8_t index = (data[y][x + frame_x_offset]);
// // gfx->writeColor(myPalette[index], 1);
// // gfx->writePixel(x + frame_x, y + frame_y, myPalette[index]);
// nofrendo_log_printf("x: %d, y: %d\n", x, y);
// gfx->writePixel(x + 32, y + 32, rand() % 65536);
// }
// }
lilka::display.writeAddrWindow(frame_x, frame_y, frame_width, frame_height);
// nofrendo_log_printf("Start\n");
for (int32_t i = 0; i < NES_SCREEN_HEIGHT; i++) {
// nofrendo_log_printf("line %d of %d: \n", i, NES_SCREEN_HEIGHT);
lilka::display.writeIndexedPixels((uint8_t *)(data[i] + frame_x_offset), myPalette, frame_line_pixels);
}
// nofrendo_log_printf("End\n");
lilka::display.writeAddrWindow(frame_x, frame_y, frame_width, frame_height);
// nofrendo_log_printf("Start\n");
for (int32_t i = 0; i < NES_SCREEN_HEIGHT; i++) {
lilka::display.writeIndexedPixels((uint8_t *)(data[i] + frame_x_offset), myPalette, frame_line_pixels);
}
// gfx->endWrite();
lilka::display.endWrite();
if (last_frame_duration > 0) {
lilka::display.fillRect(80, LILKA_DISPLAY_HEIGHT - 20, 80, 20, lilka::display.color565(0, 0, 0));
// gfx->fillRect(0, 0, LILKA_DISPLAY_WIDTH, LILKA_DISPLAY_HEIGHT, gfx->color565(255, 0, 0));
lilka::display.setCursor(80, LILKA_DISPLAY_HEIGHT - 4);
lilka::display.setTextSize(1);
lilka::display.setTextColor(lilka::display.color565(128, 128, 128));
Expand Down
3 changes: 2 additions & 1 deletion lib/lilka/src/lilka/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

#include "splash.h"

#include "spi.h"
#include "serial.h"

namespace lilka {

Arduino_HWSPI displayBus(LILKA_DISPLAY_DC, LILKA_DISPLAY_CS, LILKA_SPI_SCK, LILKA_SPI_MOSI, LILKA_SPI_MISO);
Arduino_ESP32SPI displayBus(LILKA_DISPLAY_DC, LILKA_DISPLAY_CS, LILKA_SPI_SCK, LILKA_SPI_MOSI, LILKA_SPI_MISO, SPI1_NUM);

Display::Display() : Arduino_ST7789(&displayBus, LILKA_DISPLAY_RST, LILKA_DISPLAY_ROTATION, true, LILKA_DISPLAY_WIDTH, LILKA_DISPLAY_HEIGHT, 0, 20) {}

Expand Down
3 changes: 2 additions & 1 deletion lib/lilka/src/lilka/sdcard.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "sdcard.h"

#include "serial.h"
#include "spi.h"

#define LILKA_SDROOT "/sd"

Expand All @@ -16,7 +17,7 @@ void SDCard::begin() {
#if LILKA_SDCARD_CS < 0
serial_err("SD init failed: no CS pin");
#else
fs->begin(LILKA_SDCARD_CS, SPI, 1000000, LILKA_SDROOT);
fs->begin(LILKA_SDCARD_CS, SPI1, 1000000, LILKA_SDROOT);
sdcard_type_t cardType = fs->cardType();

if (cardType == CARD_NONE) {
Expand Down
6 changes: 6 additions & 0 deletions lib/lilka/src/lilka/spi.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "spi.h"

SPIClass SPI1(SPI1_NUM);
#ifdef SPI2_NUM
SPIClass SPI2(SPI2_NUM);
#endif
23 changes: 23 additions & 0 deletions lib/lilka/src/lilka/spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef LILKA_SPI_H
#define LILKA_SPI_H

#include <SPI.h>

#if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
# define SPI1_NUM HSPI
# define SPI2_NUM FSPI
extern SPIClass SPI1;
extern SPIClass SPI2;
#elif CONFIG_IDF_TARGET_ESP32C3
# define SPI1_NUM FSPI
extern SPIClass SPI1;
#endif

// #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
// #define VSPI FSPI
// #endif
//
// SPIClass SPI1(VSPI);
// SPIClass SPI2(HSPI);

#endif // LILKA_SPI_H
2 changes: 2 additions & 0 deletions lib/lilka/src/lilka/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "lilka/display.h"
#include "lilka/controller.h"

#include "serial.h"

namespace lilka {

int ui_menu(String title, String menu[], int menu_size, int cursor, const menu_icon_t *icons[]) {
Expand Down

0 comments on commit 9b9ea86

Please sign in to comment.