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
//
427 farthen 6
//    This file is part of emCORE.
273 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
273 theseven 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
//
427 farthen 13
//    emCORE is distributed in the hope that it will be useful,
273 theseven 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
427 farthen 19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
273 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "thread.h"
26
#include "s5l8702.h"
27
#include "util.h"
28
 
29
 
278 theseven 30
static struct dma_lli lcd_lli[(LCD_WIDTH * LCD_HEIGHT - 1) / 0xfff]
31
    IDATA_ATTR __attribute__((aligned(16)));
273 theseven 32
 
33
static uint16_t lcd_color IDATA_ATTR;
34
 
35
 
36
void lcd_init()
37
{
38
}
39
 
40
int lcd_get_width()
41
{
42
    return LCD_WIDTH;
43
}
44
 
45
int lcd_get_height()
46
{
47
    return LCD_HEIGHT;
48
}
49
 
50
int lcd_get_bytes_per_pixel()
51
{
52
    return LCD_BYTESPERPIXEL;
53
}
54
 
489 theseven 55
int lcd_get_format()
56
{
57
    return LCD_FORMAT;
58
}
59
 
273 theseven 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);
419 theseven 69
    LCDWDATA = (data & 0xff) | ((data & 0x7f00) << 1);
273 theseven 70
}
71
 
72
static uint32_t lcd_detect()
73
{
74
    return (PDAT6 & 0x30) >> 4;
75
}
76
 
77
bool displaylcd_busy()
78
{
388 theseven 79
    return DMAC0C4CONFIG & 1;
273 theseven 80
}
81
 
82
bool displaylcd_safe()
83
{
388 theseven 84
    return !(DMAC0C4CONFIG & 1);
273 theseven 85
}
86
 
87
void displaylcd_sync()
88
{
89
    while (displaylcd_busy()) sleep(100);
90
}
91
 
92
void displaylcd(unsigned int startx, unsigned int endx,
93
                unsigned int starty, unsigned int endy, void* data, int color)
94
{
95
    displaylcd_sync();
378 theseven 96
    if (lcd_detect() & 2)
273 theseven 97
    {
98
        lcd_send_cmd(0x210);
99
        lcd_send_data(startx);
100
        lcd_send_cmd(0x211);
101
        lcd_send_data(endx);
102
        lcd_send_cmd(0x212);
103
        lcd_send_data(starty);
104
        lcd_send_cmd(0x213);
105
        lcd_send_data(endy);
106
        lcd_send_cmd(0x200);
107
        lcd_send_data(startx);
108
        lcd_send_cmd(0x201);
109
        lcd_send_data(starty);
110
        lcd_send_cmd(0x202);
111
    }
112
    else
113
    {
114
        lcd_send_cmd(0x2a);
115
        lcd_send_data(startx >> 8);
116
        lcd_send_data(startx & 0xff);
117
        lcd_send_data(endx >> 8);
118
        lcd_send_data(endx & 0xff);
119
        lcd_send_cmd(0x2b);
120
        lcd_send_data(starty >> 8);
121
        lcd_send_data(starty & 0xff);
122
        lcd_send_data(endy >> 8);
123
        lcd_send_data(endy & 0xff);
124
        lcd_send_cmd(0x2c);
125
    }
126
    int pixels = (endx - startx + 1) * (endy - starty + 1);
278 theseven 127
    if (pixels <= 0) return;
273 theseven 128
    int i;
129
    bool solid = (int)data == -1;
130
    if (solid) lcd_color = color;
278 theseven 131
    for (i = -1; i < (int)ARRAYLEN(lcd_lli) && pixels > 0; i++, pixels -= 0xfff)
273 theseven 132
    {
278 theseven 133
        bool last = i + 1 >= ARRAYLEN(lcd_lli) || pixels <= 0xfff;
388 theseven 134
        struct dma_lli* lli = i < 0 ? (struct dma_lli*)((int)&DMAC0C4LLI) : &lcd_lli[i];
278 theseven 135
        lli->srcaddr = solid ? &lcd_color : data;
136
        lli->dstaddr = (void*)((int)&LCDWDATA);
137
        lli->nextlli = last ? NULL : &lcd_lli[i + 1];
138
        lli->control = 0x70240000 | (last ? pixels : 0xfff)
139
                     | (last ? 0x80000000 : 0) | (solid ? 0 : 0x4000000);
273 theseven 140
        data = (void*)(((uint32_t)data) + 0x1ffe);
141
    }
142
    clean_dcache();
388 theseven 143
    DMAC0C4CONFIG = 0x88c1;
273 theseven 144
}
145
 
309 theseven 146
void lcd_shutdown()
147
{
148
    displaylcd_sync();
319 theseven 149
    uint32_t type = lcd_detect();
419 theseven 150
    if (type & 2)
319 theseven 151
    {
152
        lcd_send_cmd(0x7);
153
        lcd_send_data(0x172);
154
        lcd_send_cmd(0x30);
155
        lcd_send_data(0x3ff);
156
        sleep(90000);
157
        lcd_send_cmd(0x7);
158
        lcd_send_data(0x120);
159
        lcd_send_cmd(0x30);
160
        lcd_send_data(0x0);
161
        lcd_send_cmd(0x100);
162
        lcd_send_data(0x780);
163
        lcd_send_cmd(0x7);
164
        lcd_send_data(0x0);
165
        lcd_send_cmd(0x101);
166
        lcd_send_data(0x260);
167
        lcd_send_cmd(0x102);
168
        lcd_send_data(0xa9);
169
        sleep(30000);
170
        lcd_send_cmd(0x100);
171
        lcd_send_data(0x700);
172
        lcd_send_cmd(0x100);
173
        lcd_send_data(0x704);
174
    }
175
    else if (type == 1)
176
    {
177
        lcd_send_cmd(0x28);
178
        lcd_send_cmd(0x10);
179
        sleep(100000);
180
    }
181
    else
182
    {
183
        lcd_send_cmd(0x28);
184
        sleep(50000);
185
        lcd_send_cmd(0x10);
186
        sleep(50000);
187
    }
309 theseven 188
}
189
 
388 theseven 190
void INT_DMAC0C4()
273 theseven 191
{
388 theseven 192
    DMAC0INTTCCLR = 0x10;
273 theseven 193
    lcdconsole_callback();
194
}
195
 
196
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
197
    ICODE_ATTR __attribute__((naked, noinline));
198
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
199
{
200
    asm volatile(
201
        "cmp r0, #0xff             \n\t"
202
        "moveq r0, #-1             \n\t"
203
        "moveq pc, lr              \n\t"
204
        "cmp r0, #0                \n\t"
205
        "movne r0, #0xff000000     \n\t"
206
        "orrne r0, r0, #0xff0000   \n\t"
207
        "mov r2, r2,lsr#2          \n\t"
208
        "orr r0, r0, r3,lsr#3      \n\t"
209
        "mov r1, r1,lsr#3          \n\t"
210
        "orr r0, r0, r2,lsl#5      \n\t"
211
        "orr r0, r0, r1,lsl#11     \n\t"
212
        "mov pc, lr                \n\t"
213
    );
214
}