OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_AT91SAM3U256_IAR/] [AT91Lib/] [drivers/] [lcd/] [draw_hx8347.c] - Blame information for rev 580

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 580 jeremybenn
/* ----------------------------------------------------------------------------
2
 *         ATMEL Microcontroller Software Support
3
 * ----------------------------------------------------------------------------
4
 * Copyright (c) 2008, Atmel Corporation
5
 *
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions are met:
10
 *
11
 * - Redistributions of source code must retain the above copyright notice,
12
 * this list of conditions and the disclaimer below.
13
 *
14
 * Atmel's name may not be used to endorse or promote products derived from
15
 * this software without specific prior written permission.
16
 *
17
 * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
20
 * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 * ----------------------------------------------------------------------------
28
 */
29
 
30
//------------------------------------------------------------------------------
31
//         Headers
32
//------------------------------------------------------------------------------
33
 
34
#include "draw.h"
35
#include "font.h"
36
#include <board.h>
37
#include <utility/assert.h>
38
#include <hx8347/hx8347.h>
39
 
40
#include <string.h>
41
 
42
//------------------------------------------------------------------------------
43
//         Global functions
44
//------------------------------------------------------------------------------
45
 
46
//------------------------------------------------------------------------------
47
/// Fills the given LCD buffer with a particular color.
48
/// Only works in 24-bits packed mode for now.
49
/// \param pBuffer  LCD buffer to fill.
50
/// \param color  Fill color.
51
//------------------------------------------------------------------------------
52
void LCDD_Fill(void *pBuffer, unsigned int color)
53
{
54
    unsigned int i;
55
    unsigned short color16 = RGB24ToRGB16(color);
56
 
57
 
58
    LCD_SetCursor((void *)BOARD_LCD_BASE, 0, 0);
59
    LCD_WriteRAM_Prepare((void *)BOARD_LCD_BASE);
60
    for (i = 0; i < (BOARD_LCD_WIDTH * BOARD_LCD_HEIGHT); i++) {
61
 
62
        LCD_WriteRAM((void *)BOARD_LCD_BASE, color16);
63
    }
64
}
65
 
66
//------------------------------------------------------------------------------
67
/// Sets the specified pixel to the given color.
68
/// !!! Only works in 24-bits packed mode for now. !!!
69
/// \param pBuffer  LCD buffer to draw on.
70
/// \param x  X-coordinate of pixel.
71
/// \param y  Y-coordinate of pixel.
72
/// \param color  Pixel color.
73
//------------------------------------------------------------------------------
74
void LCDD_DrawPixel(
75
    void *pBuffer,
76
    unsigned int x,
77
    unsigned int y,
78
    unsigned int color)
79
{
80
    unsigned short color16 = RGB24ToRGB16(color);
81
 
82
    LCD_SetCursor(pBuffer, x, y);
83
    LCD_WriteRAM_Prepare(pBuffer);
84
    LCD_WriteRAM(pBuffer, color16);
85
}
86
 
87
//------------------------------------------------------------------------------
88
/// Draws a rectangle inside a LCD buffer, at the given coordinates.
89
/// \param pBuffer  LCD buffer to draw on.
90
/// \param x  X-coordinate of upper-left rectangle corner.
91
/// \param y  Y-coordinate of upper-left rectangle corner.
92
/// \param width  Rectangle width in pixels.
93
/// \param height  Rectangle height in pixels.
94
/// \param color  Rectangle color.
95
//------------------------------------------------------------------------------
96
void LCDD_DrawRectangle(
97
    void *pBuffer,
98
    unsigned int x,
99
    unsigned int y,
100
    unsigned int width,
101
    unsigned int height,
102
    unsigned int color)
103
{
104
    unsigned int rx, ry;
105
 
106
    for (ry=0; ry < height; ry++) {
107
 
108
        for (rx=0; rx < width; rx++) {
109
 
110
            LCDD_DrawPixel(pBuffer, x+rx, y+ry, color);
111
        }
112
    }
113
}
114
 
115
//------------------------------------------------------------------------------
116
/// Draws a string inside a LCD buffer, at the given coordinates. Line breaks
117
/// will be honored.
118
/// \param pBuffer  Buffer to draw on.
119
/// \param x  X-coordinate of string top-left corner.
120
/// \param y  Y-coordinate of string top-left corner.
121
/// \param pString  String to display.
122
/// \param color  String color.
123
//------------------------------------------------------------------------------
124
void LCDD_DrawString(
125
    void *pBuffer,
126
    unsigned int x,
127
    unsigned int y,
128
    const char *pString,
129
    unsigned int color)
130
{
131
    unsigned xorg = x;
132
 
133
    while (*pString != 0) {
134
        if (*pString == '\n') {
135
 
136
            y += gFont.height + 2;
137
            x = xorg;
138
        }
139
        else {
140
 
141
            LCDD_DrawChar(pBuffer, x, y, *pString, color);
142
            x += gFont.width + 2;
143
        }
144
        pString++;
145
    }
146
}
147
 
148
//------------------------------------------------------------------------------
149
/// Returns the width & height in pixels that a string will occupy on the screen
150
/// if drawn using LCDD_DrawString.
151
/// \param pString  String.
152
/// \param pWidth  Pointer for storing the string width (optional).
153
/// \param pHeight  Pointer for storing the string height (optional).
154
/// \return String width in pixels.
155
//------------------------------------------------------------------------------
156
void LCDD_GetStringSize(
157
    const char *pString,
158
    unsigned int *pWidth,
159
    unsigned int *pHeight)
160
{
161
    unsigned int width = 0;
162
    unsigned int height = gFont.height;
163
 
164
    while (*pString != 0) {
165
 
166
        if (*pString == '\n') {
167
 
168
            height += gFont.height + 2;
169
        }
170
        else {
171
 
172
            width += gFont.width + 2;
173
        }
174
        pString++;
175
    }
176
 
177
    if (width > 0) width -= 2;
178
 
179
    if (pWidth) *pWidth = width;
180
    if (pHeight) *pHeight = height;
181
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.