From 743dcf7f69c4afa1efd2f84a2bd0b5e23d53b0b9 Mon Sep 17 00:00:00 2001 From: Bertrik Sikken Date: Tue, 23 Jun 2009 18:11:03 +0000 Subject: Implement PWM backlight driver for the Meizus. Update Meizu M3 bootloader to control brightness with the touch strip. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21478 a1c6a512-1295-4272-9138-f99709370657 --- bootloader/meizu_m3.c | 7 +- firmware/SOURCES | 1 + firmware/export/config-meizu-m3.h | 7 +- firmware/target/arm/s5l8700/backlight-meizu.c | 111 +++++++++++++++++++++ firmware/target/arm/s5l8700/backlight-target.h | 29 ++++++ .../target/arm/s5l8700/meizu-m3/backlight-target.h | 29 ------ .../arm/s5l8700/meizu-m6sl/backlight-target.h | 29 ------ .../arm/s5l8700/meizu-m6sp/backlight-target.h | 29 ------ firmware/target/arm/s5l8700/system-s5l8700.c | 11 +- 9 files changed, 155 insertions(+), 98 deletions(-) create mode 100644 firmware/target/arm/s5l8700/backlight-meizu.c create mode 100644 firmware/target/arm/s5l8700/backlight-target.h delete mode 100644 firmware/target/arm/s5l8700/meizu-m3/backlight-target.h delete mode 100644 firmware/target/arm/s5l8700/meizu-m6sl/backlight-target.h delete mode 100644 firmware/target/arm/s5l8700/meizu-m6sp/backlight-target.h diff --git a/bootloader/meizu_m3.c b/bootloader/meizu_m3.c index 2fb0b551a0..84961228b7 100644 --- a/bootloader/meizu_m3.c +++ b/bootloader/meizu_m3.c @@ -43,7 +43,7 @@ #include "rbunicode.h" #include "usb.h" #include "qt1106.h" -#include "rockboxlogo.h" +#include "bitmaps/rockboxlogo.h" #include @@ -108,7 +108,7 @@ void main(void) int oldval = PCON0; PCON0 = ((oldval & ~(3 << 4)) | (1 << 4)); PDAT0 |= (1 << 2); - + //power on // oldval = PCON1; // PCON1 = ((oldval & ~(0xf << 12)) | (1 << 12)); @@ -128,6 +128,7 @@ void main(void) EINTMSK = 0x11; asm volatile("msr cpsr_c, #0x13\n\t"); // enable interrupts + backlight_init(); lcd_init(); lcd_update(); @@ -157,6 +158,8 @@ void main(void) if(slider & 0x008000) bl_debug_count(((slider&0xff)) + 1); */ + + _backlight_set_brightness(slider & 0xFF); } //power off diff --git a/firmware/SOURCES b/firmware/SOURCES index a7741c1870..0eff012660 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -1241,6 +1241,7 @@ target/arm/s5l8700/meizu-m6sp/lcd-m6sp.c #endif /* MEIZU_M6SP */ #ifdef MEIZU_M3 +target/arm/s5l8700/backlight-meizu.c target/arm/s5l8700/meizu-m3/lcd-m3.c drivers/qt1106.c #ifndef SIMULATOR diff --git a/firmware/export/config-meizu-m3.h b/firmware/export/config-meizu-m3.h index 2ad20550d0..9e2d6cbf4e 100644 --- a/firmware/export/config-meizu-m3.h +++ b/firmware/export/config-meizu-m3.h @@ -178,8 +178,7 @@ #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 */ +#define MIN_BRIGHTNESS_SETTING 0 +#define MAX_BRIGHTNESS_SETTING 255 +#define DEFAULT_BRIGHTNESS_SETTING 200 diff --git a/firmware/target/arm/s5l8700/backlight-meizu.c b/firmware/target/arm/s5l8700/backlight-meizu.c new file mode 100644 index 0000000000..43cbb16a2d --- /dev/null +++ b/firmware/target/arm/s5l8700/backlight-meizu.c @@ -0,0 +1,111 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 by Bertrik Sikken + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include + +#include "config.h" +#include "backlight.h" +#include "backlight-target.h" +#include "system.h" + +/* + Interrupt-driven backlight driver using the PWM mode of a hardware timer. + + Backlight brightness is implemented by configuring one of the timers in + the SoC for PWM mode. In this mode, two interrupts are generated for each + cycle, one at the start of the cycle and another one sometime between the + first interrupt and the start of the next cycle. The backlight is switched + on at the first interrupt and switched off at the second interrupt. This + way, the position in time of the second interrupt determines the duty cycle + and thereby the brightness of the backlight. + The backlight is switched on and off by means of a GPIO pin. + */ + +void INT_TIMERA(void) +{ + unsigned int tacon = TACON; + + /* clear interrupts */ + TACON = tacon; + + /* TA_INT1, start of PWM cycle: enable backlight */ + if (tacon & (1 << 17)) { + PDAT0 |= (1 << 2); + } + + /* TA_INT0, disable backlight until next cycle */ + if (tacon & (1 << 16)) { + PDAT0 &= ~(1 << 2); + } +} + +void _backlight_set_brightness(int brightness) +{ + if (brightness == MIN_BRIGHTNESS_SETTING) { + /* turn backlight fully off and disable interrupt */ + PDAT0 &= ~(1 << 2); + INTMSK &= ~(1 << 5); + } + else if (brightness == MAX_BRIGHTNESS_SETTING) { + /* turn backlight fully on and disable interrupt */ + PDAT0 |= (1 << 2); + INTMSK &= ~(1 << 5); + } + else { + /* set PWM width and enable interrupt */ + TADATA0 = brightness; + INTMSK |= (1 << 5); + } +} + +void _backlight_on(void) +{ + _backlight_set_brightness(backlight_brightness); +} + +void _backlight_off(void) +{ + _backlight_set_brightness(MIN_BRIGHTNESS_SETTING); +} + +bool _backlight_init(void) +{ + /* enable backlight pin as GPIO */ + PCON0 = ((PCON0 & ~(3 << 4)) | (1 << 4)); + + /* enable timer clock */ + PWRCON &= ~(1 << 4); + + /* configure timer */ + TACMD = (1 << 1); /* TA_CLR */ + TACMD = (1 << 0); /* TA_EN */ + TACON = (1 << 13) | /* TA_INT1_EN */ + (1 << 12) | /* TA_INT0_EN */ + (1 << 11) | /* TA_START */ + (3 << 8) | /* TA_CS = PCLK / 64 */ + (1 << 4); /* TA_MODE_SEL = PWM mode */ + TADATA1 = MAX_BRIGHTNESS_SETTING; /* set PWM period */ + TAPRE = 100; /* prescaler */ + + _backlight_on(); + + return true; +} + diff --git a/firmware/target/arm/s5l8700/backlight-target.h b/firmware/target/arm/s5l8700/backlight-target.h new file mode 100644 index 0000000000..91579b080d --- /dev/null +++ b/firmware/target/arm/s5l8700/backlight-target.h @@ -0,0 +1,29 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Marcoen Hirschberg + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef BACKLIGHT_TARGET_H +#define BACKLIGHT_TARGET_H + +bool _backlight_init(void); +void _backlight_on(void); +void _backlight_off(void); +void _backlight_set_brightness(int brightness); + +#endif diff --git a/firmware/target/arm/s5l8700/meizu-m3/backlight-target.h b/firmware/target/arm/s5l8700/meizu-m3/backlight-target.h deleted file mode 100644 index 91579b080d..0000000000 --- a/firmware/target/arm/s5l8700/meizu-m3/backlight-target.h +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2008 by Marcoen Hirschberg - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef BACKLIGHT_TARGET_H -#define BACKLIGHT_TARGET_H - -bool _backlight_init(void); -void _backlight_on(void); -void _backlight_off(void); -void _backlight_set_brightness(int brightness); - -#endif diff --git a/firmware/target/arm/s5l8700/meizu-m6sl/backlight-target.h b/firmware/target/arm/s5l8700/meizu-m6sl/backlight-target.h deleted file mode 100644 index 91579b080d..0000000000 --- a/firmware/target/arm/s5l8700/meizu-m6sl/backlight-target.h +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2008 by Marcoen Hirschberg - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef BACKLIGHT_TARGET_H -#define BACKLIGHT_TARGET_H - -bool _backlight_init(void); -void _backlight_on(void); -void _backlight_off(void); -void _backlight_set_brightness(int brightness); - -#endif diff --git a/firmware/target/arm/s5l8700/meizu-m6sp/backlight-target.h b/firmware/target/arm/s5l8700/meizu-m6sp/backlight-target.h deleted file mode 100644 index 91579b080d..0000000000 --- a/firmware/target/arm/s5l8700/meizu-m6sp/backlight-target.h +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2008 by Marcoen Hirschberg - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef BACKLIGHT_TARGET_H -#define BACKLIGHT_TARGET_H - -bool _backlight_init(void); -void _backlight_on(void); -void _backlight_off(void); -void _backlight_set_brightness(int brightness); - -#endif diff --git a/firmware/target/arm/s5l8700/system-s5l8700.c b/firmware/target/arm/s5l8700/system-s5l8700.c index c535a0d955..48c50645e9 100644 --- a/firmware/target/arm/s5l8700/system-s5l8700.c +++ b/firmware/target/arm/s5l8700/system-s5l8700.c @@ -95,12 +95,13 @@ void irq_handler(void) asm volatile( "stmfd sp!, {r0-r7, ip, lr} \n" /* Store context */ "sub sp, sp, #8 \n"); /* Reserve stack */ - int irq_no = INTOFFSET; /* Read clears the corresponding IRQ status */ + int irq_no = INTOFFSET; - if ((irq_no & (1<<31)) == 0) /* Ensure invalid flag is not set */ - { - irqvector[irq_no](); - } + irqvector[irq_no](); + + /* clear interrupt */ + SRCPND = (1 << irq_no); + INTPND = INTPND; asm volatile( "add sp, sp, #8 \n" /* Cleanup stack */ "ldmfd sp!, {r0-r7, ip, lr} \n" /* Restore context */ -- cgit v1.2.3