void LCDDisplay::Plot(UINT X, UINT Y, Color C) { WORD Address; BYTE BitSetCommand; if ((X > MaxX) || (Y > MaxY)) IgnorableError(LCDDisplay_PlotOutOfBounds); else { Address = (30*Y+X/8)+GraphicsHomeAddress; // Now that we know what byte contains the specified dot, // set the LCD display address pointer to point to that // location LCDWriteData(LOBYTE(Address)); LCDWriteData(HIBYTE(Address)); LCDWriteCommand(0x24); // address pointer set command // Set or clear the correct bit at that address. // Figure out which bit in that byte to set. BitSetCommand = 7 - (X % 8); // Set the color of the bit. if (C == Black) BitSetCommand = BitSetCommand | 0x08; // Set the bit // Finish the command BitSetCommand = BitSetCommand | 0xF0; LCDWriteCommand(BitSetCommand); } }
// Configure display controller to write to defined display area void LCDAddressWindow(const tRectangle *pRect) { #ifdef PORTRAIT LCDWriteCommand(ILI_HOR_START_AD); LCDWriteData(pRect->sXMin); LCDWriteCommand(ILI_HOR_END_AD); LCDWriteData(pRect->sXMax); LCDWriteCommand(ILI_VER_START_AD); LCDWriteData(pRect->sYMin); LCDWriteCommand(ILI_VER_END_AD); LCDWriteData(pRect->sYMax); #else LCDWriteCommand(ILI_HOR_START_AD); LCDWriteData(LCD_X - pRect->sYMax); LCDWriteCommand(ILI_HOR_END_AD); LCDWriteData(LCD_X - pRect->sYMin); LCDWriteCommand(ILI_VER_START_AD); LCDWriteData(pRect->sXMin); LCDWriteCommand(ILI_VER_END_AD); LCDWriteData(pRect->sXMax); #endif // Set pointer to first address in that window LCDGoto(pRect->sXMin, pRect->sYMin); }
void Adafruit320x240x16_ILI9325PixelDrawMultiple(void *pvDisplayData, long lX, long lY, long lX0, long lCount, long lBPP, const unsigned char *pucData, const unsigned char *pucPalette) { // Start talking to LCD LCD_CS_ACTIVE #ifdef LANDSCAPE // Configure write direction to horizontal LCDWriteCommand(ILI_ENTRY_MOD); LCDWriteData(0x1038); #endif LCDGoto(lX,lY); unsigned long ulPixel = 0; unsigned long ulColor = 0; if(lBPP == 1) { // 1 bit per pixel in pucData // lX0 is the index of the bit processed within a byte // pucPalette holds the pre-translated 32bit display color while(lCount) { ulPixel = *pucData++; while(lCount && lX0 < 8) // while there are pixels in this byte { ulColor = ((unsigned long *)pucPalette)[ulPixel & 1]; // retrieve already translated color LCDWriteData(ulColor); lCount--; // processed another pixel lX0++; // done with this bit ulPixel >>= 1; // prepare next bit } lX0 = 0; // process next byte, reset bit counter } } else if(lBPP == 4)
// Coordinates of next display write void LCDGoto(unsigned short x, unsigned short y) { if(x >= LCD_WIDTH) x = LCD_WIDTH - 1; if(y >= LCD_HEIGHT) y = LCD_HEIGHT - 1; #ifdef PORTRAIT LCDWriteCommand(ILI_GRAM_HOR_AD); // GRAM Address Set (Horizontal Address) (R20h) LCDWriteData(x); LCDWriteCommand(ILI_GRAM_VER_AD); // GRAM Address Set (Vertical Address) (R21h) LCDWriteData(y); LCDWriteCommand(ILI_RW_GRAM); // Write Data to GRAM (R22h) #else LCDWriteCommand(ILI_GRAM_HOR_AD); // GRAM Address Set (Horizontal Address) (R20h) LCDWriteData(LCD_X - y); LCDWriteCommand(ILI_GRAM_VER_AD); // GRAM Address Set (Vertical Address) (R21h) LCDWriteData(x); LCDWriteCommand(ILI_RW_GRAM); // Write Data to GRAM (R22h) #endif g_usPosX = x; g_usPosY = y; }
// Initializing display void Adafruit320x240x16_ILI9325Init(void) { unsigned short usAddress, usData; // Reset global variables g_ulWait1ms = SysCtlClockGet() / (3 * 1000); // Enable GPIO peripherals SysCtlPeripheralEnable(LCD_DATA_PERIPH); SysCtlPeripheralEnable(LCD_CS_PERIPH); SysCtlPeripheralEnable(LCD_CD_PERIPH); SysCtlPeripheralEnable(LCD_WR_PERIPH); SysCtlPeripheralEnable(LCD_RD_PERIPH); SysCtlPeripheralEnable(LCD_RST_PERIPH); SysCtlPeripheralEnable(LCD_BKLT_PERIPH); // Configure pins, all output GPIOPinTypeGPIOOutput(LCD_DATA_BASE, LCD_DATA_PINS); GPIOPinTypeGPIOOutput(LCD_CS_BASE, LCD_CS_PIN); GPIOPinTypeGPIOOutput(LCD_CD_BASE, LCD_CD_PIN); GPIOPinTypeGPIOOutput(LCD_WR_BASE, LCD_WR_PIN); GPIOPinTypeGPIOOutput(LCD_RD_BASE, LCD_RD_PIN); GPIOPinTypeGPIOOutput(LCD_BKLT_BASE, LCD_BKLT_PIN); GPIOPinTypeGPIOOutput(LCD_RST_BASE, LCD_RST_PIN); // Set control pins to idle/off state LCD_CS_IDLE LCD_RD_IDLE LCD_WR_IDLE LCD_BKLT_OFF // Reset LCD LCD_RST_ACTIVE LCD_DELAY(50); LCD_RST_IDLE LCD_DELAY(50); // Talk to LCD for init LCD_CS_ACTIVE // Sync communication LCDWriteData(0); LCDWriteData(0); LCDWriteData(0); LCDWriteData(0); LCD_DELAY(50); // Process initialization sequence of display driver int i = 0; while(usInitScript[i] != ILI_STOPCMD) { usAddress = usInitScript[i++]; usData = usInitScript[i++]; if(usAddress == ILI_DELAYCMD) { LCD_DELAY(usData); } else { LCDWriteCommand(usAddress); LCDWriteData(usData); } } // Clear display of any stray pixels LCDClear(); // Done talking to LCD LCD_CS_IDLE // Turn back light on LCD_BKLT_ON return; }