📄 lpc177x_8x_lcd.c
字号:
if(lcd_config.big_endian_pixel & lcd_config.big_endian_byte)
{
ofs = 32 - bits_per_pixel[lcd_config.lcd_bpp] - ofs;
}
else if (lcd_config.big_endian_pixel & !lcd_config.big_endian_byte)
{
if(bits_per_pixel[lcd_config.lcd_bpp] < 8)
{
ofs = (ofs/8)*8 + (8 - (ofs%8)-bits_per_pixel[lcd_config.lcd_bpp]);
}
}
return ofs;
}
/*********************************************************************//**
* @brief Copy pixel values from image buffer to frame buffer.
*
* @param[in] panel It can be:
* - LCD_PANEL_UPPER
* - LCD_PANEL_LOWER
* @param[in] pPain point to image buffer.
*
* @return None.
*
**********************************************************************/
void LCD_SetImage(LCD_PANEL panel, const uint8_t *pPain)
{
uint32_t i;
uint32_t * pWordDst = NULL;
uint8_t* pByteDst = NULL;
uint32_t bytes_num;
if(panel == LCD_PANEL_UPPER)
pWordDst = (uint32_t*) LPC_LCD->UPBASE;
else
pWordDst = (uint32_t*) LPC_LCD->LPBASE;
pByteDst = (uint8_t*) pWordDst;
bytes_num = ((lcd_hsize * lcd_vsize) * bits_per_pixel[lcd_config.lcd_bpp]) /8;
if (NULL == pPain)
{
// clear display memory
for( i = 0; bytes_num > i; i++)
{
*pByteDst++ = 0;
}
}
else
{
// set display memory
for(i = 0; bytes_num > i; i++)
{
*pByteDst++ = *pPain++;
}
}
for(i = LCD_PWR_ENA_DIS_DLY; i; i--);
}
/*********************************************************************//**
* @brief Place given image to given position.
*
* @param[in] panel It can be:
* - LCD_PANEL_UPPER
* - LCD_PANEL_LOWER
* @param[in] X_Left Start X position.
* @param[in] Y_Up Start Y position.
* @param[in] pBmp Image information.
* @param[in] Mask Mask on pixel values.
*
* @return None.
*
**********************************************************************/
void LCD_LoadPic (LCD_PANEL panel, uint32_t X_Left, uint32_t Y_Up,
Bmp_t * pBmp, uint32_t Mask)
{
uint32_t i, j, k, inc;
uint32_t * pWordData = NULL;
uint8_t* pByteData = NULL;
uint32_t bitOffset;
uint8_t* pByteSrc = (uint8_t*) pBmp->pPicStream;
uint32_t X_LeftHold = X_Left;
uint8_t bpp = bits_per_pixel[lcd_config.lcd_bpp];
uint8_t bytes_per_pixel = bpp/8;
uint8_t pixels_per_byte = 8/bpp;
uint32_t hsize, vsize;
uint32_t start_bit;
if(pBmp->BytesPP == 0)
pBmp->BytesPP = bytes_per_pixel;
hsize = pBmp->H_Size;
vsize = pBmp->V_Size;
inc = (pixels_per_byte > 0) ? pixels_per_byte:1;
for(i = 0; i < vsize; i++)
{
if(panel == LCD_PANEL_UPPER)
pWordData = (uint32_t*) LPC_LCD->UPBASE + LCD_GetWordOffset(X_Left,Y_Up);
else
pWordData = (uint32_t*) LPC_LCD->LPBASE + LCD_GetWordOffset(X_Left,Y_Up);
bitOffset = LCD_GetBitOffset(X_Left,Y_Up);
pByteData = (uint8_t*) pWordData;
pByteData += bitOffset/8;
start_bit = bitOffset%8;
if(pBmp->BytesPP > 0)
pByteSrc = (uint8_t*) pBmp->pPicStream + i*hsize*pBmp->BytesPP; // storage of each line must be word alignment
else
pByteSrc = (uint8_t*) pBmp->pPicStream + (i*hsize*pBmp->BitsPP + 7)/8; // storage of each line must be word alignment
X_LeftHold = X_Left;
for(j = 0; j <= hsize; j+= inc)
{
if((X_LeftHold >= lcd_hsize) || (X_LeftHold - X_Left >= hsize))
break;
if(bpp < 8)
{
uint8_t bit_pos = start_bit;
uint8_t bit_ofs = 0;
for(k = 0; k < 8; k+= bpp)
{
for(bit_ofs = 0;bit_ofs <bpp; bit_ofs++,bit_pos++)
{
*pByteData &= ~ (0x01 << bit_pos);
*pByteData |= ((*pByteSrc >> (k+bit_ofs)) & 0x01) << bit_pos;
}
if(lcd_config.big_endian_byte && lcd_config.big_endian_pixel)
{
if(bit_pos >= bpp*2)
bit_pos -= bpp*2;
else
{
bit_pos = 8-bpp;
if((((uint32_t)pByteData)%4) == 0)
pByteData += 7; // change to next word
else
pByteData--; // change to previous byte
}
}
else if( !lcd_config.big_endian_byte && lcd_config.big_endian_pixel)
{
if(bit_pos >= bpp*2)
bit_pos -= bpp*2;
else
{
bit_pos = 8-bpp;
pByteData++; // change to next byte
}
}
else
{
if(bit_pos >= 8)
{
bit_pos = 0;
pByteData++; // change to next byte
}
}
X_LeftHold++;
if((X_LeftHold >= lcd_hsize) ||
(X_LeftHold - X_Left >= hsize))
break;
}
pByteSrc++;
continue;
}
else
{
for(k = 0; k < pBmp->BytesPP; k++)
{
*(pByteData+ k) = *pByteSrc++ ^ Mask;
}
if(lcd_config.big_endian_byte)
{
if((uint32_t)pByteData %4 > 0)
pByteData -= bytes_per_pixel;
else
pByteData += 8 - bytes_per_pixel;
}
else
pByteData+= bytes_per_pixel;
X_LeftHold++;
}
}
if(Y_Up++ >= lcd_vsize)
{
break;
}
}
}
/*********************************************************************//**
* @brief Fill a rectangle.
*
* @param[in] panel It can be:
* - LCD_PANEL_UPPER
* - LCD_PANEL_LOWER
* @param[in] startx Start X position.
* @param[in] endy End X position.
* @param[in] starty Start Y position.
* @param[in] endy End Y position.
*
* @return None.
*
**********************************************************************/
void LCD_FillRect (LCD_PANEL panel, uint32_t startx,uint32_t endx,
uint32_t starty, uint32_t endy,
LcdPixel_t color)
{
uint32_t x, xs, xe, ys, ye;
uint8_t bpp, pixels_per_word;
uint32_t word_val, mask;
uint32_t max_vsize = 0;
Bmp_t bitmap;
uint32_t hsize, vsize;
bpp = bits_per_pixel[lcd_config.lcd_bpp];
pixels_per_word = 32/bpp;
mask = 0;
for( x = 0; x < bpp; x++)
mask |= 0x01 << x;
color &= mask;
word_val = 0;
for(x = 0; x < pixels_per_word; x++)
word_val |= color << (x*bpp);
ys = (starty > endy) ? endy : starty;
ye = (starty > endy) ? starty : endy;
xs = (startx > endx) ? endx : startx;
xe = (startx > endx) ? startx : endx;
bitmap.BitsPP = bpp;
bitmap.BytesPP = bpp/8;
hsize = xe - xs + 1;
bitmap.H_Size = hsize;
vsize = ye - ys + 1;
bitmap.pPicStream = (uint8_t*)rect;
max_vsize = ((1024 * 32)/(hsize*bpp));
for( x = 0; x < 1024; x++)
{
rect[x] = word_val;
}
while(1)
{
if(max_vsize >= vsize)
{
bitmap.V_Size = vsize;
LCD_LoadPic(panel,xs,ys, &bitmap, 0);
break;
}
else {
bitmap.V_Size = max_vsize;
vsize -= bitmap.V_Size;
LCD_LoadPic(panel,xs,ys, &bitmap, 0);
ys += max_vsize;
}
}
}
/*********************************************************************//**
* @brief Configure display of cursor.
*
* @param[in] pConfig Configuration information.
*
* @return None.
*
**********************************************************************/
void LCD_Cursor_Cfg(LCD_Cursor_Config_Type* pConfig)
{
if(pConfig->size32) {
LPC_LCD->CRSR_CFG &= ~(0x01 << 0);
lcd_cursor_size = 32;
}
else {
LPC_LCD->CRSR_CFG |= (0x01 << 0);
lcd_cursor_size = 64;
}
if(pConfig->framesync)
LPC_LCD->CRSR_CFG &= ~(0x01 << 1);
else
LPC_LCD->CRSR_CFG |= (0x01 << 1);
lcd_cursor_base_addr = pConfig->baseaddress;
LPC_LCD->CRSR_PAL0 = pConfig->palette[0].Red |
pConfig->palette[0].Green << 8 |
pConfig->palette[0].Blue << 16;
LPC_LCD->CRSR_PAL1 = pConfig->palette[1].Red |
pConfig->palette[1].Green << 8 |
pConfig->palette[1].Blue << 16;
}
/*********************************************************************//**
* @brief Enable/disable cursor display.
*
* @param[in] enable 0: disable, 1: enable.
* @param[in] cursor identify which cursor image is used.
*
* @return None.
*
**********************************************************************/
void LCD_Cursor_Enable(int enable, int cursor)
{
if(enable) {
LPC_LCD->CRSR_CTRL |= (1<<0);
LPC_LCD->CRSR_CTRL |= (cursor<<4);
}
else {
LPC_LCD->CRSR_CTRL &= ~(1<<0);
}
}
/*********************************************************************//**
* @brief move the cursor to the inputted position.
*
* @param[in] x Position in x-direction.
* @param[in] y Position in y-direction.
*
* @return None.
*
**********************************************************************/
void LCD_Move_Cursor(int x, int y)
{
LPC_LCD->CRSR_CLIP = 0;
LPC_LCD->CRSR_XY = 0;
if(0 <= x)
{//no clipping
LPC_LCD->CRSR_XY |= (x & 0x3FF);
}
else
{//clip x
LPC_LCD->CRSR_CLIP |= -x;
}
if(0 <= y)
{//no clipping
LPC_LCD->CRSR_XY |= (y << 16);
}
else
{//clip y
LPC_LCD->CRSR_CLIP |= (-y << 8);
}
}
/*********************************************************************//**
* @brief Set the cursor image.
*
* @param[in] pCursor point to cursor image.
* @param[in] cursor cursor image number. It has no meaning when cursor size is 64x64
* @param[in] cursor cursor size in words.
*
* @return None.
*
**********************************************************************/
void LCD_Cursor_SetImage (const uint32_t *pCursor, int cursor, int size)
{
uint32_t i ;
uint32_t * pDst = (uint32_t *)lcd_cursor_base_addr;
if(lcd_cursor_size == 32)
pDst += cursor*GET_CURSOR_IMG_SIZE(lcd_cursor_size);
for(i = 0; i < size ; i++)
{
*pDst = *pCursor;
pDst++;
pCursor++;
}
}
/**
* @}
*/
#endif /*_LCD*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -