From 5c17777323375f0be05b2ddc325e985ba98af404 Mon Sep 17 00:00:00 2001 From: Torsten Kurbad Date: Mon, 3 Jan 2022 22:59:34 +0100 Subject: [PATCH 1/2] Fix notify display for SPI1 w/ 36 MHz clock (VGA hires mode) --- inc/stm32f10x_regs.h | 3 +++ src/main.c | 28 +++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/inc/stm32f10x_regs.h b/inc/stm32f10x_regs.h index c5c0206..5d9c84b 100644 --- a/inc/stm32f10x_regs.h +++ b/inc/stm32f10x_regs.h @@ -262,6 +262,9 @@ struct rcc { #define RCC_AHBRSTR_ETHMACRST (1u<<14) #define RCC_AHBRSTR_OTGFSRST (1u<<12) +#define RCC_APB1RSTR_SPI2RST (1u<< 14) +#define RCC_APB2RSTR_SPI1RST (1u<< 12) + #define RCC_BASE 0x40021000 /* Independent Watchdog */ diff --git a/src/main.c b/src/main.c index 11327a6..c076c67 100644 --- a/src/main.c +++ b/src/main.c @@ -626,11 +626,23 @@ static void update_amiga_keys(void) /* OSD On/Off. */ if ((del_pressed ^ amiga_key_pressed(AMI_DEL)) && (del_pressed ^= 1)) { + int row; osd_on ^= 1; - snprintf((char *)notify.text[0], sizeof(notify.text[0]), + memset(notify.text, 0, sizeof(notify.text)); + if ((running_display_timing == DISP_VGA) + && (startup_display_spi == DISP_SPI1)) { + row = 1; + notify.rows = 3; + notify.heights = 1u << row; /* Row index 1 -> double height */ + } else { + row = 0; + notify.rows = 1; + notify.heights = 0; + } + snprintf((char *)notify.text[row], sizeof(notify.text[row]), "OSD O%s", osd_on ? "n" : "ff"); - notify.cols = strlen((char *)notify.text[0]); - notify.rows = 1; + notify.cols = (row == 0) ? strlen((char *)notify.text[row]) + : sizeof(notify.text[row]); notify.on = TRUE; notify_time = time_now(); } @@ -727,6 +739,11 @@ void display_off(void) void setup_spi1(void) { + /* Reset SPI Port. */ + rcc->apb2rstr |= RCC_APB2RSTR_SPI1RST; + rcc->apb2rstr &= ~RCC_APB2RSTR_SPI1RST; + rcc->apb2enr |= RCC_APB2ENR_SPI1EN; + /* Configure SPI: 16-bit mode, MSB first, CPOL Low, CPHA Leading Edge. */ /* SPI1 is on APB2 which runs at 72MHz */ spi_display_spi1->cr2 = SPI_CR2_TXDMAEN; @@ -754,6 +771,11 @@ void setup_spi1(void) void setup_spi2(void) { + /* Reset SPI Port. */ + rcc->apb1rstr |= RCC_APB1RSTR_SPI2RST; + rcc->apb1rstr &= ~RCC_APB1RSTR_SPI2RST; + rcc->apb1enr |= RCC_APB1ENR_SPI2EN; + /* Configure SPI: 16-bit mode, MSB first, CPOL Low, CPHA Leading Edge. */ /* SPI2 is on APB1 which runs at 36MHz */ spi_display_spi2->cr2 = SPI_CR2_TXDMAEN; From 2af0da9ea5d14a555e1b2279542ec56f28016359 Mon Sep 17 00:00:00 2001 From: Torsten Kurbad Date: Tue, 4 Jan 2022 13:10:17 +0100 Subject: [PATCH 2/2] Ensure OSD size stays the same for hotkey output --- inc/util.h | 1 + src/main.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/inc/util.h b/inc/util.h index 51f488c..3d66a5a 100644 --- a/inc/util.h +++ b/inc/util.h @@ -46,6 +46,7 @@ void *memset(void *s, int c, size_t n); void *memcpy(void *dest, const void *src, size_t n); void *memmove(void *dest, const void *src, size_t n); +#define LEN(arr) ((int) (sizeof (arr) / sizeof (arr)[0])) size_t strlen(const char *s); size_t strnlen(const char *s, size_t maxlen); int strcmp(const char *s1, const char *s2); diff --git a/src/main.c b/src/main.c index c076c67..1f4c87e 100644 --- a/src/main.c +++ b/src/main.c @@ -677,15 +677,58 @@ static void update_amiga_keys(void) /* Hotkey is now pressed: Perform configured action. */ gpio_user->bsrr = ((uint32_t)r << 16) | s; if (*(p = hk->str)) { - notify.cols = notify.rows = 0; memset(notify.text, 0, sizeof(notify.text)); - while (*p) { - int len = strlen(p); - strcpy((char *)notify.text[notify.rows], p); - notify.cols = max(notify.cols, len); - notify.rows++; - p += len + 1; + if ((running_display_timing == DISP_VGA) + && (startup_display_spi == DISP_SPI1)) { + + /* In VGA mode, don't resize the OSD box. */ + char buf[LEN(notify.text)][LEN(notify.text[0])]; + int rows; + rows = 0; + memset(buf, '\0', sizeof(buf)); + while (*p) { + int len = strlen(p); + strcpy(buf[rows], p); + rows++; + p += len + 1; + } + notify.rows = rows; + switch (rows) { + case 1: + /* One line of text: Double height at second row. */ + strcpy((char *)notify.text[notify.rows], buf[--rows]); + notify.heights = 1u << notify.rows; + notify.rows = LEN(notify.text)-1; + break; + case 2: + /* Two lines of text: Normal height 2nd and 3rd row. */ + for (rows = 0; rows < notify.rows; rows++) + strcpy((char *)notify.text[rows+1], buf[rows]); + notify.heights = 0; + notify.rows = LEN(notify.text); + break; + default: + /* Three or four lines of text: Start from first row. */ + for (rows = 0; rows < notify.rows; rows++) + strcpy((char *)notify.text[rows], buf[rows]); + notify.heights = 0; + notify.rows = LEN(notify.text); + break; + } + /* Set notify.cols to maximum to retain the OSD size. */ + notify.cols = LEN(notify.text[0]); + } else { + /* 15 kHz mode or SPI2 output. */ + notify.cols = notify.rows = 0; + while (*p) { + int len = strlen(p); + strcpy((char *)notify.text[notify.rows], p); + notify.cols = max(notify.cols, len); + notify.rows++; + p += len + 1; + } } + notify.cols = max(notify.cols, LEN(notify.text[0])); notify.on = TRUE; notify_time = time_now(); }