From 044ad7c3987460ede48ff27afd6bdb0ca05a0432 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 4 Jul 2011 20:52:54 +0200 Subject: import at91lib from at91lib_20100901_softpack_1_9_v_1_0_svn_v15011 it's sad to see that atmel doesn't publish their svn repo or has a centralized location or even puts proper version/release info into the library itself --- drivers/lcd/color.h | 132 ++++++++++++++++ drivers/lcd/draw.c | 237 ++++++++++++++++++++++++++++ drivers/lcd/draw.h | 110 +++++++++++++ drivers/lcd/draw_hx8347.c | 387 ++++++++++++++++++++++++++++++++++++++++++++++ drivers/lcd/font.c | 209 +++++++++++++++++++++++++ drivers/lcd/font.h | 112 ++++++++++++++ drivers/lcd/font10x14.h | 237 ++++++++++++++++++++++++++++ drivers/lcd/lcd.dir | 39 +++++ drivers/lcd/lcdd.c | 138 +++++++++++++++++ drivers/lcd/lcdd.h | 61 ++++++++ drivers/lcd/lcdd_hx8347.c | 147 ++++++++++++++++++ 11 files changed, 1809 insertions(+) create mode 100644 drivers/lcd/color.h create mode 100644 drivers/lcd/draw.c create mode 100644 drivers/lcd/draw.h create mode 100644 drivers/lcd/draw_hx8347.c create mode 100644 drivers/lcd/font.c create mode 100644 drivers/lcd/font.h create mode 100644 drivers/lcd/font10x14.h create mode 100644 drivers/lcd/lcd.dir create mode 100644 drivers/lcd/lcdd.c create mode 100644 drivers/lcd/lcdd.h create mode 100644 drivers/lcd/lcdd_hx8347.c (limited to 'drivers/lcd') diff --git a/drivers/lcd/color.h b/drivers/lcd/color.h new file mode 100644 index 0000000..68128c2 --- /dev/null +++ b/drivers/lcd/color.h @@ -0,0 +1,132 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef COLOR_H +#define COLOR_H + +//------------------------------------------------------------------------------ +/// RGB 24 Bpp +/// RGB 888 +/// R7R6R5R4 R3R2R1R0 G7G6G5G4 G3G2G1G0 B7B6B5B4 B3B2B1B0 +//------------------------------------------------------------------------------ +#define COLOR_BLACK 0x000000 +#define COLOR_WHITE 0xFFFFFF + +#define COLOR_BLUE 0x0000FF +#define COLOR_GREEN 0x00FF00 +#define COLOR_RED 0xFF0000 + +#define COLOR_NAVY 0x000080 +#define COLOR_DARKBLUE 0x00008B +#define COLOR_DARKGREEN 0x006400 +#define COLOR_DARKCYAN 0x008B8B +#define COLOR_CYAN 0x00FFFF +#define COLOR_TURQUOISE 0x40E0D0 +#define COLOR_INDIGO 0x4B0082 +#define COLOR_DARKRED 0x800000 +#define COLOR_OLIVE 0x808000 +#define COLOR_GRAY 0x808080 +#define COLOR_SKYBLUE 0x87CEEB +#define COLOR_BLUEVIOLET 0x8A2BE2 +#define COLOR_LIGHTGREEN 0x90EE90 +#define COLOR_DARKVIOLET 0x9400D3 +#define COLOR_YELLOWGREEN 0x9ACD32 +#define COLOR_BROWN 0xA52A2A +#define COLOR_DARKGRAY 0xA9A9A9 +#define COLOR_SIENNA 0xA0522D +#define COLOR_LIGHTBLUE 0xADD8E6 +#define COLOR_GREENYELLOW 0xADFF2F +#define COLOR_SILVER 0xC0C0C0 +#define COLOR_LIGHTGREY 0xD3D3D3 +#define COLOR_LIGHTCYAN 0xE0FFFF +#define COLOR_VIOLET 0xEE82EE +#define COLOR_AZUR 0xF0FFFF +#define COLOR_BEIGE 0xF5F5DC +#define COLOR_MAGENTA 0xFF00FF +#define COLOR_TOMATO 0xFF6347 +#define COLOR_GOLD 0xFFD700 +#define COLOR_ORANGE 0xFFA500 +#define COLOR_SNOW 0xFFFAFA +#define COLOR_YELLOW 0xFFFF00 + +#endif // #define COLOR_H + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/drivers/lcd/draw.c b/drivers/lcd/draw.c new file mode 100644 index 0000000..e7d5909 --- /dev/null +++ b/drivers/lcd/draw.c @@ -0,0 +1,237 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "draw.h" +#include "font.h" +#include +#include + +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Fills the given LCD buffer with a particular color. +/// Only works in 24-bits packed mode for now. +/// \param pBuffer LCD buffer to fill. +/// \param color Fill color. +//------------------------------------------------------------------------------ +void LCDD_Fill(void *pBuffer, unsigned int color) +{ + unsigned int i; + unsigned char tmpBuffer[12]; + + // Prepare temporary buffer + for (i=0; i < 4; i++) { + + memcpy(&(tmpBuffer[i*3]), &color, 3); + } + + // Copy in LCD buffer + i = 0; + while (i < (BOARD_LCD_FRAMESIZE * 4)) { + + memcpy(&(((unsigned char *) pBuffer)[i]), tmpBuffer, 12); + i += 12; + } +} + +//------------------------------------------------------------------------------ +/// Sets the specified pixel to the given color. +/// !!! Only works in 24-bits packed mode for now. !!! +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of pixel. +/// \param y Y-coordinate of pixel. +/// \param color Pixel color. +//------------------------------------------------------------------------------ +void LCDD_DrawPixel( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int color) +{ + unsigned char *pTmp = &(((unsigned char *) pBuffer)[y*3*BOARD_LCD_WIDTH + x*3]); + + // Modify color when using RGB565 +#ifdef BOARD_LCD_RGB565 + unsigned char r; + unsigned char g; + unsigned char b; + + r = (color >> 16) & 0xFF; + g = (color >> 8) & 0xFF; + b = color & 0xFF; + r = ((r & 0x78) << 1) | ((r & 0x80) >> 5) | ((g & 0x80) >> 4); + g = ((g & 0x7C) << 1); + b = (b & 0xFC); + color = (b << 16) | (g << 8) | r; +#elif defined (BOARD_LCD_BGR565) + unsigned char r; + unsigned char g; + unsigned char b; + + r = (color >> 16) & 0xFF; + g = (color >> 8) & 0xFF; + b = color & 0xFF; + color = (b << 16) | (g << 8) | r; +#endif + + pTmp[0] = (color >> 16) & 0xFF; + pTmp[1] = (color >> 8) & 0xFF; + pTmp[2] = (color >> 0) & 0xFF; +} + +//------------------------------------------------------------------------------ +/// Read pixel of given coordinate. +/// !!! Only works in 24-bits packed mode for now. !!! +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of pixel. +/// \param y Y-coordinate of pixel. +/// \return Pixel color. +//------------------------------------------------------------------------------ +unsigned int LCDD_ReadPixel( + void *pBuffer, + unsigned int x, + unsigned int y) +{ + unsigned char *pTmp = &(((unsigned char *) pBuffer)[y*3*BOARD_LCD_WIDTH + x*3]); + unsigned int color; + +#ifdef BOARD_LCD_RGB565 + color = 0; // TBD +#elif defined (BOARD_LCD_BGR565) + color = ((pTmp[2] << 16) | (pTmp[1] << 8) | pTmp[0]); +#else + color = ((pTmp[0] << 16) | (pTmp[1] << 8) | pTmp[2]); +#endif + + return color; +} + +//------------------------------------------------------------------------------ +/// Draws a rectangle inside a LCD buffer, at the given coordinates. +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of upper-left rectangle corner. +/// \param y Y-coordinate of upper-left rectangle corner. +/// \param width Rectangle width in pixels. +/// \param height Rectangle height in pixels. +/// \param color Rectangle color. +//------------------------------------------------------------------------------ +void LCDD_DrawRectangle( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + unsigned int color) +{ + unsigned int rx, ry; + + for (ry=0; ry < height; ry++) { + + for (rx=0; rx < width; rx++) { + + LCDD_DrawPixel(pBuffer, x+rx, y+ry, color); + } + } +} + +//------------------------------------------------------------------------------ +/// Draws a string inside a LCD buffer, at the given coordinates. Line breaks +/// will be honored. +/// \param pBuffer Buffer to draw on. +/// \param x X-coordinate of string top-left corner. +/// \param y Y-coordinate of string top-left corner. +/// \param pString String to display. +/// \param color String color. +//------------------------------------------------------------------------------ +void LCDD_DrawString( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int color) +{ + unsigned xorg = x; + + while (*pString != 0) { + if (*pString == '\n') { + + y += gFont.height + 2; + x = xorg; + } + else { + + LCDD_DrawChar(pBuffer, x, y, *pString, color); + x += gFont.width + 2; + } + pString++; + } +} + +//------------------------------------------------------------------------------ +/// Returns the width & height in pixels that a string will occupy on the screen +/// if drawn using LCDD_DrawString. +/// \param pString String. +/// \param pWidth Pointer for storing the string width (optional). +/// \param pHeight Pointer for storing the string height (optional). +/// \return String width in pixels. +//------------------------------------------------------------------------------ +void LCDD_GetStringSize( + const char *pString, + unsigned int *pWidth, + unsigned int *pHeight) +{ + unsigned int width = 0; + unsigned int height = gFont.height; + + while (*pString != 0) { + + if (*pString == '\n') { + + height += gFont.height + 2; + } + else { + + width += gFont.width + 2; + } + pString++; + } + + if (width > 0) width -= 2; + + if (pWidth) *pWidth = width; + if (pHeight) *pHeight = height; +} diff --git a/drivers/lcd/draw.h b/drivers/lcd/draw.h new file mode 100644 index 0000000..5690b66 --- /dev/null +++ b/drivers/lcd/draw.h @@ -0,0 +1,110 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Provides simple drawing function to use with the LCD. +/// +/// !!!Usage +/// +/// -# Use LCDD_Fill to fill the LCD buffer with a specific color. +/// -# Draw a pixel on the screen at the specified coordinates using +/// LCDD_DrawPixel. +/// -# Draw a rectangle with LCDD_DrawRectangle. +/// -# Draw a string on the LCD with LCDD_DrawString. +//------------------------------------------------------------------------------ + +#ifndef DRAW_H +#define DRAW_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void LCDD_Fill(void *pBuffer, unsigned int color); + +extern void LCDD_DrawPixel( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int c); + +extern unsigned int LCDD_ReadPixel( + void *pBuffer, + unsigned int x, + unsigned int y); + +extern void LCDD_DrawRectangle( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + unsigned int color); + +extern void LCDD_DrawString( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int color); +extern void LCDD_DrawStringEx( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int color, + unsigned int dir); + +extern void LCDD_DrawStringWithBGColor( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int fontColor, + unsigned int bgColor); + +extern void LCDD_DrawStringWithBGColorEx( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int fontColor, + unsigned int bgColor, + unsigned int dir); + +extern void LCDD_GetStringSize( + const char *pString, + unsigned int *pWidth, + unsigned int *pHeight); + +#endif //#ifndef DRAW_H diff --git a/drivers/lcd/draw_hx8347.c b/drivers/lcd/draw_hx8347.c new file mode 100644 index 0000000..f262d9a --- /dev/null +++ b/drivers/lcd/draw_hx8347.c @@ -0,0 +1,387 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "draw.h" +#include "font.h" +#include +#include +#include + +#include +/// lcd is busy,0 free,1 busy +int gLCDIsBusy = 0; +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +/// indicate the lcd is available for use +//------------------------------------------------------------------------------ +int LCDD_IsBusy() +{ + return gLCDIsBusy; +} +//------------------------------------------------------------------------------ +/// Set lcd to busy +//------------------------------------------------------------------------------ +void LCDD_SetBusy() +{ + gLCDIsBusy = 1; +} +//------------------------------------------------------------------------------ +/// clear lcd to free +//------------------------------------------------------------------------------ +void LCDD_ClearBusy() +{ + gLCDIsBusy = 0; +} +//------------------------------------------------------------------------------ +/// Fills the given LCD buffer with a particular color. +/// Only works in 24-bits packed mode for now. +/// \param pBuffer LCD buffer to fill. +/// \param color Fill color. +//------------------------------------------------------------------------------ +void LCDD_Fill(void *pBuffer, unsigned int color) +{ + unsigned int i; + unsigned short color16 = RGB24ToRGB16(color); + + + LCD_SetCursor((void *)BOARD_LCD_BASE, 0, 0); + LCD_WriteRAM_Prepare((void *)BOARD_LCD_BASE); + for (i = 0; i < (BOARD_LCD_WIDTH * BOARD_LCD_HEIGHT); i++) { + + LCD_WriteRAM((void *)BOARD_LCD_BASE, color16); + } +} + +//------------------------------------------------------------------------------ +/// Sets the specified pixel to the given color. +/// !!! Only works in 24-bits packed mode for now. !!! +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of pixel. +/// \param y Y-coordinate of pixel. +/// \param color Pixel color. +//------------------------------------------------------------------------------ +void LCDD_DrawPixel( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int color) +{ + unsigned short color16 = RGB24ToRGB16(color); + + LCD_SetCursor(pBuffer, x, y); + LCD_WriteRAM_Prepare(pBuffer); + LCD_WriteRAM(pBuffer, color16); +} + +//------------------------------------------------------------------------------ +/// Read pixel of given coordinate. +/// !!! The return pixel is RGB565 format !!! +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of pixel. +/// \param y Y-coordinate of pixel. +/// \return Pixel color. +//------------------------------------------------------------------------------ +unsigned int LCDD_ReadPixel( + void *pBuffer, + unsigned int x, + unsigned int y) +{ + unsigned short readData[4]; + unsigned int color; + + LCD_SetCursor(pBuffer, x, y); + LCD_ReadRAM_Prepare(pBuffer); + readData[0] = LCD_ReadRAM(pBuffer); // Dummy date + readData[1] = LCD_ReadRAM(pBuffer); // color R + readData[2] = LCD_ReadRAM(pBuffer); // color G + readData[3] = LCD_ReadRAM(pBuffer); // color B + color = (((readData[1] & 0xF8) << 8) | + ((readData[2] & 0xFC) << 3) | + ((readData[3] & 0xF8) >> 3)); + + return color; +} + +//------------------------------------------------------------------------------ +/// Draws a rectangle inside a LCD buffer, at the given coordinates. +/// \param pBuffer LCD buffer to draw on. +/// \param x X-coordinate of upper-left rectangle corner. +/// \param y Y-coordinate of upper-left rectangle corner. +/// \param width Rectangle width in pixels. +/// \param height Rectangle height in pixels. +/// \param color Rectangle color. +//------------------------------------------------------------------------------ +void LCDD_DrawRectangle( + void *pBuffer, + unsigned int x, + unsigned int y, + unsigned int width, + unsigned int height, + unsigned int color) +{ + unsigned int rx, ry; + + for (ry=0; ry < height; ry++) { + + for (rx=0; rx < width; rx++) { + + LCDD_DrawPixel(pBuffer, x+rx, y+ry, color); + } + } +} + +//------------------------------------------------------------------------------ +/// Draws a string inside a LCD buffer, at the given coordinates. Line breaks +/// will be honored. +/// \param pBuffer Buffer to draw on. +/// \param x X-coordinate of string top-left corner. +/// \param y Y-coordinate of string top-left corner. +/// \param pString String to display. +/// \param color String color. +//------------------------------------------------------------------------------ +void LCDD_DrawString( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int color) +{ + unsigned xorg = x; + + while (*pString != 0) { + if (*pString == '\n') { + + y += gFont.height + 2; + x = xorg; + } + else { + + LCDD_DrawChar(pBuffer, x, y, *pString, color); + x += gFont.width + 2; + } + pString++; + } +} +//------------------------------------------------------------------------------ +/// Draws a string inside a LCD buffer, at the given coordinates. Line breaks +/// will be honored. +/// \param pBuffer Buffer to draw on. +/// \param x X-coordinate of string top-left corner. +/// \param y Y-coordinate of string top-left corner. +/// \param pString String to display. +/// \param color String color. +/// \param dir The dirciton of the string,0 for horizontal,1 for vertical +//------------------------------------------------------------------------------ +void LCDD_DrawStringEx( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int color, + unsigned int dir) +{ + unsigned int xorg = x; + unsigned int yorg = y; + + if(LCDD_IsBusy()) return; + + gLCDIsBusy = 1; + + if(dir) + { + while (*pString != 0) { + if (*pString == '\n') { + + x -= gFont.height + 2; + y = yorg; + + } + else { + LCDD_DrawCharVertical(pBuffer, x, y, *pString, color); + y += gFont.width + 2; + } + pString++; + } + + } + else + { + while (*pString != 0) { + if (*pString == '\n') { + + y += gFont.height + 2; + x = xorg; + + } + else { + LCDD_DrawChar(pBuffer, x, y, *pString, color); + x += gFont.width + 2; + } + pString++; + } + } + gLCDIsBusy = 0; + +} +//------------------------------------------------------------------------------ +/// Draws a string inside a LCD buffer, at the given coordinates. Line breaks +/// will be honored. +/// \param pBuffer Buffer to draw on. +/// \param x X-coordinate of string top-left corner. +/// \param y Y-coordinate of string top-left corner. +/// \param pString String to display. +/// \param color String color. +//------------------------------------------------------------------------------ +void LCDD_DrawStringWithBGColor( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int fontColor, + unsigned int bgColor) +{ + unsigned xorg = x; + + while (*pString != 0) { + if (*pString == '\n') { + + y += gFont.height + 2; + x = xorg; + } + else { + + LCDD_DrawCharWithBGColor(pBuffer, x, y, *pString, fontColor, bgColor); + x += gFont.width + 2; + } + pString++; + } +} +//------------------------------------------------------------------------------ +/// Draws a string inside a LCD buffer, at the given coordinates. Line breaks +/// will be honored. +/// \param pBuffer Buffer to draw on. +/// \param x X-coordinate of string top-left corner. +/// \param y Y-coordinate of string top-left corner. +/// \param pString String to display. +/// \param color String color. +/// \param dir The dirciton of the string,0 for horizontal,1 for vertical +//------------------------------------------------------------------------------ +void LCDD_DrawStringWithBGColorEx( + void *pBuffer, + unsigned int x, + unsigned int y, + const char *pString, + unsigned int fontColor, + unsigned int bgColor, + unsigned int dir) +{ + unsigned int xorg = x; + unsigned int yorg = y; + + if(LCDD_IsBusy()) return; + + gLCDIsBusy = 1; + + if(dir) + { + while (*pString != 0) { + if (*pString == '\n') { + + x -= gFont.height + 2; + y = yorg; + + } + else { + LCDD_DrawCharVerticalWithBGColor(pBuffer, x, y, *pString, fontColor, bgColor); + y += gFont.width + 2; + } + pString++; + } + } + else + { + while (*pString != 0) { + if (*pString == '\n') { + + y += gFont.height + 2; + x = xorg; + + } + else { + LCDD_DrawCharWithBGColor(pBuffer, x, y, *pString, fontColor, bgColor); + x += gFont.width + 2; + } + pString++; + } + + } + + gLCDIsBusy = 0; + +} +//------------------------------------------------------------------------------ +/// Returns the width & height in pixels that a string will occupy on the screen +/// if drawn using LCDD_DrawString. +/// \param pString String. +/// \param pWidth Pointer for storing the string width (optional). +/// \param pHeight Pointer for storing the string height (optional). +/// \return String width in pixels. +//------------------------------------------------------------------------------ +void LCDD_GetStringSize( + const char *pString, + unsigned int *pWidth, + unsigned int *pHeight) +{ + unsigned int width = 0; + unsigned int height = gFont.height; + + while (*pString != 0) { + + if (*pString == '\n') { + + height += gFont.height + 2; + } + else { + + width += gFont.width + 2; + } + pString++; + } + + if (width > 0) width -= 2; + + if (pWidth) *pWidth = width; + if (pHeight) *pHeight = height; +} diff --git a/drivers/lcd/font.c b/drivers/lcd/font.c new file mode 100644 index 0000000..843c669 --- /dev/null +++ b/drivers/lcd/font.c @@ -0,0 +1,209 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "font.h" +#include "draw.h" +#include "font10x14.h" +#include + +//------------------------------------------------------------------------------ +// Local variables +//------------------------------------------------------------------------------ + +/// Global variable describing the font being instancied. +const Font gFont = {10, 14}; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Draws an ASCII character on the given LCD buffer. +/// \param pBuffer Buffer to write on. +/// \param x X-coordinate of character upper-left corner. +/// \param y Y-coordinate of character upper-left corner. +/// \param c Character to output. +/// \param color Character color. +//------------------------------------------------------------------------------ +void LCDD_DrawChar( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int color) +{ + unsigned int row, col; + + SANITY_CHECK((c >= 0x20) && (c <= 0x7F)); + + for (col = 0; col < 10; col++) { + + for (row = 0; row < 8; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x+col, y+row, color); + } + } + for (row = 0; row < 6; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x+col, y+row+8, color); + } + } + } +} +//------------------------------------------------------------------------------ +/// Draws an ASCII character on the given LCD buffer with 90 degree clockwise rotate . +/// \param pBuffer Buffer to write on. +/// \param x X-coordinate of character upper-left corner, x decreasing by step. +/// \param y Y-coordinate of character upper-left corner, y increasing by step. +/// \param c Character to output. +/// \param color Character color. +//------------------------------------------------------------------------------ +void LCDD_DrawCharVertical( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int color) +{ + unsigned int row, col; + + SANITY_CHECK((c >= 0x20) && (c <= 0x7F)); + + for (col = 0; col < 10; col++) { + + for (row = 0; row < 8; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x-row, y+col, color); + } + } + for (row = 0; row < 6; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x-row-8, y+col, color); + } + } + } +} +//------------------------------------------------------------------------------ +/// Draws an ASCII character on the given LCD buffer. +/// \param pBuffer Buffer to write on. +/// \param x X-coordinate of character upper-left corner. +/// \param y Y-coordinate of character upper-left corner. +/// \param c Character to output. +/// \param fontColor Character foreground color. +/// \param bgColor Background color of character +//------------------------------------------------------------------------------ +void LCDD_DrawCharWithBGColor( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int fontColor, + unsigned int bgColor) +{ + unsigned int row, col; + + SANITY_CHECK((c >= 0x20) && (c <= 0x7F)); + + for (col = 0; col < 10; col++) { + + for (row = 0; row < 8; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x+col, y+row, fontColor); + } else { + LCDD_DrawPixel(pBuffer, x+col, y+row, bgColor); + } + } + for (row = 0; row < 6; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x+col, y+row+8, fontColor); + } else { + LCDD_DrawPixel(pBuffer, x+col, y+row+8, bgColor); + } + } + } +} +//------------------------------------------------------------------------------ +/// Draws an ASCII character on the given LCD buffer ith 90 degree clockwise rotate. +/// \param pBuffer Buffer to write on. +/// \param x X-coordinate of character upper-left corner x decreasing by step. +/// \param y Y-coordinate of character upper-left corner y increasing by step. +/// \param c Character to output. +/// \param fontColor Character foreground color. +/// \param bgColor Background color of character +//------------------------------------------------------------------------------ +void LCDD_DrawCharVerticalWithBGColor( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int fontColor, + unsigned int bgColor) +{ + unsigned int row, col; + + SANITY_CHECK((c >= 0x20) && (c <= 0x7F)); + + for (col = 0; col < 10; col++) { + + for (row = 0; row < 8; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x-row, y+col, fontColor); + } else { + LCDD_DrawPixel(pBuffer, x-row, y+col, bgColor); + } + } + for (row = 0; row < 6; row++) { + + if ((pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] >> (7 - row)) & 0x1) { + + LCDD_DrawPixel(pBuffer, x-row-8, y+col, fontColor); + } else { + LCDD_DrawPixel(pBuffer, x-row-8, y+col, bgColor); + } + } + } +} diff --git a/drivers/lcd/font.h b/drivers/lcd/font.h new file mode 100644 index 0000000..2576de6 --- /dev/null +++ b/drivers/lcd/font.h @@ -0,0 +1,112 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// The font.h files declares a font structure and a LCDD_DrawChar function +/// that must be implemented by a font definition file to be used with the +/// LCDD_DrawString method of draw.h. +/// +/// The font10x14.c implements the necessary variable and function for a 10x14 +/// font. +/// +/// !!!Usage +/// +/// -# Declare a gFont global variable with the necessary Font information. +/// -# Implement an LCDD_DrawChar function which displays the specified +/// character on the LCD. +/// -# Use the LCDD_DrawString method defined in draw.h to display a complete +/// string. +//------------------------------------------------------------------------------ + +#ifndef FONT_H +#define FONT_H + +//------------------------------------------------------------------------------ +// Global types +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Describes the font (width, height, supported characters, etc.) used by +/// the LCD driver draw API. +//------------------------------------------------------------------------------ +typedef struct _Font { + + /// Font width in pixels. + unsigned char width; + /// Font height in pixels. + unsigned char height; + +} Font; + +//------------------------------------------------------------------------------ +// Global variables +//------------------------------------------------------------------------------ + +/// Global variable describing the font being instancied. +extern const Font gFont; + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void LCDD_DrawChar( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int color); + +extern void LCDD_DrawCharVertical( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int color); + +extern void LCDD_DrawCharWithBGColor( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int fontColor, + unsigned int bgColor); + +extern void LCDD_DrawCharVerticalWithBGColor( + void *pBuffer, + unsigned int x, + unsigned int y, + char c, + unsigned int fontColor, + unsigned int bgColor); + +#endif //#ifndef FONT_H diff --git a/drivers/lcd/font10x14.h b/drivers/lcd/font10x14.h new file mode 100644 index 0000000..b86612a --- /dev/null +++ b/drivers/lcd/font10x14.h @@ -0,0 +1,237 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +#ifndef LCD_FONT_10x14_H +#define LCD_FONT_10x14_H + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +// Definitions +//------------------------------------------------------------------------------ + +const unsigned char pCharset10x14[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xCC, + 0xFF, 0xCC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xF0, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0xC0, 0x0C, 0xC0, 0xFF, 0xFC, 0xFF, 0xFC, 0x0C, 0xC0, + 0x0C, 0xC0, 0xFF, 0xFC, 0xFF, 0xFC, 0x0C, 0xC0, 0x0C, 0xC0, + 0x0C, 0x60, 0x1E, 0x70, 0x3F, 0x30, 0x33, 0x30, 0xFF, 0xFC, + 0xFF, 0xFC, 0x33, 0x30, 0x33, 0xF0, 0x39, 0xE0, 0x18, 0xC0, + 0x60, 0x00, 0xF0, 0x0C, 0xF0, 0x3C, 0x60, 0xF0, 0x03, 0xC0, + 0x0F, 0x00, 0x3C, 0x18, 0xF0, 0x3C, 0xC0, 0x3C, 0x00, 0x18, + 0x3C, 0xF0, 0x7F, 0xF8, 0xC3, 0x1C, 0xC7, 0x8C, 0xCF, 0xCC, + 0xDC, 0xEC, 0x78, 0x78, 0x30, 0x30, 0x00, 0xFC, 0x00, 0xCC, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00, 0xEC, 0x00, + 0xF8, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x0F, 0xC0, 0x3F, 0xF0, 0x78, 0x78, + 0x60, 0x18, 0xC0, 0x0C, 0xC0, 0x0C, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0C, 0xC0, 0x0C, 0x60, 0x18, + 0x78, 0x78, 0x3F, 0xF0, 0x0F, 0xC0, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x60, 0x0E, 0xE0, 0x07, 0xC0, 0x03, 0x80, 0x3F, 0xF8, + 0x3F, 0xF8, 0x03, 0x80, 0x07, 0xC0, 0x0E, 0xE0, 0x0C, 0x60, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x3F, 0xF0, + 0x3F, 0xF0, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x00, 0x44, 0x00, 0xEC, 0x00, 0xF8, 0x00, 0x70, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, 0x03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07, 0x00, 0xFE, 0x00, 0xFC, 0x00, + 0xC0, 0x3C, 0xC0, 0x7C, 0xC0, 0xEC, 0xC1, 0xCC, 0xC3, 0x8C, + 0xC7, 0x0C, 0xCE, 0x0C, 0xDC, 0x0C, 0xF8, 0x0C, 0xF0, 0x0C, + 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFC, 0xC0, 0x0C, + 0xC0, 0x0C, 0xC0, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x30, 0x00, 0x30, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0x30, 0x00, 0x30, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x0C, 0xC0, 0x0C, 0xC0, 0x0C, + 0xFF, 0xFC, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x00, 0x1C, 0x00, 0x38, 0x00, 0x70, 0x00, 0xE0, 0x00, + 0xE0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1C, 0x00, 0x0C, 0x00, + 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, + 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, 0x00, 0x0C, + 0x00, 0x00, 0x00, 0x00, 0xC0, 0x00, 0xE0, 0x00, 0x70, 0x00, + 0x38, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x06, 0x78, 0x0E, 0xFC, 0x0C, 0xCC, 0x0C, 0xCC, + 0x0C, 0xCC, 0x0C, 0xCC, 0x0E, 0xCC, 0x07, 0xFC, 0x03, 0xF8, + 0xFF, 0xFC, 0xFF, 0xFC, 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x0C, + 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x9C, 0x01, 0xF8, 0x00, 0xF0, + 0x03, 0xF0, 0x07, 0xF8, 0x0E, 0x1C, 0x0C, 0x0C, 0x0C, 0x0C, + 0x0C, 0x0C, 0x0C, 0x0C, 0x0E, 0x1C, 0x07, 0x38, 0x03, 0x30, + 0x00, 0xF0, 0x01, 0xF8, 0x03, 0x9C, 0x03, 0x0C, 0x03, 0x0C, + 0x03, 0x0C, 0x03, 0x0C, 0x03, 0x0C, 0xFF, 0xFC, 0xFF, 0xFC, + 0x03, 0xF0, 0x07, 0xF8, 0x0E, 0xDC, 0x0C, 0xCC, 0x0C, 0xCC, + 0x0C, 0xCC, 0x0C, 0xCC, 0x0E, 0xDC, 0x07, 0xD8, 0x03, 0x90, + 0x00, 0x00, 0x03, 0x00, 0x3F, 0xFC, 0x7F, 0xFC, 0xE3, 0x00, + 0xE3, 0x00, 0x70, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x18, 0x07, 0x9C, 0x0F, 0xCC, 0x0C, 0xCC, 0x0C, 0xCC, + 0x0C, 0xCC, 0x0C, 0xCC, 0x0C, 0xDC, 0x0F, 0xF8, 0x07, 0xF0, + 0xFF, 0xFC, 0xFF, 0xFC, 0x03, 0x00, 0x03, 0x00, 0x03, 0x00, + 0x03, 0x00, 0x03, 0x80, 0x01, 0xFC, 0x00, 0xFC, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B, 0xFC, + 0x1B, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x30, 0x00, 0x38, 0x00, 0x1C, 0x00, 0x0C, + 0x00, 0x0C, 0x00, 0x1C, 0xCF, 0xF8, 0xCF, 0xF0, 0x00, 0x00, + 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFC, 0x00, 0xE0, 0x01, 0xE0, + 0x03, 0xF0, 0x07, 0x38, 0x0E, 0x1C, 0x0C, 0x0C, 0x00, 0x00, + 0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03, 0x00, 0x00, 0x00, + 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, + 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, 0xC0, 0x00, + 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, + 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC, 0xFF, 0xFC +}; + + +#endif // #ifdef _LCD_FONT_10x14_h diff --git a/drivers/lcd/lcd.dir b/drivers/lcd/lcd.dir new file mode 100644 index 0000000..260d5ea --- /dev/null +++ b/drivers/lcd/lcd.dir @@ -0,0 +1,39 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \dir +/// +/// !!!Contents +/// +/// This directory contains the source code for the LCD driver in lcd.h. In +/// addition, several drawing function are provided by draw.h. A font system is +/// also defined in font.h. Now supports two types of lcd controller: +/// peripheral LCDC and and HX8347 LCDC. +//------------------------------------------------------------------------------ diff --git a/drivers/lcd/lcdd.c b/drivers/lcd/lcdd.c new file mode 100644 index 0000000..efb14ed --- /dev/null +++ b/drivers/lcd/lcdd.c @@ -0,0 +1,138 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "lcdd.h" +#include +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initializes the LCD controller using the board-specific parameters (stored +/// in the corresponding board.h). The LCD and DMA are not enabled by this +/// function; this is done during the first call to LCDD_DisplayBuffer. +//------------------------------------------------------------------------------ +void LCDD_Initialize(void) +{ + const Pin pPins[] = {PINS_LCD}; + + // Enable pins + PIO_Configure(pPins, PIO_LISTSIZE(pPins)); + + // Enable peripheral clock + AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_LCDC; + +#if defined(at91sam9g10)||defined(at91sam9261) + AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_HCK1; +#endif + + // Disable the LCD and the DMA + LCD_DisableDma(); + LCD_Disable(0); + + // Configure the LCD controller + LCD_SetPixelClock(BOARD_MCK, BOARD_LCD_PIXELCLOCK); + LCD_SetDisplayType(BOARD_LCD_DISPLAYTYPE); + LCD_SetScanMode(AT91C_LCDC_SCANMOD_SINGLESCAN); + LCD_SetBitsPerPixel(BOARD_LCD_BPP); + LCD_SetPolarities(BOARD_LCD_POLARITY_INVVD, + BOARD_LCD_POLARITY_INVFRAME, + BOARD_LCD_POLARITY_INVLINE, + BOARD_LCD_POLARITY_INVCLK, + BOARD_LCD_POLARITY_INVDVAL); + LCD_SetClockMode(BOARD_LCD_CLOCKMODE); + LCD_SetMemoryFormat((unsigned int) AT91C_LCDC_MEMOR_LITTLEIND); + LCD_SetSize(BOARD_LCD_WIDTH, BOARD_LCD_HEIGHT); + + // Configure timings + LCD_SetVerticalTimings(BOARD_LCD_TIMING_VFP, + BOARD_LCD_TIMING_VBP, + BOARD_LCD_TIMING_VPW, + BOARD_LCD_TIMING_VHDLY); + LCD_SetHorizontalTimings(BOARD_LCD_TIMING_HBP, + BOARD_LCD_TIMING_HPW, + BOARD_LCD_TIMING_HFP); + + // Configure contrast (TODO functions) + LCD_SetContrastPrescaler(AT91C_LCDC_PS_NOTDIVIDED); + LCD_SetContrastPolarity(AT91C_LCDC_POL_POSITIVEPULSE); + LCD_SetContrastValue(0x80); + LCD_EnableContrast(); + + // Configure DMA + LCD_SetFrameSize(BOARD_LCD_FRAMESIZE); + LCD_SetBurstLength(4); +} + +//------------------------------------------------------------------------------ +/// Displays the contents of the provided buffer on the LCD. The buffer is +/// provided as-is to the LCD DMA and is not copied. +/// If the LCD and DMA are not yet enabled, this function enables them. +/// \param pBuffer Buffer to display. +/// \return The address of the previously displayed buffer. +//------------------------------------------------------------------------------ +void * LCDD_DisplayBuffer(void *pBuffer) +{ + void *pOldBuffer; + + pOldBuffer = LCD_SetFrameBufferAddress(pBuffer); + + // Enable LCD & DMA if needed + if ((AT91C_BASE_LCDC->LCDC_DMACON & AT91C_LCDC_DMAEN) != AT91C_LCDC_DMAEN) { + + LCD_EnableDma(); + LCD_Enable(0x0C); + } + + return pOldBuffer; +} + +//------------------------------------------------------------------------------ +/// Shutdown the LCD +//------------------------------------------------------------------------------ +void LCDD_Stop(void) +{ + // Enable peripheral clock + AT91C_BASE_PMC->PMC_PCDR = 1 << AT91C_ID_LCDC; + +#if defined(at91sam9g10)||defined(at91sam9261) + AT91C_BASE_PMC->PMC_SCDR = AT91C_PMC_HCK1; +#endif + + // Disable the LCD and the DMA + LCD_DisableDma(); + LCD_Disable(0); +} diff --git a/drivers/lcd/lcdd.h b/drivers/lcd/lcdd.h new file mode 100644 index 0000000..27da073 --- /dev/null +++ b/drivers/lcd/lcdd.h @@ -0,0 +1,61 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +/// \unit +/// +/// !!!Purpose +/// +/// Simple driver for the LCD, which takes care of the initialization. +/// +/// !!!Usage +/// +/// -# Call LCDD_Initialize to configure the LCD controller. +/// -# Set the buffer displayed by the LCD with LCDD_DisplayBuffer if using +/// peripheral LCDC, or start displaying with LCDD_Start if using HX8347. +//------------------------------------------------------------------------------ + +#ifndef LCDD_H +#define LCDD_H + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +extern void LCDD_Initialize(void); // For peripheral LCDC & HX8347 + +extern void * LCDD_DisplayBuffer(void *pBuffer); // For peripheral LCDC only + +extern void LCDD_Start(void); // For HX8347 only + +extern void LCDD_Stop(void); // For peripheral LCDC & HX8347 + +extern void LCDD_SetBacklight (unsigned int step); // For peripheral LCDC only + +#endif //#ifndef LCDD_H diff --git a/drivers/lcd/lcdd_hx8347.c b/drivers/lcd/lcdd_hx8347.c new file mode 100644 index 0000000..e5871ad --- /dev/null +++ b/drivers/lcd/lcdd_hx8347.c @@ -0,0 +1,147 @@ +/* ---------------------------------------------------------------------------- + * ATMEL Microcontroller Software Support + * ---------------------------------------------------------------------------- + * Copyright (c) 2008, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +//------------------------------------------------------------------------------ +// Headers +//------------------------------------------------------------------------------ + +#include "lcdd.h" + +#include +#include +#include +#include + +//------------------------------------------------------------------------------ +// Global functions +//------------------------------------------------------------------------------ + +//------------------------------------------------------------------------------ +/// Initializes the LCD controller. +/// SMC are configured @ 96MHz for LCD. +/// \param pLcdBase LCD base address. +//------------------------------------------------------------------------------ +void LCDD_Initialize(void) +{ + const Pin pPins[] = {BOARD_LCD_PINS}; + AT91PS_HSMC4_CS pSMC = AT91C_BASE_HSMC4_CS2; + unsigned int rMode; + + // Enable pins + PIO_Configure(pPins, PIO_LISTSIZE(pPins)); + + // Enable peripheral clock + PMC_EnablePeripheral(AT91C_ID_HSMC4); + + // EBI SMC Configuration + pSMC->HSMC4_SETUP = 0 + | ((1 << 0) & AT91C_HSMC4_NWE_SETUP) + | ((1 << 8) & AT91C_HSMC4_NCS_WR_SETUP) + | ((9 << 16) & AT91C_HSMC4_NRD_SETUP) + | ((9 << 24) & AT91C_HSMC4_NCS_RD_SETUP) + ; + + pSMC->HSMC4_PULSE = 0 + | (( 4 << 0) & AT91C_HSMC4_NWE_PULSE) + | (( 4 << 8) & AT91C_HSMC4_NCS_WR_PULSE) + | (( 36 << 16) & AT91C_HSMC4_NRD_PULSE) + | (( 36 << 24) & AT91C_HSMC4_NCS_RD_PULSE) + ; + + pSMC->HSMC4_CYCLE = 0 + | ((10 << 0) & AT91C_HSMC4_NWE_CYCLE) + | ((45 << 16) & AT91C_HSMC4_NRD_CYCLE) + ; + + rMode = pSMC->HSMC4_MODE & ~(AT91C_HSMC4_DBW | AT91C_HSMC4_READ_MODE | AT91C_HSMC4_WRITE_MODE); + pSMC->HSMC4_MODE = rMode + | (AT91C_HSMC4_READ_MODE) + | (AT91C_HSMC4_WRITE_MODE) + | (AT91C_HSMC4_DBW_WIDTH_SIXTEEN_BITS) + ; + + // Initialize LCD controller (HX8347) + LCD_Initialize((void *)BOARD_LCD_BASE); + + // Set LCD backlight + LCDD_SetBacklight(25); +} + +//------------------------------------------------------------------------------ +/// Turn on the LCD +//------------------------------------------------------------------------------ +void LCDD_Start(void) +{ + LCD_On((void *)BOARD_LCD_BASE); +} + +//------------------------------------------------------------------------------ +/// Turn off the LCD +//------------------------------------------------------------------------------ +void LCDD_Stop(void) +{ + LCD_Off((void *)BOARD_LCD_BASE); +} + +//------------------------------------------------------------------------------ +/// Set the backlight of the LCD. +/// \param level Backlight brightness level [1..32], 32 is maximum level. +//------------------------------------------------------------------------------ +void LCDD_SetBacklight (unsigned int level) +{ + unsigned int i; + const Pin pPins[] = {BOARD_BACKLIGHT_PIN}; + + // Enable pins + PIO_Configure(pPins, PIO_LISTSIZE(pPins)); + + // Switch off backlight + PIO_Clear(pPins); + i = 600 * (BOARD_MCK / 1000000); // wait for at least 500us + while(i--); + + // Set new backlight level + for (i = 0; i < level; i++) { + + + PIO_Clear(pPins); + PIO_Clear(pPins); + PIO_Clear(pPins); + + + PIO_Set(pPins); + PIO_Set(pPins); + PIO_Set(pPins); + +// PIO_Clear(pPins); +// PIO_Clear(pPins); +// PIO_Clear(pPins); + } +// PIO_Set(pPins); +} -- cgit v1.2.3