Subversion Repositories freemyipod

Rev

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

Rev 669 Rev 704
Line 23... Line 23...
23
 
23
 
24
#include "global.h"
24
#include "global.h"
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
#include "lcd.h"
28
 
29
 
29
 
30
 
30
static struct mutex lcd_mutex IDATA_ATTR;
31
static struct mutex lcd_mutex IDATA_ATTR;
31
static struct wakeup lcd_wakeup IDATA_ATTR;
32
static struct wakeup lcd_wakeup IDATA_ATTR;
32
 
33
 
33
static bool lcd_dma_busy IDATA_ATTR;
34
static bool lcd_dma_busy IDATA_ATTR;
34
static bool lcd_in_irq IDATA_ATTR;
-
 
35
 
35
 
36
 
36
 
37
void lcd_init()
37
void lcd_init()
38
{
38
{
39
    mutex_init(&lcd_mutex);
39
    mutex_init(&lcd_mutex);
40
    wakeup_init(&lcd_wakeup);
40
    wakeup_init(&lcd_wakeup);
41
    DMACON8 = 0x20590000;
41
    DMACON8 = 0x20590000;
42
    LCDCON = 0xd01;
42
    LCDCON = 0xd01;
43
    LCDPHTIME = 0;
43
    LCDPHTIME = 0;
44
    lcd_in_irq = false;
-
 
45
    lcd_dma_busy = false;
44
    lcd_dma_busy = false;
46
}
45
}
47
 
46
 
