Skip to content

Commit

Permalink
Add option for display output enable
Browse files Browse the repository at this point in the history
- like spi changes, a save+reset is needed to activate

Add option for double height display
- good for VGA on SPI2
  • Loading branch information
penfold42 committed Dec 8, 2019
1 parent 8ae4db2 commit 676ff1a
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
14 changes: 11 additions & 3 deletions inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
* See the file COPYING for more details, or visit <http://unlicense.org>.
*/

enum dispen { DISPCTL_tristate = 0, DISPCTL_enable_high, DISPCTL_enable_low, DISPCTL_MAX };
/* PB15 is tristate outside OSD; PA15 unused
* PA15 is Display Enable: Active HIGH
* PA15 is Display Enable: Active LOW */

extern struct __packed config {

uint16_t polarity;
Expand All @@ -27,11 +32,14 @@ extern struct __packed config {
#define DISP_SPI1 1
uint16_t display_spi;

#define DISPCTL_tristate 0 /* PB15 is tristate outside OSD; PA15 unused */
#define DISPCTL_enable_high 1 /* PA15 is Display Enable: Active HIGH */
#define DISPCTL_enable_low 2 /* PA15 is Display Enable: Active LOW */
/* dispen enum
* DISPCTL_tristate 0 PB15 is tristate outside OSD; PA15 unused
* DISPCTL_enable_high 1 PA15 is Display Enable: Active HIGH
* DISPCTL_enable_low 2 PA15 is Display Enable: Active LOW */
uint16_t dispctl_mode;

uint16_t display_2Y;

/* Mask of user-assigned pins configured in open-drain mode. */
uint8_t user_pin_opendrain;
/* Mask of user-assigned pins configured in push-pull mode. */
Expand Down
45 changes: 39 additions & 6 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ struct config config;

extern void setup_spi(void);

const static char *dispen_pretty[] = { "None", "PA15 Act.HIGH", "PA15 Act.LOW" };
/* PB15 is tristate outside OSD; PA15 unused
* PA15 is Display Enable: Active HIGH
* PA15 is Display Enable: Active LOW */

static void config_printk(const struct config *conf)
{
printk("\nCurrent config:\n");
printk(" Sync: Active %s\n", conf->polarity ? "HIGH" : "LOW");
printk(" Pixel Timing: %s\n", config.display_timing ? "VGA" : "15kHz");
printk(" Video Output: SPI%s\n", config.display_spi ? "1 (PA7)" : "2 (PB15)");
printk(" Output Enable: %d\n", config.dispctl_mode );
printk(" Display Height: %s\n", conf->display_2Y ? "Double" : "Normal");
printk(" Display Output: %s\n", config.display_spi ? "PA7/SPI1" : "PB15/SPI2");
printk(" Display Enable: %s\n", dispen_pretty[config.dispctl_mode] );
printk(" H.Off: %u\n", conf->h_off);
printk(" V.Off: %u\n", conf->v_off);
printk(" Rows: %u\n", conf->rows);
Expand Down Expand Up @@ -88,7 +94,9 @@ static enum {
/* Output */
C_polarity,
C_disptiming,
C_disp2Y,
C_spibus,
C_dispen,
C_h_off,
C_v_off,
/* LCD */
Expand Down Expand Up @@ -216,7 +224,7 @@ void config_process(uint8_t b)
break;
case C_polarity:
if (changed)
cnf_prt(0, "Sync:");
cnf_prt(0, "Sync Polarity:");
if (b & (B_LEFT|B_RIGHT))
config.polarity ^= 1;
if (b)
Expand All @@ -232,14 +240,38 @@ void config_process(uint8_t b)
if (b)
cnf_prt(1, "%s", config.display_timing ? "VGA" : "15kHz");
break;
case C_disp2Y:
if (changed)
cnf_prt(0, "Display Height:");
if (b & (B_LEFT|B_RIGHT)) {
config.display_2Y ^= 1;
}
if (b)
cnf_prt(1, "%s", config.display_2Y ? "Double" : "Normal");
break;
case C_spibus:
if (changed)
cnf_prt(0, "SPI");
cnf_prt(0, "Display Output:");
if (b & (B_LEFT|B_RIGHT)) {
config.display_spi ^= 1;
}
if (b)
cnf_prt(1, "%s", config.display_spi ? "1 (PA7)" : "2 (PB15)");
cnf_prt(1, "%s", config.display_spi ? "PA7/SPI1" : "PB15/SPI2");
break;
case C_dispen:
if (changed)
cnf_prt(0, "Display Enable:");
if (b & B_LEFT) {
if (config.dispctl_mode > 0)
--config.dispctl_mode;
else
config.dispctl_mode = DISPCTL_MAX-1;
}
if (b & B_RIGHT)
if (++config.dispctl_mode >= DISPCTL_MAX)
config.dispctl_mode = 0;
if (b)
cnf_prt(1, "%s", dispen_pretty[config.dispctl_mode] );
break;
case C_h_off:
if (changed)
Expand Down Expand Up @@ -299,7 +331,8 @@ void config_process(uint8_t b)
"Discard", "Factory Reset" };
if (changed) {
cnf_prt(0, "Save New Config?");
if (old_config.display_spi == config.display_spi)
if ((old_config.display_spi == config.display_spi)
&& (old_config.dispctl_mode == config.dispctl_mode) )
new_config = C_SAVE;
else
new_config = C_SAVEREBOOT;
Expand Down
1 change: 1 addition & 0 deletions src/default_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const static struct config dfl_config = {
.rows = 2,
.display_timing = DISP_15KHZ,
.display_spi = DISP_SPI2,
.display_2Y = FALSE,

#define F(x) (x-1) /* Hotkey (F1-F10) array index */
#define U(x) (1u<<x) /* User pin (U0-U2) bitmask */
Expand Down
17 changes: 12 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ int EXC_reset(void) __attribute__((alias("main")));
void setup_spi(void);
static void slave_arr_update(void);
static uint16_t startup_display_spi;
static uint16_t startup_dispctl_mode;

/* Guard the stacks with known values. */
static void canary_init(void)
Expand Down Expand Up @@ -389,7 +390,7 @@ static uint32_t dispctl_off;
* configured display-control mode. */
static void setup_dispctl_mode(void)
{
switch (config.dispctl_mode) {
switch (startup_dispctl_mode) {

case DISPCTL_tristate:
/* PA15: Unused
Expand Down Expand Up @@ -418,7 +419,7 @@ static void setup_dispctl_mode(void)
case DISPCTL_enable_low: {
/* PA15: Display Enable: Active HIGH or LOW
* PB15: Always driven */
bool_t active_low = (config.dispctl_mode == DISPCTL_enable_low);
bool_t active_low = (startup_dispctl_mode == DISPCTL_enable_low);

if (startup_display_spi == DISP_SPI1) {
gpio_configure_pin(gpio_display_spi1, pin_display_spi1, AFO_pushpull(_50MHz));
Expand Down Expand Up @@ -476,11 +477,13 @@ static void IRQ_osd_end(void)
if (startup_display_spi == DISP_SPI1) {
dma_display_spi1.ccr = 0;
dma_display_spi1.cndtr = cur_display->cols/2 + 1;
dma_display_spi1.cmar += sizeof(display_dat[0]);
if ((config.display_2Y == FALSE) || (hline & 0x1))
dma_display_spi1.cmar += sizeof(display_dat[0]);
} else {
dma_display_spi2.ccr = 0;
dma_display_spi2.cndtr = cur_display->cols/2 + 1;
dma_display_spi2.cmar += sizeof(display_dat[0]);
if ((config.display_2Y == FALSE) || (hline & 0x1))
dma_display_spi2.cmar += sizeof(display_dat[0]);
}
}

Expand Down Expand Up @@ -761,6 +764,7 @@ int main(void)

config_init();
startup_display_spi = config.display_spi;
startup_dispctl_mode = config.dispctl_mode;

/* Set user pin output modes and initial logic levels. */
for (i = 0; i < 3; i++) {
Expand Down Expand Up @@ -971,7 +975,10 @@ int main(void)

tim1->ccr4 = tim1->ccr3 - sysclk_us(1);
barrier(); /* Set post-OSD timeout /then/ enable display */
display_height = height;
if (config.display_2Y)
display_height = 2*height;
else
display_height = height;
} else {
display_height = 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/stm32f10x.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ static void peripheral_init(void)

rcc->ahbenr = RCC_AHBENR_DMA1EN;

/* Turn off serial-wire JTAG and reclaim the GPIOs.
/* Enable SWD, Turn off serial-wire JTAG and reclaim the GPIOs.
* Amiga keyboard map PB4 (KBCLK) to TIM3,CH1 and use its input filter
* and edge detector to generate interrupts on clock transitions. */
afio->mapr = (AFIO_MAPR_SWJ_CFG_JTAGDISABLE
Expand Down

0 comments on commit 676ff1a

Please sign in to comment.