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

Video pixel timing and polarity auto detection #25

Merged
merged 1 commit into from
Dec 12, 2019
Merged
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
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export ROOT := $(CURDIR)

all:
$(MAKE) -C src -f $(ROOT)/Rules.mk $(PROJ).elf $(PROJ).bin $(PROJ).hex
debug:
debug=y $(MAKE) -C src -f $(ROOT)/Rules.mk $(PROJ).elf $(PROJ).bin $(PROJ).hex
clean:
rm -rf $(PROJ)-$(VER)*
$(MAKE) -f $(ROOT)/Rules.mk $@
Expand Down
4 changes: 4 additions & 0 deletions Rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ FLAGS += -Wstrict-prototypes -Wredundant-decls -Wnested-externs
FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing
FLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3 -mfloat-abi=soft

ifneq ($(debug),y)
FLAGS += -DNDEBUG
endif

FLAGS += -MMD -MF .$(@F).d
DEPS = .*.d

Expand Down
12 changes: 8 additions & 4 deletions inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ enum dispen { DISPCTL_tristate = 0, DISPCTL_enable_high, DISPCTL_enable_low, DIS
* PA15 is Display Enable: Active HIGH
* PA15 is Display Enable: Active LOW */

enum timings { DISP_15KHZ=0, DISP_VGA, DISP_AUTO, DISP_MAX };

enum polarities { SYNC_LOW=0, SYNC_HIGH, SYNC_AUTO, SYNC_MAX };

extern struct __packed config {

uint16_t polarity;
Expand All @@ -24,12 +28,12 @@ extern struct __packed config {

uint16_t rows;

#define DISP_15KHZ 0
#define DISP_VGA 1
/* timings enum
* DISP_15KHZ 0
* DISP_VGA 1
* DISP_AUTO 2 */
uint16_t display_timing;

uint16_t display_autosync;

#define DISP_SPI2 0
#define DISP_SPI1 1
uint16_t display_spi;
Expand Down
68 changes: 47 additions & 21 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@ const static struct config *flash_config = (struct config *)0x0800fc00;

struct config config;

extern void setup_spi(void);
extern void setup_spi(uint16_t video_mode);
extern uint16_t running_polarity;
extern uint16_t running_display_timing;

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 */

const static char *timing_pretty[] = { "15kHz", "VGA", "Auto" };

const static char *polarity_pretty[] = { "Low", "High", "Auto" };

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(" Auto Sync: %s\n", config.display_autosync ? "ON" : "OFF");
printk(" Sync Polarity: %s\n", polarity_pretty[conf->polarity]);
printk(" Pixel Timing: %s\n", timing_pretty[config.display_timing]);
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] );
Expand Down Expand Up @@ -95,7 +100,6 @@ static enum {
/* Output */
C_polarity,
C_disptiming,
C_autosync,
C_disp2Y,
C_spibus,
C_dispen,
Expand Down Expand Up @@ -227,28 +231,50 @@ void config_process(uint8_t b)
case C_polarity:
if (changed)
cnf_prt(0, "Sync Polarity:");
if (b & (B_LEFT|B_RIGHT))
config.polarity ^= 1;
if (b)
cnf_prt(1, "Active %s", config.polarity ? "HIGH" : "LOW");
if (b & B_LEFT) {
if (config.polarity > 0)
--config.polarity;
else
config.polarity = SYNC_MAX-1;
}
if (b & B_RIGHT) {
if (++config.polarity >= SYNC_MAX)
config.polarity = 0;
}
if (b & (B_LEFT|B_RIGHT)) {
if (config.polarity != SYNC_AUTO)
running_polarity = config.polarity;
}
if (b) {
if (config.polarity == SYNC_AUTO)
cnf_prt(1, "%s (%s)", polarity_pretty[config.polarity], polarity_pretty[running_polarity]);
else
cnf_prt(1, "%s", polarity_pretty[config.polarity]);
}
break;
case C_disptiming:
if (changed)
cnf_prt(0, "Pixel Timing:");
if (b & B_LEFT) {
if (config.display_timing > 0)
--config.display_timing;
else
config.display_timing = DISP_MAX-1;
}
if (b & B_RIGHT) {
if (++config.display_timing >= DISP_MAX)
config.display_timing = 0;
}
if (b & (B_LEFT|B_RIGHT)) {
config.display_timing ^= 1;
setup_spi();
if (config.display_timing != DISP_AUTO)
setup_spi(config.display_timing);
}
if (b) {
if (config.display_timing == DISP_AUTO)
cnf_prt(1, "%s (%s)", timing_pretty[config.display_timing], timing_pretty[running_display_timing]);
else
cnf_prt(1, "%s", timing_pretty[config.display_timing]);
}
if (b)
cnf_prt(1, "%s", config.display_timing ? "VGA" : "15kHz");
break;
case C_autosync:
if (changed)
cnf_prt(0, "Auto Sync:");
if (b & (B_LEFT|B_RIGHT))
config.display_autosync ^= 1;
if (b)
cnf_prt(1, "%s", config.display_autosync ? "ON" : "OFF");
break;
case C_disp2Y:
if (changed)
Expand Down
1 change: 0 additions & 1 deletion src/default_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const static struct config dfl_config = {
.dispctl_mode = DISPCTL_tristate,
.rows = 2,
.display_timing = DISP_15KHZ,
.display_autosync = FALSE,
.display_spi = DISP_SPI2,
.display_2Y = FALSE,

Expand Down
Loading