This file defines a usefull set of functions for the SIDSA LCD controller on the AVR32 devices.
Definition in file lcdc.h.
#include <avr32/io.h>
Go to the source code of this file.
Data Structures | |
struct | lcdc_configuration_s |
Struct that defines the configuration of the LCD controller. More... | |
Defines | |
#define | LCDC_ALWAYS_ACTIVE 1 |
#define | LCDC_BIG_ENDIAN 0 |
#define | LCDC_BPP_1 1 |
#define | LCDC_BPP_16 16 |
#define | LCDC_BPP_2 2 |
#define | LCDC_BPP_24 24 |
#define | LCDC_BPP_32 32 |
#define | LCDC_BPP_4 4 |
#define | LCDC_BPP_8 8 |
#define | LCDC_DISABLED 0 |
#define | LCDC_DUAL_SCAN 1 |
#define | LCDC_EACH_FRAME 0 |
#define | LCDC_ENABLED 1 |
#define | LCDC_IF_WIDTH16 2 |
#define | LCDC_IF_WIDTH4 0 |
#define | LCDC_IF_WIDTH8 1 |
#define | LCDC_INVERTED 1 |
#define | LCDC_LITTLE_ENDIAN 1 |
#define | LCDC_MODE_2D_OFF 0 |
#define | LCDC_MODE_2D_ON 1 |
#define | LCDC_MVAL_DEFINED 1 |
#define | LCDC_NORMAL 0 |
#define | LCDC_PARTLY_ACTIVE 0 |
#define | LCDC_PRE_EIGTH 3 |
#define | LCDC_PRE_FOURTH 2 |
#define | LCDC_PRE_HALF 1 |
#define | LCDC_PRE_NONE 0 |
#define | LCDC_SINGLE_SCAN 0 |
#define | LCDC_STN_COLOR 1 |
#define | LCDC_STN_MONO 0 |
#define | LCDC_TFT 2 |
#define | LCDC_WIN_CE 2 |
Typedefs | |
typedef struct lcdc_configuration_s | lcdc_conf_t |
Struct that defines the configuration of the LCD controller. | |
Functions | |
int | lcdc_init (lcdc_conf_t *lcdc_conf) |
Configures the LCD module. |
#define LCDC_DUAL_SCAN 1 |
#define LCDC_IF_WIDTH16 2 |
#define LCDC_IF_WIDTH4 0 |
#define LCDC_IF_WIDTH8 1 |
#define LCDC_SINGLE_SCAN 0 |
#define LCDC_STN_COLOR 1 |
#define LCDC_STN_MONO 0 |
#define LCDC_TFT 2 |
typedef struct lcdc_configuration_s lcdc_conf_t |
Struct that defines the configuration of the LCD controller.
int lcdc_init | ( | lcdc_conf_t * | lcdc_conf | ) |
Configures the LCD module.
lcdc_conf | Pointer to LCD controller configuration structure |
0 | = success | |
-1 | = failure |
lcdc_conf | Pointer to LCD controller configuration structure |
0 | = success | |
-1 | = invalid argument |
Definition at line 57 of file lcdc.c.
References lcdc_configuration_s::burst_length, lcdc_configuration_s::clkmod, lcdc_configuration_s::ctrst_ena, lcdc_configuration_s::ctrst_pol, lcdc_configuration_s::ctrst_ps, lcdc_configuration_s::ctrstval, lcdc_configuration_s::distype, lcdc_configuration_s::dmabaddr1, lcdc_configuration_s::dmabaddr2, lcdc_configuration_s::frame_rate, lcdc_configuration_s::guard_time, lcdc_configuration_s::hbp, lcdc_configuration_s::hfp, lcdc_configuration_s::hpw, lcdc_configuration_s::ifwidth, lcdc_configuration_s::invclk, lcdc_configuration_s::invdval, lcdc_configuration_s::invframe, lcdc_configuration_s::invline, lcdc_configuration_s::invvd, LCDC_DUAL_SCAN, LCDC_IF_WIDTH16, LCDC_IF_WIDTH4, LCDC_IF_WIDTH8, LCDC_SINGLE_SCAN, LCDC_STN_COLOR, LCDC_STN_MONO, LCDC_TFT, lcdc_configuration_s::lcdcclock, lcdc_configuration_s::memor, lcdc_configuration_s::mmode, lcdc_configuration_s::mval, lcdc_configuration_s::pixelsize, lcdc_configuration_s::scanmod, lcdc_configuration_s::set2dmode, lcdc_configuration_s::vbp, lcdc_configuration_s::vfp, lcdc_configuration_s::vhdly, lcdc_configuration_s::virtual_xres, lcdc_configuration_s::vpw, lcdc_configuration_s::xres, and lcdc_configuration_s::yres.
Referenced by main().
00058 { 00059 volatile avr32_lcdc_t *plcdc = &AVR32_LCDC; 00060 unsigned char valid_data_lines = 0; 00061 unsigned char pixel_size = 0; 00062 unsigned char clkval = 0; 00063 unsigned int pixel_clock_theo = 0; 00064 unsigned short lineval, hozval; 00065 00066 /* Turn off LCD Controller (core first then DMA) */ 00067 plcdc->pwrcon &= ~(1 << AVR32_LCDC_PWRCON_PWR_OFFSET); 00068 plcdc->dmacon &= ~(1 << AVR32_LCDC_DMACON_DMAEN_OFFSET); 00069 00070 /* LCDFRCFG */ 00071 if(lcdc_conf->distype != LCDC_TFT){ 00072 switch(lcdc_conf->scanmod){ 00073 case LCDC_SINGLE_SCAN: 00074 switch(lcdc_conf->ifwidth){ 00075 case LCDC_IF_WIDTH4: 00076 valid_data_lines = 4; 00077 break; 00078 case LCDC_IF_WIDTH8: 00079 valid_data_lines = 8; 00080 break; 00081 default: 00082 return -1; 00083 } 00084 00085 case LCDC_DUAL_SCAN: 00086 switch(lcdc_conf->ifwidth){ 00087 case LCDC_IF_WIDTH8: 00088 valid_data_lines = 4; 00089 break; 00090 case LCDC_IF_WIDTH16: 00091 valid_data_lines = 8; 00092 break; 00093 default: 00094 return -1; 00095 } 00096 default: 00097 return -1; 00098 } 00099 } 00100 00101 lineval = lcdc_conf->yres - 1; 00102 switch(lcdc_conf->distype){ 00103 case LCDC_STN_MONO: 00104 hozval = (lcdc_conf->xres / valid_data_lines) - 1; 00105 break; 00106 case LCDC_STN_COLOR: 00107 hozval = (lcdc_conf->xres * 3 / valid_data_lines) - 1; 00108 break; 00109 case LCDC_TFT: 00110 hozval = lcdc_conf->xres - 1; 00111 break; 00112 default: 00113 return -1; 00114 } 00115 plcdc->lcdfrmcfg = (lineval & AVR32_LCDC_LINEVAL_MASK) | 00116 ((hozval << AVR32_LCDC_HOZVAL) & AVR32_LCDC_HOZVAL_MASK); 00117 00118 /* Calculation of theoretical pixel clock */ 00119 switch(lcdc_conf->distype){ 00120 case LCDC_STN_MONO: 00121 pixel_clock_theo = lcdc_conf->frame_rate * lcdc_conf->xres * lcdc_conf->yres / valid_data_lines; 00122 break; 00123 case LCDC_STN_COLOR: 00124 pixel_clock_theo = lcdc_conf->frame_rate * lcdc_conf->xres * lcdc_conf->yres * 3 / valid_data_lines; 00125 break; 00126 case LCDC_TFT: 00127 pixel_clock_theo = lcdc_conf->frame_rate * lcdc_conf->xres * lcdc_conf->yres; 00128 break; 00129 default: 00130 return -1; 00131 } 00132 clkval = (lcdc_conf->lcdcclock / (2 * pixel_clock_theo)); 00133 if (clkval == 0) { 00134 plcdc->lcdcon1 = 1; /* bypass pixel clock */ 00135 } else { 00136 plcdc->lcdcon1 = ((clkval - 1) << AVR32_LCDC_LCDCON1_CLKVAL) & AVR32_LCDC_LCDCON1_CLKVAL_MASK; 00137 } 00138 00139 /* LCDCON2 */ 00140 switch(lcdc_conf->pixelsize){ 00141 case 1: pixel_size = 0;break; 00142 case 2: pixel_size = 1;break; 00143 case 4: pixel_size = 2;break; 00144 case 8: pixel_size = 3;break; 00145 case 16: pixel_size = 4;break; 00146 case 24: pixel_size = 5;break; 00147 case 32: pixel_size = 6;break; 00148 default: 00149 return -1; 00150 } 00151 plcdc->lcdcon2 = (lcdc_conf->distype & AVR32_LCDC_LCDCON2_DISTYPE_MASK) | 00152 ((lcdc_conf->scanmod << AVR32_LCDC_LCDCON2_SCANMOD) & AVR32_LCDC_LCDCON2_SCANMOD_MASK) | 00153 ((lcdc_conf->ifwidth << AVR32_LCDC_LCDCON2_IFWIDTH) & AVR32_LCDC_LCDCON2_IFWIDTH_MASK) | 00154 ((lcdc_conf->invvd << AVR32_LCDC_LCDCON2_INVVD) & AVR32_LCDC_LCDCON2_INVVD_MASK) | 00155 ((lcdc_conf->invframe << AVR32_LCDC_LCDCON2_INVFRAME) & AVR32_LCDC_LCDCON2_INVFRAME_MASK) | 00156 ((pixel_size << AVR32_LCDC_LCDCON2_PIXELSIZE) & AVR32_LCDC_LCDCON2_PIXELSIZE_MASK) | 00157 ((lcdc_conf->invline << AVR32_LCDC_LCDCON2_INVLINE) & AVR32_LCDC_LCDCON2_INVLINE_MASK) | 00158 ((lcdc_conf->invclk << AVR32_LCDC_LCDCON2_INVCLK) & AVR32_LCDC_LCDCON2_INVCLK_MASK) | 00159 ((lcdc_conf->invdval << AVR32_LCDC_LCDCON2_INVDVAL) & AVR32_LCDC_LCDCON2_INVDVAL_MASK) | 00160 ((lcdc_conf->clkmod << AVR32_LCDC_LCDCON2_CLKMOD) & AVR32_LCDC_LCDCON2_CLKMOD_MASK) | 00161 ((lcdc_conf->memor << AVR32_LCDC_LCDCON2_MEMOR) & AVR32_LCDC_LCDCON2_MEMOR_MASK); 00162 00163 /* Timings */ 00164 plcdc->lcdtim1 = (lcdc_conf->vfp & AVR32_LCDC_LCDTIM1_VFP_MASK) | 00165 ((lcdc_conf->vbp << AVR32_LCDC_LCDTIM1_VBP) & AVR32_LCDC_LCDTIM1_VBP_MASK) | 00166 (((lcdc_conf->vpw - 1) << AVR32_LCDC_LCDTIM1_VPW) & AVR32_LCDC_LCDTIM1_VPW_MASK) | 00167 ((lcdc_conf->vhdly << AVR32_LCDC_LCDTIM1_VHDLY) & AVR32_LCDC_LCDTIM1_VHDLY_MASK); 00168 00169 plcdc->lcdtim2 = (lcdc_conf->hbp & AVR32_LCDC_HBP_MASK) | 00170 (((lcdc_conf->hpw - 1) << AVR32_LCDC_LCDTIM2_HPW) & AVR32_LCDC_LCDTIM2_HPW_MASK) | 00171 ((lcdc_conf->hfp << AVR32_LCDC_LCDTIM2_HFP) & AVR32_LCDC_LCDTIM2_HFP_MASK); 00172 00173 /* Interrupts */ 00174 plcdc->idr = 0xFFFFFFFF; 00175 00176 /* Toggle rate */ 00177 plcdc->lcdmval = (lcdc_conf->mval & AVR32_LCDC_LCDMVAL_MVAL_MASK) | 00178 ((lcdc_conf->mmode << AVR32_LCDC_LCDMVAL_MMODE_OFFSET) & AVR32_LCDC_LCDMVAL_MMODE_MASK); 00179 00180 /* Contrast */ 00181 plcdc->contrast_val = lcdc_conf->ctrstval; 00182 plcdc->contrast_ctr = (lcdc_conf->ctrst_ps & AVR32_LCDC_CONTRAST_CTR_PS_MASK) | 00183 ((lcdc_conf->ctrst_pol << AVR32_LCDC_CONTRAST_CTR_POL_OFFSET) & AVR32_LCDC_CONTRAST_CTR_POL_MASK) | 00184 ((lcdc_conf->ctrst_ena << AVR32_LCDC_CONTRAST_CTR_ENA_OFFSET) & AVR32_LCDC_CONTRAST_CTR_ENA_MASK); 00185 00186 /* Setup FIFO */ 00187 int lcd_fifo_size = lcdc_conf->scanmod ? 256 : 512; 00188 plcdc->lcdfifo = lcd_fifo_size - (2 * lcdc_conf->burst_length + 3); 00189 00190 /* DMA base address */ 00191 plcdc->dmabaddr1 = lcdc_conf->dmabaddr1; 00192 if(lcdc_conf->scanmod == LCDC_DUAL_SCAN){ 00193 plcdc->dmabaddr2 = lcdc_conf->dmabaddr2; 00194 } 00195 /* DMA frame configuration 00196 * The frame size is measured in words 00197 */ 00198 plcdc->dmafrmcfg = ((((lcdc_conf->xres * lcdc_conf->yres * lcdc_conf->pixelsize) + 31 )/ 32) & AVR32_LCDC_DMAFRMCFG_FRMSIZE_MASK) | 00199 (((lcdc_conf->burst_length - 1) << AVR32_LCDC_DMAFRMCFG_BRSTLEN) & AVR32_LCDC_DMAFRMCFG_BRSTLEN_MASK); 00200 00201 /* 2D configuration */ 00202 if(lcdc_conf->set2dmode){ 00203 /* Assumed is that the frame starts at a word boundary -> no pixel offset needed */ 00204 plcdc->dma2dcfg = ((lcdc_conf->virtual_xres - lcdc_conf->xres) * (lcdc_conf->pixelsize / 8)) & AVR32_LCDC_DMA2DCFG_ADDRINC_MASK; 00205 } 00206 00207 /* wait for DMA engine to become idle */ 00208 while (plcdc->dmacon & AVR32_LCDC_DMACON_DMABUSY); 00209 00210 /* and enable DMA with updated configuration */ 00211 if(lcdc_conf->set2dmode){ 00212 plcdc->dmacon = (1 << AVR32_LCDC_DMACON_DMAEN_OFFSET) | 00213 (1 << AVR32_LCDC_DMACON_DMAUPDT_OFFSET) | 00214 (1 << AVR32_LCDC_DMACON_DMA2DEN_OFFSET); 00215 } 00216 else{ 00217 plcdc->dmacon = (1 << AVR32_LCDC_DMACON_DMAEN_OFFSET) | 00218 (1 << AVR32_LCDC_DMACON_DMAUPDT_OFFSET); 00219 } 00220 /* enable LCD */ 00221 plcdc->pwrcon |= (lcdc_conf->guard_time << AVR32_LCDC_PWRCON_GUARD_TIME_OFFSET) & AVR32_LCDC_PWRCON_GUARD_TIME_MASK; 00222 00223 /* Wait for the LCDC core to become idle and enable it */ 00224 while (plcdc->PWRCON.busy == 1); 00225 plcdc->PWRCON.pwr = 1; 00226 00227 return 0; 00228 }