Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
273 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
6
//    This file is part of emBIOS.
7
//
8
//    emBIOS is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emBIOS is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emBIOS.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "thread.h"
26
#include "s5l8702.h"
27
#include "util.h"
28
 
29
 
30
static struct dma_lli
31
{
32
    void* srcaddr;
33
    void* dstaddr;
34
    struct dma_lli* nextlli;
35
    uint32_t control;
36
} lcd_lli[(LCD_WIDTH * LCD_HEIGHT - 1) / 0xfff] IDATA_ATTR __attribute__((aligned(16)));
37
 
38
static uint16_t lcd_color IDATA_ATTR;
39
 
40
 
41
void lcd_init()
42
{
43
}
44
 
45
int lcd_get_width()
46
{
47
    return LCD_WIDTH;
48
}
49
 
50
int lcd_get_height()
51
{
52
    return LCD_HEIGHT;
53
}
54
 
55
int lcd_get_bytes_per_pixel()
56
{
57
    return LCD_BYTESPERPIXEL;
58
}
59
 
60
static void lcd_send_cmd(uint16_t cmd)
61
{
62
    while (LCDSTATUS & 0x10);
63
    LCDWCMD = cmd;
64
}
65
 
66
static void lcd_send_data(uint16_t data)
67
{
68
    while (LCDSTATUS & 0x10);
69
    LCDWDATA = data;
70
}
71
 
72
static uint32_t lcd_detect()
73
{
74
    return (PDAT6 & 0x30) >> 4;
75
}
76
 
77
void lcd_shutdown()
78
{
79
}
80
 
81
bool displaylcd_busy()
82
{
83
    return DMAC0C0CONFIG & 1;
84
}
85
 
86
bool displaylcd_safe()
87
{
88
    return !(DMAC0C0CONFIG & 1);
89
}
90
 
91
void displaylcd_sync()
92
{
93
    while (displaylcd_busy()) sleep(100);
94
}
95
 
96
void displaylcd(unsigned int startx, unsigned int endx,
97
                unsigned int starty, unsigned int endy, void* data, int color)
98
{
99
    displaylcd_sync();
100
    if (lcd_detect() == 3)
101
    {
102
        lcd_send_cmd(0x210);
103
        lcd_send_data(startx);
104
        lcd_send_cmd(0x211);
105
        lcd_send_data(endx);
106
        lcd_send_cmd(0x212);
107
        lcd_send_data(starty);
108
        lcd_send_cmd(0x213);
109
        lcd_send_data(endy);
110
        lcd_send_cmd(0x200);
111
        lcd_send_data(startx);
112
        lcd_send_cmd(0x201);
113
        lcd_send_data(starty);
114
        lcd_send_cmd(0x202);
115
    }
116
    else
117
    {
118
        lcd_send_cmd(0x2a);
119
        lcd_send_data(startx >> 8);
120
        lcd_send_data(startx & 0xff);
121
        lcd_send_data(endx >> 8);
122
        lcd_send_data(endx & 0xff);
123
        lcd_send_cmd(0x2b);
124
        lcd_send_data(starty >> 8);
125
        lcd_send_data(starty & 0xff);
126
        lcd_send_data(endy >> 8);
127
        lcd_send_data(endy & 0xff);
128
        lcd_send_cmd(0x2c);
129
    }
130
    int pixels = (endx - startx + 1) * (endy - starty + 1);
131
    int i;
132
    bool solid = (int)data == -1;
133
    bool last = !ARRAYLEN(lcd_lli) || pixels <= 0xfff;
134
    if (solid) lcd_color = color;
135
    DMAC0C0SRCADDR = solid ? &lcd_color : data;
136
    DMAC0C0DESTADDR = (void*)((int)&LCDWDATA);
137
    DMAC0C0LLI = last ? (void*)0 : lcd_lli;
138
    DMAC0C0CONTROL = 0x70240000 | (last ? pixels : 0xfff)
139
                   | (last ? 0x80000000 : 0) | (solid ? 0 : 0x4000000);
140
    void* origdata=data;
141
    data = (void*)(((uint32_t)data) + 0x1ffe);
142
    for (i = 0, pixels -= 0xfff; i < ARRAYLEN(lcd_lli) && pixels > 0; i++, pixels -= 0xfff)
143
    {
144
        last = i + 1 >= ARRAYLEN(lcd_lli) || pixels <= 0xfff;
145
        lcd_lli[i].srcaddr = solid ? &lcd_color : data;
146
        lcd_lli[i].dstaddr = (void*)((int)&LCDWDATA);
147
        lcd_lli[i].nextlli = last ? (void*)0 : &lcd_lli[i + 1];
148
        lcd_lli[i].control = 0x70240000 | (last ? pixels : 0xfff)
149
                           | (last ? 0x80000000 : 0) | (solid ? 0 : 0x4000000);
150
        data = (void*)(((uint32_t)data) + 0x1ffe);
151
    }
152
    clean_dcache();
153
    DMAC0C0CONFIG = 0x88c1;
154
}
155
 
156
void INT_DMAC0C0()
157
{
158
    DMAC0INTTCCLR = 1;
159
    lcdconsole_callback();
160
}
161
 
162
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
163
    ICODE_ATTR __attribute__((naked, noinline));
164
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
165
{
166
    asm volatile(
167
        "cmp r0, #0xff             \n\t"
168
        "moveq r0, #-1             \n\t"
169
        "moveq pc, lr              \n\t"
170
        "cmp r0, #0                \n\t"
171
        "movne r0, #0xff000000     \n\t"
172
        "orrne r0, r0, #0xff0000   \n\t"
173
        "mov r2, r2,lsr#2          \n\t"
174
        "orr r0, r0, r3,lsr#3      \n\t"
175
        "mov r1, r1,lsr#3          \n\t"
176
        "orr r0, r0, r2,lsl#5      \n\t"
177
        "orr r0, r0, r1,lsl#11     \n\t"
178
        "mov pc, lr                \n\t"
179
    );
180
}