Subversion Repositories freemyipod

Rev

Rev 710 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
710 theseven 1
//
2
//
3
//    Copyright 2011 TheSeven
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE 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
//    emCORE 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 emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "global.h"
25
#include "thread.h"
26
#include "util.h"
27
#include "lcd.h"
28
 
29
 
30
static struct mutex lcd_mutex IDATA_ATTR;
31
#define fb ((uint32_t*)0x0fc00000)
32
 
33
 
34
void lcd_init()
35
{
36
    mutex_init(&lcd_mutex);
37
}
38
 
39
int lcd_get_width()
40
{
41
    return LCD_WIDTH;
42
}
43
 
44
int lcd_get_height()
45
{
46
    return LCD_HEIGHT;
47
}
48
 
49
int lcd_get_bytes_per_pixel()
50
{
51
    return LCD_BYTESPERPIXEL;
52
}
53
 
54
int lcd_get_format()
55
{
56
    return LCD_FORMAT;
57
}
58
 
59
void lcd_shutdown()
60
{
61
}
62
 
63
bool displaylcd_busy() ICODE_ATTR;
64
bool displaylcd_busy()
65
{
66
    return false;
67
}
68
 
69
void displaylcd_sync() ICODE_ATTR;
70
void displaylcd_sync()
71
{
72
}
73
 
74
void displaylcd_native(unsigned int startx, unsigned int endx,
75
                       unsigned int starty, unsigned int endy, void* data)
76
{
77
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
78
    displaylcd_safe_native(startx, endx, starty, endy, data);
79
    mutex_unlock(&lcd_mutex);
80
}
81
 
82
void displaylcd_safe_native(unsigned int startx, unsigned int endx,
83
                            unsigned int starty, unsigned int endy, void* data)
84
{
85
    int pixels = (endx - startx + 1) * (endy - starty + 1);
86
    if (pixels <= 0) return;
87
    uint32_t* ptr = &fb[starty * LCD_WIDTH + startx];
88
    int rows = endy - starty + 1;
89
    int rowsize = (endx - startx + 1) * 4;
90
    while (rows--)
91
    {
92
        memcpy(ptr, data, rowsize);
93
        ptr += LCD_WIDTH;
94
        data += rowsize;
95
    }
96
}
97
 
98
void filllcd_native(unsigned int startx, unsigned int endx,
99
                    unsigned int starty, unsigned int endy, int color)
100
{
101
    int pixels = (endx - startx + 1) * (endy - starty + 1);
102
    if (pixels <= 0) return;
103
    uint32_t* ptr = &fb[starty * LCD_WIDTH + startx];
104
    int rows = endy - starty + 1;
105
    int rowsize = (endx - startx + 1) * 4;
106
    while (rows--)
107
    {
108
        int i;
109
        for (i = 0; i < rowsize; i += 4) fb[i] = color;
110
        ptr += LCD_WIDTH;
111
    }
112
    mutex_unlock(&lcd_mutex);
113
}
114
 
115
void displaylcd(unsigned int x, unsigned int y, unsigned int width, unsigned int height,
116
                void* data, unsigned int datax, unsigned int datay, unsigned int stride)
117
{
118
    if (width * height <= 0) return;
119
    mutex_lock(&lcd_mutex, TIMEOUT_BLOCK);
120
    uint32_t* ptr = &fb[y * LCD_WIDTH + x];
121
    uint8_t* inptr = &((uint8_t*)data)[datay * stride + datax];
122
    int rowsize = stride * 3;
123
    while (height--)
124
    {
125
        int pixels = width;
126
        uint8_t* ip = inptr;
127
        uint32_t* op = ptr;
128
        while (pixels--)
129
        {
130
            uint32_t value = *ip++ << 16;
131
            value |= *ip++ << 8;
132
            value |= *ip++;
133
            *op++ = value;
134
        }
135
        inptr += rowsize;
136
        ptr += LCD_WIDTH;
137
    }
138
    mutex_unlock(&lcd_mutex);
139
}
140
 
141
void filllcd(unsigned int x, unsigned int y, unsigned int width, unsigned int height, int color)
142
{
143
    filllcd_native(x, y, width, height, color);
144
}
145
 
146
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
147
    ICODE_ATTR __attribute__((naked, noinline));
148
int lcd_translate_color(uint8_t alpha, uint8_t red, uint8_t green, uint8_t blue)
149
{
150
    asm volatile(
151
        "orr r0, r3, r0,lsl#24 \n\t"
152
        "orr r1, r2, r1,lsl#8  \n\t"
153
        "orr r0, r0, r1,lsl#8  \n\t"
154
        "mov pc, lr            \n\t"
155
    );
156
}