Esempio n. 1
0
void lcd_set_address(uint16 x1,uint16 x2,uint16 y1,uint16 y2)
{
    uint16 temp;

    if(x2<x1) {                         // if x2 is below x1
        temp = x2;                      // swap
        x2 = x1;                        // both x
        x1 = temp;                      // variables
    }
    if(y2<y1) {                         // if y2 is below y1
        temp = y2;                      // swap
        y2 = y1;                        // both y
        y1 = temp;                      // variables
    }
    x1 = MIN(d_width_x,x1);
    x2 = MIN(d_width_x,x2);
    y1 = MIN(d_width_y,y1);
    y2 = MIN(d_width_y,y2);
    writecommand_last(ILI9341_PASET);
    //lcd_send_cmd(ILI9341_PASET);
    writedata16_cont(x1);
    writedata16_last(x2);
    //lcd_send_mdata(x1);
    //lcd_send_mdata(x2);
    writecommand_last(ILI9341_CASET);
    writedata16_cont(y1);
    writedata16_last(y2);
    //lcd_send_cmd(ILI9341_CASET);
    //lcd_send_mdata(y1);
    //lcd_send_mdata(y2);

    //lcd_send_cmd(ILI9341_RAMWR);
    writecommand_last(ILI9341_RAMWR);
}
Esempio n. 2
0
/*! \brief Clears the LCD screen.
 *
 *  The LCD screen is completely cleared by writing the given color to each
 *  pixel.
 */
void lcd_clear(uint16 color)
{
    int i,j;
    lcd_set_address(0,d_width_x-1,0,d_width_y-1);

    for (i=1;i<d_width_y;i++){
        for (j=0;j<d_width_x;j++){
            writedata16_cont(color);
        }
    }
    for (j=1;j<d_width_x;j++){
        writedata16_cont(color);
    }
    writedata16_last(color);
}
Esempio n. 3
0
void TFT_ILI9163C::pushData(uint16_t color) {
	#if defined(__MK20DX128__) || defined(__MK20DX256__)
		writedata16_cont(color);
	#else
		writedata16(color);
	#endif
}
Esempio n. 4
0
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
    }
}
Esempio n. 5
0
void lcd_draw_bitmap(int16 x, int16 y, const LCD_BITMAP *bitmap)
{
    uint16_t used;
    uint8_t index, mask;

    lcd_set_address(x,x+bitmap->width-1,y,y+bitmap->height-1);

    index = 0;
    mask = 0x80;
    for(used=1; used<(bitmap->width*bitmap->height); used++) {
        if(bitmap->data[index] & mask) { // if pixel value is one
            writedata16_cont(d_theme.Font_Color.Word);
        }
        else {                      // or pixel value is zero
            writedata16_cont(d_theme.BG_Color.Word);
        }
        // increment counters
        if(mask>1) {
            mask >>= 1;
        }
        else {
Esempio n. 6
0
void TFT_ILI9163C::_setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
	writecommand_cont(CMD_CLMADRS); // Column
	if (rotation == 0 || rotation > 1){
		writedata16_cont(x0);
		writedata16_cont(x1);
	} else {
		writedata16_cont(x0 + __OFFSET);
		writedata16_cont(x1 + __OFFSET);
	}
	writecommand_cont(CMD_PGEADRS); // Page
	if (rotation == 0){
		writedata16_cont(y0 + __OFFSET);
		writedata16_cont(y1 + __OFFSET);
	} else {
		writedata16_cont(y0);
		writedata16_cont(y1);
	}
	writecommand_cont(CMD_RAMWR); //Into RAM
}
Esempio n. 7
0
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();
}
Esempio n. 8
0
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();
}
Esempio n. 9
0
void lcd_draw_rect(uint16 x1, uint16 x2, uint16 y1, uint16 y2, uint16 color, uint8 fill)
{
    uint16 i;

    if(fill) {                          // if the rectangle has to be filled
        lcd_set_address(x1,x2,y1,y2);
        for(i=0; i<(((x2-x1+1)*(y2-y1+1)+1))-1; i++) {
            writedata16_cont(color);
        }
        writedata16_last(color);
    }
    else {                              // if not to be filled
        lcd_draw_rect(x1,x1,y1,y2,color,1); // draw left line
        lcd_draw_rect(x2,x2,y1,y2,color,1); // draw right line
        lcd_draw_rect(x1,x2,y1,y1,color,1); // draw bottom line
        lcd_draw_rect(x1,x2,y2,y2,color,1); // draw top line
    }
}
Esempio n. 10
0
// 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();
}
Esempio n. 11
0
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
}
Esempio n. 12
0
//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
}
Esempio n. 13
0
/*! \brief Write a character with small font.
 *
 *  This function writes a single character at the given position.
 *
 *  @param x Offset to the left.
 *  @param y Offset to the top.
 *  @param c ASCII character.
 *  @return The function returns the width of the character written.
 */
uint16 lcd_write_char(uint16 x, uint16 y, char c)
{
    uint16_t pixels_used=0;
    uint16_t pixels_to_use;
    uint16_t index;
    uint16_t font_byte;
    uint8_t font_mask;


    // if not a printable character
    if((c < d_font->first_char) || (c > d_font->last_char)) {
        return 0;                       // width=0, abort
    }
    index = c-d_font->first_char;       // get character index in font
    if(d_use_monospace) {
        lcd_set_address(x,x+d_font->width-1,y,y+d_font->height-1);
    }
    else {
        lcd_set_address(x,x+d_font->char_width[index],y,y+d_font->height-1);
    }
    // add half of the space columns in front of the character to balance the spacing
    if(d_use_monospace) {
        // one or more space columns at the beginning
        pixels_to_use = d_font->height*((d_font->width - d_font->char_width[index])/2);
        for(pixels_used=0; pixels_used < pixels_to_use; pixels_used++) {
            writedata16_cont(d_theme.BG_Color.Word);
        }
    }

    // add number of pixels occupied by the current character
    pixels_to_use = pixels_used
                    + d_font->pixel_offset[index+1]
                    - d_font->pixel_offset[index];

    // byte offset in data array
    font_byte = d_font->pixel_offset[index]>>3;
    // bit offset in current data byte
    font_mask = 1u << (d_font->pixel_offset[index]&0x07);

    // loop on all pixels to draw
    for( ; pixels_used<pixels_to_use; pixels_used++) {
        if(d_font->data[font_byte] & font_mask) { // if pixel value is one
            writedata16_cont(d_theme.Font_Color.Word);
        }
        else {                      // or pixel value is zero
            writedata16_cont(d_theme.BG_Color.Word);
        }
        // increment font counters
        if(font_mask<128) {
            font_mask <<= 1;
        }
        else {
            font_mask = 1;
            font_byte++;
        }
    }

    if(d_use_monospace) {
        pixels_to_use = d_font->height*d_font->width; // fixed width
    }
    else {
        pixels_to_use += d_font->height; // add one space column
    }

    // one or more space columns at the end
    for(; pixels_used<pixels_to_use-1; pixels_used++) {
        writedata16_cont(d_theme.BG_Color.Word);
    }
    writedata16_last(d_theme.BG_Color.Word);

    if(d_use_monospace) {
        return d_font->width;
    }
    else {
        return d_font->char_width[index] + 1;
    }
}
Esempio n. 14
0
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);
}