Skip to content

Commit

Permalink
Merge pull request #16 from tobozo/unstable
Browse files Browse the repository at this point in the history
Fixes and tweaks
  • Loading branch information
tobozo authored Feb 15, 2020
2 parents b5dad2a + 17c59da commit 368daf0
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ before_install:
- set_application_folder "$APPLICATION_FOLDER"
- set_sketchbook_folder "$SKETCHBOOK_FOLDER"

- install_ide '("1.8.0" "1.8.9" "newest")'
#- install_ide '("1.8.0" "1.8.10" "1.8.11")'
- install_ide '("1.8.0" "1.8.10" "newest")'

# Install the library from the repository
- install_library
Expand Down
20 changes: 16 additions & 4 deletions src/utility/In_eSPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h)
_cp437 = true;
_utf8 = true;


if (psramFound()) _usePsram = true; // Enable the use of PSRAM (if available)
else _usePsram = false;

addr_row = 0xFFFF;
addr_col = 0xFFFF;

Expand Down Expand Up @@ -3129,17 +3133,22 @@ void TFT_eSPI::invertDisplay(boolean i)
void TFT_eSPI::setAttribute(uint8_t attr_id, uint8_t param) {
switch (attr_id) {
break;
case 1:
case CP437_SWITCH:
_cp437 = param;
break;
case 2:
case UTF8_SWITCH:
_utf8 = param;
decoderState = 0;
break;
case PSRAM_ENABLE:
//case 3: // TBD future feature control
// _tbd = param;
// break;
if (psramFound()) _usePsram = param; // Enable the use of PSRAM (if available)
else _usePsram = false;
break;
}

}


