diff --git a/bootloader/main.c b/bootloader/main.c index 0f3d706d7b..3b3e6ecae4 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -33,9 +33,6 @@ #include "font.h" #include "adc.h" #include "backlight.h" -#ifdef IAUDIO_X5 -#include "backlight-target.h" -#endif #include "button.h" #include "panic.h" #include "power.h" @@ -208,7 +205,7 @@ void main(void) set_irq_level(0); lcd_init(); - __backlight_on(); + backlight_init(); font_init(); adc_init(); button_init(); diff --git a/firmware/backlight.c b/firmware/backlight.c index e1d92581c4..bc692b1675 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -31,10 +31,6 @@ #include "timer.h" #include "backlight.h" -#ifdef HAVE_BACKLIGHT_BRIGHTNESS -#include "pcf50606.h" /* iRiver, iAudio X5 brightness */ -#endif - #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) #include "lcd.h" /* for lcd_enable() and lcd_sleep() */ #endif @@ -110,8 +106,6 @@ static void backlight_thread(void); static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)]; #ifdef X5_BACKLIGHT_SHUTDOWN #define BACKLIGHT_QUIT 256 -/* Need to save this for x5 shutdown */ -struct thread_entry* backlight_thread_id; #endif static const char backlight_thread_name[] = "backlight"; static struct event_queue backlight_queue; @@ -473,7 +467,7 @@ void backlight_thread(void) #ifdef X5_BACKLIGHT_SHUTDOWN case BACKLIGHT_QUIT: - remove_thread(backlight_thread_id); + remove_thread(NULL); break; #endif @@ -552,23 +546,17 @@ static void backlight_tick(void) void backlight_init(void) { queue_init(&backlight_queue, true); -#ifdef X5_BACKLIGHT_SHUTDOWN - backlight_thread_id = -#endif create_thread(backlight_thread, backlight_stack, sizeof(backlight_stack), backlight_thread_name IF_PRIO(, PRIORITY_SYSTEM)); tick_add_task(backlight_tick); #ifdef SIMULATOR /* do nothing */ -#elif CONFIG_BACKLIGHT == BL_IRIVER_H100 - or_l(0x00020000, &GPIO1_ENABLE); - or_l(0x00020000, &GPIO1_FUNCTION); - and_l(~0x00020000, &GPIO1_OUT); /* Start with the backlight ON */ -#elif CONFIG_BACKLIGHT == BL_IRIVER_H300 - or_l(0x00020000, &GPIO1_ENABLE); - or_l(0x00020000, &GPIO1_FUNCTION); - or_l(0x00020000, &GPIO1_OUT); /* Start with the backlight ON */ +#elif defined(__BACKLIGHT_INIT) + /* Remove the __BACKLIGHT_INIT references when __backlight_init is + available on all backlighted targets. Take them out of the + backlight-target.h files as well */ + __backlight_init(); #elif CONFIG_BACKLIGHT == BL_PA14_LO || CONFIG_BACKLIGHT == BL_PA14_HI PACR1 &= ~0x3000; /* Set PA14 (backlight control) to GPIO */ or_b(0x40, &PAIORH); /* ..and output */ @@ -787,16 +775,26 @@ bool is_remote_backlight_on(void) #endif /* HAVE_REMOTE_LCD */ +#ifdef HAVE_BACKLIGHT_BRIGHTNESS +void backlight_set_brightness(int val) +{ + if (val < MIN_BRIGHTNESS_SETTING) + val = MIN_BRIGHTNESS_SETTING; + else if (val > MAX_BRIGHTNESS_SETTING) + val = MAX_BRIGHTNESS_SETTING; + + __backlight_set_brightness(val); +} +#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ + #else /* !defined(CONFIG_BACKLIGHT) || defined(BOOTLOADER) -- no backlight, empty dummy functions */ #if defined(BOOTLOADER) && defined(CONFIG_BACKLIGHT) void backlight_init(void) { -#ifdef IRIVER_H300_SERIES - or_l(0x00020000, &GPIO1_OUT); - or_l(0x00020000, &GPIO1_ENABLE); - or_l(0x00020000, &GPIO1_FUNCTION); +#ifdef __BACKLIGHT_INIT + __backlight_init(); #endif } #endif @@ -810,21 +808,8 @@ void remote_backlight_on(void) {} void remote_backlight_off(void) {} void remote_backlight_set_timeout(int index) {(void)index;} bool is_remote_backlight_on(void) {return true;} +#endif /* HAVE_REMOTE_LCD */ +#ifdef HAVE_BACKLIGHT_BRIGHTNESS +void backlight_set_brightness(int val) { (void)val; } #endif #endif /* defined(CONFIG_BACKLIGHT) && !defined(BOOTLOADER) */ - -#ifdef HAVE_BACKLIGHT_BRIGHTNESS -void backlight_set_brightness(int val) -{ -#ifndef SIMULATOR - if (val < MIN_BRIGHTNESS_SETTING) - val = MIN_BRIGHTNESS_SETTING; - else if (val > MAX_BRIGHTNESS_SETTING) - val = MAX_BRIGHTNESS_SETTING; - - __backlight_set_brightness(val); -#else - (void)val; -#endif -} -#endif /* HAVE_BACKLIGHT_BRIGHTNESS */ diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h index 8ef227676a..fd84f37061 100644 --- a/firmware/export/config-h100.h +++ b/firmware/export/config-h100.h @@ -154,13 +154,6 @@ #endif /* !SIMULATOR */ -#define DEFAULT_CONTRAST_SETTING 28 -#define MIN_CONTRAST_SETTING 14 /* White screen a bit higher than this */ -#define MAX_CONTRAST_SETTING 63 /* Black screen a bit lower than this*/ -#define DEFAULT_REMOTE_CONTRAST_SETTING 42 -#define MIN_REMOTE_CONTRAST_SETTING MIN_CONTRAST_SETTING -#define MAX_REMOTE_CONTRAST_SETTING MAX_CONTRAST_SETTING - /* Define this for S/PDIF input available */ #define HAVE_SPDIF_IN @@ -173,3 +166,15 @@ /* Define this for FM radio input available */ #define HAVE_FMRADIO_IN + +/** Port-specific settings **/ + +/* Main LCD backlight brightness range and defaults */ +#define MIN_CONTRAST_SETTING 14 /* White screen a bit higher than this */ +#define MAX_CONTRAST_SETTING 63 /* Black screen a bit lower than this */ +#define DEFAULT_CONTRAST_SETTING 28 + +/* Remote LCD contrast range and defaults */ +#define MIN_REMOTE_CONTRAST_SETTING 5 +#define MAX_REMOTE_CONTRAST_SETTING 63 +#define DEFAULT_REMOTE_CONTRAST_SETTING 42 diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h index e4c5cfe876..4a8a3c99be 100644 --- a/firmware/export/config-h120.h +++ b/firmware/export/config-h120.h @@ -150,13 +150,6 @@ #endif /* !SIMULATOR */ -#define DEFAULT_CONTRAST_SETTING 28 -#define MIN_CONTRAST_SETTING 14 /* White screen a bit higher than this */ -#define MAX_CONTRAST_SETTING 63 /* Black screen a bit lower than this*/ -#define DEFAULT_REMOTE_CONTRAST_SETTING 42 -#define MIN_REMOTE_CONTRAST_SETTING MIN_CONTRAST_SETTING -#define MAX_REMOTE_CONTRAST_SETTING MAX_CONTRAST_SETTING - /* Define this for S/PDIF input available */ #define HAVE_SPDIF_IN @@ -171,3 +164,15 @@ /* Define this if you have a serial port */ /*#define HAVE_SERIAL*/ + +/** Port-specific settings **/ + +/* Main LCD backlight brightness range and defaults */ +#define DEFAULT_CONTRAST_SETTING 28 +#define MIN_CONTRAST_SETTING 14 /* White screen a bit higher than this */ +#define MAX_CONTRAST_SETTING 63 /* Black screen a bit lower than this */ + +/* Remote LCD contrast range and defaults */ +#define MIN_REMOTE_CONTRAST_SETTING 5 +#define MAX_REMOTE_CONTRAST_SETTING 63 +#define DEFAULT_REMOTE_CONTRAST_SETTING 42 diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index 14034c61f0..b44a2c5108 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h @@ -151,6 +151,12 @@ #define HAVE_EEPROM #endif /* SIMULATOR */ + +/* Define this for FM radio input available */ +#define HAVE_FMRADIO_IN + +/** Port-specific settings **/ + /* Main LCD contrast range and defaults */ #define MIN_CONTRAST_SETTING 5 #define MAX_CONTRAST_SETTING 63 @@ -163,9 +169,6 @@ #define DEFAULT_BRIGHTNESS_SETTING 9 /* 9/16 (56.25%) */ /* Remote LCD contrast range and defaults */ -#define MIN_REMOTE_CONTRAST_SETTING MIN_CONTRAST_SETTING -#define MAX_REMOTE_CONTRAST_SETTING MAX_CONTRAST_SETTING +#define MIN_REMOTE_CONTRAST_SETTING 5 +#define MAX_REMOTE_CONTRAST_SETTING 63 #define DEFAULT_REMOTE_CONTRAST_SETTING 42 - -/* Define this for FM radio input available */ -#define HAVE_FMRADIO_IN diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h index d45f58f14c..82c36437f5 100644 --- a/firmware/export/config-iaudiox5.h +++ b/firmware/export/config-iaudiox5.h @@ -62,22 +62,6 @@ #define CONFIG_LCD LCD_X5 -/* Main LCD contrast range and defaults */ -#define MIN_CONTRAST_SETTING 1 -#define MAX_CONTRAST_SETTING 30 -#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */ - -/* Remote LCD contrast range and defaults */ -#define MIN_REMOTE_CONTRAST_SETTING 10 -#define MAX_REMOTE_CONTRAST_SETTING 35 -#define DEFAULT_REMOTE_CONTRAST_SETTING 24 /* Match boot contrast */ - -/* Main LCD backlight brightness range and defaults */ -/* PCF50506 can output 0%-100% duty cycle but D305A expects %15-100%. */ -#define MIN_BRIGHTNESS_SETTING 1 /* 15/16 (93.75%) */ -#define MAX_BRIGHTNESS_SETTING 13 /* 3/16 (18.75%) */ -#define DEFAULT_BRIGHTNESS_SETTING 8 /* 8/16 (50.00%) = x5 boot default */ - /* Define this for LCD backlight available */ #define CONFIG_BACKLIGHT BL_X5 /* PCF50606 I2C */ #define HAVE_BACKLIGHT_BRIGHTNESS @@ -170,3 +154,21 @@ /* Define this for FM radio input available */ #define HAVE_FMRADIO_IN + +/** Port-specific settings **/ + +/* Main LCD contrast range and defaults */ +#define MIN_CONTRAST_SETTING 1 +#define MAX_CONTRAST_SETTING 30 +#define DEFAULT_CONTRAST_SETTING 19 /* Match boot contrast */ + +/* Main LCD backlight brightness range and defaults */ +/* PCF50506 can output 0%-100% duty cycle but D305A expects %15-100%. */ +#define MIN_BRIGHTNESS_SETTING 1 /* 15/16 (93.75%) */ +#define MAX_BRIGHTNESS_SETTING 13 /* 3/16 (18.75%) */ +#define DEFAULT_BRIGHTNESS_SETTING 8 /* 8/16 (50.00%) = x5 boot default */ + +/* Remote LCD contrast range and defaults */ +#define MIN_REMOTE_CONTRAST_SETTING 10 +#define MAX_REMOTE_CONTRAST_SETTING 35 +#define DEFAULT_REMOTE_CONTRAST_SETTING 24 /* Match boot contrast */ diff --git a/firmware/target/coldfire/iaudio/x5/backlight-target.h b/firmware/target/coldfire/iaudio/x5/backlight-target.h index e982e656d6..e6feb8bc0c 100755 --- a/firmware/target/coldfire/iaudio/x5/backlight-target.h +++ b/firmware/target/coldfire/iaudio/x5/backlight-target.h @@ -19,6 +19,8 @@ #ifndef BACKLIGHT_TARGET_H #define BACKLIGHT_TARGET_H +#define __BACKLIGHT_INIT +void __backlight_init(void); void __backlight_on(void); void __backlight_off(void); void __backlight_set_brightness(int val); diff --git a/firmware/target/coldfire/iaudio/x5/backlight-x5.c b/firmware/target/coldfire/iaudio/x5/backlight-x5.c index 9d02c35988..9b50993d90 100755 --- a/firmware/target/coldfire/iaudio/x5/backlight-x5.c +++ b/firmware/target/coldfire/iaudio/x5/backlight-x5.c @@ -20,9 +20,16 @@ #include "cpu.h" #include "system.h" #include "backlight.h" +#include "backlight-target.h" #include "pcf50606.h" #include "lcd.h" +void __backlight_init(void) +{ + __backlight_set_brightness(DEFAULT_BRIGHTNESS_SETTING); + __backlight_on(); +} + void __backlight_on(void) { int level; diff --git a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c index 59140667ef..b8128617c2 100644 --- a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c +++ b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c @@ -81,15 +81,6 @@ void pcf50606_init(void) pcf50606_write(0x39, 0x00); /* GPOOD0 = green led OFF */ pcf50606_write(0x3a, 0x00); /* GPOOD1 = red led OFF */ - pcf50606_write(0x35, 0x11); /* Backlight PWM = 512Hz, 8/16, Active */ -#ifdef BOOTLOADER - /* Backlight starts OFF in bootloader */ - pcf50606_write(0x38, 0x80); /* Backlight OFF, GPO1INV=1, GPO1ACT=011 */ -#else - /* Keep backlight on when changing to firmware */ - pcf50606_write(0x38, 0xb0); /* Backlight ON, GPO1INV=1, GPO1ACT=011 */ -#endif - /* Accessory detect */ pcf50606_write(0x33, 0x8e); /* ACDAPE=1, THRSHLD=2.40V */ diff --git a/firmware/target/coldfire/iriver/backlight-target.h b/firmware/target/coldfire/iriver/backlight-target.h index 086ab02761..ac146eac83 100644 --- a/firmware/target/coldfire/iriver/backlight-target.h +++ b/firmware/target/coldfire/iriver/backlight-target.h @@ -19,6 +19,8 @@ #ifndef BACKLIGHT_TARGET_H #define BACKLIGHT_TARGET_H +#define __BACKLIGHT_INIT +void __backlight_init(void); void __backlight_on(void); void __backlight_off(void); #ifdef HAVE_BACKLIGHT_BRIGHTNESS diff --git a/firmware/target/coldfire/iriver/h100/backlight-h100.c b/firmware/target/coldfire/iriver/h100/backlight-h100.c index 8ceac8a6ff..62c24dc861 100644 --- a/firmware/target/coldfire/iriver/h100/backlight-h100.c +++ b/firmware/target/coldfire/iriver/h100/backlight-h100.c @@ -24,6 +24,13 @@ #include "backlight.h" #include "lcd.h" +void __backlight_init(void) +{ + or_l(0x00020000, &GPIO1_ENABLE); + or_l(0x00020000, &GPIO1_FUNCTION); + and_l(~0x00020000, &GPIO1_OUT); /* Start with the backlight ON */ +} + void __backlight_on(void) { and_l(~0x00020000, &GPIO1_OUT); diff --git a/firmware/target/coldfire/iriver/h300/backlight-h300.c b/firmware/target/coldfire/iriver/h300/backlight-h300.c index 50bd757612..ef1d6d344d 100644 --- a/firmware/target/coldfire/iriver/h300/backlight-h300.c +++ b/firmware/target/coldfire/iriver/h300/backlight-h300.c @@ -25,6 +25,13 @@ #include "pcf50606.h" #include "lcd.h" +void __backlight_init(void) +{ + or_l(0x00020000, &GPIO1_ENABLE); + or_l(0x00020000, &GPIO1_FUNCTION); + or_l(0x00020000, &GPIO1_OUT); /* Start with the backlight ON */ +} + void __backlight_on(void) { lcd_enable(true);