void TFT_ILI9163C::sleepMode(boolean mode) { if (mode){ if (sleep == 1) return;//already sleeping sleep = 1; #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_last(CMD_SLPIN); endProc(); #else writecommand(CMD_SLPIN); #endif delay(5);//needed } else { if (sleep == 0) return; //Already awake sleep = 0; #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_last(CMD_SLPOUT); endProc(); #else writecommand(CMD_SLPOUT); #endif delay(120);//needed } }
void TFT_ILI9163C::setRotation(uint8_t m) { rotation = m % 4; // can't be higher than 3 switch (rotation) { case 0: _Mactrl_Data = 0b00001000; _width = _TFTWIDTH; _height = _TFTHEIGHT;//-__OFFSET; break; case 1: _Mactrl_Data = 0b01101000; _width = _TFTHEIGHT;//-__OFFSET; _height = _TFTWIDTH; break; case 2: _Mactrl_Data = 0b11001000; _width = _TFTWIDTH; _height = _TFTHEIGHT;//-__OFFSET; break; case 3: _Mactrl_Data = 0b10101000; _width = _TFTWIDTH; _height = _TFTHEIGHT;//-__OFFSET; break; } colorSpace(_colorspaceData); #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_cont(CMD_MADCTL); writedata8_last(_Mactrl_Data); endProc(); #else writecommand(CMD_MADCTL); writedata(_Mactrl_Data); #endif }
void TFT_ILI9163C::pushColor(uint16_t color) { #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writedata16_last(color); endProc(); #else writedata16(color); #endif }
void TFT_ILI9163C::display(boolean onOff) { if (onOff){ #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_last(CMD_DISPON); endProc(); #else writecommand(CMD_DISPON); #endif } else { #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_last(CMD_DISPOFF); endProc(); #else writecommand(CMD_DISPOFF); #endif } }
void TFT_ILI9163C::scroll(uint16_t adrs) { #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_cont(CMD_VSSTADRS); writedata16_last(adrs); endProc(); #else writecommand(CMD_VSSTADRS); writedata16(adrs); #endif }
void TFT_ILI9163C::drawPixel(int16_t x, int16_t y, uint16_t color) { if (boundaryCheck(x,y)) return; if ((x < 0) || (y < 0)) return; setAddr(x,y,x+1,y+1); #if defined(__MK20DX128__) || defined(__MK20DX256__) writedata16_last(color); endProc(); #else writedata16(color); #endif }
JNIEXPORT void JNICALL Java_dk_cst_bracmat_end(JNIEnv * env, jobject obj) { #if defined WIN32 void mutexLockEnd(); void mutexUnlockEnd(); mutexLockEnd(); #else pthread_mutex_lock( &mutexend); #endif endProc(); #if defined WIN32 mutexUnlockEnd(); #else pthread_mutex_unlock(&mutexend); #endif }
void TFT_ILI9163C::drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { // Rudimentary clipping if (boundaryCheck(x,y)) return; if (((x+w) - 1) >= _width) w = _width-x; setAddr(x,y,(x+w)-1,y); while (w-- > 1) { #if defined(__MK20DX128__) || defined(__MK20DX256__) if (w == 0){ writedata16_last(color); } else { writedata16_cont(color); } #else writedata16(color); #endif } endProc(); }
void TFT_ILI9163C::drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { // Rudimentary clipping if (boundaryCheck(x,y)) return; if (((y + h) - 1) >= _height) h = _height-y; setAddr(x,y,x,(y+h)-1); while (h-- > 1) { #if defined(__MK20DX128__) || defined(__MK20DX256__) if (h == 0){ writedata16_last(color); } else { writedata16_cont(color); } #else writedata16(color); #endif } endProc(); }
// fill a rectangle void TFT_ILI9163C::fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) { if (boundaryCheck(x,y)) return; if (((x + w) - 1) >= _width) w = _width - x; if (((y + h) - 1) >= _height) h = _height - y; setAddr(x,y,(x+w)-1,(y+h)-1); for (y = h;y > 0;y--) { for (x = w;x > 1;x--) { #if defined(__MK20DX128__) || defined(__MK20DX256__) writedata16_cont(color); #else writedata16(color); #endif } #if defined(__MK20DX128__) || defined(__MK20DX256__) writedata16_last(color); #endif } endProc(); }
void TFT_ILI9163C::defineScrollArea(uint16_t tfa, uint16_t bfa){ tfa += __OFFSET; int16_t vsa = _GRAMHEIGH - tfa - bfa; if (vsa >= 0) { #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_cont(CMD_VSCLLDEF); writedata16_cont(tfa); writedata16_cont(vsa); writedata16_last(bfa); endProc(); #else writecommand(CMD_VSCLLDEF); writedata16(tfa); writedata16(vsa); writedata16(bfa); #endif } }
void TFT_ILI9163C::writeScreen24(const uint32_t *bitmap,uint16_t size) { uint16_t color; int px; #if defined(__MK20DX128__) || defined(__MK20DX256__) writecommand_cont(CMD_RAMWR); for (px = 0;px < size; px++){//16384 color = Color24To565(bitmap[px]); writedata16_cont(color); } _setAddrWindow(0x00,0x00,_GRAMWIDTH,_GRAMHEIGH);//home endProc(); #else writecommand(CMD_RAMWR); for (px = 0;px < size; px++){ color = Color24To565(bitmap[px]); writedata16(color); } homeAddress(); #endif }
//corrected! void TFT_ILI9163C::clearScreen(uint16_t color) { int px; #if defined(__MK20DX128__) || defined(__MK20DX256__) //SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); setAddr(0x00,0x00,_GRAMWIDTH,_GRAMHEIGH);//go home //writecommand_cont(CMD_RAMWR);//this was missed! for (px = 0;px < _GRAMSIZE; px++){ writedata16_cont(color); } _setAddrWindow(0x00,0x00,_GRAMWIDTH,_GRAMHEIGH);//go home writecommand_last(CMD_NOP); endProc(); #else setAddr(0x00,0x00,_GRAMWIDTH,_GRAMHEIGH);//go home //writecommand(CMD_RAMWR); for (px = 0;px < _GRAMSIZE; px++){ writedata16(color); } #endif }
CBracmatdll::~CBracmatdll() { endProc(); }
void TFT_ILI9163C::endPushData() { #if defined(__MK20DX128__) || defined(__MK20DX256__) writecommand_last(CMD_NOP); endProc(); #endif }
void TFT_ILI9163C::chipInit() { uint8_t i; #if defined(__GAMMASET1) const uint8_t pGammaSet[15]= {0x36,0x29,0x12,0x22,0x1C,0x15,0x42,0xB7,0x2F,0x13,0x12,0x0A,0x11,0x0B,0x06}; const uint8_t nGammaSet[15]= {0x09,0x16,0x2D,0x0D,0x13,0x15,0x40,0x48,0x53,0x0C,0x1D,0x25,0x2E,0x34,0x39}; #elif defined(__GAMMASET2) const uint8_t pGammaSet[15]= {0x3F,0x21,0x12,0x22,0x1C,0x15,0x42,0xB7,0x2F,0x13,0x02,0x0A,0x01,0x00,0x00}; const uint8_t nGammaSet[15]= {0x09,0x18,0x2D,0x0D,0x13,0x15,0x40,0x48,0x53,0x0C,0x1D,0x25,0x2E,0x24,0x29}; #elif defined(__GAMMASET3) const uint8_t pGammaSet[15]= {0x3F,0x26,0x23,0x30,0x28,0x10,0x55,0xB7,0x40,0x19,0x10,0x1E,0x02,0x01,0x00}; //&const uint8_t nGammaSet[15]= {0x00,0x19,0x1C,0x0F,0x14,0x0F,0x2A,0x48,0x3F,0x06,0x1D,0x21,0x3D,0x3F,0x3F}; const uint8_t nGammaSet[15]= {0x09,0x18,0x2D,0x0D,0x13,0x15,0x40,0x48,0x53,0x0C,0x1D,0x25,0x2E,0x24,0x29}; #else const uint8_t pGammaSet[15]= {0x3F,0x25,0x1C,0x1E,0x20,0x12,0x2A,0x90,0x24,0x11,0x00,0x00,0x00,0x00,0x00}; const uint8_t nGammaSet[15]= {0x20,0x20,0x20,0x20,0x05,0x15,0x00,0xA7,0x3D,0x18,0x25,0x2A,0x2B,0x2B,0x3A}; #endif #if defined(__MK20DX128__) || defined(__MK20DX256__) SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_cont(CMD_SWRESET);//software reset delay(500); writecommand_cont(CMD_SLPOUT);//exit sleep delay(5); writecommand_cont(CMD_PIXFMT);//Set Color Format 16bit writedata8_cont(0x05); delay(5); writecommand_cont(CMD_GAMMASET);//default gamma curve 3 writedata8_cont(0x08);//0x04 delay(1); writecommand_cont(CMD_GAMRSEL);//Enable Gamma adj writedata8_cont(0x01); delay(1); writecommand_cont(CMD_NORML); writecommand_cont(CMD_DFUNCTR); writedata8_cont(0b11111111);// writedata8_cont(0b00000110);// writecommand_cont(CMD_PGAMMAC);//Positive Gamma Correction Setting for (i=0;i<15;i++){ writedata8_cont(pGammaSet[i]); } writecommand_cont(CMD_NGAMMAC);//Negative Gamma Correction Setting for (i=0;i<15;i++){ writedata8_cont(nGammaSet[i]); } writecommand_cont(CMD_FRMCTR1);//Frame Rate Control (In normal mode/Full colors) writedata8_cont(0x08);//0x0C//0x08 writedata8_cont(0x02);//0x14//0x08 delay(1); writecommand_cont(CMD_DINVCTR);//display inversion writedata8_cont(0x07); delay(1); writecommand_cont(CMD_PWCTR1);//Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD writedata8_cont(0x0A);//4.30 - 0x0A writedata8_cont(0x02);//0x05 delay(1); writecommand_cont(CMD_PWCTR2);//Set BT[2:0] for AVDD & VCL & VGH & VGL writedata8_cont(0x02); delay(1); writecommand_cont(CMD_VCOMCTR1);//Set VMH[6:0] & VML[6:0] for VOMH & VCOML writedata8_cont(0x50);//0x50 writedata8_cont(99);//0x5b delay(1); writecommand_cont(CMD_VCOMOFFS); writedata8_cont(0);//0x40 delay(1); writecommand_cont(CMD_CLMADRS);//Set Column Address /* writedata8_cont(0x00); writedata8_cont(0X00); writedata8_cont(0X00); writedata8_cont(_GRAMWIDTH); */ writedata16_cont(0x00); writedata16_cont(_GRAMWIDTH); writecommand_cont(CMD_PGEADRS);//Set Page Address /* writedata8_cont(0x00); writedata8_cont(0X00); writedata8_cont(0X00); writedata8_last(_GRAMHEIGH); */ writedata16_cont(0x00); writedata16_last(_GRAMHEIGH); endProc(); colorSpace(_colorspaceData); setRotation(0); SPI.beginTransaction(SPISettings(SPICLOCK, MSBFIRST, SPI_MODE0)); writecommand_cont(CMD_DISPON);//display ON delay(1); writecommand_last(CMD_RAMWR);//Memory Write SPI.endTransaction(); delay(1); #else writecommand(CMD_SWRESET);//software reset delay(500); writecommand(CMD_SLPOUT);//exit sleep delay(5); writecommand(CMD_PIXFMT);//Set Color Format 16bit writedata(0x05); delay(5); writecommand(CMD_GAMMASET);//default gamma curve 3 writedata(0x04);//0x04 delay(1); writecommand(CMD_GAMRSEL);//Enable Gamma adj writedata(0x01); delay(1); writecommand(CMD_NORML); writecommand(CMD_DFUNCTR); writedata(0b11111111);// writedata(0b00000110);// writecommand(CMD_PGAMMAC);//Positive Gamma Correction Setting for (i=0;i<15;i++){ writedata(pGammaSet[i]); } writecommand(CMD_NGAMMAC);//Negative Gamma Correction Setting for (i=0;i<15;i++){ writedata(nGammaSet[i]); } writecommand(CMD_FRMCTR1);//Frame Rate Control (In normal mode/Full colors) writedata(0x08);//0x0C//0x08 writedata(0x02);//0x14//0x08 delay(1); writecommand(CMD_DINVCTR);//display inversion writedata(0x07); delay(1); writecommand(CMD_PWCTR1);//Set VRH1[4:0] & VC[2:0] for VCI1 & GVDD writedata(0x0A);//4.30 - 0x0A writedata(0x02);//0x05 delay(1); writecommand(CMD_PWCTR2);//Set BT[2:0] for AVDD & VCL & VGH & VGL writedata(0x02); delay(1); writecommand(CMD_VCOMCTR1);//Set VMH[6:0] & VML[6:0] for VOMH & VCOML writedata(0x50);//0x50 writedata(99);//0x5b delay(1); writecommand(CMD_VCOMOFFS); writedata(0);//0x40 delay(1); writecommand(CMD_CLMADRS);//Set Column Address //writedata(0x00); //writedata(0X00); //writedata(0X00); //writedata(_GRAMWIDTH); writedata16(0x00); writedata16(_GRAMWIDTH); writecommand(CMD_PGEADRS);//Set Page Address //writedata(0x00); //writedata(0X00); //writedata(0X00); //writedata(_GRAMHEIGH); writedata16(0X00); writedata16(_GRAMHEIGH); colorSpace(_colorspaceData); setRotation(0); writecommand(CMD_DISPON);//display ON delay(1); writecommand(CMD_RAMWR);//Memory Write delay(1); #endif fillScreen(BLACK); }