From e6e0989436e870e16df9274a43c609d0257cbdb1 Mon Sep 17 00:00:00 2001 From: lephe Date: Thu, 22 Dec 2016 18:36:39 +0100 Subject: [PATCH] Solved backlight issues and added backlight control to the API. --- Makefile | 15 ++++++++++++++- TODO | 2 +- include/screen.h | 6 ++++++ src/keyboard/keyboard_sh7305.c | 26 +++++++++++++------------- src/screen/screen_setBacklight.c | 22 ++++++++++++++++++++++ src/timer/timer_interrupt.c | 4 ---- 6 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 src/screen/screen_setBacklight.c diff --git a/Makefile b/Makefile index e58aff7..fc23b70 100755 --- a/Makefile +++ b/Makefile @@ -50,6 +50,12 @@ obj-std-spec = # Configuration files config = gcc.cfg +ifndef folder +folder = /usr/share/fxsdk +endif + + + #--- # Automatic variables. #--- @@ -206,5 +212,12 @@ distclean: mrproper install: p7 send -f $(target-g1a) +install_lib: $(target-std) $(target-lib) + mkdir -p $(folder) + install -m 644 $^ $(folder) + install -m 644 -T demo/gintdemo.ld $(folder)/linker.ld + mkdir -p $(folder)/gint + install -m 644 include/*.h $(folder)/gint + @ printf '\e[32;1mmsg \u00bb\e[0m All installed!\n' -.PHONY: all clean mrproper distclean install help +.PHONY: all clean mrproper distclean install install_lib help diff --git a/TODO b/TODO index 70a42f7..a176eda 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ Bugs to fix: - Left-vram overflow when rendering text - A few key hits ignored after leaving the application (could not reproduce) - Lost keyboard control at startup (could not reproduce) -- Back-light issues (0xa400012c on SH3, 0xa4050138 on SH4) Simple improvements: - bopti: Monochrome bitmaps blending modes @@ -14,6 +13,7 @@ Simple improvements: - timer: Add duration and frequency settings - core: Add VBR handlers debugging information (if possible) - core: Implement all callbacks and a complete user API +- project: Enhance Makefile install_lib rules Modules to implement: - Serial communication diff --git a/include/screen.h b/include/screen.h index 175e983..899d713 100644 --- a/include/screen.h +++ b/include/screen.h @@ -20,4 +20,10 @@ */ void screen_display(const void *vram); +/* + screen_setBacklight() + On compatible models, turns on or turns off the backlight. +*/ +void screen_setBacklight(int on); + #endif diff --git a/src/keyboard/keyboard_sh7305.c b/src/keyboard/keyboard_sh7305.c index ac740b6..ab515ed 100644 --- a/src/keyboard/keyboard_sh7305.c +++ b/src/keyboard/keyboard_sh7305.c @@ -56,8 +56,8 @@ static void kdelay(void) /* krow() - Reads a keyboard row. Works like krow() for SH7705. See gint_7705.c for - more details. + Reads a keyboard row. Works like krow() for SH7705; see source file + keyboard_7705.c for more details. */ static int krow(int row) { @@ -75,7 +75,7 @@ static int krow(int row) unsigned short smask; unsigned char cmask; - int result = 0; + int result = 0; if(row < 0 || row > 9) return 0; @@ -83,9 +83,9 @@ static int krow(int row) *detector = 0xaaaa; *key_register = 0xff; *injector1 = (*injector1 & 0xf000) | 0x0555; - *injector2 = (*injector2 & 0xf000) | 0x0555; + *injector2 = (*injector2 & 0xff00) | 0x0055; *data1 |= 0x3f; - *data2 |= 0x3f; + *data2 |= 0x0f; kdelay(); if(row < 6) @@ -94,11 +94,11 @@ static int krow(int row) cmask = ~(1 << row); *injector1 = ((*injector1 & 0xf000) | 0x0aaa) ^ smask; - *injector2 = (*injector2 & 0xf000) | 0x0aaa; + *injector2 = (*injector2 & 0xff00) | 0x00aa; kdelay(); - *data1 = (*data1 & 0xc0) | cmask; - *data2 |= 0x3f; + *data1 = (*data1 & 0xc0) | (cmask & 0x3f); + *data2 |= 0x0f; kdelay(); } else @@ -107,11 +107,11 @@ static int krow(int row) cmask = ~(1 << (row - 6)); *injector1 = (*injector1 & 0xf000) | 0x0aaa; - *injector2 = ((*injector2 & 0xf000) | 0x0aaa) ^ smask; + *injector2 = ((*injector2 & 0xff00) | 0x00aa) ^ smask; kdelay(); *data1 |= 0x3f; - *data2 = (*data2 & 0xc0) | cmask; + *data2 = (*data2 & 0xf0) | (cmask & 0x0f); kdelay(); } @@ -121,13 +121,13 @@ static int krow(int row) // Re-initializing the port configuration and data. *injector1 = (*injector1 & 0xf000) | 0x0aaa; - *injector2 = (*injector2 & 0xf000) | 0x0aaa; + *injector2 = (*injector2 & 0xff00) | 0x00aa; kdelay(); *injector1 = (*injector1 & 0xf000) | 0x0555; - *injector2 = (*injector2 & 0xf000) | 0x0555; + *injector2 = (*injector2 & 0xff00) | 0x0055; kdelay(); *data1 &= 0xc0; - *data2 &= 0xc0; + *data2 &= 0xf0; return result; } diff --git a/src/screen/screen_setBacklight.c b/src/screen/screen_setBacklight.c new file mode 100644 index 0000000..8aa231d --- /dev/null +++ b/src/screen/screen_setBacklight.c @@ -0,0 +1,22 @@ +#include +#include + +/* + screen_setBacklight() + On compatible models, turns on or turns off the backlight. +*/ +void screen_setBacklight(int on) +{ + if(isSH3()) + { + volatile unsigned char *PGDR = (void *)0xa400012c; + if(on) *PGDR |= 0x80; + else *PGDR &= ~0x80; + } + else + { + volatile unsigned char *PNDR = (void *)0xa4050138; + if(on) *PNDR |= 0x10; + else *PNDR &= ~0x10; + } +} diff --git a/src/timer/timer_interrupt.c b/src/timer/timer_interrupt.c index 7dd91e4..85f4427 100644 --- a/src/timer/timer_interrupt.c +++ b/src/timer/timer_interrupt.c @@ -14,15 +14,11 @@ void timer_interrupt(int timer) volatile struct mod_tmu *tmu; timer_get(timer, &tmu, NULL); - // Resetting the interrupt flag. tmu->TCR.UNF = 0; - - // Calling the callback function. if(timers[timer].callback) timers[timer].callback(); // Reducing the number of repetitions left, if not infinite. if(!timers[timer].repeats) return; - // And stopping it if necessary. if(timers[timer].repeats == 1) timer_stop(timer); else timers[timer].repeats--; }