📄 formike128x128x16.c
字号:
{
//
// Get the next byte of image data.
//
ulByte = *pucData++;
//
// Loop through the pixels in this byte of image data.
//
for(; (lX0 < 8) && lCount; lX0++, lCount--)
{
//
// Draw this pixel in the appropriate color.
//
lBPP = ((unsigned long *)pucPalette)[(ulByte >>
(7 - lX0)) & 1];
WriteData(lBPP >> 8);
WriteData(lBPP);
}
//
// Start at the beginning of the next byte of image data.
//
lX0 = 0;
}
//
// The image data has been drawn.
//
break;
}
//
// The pixel data is in 4 bit per pixel format.
//
case 4:
{
//
// Loop while there are more pixels to draw. "Duff's device" is
// used to jump into the middle of the loop if the first nibble of
// the pixel data should not be used. Duff's device makes use of
// the fact that a case statement is legal anywhere within a
// sub-block of a switch statement. See
// http://en.wikipedia.org/wiki/Duff's_device for detailed
// information about Duff's device.
//
switch(lX0 & 1)
{
case 0:
while(lCount)
{
//
// Get the upper nibble of the next byte of pixel data
// and extract the corresponding entry from the
// palette.
//
ulByte = (*pucData >> 4) * 3;
ulByte = (*(unsigned long *)(pucPalette + ulByte) &
0x00ffffff);
//
// Translate this palette entry and write it to the
// screen.
//
ulByte = DPYCOLORTRANSLATE(ulByte);
WriteData(ulByte >> 8);
WriteData(ulByte);
//
// Decrement the count of pixels to draw.
//
lCount--;
//
// See if there is another pixel to draw.
//
if(lCount)
{
case 1:
//
// Get the lower nibble of the next byte of pixel
// data and extract the corresponding entry from
// the palette.
//
ulByte = (*pucData++ & 15) * 3;
ulByte = (*(unsigned long *)(pucPalette + ulByte) &
0x00ffffff);
//
// Translate this palette entry and write it to the
// screen.
//
ulByte = DPYCOLORTRANSLATE(ulByte);
WriteData(ulByte >> 8);
WriteData(ulByte);
//
// Decrement the count of pixels to draw.
//
lCount--;
}
}
}
//
// The image data has been drawn.
//
break;
}
//
// The pixel data is in 8 bit per pixel format.
//
case 8:
{
//
// Loop while there are more pixels to draw.
//
while(lCount--)
{
//
// Get the next byte of pixel data and extract the
// corresponding entry from the palette.
//
ulByte = *pucData++ * 3;
ulByte = *(unsigned long *)(pucPalette + ulByte) & 0x00ffffff;
//
// Translate this palette entry and write it to the screen.
//
ulByte = DPYCOLORTRANSLATE(ulByte);
WriteData(ulByte >> 8);
WriteData(ulByte);
}
//
// The image data has been drawn.
//
break;
}
}
}
//*****************************************************************************
//
//! Flushes any cached drawing operations.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//!
//! This functions flushes any cached drawing operations to the display. This
//! is useful when a local frame buffer is used for drawing operations, and the
//! flush would copy the local frame buffer to the display. For the ST7637
//! driver, the flush is a no operation.
//!
//! \return None.
//
//*****************************************************************************
static void
Formike128x128x16Flush(void *pvDisplayData)
{
//
// There is nothing to be done.
//
}
//*****************************************************************************
//
//! Draws a horizontal line.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX1 is the X coordinate of the start of the line.
//! \param lX2 is the X coordinate of the end of the line.
//! \param lY is the Y coordinate of the line.
//! \param ulValue is the color of the line.
//!
//! This function draws a horizontal line on the display. The coordinates of
//! the line are assumed to be within the extents of the display.
//!
//! \return None.
//
//*****************************************************************************
static void
Formike128x128x16LineDrawH(void *pvDisplayData, long lX1, long lX2, long lY,
unsigned long ulValue)
{
//
// Set the extent of the line along the X axis.
//
WriteCommand(0x2a);
WriteData(lX1);
WriteData(lX2);
//
// Set the Y address of the display cursor.
//
WriteCommand(0x2b);
WriteData(lY + 1);
WriteData(lY + 1);
//
// Write the data RAM write command.
//
WriteCommand(0x2c);
//
// Loop through the pixels of this horizontal line.
//
while(lX1++ <= lX2)
{
//
// Write the pixel value.
//
WriteData(ulValue >> 8);
WriteData(ulValue);
}
}
//*****************************************************************************
//
//! Draws a vertical line.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param lX is the X coordinate of the line.
//! \param lY1 is the Y coordinate of the start of the line.
//! \param lY2 is the Y coordinate of the end of the line.
//! \param ulValue is the color of the line.
//!
//! This function draws a vertical line on the display. The coordinates of the
//! line are assumed to be within the extents of the display.
//!
//! \return None.
//
//*****************************************************************************
static void
Formike128x128x16LineDrawV(void *pvDisplayData, long lX, long lY1, long lY2,
unsigned long ulValue)
{
//
// Set the X address of the display cursor.
//
WriteCommand(0x2a);
WriteData(lX);
WriteData(lX);
//
// Set the extent of the line along the Y axis.
//
WriteCommand(0x2b);
WriteData(lY1 + 1);
WriteData(lY2 + 1);
//
// Write the data RAM write command.
//
WriteCommand(0x2c);
//
// Loop through the pixels of this vertical line.
//
while(lY1++ <= lY2)
{
//
// Write the pixel value.
//
WriteData(ulValue >> 8);
WriteData(ulValue);
}
}
//*****************************************************************************
//
//! Fills a rectangle.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param pRect is a pointer to the structure describing the rectangle.
//! \param ulValue is the color of the rectangle.
//!
//! This function fills a rectangle on the display. The coordinates of the
//! rectangle are assumed to be within the extents of the display, and the
//! rectangle specification is fully inclusive (i.e. both sXMin and sXMax are
//! drawn, along with sYMin and sYMax).
//!
//! \return None.
//
//*****************************************************************************
static void
Formike128x128x16RectFill(void *pvDisplayData, const tRectangle *pRect,
unsigned long ulValue)
{
long lCount;
//
// Set the extent of the rectangle along the X axis.
//
WriteCommand(0x2a);
WriteData(pRect->sXMin);
WriteData(pRect->sXMax);
//
// Set the extent of the rectangle along the Y axis.
//
WriteCommand(0x2b);
WriteData(pRect->sYMin + 1);
WriteData(pRect->sYMax + 1);
//
// Write the data RAM write command.
//
WriteCommand(0x2c);
//
// Loop through the pixels in this rectangle.
//
for(lCount = ((pRect->sXMax - pRect->sXMin + 1) *
(pRect->sYMax - pRect->sYMin + 1)); lCount > 0; lCount--)
{
//
// Write the pixel value.
//
WriteData(ulValue >> 8);
WriteData(ulValue);
}
}
//*****************************************************************************
//
//! Translates a 24-bit RGB color to a display driver-specific color.
//!
//! \param pvDisplayData is a pointer to the driver-specific data for this
//! display driver.
//! \param ulValue is the 24-bit RGB color. The least-significant byte is the
//! blue channel, the next byte is the green channel, and the third byte is the
//! red channel.
//!
//! This function translates a 24-bit RGB color into a value that can be
//! written into the display's frame buffer in order to reproduce that color,
//! or the closest possible approximation of that color.
//!
//! \return Returns the display-driver specific color.
//
//*****************************************************************************
static unsigned long
Formike128x128x16ColorTranslate(void *pvDisplayData, unsigned long ulValue)
{
//
// Translate from a 24-bit RGB color to a 5-6-5 RGB color.
//
return(DPYCOLORTRANSLATE(ulValue));
}
//*****************************************************************************
//
//! The display structure that describes the driver for the Formike Electronic
//! KWH015C04-F01 CSTN panel with an ST7637 controller.
//
//*****************************************************************************
const tDisplay g_sFormike128x128x16 =
{
sizeof(tDisplay),
0,
128,
128,
Formike128x128x16PixelDraw,
Formike128x128x16PixelDrawMultiple,
Formike128x128x16LineDrawH,
Formike128x128x16LineDrawV,
Formike128x128x16RectFill,
Formike128x128x16ColorTranslate,
Formike128x128x16Flush
};
//*****************************************************************************
//
// Close the Doxygen group.
//! @}
//
//*****************************************************************************
/* FreeRTOS.org demo wrappers. These are required so the prototypes for the
functions are the same as for the display drivers used by other evaluation
kits. */
static tContext sContext;
void vFormike128x128x16Clear( void )
{
const tRectangle xRectangle = { 0, 0, 127, 127 };
GrContextForegroundSet( &sContext, ClrBlack );
GrRectFill( &sContext, &xRectangle );
GrContextForegroundSet(&sContext, ClrWhite);
}
/*-----------------------------------------------------------*/
void vFormike128x128x16StringDraw( const char *pcString, unsigned long lX, unsigned long lY, unsigned char ucColor )
{
GrContextForegroundSet(&sContext, ClrWhite);
GrStringDraw( &sContext, pcString, strlen( pcString ), lX, lY, false );
}
/*-----------------------------------------------------------*/
void vFormike128x128x16Init( unsigned long ul )
{
tRectangle rectScreen;
( void ) ul;
Formike128x128x16Init();
Formike128x128x16BacklightOn();
GrContextInit(&sContext, &g_sFormike128x128x16);
GrContextFontSet(&sContext, &g_sFontCmss12);
rectScreen.sXMin = 0;
/* Fill the screen with a black rectangle. */
rectScreen.sYMin = 0;
rectScreen.sXMax = g_sFormike128x128x16.usWidth - 1;
rectScreen.sYMax = g_sFormike128x128x16.usHeight - 1;
GrContextForegroundSet(&sContext, ClrBlack);
GrRectFill(&sContext, &rectScreen);
}
/*-----------------------------------------------------------*/
void vFormike128x128x16ImageDraw( const unsigned char *pucImage, unsigned long ulX, unsigned long ulY, unsigned long ulWidth, unsigned long ulHeight )
{
GrImageDraw( &sContext, pucImage, ( long ) ulX, ( long ) ulY);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -