00001 /* ---------------------------------------------------------------------------- */ 00002 /* Atmel Microcontroller Software Support */ 00003 /* SAM Software Package License */ 00004 /* ---------------------------------------------------------------------------- */ 00005 /* Copyright (c) 2015, Atmel Corporation */ 00006 /* */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without */ 00010 /* modification, are permitted provided that the following condition is met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, */ 00013 /* this list of conditions and the disclaimer below. */ 00014 /* */ 00015 /* Atmel's name may not be used to endorse or promote products derived from */ 00016 /* this software without specific prior written permission. */ 00017 /* */ 00018 /* DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR */ 00019 /* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */ 00020 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE */ 00021 /* DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, */ 00022 /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT */ 00023 /* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */ 00024 /* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */ 00025 /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */ 00026 /* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, */ 00027 /* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00028 /* ---------------------------------------------------------------------------- */ 00029 00030 /** 00031 * \file 00032 * 00033 * Implementation of draw font on LCD. 00034 * 00035 */ 00036 00037 /*---------------------------------------------------------------------------- 00038 * Headers 00039 *----------------------------------------------------------------------------*/ 00040 00041 #include "board.h" 00042 00043 #include <stdint.h> 00044 #include <assert.h> 00045 00046 /*---------------------------------------------------------------------------- 00047 * Local variables 00048 *----------------------------------------------------------------------------*/ 00049 00050 /** Global variable describing the font being instantiated. */ 00051 const Font gFont = {10, 14}; 00052 00053 /*---------------------------------------------------------------------------- 00054 * Exported functions 00055 *----------------------------------------------------------------------------*/ 00056 00057 /** 00058 * \brief Draws an ASCII character on LCD. 00059 * 00060 * \param pCanvasBuffer Pointer to dedicate canvas buffer. 00061 * \param x X-coordinate of character upper-left corner. 00062 * \param y Y-coordinate of character upper-left corner. 00063 * \param c Character to output. 00064 * \param color Character color. 00065 */ 00066 extern void LCDD_DrawChar(uint16_t *pCanvasBuffer, uint32_t x, uint32_t y, 00067 uint8_t c, uint32_t color) 00068 { 00069 uint32_t row, col; 00070 00071 assert((c >= 0x20) && (c <= 0x7F)); 00072 00073 for (col = 0; col < 10; col++) { 00074 for (row = 0; row < 8; row++) { 00075 if ((pCharset10x14[((c - 0x20) * 20) + col * 2] >> (7 - row)) & 0x1) 00076 LCDD_DrawPixel(pCanvasBuffer, x + col, y + row, color); 00077 } 00078 00079 for (row = 0; row < 6; row++) { 00080 if ((pCharset10x14[((c - 0x20) * 20) + col * 2 + 1] 00081 >> (7 - row)) & 0x1) 00082 LCDD_DrawPixel(pCanvasBuffer, x + col, y + row + 8, color); 00083 } 00084 } 00085 } 00086 00087 /** 00088 * \brief Draws a string inside a LCD buffer, at the given coordinates. 00089 * Line breaks will be honoured. 00090 * 00091 * \param pCanvasBuffer Pointer to dedicate canvas buffer. 00092 * \param dwX X-coordinate of string top-left corner. 00093 * \param dwY Y-coordinate of string top-left corner. 00094 * \param pString String to display. 00095 */ 00096 extern void LCD_DrawString(uint16_t *pCanvasBuffer, uint32_t dwX, uint32_t dwY, 00097 const uint8_t *pString, uint32_t color) 00098 { 00099 uint32_t dwXorg = dwX; 00100 00101 while (*pString != 0) { 00102 if (*pString == '\n') { 00103 dwY += gFont.height + 2; 00104 dwX = dwXorg; 00105 } else { 00106 LCDD_DrawChar(pCanvasBuffer, dwX, dwY, *pString, color); 00107 dwX += gFont.width + 2; 00108 } 00109 00110 pString++; 00111 } 00112 } 00113 00114