Subversion Repositories freemyipod

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
268 theseven 1
//
2
//
3
//    Copyright 2010 TheSeven
4
//
5
//
427 farthen 6
//    This file is part of emCORE.
268 theseven 7
//
427 farthen 8
//    emCORE is free software: you can redistribute it and/or
268 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,
268 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/>.
268 theseven 20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "thread.h"
26
#include "s5l8720.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)));
268 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
 
268 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);
69
    LCDWDATA = data;
70
}
71
 
72
void lcd_shutdown()
73
{
74
}
75
 
76
bool displaylcd_busy()
77
{
78
    return DMAC0C0CONFIG & 1;
79
}
80
 
81
bool displaylcd_safe()
82
{
83
    return !(DMAC0C0CONFIG & 1);
84
}
85
 
86
void displaylcd_sync()
87
{
88
    while (displaylcd_busy()) sleep(100);
89
}
90
 
91
void displaylcd(unsigned int startx, unsigned int endx,
92
                unsigned int starty, unsigned int endy, void* data, int color)
93
{
94
    displaylcd_sync();
95
    lcd_send_cmd(0x2a);
96
    lcd_send_data(((startx & 0x7f00) << 1) | (startx & 0xff));
97
    lcd_send_data(((endx & 0x7f00) << 1) | (endx & 0xff));
98
    lcd_send_cmd(0x2b);
99
    lcd_send_data(((starty & 0x7f00) << 1) | (starty & 0xff));
100
    lcd_send_data(((endy & 0x7f00) << 1) | (endy & 0xff));
101
    lcd_send_cmd(0x2c);
102
    int pixels = (endx - startx + 1) * (endy - starty + 1);
103
    int i;
104
    bool solid = (int)data == -1;
105
    if (solid) lcd_color = color;
278 theseven 106
    for (i = -1; i < (int)ARRAYLEN(lcd_lli) && pixels > 0; i++, pixels -= 0xfff)
268 theseven 107
    {
278 theseven 108
        bool last = i + 1 >= ARRAYLEN(lcd_lli) || pixels <= 0xfff;
109
        struct dma_lli* lli = i < 0 ? (struct dma_lli*)((int)&DMAC0C0LLI) : &lcd_lli[i];
110
        lli->srcaddr = solid ? &lcd_color : data;
111
        lli->dstaddr = (void*)((int)&LCDWDATA);
112
        lli->nextlli = last ? NULL : &lcd_lli[i + 1];
113
        lli->control = 0x70240000 | (last ? pixels : 0xfff)
114
                     | (last ? 0x80000000 : 0) | (solid ? 0 : 0x4000000);
268 theseven 115
        data = (void*)(((uint32_t)data) + 0x1ffe);
116
    }
117
    clean_dcache();
118
    DMAC0C0CONFIG = 0x88c1;
119
}
120
 
121
void INT_DMAC0C0()
122
{
123
    DMAC0INTTCCLR = 1;
124
    lcdconsole_callback();
125
}
126
 
127
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
128
    ICODE_ATTR __attribute__((naked, noinline));
129
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
130
{
131
    asm volatile(
132
        "cmp r0, #0xff             \n\t"
133
        "moveq r0, #-1             \n\t"
134
        "moveq pc, lr              \n\t"
135
        "cmp r0, #0                \n\t"
136
        "movne r0, #0xff000000     \n\t"
137
        "orrne r0, r0, #0xff0000   \n\t"
138
        "mov r2, r2,lsr#2          \n\t"
139
        "orr r0, r0, r3,lsr#3      \n\t"
140
        "mov r1, r1,lsr#3          \n\t"
141
        "orr r0, r0, r2,lsl#5      \n\t"
142
        "orr r0, r0, r1,lsl#11     \n\t"
143
        "mov pc, lr                \n\t"
144
    );
145
}