/********************************************************************* * Function: WORD GetPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: pixel position * * Output: pixel color * * Side Effects: none * * Overview: returns pixel at given position * * Note: none * ********************************************************************/ GFX_COLOR GetPixel(SHORT x, SHORT y) { BYTE columnPixel[3]; // 3 Pixels in each column DisplayEnable(); // Set Row and Column Address DisplaySetCommand(); DeviceWrite(LASET); DisplaySetData(); DeviceWrite(y + 16); DeviceWrite(0x8f); DisplaySetCommand(); DeviceWrite(CASET); DisplaySetData(); DeviceWrite(x / 3); DeviceWrite(0x54); // Read Column DisplaySetCommand(); DeviceWrite(RMWIN); DisplaySetData(); columnPixel[0] = DeviceRead(); // Dummy columnPixel[0] = DeviceRead(); // Start reading cycle for pixel 0 columnPixel[1] = DeviceRead(); // Start reading cycle for pixel 1 columnPixel[2] = DeviceRead(); // Start reading cycle for pixel 2 DisplaySetCommand(); DeviceWrite(RMWOUT); DisplayDisable(); DisplaySetData(); return (columnPixel[x % 3]); }
/********************************************************************* * Function: void ClearDevice(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: clears screen with current color * * Note: none * ********************************************************************/ void ClearDevice(void) { WORD counter; DisplayEnable(); // Whole screen DisplaySetCommand(); DeviceWrite(LASET); //Line Address Set(lines from 16 to 144 are used) DisplaySetData(); DeviceWrite(0x10); //Start Line=16 DeviceWrite(0x8f); //End Line =144-1 DisplaySetCommand(); DeviceWrite(CASET); //Column Address Set DisplaySetData(); DeviceWrite(0x00); //Start Column=0 DeviceWrite(0x54); //End Column =84 ((84+1)*3 == 255) DisplaySetCommand(); DeviceWrite(RAMWR); DisplaySetData(); for(counter = 0; counter < (WORD) (GetMaxX() + 1) * (GetMaxY() + 1); counter++) { DeviceWrite(_color); } DisplayDisable(); }
/********************************************************************* * Function: void PutPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: pixel position * * Output: none * * Side Effects: none * * Overview: puts pixel with current color at given position * * Note: none * ********************************************************************/ void PutPixel(SHORT x, SHORT y) { BYTE columnPixel[3]; // 3 Pixels in each column if(_clipRgn) { if(x < _clipLeft) return; if(x > _clipRight) return; if(y < _clipTop) return; if(y > _clipBottom) return; } DisplayEnable(); // Set Row and Column Address DisplaySetCommand(); DeviceWrite(LASET); DisplaySetData(); DeviceWrite(y + 16); DeviceWrite(0x8f); DisplaySetCommand(); DeviceWrite(CASET); DisplaySetData(); DeviceWrite(x / 3); DeviceWrite(0x54); // Read Column DisplaySetCommand(); DeviceWrite(RMWIN); DisplaySetData(); columnPixel[0] = DeviceRead(); // Dummy reading columnPixel[0] = DeviceRead(); // Start reading cycle for pixel 0 columnPixel[1] = DeviceRead(); // Start reading cycle for pixel 1 columnPixel[2] = DeviceRead(); // Start reading cycle for pixel 2 // Modify pixel columnPixel[x % 3] = _color; // Write Column DeviceWrite(columnPixel[0]); DeviceWrite(columnPixel[1]); DeviceWrite(columnPixel[2]); DisplaySetCommand(); DeviceWrite(RMWOUT); DisplayDisable(); DisplaySetData(); }
/********************************************************************* * Function: void DisplayOn(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: turns off display * * Note: none * ********************************************************************/ void DisplayOff(void) { DisplayEnable(); DisplaySetCommand(); DeviceWrite(DISOFF); DisplayDisable(); DisplaySetData(); }
/********************************************************************* * Function: void SleepIn(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: enters sleep mode * * Note: none * ********************************************************************/ void SleepIn(void) { DisplayEnable(); DisplaySetCommand(); DeviceWrite(SLPIN); DisplayDisable(); DisplaySetData(); }
/********************************************************************* * Function: void WakeUp(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: wakes up from sleep * * Note: none * ********************************************************************/ void WakeUp(void) { DisplayEnable(); DisplaySetCommand(); DeviceWrite(SLPOUT); DisplayDisable(); DisplaySetData(); }
void WriteData(unsigned int _data) { DisplayEnable(); DisplaySetData(); PMDIN = _data; PMPWaitBusy(); DisplayDisable(); }
/********************************************************************* * Function: void ContrastDown(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: decreases contrast * * Note: none * ********************************************************************/ void ContrastDown(void) { DisplayEnable(); DisplaySetCommand(); DeviceWrite(VOLDOWN); //Electronic Control DisplayDisable(); DisplaySetData(); }
/********************************************************************* * Function: void ContrastUp(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: increases contrast * * Note: none * ********************************************************************/ void ContrastUp(void) { DisplayEnable(); DisplaySetCommand(); DeviceWrite(VOLUP); DisplayDisable(); DisplaySetData(); }
/********************************************************************* * Function: void SetReg(BYTE index, BYTE value) * * PreCondition: none * * Input: index - register number * value - value to be set * * Output: none * * Side Effects: none * * Overview: sets graphics controller register * * Note: none * ********************************************************************/ void SetReg(BYTE index, BYTE value) { DisplayEnable(); DisplaySetCommand(); DeviceWrite(index); DisplaySetData(); DeviceWrite(value); DisplayDisable(); }
/********************************************************************* * Function: SetAddress(addr2,addr1,addr0) * * PreCondition: none * * Input: addr0,addr1,addr2 - address bytes * * Output: none * * Side Effects: none * * Overview: writes S6D0129 address pointer * * Note: none * ********************************************************************/ inline void SetAddress(DWORD address) { DisplaySetCommand(); DeviceWrite(SET_DATA_POINTER); DisplaySetData(); DeviceWrite(((DWORD_VAL)address).v[0]); DeviceWrite(((DWORD_VAL)address).v[1]); DeviceWrite(((DWORD_VAL)address).v[2]); }
/********************************************************************* * Function: void ContrastSet(WORD contrast) * * PreCondition: none * * Input: contrast value (LSB 10-0 are valid, MSB 15-11 are not used) * * Output: none * * Side Effects: none * * Overview: sets contrast * * Note: none * ********************************************************************/ void ContrastSet(WORD contrast) { DisplayEnable(); DisplaySetCommand(); DeviceWrite(VOLCTRL); DisplaySetData(); DeviceWrite((((WORD_VAL) contrast).v[0])); DeviceWrite((((WORD_VAL) contrast).v[1])); DisplayDisable(); }
inline void SetRegion(SHORT xbeg, SHORT xend, SHORT ybeg, SHORT yend) { DisplaySetCommand(); DeviceWrite(ColumnAddressSet); DisplaySetData(); DeviceWrite(((WORD_VAL) (WORD) xbeg).byte.HB); DeviceWrite(((WORD_VAL) (WORD) xbeg).byte.LB); DeviceWrite(((WORD_VAL) (WORD) xend).byte.HB); DeviceWrite(((WORD_VAL) (WORD) xend).byte.LB); DisplaySetCommand(); DeviceWrite(PageAddressSet); DisplaySetData(); DeviceWrite(((WORD_VAL) (WORD) ybeg).byte.HB); DeviceWrite(((WORD_VAL) (WORD) ybeg).byte.LB); DeviceWrite(((WORD_VAL) (WORD) yend).byte.HB); DeviceWrite(((WORD_VAL) (WORD) yend).byte.LB); }
WORD GetPixel(SHORT x, SHORT y) { DWORD address; WORD result; #if (DISP_ORIENTATION == 0) address = (long)LINE_MEM_PITCH * y + x; #else y = GetMaxY() - y; address = (long)LINE_MEM_PITCH * x + y; #endif DisplayEnable(); SetAddress(address); // Temporary change wait cycles for reading (250ns = 4 cycles) #if defined(__C30__) PMMODEbits.WAITM = 4; #elif defined(__PIC32MX__) PMMODEbits.WAITM = 8; #else #error Need wait states for the device #endif DisplaySetData(); // First RD cycle to move data from GRAM to Read Data Latch result = PMDIN1; while(PMMODEbits.BUSY); // Second RD cycle to get data from Read Data Latch result = PMDIN1; while(PMMODEbits.BUSY); // Disable LCD DisplayDisable(); // Disable PMP PMCONbits.PMPEN = 1; // Read result result = PMDIN1; // Restore wait cycles for writing (60ns) #if defined(__dsPIC33F__) || defined(__PIC24H__) PMMODEbits.WAITM = 2; #else PMMODEbits.WAITM = 1; #endif // Enable PMP PMCONbits.PMPEN = 1; return (result); }
/********************************************************************* * Function: void SetReg(WORD index, WORD value) * * PreCondition: none * * Input: index - register number * value - value to be set * * Output: none * * Side Effects: none * * Overview: sets graphics controller register * * Note: none * ********************************************************************/ void SetReg(WORD index, WORD value) { #ifdef USE_16BIT_PMP DisplayEnable(); DisplaySetCommand(); DeviceWrite(index); DisplaySetData(); DeviceWrite(value); DisplayDisable(); #else DisplayEnable(); DisplaySetCommand(); DeviceWrite(((WORD_VAL)index).v[1]); DeviceWrite(((WORD_VAL)index).v[0]); DisplaySetData(); DeviceWrite(((WORD_VAL)value).v[1]); DeviceWrite(((WORD_VAL)value).v[0]); DisplayDisable(); #endif }
/********************************************************************* * Function: void SetAddress(SHORT x, SHORT y) * * Overview: Writes address pointer. * * PreCondition: none * * Input: x - horizontal position * y - vertical position * * Output: none * * Side Effects: none * ********************************************************************/ inline void SetAddress(SHORT x, SHORT y) { // DisplayEnable(); DisplaySetCommand(); DeviceWrite(ColumnAddressSet); DisplaySetData(); DeviceWrite(((WORD_VAL) (WORD) x).byte.HB); DeviceWrite(((WORD_VAL) (WORD) x).byte.LB); DeviceWrite(((WORD_VAL) (WORD) x).byte.HB); DeviceWrite(((WORD_VAL) (WORD) x).byte.LB); DisplaySetCommand(); DeviceWrite(PageAddressSet); DisplaySetData(); DeviceWrite(((WORD_VAL) (WORD) y).byte.HB); DeviceWrite(((WORD_VAL) (WORD) y).byte.LB); DeviceWrite(((WORD_VAL) (WORD) y).byte.HB); DeviceWrite(((WORD_VAL) (WORD) y).byte.LB); // DisplayDisable(); }
/********************************************************************* * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) * PreCondition: none * Input: left,top - top left corner coordinates, * right,bottom - bottom right corner coordinates * Output: none * Side Effects: none * Overview: draws rectangle filled with current color * Note: none ********************************************************************/ WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) { register SHORT x, y; #ifndef USE_NONBLOCKING_CONFIG while(IsDeviceBusy() != 0); /* Ready */ #else if(IsDeviceBusy() != 0) return (0); #endif if(_clipRgn) { if(left < _clipLeft) left = _clipLeft; if(right > _clipRight) right = _clipRight; if(top < _clipTop) top = _clipTop; if(bottom > _clipBottom) bottom = _clipBottom; } DisplayEnable(); SetRegion(left, right, top, bottom); DisplaySetCommand(); DeviceWrite(MemoryWrite); DisplaySetData(); for(y = top; y < bottom + 1; y++) { for(x = left; x < right + 1; x++) { DeviceWrite(_color); } } // SetRegion(0, GetMaxX(), 0, GetMaxY()); /* for(y = top; y < bottom + 1; y++) { SetAddress(left, y); for(x = left; x < right + 1; x++) { WritePixel(_color); } }*/ // SetRegion(0, GetMaxX(), 0, GetMaxY()); DisplayDisable(); return (1); }
/********************************************************************* * Function: void ClearDevice(void) * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: clears screen with current color * * Note: none * ********************************************************************/ void ClearDevice(void) { int x, y; DisplayEnable(); SetRegion(0, GetMaxX(), 0, GetMaxY()); DisplaySetCommand(); DeviceWrite(MemoryWrite); DisplaySetData(); for (x = 0; x < GetMaxY() + 1; x++) { for (y = 0; y < GetMaxX() + 1; y++) { DeviceWrite(_color); } } DisplayDisable(); }
/********************************************************************* * Function: GFX_COLOR GetPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: x,y - pixel coordinates * * Output: pixel color * * Side Effects: none * * Overview: return pixel color at x,y position * * Note: This implementation assumes an 8bit Data interface. * For other data interface, this function should be modified. * ********************************************************************/ GFX_COLOR GetPixel(SHORT x, SHORT y) { GFX_COLOR result; BYTE red = 0, green = 0, blue = 0; DisplayEnable(); SetAddress(x, y); DisplaySetCommand(); DeviceWrite(READMEMCONTINUE_REG); DisplaySetData(); SingleDeviceRead(); // read RED result = SingleDeviceRead(); /* // read GREEN green = SingleDeviceRead(); // read BLUE blue = SingleDeviceRead();*/ DisplayDisable(); return result; // return ((WORD) (((((GFX_COLOR)(red) & 0xF8) >> 3) << 11) | ((((GFX_COLOR)(green) & 0xFC) >> 2) << 5) | (((GFX_COLOR)(blue) & 0xF8) >> 3))); }
/********************************************************************* * Function: void PutPixel(SHORT x, SHORT y) * PreCondition: none * Input: x,y - pixel coordinates * Output: none * Side Effects: none * Overview: puts pixel * Note: none ********************************************************************/ void PutPixel(SHORT x, SHORT y) { if(_clipRgn) { if(x < _clipLeft) return; if(x > _clipRight) return; if(y < _clipTop) return; if(y > _clipBottom) return; } DisplayEnable(); SetAddress(x, y); DisplaySetCommand(); DeviceWrite(MemoryWrite); DisplaySetData(); DeviceWrite(_color); DisplayDisable(); }
/********************************************************************* * Function: void ResetDevice() * * PreCondition: none * * Input: none * * Output: none * * Side Effects: none * * Overview: resets LCD, initializes PMP * * Note: none * ********************************************************************/ void ResetDevice(void) { // Initialize device DriverInterfaceInit(); DelayMs(20); DisplayEnable(); DisplaySetCommand(); DeviceWrite(EXTIN); //Ext = 0 DeviceWrite(SLPOUT); //Sleep Out DeviceWrite(OSCON); //OSC On DeviceWrite(PWRCTRL); //Power Control Set DisplaySetData(); DeviceWrite(0x08); //Booster Must Be On First DelayMs(2); DisplaySetCommand(); DeviceWrite(0x20); //Power Control Set DisplaySetData(); DeviceWrite(0x0B); //Booster, Regulator, Follower ON DisplaySetCommand(); DeviceWrite(VOLCTRL); //Electronic Control DisplaySetData(); DeviceWrite(0x3f); //Vop=18.0V DeviceWrite(0x04); DisplaySetCommand(); DeviceWrite(DISCTRL); //Display Control DisplaySetData(); DeviceWrite(0x00); //CL=X1 DeviceWrite(0x27); //Duty=160 DeviceWrite(0x00); //FR Inverse-Set Value DisplaySetCommand(); DeviceWrite(DISNOR); // Normal Display DeviceWrite(COMSCN); //COM Scan Direction DisplaySetData(); DeviceWrite(0x01); // 0->79 159->80 DisplaySetCommand(); DeviceWrite(DATSDR); //Data Scan Direction DisplaySetData(); #if (DISP_ORIENTATION == 180) DeviceWrite(0x01); //Row Reverse DeviceWrite(0x00); //Derect 3 Pixels Arrangement #else DeviceWrite(0x02); //Column Reverse DeviceWrite(0x01); //Inverse 3 Pixels Arrangement #endif DeviceWrite(0x02); //3Byte 3Pixel mode DisplaySetCommand(); DeviceWrite(LASET); //Line Address Set(lines from 16 to 144 are used) DisplaySetData(); DeviceWrite(0x10); //Start Line=16 DeviceWrite(0x8f); //End Line =144-1 DisplaySetCommand(); DeviceWrite(CASET); //Column Address Set DisplaySetData(); DeviceWrite(0x00); //Start Column=0 DeviceWrite(0x54); //End Column =84 ((84+1)*3 == 255) DisplaySetCommand(); DeviceWrite(EXTOUT); //Ext = 1 DeviceWrite(ANASET); //Analog Circuit Set DisplaySetData(); DeviceWrite(0x00); //OSC Frequency =000 (Default) DeviceWrite(0x01); //Booster Efficiency=01(Default) DeviceWrite(0x00); //Bias=1/14 DisplaySetCommand(); DeviceWrite(SWINT); //Software Initial DeviceWrite(EXTIN); //Ext = 0 DeviceWrite(DISON); //Display On DisplayDisable(); DisplaySetData(); DelayMs(100); }
/********************************************************************* * Macros: SetAddress(addr2,addr1,addr0) * * Overview: Writes address pointer. * * PreCondition: none * * Input: addr0 - Lower byte of the address. * addr1 - Middle byte of the address. * addr2 - Upper byte of the address. * * Output: none * * Side Effects: none * ********************************************************************/ inline void SetAddress(WORD x, WORD y) { DisplaySetCommand(); #ifdef USE_16BIT_PMP #if (DISP_ORIENTATION == 0) DeviceWrite(0x004e); #else DeviceWrite(0x004f); #endif #else #if (DISP_ORIENTATION == 0) DeviceWrite(0); DeviceWrite(0x4e); #else DeviceWrite(0); DeviceWrite(0x4f); #endif #endif DisplaySetData(); #ifdef USE_16BIT_PMP DeviceWrite(x); #else DeviceWrite(((WORD_VAL)x).v[1]); DeviceWrite(((WORD_VAL)x).v[0]); #endif DisplaySetCommand(); #ifdef USE_16BIT_PMP #if (DISP_ORIENTATION == 0) DeviceWrite(0x004f); #else DeviceWrite(0x004e); #endif #else #if (DISP_ORIENTATION == 0) DeviceWrite(0); DeviceWrite(0x4f); #else DeviceWrite(0); DeviceWrite(0x4e); #endif #endif DisplaySetData(); #ifdef USE_16BIT_PMP DeviceWrite(y); #else DeviceWrite(((WORD_VAL)y).v[1]); DeviceWrite(((WORD_VAL)y).v[0]); #endif DisplaySetCommand(); #ifdef USE_16BIT_PMP DeviceWrite(0x0022); #else DeviceWrite(0); DeviceWrite(0x22); #endif DisplaySetData(); }