00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
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
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
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
00161 #else
00162 #define LCD_EN_SET()
00163 #define LCD_EN_CLR()
00164 #endif
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
00181 #else
00182 #define LCD_RS_SET()
00183 #define LCD_RS_CLR()
00184 #endif
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
00201 #else
00202 #define LCD_RW_SET()
00203 #define LCD_RW_CLR()
00204 #endif
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
00221 #else
00222 #define LCD_EN2_SET()
00223 #define LCD_EN2_CLR()
00224 #endif
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
00241 #else
00242 #define LCD_RST_SET()
00243 #define LCD_RST_CLR()
00244 #endif
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
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