SAMV71 Xplained Ultra Software Package 1.3

lcd_font.c

Go to the documentation of this file.
00001 /* ----------------------------------------------------------------------------
00002  *     SAM Software Package License
00003  * ----------------------------------------------------------------------------
00004  * Copyright (c) 2011, Atmel Corporation
00005  *
00006  * All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *
00011  * - Redistributions of source code must retain the above copyright notice,
00012  * this list of conditions and the disclaimer below.
00013  *
00014  * Atmel's name may not be used to endorse or promote products derived from
00015  * this software without specific prior written permission.
00016  *
00017  * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00019  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00020  * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00025  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
00026  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  * ----------------------------------------------------------------------------
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 /**
00089  * \brief Draws a string inside a LCD buffer, at the given coordinates.
00090  * Line breaks will be honoured.
00091  *
00092  * \param pCanvasBuffer Pointer to dedicate canvas buffer.
00093  * \param dwX      X-coordinate of string top-left corner.
00094  * \param dwY      Y-coordinate of string top-left corner.
00095  * \param pString  String to display.
00096  */
00097 extern void LCD_DrawString(uint16_t* pCanvasBuffer, uint32_t dwX, uint32_t dwY, 
00098                         const uint8_t *pString, uint32_t color )
00099 {
00100     uint32_t dwXorg = dwX;
00101 
00102     while ( *pString != 0 ) {
00103         if ( *pString == '\n' ) {
00104             dwY += gFont.height + 2;
00105             dwX = dwXorg;
00106         } else {
00107             LCDD_DrawChar(pCanvasBuffer, dwX, dwY, *pString, color );
00108             dwX += gFont.width + 2;
00109         }
00110         pString++;
00111     }
00112 }
00113 
00114 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines