Skip to content
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

Fix notify display for SPI1 w/ 36 MHz clock (VGA hires mode) #46

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions inc/stm32f10x_regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions inc/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
85 changes: 75 additions & 10 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -665,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();
}
Expand Down Expand Up @@ -727,6 +782,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;
Expand Down Expand Up @@ -754,6 +814,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;
Expand Down