Subversion Repositories freemyipod

Rev

Rev 540 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 540 Rev 560
Line 25... Line 25...
25
#include "thread.h"
25
#include "thread.h"
26
#include "s5l8701.h"
26
#include "s5l8701.h"
27
#include "util.h"
27
#include "util.h"
28
 
28
 
29
 
29
 
30
static struct mutex lcd_mutex;
30
static struct mutex lcd_mutex IDATA_ATTR;
-
 
31
static struct wakeup lcd_wakeup IDATA_ATTR;
-
 
32
 
-
 
33
static bool lcd_dma_busy IDATA_ATTR;
-
 
34
static bool lcd_in_irq IDATA_ATTR;
31
 
35
 
32
 
36
 
33
void lcd_init()
37
void lcd_init()
34
{
38
{
-
 
39
    mutex_init(&lcd_mutex);
-
 
40
    wakeup_init(&lcd_wakeup);
35
    DMACON8 = 0x20590000;
41
    DMACON8 = 0x20590000;
36
    LCDCON = 0xd01;
42
    LCDCON = 0xd01;
37
    LCDPHTIME = 0;
43
    LCDPHTIME = 0;
-
 
44
    lcd_in_irq = false;
-
 
45
    lcd_dma_busy = false;
38
}
46
}
39
 
47
 
40
int lcd_get_width()
48
int lcd_get_width()
41
{
49
{
42
    return LCD_WIDTH;
50
    return LCD_WIDTH;
Line 78... Line 86...
78
}
86
}
79
 
87
 
80
bool displaylcd_busy() ICODE_ATTR;
88
bool displaylcd_busy() ICODE_ATTR;
81
bool displaylcd_busy()
89
bool displaylcd_busy()
82
{
90
{
83
    return DMAALLST2 & 0x70000;
91
    return lcd_dma_busy;
84
}
92
}
85
 
93
 
86
bool displaylcd_safe()
94
bool displaylcd_safe()
87
{
95
{
-
 
96
    lcd_in_irq = true;
-
 
97
    if (!lcd_dma_busy) return true;
88
    return !(DMAALLST2 & 0x70000);
98
    return !(DMAALLST2 & 0x70000);
89
}
99
}
90
 
100
 
91
void displaylcd_sync() ICODE_ATTR;
101
void displaylcd_sync() ICODE_ATTR;
92
void displaylcd_sync()
102
void displaylcd_sync()
93
{
103
{
-
 
104
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
94
    while (displaylcd_busy()) sleep(100);
105
    while (displaylcd_busy()) wakeup_wait(&lcd_wakeup, TIMEOUT_BLOCK);
-
 
106
    mutex_unlock(&lcd_mutex);
95
}
107
}
96
 
108
 
97
void displaylcd_setup(unsigned int startx, unsigned int endx,
109
void displaylcd_setup(unsigned int startx, unsigned int endx,
98
                      unsigned int starty, unsigned int endy) ICODE_ATTR;
110
                      unsigned int starty, unsigned int endy) ICODE_ATTR;
99
void displaylcd_setup(unsigned int startx, unsigned int endx,
111
void displaylcd_setup(unsigned int startx, unsigned int endx,
100
                      unsigned int starty, unsigned int endy)
112
                      unsigned int starty, unsigned int endy)
