Nut/OS  4.10.3
API Reference
charlcd_at91.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 by egnite Software GmbH. All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions
00006  * are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the copyright holders nor the names of
00014  *    contributors may be used to endorse or promote products derived
00015  *    from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00018  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00019  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00020  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00021  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00022  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00023  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00024  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00025  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00026  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00027  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00028  * SUCH DAMAGE.
00029  *
00030  * For additional information see http://www.ethernut.de/
00031  *
00032  */
00033 
00034 /*
00035  * $Log$
00036  * Revision 1.6  2009/01/17 11:26:37  haraldkipp
00037  * Getting rid of two remaining BSD types in favor of stdint.
00038  * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
00039  *
00040  * Revision 1.5  2008/08/11 06:59:13  haraldkipp
00041  * BSD types replaced by stdint types (feature request #1282721).
00042  *
00043  * Revision 1.4  2008/06/06 10:28:21  haraldkipp
00044  * ST7036 LCD controller settings moved from source to configuration files.
00045  *
00046  * Revision 1.3  2008/02/15 16:59:02  haraldkipp
00047  * Spport for AT91SAM7SE512 added.
00048  *
00049  * Revision 1.2  2007/10/04 20:01:50  olereinhardt
00050  * Support for SAM7S256 added
00051  *
00052  * Revision 1.1  2007/02/15 16:09:07  haraldkipp
00053  * Tested with EA DOG-M LCDs.
00054  *
00055  */
00056 
00057 #include <cfg/arch.h>
00058 #include <cfg/arch/gpio.h>
00059 #include <cfg/lcd.h>
00060 
00061 #include <stdlib.h>
00062 #include <string.h>
00063 
00064 #include <sys/nutconfig.h>
00065 #include <dev/st7036.h>
00066 #include <dev/term.h>
00067 #include <sys/timer.h>
00068 
00069 #ifndef LCD_ROWS
00070 #define LCD_ROWS    2
00071 #endif
00072 
00073 #ifndef LCD_COLS
00074 #define LCD_COLS    16
00075 #endif
00076 
00077 #ifndef LCD_E2E_DLY
00078 #define LCD_E2E_DLY 80
00079 #endif
00080 
00081 #ifndef LCD_LONG_DELAY
00082 #define LCD_LONG_DELAY  1000
00083 #endif
00084 
00085 #if !defined(LCD_IF_8BIT) && !defined(LCD_IF_4BIT)
00086 #define LCD_IF_4BIT
00087 #endif
00088 
00089 /*
00090  * Fallback definition for PIO_IDs and bits
00091  */
00092 #ifndef LCD_EN_PIO_ID
00093 #if defined(MCU_AT91SAM7X) || defined (MCU_AT91SAM7S256) || defined (MCU_AT91SAM7SE512)
00094 #define LCD_EN_PIO_ID PIOA_ID
00095 #elif defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE512)
00096 #define LCD_CS_PIO_ID PIOB_ID
00097 #else
00098 #define LCD_CS_PIO_ID PIO_ID
00099 #endif
00100 #endif
00101 
00102 #ifndef LCD_EN_PIO_ID
00103 #if defined(MCU_AT91SAM7X) || defined (MCU_AT91SAM7S256) || defined (MCU_AT91SAM7SE512)
00104 #define LCD_EN_PIO_ID PIOA_ID
00105 #elif defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE512)
00106 #define LCD_EN_PIO_ID PIOB_ID
00107 #else
00108 #define LCD_EN_PIO_ID PIO_ID
00109 #endif
00110 #endif
00111 
00112 #ifndef LCD_RW_PIO_ID
00113 #if defined(MCU_AT91SAM7X) || defined (MCU_AT91SAM7S256) || defined (MCU_AT91SAM7SE512)
00114 #define LCD_RW_PIO_ID PIOA_ID
00115 #elif defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE512)
00116 #define LCD_RW_PIO_ID PIOB_ID
00117 #else
00118 #define LCD_RW_PIO_ID PIO_ID
00119 #endif
00120 #endif
00121 
00122 #ifndef LCD_RS_PIO_ID
00123 #if defined(MCU_AT91SAM7X) || defined (MCU_AT91SAM7S256) || defined (MCU_AT91SAM7SE512)
00124 #define LCD_RS_PIO_ID PIOA_ID
00125 #elif defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE512)
00126 #define LCD_RS_PIO_ID PIOB_ID
00127 #else
00128 #define LCD_RS_PIO_ID PIO_ID
00129 #endif
00130 #endif
00131 
00132 #ifndef LCD_DATA_PIO_ID
00133 #if defined(MCU_AT91SAM7X) || defined (MCU_AT91SAM7S256) || defined (MCU_AT91SAM7SE512)
00134 #define LCD_DATA_PIO_ID PIOA_ID
00135 #elif defined(MCU_AT91SAM9260) || defined(MCU_AT91SAM9XE512)
00136 #define LCD_DATA_PIO_ID PIOB_ID
00137 #else
00138 #define LCD_DATA_PIO_ID PIO_ID
00139 #endif
00140 #endif
00141 
00142 /*
00143  * Control lines abstraction.
00144  */
00145 
00146 #ifdef LCD_EN_BIT
00147 #define LCD_CS      _BV(LCD_EN_BIT)
00148 #if LCD_EN_PIO_ID == PIOA_ID
00149 #define LCD_EN_SET() { outr(PIOA_PER, LCD_CS); outr(PIOA_SODR, LCD_CS); outr(PIOA_OER, LCD_CS); }
00150 #define LCD_EN_CLR() { outr(PIOA_PER, LCD_CS); outr(PIOA_CODR, LCD_CS); outr(PIOA_OER, LCD_CS); }
00151 #elif LCD_EN_PIO_ID == PIOB_ID
00152 #define LCD_EN_SET() { outr(PIOB_PER, LCD_CS); outr(PIOB_SODR, LCD_CS); outr(PIOB_OER, LCD_CS); }
00153 #define LCD_EN_CLR() { outr(PIOB_PER, LCD_CS); outr(PIOB_CODR, LCD_CS); outr(PIOB_OER, LCD_CS); }
00154 #elif LCD_EN_PIO_ID == PIOC_ID
00155 #define LCD_EN_SET() { outr(PIOC_PER, LCD_CS); outr(PIOC_SODR, LCD_CS); outr(PIOC_OER, LCD_CS); }
00156 #define LCD_CS_CLR() { outr(PIOC_PER, LCD_CS); outr(PIOC_CODR, LCD_CS); outr(PIOC_OER, LCD_CS); }
00157 #else
00158 #define LCD_EN_SET() { outr(PIO_PER, LCD_CS); outr(PIO_SODR, LCD_CS); outr(PIO_OER, LCD_CS); }
00159 #define LCD_EN_CLR() { outr(PIO_PER, LCD_CS); outr(PIO_CODR, LCD_CS); outr(PIO_OER, LCD_CS); }
00160 #endif /* LCD_EN_PIO_ID */
00161 #else /* LCD_EN_BIT */
00162 #define LCD_EN_SET()
00163 #define LCD_EN_CLR()
00164 #endif /* LCD_EN_BIT */
00165 
00166 #ifdef LCD_RS_BIT
00167 #define LCD_RS      _BV(LCD_RS_BIT)
00168 #if LCD_RS_PIO_ID == PIOA_ID
00169 #define LCD_RS_SET() { outr(PIOA_PER, LCD_RS); outr(PIOA_SODR, LCD_RS); outr(PIOA_OER, LCD_RS); }
00170 #define LCD_RS_CLR() { outr(PIOA_PER, LCD_RS); outr(PIOA_CODR, LCD_RS); outr(PIOA_OER, LCD_RS); }
00171 #elif LCD_RS_PIO_ID == PIOB_ID
00172 #define LCD_RS_SET() { outr(PIOB_PER, LCD_RS); outr(PIOB_SODR, LCD_RS); outr(PIOB_OER, LCD_RS); }
00173 #define LCD_RS_CLR() { outr(PIOB_PER, LCD_RS); outr(PIOB_CODR, LCD_RS); outr(PIOB_OER, LCD_RS); }
00174 #elif LCD_RS_PIO_ID == PIOC_ID
00175 #define LCD_RS_SET() { outr(PIOC_PER, LCD_RS); outr(PIOC_SODR, LCD_RS); outr(PIOC_OER, LCD_RS); }
00176 #define LCD_RS_CLR() { outr(PIOC_PER, LCD_RS); outr(PIOC_CODR, LCD_RS); outr(PIOC_OER, LCD_RS); }
00177 #else
00178 #define LCD_RS_SET() { outr(PIO_PER, LCD_RS); outr(PIO_SODR, LCD_RS); outr(PIO_OER, LCD_RS); }
00179 #define LCD_RS_CLR() { outr(PIO_PER, LCD_RS); outr(PIO_CODR, LCD_RS); outr(PIO_OER, LCD_RS); }
00180 #endif /* LCD_RS_PIO_ID */
00181 #else /* LCD_RS_BIT */
00182 #define LCD_RS_SET()
00183 #define LCD_RS_CLR()
00184 #endif /* LCD_RS_BIT */
00185 
00186 #ifdef LCD_RW_BIT
00187 #define LCD_RW      _BV(LCD_RW_BIT)
00188 #if LCD_RS_PIO_ID == PIOA_ID
00189 #define LCD_RW_SET() { outr(PIOA_PER, LCD_RS); outr(PIOA_SODR, LCD_RS); outr(PIOA_OER, LCD_RS); }
00190 #define LCD_RW_CLR() { outr(PIOA_PER, LCD_RS); outr(PIOA_CODR, LCD_RS); outr(PIOA_OER, LCD_RS); }
00191 #elif LCD_RS_PIO_ID == PIOB_ID
00192 #define LCD_RW_SET() { outr(PIOB_PER, LCD_RS); outr(PIOB_SODR, LCD_RS); outr(PIOB_OER, LCD_RS); }
00193 #define LCD_RW_CLR() { outr(PIOB_PER, LCD_RS); outr(PIOB_CODR, LCD_RS); outr(PIOB_OER, LCD_RS); }
00194 #elif LCD_RS_PIO_ID == PIOC_ID
00195 #define LCD_RW_SET() { outr(PIOC_PER, LCD_RS); outr(PIOC_SODR, LCD_RS); outr(PIOC_OER, LCD_RS); }
00196 #define LCD_RW_CLR() { outr(PIOC_PER, LCD_RS); outr(PIOC_CODR, LCD_RS); outr(PIOC_OER, LCD_RS); }
00197 #else
00198 #define LCD_RW_SET() { outr(PIO_PER, LCD_RS); outr(PIO_SODR, LCD_RS); outr(PIO_OER, LCD_RS); }
00199 #define LCD_RW_CLR() { outr(PIO_PER, LCD_RS); outr(PIO_CODR, LCD_RS); outr(PIO_OER, LCD_RS); }
00200 #endif /* LCD_RW_PIO_ID */
00201 #else /* LCD_RW_BIT */
00202 #define LCD_RW_SET()
00203 #define LCD_RW_CLR()
00204 #endif /* LCD_RW_BIT */
00205 
00206 #ifdef LCD_EN2_BIT
00207 #define LCD_EN2     _BV(LCD_EN2_BIT)
00208 #if LCD_EN2_PIO_ID == PIOA_ID
00209 #define LCD_EN2_SET() { outr(PIOA_PER, LCD_EN2); outr(PIOA_SODR, LCD_EN2); outr(PIOA_OER, LCD_EN2); }
00210 #define LCD_EN2_CLR() { outr(PIOA_PER, LCD_EN2); outr(PIOA_CODR, LCD_EN2); outr(PIOA_OER, LCD_EN2); }
00211 #elif LCD_EN2_PIO_ID == PIOB_ID
00212 #define LCD_EN2_SET() { outr(PIOB_PER, LCD_EN2); outr(PIOB_SODR, LCD_EN2); outr(PIOB_OER, LCD_EN2); }
00213 #define LCD_EN2_CLR() { outr(PIOB_PER, LCD_EN2); outr(PIOB_CODR, LCD_EN2); outr(PIOB_OER, LCD_EN2); }
00214 #elif LCD_EN2_PIO_ID == PIOC_ID
00215 #define LCD_EN2_SET() { outr(PIOC_PER, LCD_EN2); outr(PIOC_SODR, LCD_EN2); outr(PIOC_OER, LCD_EN2); }
00216 #define LCD_EN2_CLR() { outr(PIOC_PER, LCD_EN2); outr(PIOC_CODR, LCD_EN2); outr(PIOC_OER, LCD_EN2); }
00217 #else
00218 #define LCD_EN2_SET() { outr(PIO_PER, LCD_EN2); outr(PIO_SODR, LCD_EN2); outr(PIO_OER, LCD_EN2); }
00219 #define LCD_EN2_CLR() { outr(PIO_PER, LCD_EN2); outr(PIO_CODR, LCD_EN2); outr(PIO_OER, LCD_EN2); }
00220 #endif /* LCD_EN2_PIO_ID */
00221 #else /* LCD_EN2_BIT */
00222 #define LCD_EN2_SET()
00223 #define LCD_EN2_CLR()
00224 #endif /* LCD_EN2_BIT */
00225 
00226 #ifdef LCD_RST_BIT
00227 #define LCD_RST    _BV(LCD_RST_BIT)
00228 #if LCD_RST_PIO_ID == PIOA_ID
00229 #define LCD_RST_SET() { outr(PIOA_PER, LCD_RST); outr(PIOA_SODR, LCD_RST); outr(PIOA_OER, LCD_RST); }
00230 #define LCD_RST_CLR() { outr(PIOA_PER, LCD_RST); outr(PIOA_CODR, LCD_RST); outr(PIOA_OER, LCD_RST); }
00231 #elif LCD_RST_PIO_ID == PIOB_ID
00232 #define LCD_RST_SET() { outr(PIOB_PER, LCD_RST); outr(PIOB_SODR, LCD_RST); outr(PIOB_OER, LCD_RST); }
00233 #define LCD_RST_CLR() { outr(PIOB_PER, LCD_RST); outr(PIOB_CODR, LCD_RST); outr(PIOB_OER, LCD_RST); }
00234 #elif LCD_RST_PIO_ID == PIOC_ID
00235 #define LCD_RST_SET() { outr(PIOC_PER, LCD_RST); outr(PIOC_SODR, LCD_RST); outr(PIOC_OER, LCD_RST); }
00236 #define LCD_RST_CLR() { outr(PIOC_PER, LCD_RST); outr(PIOC_CODR, LCD_RST); outr(PIOC_OER, LCD_RST); }
00237 #else
00238 #define LCD_RST_SET() { outr(PIO_PER, LCD_RST); outr(PIO_SODR, LCD_RST); outr(PIO_OER, LCD_RST); }
00239 #define LCD_RST_CLR() { outr(PIO_PER, LCD_RST); outr(PIO_CODR, LCD_RST); outr(PIO_OER, LCD_RST); }
00240 #endif /* LCD_RST_PIO_ID */
00241 #else /* LCD_RST_BIT */
00242 #define LCD_RST_SET()
00243 #define LCD_RST_CLR()
00244 #endif /* LCD_RST_BIT */
00245 
00246 
00247 #if LCD_DATA_PIO_ID == PIOA_ID
00248 #define LCD_DATA_BASE PIOA_BASE
00249 #elif LCD_DATA_PIO_ID == PIOB_ID
00250 #define LCD_DATA_BASE PIOB_BASE
00251 #elif LCD_DATA_PIO_ID == PIOC_ID
00252 #define LCD_DATA_BASE PIOC_BASE
00253 #else /* LCD_DATA_PIO_ID */
00254 #define LCD_DATA_BASE PIO_BASE
00255 #endif
00256 
00261 
00262 #if defined(LCD_HD44780) || defined(LCD_KS0066) || defined(LCD_KS0073)
00263 #include "hd44780_at91.c"
00264 #elif defined(LCD_ST7036)
00265 #include "st7036_at91.c"
00266 #endif
00267