From 9a24892e2e8b6ef9f8a616c630d1bb123ce713e7 Mon Sep 17 00:00:00 2001 From: Marcin Bukat Date: Fri, 26 Nov 2010 23:28:08 +0000 Subject: MPIO HD300 - initial commit git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28680 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/coldfire/crt0.S | 8 +- firmware/target/coldfire/debug-target.h | 3 +- firmware/target/coldfire/mpio/audio-mpio.c | 8 + firmware/target/coldfire/mpio/hd300/button-hd300.c | 234 ++++++++++++++++++++ .../target/coldfire/mpio/hd300/button-target.h | 55 +++++ firmware/target/coldfire/mpio/hd300/lcd-as-hd300.S | 227 +++++++++++++++++++ firmware/target/coldfire/mpio/hd300/lcd-hd300.c | 244 +++++++++++++++++++++ .../target/coldfire/mpio/hd300/powermgmt-hd300.c | 58 +++++ firmware/target/coldfire/mpio/power-mpio.c | 2 + firmware/target/coldfire/wmcodec-coldfire.c | 2 +- 10 files changed, 835 insertions(+), 6 deletions(-) create mode 100644 firmware/target/coldfire/mpio/hd300/button-hd300.c create mode 100644 firmware/target/coldfire/mpio/hd300/button-target.h create mode 100644 firmware/target/coldfire/mpio/hd300/lcd-as-hd300.S create mode 100644 firmware/target/coldfire/mpio/hd300/lcd-hd300.c create mode 100644 firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c (limited to 'firmware/target/coldfire') diff --git a/firmware/target/coldfire/crt0.S b/firmware/target/coldfire/crt0.S index 23bf297316..8b0ee91f9b 100644 --- a/firmware/target/coldfire/crt0.S +++ b/firmware/target/coldfire/crt0.S @@ -63,14 +63,14 @@ start: move.l #0x00000180,%d0 /* CSCR0 - no wait states, 16 bits, no bursts */ move.l %d0,(0x088,%a0) -#ifdef MPIO_HD200 +#if (defined MPIO_HD200) || (defined MPIO_HD300) /* Chip select 3 - LCD controller */ - /* values taken from original firmware except base address*/ + /* FIXME Check if we really need this 2 wait states! */ move.l #0xf0000000,%d0 /* CSAR3 - Base = 0xf0000000 */ move.l %d0,(0x0a4,%a0) moveq.l #0x1,%d0 /* CSMR3 - 64K */ move.l %d0,(0x0a8,%a0) - move.l #0x00000980,%d0 /* CSCR3 - 1 wait state, 16 bits no bursts */ + move.l #0x00000980,%d0 /* CSCR3 - 2 wait states, 16 bits no bursts */ move.l %d0,(0x0ac,%a0) #elif !(defined IAUDIO_M3) /* Chip select 1 - LCD controller */ @@ -276,7 +276,7 @@ start: or.l %d0,(0xbc,%a1) #endif -#ifdef MPIO_HD200 +#if (defined MPIO_HD200) || (defined MPIO_HD300) /* Set KEEP_ACT * Set GPIO57 high to remove hissing nois on startup */ diff --git a/firmware/target/coldfire/debug-target.h b/firmware/target/coldfire/debug-target.h index 76b502e4ff..8d01cdd6f1 100644 --- a/firmware/target/coldfire/debug-target.h +++ b/firmware/target/coldfire/debug-target.h @@ -28,7 +28,8 @@ #elif (CONFIG_KEYPAD == IAUDIO_M3_PAD) # define DEBUG_CANCEL BUTTON_RC_REC -#elif (CONFIG_KEYPAD == MPIO_HD200_PAD) +#elif (CONFIG_KEYPAD == MPIO_HD200_PAD) || \ + (CONFIG_KEYPAD == MPIO_HD300_PAD) # define DEBUG_CANCEL BUTTON_REC #endif bool dbg_ports(void); diff --git a/firmware/target/coldfire/mpio/audio-mpio.c b/firmware/target/coldfire/mpio/audio-mpio.c index 4455281267..ba1258e5e7 100644 --- a/firmware/target/coldfire/mpio/audio-mpio.c +++ b/firmware/target/coldfire/mpio/audio-mpio.c @@ -36,9 +36,15 @@ void audio_set_output_source(int source) static const unsigned char txsrc_select[AUDIO_NUM_SOURCES+1] = { [AUDIO_SRC_PLAYBACK+1] = 3, /* PDOR3 */ +#if (INPUT_SRC_CAPS & SRC_CAP_MIC) [AUDIO_SRC_MIC+1] = 4, /* IIS1 RcvData */ +#endif +#if (INPUT_SRC_CAPS & SRC_CAP_LINEIN) [AUDIO_SRC_LINEIN+1] = 4, /* IIS1 RcvData */ +#endif +#if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) [AUDIO_SRC_FMRADIO+1] = 4, /* IIS1 RcvData */ +#endif }; int level = set_irq_level(DMA_IRQ_LEVEL); @@ -74,7 +80,9 @@ void audio_input_mux(int source, unsigned flags) break; case AUDIO_SRC_MIC: +#if (INPUT_SRC_CAPS & SRC_CAP_LINEIN) case AUDIO_SRC_LINEIN: +#endif /* recording only */ if (source != last_source) { diff --git a/firmware/target/coldfire/mpio/hd300/button-hd300.c b/firmware/target/coldfire/mpio/hd300/button-hd300.c new file mode 100644 index 0000000000..19c93abfca --- /dev/null +++ b/firmware/target/coldfire/mpio/hd300/button-hd300.c @@ -0,0 +1,234 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * scrollstrip logic inspired by button-mini1g.c + * + * 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 "config.h" +#include "cpu.h" +#include "system.h" +#include "button.h" +#include "backlight.h" +#include "adc.h" +#include "powermgmt.h" + +#define SLIDER_BASE_SENSITIVITY 6 + +/* GPI7 H-L, GPI6 H-L, GPI7 L-H, GPI6 L-H */ +#define SLIDER_GPIO_MASK ((1<<15)|(1<<14)|(1<<7)|(1<<6)) + +static inline void disable_scrollstrip_interrupts(void) +{ + and_l(~SLIDER_GPIO_MASK,&GPIO_INT_EN); +} + +static inline void enable_scrollstrip_interrupts(void) +{ + + or_l(SLIDER_GPIO_MASK,&GPIO_INT_EN); +} + +static inline void ack_scrollstrip_interrupt(void) +{ + or_l(SLIDER_GPIO_MASK,&GPIO_INT_CLEAR); +} + +void scrollstrip_isr(void) __attribute__ ((interrupt_handler,section(".icode"))); +void scrollstrip_isr(void) +{ + /* reading line 6 and 7 forms four possible states: + * 0, 1 , 2, 3 + * tracking the order of line changes we can judge + * if the slide is up or down in the following way: + * sliding up order: 0 2 3 1 0 2 3 1 + * sliding down order: 0 1 3 2 0 1 3 2 + */ + static const signed char scroll_state[4][4] ICONST_ATTR = { + { BUTTON_NONE, BUTTON_DOWN, BUTTON_UP, BUTTON_NONE}, + { BUTTON_UP, BUTTON_NONE, BUTTON_NONE, BUTTON_DOWN}, + { BUTTON_DOWN, BUTTON_NONE, BUTTON_NONE, BUTTON_UP}, + { BUTTON_NONE, BUTTON_UP, BUTTON_DOWN, BUTTON_NONE} + }; + + static signed char prev_scroll_lines = -1; + static signed char direction = 0; + static unsigned char count = 0; + static long next_backlight_on = 0; + + signed int new_scroll_lines; + signed int scroll_dir; + + disable_scrollstrip_interrupts(); + + /* read GPIO6 and GPIO7 state*/ + new_scroll_lines = (GPIO_READ >> 6) & 0x03; + + if ( prev_scroll_lines == -1 ) + { + prev_scroll_lines = new_scroll_lines; + ack_scrollstrip_interrupt(); + enable_scrollstrip_interrupts(); + return; + } + + scroll_dir = scroll_state[prev_scroll_lines][new_scroll_lines]; + prev_scroll_lines = new_scroll_lines; + + if (direction != scroll_dir) + { + /* direction reversal */ + direction = scroll_dir; + count = 0; + ack_scrollstrip_interrupt(); + enable_scrollstrip_interrupts(); + return; + } + + /* poke backlight */ + if (TIME_AFTER(current_tick, next_backlight_on)) + { + backlight_on(); + reset_poweroff_timer(); + next_backlight_on = current_tick + HZ/4; + } + + if (++count < SLIDER_BASE_SENSITIVITY) + { + ack_scrollstrip_interrupt(); + enable_scrollstrip_interrupts(); + return; + } + + count = 0; + + /* post scrollstrip event to the button queue */ + if (queue_empty(&button_queue)) + queue_post(&button_queue, scroll_dir, 0); + + ack_scrollstrip_interrupt(); + enable_scrollstrip_interrupts(); +} + +/* register interrupt service routine for scrollstrip lines */ +void GPI6(void) __attribute__ ((alias("scrollstrip_isr"))); +void GPI7(void) __attribute__ ((alias("scrollstrip_isr"))); + +void button_init_device(void) +{ + /* GPIO56 (PLAY) general input + * GPIO45 (ENTER) general input + * GPIO41 (MENU) dual function pin shared with audio serial data + * + * GPIO6, GPIO7 scrollstrip lines + * GPIO31 scrollstrip enable + */ + + or_l((1<<24)|(1<<13),&GPIO1_FUNCTION); + and_l(~((1<<24)|(1<<13)),&GPIO1_ENABLE); + + or_l((1<<31)|(1<<7)|(1<<6),&GPIO_FUNCTION); + and_l(~((1<<7)|(1<<6)),&GPIO_ENABLE); + + /* scrollstrip enable active low */ + and_l(~(1<<31),&GPIO_OUT); + or_l((1<<31),&GPIO_ENABLE); + + /* GPI6, GPI7 interrupt level 4.0 */ + or_l((4<<28)|(4<<24), &INTPRI5); + + enable_scrollstrip_interrupts(); +} + +bool button_hold(void) +{ + /* GPIO51 active low */ + return (GPIO1_READ & (1<<19))?false:true; +} + +/* + * Get button pressed from hardware + */ +int button_read_device(void) +{ + int btn = BUTTON_NONE; + int data = 0; + static bool hold_button = false; + + bool hold_button_old; + + + /* read hold buttons status */ + hold_button_old = hold_button; + hold_button = button_hold(); + +#ifndef BOOTLOADER + /* Only main hold affects backlight */ + if (hold_button != hold_button_old) + backlight_hold_changed(hold_button); +#endif + + /* Skip if main hold is active */ + if (!hold_button) + { + data = adc_scan(ADC_BUTTONS); + + if (data < 800) /* middle */ + { + if (data < 450) + { + if (data > 250) + btn |= BUTTON_FF; + } + else /* 800 - 450 */ + { + if (data > 600) + btn |= BUTTON_REW; + } + } + else /* data > 800 */ + { + if (data < 1150) + if (data > 950) + btn |= BUTTON_REC; + } + } + + /* Handle GPIOs buttons + * + * GPIO56 active high PLAY/PAUSE/ON + * GPIO45 active low ENTER + * GPIO41 active low MENU + */ + + data = GPIO1_READ; + + if (!hold_button) + { + if (data & (1<<24)) + btn |= BUTTON_PLAY; + + if (!(data & (1<<13))) + btn |= BUTTON_ENTER; + + if (!(data & (1<<9))) + btn |= BUTTON_MENU; + } + + return btn; +} diff --git a/firmware/target/coldfire/mpio/hd300/button-target.h b/firmware/target/coldfire/mpio/hd300/button-target.h new file mode 100644 index 0000000000..5cb2ae8bf2 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd300/button-target.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * 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 _BUTTON_TARGET_H_ +#define _BUTTON_TARGET_H_ + +#include +#include "config.h" + +#define HAS_BUTTON_HOLD +#define BUTTON_REMOTE 0 + +bool button_hold(void); +void button_init_device(void); +int button_read_device(void); + +/* HD300 specific button codes */ +#define BUTTON_PLAY 0x00000001 +#define BUTTON_REW 0x00000004 +#define BUTTON_FF 0x00000002 +#define BUTTON_UP 0x00000008 +#define BUTTON_DOWN 0x00000010 +#define BUTTON_REC 0x00000020 +#define BUTTON_MENU 0x00000040 +#define BUTTON_ENTER 0x00000080 + +#define BUTTON_LEFT BUTTON_REW +#define BUTTON_RIGHT BUTTON_FF +#define BUTTON_ON BUTTON_PLAY + +#define BUTTON_MAIN (BUTTON_PLAY|BUTTON_REW|BUTTON_FF|\ + BUTTON_UP|BUTTON_DOWN|BUTTON_REC|BUTTON_MENU|\ + BUTTON_ENTER) + +#define POWEROFF_BUTTON BUTTON_PLAY +#define POWEROFF_COUNT 30 + +#endif /* _BUTTON_TARGET_H_ */ diff --git a/firmware/target/coldfire/mpio/hd300/lcd-as-hd300.S b/firmware/target/coldfire/mpio/hd300/lcd-as-hd300.S new file mode 100644 index 0000000000..e5b04001dc --- /dev/null +++ b/firmware/target/coldfire/mpio/hd300/lcd-as-hd300.S @@ -0,0 +1,227 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Adopted for MPIO HD300 by Marcin Bukat + * Copyright (C) 2007 by Jens Arnold + * + * 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 "config.h" +#include "cpu.h" + + .section .icode,"ax",@progbits + + .align 2 + .global lcd_write_command + .type lcd_write_command,@function + +lcd_write_command: + move.l (4, %sp), %d0 + move.w %d0, 0xf0000000 + rts +.wc_end: + .size lcd_write_command,.wc_end-lcd_write_command + + + .align 2 + .global lcd_write_command_ex + .type lcd_write_command_ex,@function + +lcd_write_command_ex: + lea.l 0xf0000000, %a0 + + move.l (4, %sp), %d0 /* Command */ + move.w %d0, (%a0)+ /* Write to LCD, set A0 = 1 */ + + move.l (8, %sp), %d0 /* Data */ + cmp.l #-1, %d0 /* -1? */ + beq.b .last + move.w %d0, (%a0) /* Write to LCD */ + + move.l (12, %sp), %d0 /* Data */ + cmp.l #-1, %d0 /* -1? */ + beq.b .last + move.w %d0, (%a0) /* Write to LCD */ + +.last: + rts +.wcex_end: + .size lcd_write_command_ex,.wcex_end-lcd_write_command_ex + + + .align 2 + .global lcd_write_data + .type lcd_write_data,@function + +lcd_write_data: + movem.l (4, %sp), %a0-%a1 /* Data pointer */ + move.l %a1, %d0 /* Length */ + lea 0xf0000002, %a1 + +.loop: + /* When running in IRAM, this loop takes 10 cycles plus the LCD write. + The 10 cycles are necessary to follow the LCD timing specs + at 140MHz */ + nop /* 3(0/0) */ + move.b (%a0)+, %d1 /* 3(1/0) */ + move.w %d1, (%a1) /* 1(0/1) */ + subq.l #1, %d0 /* 1(0/0) */ + bne .loop /* 2(0/0) */ + rts +.wd_end: + .size lcd_write_data,.wd_end-lcd_write_data + + + .align 2 + .global lcd_grey_data + .type lcd_grey_data,@function + + /* The main loop assumes the buffers are in SDRAM. Otherwise the LCD + * controller timing won't be met at 124 MHz and graphical glitches + * will occur. */ + +lcd_grey_data: + lea.l (-11*4, %sp), %sp + movem.l %d2-%d7/%a2-%a6, (%sp) /* free some registers */ + movem.l (11*4+4, %sp), %a0-%a2 /* values, phases, length */ + lea.l (%a1, %a2.l*4), %a2 /* end address */ + lea 0xf0000002, %a3 /* LCD data port */ + moveq.l #24, %d6 /* shift count */ + move.l #0xc30c3, %d7 /* bit shuffle factor */ + + moveq.l #12, %d2 + add.l %a1, %d2 + and.l #0xfffffff0, %d2 /* first line bound */ + cmp.l %d2, %a2 /* end address lower than first line bound? */ + bhs.s 1f + move.l %a2, %d2 /* -> adjust end address of head loop */ +1: + cmp.l %a1, %d2 + bls.s .g_hend + +.g_hloop: + move.l (%a1), %d0 /* fetch 4 pixel phases */ + + move.l %d0, %d1 + and.l #0x80808080, %d1 /* separate MSBs of the 4 phases */ + eor.l %d1, %d0 /* clear them in %d0 */ + add.l (%a0)+, %d0 /* add 4 pixel values to the phases */ + move.l %d0, (%a1)+ /* store new phases, advance pointer */ + + lsr.l #1, %d1 /* %d1 = .0.......1.......2.......3...... */ + mulu.l %d7, %d1 /* %d1 = 00112233112233..2233....33...... */ + not.l %d1 /* negate bits */ + lsr.l %d6, %d1 /* %d1 = ........................00112233 */ + move.w %d1, (%a3) /* write pixel block */ + + cmp.l %a1, %d2 /* go up to first line bound */ + bhi.s .g_hloop + +.g_hend: + cmp.l %a1, %a2 + bls.w .g_tend + lea.l (-12, %a2), %a2 + cmp.l %a1, %a2 + bls.s .g_lend + +.g_lloop: + movem.l (%a1), %d0-%d3 /* fetch 4 blocks of 4 pixel phases each */ + + move.l %d0, %d4 /* calculate first pixel block */ + and.l #0x80808080, %d4 + eor.l %d4, %d0 + lsr.l #1, %d4 + mulu.l %d7, %d4 + not.l %d4 + lsr.l %d6, %d4 + + move.w %d4, (%a3) /* write first pixel block to LCD */ + + move.l %d1, %d5 /* calculate second pixel block */ + and.l #0x80808080, %d5 + eor.l %d5, %d1 + lsr.l #1, %d5 + mulu.l %d7, %d5 + not.l %d5 + lsr.l %d6, %d5 + + move.l %d2, %d4 /* calculate third pixel block */ + and.l #0x80808080, %d4 + eor.l %d4, %d2 + lsr.l #1, %d4 + mulu.l %d7, %d4 + not.l %d4 + lsr.l %d6, %d4 + + move.w %d5, (%a3) /* write second pixel block to LCD */ + + movem.l (%a0), %d5/%a4-%a6 /* fetch 4 blocks of 4 pixel values each */ + lea.l (16, %a0), %a0 + + move.w %d4, (%a3) /* write third pixel block to LCD */ + + move.l %d3, %d4 /* calculate fourth pixel block */ + and.l #0x80808080, %d4 + eor.l %d4, %d3 + lsr.l #1, %d4 + mulu.l %d7, %d4 + not.l %d4 + lsr.l %d6, %d4 + + add.l %d5, %d0 /* calculate 4*4 new pixel phases */ + add.l %a4, %d1 /* (packed addition) */ + add.l %a5, %d2 + add.l %a6, %d3 + + movem.l %d0-%d3, (%a1) /* store 4*4 new pixel phases */ + lea.l (16, %a1), %a1 + + move.w %d4, (%a3) /* write fourth pixel block to LCD */ + + cmp.l %a1, %a2 /* go up to last line bound */ + bhi.s .g_lloop + +.g_lend: + lea.l (12, %a2), %a2 + cmp.l %a1, %a2 + bls.s .g_tend + +.g_tloop: + move.l (%a1), %d0 /* fetch 4 pixel phases */ + + move.l %d0, %d1 + and.l #0x80808080, %d1 + eor.l %d1, %d0 + add.l (%a0)+, %d0 /* add 4 pixel values to the phases */ + move.l %d0, (%a1)+ /* store new phases, advance pointer */ + + lsr.l #1, %d1 + mulu.l %d7, %d1 + not.l %d1 + lsr.l %d6, %d1 + move.w %d1, (%a3) /* write pixel block */ + + cmp.l %a1, %a2 /* go up to end address */ + bhi.s .g_tloop + +.g_tend: + movem.l (%sp), %d2-%d7/%a2-%a6 /* restore registers */ + lea.l (11*4, %sp), %sp + rts + +.gd_end: + .size lcd_grey_data,.gd_end-lcd_grey_data diff --git a/firmware/target/coldfire/mpio/hd300/lcd-hd300.c b/firmware/target/coldfire/mpio/hd300/lcd-hd300.c new file mode 100644 index 0000000000..10ee59571e --- /dev/null +++ b/firmware/target/coldfire/mpio/hd300/lcd-hd300.c @@ -0,0 +1,244 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Adopted for MPIO HD300 by Marcin Bukat + * Copyright (C) 2007 by Jens Arnold + * + * 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 "config.h" + +#include "system.h" +#include "kernel.h" +#include "lcd.h" + +/*** definitions ***/ + +/* LCD command codes */ +#define LCD_CNTL_POWER_CONTROL 0x25 +#define LCD_CNTL_VOLTAGE_SELECT 0x2b +#define LCD_CNTL_LINE_INVERT_DRIVE 0x36 +#define LCD_CNTL_GRAY_SCALE_PATTERN 0x39 +#define LCD_CNTL_TEMP_GRADIENT_SELECT 0x4e +#define LCD_CNTL_OSC_FREQUENCY 0x5f +#define LCD_CNTL_ON_OFF 0xae +#define LCD_CNTL_OSC_ON_OFF 0xaa +#define LCD_CNTL_OFF_MODE 0xbe +#define LCD_CNTL_POWER_SAVE 0xa8 +#define LCD_CNTL_REVERSE 0xa6 +#define LCD_CNTL_ALL_LIGHTING 0xa4 +#define LCD_CNTL_COMMON_OUTPUT_STATUS 0xc4 +#define LCD_CNTL_COLUMN_ADDRESS_DIR 0xa0 +#define LCD_CNTL_NLINE_ON_OFF 0xe4 +#define LCD_CNTL_DISPLAY_MODE 0x66 +#define LCD_CNTL_DUTY_SET 0x6d +#define LCD_CNTL_ELECTRONIC_VOLUME 0x81 +#define LCD_CNTL_DATA_INPUT_DIR 0x84 +#define LCD_CNTL_DISPLAY_START_LINE 0x8a +#define LCD_CNTL_AREA_SCROLL 0x10 + +#define LCD_CNTL_PAGE 0xb1 +#define LCD_CNTL_COLUMN 0x13 +#define LCD_CNTL_DATA_WRITE 0x1d + +/*** shared semi-private declarations ***/ +extern const unsigned char lcd_dibits[16] ICONST_ATTR; + +/*** hardware configuration ***/ +int lcd_default_contrast(void) +{ + return DEFAULT_CONTRAST_SETTING; +} + +void lcd_set_contrast(int val) +{ + /* Keep val in acceptable hw range */ + if (val < 0) + val = 0; + else if (val > 127) + val = 127; + + lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, val, -1); +} + +void lcd_set_invert_display(bool yesno) +{ + lcd_write_command(LCD_CNTL_REVERSE | (yesno?1:0)); +} + +/* turn the display upside down (call lcd_update() afterwards) */ +void lcd_set_flip(bool yesno) +{ + if (yesno) + { + lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 1); + lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 0); + lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 0); + } + else + { + lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0); + lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1); + lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1); + } +} + +void lcd_init_device(void) +{ + and_l(~0x00000800, &GPIO_FUNCTION); /* CS3 line */ + + /* LCD Reset GPO34 */ + or_l(0x00000004, &GPIO1_ENABLE); /* set as output */ + or_l(0x00000004, &GPIO1_FUNCTION); /* switch to secondary function - GPIO */ + + and_l(~0x00000004, &GPIO1_OUT); /* RESET low */ + sleep(1); /* delay at least 1000 ns */ + or_l(0x00000004, &GPIO1_OUT); /* RESET high */ + sleep(1); + + lcd_write_command(LCD_CNTL_ON_OFF | 1); /* LCD ON */ + lcd_write_command(LCD_CNTL_OFF_MODE | 1); /* OFF -> VCC on drivers */ + lcd_write_command(LCD_CNTL_REVERSE | 0); /* Reverse OFF */ + lcd_write_command(LCD_CNTL_ALL_LIGHTING | 0); /* Normal */ + lcd_write_command(LCD_CNTL_COMMON_OUTPUT_STATUS | 1); /* Reverse dir */ + lcd_write_command_ex(LCD_CNTL_DISPLAY_START_LINE, 0, -1); + lcd_write_command(LCD_CNTL_COLUMN_ADDRESS_DIR | 0); /* Normal */ + lcd_write_command_ex(LCD_CNTL_DISPLAY_MODE, 0, -1); /* Greyscale mode */ + lcd_write_command_ex(LCD_CNTL_GRAY_SCALE_PATTERN, 0x53, -1); + lcd_write_command_ex(LCD_CNTL_DUTY_SET, 0x20, 1); + lcd_write_command_ex(LCD_CNTL_ELECTRONIC_VOLUME, 24, -1); /* 0x18 */ + + lcd_write_command(LCD_CNTL_OSC_ON_OFF | 1); /* Oscillator ON */ + lcd_write_command(LCD_CNTL_POWER_SAVE | 0); + lcd_write_command_ex(LCD_CNTL_VOLTAGE_SELECT, 3, -1); + lcd_write_command_ex(LCD_CNTL_POWER_CONTROL, 0x17, -1); + lcd_write_command_ex(LCD_CNTL_OSC_FREQUENCY, 3, -1); + lcd_write_command(LCD_CNTL_NLINE_ON_OFF | 1); /* N-line ON */ + lcd_write_command_ex(LCD_CNTL_LINE_INVERT_DRIVE, 0x10, -1); + lcd_write_command_ex(LCD_CNTL_TEMP_GRADIENT_SELECT, 0, -1); + + lcd_update(); +} + +/*** update functions ***/ + +/* Performance function that works with an external buffer + note that by and bheight are in 8-pixel units! */ +void lcd_blit_mono(const unsigned char *data, int x, int by, int width, + int bheight, int stride) +{ + const unsigned char *src, *src_end; + unsigned char *dst_u, *dst_l; + static unsigned char upper[LCD_WIDTH] IBSS_ATTR; + static unsigned char lower[LCD_WIDTH] IBSS_ATTR; + unsigned int byte; + + by *= 2; + + while (bheight--) + { + src = data; + src_end = data + width; + dst_u = upper; + dst_l = lower; + do + { + byte = *src++; + *dst_u++ = lcd_dibits[byte & 0x0F]; + byte >>= 4; + *dst_l++ = lcd_dibits[byte & 0x0F]; + } + while (src < src_end); + + lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1); + lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); + lcd_write_command(LCD_CNTL_DATA_WRITE); + lcd_write_data(upper, width); + + lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1); + lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); + lcd_write_command(LCD_CNTL_DATA_WRITE); + lcd_write_data(lower, width); + + data += stride; + } +} + +/* Helper function for lcd_grey_phase_blit(). */ +void lcd_grey_data(unsigned char *values, unsigned char *phases, int count); + +/* Performance function that works with an external buffer + note that by and bheight are in 4-pixel units! */ +void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, + int x, int by, int width, int bheight, int stride) +{ + stride <<= 2; /* 4 pixels per block */ + while (bheight--) + { + lcd_write_command_ex(LCD_CNTL_PAGE, by++, -1); + lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); + lcd_write_command(LCD_CNTL_DATA_WRITE); + lcd_grey_data(values, phases, width); + values += stride; + phases += stride; + } +} + +/* Update the display. + This must be called after all other LCD functions that change the display. */ +void lcd_update(void) ICODE_ATTR; +void lcd_update(void) +{ + int y; + + /* Copy display bitmap to hardware */ + for (y = 0; y < LCD_FBHEIGHT; y++) + { + lcd_write_command_ex(LCD_CNTL_PAGE, y, -1); + lcd_write_command_ex(LCD_CNTL_COLUMN, 0, -1); + + lcd_write_command(LCD_CNTL_DATA_WRITE); + lcd_write_data (lcd_framebuffer[y], LCD_WIDTH); + } +} + +/* Update a fraction of the display. */ +void lcd_update_rect(int, int, int, int) ICODE_ATTR; +void lcd_update_rect(int x, int y, int width, int height) +{ + int ymax; + + /* The Y coordinates have to work on even 8 pixel rows */ + ymax = (y + height-1) >> 2; + y >>= 2; + + if(x + width > LCD_WIDTH) + width = LCD_WIDTH - x; + if (width <= 0) + return; /* nothing left to do, 0 is harmful to lcd_write_data() */ + if(ymax >= LCD_FBHEIGHT) + ymax = LCD_FBHEIGHT-1; + + /* Copy specified rectange bitmap to hardware */ + for (; y <= ymax; y++) + { + lcd_write_command_ex(LCD_CNTL_PAGE, y, -1); + lcd_write_command_ex(LCD_CNTL_COLUMN, x, -1); + + lcd_write_command(LCD_CNTL_DATA_WRITE); + lcd_write_data (&lcd_framebuffer[y][x], width); + } +} diff --git a/firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c b/firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c new file mode 100644 index 0000000000..9d95938ff9 --- /dev/null +++ b/firmware/target/coldfire/mpio/hd300/powermgmt-hd300.c @@ -0,0 +1,58 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Marcin Bukat + * + * 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 "config.h" +#include "adc.h" +#include "powermgmt.h" + +const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = +{ + 3600 +}; + +const unsigned short battery_level_shutoff[BATTERY_TYPES_COUNT] = +{ + 3500 +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging disabled */ +const unsigned short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = +{ + { 3500, 3566, 3597, 3619, 3644, 3676, 3732, 3806, 3868, 3937, 4004 } +}; + +/* voltages (millivolt) of 0%, 10%, ... 100% when charging enabled */ +const unsigned short percent_to_volt_charge[11] = +{ + /* values measured over one full charging cycle */ + 3386, 3872, 3904, 3942, 3996, 4029, 4033, 4036, 4038, 4039, 4041 +}; + +/* 3.33V as reference */ +#define BATTERY_SCALE_FACTOR 3330 + + +/* Returns battery voltage from ADC [millivolts] */ +unsigned int battery_adc_voltage(void) +{ + return (adc_read(ADC_BATTERY) * BATTERY_SCALE_FACTOR) >> 11; +} + diff --git a/firmware/target/coldfire/mpio/power-mpio.c b/firmware/target/coldfire/mpio/power-mpio.c index 3034bab82d..5ca3b947b0 100644 --- a/firmware/target/coldfire/mpio/power-mpio.c +++ b/firmware/target/coldfire/mpio/power-mpio.c @@ -122,7 +122,9 @@ bool ide_powered(void) void power_off(void) { +#ifdef HAVE_LCD_SHUTDOWN lcd_shutdown(); +#endif set_irq_level(DISABLE_INTERRUPTS); and_l(~(1<<21), &GPIO1_OUT); /* pull KEEPACT low */ asm("halt"); diff --git a/firmware/target/coldfire/wmcodec-coldfire.c b/firmware/target/coldfire/wmcodec-coldfire.c index 4403b9a2a2..e5bf2d65a8 100644 --- a/firmware/target/coldfire/wmcodec-coldfire.c +++ b/firmware/target/coldfire/wmcodec-coldfire.c @@ -32,7 +32,7 @@ #include "i2s.h" #include "wmcodec.h" -#if defined(MPIO_HD200) +#if defined(MPIO_HD200) || defined(MPIO_HD300) #define I2C_CODEC_ADDRESS 0x34 #define I2C_IFACE I2C_IFACE_1 #endif -- cgit v1.2.3