Skip to content

Commit

Permalink
get slash screen running
Browse files Browse the repository at this point in the history
  • Loading branch information
hathach committed Jan 5, 2024
1 parent 79add7b commit a6a8962
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
48 changes: 21 additions & 27 deletions src/boards/boards.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static inline void tft_dc(bool state) {
}
}

static void tft_cmd(uint8_t cmd, uint8_t const* data, uint8_t narg) {
static void tft_cmd(uint8_t cmd, uint8_t const* data, size_t narg) {
tft_cs(false);

// send command
Expand Down Expand Up @@ -269,34 +269,20 @@ void board_display_teardown(void) {
nrf_spim_disable(_spim);
}

// Send the whole buffer data to display controller
extern const uint16_t color_palette[];
void board_display_draw_screen(uint8_t const* fb) {
void board_display_draw_line(uint16_t y, uint8_t const* buf, size_t nbytes) {
// column and row address set
uint32_t xa32 = DISPLAY_COL_OFFSET << 16 | DISPLAY_WIDTH;
xa32 = __builtin_bswap32(xa32);

tft_cs(false);

// command: memory write
uint8_t cmd = 0x2C;
tft_dc(false);
spi_write(_spim, &cmd, 1);
y += DISPLAY_ROW_OFFSET;
uint32_t ya32 = (y << 16) | (y + 1);
ya32 = __builtin_bswap32(ya32);

// data
tft_dc(true);

uint8_t const* p = fb;
for (int i = 0; i < DISPLAY_WIDTH; ++i) {
uint8_t cc[DISPLAY_HEIGHT * 2];
uint32_t dst = 0;
for (int j = 0; j < DISPLAY_HEIGHT; ++j) {
uint16_t color = color_palette[*p++ & 0xf];
cc[dst++] = color >> 8;
cc[dst++] = color & 0xff;
}
tft_cmd(0x2A, (uint8_t*) &xa32, 4);
tft_cmd(0x2B, (uint8_t*) &ya32, 4);

spi_write(_spim, cc, sizeof(cc));
}

tft_cs(true);
// command: memory write
tft_cmd(0x2C, buf, nbytes);
}

#endif
Expand Down Expand Up @@ -681,6 +667,14 @@ void neopixel_write (uint8_t *pixels) {
}
#endif

#define TFT_MADCTL_MY 0x80 ///< Page addr order: Bottom to top
#define TFT_MADCTL_MX 0x40 ///< Column addr order: Right to left
#define TFT_MADCTL_MV 0x20 ///< Page/Column order: Reverse Mode ( X <-> Y )
#define TFT_MADCTL_ML 0x10 ///< LCD refresh Bottom to top
#define TFT_MADCTL_MH 0x04 ///< LCD refresh right to left
#define TFT_MADCTL_RGB 0x00 ///< Red-Green-Blue pixel order
#define TFT_MADCTL_BGR 0x08 ///< Blue-Green-Red pixel order

#ifdef DISPLAY_CONTROLLER_ST7789

#define ST_CMD_DELAY 0x80 // special signifier for command lists
Expand Down Expand Up @@ -742,7 +736,7 @@ static void tft_controller_init(void) {
// 3: Set color mode, 1 arg + delay: 16-bit color, 10 ms delay
ST77XX_COLMOD, 1 + ST_CMD_DELAY, 0x55, 10,
// 4: Mem access ctrl (directions), 1 arg: Row/col addr, bottom-top refresh
ST77XX_MADCTL, 1, 0x08,
ST77XX_MADCTL, 1, DISPLAY_MADCTL,
// 5: Column addr set, 4 args, no delay: XSTART = 0, XEND = 240
ST77XX_CASET, 4, 0x00, 0, 0, 240,
// 6: Row addr set, 4 args, no delay: YSTART = 0 YEND = 320
Expand Down
2 changes: 1 addition & 1 deletion src/boards/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ bool is_ota(void);
#ifdef DISPLAY_PIN_SCK
void board_display_init(void);
void board_display_teardown(void);
void board_display_draw_screen(uint8_t const* fb);
void board_display_draw_line(uint16_t y, uint8_t const* buf, size_t nbytes);
void screen_draw_drag(void);
#endif

Expand Down
19 changes: 17 additions & 2 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ enum {
};

// 16-bit 565 color from 24-bit 888 format
const uint16_t color_palette[] = {
const uint16_t palette[] = {
COL(0x000000), // 0
COL(0xffffff), // 1
COL(0xff2121), // 2
Expand Down Expand Up @@ -214,6 +214,21 @@ static void print4(int x, int y, int color, const char* text) {
//
//--------------------------------------------------------------------+

static void draw_screen(uint8_t const* fb) {
uint8_t const* p = fb;
for (int y = 0; y < DISPLAY_WIDTH; ++y) {
uint8_t cc[DISPLAY_HEIGHT * 2];
uint32_t dst = 0;
for (int x = 0; x < DISPLAY_HEIGHT; ++x) {
uint16_t color = palette[*p++ & 0xf];
cc[dst++] = color >> 8;
cc[dst++] = color & 0xff;
}

board_display_draw_line(y, cc, sizeof(cc));
}
}

// draw color bar
static void drawBar(int y, int h, int color) {
for (int x = 0; x < DISPLAY_WIDTH; ++x) {
Expand Down Expand Up @@ -245,7 +260,7 @@ void screen_draw_drag(void) {
print(10, DRAG - 12, COLOR_WHITE, "firmware.uf2");
print(90, DRAG - 12, COLOR_WHITE, UF2_VOLUME_LABEL);

board_display_draw_screen(frame_buf);
draw_screen(frame_buf);
}

#endif

0 comments on commit a6a8962

Please sign in to comment.