void Adafruit_TFTLCD::drawPixel(int16_t x, int16_t y, uint16_t color) { // Clip if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return; CS_ACTIVE; if(driver == ID_932X) { int16_t t; switch(rotation) { case 1: t = x; x = TFTWIDTH - 1 - y; y = t; break; case 2: x = TFTWIDTH - 1 - x; y = TFTHEIGHT - 1 - y; break; case 3: t = x; x = y; y = TFTHEIGHT - 1 - t; break; } writeRegister16(0x0020, x); writeRegister16(0x0021, y); writeRegister16(0x0022, color); } else if(driver == ID_7575) { uint8_t hi, lo; switch(rotation) { default: lo = 0 ; break; case 1 : lo = 0x60; break; case 2 : lo = 0xc0; break; case 3 : lo = 0xa0; break; } writeRegister8( HX8347G_MEMACCESS , lo); // Only upper-left is set -- bottom-right is full screen default writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x); writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y); hi = color >> 8; lo = color; CD_COMMAND; write8(0x22); CD_DATA; write8(hi); write8(lo); }
// Unlike the 932X drivers that set the address window to the full screen // by default (using the address counter for drawPixel operations), the // 7575 needs the address window set on all graphics operations. In order // to save a few register writes on each pixel drawn, the lower-right // corner of the address window is reset after most fill operations, so // that drawPixel only needs to change the upper left each time. void Adafruit_TFTLCD::setLR(void) { CS_ACTIVE; writeRegisterPair(HX8347G_COLADDREND_HI, HX8347G_COLADDREND_LO, _width - 1); writeRegisterPair(HX8347G_ROWADDREND_HI, HX8347G_ROWADDREND_LO, _height - 1); CS_IDLE; }
// Sets the LCD address window (and address counter, on 932X). // Relevant to rect/screen fills and H/V lines. Input coordinates are // assumed pre-sorted (e.g. x2 >= x1). void Adafruit_TFTLCD::setAddrWindow(int x1, int y1, int x2, int y2) { CS_ACTIVE; if(driver == ID_932X) { // Values passed are in current (possibly rotated) coordinate // system. 932X requires hardware-native coords regardless of // MADCTL, so rotate inputs as needed. The address counter is // set to the top-left corner -- although fill operations can be // done in any direction, the current screen rotation is applied // because some users find it disconcerting when a fill does not // occur top-to-bottom. int x, y, t; switch(rotation) { default: x = x1; y = y1; break; case 1: t = y1; y1 = x1; x1 = TFTWIDTH - 1 - y2; y2 = x2; x2 = TFTWIDTH - 1 - t; x = x2; y = y1; break; case 2: t = x1; x1 = TFTWIDTH - 1 - x2; x2 = TFTWIDTH - 1 - t; t = y1; y1 = TFTHEIGHT - 1 - y2; y2 = TFTHEIGHT - 1 - t; x = x2; y = y2; break; case 3: t = x1; x1 = y1; y1 = TFTHEIGHT - 1 - x2; x2 = y2; y2 = TFTHEIGHT - 1 - t; x = x1; y = y2; break; } writeRegister16(0x0050, x1); // Set address window writeRegister16(0x0051, x2); writeRegister16(0x0052, y1); writeRegister16(0x0053, y2); writeRegister16(0x0020, x ); // Set address counter to top left writeRegister16(0x0021, y ); } else if(driver == ID_7575) { writeRegisterPair(HX8347G_COLADDRSTART_HI, HX8347G_COLADDRSTART_LO, x1); writeRegisterPair(HX8347G_ROWADDRSTART_HI, HX8347G_ROWADDRSTART_LO, y1); writeRegisterPair(HX8347G_COLADDREND_HI , HX8347G_COLADDREND_LO , x2); writeRegisterPair(HX8347G_ROWADDREND_HI , HX8347G_ROWADDREND_LO , y2); } else if (driver == ID_9341) { uint32_t t; t = x1; t <<= 16; t |= x2; writeRegister32(ILI9341_COLADDRSET, t); t = y1; t <<= 16; t |= y2; writeRegister32(ILI9341_PAGEADDRSET, t); } CS_IDLE; }