📄 xslcdcontroller.c
字号:
PostDisplayProgress(ERR_L_LCD, 5, 8);
// Setup control register 3
LCDCTRL_REG_BASE->LCCR3 = lcdPanelP->pixelClkDiv << LCD_LCCR3_PCD_SHIFT |
lcdPanelP->acBiasCount << LCD_LCCR3_ACB_SHIFT |
(lcdPanelP->clockPol ? LCD_LCCR3_PCP_DATSAMPFALL : 0) |
calculateBpp(lcdPanelP->colorDepth) << LCD_LCCR3_BPP_SHIFT |
(lcdPanelP->horizSyncPol ? LCD_LCCR3_HSP_ACTLOW : 0) |
(lcdPanelP->frameSyncPol ? LCD_LCCR3_VSP_ACTLOW : 0)
// | LCD_LCCR3_DPC_DBLFRQ
;
PostDisplayProgress(ERR_L_LCD, 5, 9);
// Point to the descriptor
LCDCTRL_REG_BASE->FDADR0 = frameP->header.DmaDescriptor.FDADR;
PostDisplayProgress(ERR_L_LCD, 5, 0xa);
if (fifo==NULL) fifo = FIFOalloc(2048, first, last);
if (fifo==NULL) return ERRORCODEX(ERR_L_LCD, 5, 0xa, ERR_L_HEAP);
PostDisplayProgress(ERR_L_LCD, 5, 0xb);
if (ROS_Tasks) {
XsLcdTask = ROS_New(ROS_STACK, ROS_HIGHESTPRIO, XsLcdOut);
if (!XsLcdTask) return ERRORCODEX(ERR_L_LCD, 5, 0xb, ERR_L_ROS);
ROS_Sleep(XsLcdTask);
}
return ERR_NONE;
} // end XsLcdHWSetup
/*
*******************************************************************************
*
* FUNCTION: XsLcdSWInit
*
* DESCRIPTION: This function is the software init for this driver.
*
* INPUT PARAMETERS: None.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdSWInit(void);
*
*******************************************************************************
*/
void XsLcdSWInit(void)
{
PostDisplayProgress(ERR_L_LCD, 6, 0);
if (fifo==NULL) fifo = FIFOalloc(2048, first, last);
PostDisplayProgress(ERR_L_LCD, 6, 1);
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdBackLightOn
*
* DESCRIPTION: This function turns the LCD backlight on.
*
* INPUT PARAMETERS: None.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdBackLightOn(void);
*
*******************************************************************************
*/
void XsLcdBackLightOn(void)
{
PostDisplayProgress(ERR_L_LCD, 7, 0);
XsPwmWriteCtrl(0,0);
PostDisplayProgress(ERR_L_LCD, 7, 1);
//Set the duty cycle to 100%
XsPwmWriteDuty(0,0x3FF);
PostDisplayProgress(ERR_L_LCD, 7, 2);
//Set the period value to its max. (0x3FF)
XsPwmWritePerval(0,0x3FF);
PostDisplayProgress(ERR_L_LCD, 7, 3);
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdClear
*
* DESCRIPTION: This function clears the LCD to the color in XsLcdBg.
*
* INPUT PARAMETERS: None.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdClear(void);
*
*******************************************************************************
*/
void XsLcdClear(void)
{
PUINT32 p = (PUINT32)frameP->buffer;
PUINT32 e = (PUINT32)((PUINT8)frameP->buffer+frameP->header.size);
UINT32 z;
y = x = 0; // Reset character output "cursor".
PostDisplayProgress(ERR_L_LCD, 8, 0);
z = XsLcdBg;
z |= z<<16;
while (p<e) *(p++) = z;
PostDisplayProgress(ERR_L_LCD, 8, 1);
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdRGB565
*
* DESCRIPTION: This function translates a 24 bit color to a 16 bit color.
*
* INPUT PARAMETERS: UINT8 red - The "red" part of the 24 bit color.
* UINT8 green - The "green" part of the 24 bit color.
* UINT8 blue - The "blue" part of the 24 bit color.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: UINT16 XsLcdRGB565(UINT8 red, UINT8 green, UINT8 blue);
*
*******************************************************************************
*/
UINT16 XsLcdRGB565(UINT8 red, UINT8 green, UINT8 blue)
{
return ((UINT16)((UINT16)red>>3)<<11 | ((UINT16)green>>2)<<5 | (UINT16)blue>>3);
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdChar
*
* DESCRIPTION: This function puts a text character to the LCD FIFO.
*
* INPUT PARAMETERS: CHAR c - The character to put.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdChar(CHAR c);
*
*******************************************************************************
*/
void XsLcdChar(CHAR c)
{
// PostDisplayProgress(ERR_L_LCD, 0xe, 0);
if (fifo != NULL) FIFOput(fifo, c);
// if (FIFOcharsAvailable(fifo)) XsLcdOut();
// PostDisplayProgress(ERR_L_LCD, 0xe, 1);
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdStr
*
* DESCRIPTION: This function writes a text string to the LCD.
*
* INPUT PARAMETERS: PCHAR s - The string to write.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdStr(PCHAR s);
*
*******************************************************************************
*/
void XsLcdStr(PCHAR s)
{
while (*s) XsLcdChar(*s++);
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdOut
*
* DESCRIPTION: This function writes a text character to the LCD
* from the FIFO.
*
* INPUT PARAMETERS: None.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdOut(void);
*
*******************************************************************************
*/
void XsLcdOut(void)
{
static INT16 maxx, maxy;
UINT8 px, py, s1, s2;
INT16 c;
while (1) {
// PostDisplayProgress(ERR_L_LCD, 0xa, 0);
if (x==0 && y==0) {
maxx = (XsLcdOrient!=LRTB?frameP->header.vertPixel:frameP->header.horizPixel)/(FONT_HORZ_PIX*XsLcdFontScale);
maxy = (XsLcdOrient!=LRTB?frameP->header.horizPixel:frameP->header.vertPixel)/(FONT_VERT_PIX*XsLcdFontScale);
}
c = FIFOget(fifo);
if (c == '\r') x = 0;
else if (c == '\n') y++;
else if (c == '\f') XsLcdClear();
else if (c == '\a') {
if (!XsLcdTask) DM_WaitS(5);
else ROS_Timer(XsLcdTask, 500, 2);
} else if (c == '\b') { if (x) x--; }
else if (c != EOF) {
if (x >= maxx) {
x = 0;
y++;
}
while (y >= maxy) {
y--;
// PostDisplayProgress(ERR_L_LCD, 0xa, 1);
XsLcdScroll();
}
// PostDisplayProgress(ERR_L_LCD, 0xa, 2);
for (py=0; py<FONT_VERT_PIX; py++)
for (px=0; px<FONT_HORZ_PIX; px++)
for (s1=0; s1<XsLcdFontScale; s1++)
for (s2=0; s2<XsLcdFontScale; s2++)
XsLcdPutXY(
(x*FONT_HORZ_PIX+px)*XsLcdFontScale+s1,
(XsLcdOrient!=LRTB?frameP->header.horizPixel:frameP->header.vertPixel)-1 // Max y pixel.
- ((y*FONT_VERT_PIX+py)*XsLcdFontScale+s2),
(font[c][py]&(0x80>>px))?XsLcdFg:XsLcdBg
);
x++;
}
// PostDisplayProgress(ERR_L_LCD, 0xa, 3);
if (!XsLcdTask) {
if (FIFOcharsAvailable(fifo)) continue;
return; // If the task isn't running, just return.
}
ROS_Sleep(ROS_Task);
// PostDisplayProgress(ERR_L_LCD, 0xa, 4);
ROS_Release();
// PostDisplayProgress(ERR_L_LCD, 0xa, 5);
}
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdPutXY
*
* DESCRIPTION: This function writes a pixel to the LCD.
* The origin (0,0) is the lower left hand corner.
*
* INPUT PARAMETERS: UINT16 x - The "X" coordinate.
* UINT16 y - The "Y" coordinate.
* UINT16 p - The pixel data to put.
*
* RETURNS: None.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: 16 bits per pixel
*
* CALLS: None.
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdPutXY(UINT16 x, UINT16 y, UINT16 p);
*
*******************************************************************************
*/
void XsLcdPutXY(UINT16 x, UINT16 y, UINT16 p)
{
if (XsLcdOrient == BTLR) { // Scan is Bottom to Top, Left to Right
// PostDisplayProgress(ERR_L_LCD, 0xd, 0);
*(frameP->buffer + y +
x*frameP->header.horizPixel) = p;
} else if (XsLcdOrient == LRTB) { // Scan is Left to Right, Top to Bottom
// PostDisplayProgress(ERR_L_LCD, 0xd, 1);
*(frameP->buffer + x +
(frameP->header.vertPixel-y-1)*frameP->header.horizPixel) = p;
} else if (XsLcdOrient == TBRL) { // Scan is Top to Bottom, Right to Left
*(frameP->buffer + (frameP->header.horizPixel-y-1) +
(frameP->header.vertPixel-x-1)*frameP->header.horizPixel) = p;
} else if (XsLcdOrient == LRBT) { // Scan is Left to Right, Bottom to Top
*(frameP->buffer + x +
y*frameP->header.horizPixel) = p;
}
// PostDisplayProgress(ERR_L_LCD, 0xd, 2);
}
/*
*******************************************************************************
*
* FUNCTION: XsLcdBmp
*
* DESCRIPTION: This function is responsible for parsing a BMP
* file (24bpp depth), converting it into a 16bpp
* depth format and displaying the converted file.
*
* INPUT PARAMETERS: BmpT *bmpP - Pointer to the BMP.
*
* RETURNS: TRUE if successful, else FALSE.
*
* GLOBAL EFFECTS: None.
*
* ASSUMPTIONS: None.
*
* CALLS:
*
* CALLED BY: Anyone.
*
* PROTOTYPE: void XsLcdBmp(BmpT *bmpP);
*
*******************************************************************************
*/
BOOL XsLcdBmp(BmpT *bmpP)
{
UINT x, y, z=0;
BOOL twist = FALSE;
UINT orient = XsLcdOrient;
// First, verify it.
// look for the expected width and height
PostDisplayProgress(ERR_L_LCD, 0xc, 0);
((PUINT16)bmpHeader)[9] = frameP->header.horizPixel;
((PUINT16)bmpHeader)[11] = frameP->header.vertPixel;
// compute the expected file size.
x = frameP->header.horizPixel;
x *= frameP->header.vertPixel;
x *= 3; // 3 bytes per pixel
((PUINT16)bmpHeader)[17] = (UINT16)(x % 0x10000);
((PUINT16)bmpHeader)[18] = (UINT16)(x / 0x10000);
x += 54; // .BMP header size
((PUINT16)bmpHeader)[1] = (UINT16)(x % 0x10000);
((PUINT16)bmpHeader)[2] = (UINT16)(x / 0x10000);
for (x=0; x<sizeof(bmpP->header)/4; x++) {
if (((PUINT32)bmpP->header)[x] != bmpHeader[x]) {
PostDisplayProgress(ERR_L_LCD, 0xc, 1);
if (x==4 && !twist) { // try the other orientation
PostDisplayProgress(ERR_L_LCD, 0xc, 2);
x = bmpHeader[4]; // swap expected width and height
bmpHeader[4] = bmpHeader[5];
bmpHeader[5] = x;
twist = TRUE;
x = 3;
} else return FALSE;
}
}
// Now, parse it.
if (twist) {
if (XsLcdOrient == LRTB) XsLcdOrient = BTLR;
PostDisplayProgress(ERR_L_LCD, 0xc, 3);
for (y=0; y<frameP->header.horizPixel; y++) {
for (x=0; x<frameP->header.vertPixel; x++) {
XsLcdPutXY(
x,
y,
XsLcdRGB565(
bmpP->pixel[z].red,
bmpP->pixel[z].green,
bmpP->pixel[z].blue
)
);
z++;
}
if (!(y&0xf)) ROS_Release();
}
} else {
if (XsLcdOrient != LRTB) XsLcdOrient = LRTB;
PostDisplayProgress(ERR_L_LCD, 0xc, 4);
for (y=0; y<frameP->header.vertPixel; y++) {
for (x=0; x<frameP->header.horizPixel; x++) {
XsLcdPutXY(
x,
y,
XsLcdRGB565(
bmpP->pixel[z].red,
bmpP->pixel[z].green,
bmpP->pixel[z].blue
)
);
z++;
}
if (!(y&0xf)) ROS_Release();
}
}
XsLcdOrient = orient; // Restore orientation;
PostDisplayProgress(ERR_L_LCD, 0xc, 5);
return TRUE;
}
/**************************************************************
在LCD屏幕上指定坐标点画一个指定大小的图片
**************************************************************/
void Paint_Bmp(int x0,int y0,int h,int l,unsigned char bmp[])
{
int x,y;
UINT32 c;
int p = 0;
//本图片显示是正的显示方式
for( y = 0 ; y < l ; y++ )
{
for( x = 0 ; x < h ; x++ )
{
c = bmp[p+1] | (bmp[p]<<8) ;
if ( ( (x0+x) < 240) && ( (y0+y) < 320) )
XsLcdPutXY(x0+x, y0+y, c);
p = p + 2 ;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -