diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 1 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/m3/lcd-as-m3.S | 516 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/m3/lcd-m3.c | 305 |
3 files changed, 548 insertions, 274 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 0a8ac2a8e3..1d60ea1016 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -513,6 +513,7 @@ target/coldfire/iaudio/m3/backlight-m3.c target/coldfire/iaudio/m3/button-m3.c target/coldfire/iaudio/m3/fmradio_i2c-m3.c target/coldfire/iaudio/m3/lcd-m3.c +target/coldfire/iaudio/m3/lcd-as-m3.S target/coldfire/iaudio/m3/power-m3.c target/coldfire/iaudio/m3/powermgmt-m3.c target/coldfire/iaudio/m3/system-m3.c diff --git a/firmware/target/coldfire/iaudio/m3/lcd-as-m3.S b/firmware/target/coldfire/iaudio/m3/lcd-as-m3.S new file mode 100644 index 0000000000..5f77e01e86 --- /dev/null +++ b/firmware/target/coldfire/iaudio/m3/lcd-as-m3.S @@ -0,0 +1,516 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Jens Arnold + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#define CLOCK_MASK 0x20000000 +#define DATA_MASK 0x04000000 +#define GPIO_OUT_ADDR 0x80000004 + +#define CS_MASK 0x00010000 +#define RS_MASK 0x00001000 +#define GPIO1_OUT_ADDR 0x800000b4 + + .extern cpu_frequency /* Global variable from system.c */ + + .section .icode,"ax",@progbits + + /* Output 8 bits to the LCD. Instruction order is devised to maximize the + * delay between changing the data line and the CLK L->H transition, which + * makes the LCD controller sample DATA. + * + * Custom calling convention: + * %a0 - GPIO_OUT_ADDR + * %d3 - data byte + * %d6 - DATA_MASK + * %d7 - CLOCK_MASK + * Clobbers: + * %d0..%d3 + */ +.write_byte: + move.w %sr, %d2 + move.w #0x2700, %sr + + move.l (%a0), %d0 /* Get current state of data port */ + move.l %d0, %d1 + and.l %d6, %d1 /* Check current state of data line */ + beq.s 1f /* and set it as previous-state bit */ + bset #8, %d3 +1: + move.l %d3, %d1 /* Compute the 'bit derivative', i.e. a value */ + lsr.l #1, %d1 /* with 1's where the data changes from the */ + eor.l %d1, %d3 /* previous state, and 0's where it doesn't */ + swap %d3 /* Shift data to upper byte */ + lsl.l #8, %d3 + + eor.l %d7, %d0 /* precalculate opposite state of clock line */ + + lsl.l #1,%d3 /* Shift out MSB */ + bcc.s 1f + eor.l %d6, %d0 /* 1: Flip data bit */ +1: + move.l %d0, %d1 + move.l %d0, (%a0) /* Output new state and set CLK = 0*/ + eor.l %d7, %d1 + bra.w .wr_bit7 + + + /* Output 16 bits to the LCD. Instruction order is devised to maximize the + * delay between changing the data line and the CLK L->H transition, which + * makes the LCD controller sample DATA. + * + * Custom calling convention: + * %a0 - GPIO_OUT_ADDR + * %d3 - data word + * %d6 - DATA_MASK + * %d7 - CLOCK_MASK + * Clobbers: + * %d0..%d3 + */ +.write_word: + move.w %sr, %d2 + move.w #0x2700, %sr + + move.l (%a0), %d0 /* Get current state of data port */ + move.l %d0, %d1 + and.l %d6, %d1 /* Check current state of data line */ + beq.s 1f /* and set it as previous-state bit */ + bset #16, %d3 +1: + move.l %d3, %d1 /* Compute the 'bit derivative', i.e. a value */ + lsr.l #1, %d1 /* with 1's where the data changes from the */ + eor.l %d1, %d3 /* previous state, and 0's where it doesn't */ + swap %d3 /* Shift data to upper word */ + + eor.l %d7, %d0 /* precalculate opposite state of clock line */ + + lsl.l #1,%d3 /* Shift out MSB */ + bcc.s 1f + eor.l %d6, %d0 /* 1: Flip data bit */ +1: + move.l %d0, %d1 + move.l %d0, (%a0) /* Output new state and set CLK = 0*/ + eor.l %d7, %d1 + nop + +.macro bit_out + lsl.l #1,%d3 + bcc.s 1f + eor.l %d6, %d0 +1: + move.l %d1, (%a0) /* Set CLK = 1 (delayed) */ + move.l %d0, %d1 + move.l %d0, (%a0) + eor.l %d7, %d1 +.endm + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + +.wr_bit7: + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + bit_out + nop + + nop + move.l %d1, (%a0) /* Set CLK = 1 (delayed) */ + move.w %d2, %sr + rts + + + /* Output 16 bits to the LCD as fast as possible. Use only at < 60MHz. + * + * Custom calling convention: + * %a0 - GPIO_OUT_ADDR + * %d3 - data word + * %d6 - DATA_MASK + * %d7 - CLOCK_MASK + * Clobbers: + * %d0..%d3 + */ +.write_word_fast: + move.w %sr, %d2 /* Get current interrupt level */ + move.w #0x2700, %sr /* Disable interrupts */ + + move.l (%a0), %d0 /* Get current state of data port */ + move.l %d0, %d1 + and.l %d6, %d1 /* Check current state of data line */ + beq.s 1f /* and set it as previous-state bit */ + bset #16, %d3 +1: + move.l %d3, %d1 /* Compute the 'bit derivative', i.e. a value */ + lsr.l #1, %d1 /* with 1's where the data changes from the */ + eor.l %d1, %d3 /* previous state, and 0's where it doesn't */ + swap %d3 /* Shift data to upper byte */ + + move.l %d0, %d1 /* precalculate opposite state of clock line */ + eor.l %d7, %d1 + +.macro bit_out_fast + lsl.l #1,%d3 /* Shift out MSB */ + bcc.s 1f + eor.l %d6, %d0 /* 1: Flip data bit */ + eor.l %d6, %d1 /* for both clock states */ +1: + move.l %d1, (%a0) /* Output new state and set CLK = 0*/ + move.l %d0, (%a0) /* set CLK = 1 */ +.endm + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + bit_out_fast + + move.w %d2, %sr /* Restore interrupt level */ + rts + + + .global lcd_write_command + .type lcd_write_command, @function + +lcd_write_command: + lea.l (-4*4, %sp), %sp + movem.l %d2-%d3/%d6-%d7, (%sp) + + move.l (4*4+4, %sp), %d3 /* cmd */ + + lea.l GPIO_OUT_ADDR, %a0 + lea.l GPIO1_OUT_ADDR, %a1 + move.l #DATA_MASK, %d6 + move.l #CLOCK_MASK, %d7 + + move.l #~(RS_MASK+CS_MASK), %d0 + and.l %d0, (%a1) + + bsr.w .write_byte + + move.l #CS_MASK, %d0 + or.l %d0, (%a1) + + movem.l (%sp), %d2-%d3/%d6-%d7 + lea.l (4*4, %sp), %sp + rts + + + .global lcd_write_command_e + .type lcd_write_command_e, @function + +lcd_write_command_e: + lea.l (-4*4, %sp), %sp + movem.l %d2-%d3/%d6-%d7, (%sp) + + movem.l (4*4+4, %sp), %d2-%d3 /* cmd, data */ + + lea.l GPIO_OUT_ADDR, %a0 + lea.l GPIO1_OUT_ADDR, %a1 + move.l #DATA_MASK, %d6 + move.l #CLOCK_MASK, %d7 + + move.l #~(RS_MASK+CS_MASK), %d0 + and.l %d0, (%a1) + + lsl.l #8, %d2 + or.l %d2, %d3 + bsr.w .write_word + + move.l #CS_MASK, %d0 + or.l %d0, (%a1) + + movem.l (%sp), %d2-%d3/%d6-%d7 + lea.l (4*4, %sp), %sp + rts + + + .global lcd_write_data + .type lcd_write_data, @function + +lcd_write_data: + lea.l (-7*4, %sp), %sp + movem.l %d2-%d4/%d6-%d7/%a2-%a3, (%sp) + + move.l (7*4+4, %sp), %a2 /* p_words */ + move.l (7*4+8, %sp), %d4 /* count */ + + lea.l GPIO_OUT_ADDR, %a0 + lea.l GPIO1_OUT_ADDR, %a1 + move.l #DATA_MASK, %d6 + move.l #CLOCK_MASK, %d7 + + lea.l .write_word, %a3 + move.l cpu_frequency, %d0 + cmp.l #60000000, %d0 + bhi.b 1f + lea.l .write_word_fast, %a3 +1: + + move.l #RS_MASK, %d0 + or.l %d0, (%a1) + move.l #~CS_MASK, %d0 + and.l %d0, (%a1) + +.wd_loop: + clr.l %d3 + move.w (%a2)+, %d3 + jsr (%a3) + subq.l #1, %d4 + bne.s .wd_loop + + move.l #CS_MASK, %d0 + or.l %d0, (%a1) + + movem.l (%sp), %d2-%d4/%d6-%d7/%a2-%a3 + lea.l (7*4, %sp), %sp + rts + + +/*** The following functions are only needed for main LCDs ***/ + + + .global lcd_mono_data + .type lcd_mono_data, @function + +lcd_mono_data: + lea.l (-7*4, %sp), %sp + movem.l %d2-%d4/%d6-%d7/%a2-%a3, (%sp) + + move.l (7*4+4, %sp), %a2 /* p_bytes */ + move.l (7*4+8, %sp), %d4 /* count */ + + lea.l GPIO_OUT_ADDR, %a0 + lea.l GPIO1_OUT_ADDR, %a1 + move.l #DATA_MASK, %d6 + move.l #CLOCK_MASK, %d7 + + lea.l .write_word, %a3 + move.l cpu_frequency, %d0 + cmp.l #60000000, %d0 + bhi.b 1f + lea.l .write_word_fast, %a3 +1: + + move.l #RS_MASK, %d0 + or.l %d0, (%a1) + move.l #~CS_MASK, %d0 + and.l %d0, (%a1) + +.md_loop: + clr.l %d3 + move.b (%a2)+, %d3 + move.l %d3, %d2 + lsl.l #8, %d2 + or.l %d2, %d3 + jsr (%a3) + subq.l #1, %d4 + bne.s .md_loop + + move.l #CS_MASK, %d0 + or.l %d0, (%a1) + + movem.l (%sp), %d2-%d4/%d6-%d7/%a2-%a3 + lea.l (7*4, %sp), %sp + rts + + + .global lcd_grey_data + .type lcd_grey_data,@function + +lcd_grey_data: + lea.l (-9*4, %sp), %sp + movem.l %d2-%d7/%a2-%a4, (%sp) + + movem.l (9*4+4, %sp), %a2-%a4 /* values, phases, length */ + add.l %a4, %a4 + lea.l (%a3, %a4.l*4), %a4 /* end address */ + + lea.l GPIO_OUT_ADDR, %a0 + lea.l GPIO1_OUT_ADDR, %a1 + move.l #DATA_MASK, %d6 + move.l #CLOCK_MASK, %d7 + + move.l #RS_MASK, %d0 + or.l %d0, (%a1) + move.l #~CS_MASK, %d0 + and.l %d0, (%a1) + + clr.l %d5 + move.l (%a3), %d4 /* fetch 4 pixel phases */ + bclr.l #31, %d4 /* Z = !(p0 & 0x80); p0 &= ~0x80; */ + seq.b %d5 /* %d5 = ........................00000000 */ + lsl.l #1, %d5 /* %d5 = .......................00000000. */ + bclr.l #23, %d4 /* Z = !(p1 & 0x80); p1 &= ~0x80; */ + seq.b %d5 /* %d5 = .......................011111111 */ + lsl.l #1, %d5 /* %d5 = ......................011111111. */ + bclr.l #15, %d4 /* Z = !(p2 & 0x80); p2 &= ~0x80; */ + seq.b %d5 /* %d5 = ......................0122222222 */ + lsl.l #1, %d5 /* %d5 = .....................0122222222. */ + bclr.l #7, %d4 /* Z = !(p3 & 0x80); p3 &= ~0x80; */ + seq.b %d5 /* %d5 = .....................01233333333 */ + lsl.l #1, %d5 /* %d5 = ....................01233333333. */ + add.l (%a2)+, %d4 /* add 4 pixel values to the phases */ + move.l %d4, (%a3)+ /* store new phases, advance pointer */ + + move.l (%a3), %d4 /* fetch 4 pixel phases */ + bclr.l #31, %d4 /* Z = !(p0 & 0x80); p0 &= ~0x80; */ + seq.b %d5 /* %d5 = ....................012344444444 */ + lsl.l #1, %d5 /* %d5 = ...................012344444444. */ + bclr.l #23, %d4 /* Z = !(p1 & 0x80); p1 &= ~0x80; */ + seq.b %d5 /* %d5 = ...................0123455555555 */ + lsl.l #1, %d5 /* %d5 = ..................0123455555555. */ + bclr.l #15, %d4 /* Z = !(p2 & 0x80); p2 &= ~0x80; */ + seq.b %d5 /* %d5 = ..................01234566666666 */ + lsl.l #1, %d5 /* %d5 = .................01234566666666. */ + bclr.l #7, %d4 /* Z = !(p3 & 0x80); p3 &= ~0x80; */ + seq.b %d5 /* %d5 = .................012345677777777 */ + lsr.l #7, %d5 /* %d5 = ........................01234567 */ + add.l (%a2)+, %d4 /* add 4 pixel values to the phases */ + move.l %d4, (%a3)+ /* store new phases, advance pointer */ + + move.l %d5, %d3 + lsl.l #8, %d3 + or.l %d5, %d3 + + cmp.l %a3, %a4 + bls.w .gd_last + +.gd_loop: + move.w %sr, %d2 + move.w #0x2700, %sr + + move.l (%a0), %d0 /* Get current state of data port */ + move.l %d0, %d1 + and.l %d6, %d1 /* Check current state of data line */ + beq.s 1f /* and set it as previous-state bit */ + bset #16, %d3 +1: + move.l %d3, %d1 /* Compute the 'bit derivative', i.e. a value */ + lsr.l #1, %d1 /* with 1's where the data changes from the */ + eor.l %d1, %d3 /* previous state, and 0's where it doesn't */ + swap %d3 /* Shift data to upper word */ + + eor.l %d7, %d0 /* precalculate opposite state of clock line */ + + lsl.l #1,%d3 /* Shift out MSB */ + bcc.s 1f + eor.l %d6, %d0 /* 1: Flip data bit */ +1: + move.l %d0, %d1 + move.l %d0, (%a0) /* Output new state and set CLK = 0*/ + eor.l %d7, %d1 + + move.l (%a3), %d4 /* fetch 4 pixel phases */ + bit_out + bclr.l #31, %d4 /* Z = !(p0 & 0x80); p0 &= ~0x80; */ + seq.b %d5 /* %d5 = ........................00000000 */ + lsl.l #1, %d5 /* %d5 = .......................00000000. */ + bit_out + bclr.l #23, %d4 /* Z = !(p1 & 0x80); p1 &= ~0x80; */ + seq.b %d5 /* %d5 = .......................011111111 */ + lsl.l #1, %d5 /* %d5 = ......................011111111. */ + bit_out + bclr.l #15, %d4 /* Z = !(p2 & 0x80); p2 &= ~0x80; */ + seq.b %d5 /* %d5 = ......................0122222222 */ + lsl.l #1, %d5 /* %d5 = .....................0122222222. */ + bit_out + bclr.l #7, %d4 /* Z = !(p3 & 0x80); p3 &= ~0x80; */ + seq.b %d5 /* %d5 = .....................01233333333 */ + lsl.l #1, %d5 /* %d5 = ....................01233333333. */ + bit_out + add.l (%a2)+, %d4 /* add 4 pixel values to the phases */ + bit_out + move.l %d4, (%a3)+ /* store new phases, advance pointer */ + + bit_out + move.l (%a3), %d4 /* fetch 4 pixel phases */ + bit_out + bclr.l #31, %d4 /* Z = !(p0 & 0x80); p0 &= ~0x80; */ + seq.b %d5 /* %d5 = ....................012344444444 */ + lsl.l #1, %d5 /* %d5 = ...................012344444444. */ + bit_out + bclr.l #23, %d4 /* Z = !(p1 & 0x80); p1 &= ~0x80; */ + seq.b %d5 /* %d5 = ...................0123455555555 */ + lsl.l #1, %d5 /* %d5 = ..................0123455555555. */ + bit_out + bclr.l #15, %d4 /* Z = !(p2 & 0x80); p2 &= ~0x80; */ + seq.b %d5 /* %d5 = ..................01234566666666 */ + lsl.l #1, %d5 /* %d5 = .................01234566666666. */ + bit_out + bclr.l #7, %d4 /* Z = !(p3 & 0x80); p3 &= ~0x80; */ + seq.b %d5 /* %d5 = .................012345677777777 */ + lsr.l #7, %d5 /* %d5 = ........................01234567 */ + bit_out + add.l (%a2)+, %d4 /* add 4 pixel values to the phases */ + bit_out + move.l %d4, (%a3)+ /* store new phases, advance pointer */ + + bit_out + nop + bit_out + move.l %d5, %d3 + lsl.l #8, %d3 + or.l %d5, %d3 + + nop + move.l %d1, (%a0) /* Set CLK = 1 (delayed) */ + move.w %d2, %sr + + cmp.l %a3, %a4 + bhi.w .gd_loop + +.gd_last: + bsr.w .write_word + + move.l #CS_MASK, %d0 + or.l %d0, (%a1) + + movem.l (%sp), %d2-%d7/%a2-%a4 + lea.l (9*4, %sp), %sp + rts diff --git a/firmware/target/coldfire/iaudio/m3/lcd-m3.c b/firmware/target/coldfire/iaudio/m3/lcd-m3.c index ae72832a82..81f19bd73f 100644 --- a/firmware/target/coldfire/iaudio/m3/lcd-m3.c +++ b/firmware/target/coldfire/iaudio/m3/lcd-m3.c @@ -61,263 +61,6 @@ static int cached_contrast = DEFAULT_CONTRAST_SETTING; bool initialized = false; -/* Standard low-level byte writer. Requires CLK high on entry */ -static inline void _write_byte(unsigned data) -{ - asm volatile ( - "move.l (%[gpo0]), %%d0 \n" /* Get current state of data line */ - "and.l %[dbit], %%d0 \n" - "beq.s 1f \n" /* and set it as previous-state bit */ - "bset #8, %[data] \n" - "1: \n" - "move.l %[data], %%d0 \n" /* Compute the 'bit derivative', i.e. a value */ - "lsr.l #1, %%d0 \n" /* with 1's where the data changes from the */ - "eor.l %%d0, %[data] \n" /* previous state, and 0's where it doesn't */ - "swap %[data] \n" /* Shift data to upper byte */ - "lsl.l #8, %[data] \n" - - "move.l %[cbit], %%d1 \n" /* Prepare mask for flipping CLK */ - "or.l %[dbit], %%d1 \n" /* and DATA at once */ - - "lsl.l #1,%[data] \n" /* Shift out MSB */ - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" /* 1: Flip both CLK and DATA */ - ".word 0x51fa \n" /* (trapf.w - shadow next insn) */ - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" /* else flip CLK only */ - "eor.l %[cbit], (%[gpo0]) \n" /* Flip CLK again */ - - "lsl.l #1,%[data] \n" /* ..unrolled.. */ - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" - ".word 0x51fa \n" - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" - "eor.l %[cbit], (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" - ".word 0x51fa \n" - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" - "eor.l %[cbit], (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" - ".word 0x51fa \n" - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" - "eor.l %[cbit], (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" - ".word 0x51fa \n" - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" - "eor.l %[cbit], (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" - ".word 0x51fa \n" - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" - "eor.l %[cbit], (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" - ".word 0x51fa \n" - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" - "eor.l %[cbit], (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %%d1, (%[gpo0]) \n" - ".word 0x51fa \n" - "1: \n" - "eor.l %[cbit], (%[gpo0]) \n" - "eor.l %[cbit], (%[gpo0]) \n" - : /* outputs */ - [data]"+d"(data) - : /* inputs */ - [gpo0]"a"(&GPIO_OUT), - [cbit]"d"(0x20000000), - [dbit]"d"(0x04000000) - : /* clobbers */ - "d0", "d1" - ); -} - -/* Fast low-level byte writer. Don't use with high CPU clock. - * Requires CLK high on entry */ -static inline void _write_fast(unsigned data) -{ - asm volatile ( - "move.w %%sr,%%d3 \n" /* Get current interrupt level */ - "move.w #0x2700,%%sr \n" /* Disable interrupts */ - - "move.l (%[gpo0]), %%d0 \n" /* Get current state of data port */ - "move.l %%d0, %%d1 \n" - "and.l %[dbit], %%d1 \n" /* Check current state of data line */ - "beq.s 1f \n" /* and set it as previous-state bit */ - "bset #8, %[data] \n" - "1: \n" - "move.l %[data], %%d1 \n" /* Compute the 'bit derivative', i.e. a value */ - "lsr.l #1, %%d1 \n" /* with 1's where the data changes from the */ - "eor.l %%d1, %[data] \n" /* previous state, and 0's where it doesn't */ - "swap %[data] \n" /* Shift data to upper byte */ - "lsl.l #8, %[data] \n" - - "move.l %%d0, %%d1 \n" /* precalculate opposite state of clock line */ - "eor.l %[cbit], %%d1 \n" - - "lsl.l #1,%[data] \n" /* Shift out MSB */ - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" /* 1: Flip data bit */ - "eor.l %[dbit], %%d1 \n" /* for both clock states */ - "1: \n" - "move.l %%d1, (%[gpo0]) \n" /* Output new state and set CLK */ - "move.l %%d0, (%[gpo0]) \n" /* reset CLK */ - - "lsl.l #1,%[data] \n" /* ..unrolled.. */ - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" - "eor.l %[dbit], %%d1 \n" - "1: \n" - "move.l %%d1, (%[gpo0]) \n" - "move.l %%d0, (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" - "eor.l %[dbit], %%d1 \n" - "1: \n" - "move.l %%d1, (%[gpo0]) \n" - "move.l %%d0, (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" - "eor.l %[dbit], %%d1 \n" - "1: \n" - "move.l %%d1, (%[gpo0]) \n" - "move.l %%d0, (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" - "eor.l %[dbit], %%d1 \n" - "1: \n" - "move.l %%d1, (%[gpo0]) \n" - "move.l %%d0, (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" - "eor.l %[dbit], %%d1 \n" - "1: \n" - "move.l %%d1, (%[gpo0]) \n" - "move.l %%d0, (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" - "eor.l %[dbit], %%d1 \n" - "1: \n" - "move.l %%d1, (%[gpo0]) \n" - "move.l %%d0, (%[gpo0]) \n" - - "lsl.l #1,%[data] \n" - "bcc.s 1f \n" - "eor.l %[dbit], %%d0 \n" - "eor.l %[dbit], %%d1 \n" - "1: \n" - "move.l %%d1, (%[gpo0]) \n" - "move.l %%d0, (%[gpo0]) \n" - - "move.w %%d3, %%sr \n" /* Restore interrupt level */ - : /* outputs */ - [data]"+d"(data) - : /* inputs */ - [gpo0]"a"(&GPIO_OUT), - [cbit]"d"(0x20000000), - [dbit]"d"(0x04000000) - : /* clobbers */ - "d0", "d1", "d2", "d3" - ); -} - -void lcd_write_command(int cmd) -{ - RS_LO; - CS_LO; - _write_byte(cmd); - CS_HI; -} - -void lcd_write_command_e(int cmd, int data) -{ - RS_LO; - CS_LO; - _write_byte(cmd); - _write_byte(data); - CS_HI; -} - -void lcd_write_data(const fb_data *p_words, int count) -{ - const unsigned char *p_bytes = (const unsigned char *)p_words; - const unsigned char *p_end = (const unsigned char *)(p_words + count); - - RS_HI; - CS_LO; - if (cpu_frequency < 50000000) - { - while (p_bytes < p_end) - _write_fast(*p_bytes++); - } - else - { - while (p_bytes < p_end) - _write_byte(*p_bytes++); - } - CS_HI; -} - -static void lcd_mono_data(const unsigned char *p_words, int count) -{ - unsigned data; - const unsigned char *p_bytes = p_words; - const unsigned char *p_end = p_words + count; - - RS_HI; - CS_LO; - if (cpu_frequency < 50000000) - { - while (p_bytes < p_end) - { - data = *p_bytes++; - _write_fast(data); - _write_fast(data); - } - } - else - { - while (p_bytes < p_end) - { - data = *p_bytes++; - _write_byte(data); - _write_byte(data); - } - } - CS_HI; -} - int lcd_default_contrast(void) { return DEFAULT_CONTRAST_SETTING; @@ -457,6 +200,9 @@ void lcd_init_device(void) #endif } +/* Helper function. */ +void lcd_mono_data(const unsigned char *data, int count); + /* 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, @@ -477,36 +223,44 @@ void lcd_blit_mono(const unsigned char *data, int x, int by, int width, } } -/* TODO: implement grey blit function */ +/* 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 8-pixel units! */ void lcd_blit_grey_phase(unsigned char *values, unsigned char *phases, int x, int by, int width, int bheight, int stride) { - (void)values; - (void)phases; - (void)x; - (void)by; - (void)width; - (void)bheight; - (void)stride; + if (initialized) + { + stride <<= 3; /* 8 pixels per block */ + while (bheight--) + { + lcd_write_command(LCD_SET_PAGE | ((by > 5 ? by + 2 : by) & 0xf)); + lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0xf); + + lcd_grey_data(values, phases, width); + values += stride; + phases += stride; + by++; + } + } } /* 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; if (initialized) { - for(y = 0;y < LCD_FBHEIGHT;y++) { + for(y = 0;y < LCD_FBHEIGHT;y++) + { /* Copy display bitmap to hardware. The COM48-COM63 lines are not connected so we have to skip them. Further, the column address doesn't wrap, so we have to update one page at a time. */ - lcd_write_command(LCD_SET_PAGE | (y>5?y+2:y)); + lcd_write_command(LCD_SET_PAGE | (y > 5 ? y + 2 : y)); lcd_write_command_e(LCD_SET_COLUMN | 0, 0); lcd_write_data(lcd_framebuffer[y], LCD_WIDTH); } @@ -514,7 +268,6 @@ void lcd_update(void) } /* 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) { if (initialized) @@ -536,7 +289,7 @@ void lcd_update_rect(int x, int y, int width, int height) COM48-COM63 are not connected, so we need to skip those */ for (; y <= ymax; y++) { - lcd_write_command(LCD_SET_PAGE | ((y > 5?y + 2:y) & 0xf)); + lcd_write_command(LCD_SET_PAGE | ((y > 5 ? y + 2 : y) & 0xf)); lcd_write_command_e(LCD_SET_COLUMN | ((x >> 4) & 0xf), x & 0xf); lcd_write_data(&lcd_framebuffer[y][x], width); @@ -547,19 +300,23 @@ void lcd_update_rect(int x, int y, int width, int height) void lcd_set_invert_display(bool yesno) { cached_invert = yesno; - if(initialized) + if (initialized) lcd_write_command(LCD_REVERSE | yesno); } void lcd_set_flip(bool yesno) { cached_flip = yesno; - if(initialized) { - if(yesno) { + if (initialized) + { + if(yesno) + { lcd_write_command(LCD_SELECT_ADC | 0); lcd_write_command(LCD_SELECT_SHL | 0); lcd_write_command_e(LCD_SET_COM0, 16); - } else { + } + else + { lcd_write_command(LCD_SELECT_ADC | 1); lcd_write_command(LCD_SELECT_SHL | 8); lcd_write_command_e(LCD_SET_COM0, 0); |