101
{
113
{
102
    displaylcd_sync();
114
    if (!lcd_in_irq)
-
 
115
    {
103
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
116
        mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
-
 
117
        displaylcd_sync();
-
 
118
    }
104
    if (lcd_detect() == 2)
119
    if (lcd_detect() == 2)
105
    {
120
    {
106
        lcd_send_cmd(0x50);
121
        lcd_send_cmd(0x50);
107
        lcd_send_data(startx);
122
        lcd_send_data(startx);
108
        lcd_send_cmd(0x51);
123
        lcd_send_cmd(0x51);
Line 137... Line 152...
137
    while (pixels & 3)
152
    while (pixels & 3)
138
	{
153
	{
139
        LCDWDATA = *in++;
154
        LCDWDATA = *in++;
140
        pixels--;
155
        pixels--;
141
	}
156
	}
-
 
157
    lcd_dma_busy = true;
142
    DMABASE8 = in;
158
    DMABASE8 = in;
143
    DMACON8 = 0x20590000;
159
    DMACON8 = 0x20590000;
144
    DMATCNT8 = pixels / 4;
160
    DMATCNT8 = pixels / 4;
145
    clean_dcache();
161
    clean_dcache();
146
    DMACOM8 = 4;
162
    DMACOM8 = 4;
Line 171... Line 187...
171
{
187
{
172
    int pixels = (endx - startx + 1) * (endy - starty + 1);
188
    int pixels = (endx - startx + 1) * (endy - starty + 1);
173
    if (pixels <= 0) return;
189
    if (pixels <= 0) return;
174
    displaylcd_setup(startx, endx, starty, endy);
190
    displaylcd_setup(startx, endx, starty, endy);
175
    displaylcd_dma(data, pixels);
191
    displaylcd_dma(data, pixels);
176
    mutex_unlock(&lcd_mutex);
192
    if (!lcd_in_irq) mutex_unlock(&lcd_mutex);
177
}
193
}
178
 
194
 
179
void filllcd_native(unsigned int startx, unsigned int endx,
195
void filllcd_native(unsigned int startx, unsigned int endx,
180
                    unsigned int starty, unsigned int endy, int color)
196
                    unsigned int starty, unsigned int endy, int color)
181
{
197
{
182
    int pixels = (endx - startx + 1) * (endy - starty + 1);
198
    int pixels = (endx - startx + 1) * (endy - starty + 1);
183
    if (pixels <= 0) return;
199
    if (pixels <= 0) return;
184
    displaylcd_setup(startx, endx, starty, endy);
200
    displaylcd_setup(startx, endx, starty, endy);
185
    displaylcd_solid(color, pixels);
201
    displaylcd_solid(color, pixels);
186
    mutex_unlock(&lcd_mutex);
202
    if (!lcd_in_irq) mutex_unlock(&lcd_mutex);
187
}
203
}
188
 
204
 
189
void displaylcd_dither(unsigned int x, unsigned int y, unsigned int width,
205
void displaylcd_dither(unsigned int x, unsigned int y, unsigned int width,
190
                       unsigned int height, void* data, unsigned int datax,
206
                       unsigned int height, void* data, unsigned int datax,
191
                       unsigned int datay, unsigned int stride, bool solid)
207
                       unsigned int datay, unsigned int stride, bool solid)
Line 312... Line 328...
312
}
328
}
313
 
329
 
314
void filllcd(unsigned int x, unsigned int y, unsigned int width, unsigned int height, int color)
330
void filllcd(unsigned int x, unsigned int y, unsigned int width, unsigned int height, int color)
315
{
331
{
316
    if (width * height <= 0) return;
332
    if (width * height <= 0) return;
317
    displaylcd_sync();
-
 
318
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
333
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
-
 
334
    displaylcd_sync();
319
    displaylcd_dither(x, y, width, height, &color, 0, 0, 0, true);
335
    displaylcd_dither(x, y, width, height, &color, 0, 0, 0, true);
320
    mutex_unlock(&lcd_mutex);
336
    mutex_unlock(&lcd_mutex);
321
}
337
}
322
 
338
 
323
void lcd_shutdown()
339
void lcd_shutdown()
Line 354... Line 370...
354
}
370
}
355
 
371
 
356
void INT_DMA8()
372
void INT_DMA8()
357
{
373
{
358
    DMACOM8 = 7;
374
    DMACOM8 = 7;
-
 
375
    lcd_in_irq = true;
-
 
376
    lcd_dma_busy = false;
359
    lcdconsole_callback();
377
    lcdconsole_callback();
-
 
378
    wakeup_signal(&lcd_wakeup);
-
 
379
    lcd_in_irq = false;
360
}
380
}
361
 
381
 
362
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
382
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
363
    ICODE_ATTR __attribute__((naked, noinline));
383
    ICODE_ATTR __attribute__((naked, noinline));
364
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
384
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)