Permalink
Browse files

Feature: LED brightness

  • Loading branch information...
mrehkopf committed Sep 3, 2018
1 parent c7cc929 commit 82d30ed098c5737043737ebfff91259789a45e8f
Showing with 104 additions and 8 deletions.
  1. +18 −0 snes/const.a65
  2. +2 −0 snes/memmap.i65
  3. +44 −2 snes/menudata.a65
  4. +10 −1 src/cfg.c
  5. +2 −0 src/cfg.h
  6. +19 −5 src/led.c
  7. +1 −0 src/led.h
  8. +7 −0 src/main.c
  9. +1 −0 src/snes.h
View
@@ -205,6 +205,7 @@ mtext_browser_sort .byt "Sort directories", 0
mtext_browser_hide_ext .byt "Hide file extensions", 0
mtext_browser_screensaver .byt "Screensaver", 0
mtext_browser_screensaver_timeout .byt "Fade screen after", 0
mtext_browser_ledbright .byt "LED brightness", 0
mtext_ingame_shortreset .byt "Reset to menu", 0
mtext_ingame_enable .byt "In-game hook", 0
mtext_ingame_buttons .byt " ",129,"In-game buttons", 0
@@ -234,6 +235,7 @@ mdesc_browser_sort .byt "Choose whether to sort file lists", 0
mdesc_browser_hide_ext .byt "Choose whether to hide file extensions", 0
mdesc_browser_screensaver .byt "Fade-out the screen after some time", 0
mdesc_browser_screensaver_timeout .byt "Set time after which to fade the screen", 0
mdesc_browser_ledbright .byt "Change brightness of LEDs", 0
mdesc_ingame_shortreset .byt "Go back to menu on short reset if enabled", 0
mdesc_ingame_enable .byt "Required for in-game buttons and 7E/7F cheats", 0
mdesc_ingame_buttons .byt "Enable in-game buttons (reset, en/disable cheats", 127, 128, "). Requires in-game hook to be enabled.", 0
@@ -293,6 +295,22 @@ text_minus5 .byt "-5", 0
text_minus6 .byt "-6", 0
text_minus7 .byt "-7", 0
text_1 .byt "1", 0
text_2 .byt "2", 0
text_3 .byt "3", 0
text_4 .byt "4", 0
text_5 .byt "5", 0
text_6 .byt "6", 0
text_7 .byt "7", 0
text_8 .byt "8", 0
text_9 .byt "9", 0
text_10 .byt "10", 0
text_11 .byt "11", 0
text_12 .byt "12", 0
text_13 .byt "13", 0
text_14 .byt "14", 0
text_15_max .byt "15 (max)", 0
text_3_5db .byt "+3.5dBFS", 0
text_6db .byt "+6dBFS", 0
text_9_5db .byt "+9.5dBFS", 0
View
@@ -72,6 +72,7 @@
#define CMD_SET_CFG $0F
#define CMD_SELECTROM $10
#define CMD_RUNROM $11 /* ROM must first be selected by SELECTROM */
#define CMD_LED_BRIGHTNESS $12
#define CMD_MCU_RDY $55
#define CMD_RESET $80
#define CMD_RESET_TO_MENU $81
@@ -103,6 +104,7 @@
#define CFG_BRIGHTNESS_LIMIT CFG_ADDR+$009D
#define CFG_GSU_SPEED CFG_ADDR+$009E
#define CFG_ENABLE_RST_TO_MENU CFG_ADDR+$009F
#define CFG_LED_BRIGHTNESS CFG_ADDR+$00A0
#define MENU_ENTRY_SIZE 23
View
@@ -273,6 +273,21 @@ menu_enttab_browser:
.byt 0,0,0
.byt 0,0,0
.byt MTYPE_VALUE
.word !mtext_browser_ledbright
.byt ^mtext_browser_ledbright
.word !kv_led_bright
.byt ^kv_led_bright
.byt OPTTYPE_KVBYTE
.word !CFG_LED_BRIGHTNESS
.byt ^CFG_LED_BRIGHTNESS
.word !mdesc_browser_ledbright
.byt ^mdesc_browser_ledbright
.word !(mfunc_chg_ledbright-1)
.byt ^(mfunc_chg_ledbright-1)
.byt 0,0,0
.byt 0,0,0
; .byt MTYPE_VALUE
; .word !mtext_browser_screensaver_timeout
; .byt ^mtext_browser_screensaver_timeout
@@ -322,7 +337,7 @@ menu_enttab_chip:
.byt 0,0,0
.byt 0,0,0
.byt 0,0,0
.byt MTYPE_VALUE
.word !mtext_chip_msu1_volume_boost
.byt ^mtext_chip_msu1_volume_boost
@@ -358,7 +373,7 @@ menu_enttab_ingame:
.byt 0,0,0
.byt 0,0,0
.byt 0,0,0
.byt MTYPE_VALUE
.word !mtext_ingame_enable
.byt ^mtext_ingame_enable
@@ -538,6 +553,14 @@ mfunc_chg_brightness:
sta @bright_limit
rtl
mfunc_chg_ledbright:
sta @CFG_LED_BRIGHTNESS
lda #CMD_LED_BRIGHTNESS
- sta @MCU_CMD
cmp @SNES_CMD
bne -
rtl
kv_bsx_timesource:
.word $0000, !text_rtc : .byt ^text_rtc
.word $0001, !text_custom : .byt ^text_custom
@@ -615,6 +638,25 @@ kv_bright_limit:
.word $000f, !text_off : .byt ^text_off
.word $ffff
kv_led_bright:
.word $0000, !text_off : .byt ^text_off
.word $0001, !text_1 : .byt ^text_1
.word $0002, !text_2 : .byt ^text_2
.word $0003, !text_3 : .byt ^text_3
.word $0004, !text_4 : .byt ^text_4
.word $0005, !text_5 : .byt ^text_5
.word $0006, !text_6 : .byt ^text_6
.word $0007, !text_7 : .byt ^text_7
.word $0008, !text_8 : .byt ^text_8
.word $0009, !text_9 : .byt ^text_9
.word $000a, !text_10 : .byt ^text_10
.word $000b, !text_11 : .byt ^text_11
.word $000c, !text_12 : .byt ^text_12
.word $000d, !text_13 : .byt ^text_13
.word $000e, !text_14 : .byt ^text_14
.word $000f, !text_15_max : .byt ^text_15_max
.word $ffff
menu_enttab_test:
; HEADER
.byt 1
View
@@ -31,7 +31,8 @@ cfg_t CFG_DEFAULT = {
.onechip_transient_fixes = 0,
.brightness_limit = 15,
.gsu_speed = 0,
.reset_to_menu = 0
.reset_to_menu = 0,
.led_brightness = 15
};
cfg_t CFG;
@@ -77,8 +78,10 @@ int cfg_save() {
f_puts("\n# UI related settings\n", &file_handle);
f_printf(&file_handle, "# %s: Sort directories (slower but files are guaranteed to be in order)\n", CFG_SORT_DIRECTORIES);
f_printf(&file_handle, "# %s: Hide file extensions\n", CFG_HIDE_EXTENSIONS);
f_printf(&file_handle, "# %s: LED brightness (0: minimum, 15: maximum)\n", CFG_LED_BRIGHTNESS);
f_printf(&file_handle, "%s: %s\n", CFG_SORT_DIRECTORIES, CFG.sort_directories ? "true" : "false");
f_printf(&file_handle, "%s: %s\n", CFG_HIDE_EXTENSIONS, CFG.hide_extensions ? "true" : "false");
f_printf(&file_handle, "%s: %d\n", CFG_LED_BRIGHTNESS, CFG.led_brightness);
f_puts("\n# Enhancement chip settings\n", &file_handle);
f_printf(&file_handle, "# %s: Cx4 core speed (0: original, 1: fast, all instructions are single cycle)\n", CFG_CX4_SPEED);
f_printf(&file_handle, "%s: %d\n", CFG_CX4_SPEED, CFG.cx4_speed);
@@ -156,6 +159,12 @@ int cfg_load() {
if(yaml_get_itemvalue(CFG_ENABLE_RST_TO_MENU, &tok)) {
CFG.reset_to_menu = tok.boolvalue ? 1 : 0;
}
if(yaml_get_itemvalue(CFG_LED_BRIGHTNESS, &tok)) {
CFG.led_brightness = tok.longvalue;
if(CFG.led_brightness > 15) {
CFG.led_brightness = 15;
}
}
}
yaml_file_close();
return err;
View
@@ -28,6 +28,7 @@
#define CFG_1CHIP_TRANSIENT_FIXES ("1CHIPTransientFixes")
#define CFG_BRIGHTNESS_LIMIT ("BrightnessLimit")
#define CFG_ENABLE_RST_TO_MENU ("ShortReset2Menu")
#define CFG_LED_BRIGHTNESS ("LEDBrightness")
typedef enum {
VIDMODE_60 = 0,
@@ -57,6 +58,7 @@ typedef struct __attribute__ ((__packed__)) _cfg_block {
uint8_t brightness_limit; /* limit brightness set by register 2100 */
uint8_t gsu_speed; /* GSU speed (0: original, 1: no waitstates */
uint8_t reset_to_menu; /* Go back to menu on short reset */
uint8_t led_brightness; /* LED brightness (0..15) */
} cfg_t;
int cfg_save(void);
View
@@ -6,14 +6,20 @@
#include "led.h"
#include "cli.h"
#include "fileops.h"
#include "cfg.h"
static uint8_t led_bright[16]={255,253,252,251,249,247,244,239,232,223,210,191,165,127,74,0};
static uint16_t led_bright[16]={60000, 59920, 59871, 59794,
59669, 59469, 59148, 58633,
57806, 56481, 54354, 50942,
45469, 36688, 22601, 0};
int led_rdyledstate = 0;
int led_readledstate = 0;
int led_writeledstate = 0;
int led_pwmstate = 0;
extern cfg_t CFG;
/* LED connections (Rev.C)
LED color IO PWM
@@ -25,7 +31,7 @@ int led_pwmstate = 0;
void rdyled(unsigned int state) {
if(led_pwmstate) {
rdybright(state?15:0);
rdybright(state ? CFG.led_brightness : 0);
} else {
BITBAND(LPC_GPIO2->FIODIR, 4) = state;
}
@@ -34,7 +40,7 @@ void rdyled(unsigned int state) {
void readled(unsigned int state) {
if(led_pwmstate) {
readbright(state?15:0);
readbright(state ? CFG.led_brightness : 0);
} else {
BITBAND(LPC_GPIO2->FIODIR, 5) = state;
}
@@ -43,7 +49,7 @@ void readled(unsigned int state) {
void writeled(unsigned int state) {
if(led_pwmstate) {
writebright(state?15:0);
writebright(state ? CFG.led_brightness : 0);
} else {
BITBAND(LPC_GPIO1->FIODIR, 23) = state;
}
@@ -141,7 +147,8 @@ void led_init() {
/* set PCLK divider to 8 */
BITBAND(LPC_SC->PCLKSEL0, 13) = 1;
BITBAND(LPC_SC->PCLKSEL0, 12) = 1;
LPC_PWM1->MR0 = 255;
/* PWM rate 200Hz -> 60000 counts */
LPC_PWM1->MR0 = 60000;
BITBAND(LPC_PWM1->LER, 0) = 1;
BITBAND(LPC_PWM1->TCR, 0) = 1;
BITBAND(LPC_PWM1->TCR, 3) = 1;
@@ -185,3 +192,10 @@ void led_error() {
framecount++;
}
}
void led_set_brightness(uint8_t bright) {
rdybright(led_rdyledstate ? bright : 0);
readbright(led_readledstate ? bright : 0);
writebright(led_writeledstate ? bright : 0);
CFG.led_brightness = bright;
}
View
@@ -24,4 +24,5 @@ void led_pwm(void);
void led_std(void);
void led_init(void);
void led_error(void);
void led_set_brightness(uint8_t bright);
#endif
View
@@ -143,6 +143,7 @@ printf("PCONP=%lx\n", LPC_SC->PCONP);
file_close();
}
// snes_bootprint(" Loading ... \0");
led_pwm();
rdyled(1);
readled(0);
writeled(0);
@@ -155,6 +156,7 @@ printf("PCONP=%lx\n", LPC_SC->PCONP);
}
if(fpga_config != FPGA_BASE) fpga_pgm((uint8_t*)FPGA_BASE);
cfg_dump_recent_games_for_snes(SRAM_LASTGAME_ADDR);
led_set_brightness(1 /*CFG.led_brightness*/);
/* load menu */
sram_writelong(0x12345678, SRAM_SCRATCHPAD);
@@ -308,6 +310,11 @@ printf("PCONP=%lx\n", LPC_SC->PCONP);
cfg_save();
cmd=0; /* stay in menu loop */
break;
case SNES_CMD_LED_BRIGHTNESS:
cfg_get_from_menu();
led_set_brightness(CFG.led_brightness);
cmd=0;
break;
case SNES_CMD_LOAD_CHT:
/* load cheats */
cmd=0; /* stay in menu loop */
View
@@ -40,6 +40,7 @@
#define SNES_CMD_LOAD_CHT (0x0c)
#define SNES_CMD_SAVE_CHT (0x0d)
#define SNES_CMD_SAVE_CFG (0x0e)
#define SNES_CMD_LED_BRIGHTNESS (0x12)
#define SNES_CMD_RESET (0x80)
#define SNES_CMD_RESET_TO_MENU (0x81)
#define SNES_CMD_ENABLE_CHEATS (0x82)

1 comment on commit 82d30ed

@juef17

This comment has been minimized.

Show comment
Hide comment
@juef17

juef17 Sep 3, 2018

The feature we never knew we wanted! :D Thanks for your work and devotion to the greatest thing since the SNES itself!

juef17 commented on 82d30ed Sep 3, 2018

The feature we never knew we wanted! :D Thanks for your work and devotion to the greatest thing since the SNES itself!

Please sign in to comment.