diff --git a/MCUFRIEND_kbv.cpp b/MCUFRIEND_kbv.cpp index adbfb94..fb2d6ea 100644 --- a/MCUFRIEND_kbv.cpp +++ b/MCUFRIEND_kbv.cpp @@ -358,7 +358,7 @@ int16_t MCUFRIEND_kbv::readGRAM(int16_t x, int16_t y, uint16_t * block, int16_t void MCUFRIEND_kbv::setRotation(uint8_t r) { - uint16_t GS, SS_v, ORG, REV = _lcd_rev; + uint16_t GS, SS_v, ORG, REV = _lcd_rev, NL; uint8_t val, d[3]; rotation = r & 3; // just perform the operation ourselves on the protected variables _width = (rotation & 1) ? HEIGHT : WIDTH; @@ -472,9 +472,11 @@ void MCUFRIEND_kbv::setRotation(uint8_t r) case 0xB509: _MC = 0x200, _MP = 0x201, _MW = 0x202, _SC = 0x210, _EC = 0x211, _SP = 0x212, _EP = 0x213; GS = (val & 0x80) ? (1 << 15) : 0; - uint16_t NL; - NL = ((432 / 8) - 1) << 9; - if (_lcd_ID == 0x9326 || _lcd_ID == 0x5420) NL >>= 1; + NL = ((400 / 8) - 1) << 9; // 400 rows + if (_lcd_ID == 0x9326 || _lcd_ID == 0x5420) { //NL and SCN are in diff position + if (GS) GS |= (4 << 0); //start SCN at row 32 PLEASE TEST ILI9326, SPFD5420 + NL >>= 1; + } WriteCmdData(0x400, GS | NL); goto common_SS; default: diff --git a/utility/mcufriend_special.h b/utility/mcufriend_special.h index 958cbe0..52ef699 100644 --- a/utility/mcufriend_special.h +++ b/utility/mcufriend_special.h @@ -334,8 +334,8 @@ static __attribute((always_inline)) #define RESET_PORT PORTD //n.c. on Open-Smart shields #define RESET_PIN 2 // aliexpress.com/store/1199788 -#define BMASK B00101111 -#define DMASK B11010000 +#define BMASK 0b00101111 +#define DMASK 0b11010000 #define write_8(x) { \ PORTD = (PORTD & ~DMASK) | ((x) & DMASK); \ @@ -368,7 +368,7 @@ static __attribute((always_inline)) #define RESET_PORT PORTF #define RESET_PIN 1 // n/a. so mimic WR_PIN -#define BMASK B10110000 //D13, D11, D10 +#define BMASK 0b10110000 //D13, D11, D10 #define GMASK 0x20 //D4 #define HMASK 0x78 //D6, D7, D8, D9 @@ -392,15 +392,15 @@ static __attribute((always_inline)) void write_8(uint8_t val) } #else #define write_8(x) { \ - PORTH = (PORTH&~HMASK)|(((x)&B11000000)>>3)|(((x)&B00000011)<<5); \ - PORTB = (PORTB&~BMASK)|(((x)&B00101100)<<2); \ - PORTG = (PORTG&~GMASK)|(((x)&B00010000)<<1); \ + PORTH = (PORTH&~HMASK)|(((x)& 0b11000000)>>3)|(((x)& 0b00000011)<<5); \ + PORTB = (PORTB&~BMASK)|(((x)& 0b00101100)<<2); \ + PORTG = (PORTG&~GMASK)|(((x)& 0b00010000)<<1); \ } #endif #define read_8()(\ - ((PINH & B00011000) << 3) | ((PINB & BMASK) >> 2) | \ - ((PING & GMASK) >> 1) | ((PINH & B01100000) >> 5) ) + ((PINH & 0b00011000) << 3) | ((PINB & BMASK) >> 2) | \ + ((PING & GMASK) >> 1) | ((PINH & 0b01100000) >> 5) ) #define setWriteDir() { DDRH |= HMASK; DDRB |= BMASK; DDRG |= GMASK; } #define setReadDir() { DDRH &= ~HMASK; DDRB &= ~BMASK; DDRG &= ~GMASK; }