48
int lcd_get_width()
47
int lcd_get_width()
49
{
48
{
Line 89... Line 88...
89
bool displaylcd_busy()
88
bool displaylcd_busy()
90
{
89
{
91
    return lcd_dma_busy;
90
    return lcd_dma_busy;
92
}
91
}
93
 
92
 
94
bool displaylcd_safe()
-
 
95
{
-
 
96
    lcd_in_irq = true;
-
 
97
    if (!lcd_dma_busy) return true;
-
 
98
    return !(DMAALLST2 & 0x70000);
-
 
99
}
-
 
100
 
-
 
101
void displaylcd_sync() ICODE_ATTR;
93
void displaylcd_sync() ICODE_ATTR;
102
void displaylcd_sync()
94
void displaylcd_sync()
103
{
95
{
104
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
96
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
105
    while (displaylcd_busy()) wakeup_wait(&lcd_wakeup, TIMEOUT_BLOCK);
97
    while (displaylcd_busy()) wakeup_wait(&lcd_wakeup, TIMEOUT_BLOCK);
106
    mutex_unlock(&lcd_mutex);
98
    mutex_unlock(&lcd_mutex);
107
}
99
}
108
 
100
 
109
void displaylcd_setup(unsigned int startx, unsigned int endx,
101
void displaylcd_setup(unsigned int startx, unsigned int endx,
110
                      unsigned int starty, unsigned int endy) ICODE_ATTR;
102
                      unsigned int starty, unsigned int endy, bool safe) ICODE_ATTR;
111
void displaylcd_setup(unsigned int startx, unsigned int endx,
103
void displaylcd_setup(unsigned int startx, unsigned int endx,
112
                      unsigned int starty, unsigned int endy)
104
                      unsigned int starty, unsigned int endy, bool safe)
113
{
105
{
114
    if (!lcd_in_irq)
106
    if (!safe)
115
    {
107
    {
116
        mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
108
        mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
117
        displaylcd_sync();
109
        displaylcd_sync();
118
    }
110
    }
-
 
111
    else while (DMAALLST2 & 0x70000);
119
    if (lcd_detect() == 2)
112
    if (lcd_detect() == 2)
120
    {
113
    {
121
        lcd_send_cmd(0x50);
114
        lcd_send_cmd(0x50);
122
        lcd_send_data(startx);
115
        lcd_send_data(startx);
123
        lcd_send_cmd(0x51);
116
        lcd_send_cmd(0x51);
Line 185... Line 178...
185
void displaylcd_native(unsigned int startx, unsigned int endx,
178
void displaylcd_native(unsigned int startx, unsigned int endx,
186
                       unsigned int starty, unsigned int endy, void* data)
179
                       unsigned int starty, unsigned int endy, void* data)
187
{
180
{
188
    int pixels = (endx - startx + 1) * (endy - starty + 1);
181
    int pixels = (endx - startx + 1) * (endy - starty + 1);
189
    if (pixels <= 0) return;
182
    if (pixels <= 0) return;
-
 
183
    displaylcd_setup(startx, endx, starty, endy, false);
-
 
184
    displaylcd_dma(data, pixels);
-
 
185
    mutex_unlock(&lcd_mutex);
-
 
186
}
-
 
187
 
-
 
188
void displaylcd_safe_native(unsigned int startx, unsigned int endx,
-
 
189
                            unsigned int starty, unsigned int endy, void* data)
-
 
190
{
-
 
191
    int pixels = (endx - startx + 1) * (endy - starty + 1);
-
 
192
    if (pixels <= 0) return;
190
    displaylcd_setup(startx, endx, starty, endy);
193
    displaylcd_setup(startx, endx, starty, endy, true);
191
    displaylcd_dma(data, pixels);
194
    displaylcd_dma(data, pixels);
192
    if (!lcd_in_irq) mutex_unlock(&lcd_mutex);
-
 
193
}
195
}
194
 
196
 
195
void filllcd_native(unsigned int startx, unsigned int endx,
197
void filllcd_native(unsigned int startx, unsigned int endx,
196
                    unsigned int starty, unsigned int endy, int color)
198
                    unsigned int starty, unsigned int endy, int color)
197
{
199
{
198
    int pixels = (endx - startx + 1) * (endy - starty + 1);
200
    int pixels = (endx - startx + 1) * (endy - starty + 1);
199
    if (pixels <= 0) return;
201
    if (pixels <= 0) return;
200
    displaylcd_setup(startx, endx, starty, endy);
202
    displaylcd_setup(startx, endx, starty, endy, false);
201
    displaylcd_solid(color, pixels);
203
    displaylcd_solid(color, pixels);
202
    if (!lcd_in_irq) mutex_unlock(&lcd_mutex);
204
    mutex_unlock(&lcd_mutex);
203
}
205
}
204
 
206
 
205
void displaylcd_dither(unsigned int x, unsigned int y, unsigned int width,
207
void displaylcd_dither(unsigned int x, unsigned int y, unsigned int width,
206
                       unsigned int height, void* data, unsigned int datax,
208
                       unsigned int height, void* data, unsigned int datax,
207
                       unsigned int datay, unsigned int stride, bool solid)
209
                       unsigned int datay, unsigned int stride, bool solid)
Line 210... Line 212...
210
                       unsigned int height, void* data, unsigned int datax,
212
                       unsigned int height, void* data, unsigned int datax,
211
                       unsigned int datay, unsigned int stride, bool solid)
213
                       unsigned int datay, unsigned int stride, bool solid)
212
{
214
{
213
    __asm__ volatile("    muls r12, r2, r3             \n");
215
    __asm__ volatile("    muls r12, r2, r3             \n");
214
    __asm__ volatile("    bxeq lr                      \n");
216
    __asm__ volatile("    bxeq lr                      \n");
215
    __asm__ volatile("    stmfd sp!, {r2-r11,lr}       \n");
217
    __asm__ volatile("    stmfd sp!, {r1-r11,lr}       \n");
-
 
218
    __asm__ volatile("    mov r12, #0                  \n");
-
 
219
    __asm__ volatile("    str r12, [sp]                \n");
216
    __asm__ volatile("    mov r12, r2                  \n");
220
    __asm__ volatile("    mov r12, r2                  \n");
217
    __asm__ volatile("    add r8, r2, r2,lsl#1         \n");
221
    __asm__ volatile("    add r8, r2, r2,lsl#1         \n");
218
    __asm__ volatile("    add r3, r1, r3               \n");
222
    __asm__ volatile("    add r3, r1, r3               \n");
219
    __asm__ volatile("    sub r3, r3, #1               \n");
223
    __asm__ volatile("    sub r3, r3, #1               \n");
220
    __asm__ volatile("    mov r2, r1                   \n");
224
    __asm__ volatile("    mov r2, r1                   \n");
221
    __asm__ volatile("    add r1, r0, r12              \n");
225
    __asm__ volatile("    add r1, r0, r12              \n");
222
    __asm__ volatile("    sub r1, r1, #1               \n");
226
    __asm__ volatile("    sub r1, r1, #1               \n");
223
    __asm__ volatile("    bl displaylcd_setup          \n");
227
    __asm__ volatile("    bl displaylcd_setup          \n");
-
 
228
    __asm__ volatile("    add sp, sp, #4               \n");
224
    __asm__ volatile("    mov r0, r8                   \n");
229
    __asm__ volatile("    mov r0, r8                   \n");
225
    __asm__ volatile("    bl malloc                    \n");
230
    __asm__ volatile("    bl malloc                    \n");
226
    __asm__ volatile("    cmp r0, #0                   \n");
231
    __asm__ volatile("    cmp r0, #0                   \n");
227
    __asm__ volatile("    beq displaylcd_dither_unlock \n");
232
    __asm__ volatile("    beq displaylcd_dither_unlock \n");
228
    __asm__ volatile("    mov r2, r8                   \n");
233
    __asm__ volatile("    mov r2, r8                   \n");
Line 367... Line 372...
367
}
372
}
368
 
373
 
369
void INT_DMA8()
374
void INT_DMA8()
370
{
375
{
371
    DMACOM8 = 7;
376
    DMACOM8 = 7;
372
    lcd_in_irq = true;
-
 
373
    lcd_dma_busy = false;
377
    lcd_dma_busy = false;
374
    lcdconsole_callback();
378
    lcdconsole_callback();
375
    wakeup_signal(&lcd_wakeup);
379
    wakeup_signal(&lcd_wakeup);
376
    lcd_in_irq = false;
-
 
377
}
380
}
378
 
381
 
379
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)
380
    ICODE_ATTR __attribute__((naked, noinline));
383
    ICODE_ATTR __attribute__((naked, noinline));
381
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)