summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
authorRafaël Carré <rafael.carre@gmail.com>2009-05-12 13:22:39 +0000
committerRafaël Carré <rafael.carre@gmail.com>2009-05-12 13:22:39 +0000
commitb1d03ccee7066d7e8e218b7cafcd85b17f5549d8 (patch)
treedc0039d583343471b3e3315fd04625fe9212e567 /firmware
parentf2c18d6922257c6610f4c01ed09ce318295bee68 (diff)
FS#10118 & FS#10165 : lcd_blit_yuv() for Sansa Fuze & Sansa e200v2
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20919 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/SOURCES2
-rw-r--r--firmware/target/arm/as3525/lcd-as-e200v2-fuze.S501
-rw-r--r--firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c99
-rw-r--r--firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c121
4 files changed, 676 insertions, 47 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index d96dc8c8a9..7a00bb903a 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1108,6 +1108,7 @@ target/arm/as3525/sansa-clip/powermgmt-clip.c
#ifdef SANSA_E200V2
#ifndef SIMULATOR
target/arm/as3525/sansa-e200v2/lcd-e200v2.c
+target/arm/as3525/lcd-as-e200v2-fuze.S
target/arm/as3525/sansa-e200v2/button-e200v2.c
target/arm/as3525/backlight-e200v2-fuze.c
#ifndef BOOTLOADER
@@ -1142,6 +1143,7 @@ target/arm/as3525/sansa-m200v4/powermgmt-m200v4.c
#ifndef SIMULATOR
target/arm/as3525/sansa-fuze/button-fuze.c
target/arm/as3525/sansa-fuze/lcd-fuze.c
+target/arm/as3525/lcd-as-e200v2-fuze.S
target/arm/as3525/backlight-e200v2-fuze.c
#ifndef BOOTLOADER
target/arm/as3525/powermgmt-as3525.c
diff --git a/firmware/target/arm/as3525/lcd-as-e200v2-fuze.S b/firmware/target/arm/as3525/lcd-as-e200v2-fuze.S
new file mode 100644
index 0000000000..254816cd0e
--- /dev/null
+++ b/firmware/target/arm/as3525/lcd-as-e200v2-fuze.S
@@ -0,0 +1,501 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2007 by Jens Arnold
+ * Heavily based on lcd-as-memframe.c by Michael Sevakis
+ * Adapted for Sansa Fuze/e200v2 by Rafaël Carré
+ *
+ * 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"
+
+#define DBOP_BUSY (1<<10)
+
+/****************************************************************************
+ * void lcd_write_yuv_420_lines(unsigned char const * const src[3],
+ * int width,
+ * int stride);
+ *
+ * |R| |1.000000 -0.000001 1.402000| |Y'|
+ * |G| = |1.000000 -0.334136 -0.714136| |Pb|
+ * |B| |1.000000 1.772000 0.000000| |Pr|
+ * Scaled, normalized, rounded and tweaked to yield RGB 565:
+ * |R| |74 0 101| |Y' - 16| >> 9
+ * |G| = |74 -24 -51| |Cb - 128| >> 8
+ * |B| |74 128 0| |Cr - 128| >> 9
+ *
+ * Write four RGB565 pixels in the following order on each loop:
+ * 1 3 + > down
+ * 2 4 \/ left
+ */
+ .section .icode, "ax", %progbits
+ .align 2
+ .global lcd_write_yuv420_lines
+ .type lcd_write_yuv420_lines, %function
+lcd_write_yuv420_lines:
+ @ r0 = yuv_src
+ @ r1 = width
+ @ r2 = stride
+ stmfd sp!, { r4-r12 } @ save non-scratch
+ ldmia r0, { r4, r5, r6 } @ r4 = yuv_src[0] = Y'_p
+ @ r5 = yuv_src[1] = Cb_p
+ @ r6 = yuv_src[2] = Cr_p
+ @ r0 = scratch
+ sub r2, r2, #1 @
+ mov r3, #0xC8000000 @
+ orr r3, r3, #0x120000 @ r3 = DBOP_BASE
+10: @ loop line @
+ ldrb r7, [r4], #1 @ r7 = *Y'_p++;
+ ldrb r8, [r5], #1 @ r8 = *Cb_p++;
+ ldrb r9, [r6], #1 @ r9 = *Cr_p++;
+ @
+ sub r7, r7, #16 @ r7 = Y = (Y' - 16)*74
+ add r12, r7, r7, asl #2 @ actually (Y' - 16)*37 and shift right
+ add r7, r12, r7, asl #5 @ by one less when adding - same for all
+ @
+ sub r8, r8, #128 @ Cb -= 128
+ sub r9, r9, #128 @ Cr -= 128
+ @
+ add r10, r9, r9, asl #1 @ r10 = Cr*51 + Cb*24
+ add r10, r10, r10, asl #4 @
+ add r10, r10, r8, asl #3 @
+ add r10, r10, r8, asl #4 @
+ @
+ add r11, r9, r9, asl #2 @ r9 = Cr*101
+ add r11, r11, r9, asl #5 @
+ add r9, r11, r9, asl #6 @
+ @
+ add r8, r8, #2 @ r8 = bu = (Cb*128 + 128) >> 8
+ mov r8, r8, asr #2 @
+ add r9, r9, #256 @ r9 = rv = (r9 + 256) >> 9
+ mov r9, r9, asr #9 @
+ rsb r10, r10, #128 @ r10 = guv = (-r10 + 128) >> 8
+ mov r10, r10, asr #8 @
+ @ compute R, G, and B
+ add r0, r8, r7, asr #8 @ r0 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #8 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #7 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r0, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 15f @ no clamp @
+ cmp r0, #31 @ clamp b
+ mvnhi r0, r0, asr #31 @
+ andhi r0, r0, #31 @
+ cmp r11, #31 @ clamp r
+ mvnhi r11, r11, asr #31 @
+ andhi r11, r11, #31 @
+ cmp r7, #63 @ clamp g
+ mvnhi r7, r7, asr #31 @
+ andhi r7, r7, #63 @
+15: @ no clamp @
+ @
+ ldrb r12, [r4, r2] @ r12 = Y' = *(Y'_p + stride)
+ @
+ orr r0, r0, r11, lsl #11 @ r0 = (r << 11) | b
+ orr r0, r0, r7, lsl #5 @ r0 = (r << 11) | (g << 5) | b
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ sub r7, r12, #16 @ r7 = Y = (Y' - 16)*74
+ add r12, r7, r7, asl #2 @
+ add r7, r12, r7, asl #5 @
+ @ compute R, G, and B
+ add r0, r8, r7, asr #8 @ r0 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #8 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #7 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r0, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 15f @ no clamp @
+ cmp r0, #31 @ clamp b
+ mvnhi r0, r0, asr #31 @
+ andhi r0, r0, #31 @
+ cmp r11, #31 @ clamp r
+ mvnhi r11, r11, asr #31 @
+ andhi r11, r11, #31 @
+ cmp r7, #63 @ clamp g
+ mvnhi r7, r7, asr #31 @
+ andhi r7, r7, #63 @
+15: @ no clamp @
+ @
+ ldrb r12, [r4], #1 @ r12 = Y' = *(Y'_p++)
+ @
+ orr r0, r0, r11, lsl #11 @ r0 = (r << 11) | b
+ orr r0, r0, r7, lsl #5 @ r0 = (r << 11) | (g << 5) | b
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ sub r7, r12, #16 @ r7 = Y = (Y' - 16)*74
+ add r12, r7, r7, asl #2 @
+ add r7, r12, r7, asl #5 @
+ @ compute R, G, and B
+ add r0, r8, r7, asr #8 @ r0 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #8 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #7 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r0, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 15f @ no clamp @
+ cmp r0, #31 @ clamp b
+ mvnhi r0, r0, asr #31 @
+ andhi r0, r0, #31 @
+ cmp r11, #31 @ clamp r
+ mvnhi r11, r11, asr #31 @
+ andhi r11, r11, #31 @
+ cmp r7, #63 @ clamp g
+ mvnhi r7, r7, asr #31 @
+ andhi r7, r7, #63 @
+15: @ no clamp @
+ @
+ ldrb r12, [r4, r2] @ r12 = Y' = *(Y'_p + stride)
+ @
+ @
+ orr r0, r0, r11, lsl #11 @ r0 = (r << 11) | b
+ orr r0, r0, r7, lsl #5 @ r0 = (r << 11) | (g << 5) | b
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ sub r7, r12, #16 @ r7 = Y = (Y' - 16)*74
+ add r12, r7, r7, asl #2 @
+ add r7, r12, r7, asl #5 @
+ @ compute R, G, and B
+ add r0, r8, r7, asr #8 @ r0 = b = (Y >> 9) + bu
+ add r11, r9, r7, asr #8 @ r11 = r = (Y >> 9) + rv
+ add r7, r10, r7, asr #7 @ r7 = g = (Y >> 8) + guv
+ @
+ orr r12, r0, r11 @ check if clamping is needed...
+ orr r12, r12, r7, asr #1 @ ...at all
+ cmp r12, #31 @
+ bls 15f @ no clamp @
+ cmp r0, #31 @ clamp b
+ mvnhi r0, r0, asr #31 @
+ andhi r0, r0, #31 @
+ cmp r11, #31 @ clamp r
+ mvnhi r11, r11, asr #31 @
+ andhi r11, r11, #31 @
+ cmp r7, #63 @ clamp g
+ mvnhi r7, r7, asr #31 @
+ andhi r7, r7, #63 @
+15: @ no clamp @
+ @
+ orr r0, r0, r11, lsl #11 @ r0 = (r << 11) | b
+ orr r0, r0, r7, lsl #5 @ r0 = (r << 11) | (g << 5) | b
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ subs r1, r1, #2 @ subtract block from width
+ bgt 10b @ loop line @
+ @
+ ldmfd sp!, { r4-r12 } @ restore registers and return
+ bx lr @
+ .ltorg @ dump constant pool
+ .size lcd_write_yuv420_lines, .-lcd_write_yuv420_lines
+
+/****************************************************************************
+ * void lcd_write_yuv_420_lines_odither(unsigned char const * const src[3],
+ * int width,
+ * int stride,
+ * int x_screen,
+ * int y_screen);
+ *
+ * |R| |1.000000 -0.000001 1.402000| |Y'|
+ * |G| = |1.000000 -0.334136 -0.714136| |Pb|
+ * |B| |1.000000 1.772000 0.000000| |Pr|
+ * Red scaled at twice g & b but at same precision to place it in correct
+ * bit position after multiply and leave instruction count lower.
+ * |R| |258 0 408| |Y' - 16|
+ * |G| = |149 -49 -104| |Cb - 128|
+ * |B| |149 258 0| |Cr - 128|
+ *
+ * Write four RGB565 pixels in the following order on each loop:
+ * 1 3 + > down
+ * 2 4 \/ left
+ *
+ * Kernel pattern (raw|rotated|use order):
+ * 5 3 4 2 2 6 3 7 row0 row2 > down
+ * 1 7 0 6 | 4 0 5 1 | 2 4 6 0 3 5 7 1 col0 left
+ * 4 2 5 3 | 3 7 2 6 | 3 5 7 1 2 4 6 0 col2 \/
+ * 0 6 1 7 5 1 4 0
+ */
+ .section .icode, "ax", %progbits
+ .align 2
+ .global lcd_write_yuv420_lines_odither
+ .type lcd_write_yuv420_lines_odither, %function
+lcd_write_yuv420_lines_odither:
+ @ r0 = yuv_src
+ @ r1 = width
+ @ r2 = stride
+ @ r3 = x_screen
+ @ [sp] = y_screen
+ stmfd sp!, { r4-r12, lr } @ save non-scratch
+ ldmia r0, { r4, r5, r6 } @ r4 = yuv_src[0] = Y'_p
+ @ r5 = yuv_src[1] = Cb_p
+ @ r6 = yuv_src[2] = Cr_p
+ @
+ sub r2, r2, #1 @
+ ldr r14, [sp, #40] @ Line up pattern and kernel quadrant
+ eor r14, r14, r3 @
+ and r14, r14, #0x2 @
+ mov r14, r14, lsl #6 @ 0x00 or 0x80
+ mov r3, #0xC8000000 @
+ orr r3, r3, #0x120000 @ r3 = DBOP_BASE
+10: @ loop line @
+ @
+ ldrb r7, [r4], #1 @ r7 = *Y'_p++;
+ ldrb r8, [r5], #1 @ r8 = *Cb_p++;
+ ldrb r9, [r6], #1 @ r9 = *Cr_p++;
+ @
+ eor r14, r14, #0x80 @ flip pattern quadrant
+ @
+ sub r7, r7, #16 @ r7 = Y = (Y' - 16)*149
+ add r12, r7, r7, asl #2 @
+ add r12, r12, r12, asl #4 @
+ add r7, r12, r7, asl #6 @
+ @
+ sub r8, r8, #128 @ Cb -= 128
+ sub r9, r9, #128 @ Cr -= 128
+ @
+ add r10, r8, r8, asl #4 @ r10 = guv = Cr*104 + Cb*49
+ add r10, r10, r8, asl #5 @
+ add r10, r10, r9, asl #3 @
+ add r10, r10, r9, asl #5 @
+ add r10, r10, r9, asl #6 @
+ @
+ mov r8, r8, asl #1 @ r8 = bu = Cb*258
+ add r8, r8, r8, asl #7 @
+ @
+ add r9, r9, r9, asl #1 @ r9 = rv = Cr*408
+ add r9, r9, r9, asl #4 @
+ mov r9, r9, asl #3 @
+ @
+ @ compute R, G, and B
+ add r0, r8, r7 @ r0 = b' = Y + bu
+ add r11, r9, r7, asl #1 @ r11 = r' = Y*2 + rv
+ rsb r7, r10, r7 @ r7 = g' = Y + guv
+ @
+ @ r8 = bu, r9 = rv, r10 = guv
+ @
+ sub r12, r0, r0, lsr #5 @ r0 = 31/32*b + b/256
+ add r0, r12, r0, lsr #8 @
+ @
+ sub r12, r11, r11, lsr #5 @ r11 = 31/32*r + r/256
+ add r11, r12, r11, lsr #8 @
+ @
+ sub r12, r7, r7, lsr #6 @ r7 = 63/64*g + g/256
+ add r7, r12, r7, lsr #8 @
+ @
+ add r12, r14, #0x100 @
+ @
+ add r0, r0, r12 @ b = r0 + delta
+ add r11, r11, r12, lsl #1 @ r = r11 + delta*2
+ add r7, r7, r12, lsr #1 @ g = r7 + delta/2
+ @
+ orr r12, r0, r11, asr #1 @ check if clamping is needed...
+ orr r12, r12, r7 @ ...at all
+ movs r12, r12, asr #15 @
+ beq 15f @ no clamp @
+ movs r12, r0, asr #15 @ clamp b
+ mvnne r0, r12, lsr #15 @
+ andne r0, r0, #0x7c00 @ mask b only if clamped
+ movs r12, r11, asr #16 @ clamp r
+ mvnne r11, r12, lsr #16 @
+ movs r12, r7, asr #15 @ clamp g
+ mvnne r7, r12, lsr #15 @
+15: @ no clamp @
+ @
+ ldrb r12, [r4, r2] @ r12 = Y' = *(Y'_p + stride)
+ @
+ and r11, r11, #0xf800 @ pack pixel
+ and r7, r7, #0x7e00 @ r0 = pixel = (r & 0xf800) |
+ orr r11, r11, r7, lsr #4 @ ((g & 0x7e00) >> 4) |
+ orr r0, r11, r0, lsr #10 @ (b >> 10)
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ sub r7, r12, #16 @ r7 = Y = (Y' - 16)*149
+ add r12, r7, r7, asl #2 @
+ add r12, r12, r12, asl #4 @
+ add r7, r12, r7, asl #6 @
+ @ compute R, G, and B
+ add r0, r8, r7 @ r0 = b' = Y + bu
+ add r11, r9, r7, asl #1 @ r11 = r' = Y*2 + rv
+ rsb r7, r10, r7 @ r7 = g' = Y + guv
+ @
+ sub r12, r0, r0, lsr #5 @ r0 = 31/32*b' + b'/256
+ add r0, r12, r0, lsr #8 @
+ @
+ sub r12, r11, r11, lsr #5 @ r11 = 31/32*r' + r'/256
+ add r11, r12, r11, lsr #8 @
+ @
+ sub r12, r7, r7, lsr #6 @ r7 = 63/64*g' + g'/256
+ add r7, r12, r7, lsr #8 @
+ @
+ add r12, r14, #0x200 @
+ @
+ add r0, r0, r12 @ b = r0 + delta
+ add r11, r11, r12, lsl #1 @ r = r11 + delta*2
+ add r7, r7, r12, lsr #1 @ g = r7 + delta/2
+ @
+ orr r12, r0, r11, asr #1 @ check if clamping is needed...
+ orr r12, r12, r7 @ ...at all
+ movs r12, r12, asr #15 @
+ beq 15f @ no clamp @
+ movs r12, r0, asr #15 @ clamp b
+ mvnne r0, r12, lsr #15 @
+ andne r0, r0, #0x7c00 @ mask b only if clamped
+ movs r12, r11, asr #16 @ clamp r
+ mvnne r11, r12, lsr #16 @
+ movs r12, r7, asr #15 @ clamp g
+ mvnne r7, r12, lsr #15 @
+15: @ no clamp @
+ @
+ ldrb r12, [r4], #1 @ r12 = Y' = *(Y'_p++)
+
+ and r11, r11, #0xf800 @ pack pixel
+ and r7, r7, #0x7e00 @ r0 = pixel = (r & 0xf800) |
+ orr r11, r11, r7, lsr #4 @ ((g & 0x7e00) >> 4) |
+ orr r0, r11, r0, lsr #10 @ (b >> 10)
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ sub r7, r12, #16 @ r7 = Y = (Y' - 16)*149
+ add r12, r7, r7, asl #2 @
+ add r12, r12, r12, asl #4 @
+ add r7, r12, r7, asl #6 @
+ @ compute R, G, and B
+ add r0, r8, r7 @ r0 = b' = Y + bu
+ add r11, r9, r7, asl #1 @ r11 = r' = Y*2 + rv
+ rsb r7, r10, r7 @ r7 = g' = Y + guv
+ @
+ @ r8 = bu, r9 = rv, r10 = guv
+ @
+ sub r12, r0, r0, lsr #5 @ r0 = 31/32*b' + b'/256
+ add r0, r12, r0, lsr #8 @
+ @
+ sub r12, r11, r11, lsr #5 @ r11 = 31/32*r' + r'/256
+ add r11, r12, r11, lsr #8 @
+ @
+ sub r12, r7, r7, lsr #6 @ r7 = 63/64*g' + g'/256
+ add r7, r12, r7, lsr #8 @
+ @
+ add r12, r14, #0x300 @
+ @
+ add r0, r0, r12 @ b = r0 + delta
+ add r11, r11, r12, lsl #1 @ r = r11 + delta*2
+ add r7, r7, r12, lsr #1 @ g = r7 + delta/2
+ @
+ orr r12, r0, r11, asr #1 @ check if clamping is needed...
+ orr r12, r12, r7 @ ...at all
+ movs r12, r12, asr #15 @
+ beq 15f @ no clamp @
+ movs r12, r0, asr #15 @ clamp b
+ mvnne r0, r12, lsr #15 @
+ andne r0, r0, #0x7c00 @ mask b only if clamped
+ movs r12, r11, asr #16 @ clamp r
+ mvnne r11, r12, lsr #16 @
+ movs r12, r7, asr #15 @ clamp g
+ mvnne r7, r12, lsr #15 @
+15: @ no clamp @
+ @
+ ldrb r12, [r4, r2] @ r12 = Y' = *(Y'_p + stride)
+ @
+ and r11, r11, #0xf800 @ pack pixel
+ and r7, r7, #0x7e00 @ r0 = pixel = (r & 0xf800) |
+ orr r11, r11, r7, lsr #4 @ ((g & 0x7e00) >> 4) |
+ orr r0, r11, r0, lsr #10 @ (b >> 10)
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ sub r7, r12, #16 @ r7 = Y = (Y' - 16)*149
+ add r12, r7, r7, asl #2 @
+ add r12, r12, r12, asl #4 @
+ add r7, r12, r7, asl #6 @
+ @ compute R, G, and B
+ add r0, r8, r7 @ r0 = b' = Y + bu
+ add r11, r9, r7, asl #1 @ r11 = r' = Y*2 + rv
+ rsb r7, r10, r7 @ r7 = g' = Y + guv
+ @
+ sub r12, r0, r0, lsr #5 @ r0 = 31/32*b + b/256
+ add r0, r12, r0, lsr #8 @
+ @
+ sub r12, r11, r11, lsr #5 @ r11 = 31/32*r + r/256
+ add r11, r12, r11, lsr #8 @
+ @
+ sub r12, r7, r7, lsr #6 @ r7 = 63/64*g + g/256
+ add r7, r12, r7, lsr #8 @
+ @
+ @ This element is zero - use r14 @
+ @
+ add r0, r0, r14 @ b = r0 + delta
+ add r11, r11, r14, lsl #1 @ r = r11 + delta*2
+ add r7, r7, r14, lsr #1 @ g = r7 + delta/2
+ @
+ orr r12, r0, r11, asr #1 @ check if clamping is needed...
+ orr r12, r12, r7 @ ...at all
+ movs r12, r12, asr #15 @
+ beq 15f @ no clamp @
+ movs r12, r0, asr #15 @ clamp b
+ mvnne r0, r12, lsr #15 @
+ andne r0, r0, #0x7c00 @ mask b only if clamped
+ movs r12, r11, asr #16 @ clamp r
+ mvnne r11, r12, lsr #16 @
+ movs r12, r7, asr #15 @ clamp g
+ mvnne r7, r12, lsr #15 @
+15: @ no clamp @
+ @
+ and r11, r11, #0xf800 @ pack pixel
+ and r7, r7, #0x7e00 @ r0 = pixel = (r & 0xf800) |
+ orr r11, r11, r7, lsr #4 @ ((g & 0x7e00) >> 4) |
+ orr r0, r11, r0, lsr #10 @ (b >> 10)
+ strh r0, [r3, #0x10] @ write pixel
+1: @ busy @
+ ldr r7, [r3,#0xc] @ r7 = DBOP_STATUS
+ tst r7, #DBOP_BUSY @ fifo not empty?
+ beq 1b @
+ @
+ subs r1, r1, #2 @ subtract block from width
+ bgt 10b @ loop line @
+ @
+ ldmfd sp!, { r4-r12, pc } @ restore registers and return
+ .ltorg @ dump constant pool
+ .size lcd_write_yuv420_lines_odither, .-lcd_write_yuv420_lines_odither
diff --git a/firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c b/firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c
index 30ba8911ea..ef21893494 100644
--- a/firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c
+++ b/firmware/target/arm/as3525/sansa-e200v2/lcd-e200v2.c
@@ -74,7 +74,7 @@ static volatile bool lcd_busy = false;
#define R_GAMMA_GRAD_ADJ_NEG 0x37
#define R_GAMMA_AMP_ADJ_RES_POS 0x38
-#define R_GAMMA_AMP_AVG_ADJ_RES_NEG 0x39
+#define R_GAMMA_AMP_AVG_ADJ_RES_NEG 0x39
#define R_GATE_SCAN_POS 0x40
#define R_VERT_SCROLL_CONTROL 0x41
@@ -89,6 +89,7 @@ static volatile bool lcd_busy = false;
static unsigned short r_entry_mode = R_ENTRY_MODE_HORZ_NORMAL;
#define R_ENTRY_MODE_VERT 0x7038
#define R_ENTRY_MODE_SOLID_VERT 0x1038
+#define R_ENTRY_MODE_VIDEO 0x7020
/* Reverse Flag */
@@ -182,7 +183,7 @@ void lcd_set_invert_display(bool yesno)
void lcd_set_flip(bool yesno)
{
display_flipped = yesno;
-
+
r_entry_mode = yesno ? R_ENTRY_MODE_HORZ_FLIPPED :
R_ENTRY_MODE_HORZ_NORMAL;
}
@@ -253,13 +254,13 @@ static void _display_on(void)
/* DC12-10 = 000b: Step-up1 = clock/8,
* DC02-00 = 000b: Step-up2 = clock/16,
* VC2-0 = 010b: VciOUT = 0.87 * VciLVL */
- lcd_write_reg(R_POWER_CONTROL2, 0x0002);
+ lcd_write_reg(R_POWER_CONTROL2, 0x0002);
/* VRH3-0 = 1000b: Vreg1OUT = REGP * 1.90 */
lcd_write_reg(R_POWER_CONTROL3, 0x0008);
lcd_delay(40);
-
+
lcd_write_reg(R_POWER_CONTROL4, 0x0000); /* VCOMG = 0 */
/* This register is unknown */
@@ -270,8 +271,8 @@ static void _display_on(void)
lcd_delay(10);
- lcd_write_reg(R_POWER_CONTROL2, 0x0000);
- lcd_write_reg(R_POWER_CONTROL3, 0x0013);
+ lcd_write_reg(R_POWER_CONTROL2, 0x0000);
+ lcd_write_reg(R_POWER_CONTROL3, 0x0013);
lcd_delay(20);
@@ -296,7 +297,7 @@ static void _display_on(void)
lcd_write_reg(R_GATE_SCAN_POS, 0);
lcd_write_reg(R_VERT_SCROLL_CONTROL, 0);
- lcd_window(0, 0, LCD_WIDTH-1, LCD_HEIGHT-1);
+ lcd_window(0, 0, LCD_WIDTH-1, LCD_HEIGHT-1);
lcd_write_reg(R_1ST_SCR_DRV_POS, (LCD_HEIGHT-1) << 8);
lcd_write_reg(R_2ND_SCR_DRV_POS, (LCD_HEIGHT-1) << 8);
@@ -356,6 +357,30 @@ bool lcd_active(void)
/*** update functions ***/
+static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
+
+/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
+extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
+ int width,
+ int stride);
+extern void lcd_write_yuv420_lines_odither(unsigned char const * const src[3],
+ int width,
+ int stride,
+ int x_screen, /* To align dither pattern */
+ int y_screen);
+
+void lcd_yuv_set_options(unsigned options)
+{
+ lcd_yuv_options = options;
+}
+
+static void lcd_window_blit(int xmin, int ymin, int xmax, int ymax)
+{
+ lcd_write_reg(R_HORIZ_RAM_ADDR_POS, ((LCD_WIDTH-1 - xmin) << 8) | (LCD_WIDTH-1 - xmax));
+ lcd_write_reg(R_VERT_RAM_ADDR_POS, (ymax << 8) | ymin);
+ lcd_write_reg(R_RAM_ADDR_SET, (ymin << 8) | (LCD_WIDTH-1 - xmin));
+}
+
/* Performance function to blit a YUV bitmap directly to the LCD
* src_x, src_y, width and height should be even
* x, y, width and height have to be within LCD bounds
@@ -364,14 +389,58 @@ void lcd_blit_yuv(unsigned char * const src[3],
int src_x, int src_y, int stride,
int x, int y, int width, int height)
{
- (void)src;
- (void)src_x;
- (void)src_y;
- (void)stride;
- (void)x;
- (void)y;
- (void)width;
- (void)height;
+ unsigned char const * yuv_src[3];
+ off_t z;
+
+ lcd_busy = true;
+
+ /* Sorry, but width and height must be >= 2 or else */
+ width &= ~1;
+ height >>= 1;
+
+ z = stride*src_y;
+ yuv_src[0] = src[0] + z + src_x;
+ yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
+ yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
+
+ lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VIDEO);
+
+ if (lcd_yuv_options & LCD_YUV_DITHER)
+ {
+ do
+ {
+ lcd_window_blit(y, x, y+1, x+width-1);
+
+ /* Start write to GRAM */
+ lcd_write_cmd(R_WRITE_DATA_2_GRAM);
+
+ lcd_write_yuv420_lines_odither(yuv_src, width, stride, x, y);
+ yuv_src[0] += stride << 1; /* Skip down two luma lines */
+ yuv_src[1] += stride >> 1; /* Skip down one chroma line */
+ yuv_src[2] += stride >> 1;
+ y+=2;
+ }
+ while (--height > 0);
+ }
+ else
+ {
+ do
+ {
+ lcd_window_blit(y, x, y+1, x+width-1);
+
+ /* Start write to GRAM */
+ lcd_write_cmd(R_WRITE_DATA_2_GRAM);
+
+ lcd_write_yuv420_lines(yuv_src, width, stride);
+ yuv_src[0] += stride << 1; /* Skip down two luma lines */
+ yuv_src[1] += stride >> 1; /* Skip down one chroma line */
+ yuv_src[2] += stride >> 1;
+ y+=2;
+ }
+ while (--height > 0);
+ }
+
+ lcd_busy = false;
}
/* Update the display.
diff --git a/firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c b/firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c
index 3e08ba4dff..141b890861 100644
--- a/firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c
+++ b/firmware/target/arm/as3525/sansa-fuze/lcd-fuze.c
@@ -37,7 +37,9 @@
#define R_WRITE_DATA_2_GRAM 0x22
#define R_ENTRY_MODE_HORZ 0x7030
+#define R_ENTRY_MODE_VERT 0x7038
+static unsigned lcd_yuv_options SHAREDBSS_ATTR = 0;
static bool display_on = false; /* is the display turned on? */
static bool display_flipped = false;
static int xoffset = 20; /* needed for flip */
@@ -189,7 +191,7 @@ void lcd_enable(bool on)
* avoid irritating flash on backlight on */
while(delay--);
lcd_activation_call_hook();
-
+
}
else
{
@@ -210,22 +212,94 @@ bool lcd_active(void)
/*** update functions ***/
-/* Performance function to blit a YUV bitmap directly to the LCD
- * src_x, src_y, width and height should be even
- * x, y, width and height have to be within LCD bounds
- */
+/* Set horizontal window addresses */
+static void lcd_window_x(int xmin, int xmax)
+{
+ xmin += xoffset;
+ xmax += xoffset;
+ lcd_write_reg(0x46, (xmax << 8) | xmin);
+ lcd_write_reg(0x20, xmin);
+}
+
+/* Set vertical window addresses */
+static void lcd_window_y(int ymin, int ymax)
+{
+ lcd_write_reg(0x47, ymax);
+ lcd_write_reg(0x48, ymin);
+ lcd_write_reg(0x21, ymin);
+}
+
+void lcd_yuv_set_options(unsigned options)
+{
+ lcd_yuv_options = options;
+}
+
+/* Line write helper function for lcd_yuv_blit. Write two lines of yuv420. */
+extern void lcd_write_yuv420_lines(unsigned char const * const src[3],
+ int width,
+ int stride);
+extern void lcd_write_yuv420_lines_odither(unsigned char const * const src[3],
+ int width,
+ int stride,
+ int x_screen, /* To align dither pattern */
+ int y_screen);
+/* Performance function to blit a YUV bitmap directly to the LCD */
void lcd_blit_yuv(unsigned char * const src[3],
int src_x, int src_y, int stride,
int x, int y, int width, int height)
{
- (void)src;
- (void)src_x;
- (void)src_y;
- (void)stride;
- (void)x;
- (void)y;
- (void)width;
- (void)height;
+ unsigned char const * yuv_src[3];
+ off_t z;
+
+ lcd_busy = true;
+
+ lcd_write_reg(R_ENTRY_MODE, R_ENTRY_MODE_VERT);
+
+ /* Sorry, but width and height must be >= 2 or else */
+ width &= ~1;
+ height >>= 1;
+
+ z = stride*src_y;
+ yuv_src[0] = src[0] + z + src_x;
+ yuv_src[1] = src[1] + (z >> 2) + (src_x >> 1);
+ yuv_src[2] = src[2] + (yuv_src[1] - src[1]);
+
+ lcd_window_x(x, x + width - 1);
+
+ if (lcd_yuv_options & LCD_YUV_DITHER)
+ {
+ do
+ {
+ lcd_window_y(y, y + 1);
+ /* Start write to GRAM */
+ lcd_write_cmd(R_WRITE_DATA_2_GRAM);
+
+ lcd_write_yuv420_lines_odither(yuv_src, width, stride, x, y);
+ yuv_src[0] += stride << 1; /* Skip down two luma lines */
+ yuv_src[1] += stride >> 1; /* Skip down one chroma line */
+ yuv_src[2] += stride >> 1;
+ y += 2;
+ }
+ while (--height > 0);
+ }
+ else
+ {
+ do
+ {
+ lcd_window_y(y, y + 1);
+ /* Start write to GRAM */
+ lcd_write_cmd(R_WRITE_DATA_2_GRAM);
+
+ lcd_write_yuv420_lines(yuv_src, width, stride);
+ yuv_src[0] += stride << 1; /* Skip down two luma lines */
+ yuv_src[1] += stride >> 1; /* Skip down one chroma line */
+ yuv_src[2] += stride >> 1;
+ y += 2;
+ }
+ while (--height > 0);
+ }
+
+ lcd_busy = false;
}
void lcd_init_device()
@@ -242,23 +316,6 @@ void lcd_init_device()
_display_on();
}
-/* Set horizontal window addresses */
-void lcd_window_x(int xmin, int xmax)
-{
- xmin += xoffset;
- xmax += xoffset;
- lcd_write_reg(0x46, (xmax << 8) | xmin);
- lcd_write_reg(0x20, xmin);
-}
-
-/* Set vertical window addresses */
-void lcd_window_y(int ymin, int ymax)
-{
- lcd_write_reg(0x47, ymax);
- lcd_write_reg(0x48, ymin);
- lcd_write_reg(0x21, ymin);
-}
-
/* Update the display.
This must be called after all other LCD functions that change the display. */
void lcd_update(void)
@@ -272,7 +329,7 @@ void lcd_update(void)
lcd_window_x(0, LCD_WIDTH - 1);
lcd_window_y(0, LCD_HEIGHT - 1);
- /* Start write to GRAM */
+ /* Start write to GRAM */
lcd_write_cmd(R_WRITE_DATA_2_GRAM);
/* Write data */
@@ -313,7 +370,7 @@ void lcd_update_rect(int x, int y, int width, int height)
lcd_window_x(x, xmax);
lcd_window_y(y, ymax);
- /* Start write to GRAM */
+ /* Start write to GRAM */
lcd_write_cmd(R_WRITE_DATA_2_GRAM);
ptr = (unsigned short *)&lcd_framebuffer[y][x];