Expand All @@ -3149,15 +3158,18 @@ void TFT_eSPI::setAttribute(uint8_t attr_id, uint8_t param) {
**************************************************************************/
uint8_t TFT_eSPI::getAttribute(uint8_t attr_id) {
switch (attr_id) {
case 1: // ON/OFF control of full CP437 character set
case CP437_SWITCH: // ON/OFF control of full CP437 character set
return _cp437;
break;
case 2: // ON/OFF control of UTF-8 decoding
case UTF8_SWITCH: // ON/OFF control of UTF-8 decoding
return _utf8;
break;
//case 3: // TBD future feature control
// return _tbd;
// break;
case PSRAM_ENABLE:
return _usePsram;
break;
}

return false;
Expand Down
27 changes: 23 additions & 4 deletions src/utility/In_eSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,25 @@ struct RGBColor {
uint8_t r;
uint8_t g;
uint8_t b;
void set( uint8_t r_, uint8_t g_, uint8_t b_ ) {
r = r_; g = g_; b = b_;

RGBColor() : r{0}, g{0}, b{0} { }; // empty init on black
//RGBColor( uint16_t color565 ) { set(color565); }; // support 565
RGBColor( uint8_t r, uint8_t g, uint8_t b) : r{r}, g{g}, b{b} { }; // init rgb

void set( uint8_t _r, uint8_t _g, uint8_t _b ) {
r = _r; g = _g; b = _b;
}
bool operator==(const RGBColor& color) {

void set( uint16_t color565 ) {
r = ((color565 >> 10) & 0x3E) + 1;
g = ((color565 >> 4) & 0x7E) + 1;
b = ((color565 << 1) & 0x3E) + 1;
}
/*
bool operator!=( const RGBColor& color ) {
return color.r != r || color.g != g || color.b == b;
}*/
bool operator==( const RGBColor& color ) {
return color.r == r && color.g == g && color.b == b;
}
};
Expand Down Expand Up @@ -833,7 +848,10 @@ class TFT_eSPI : public Print {
void begin_SDA_Read(void);
void end_SDA_Read(void);
#endif

// id = 3: Enable or disable use of ESP32 PSRAM (if available)
#define CP437_SWITCH 1
#define UTF8_SWITCH 2
#define PSRAM_ENABLE 3
// Set or get an arbitrary library attribute or configuration option
void setAttribute(uint8_t id = 0, uint8_t a = 0);
uint8_t getAttribute(uint8_t id = 0);
Expand Down Expand Up @@ -905,6 +923,7 @@ class TFT_eSPI : public Print {
bool _booted; // init() or begin() has already run once
bool _cp437; // If set, use correct CP437 charset (default is ON)
bool _utf8; // If set, use UTF-8 decoder in print stream 'write()' function (default ON)
bool _usePsram = true; // use Psram if available

uint32_t _lastColor; // Buffered value of last colour used

Expand Down
2 changes: 1 addition & 1 deletion src/utility/In_eSPI_Setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
#define TFT_WIDTH 240
#define TFT_HEIGHT 320
#define TFT_DRIVER 0x7789
#define SPI_FREQUENCY 40000000
#define SPI_FREQUENCY 80000000
#define SPI_READ_FREQUENCY 16000000
#include "TFT_Drivers/ST7789_WROVER_KIT_LCD_Defines.h"
#define WROVER_KIT_LCD_DRIVER
Expand Down
10 changes: 5 additions & 5 deletions src/utility/In_imgDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,11 @@ static void jpgLegacyRenderer( const uint8_t * jpg_data, uint32_t jpg_len, int32

if (!maxWidth) {
maxWidth = GetWidthCallBack() - x;
log_w("Adjusted maxWidth to %d", maxWidth );
log_d("Adjusted maxWidth to %d", maxWidth );
}
if (!maxHeight) {
maxHeight = GetHeightCallBack() - y;
log_w("Adjusted maxHeight to %d", maxWidth );
log_d("Adjusted maxHeight to %d", maxWidth );
}

jpeg.src = jpg_data;
Expand Down Expand Up @@ -550,9 +550,9 @@ static void pngRender(pngle_t *pngle, uint32_t x, uint32_t y, uint32_t w, uint32
rgba[B] = p->bgcolor8[B];
} else {
// alpha color blend with background
rgba[R] = (p->bgcolor8[R] * p->alphaThreshold + rgba[R] * (255 - p->alphaThreshold)) / 255;
rgba[G] = (p->bgcolor8[G] * p->alphaThreshold + rgba[G] * (255 - p->alphaThreshold)) / 255;
rgba[B] = (p->bgcolor8[B] * p->alphaThreshold + rgba[B] * (255 - p->alphaThreshold)) / 255;
rgba[R] = (p->bgcolor8[R] * p->alphaThreshold + rgba[R] * (255 - p->alphaThreshold)) / 256;
rgba[G] = (p->bgcolor8[G] * p->alphaThreshold + rgba[G] * (255 - p->alphaThreshold)) / 256;
rgba[B] = (p->bgcolor8[B] * p->alphaThreshold + rgba[B] * (255 - p->alphaThreshold)) / 256;
}
}

Expand Down
35 changes: 25 additions & 10 deletions src/utility/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
// there is a nett performance gain by using swapped bytes.
***************************************************************************************/
#include "Sprite.h"

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"

/***************************************************************************************
** Function name: TFT_eSprite
** Description: Class constructor
Expand Down Expand Up @@ -2148,7 +2152,7 @@ int16_t TFT_eSprite::printToSprite(int16_t x, int16_t y, uint16_t index)




#endif


/*\
Expand All @@ -2172,13 +2176,22 @@ RGBColor TFT_eSprite::colorAt( int32_t x0, int32_t y0, int32_t x1, int32_t y1, i
}
}
if( useHline ) {
r = map( x2, x0, x1, colorstart.r, colorend.r );
g = map( x2, x0, x1, colorstart.g, colorend.g );
b = map( x2, x0, x1, colorstart.b, colorend.b );
if( x1 > x0 ) {
swap_coord( x0, x1 );
swap_coord( colorstart, colorend );
}
r = map( x2, x0, x1, colorstart.r, colorend.r );
g = map( x2, x0, x1, colorstart.g, colorend.g );
b = map( x2, x0, x1, colorstart.b, colorend.b );
} else {
r = map( y2, y0, y1, colorstart.r, colorend.r );
g = map( y2, y0, y1, colorstart.g, colorend.g );
b = map( y1, y0, y1, colorstart.b, colorend.b );
if( y1 > y0 ) {
swap_coord( y0, y1 );
swap_coord( colorstart, colorend );
}
r = map( y2, y0, y1, colorstart.r, colorend.r );
g = map( y2, y0, y1, colorstart.g, colorend.g );
b = map( y1, y0, y1, colorstart.b, colorend.b );

}
return RGBColor{r,g,b};

Expand Down Expand Up @@ -2306,8 +2319,10 @@ __attribute__((unused)) static TFT_eSPI *imgDecoderDisplay;
\*/
static bool fast_jpg_sprite_output(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t* bitmap) {
if ( y >= imgDecoderSprite->height() ) return 0;
imgDecoderSprite->pushImage(x, y, w, h, bitmap);
log_v("jpg sprite rendered");
imgDecoderSprite->setWindow( x, y, x+w-1, y+h-1 );
for( uint16_t i=0;i<w*h;i++) {
imgDecoderSprite->pushColor( bitmap[i] );
}
return 1;
}

Expand Down Expand Up @@ -2390,4 +2405,4 @@ bool TFT_eSprite::setupImgDecoder( int32_t x, int32_t y, uint16_t maxWidth, uint
return true;
}

#endif
#pragma GCC diagnostic pop
2 changes: 1 addition & 1 deletion src/utility/Sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class TFT_eSprite : public TFT_eSPI {

bool _created; // A Sprite has been created and memory reserved
bool _gFont = false;
bool _usePsram = true; // use Psram if available
//bool _usePsram = true; // use Psram if available

// int32_t _icursor_x, _icursor_y;
uint8_t _rotation = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/utility/TFT_Drivers/ST7789_WROVER_KIT_LCD_Init.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
spi_end_read();
spi_end();
delay(120);
log_d("Display ID: 0x%06X", _id);
log_w("Display ID: 0x%06X", _id);

if( _id == 0 ) {
// Software reset, needed by ILI9341 after the previous query
Expand All @@ -40,7 +40,7 @@


if( _id > 0 ) {
log_d("ST7789 Init");
log_w("ST7789 Init");
static const uint8_t PROGMEM st7789[] = {
16,
TFT_SLPOUT, 1, 255,
Expand All @@ -62,7 +62,7 @@
};
commandList(st7789);
} else {
log_d("ILI9341 Init");
log_w("ILI9341 Init");
static const uint8_t PROGMEM ili9341[] = {
21,
0xef, 3, 0x03,0x80,0x02,
Expand Down
1 change: 1 addition & 0 deletions src/utility/TinyBMPEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ bool BMP_Encoder::encodeToFile( const char* filename, const int imageW, const in
colorByteH = colorByteH >> 1;
outFile.write( colorByteL );
outFile.write( colorByteH );
//vTaskDelay(1);
}
}
outFile.close();
Expand Down
4 changes: 2 additions & 2 deletions src/utility/TouchButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class TouchButton {
TouchButton(void);
// "Classic" initButton() uses center & size
void initButton(TFT_eSPI *gfx, int16_t x, int16_t y,
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
uint16_t textcolor, char *label, uint8_t textsize);
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
uint16_t textcolor, char *label, uint8_t textsize);

// New/alt initButton() uses upper-left corner & size
void initButtonUL(TFT_eSPI *gfx, int16_t x1, int16_t y1,
Expand Down
2 changes: 1 addition & 1 deletion src/utility/quaternionFilters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static float GyroMeasDrift = PI * (0.0f / 180.0f);
static float beta = sqrt(3.0f / 4.0f) * GyroMeasError; // Compute beta
// Compute zeta, the other free parameter in the Madgwick scheme usually
// set to a small or zero value
static float zeta = sqrt(3.0f / 4.0f) * GyroMeasDrift;
__attribute__((unused)) static float zeta = sqrt(3.0f / 4.0f) * GyroMeasDrift;

// Vector to hold integral error for Mahony method
static float eInt[3] = { 0.0f, 0.0f, 0.0f };
Expand Down

0 comments on commit 368daf0

Please sign in to comment.