diff --git a/.github/workflows/prerelease.yml b/.github/workflows/prerelease.yml index de878a60..968e7ddb 100644 --- a/.github/workflows/prerelease.yml +++ b/.github/workflows/prerelease.yml @@ -3,7 +3,7 @@ name: Nerdminer Pre-Release on: push: branches: - - prerelease + - dev jobs: build: @@ -25,24 +25,17 @@ jobs: run: pip install --upgrade platformio - name: Build PlatformIO Project run: pio run - - name: Debug - Check generated files - run: | - echo "=== All .bin files found ===" - find . -name "*.bin" -type f - echo "=== Directory structure ===" - ls -la - echo "=== .pio/build contents ===" - find .pio/build -name "*.bin" -type f 2>/dev/null || echo "No .pio/build files" - echo "=== firmware directory ===" - ls -la firmware/ 2>/dev/null || echo "No firmware directory" - find firmware -name "*.bin" -type f 2>/dev/null || echo "No firmware .bin files" - echo "=== Script check ===" - ls -la post_build_merge.py - - name: Archive firmware files + - name: Archive built binaries uses: actions/upload-artifact@v4 with: - name: firmware-files-${{ github.sha }} - path: firmware/ + name: built-binaries-${{ github.sha }} + path: .pio/build/*/*.bin + if-no-files-found: error + - name: Archive bootapp binary + uses: actions/upload-artifact@v4 + with: + name: bootapp-binary-${{ github.sha }} + path: ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin if-no-files-found: error - name: Get version id: version_step @@ -54,23 +47,21 @@ jobs: contents: write discussions: write runs-on: ubuntu-latest - if: github.ref == 'refs/heads/prerelease' + if: github.ref == 'refs/heads/dev' steps: - - name: Download firmware files + - name: Download built binaries + uses: actions/download-artifact@v4 + with: + path: ${{ github.workspace }}/binaries + name: built-binaries-${{ github.sha }} + - name: Download bootapp binary uses: actions/download-artifact@v4 with: - path: ${{ github.workspace }}/ - name: firmware-files-${{ github.sha }} - - name: Debug - Check downloaded files - run: | - echo "=== Working directory ===" - pwd - ls -la - echo "=== All .bin files after download ===" - find . -name "*.bin" -type f - echo "=== firmware directory after download ===" - find firmware -type f 2>/dev/null || echo "No firmware directory found" - - name: Prerelease + path: ${{ github.workspace }}/binaries + name: bootapp-binary-${{ github.sha }} + - name: Rename built binaries + run: find ${{ github.workspace }}/binaries -mindepth 2 -maxdepth 3 -type f -name "*.bin" -exec sh -c 'cp "$0" "${{ github.workspace }}/binaries/$(basename $(dirname "$0"))_$(basename $0)"' {} \; + - name: Pre-release uses: softprops/action-gh-release@v2 with: name: nerdminer-prerelease-${{ needs.build.outputs.version }} @@ -79,5 +70,5 @@ jobs: generate_release_notes: true prerelease: true fail_on_unmatched_files: true - files: ${{ github.workspace }}/**/*.bin + files: ${{ github.workspace }}/binaries/*.bin diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 65571ec1..4f32f581 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,7 @@ name: Nerdminer Release on: push: branches: - - main + - master jobs: build: @@ -25,11 +25,17 @@ jobs: run: pip install --upgrade platformio - name: Build PlatformIO Project run: pio run - - name: Archive firmware files + - name: Archive built binaries uses: actions/upload-artifact@v4 with: - name: firmware-files-${{ github.sha }} - path: firmware/ + name: built-binaries-${{ github.sha }} + path: .pio/build/*/*.bin + if-no-files-found: error + - name: Archive bootapp binary + uses: actions/upload-artifact@v4 + with: + name: bootapp-binary-${{ github.sha }} + path: ~/.platformio/packages/framework-arduinoespressif32/tools/partitions/boot_app0.bin if-no-files-found: error - name: Get version id: version_step @@ -42,7 +48,7 @@ jobs: discussions: write issues: write runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' + if: github.ref == 'refs/heads/master' steps: - uses: trstringer/manual-approval@v1 timeout-minutes: 120 @@ -53,11 +59,18 @@ jobs: issue-title: "Releasing Nerdminer version ${{ needs.build.outputs.version }}" issue-body: "Please approve or deny the release of ${{ needs.build.outputs.version }}." exclude-workflow-initiator-as-approver: false - - name: Download firmware files + - name: Download built binaries + uses: actions/download-artifact@v4 + with: + path: ${{ github.workspace }}/binaries + name: built-binaries-${{ github.sha }} + - name: Download bootapp binary uses: actions/download-artifact@v4 with: - path: ${{ github.workspace }}/ - name: firmware-files-${{ github.sha }} + path: ${{ github.workspace }}/binaries + name: bootapp-binary-${{ github.sha }} + - name: Rename built binaries + run: find ${{ github.workspace }}/binaries -mindepth 2 -maxdepth 3 -type f -name "*.bin" -exec sh -c 'cp "$0" "${{ github.workspace }}/binaries/$(basename $(dirname "$0"))_$(basename $0)"' {} \; - name: Release uses: softprops/action-gh-release@v2 with: @@ -67,5 +80,5 @@ jobs: generate_release_notes: true make_latest: true fail_on_unmatched_files: true - files: ${{ github.workspace }}/**/*.bin + files: ${{ github.workspace }}/binaries/*.bin diff --git a/README.md b/README.md index 69759d0d..1e67db2a 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,6 @@ Every time an stratum job notification is received miner update its current work - ESP32-C3 Super Mini ([Board Info](https://docs.platformio.org/en/latest/boards/espressif32/seeed_xiao_esp32c3.html)) - Waveshare ESP32-S3-GEEK ([Board Info](https://www.waveshare.com/wiki/ESP32-S3-GEEK)) - LILYGO T-HMI ([Aliexpress link\*](https://s.click.aliexpress.com/e/_oFII4s2)) / Dev support: @cosmicpsyop -- ESP32-C3 0.42 Inch OLED ([Aliexpress link\*](https://s.click.aliexpress.com/e/_oDmT4Id) / Dev support: @mrthiti / ⚡ wallet@thiti.dev) -- ESP32-S3 0.42 Inch OLED ([Aliexpress link\*](https://s.click.aliexpress.com/e/_oFIMUoh) / Dev support: @mrthiti / ⚡ wallet@thiti.dev) \*Affiliate links @@ -150,8 +148,6 @@ Recommended low difficulty share pools: | pool.nerdminer.io | 3333 | https://nerdminer.io | Mantained by CHMEX | | pool.pyblock.xyz | 3333 | https://pool.pyblock.xyz/ | Mantained by curly60e | | pool.sethforprivacy.com | 3333 | https://pool.sethforprivacy.com/ | Mantained by @sethforprivacy - public-pool fork | -| pool.stompi.de | 3333 | http://web.stompi.de | Mantained by @odinstar - public-pool fork | -|pool.solomining.de| 3333 | https://pool.solomining.de/ | Mantained by https://x.com/solo_mining | Other standard pools not compatible with low difficulty share: diff --git a/lib/TFT_eSPI/Extensions/Smooth_font.cpp b/lib/TFT_eSPI/Extensions/Smooth_font.cpp index c67204ac..d1915a48 100644 --- a/lib/TFT_eSPI/Extensions/Smooth_font.cpp +++ b/lib/TFT_eSPI/Extensions/Smooth_font.cpp @@ -48,7 +48,7 @@ void TFT_eSPI::loadFont(String fontName, bool flash) 6. Descent in pixels from baseline to bottom of "p" Next are gCount sets of values for each glyph, each set comprises 7 int32t parameters (28 bytes): - 1. Glyph Unicode stored as a 32-bit value + 1. Glyph Unicode stored as a 32 bit value 2. Height of bitmap bounding box 3. Width of bitmap bounding box 4. gxAdvance for cursor (setWidth in Processing) @@ -57,7 +57,7 @@ void TFT_eSPI::loadFont(String fontName, bool flash) 7. padding value, typically 0 The bitmaps start next at 24 + (28 * gCount) bytes from the start of the file. - Each pixel is 1 byte, an 8-bit Alpha value which represents the transparency from + Each pixel is 1 byte, an 8 bit Alpha value which represents the transparency from 0xFF foreground colour, 0x00 background. The library uses a linear interpolation between the foreground and background RGB component colours. e.g. pixelRed = ((fgRed * alpha) + (bgRed * (255 - alpha))/255 @@ -158,7 +158,7 @@ void TFT_eSPI::loadMetrics(void) #if defined (ESP32) && defined (CONFIG_SPIRAM_SUPPORT) if ( psramFound() ) { - gUnicode = (uint16_t*)ps_malloc( gFont.gCount * 2); // Unicode 16-bit Basic Multilingual Plane (0-FFFF) + gUnicode = (uint16_t*)ps_malloc( gFont.gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF) gHeight = (uint8_t*)ps_malloc( gFont.gCount ); // Height of glyph gWidth = (uint8_t*)ps_malloc( gFont.gCount ); // Width of glyph gxAdvance = (uint8_t*)ps_malloc( gFont.gCount ); // xAdvance - to move x cursor @@ -169,7 +169,7 @@ void TFT_eSPI::loadMetrics(void) else #endif { - gUnicode = (uint16_t*)malloc( gFont.gCount * 2); // Unicode 16-bit Basic Multilingual Plane (0-FFFF) + gUnicode = (uint16_t*)malloc( gFont.gCount * 2); // Unicode 16 bit Basic Multilingual Plane (0-FFFF) gHeight = (uint8_t*)malloc( gFont.gCount ); // Height of glyph gWidth = (uint8_t*)malloc( gFont.gCount ); // Width of glyph gxAdvance = (uint8_t*)malloc( gFont.gCount ); // xAdvance - to move x cursor @@ -308,7 +308,7 @@ void TFT_eSPI::unloadFont( void ) /*************************************************************************************** ** Function name: readInt32 -** Description: Get a 32-bit integer from the font file +** Description: Get a 32 bit integer from the font file *************************************************************************************x*/ uint32_t TFT_eSPI::readInt32(void) { @@ -316,18 +316,18 @@ uint32_t TFT_eSPI::readInt32(void) #ifdef FONT_FS_AVAILABLE if (fs_font) { - val = (uint32_t)fontFile.read() << 24; - val |= (uint32_t)fontFile.read() << 16; - val |= (uint32_t)fontFile.read() << 8; - val |= (uint32_t)fontFile.read(); + val = fontFile.read() << 24; + val |= fontFile.read() << 16; + val |= fontFile.read() << 8; + val |= fontFile.read(); } else #endif { - val = (uint32_t)pgm_read_byte(fontPtr++) << 24; - val |= (uint32_t)pgm_read_byte(fontPtr++) << 16; - val |= (uint32_t)pgm_read_byte(fontPtr++) << 8; - val |= (uint32_t)pgm_read_byte(fontPtr++); + val = pgm_read_byte(fontPtr++) << 24; + val |= pgm_read_byte(fontPtr++) << 16; + val |= pgm_read_byte(fontPtr++) << 8; + val |= pgm_read_byte(fontPtr++); } return val; diff --git a/lib/TFT_eSPI/Extensions/Sprite.cpp b/lib/TFT_eSPI/Extensions/Sprite.cpp index af841cc1..bab2fac5 100644 --- a/lib/TFT_eSPI/Extensions/Sprite.cpp +++ b/lib/TFT_eSPI/Extensions/Sprite.cpp @@ -47,7 +47,7 @@ TFT_eSprite::TFT_eSprite(TFT_eSPI *tft) ** Function name: createSprite ** Description: Create a sprite (bitmap) of defined width and height ***************************************************************************************/ -// cast returned value to (uint8_t*) for 8-bit or (uint16_t*) for 16-bit colours +// cast returned value to (uint8_t*) for 8 bit or (uint16_t*) for 16 bit colours void* TFT_eSprite::createSprite(int16_t w, int16_t h, uint8_t frames) { @@ -88,6 +88,8 @@ void* TFT_eSprite::createSprite(int16_t w, int16_t h, uint8_t frames) _img8_2 = _img8 + (w * h + 1); } + if ( (_bpp == 4) && (_colorMap == nullptr)) createPalette(default_4bit_palette); + // This is to make it clear what pointer size is expected to be used // but casting in the user sketch is needed due to the use of void* if ( (_bpp == 1) && (frames > 1) ) @@ -99,8 +101,6 @@ void* TFT_eSprite::createSprite(int16_t w, int16_t h, uint8_t frames) if (_img8) { _created = true; - if ( (_bpp == 4) && (_colorMap == nullptr)) createPalette(default_4bit_palette); - rotation = 0; setViewport(0, 0, _dwidth, _dheight); setPivot(_iwidth/2, _iheight/2); @@ -776,7 +776,7 @@ bool TFT_eSprite::pushToSprite(TFT_eSprite *dspr, int32_t x, int32_t y, uint16_t if (transp == rp) { if (pixel_count) { - dspr->pushImage(ox, y, pixel_count, 1, sline_buffer); + dspr->pushImage(ox, y, pixel_count, 1, sline_buffer, _bpp); ox += pixel_count; pixel_count = 0; } @@ -1104,7 +1104,7 @@ void TFT_eSprite::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_ } else if (_bpp == 4) { - // The image is assumed to be 4-bit, where each byte corresponds to two pixels. + // The image is assumed to be 4 bit, where each byte corresponds to two pixels. // much faster when aligned to a byte boundary, because the alternative is slower, requiring // tedious bit operations. @@ -1355,10 +1355,10 @@ void TFT_eSprite::writeColor(uint16_t color) { if (!_created ) return; - // Write 16-bit RGB 565 encoded colour to RAM + // Write 16 bit RGB 565 encoded colour to RAM if (_bpp == 16) _img [_xptr + _yptr * _iwidth] = color; - // Write 8-bit RGB 332 encoded colour to RAM + // Write 8 bit RGB 332 encoded colour to RAM else if (_bpp == 8) _img8[_xptr + _yptr * _iwidth] = (uint8_t) color; else if (_bpp == 4) @@ -1985,6 +1985,10 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uin { if ( _vpOoB || !_created ) return; + if ((x >= _vpW - _xDatum) || // Clip right + (y >= _vpH - _yDatum)) // Clip bottom + return; + if (c < 32) return; #ifdef LOAD_GLCD //>>>>>>>>>>>>>>>>>> @@ -1993,17 +1997,10 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uin #endif //>>>>>>>>>>>>>>>>>> - if ((x >= _vpW - _xDatum) || // Clip right - (y >= _vpH - _yDatum)) // Clip bottom - return; - if (((x + 6 * size - 1) < (_vpX - _xDatum)) || // Clip left ((y + 8 * size - 1) < (_vpY - _yDatum))) // Clip top return; - if (c > 255) return; - if (!_cp437 && c > 175) c++; - bool fillbg = (bg != color); if ((size==1) && fillbg) @@ -2138,7 +2135,7 @@ void TFT_eSprite::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uin /*************************************************************************************** ** Function name: drawChar -** Description: draw a Unicode glyph into the sprite +** Description: draw a unicode glyph into the sprite ***************************************************************************************/ // TODO: Rationalise with TFT_eSPI // Any UTF-8 decoding must be done before calling drawChar() @@ -2290,7 +2287,7 @@ int16_t TFT_eSprite::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t fo uint8_t tnp = 0; // Temporary copy of np for while loop uint8_t ts = textsize - 1; // Temporary copy of textsize - // 16-bit pixel count so maximum font size is equivalent to 180x180 pixels in area + // 16 bit pixel count so maximum font size is equivalent to 180x180 pixels in area // w is total number of pixels to plot to fill character block while (pc < w) { line = pgm_read_byte((uint8_t *)flash_address); diff --git a/lib/TFT_eSPI/Extensions/Sprite.h b/lib/TFT_eSPI/Extensions/Sprite.h index 67e29de7..5f3e59ef 100644 --- a/lib/TFT_eSPI/Extensions/Sprite.h +++ b/lib/TFT_eSPI/Extensions/Sprite.h @@ -13,12 +13,12 @@ class TFT_eSprite : public TFT_eSPI { ~TFT_eSprite(void); // Create a sprite of width x height pixels, return a pointer to the RAM area - // Sketch can cast returned value to (uint16_t*) for 16-bit depth if needed + // Sketch can cast returned value to (uint16_t*) for 16 bit depth if needed // RAM required is: // - 1 bit per pixel for 1 bit colour depth - // - 1 nibble per pixel for 4-bit colour (with palette table) - // - 1 byte per pixel for 8-bit colour (332 RGB format) - // - 2 bytes per pixel for 16-bit color depth (565 RGB format) + // - 1 nibble per pixel for 4 bit colour (with palette table) + // - 1 byte per pixel for 8 bit colour (332 RGB format) + // - 2 bytes per pixel for 16 bit color depth (565 RGB format) void* createSprite(int16_t width, int16_t height, uint8_t frames = 1); // Returns a pointer to the sprite or nullptr if not created, user must cast to pointer type @@ -39,7 +39,7 @@ class TFT_eSprite : public TFT_eSPI { void* setColorDepth(int8_t b); int8_t getColorDepth(void); - // Set the palette for a 4-bit depth sprite. Only the first 16 colours in the map are used. + // Set the palette for a 4 bit depth sprite. Only the first 16 colours in the map are used. void createPalette(uint16_t *palette = nullptr, uint8_t colors = 16); // Palette in RAM void createPalette(const uint16_t *palette = nullptr, uint8_t colors = 16); // Palette in FLASH @@ -61,14 +61,14 @@ class TFT_eSprite : public TFT_eSPI { // Fill Sprite with a colour fillSprite(uint32_t color), - // Define a window to push 16-bit colour pixels into in a raster order + // Define a window to push 16 bit colour pixels into in a raster order // Colours are converted to the set Sprite colour bit depth setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1), // Push a color (aka singe pixel) to the sprite's set window area pushColor(uint16_t color), // Push len colors (pixels) to the sprite's set window area pushColor(uint16_t color, uint32_t len), - // Push a pixel pre-formatted as a 1, 4, 8 or 16-bit colour (avoids conversion overhead) + // Push a pixel pre-formatted as a 1, 4, 8 or 16 bit colour (avoids conversion overhead) writeColor(uint16_t color), // Set the scroll zone, top left corner at x,y with defined width and height @@ -139,7 +139,7 @@ class TFT_eSprite : public TFT_eSPI { height(void); // Functions associated with anti-aliased fonts - // Draw a single Unicode character using the loaded font + // Draw a single unicode character using the loaded font void drawGlyph(uint16_t code); // Print string to sprite using loaded font at cursor position void printToSprite(String string); @@ -162,13 +162,13 @@ class TFT_eSprite : public TFT_eSPI { protected: uint8_t _bpp; // bits per pixel (1, 4, 8 or 16) - uint16_t *_img; // pointer to 16-bit sprite - uint8_t *_img8; // pointer to 1 and 8-bit sprite frame 1 or frame 2 - uint8_t *_img4; // pointer to 4-bit sprite (uses color map) + uint16_t *_img; // pointer to 16 bit sprite + uint8_t *_img8; // pointer to 1 and 8 bit sprite frame 1 or frame 2 + uint8_t *_img4; // pointer to 4 bit sprite (uses color map) uint8_t *_img8_1; // pointer to frame 1 uint8_t *_img8_2; // pointer to frame 2 - uint16_t *_colorMap; // color map pointer: 16 entries, used with 4-bit color map. + uint16_t *_colorMap; // color map pointer: 16 entries, used with 4 bit color map. int32_t _sinra; // Sine of rotation angle in fixed point int32_t _cosra; // Cosine of rotation angle in fixed point diff --git a/lib/TFT_eSPI/Extensions/Touch.h b/lib/TFT_eSPI/Extensions/Touch.h index 9bb81fc8..d6916972 100644 --- a/lib/TFT_eSPI/Extensions/Touch.h +++ b/lib/TFT_eSPI/Extensions/Touch.h @@ -11,10 +11,7 @@ // Get the screen touch coordinates, returns true if screen has been touched // if the touch coordinates are off screen then x and y are not updated // The returned value can be treated as a bool type, false or 0 means touch not detected - // In future the function may return an 8-bit "quality" (jitter) value. - // The threshold value is optional, this must be higher than the bias level for z (pressure) - // reported by Test_Touch_Controller when the screen is NOT touched. When touched the z value - // must be higher than the threshold for a touch to be detected. + // In future the function may return an 8 "quality" (jitter) value. uint8_t getTouch(uint16_t *x, uint16_t *y, uint16_t threshold = 600); // Run screen calibration and test, report calibration values to the serial port diff --git a/lib/TFT_eSPI/Fonts/Font32rle.c b/lib/TFT_eSPI/Fonts/Font32rle.c index 7a8119b0..f163986c 100644 --- a/lib/TFT_eSPI/Fonts/Font32rle.c +++ b/lib/TFT_eSPI/Fonts/Font32rle.c @@ -1,6 +1,6 @@ // Font 4 // -// This font has been 8-bit Run Length Encoded to save FLASH space +// This font has been 8 bit Run Length Encoded to save FLASH space // // This font contains 96 ASCII characters diff --git a/lib/TFT_eSPI/Fonts/Font64rle.c b/lib/TFT_eSPI/Fonts/Font64rle.c index a80e6ea7..9d1415b0 100644 --- a/lib/TFT_eSPI/Fonts/Font64rle.c +++ b/lib/TFT_eSPI/Fonts/Font64rle.c @@ -1,6 +1,6 @@ // Font 6 is intended to display numbers and time // -// This font has been 8-bit Run Length Encoded to save FLASH space +// This font has been 8 bit Run Length Encoded to save FLASH space // // This font only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : - . a p m // The Pipe character | is a narrow space to aid formatting diff --git a/lib/TFT_eSPI/Fonts/Font72rle.c b/lib/TFT_eSPI/Fonts/Font72rle.c index 478411aa..7f5da5df 100644 --- a/lib/TFT_eSPI/Fonts/Font72rle.c +++ b/lib/TFT_eSPI/Fonts/Font72rle.c @@ -1,6 +1,6 @@ // Font 8 // -// This font has been 8-bit Run Length Encoded to save FLASH space +// This font has been 8 bit Run Length Encoded to save FLASH space // // It is a Arial 75 pixel height font intended to display large numbers // This font only contains characters [space] 0 1 2 3 4 5 6 7 8 9 0 : - . diff --git a/lib/TFT_eSPI/Fonts/Font72x53rle.c b/lib/TFT_eSPI/Fonts/Font72x53rle.c index ae8d00cb..71c2c4f6 100644 --- a/lib/TFT_eSPI/Fonts/Font72x53rle.c +++ b/lib/TFT_eSPI/Fonts/Font72x53rle.c @@ -1,6 +1,6 @@ // Font 8 // -// This font has been 8-bit Run Length Encoded to save FLASH space +// This font has been 8 bit Run Length Encoded to save FLASH space // // It is a Arial 75 pixel height font intended to display large numbers // Width for numerals reduced from 55 to 53 (to fit in 160 pixel screens) diff --git a/lib/TFT_eSPI/Fonts/Font7srle.c b/lib/TFT_eSPI/Fonts/Font7srle.c index 7d54a6fa..7c6f929b 100644 --- a/lib/TFT_eSPI/Fonts/Font7srle.c +++ b/lib/TFT_eSPI/Fonts/Font7srle.c @@ -1,6 +1,6 @@ // Font 7 // -// This font has been 8-bit Run Length Encoded to save FLASH space +// This font has been 8 bit Run Length Encoded to save FLASH space // // This is a 7 segment font intended to display numbers and time // This font only contains characters [space] 0 1 2 3 4 5 6 7 8 9 : . - diff --git a/lib/TFT_eSPI/Fonts/glcdfont.c b/lib/TFT_eSPI/Fonts/glcdfont.c index 95c1c98a..882a133b 100644 --- a/lib/TFT_eSPI/Fonts/glcdfont.c +++ b/lib/TFT_eSPI/Fonts/glcdfont.c @@ -182,9 +182,8 @@ static const unsigned char font[] PROGMEM = { 0x00, 0x00, 0x7B, 0x00, 0x00, 0x08, 0x14, 0x2A, 0x14, 0x22, 0x22, 0x14, 0x2A, 0x14, 0x08, - 0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code - 0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block - 0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block + 0xAA, 0x00, 0x55, 0x00, 0xAA, + 0xAA, 0x55, 0xAA, 0x55, 0xAA, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x10, 0x10, 0x10, 0xFF, 0x00, 0x14, 0x14, 0x14, 0xFF, 0x00, diff --git a/lib/TFT_eSPI/Kconfig b/lib/TFT_eSPI/Kconfig index 2e21c90f..1433ee5e 100644 --- a/lib/TFT_eSPI/Kconfig +++ b/lib/TFT_eSPI/Kconfig @@ -158,7 +158,7 @@ menu "TFT_eSPI" config TFT_SPI bool "SPI" config TFT_PARALLEL_8_BIT - bool "Parallel (8-bit)" + bool "Parallel (8 bit)" endchoice menu "Display Data pins" diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.c b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.c index faf30343..1b0435f7 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.c +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.c @@ -100,7 +100,7 @@ void TFT_eSPI::end_SDA_Read(void) /*************************************************************************************** ** Function name: read byte - supports class functions -** Description: Read a byte from ESP32 8-bit data port +** Description: Read a byte from ESP32 8 bit data port ***************************************************************************************/ // Parallel bus MUST be set to input before calling this function! uint8_t TFT_eSPI::readByte(void) @@ -415,7 +415,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -428,7 +428,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) uint32_t r = (color & 0xF800)>>8; uint32_t g = (color & 0x07E0)<<5; uint32_t b = (color & 0x001F)<<19; - // Concatenate 4 pixels into three 32-bit blocks + // Concatenate 4 pixels into three 32 bit blocks uint32_t r0 = r<<24 | b | g | r; uint32_t r1 = r0>>8 | g<<16; uint32_t r2 = r1>>8 | b<<8; @@ -512,7 +512,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (TFT_PARALLEL_8_BIT) // Now the code for ESP32 8-bit parallel +#elif defined (TFT_PARALLEL_8_BIT) // Now the code for ESP32 8 bit parallel //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -793,7 +793,7 @@ bool TFT_eSPI::initDMA(bool ctrl_cs) .sclk_io_num = TFT_SCLK, .quadwp_io_num = -1, .quadhd_io_num = -1, - #ifdef xCONFIG_IDF_TARGET_ESP32S2 + #ifdef CONFIG_IDF_TARGET_ESP32S2 .data4_io_num = -1, .data5_io_num = -1, .data6_io_num = -1, diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.h b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.h index ad60e3dd..87cf6679 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32.h @@ -11,7 +11,6 @@ // Include processor specific header #include "soc/spi_reg.h" #include "driver/spi_master.h" -#include "hal/gpio_ll.h" #if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32) #define CONFIG_IDF_TARGET_ESP32 @@ -87,14 +86,14 @@ SPI3_HOST = 2 // Initialise processor specific SPI functions, used by init() #define INIT_TFT_DATA_BUS // Not used -// Define a generic flag for 8-bit parallel +// Define a generic flag for 8 bit parallel #if defined (ESP32_PARALLEL) // Specific to ESP32 for backwards compatibility #if !defined (TFT_PARALLEL_8_BIT) #define TFT_PARALLEL_8_BIT // Generic parallel flag #endif #endif -// Ensure ESP32 specific flag is defined for 8-bit parallel +// Ensure ESP32 specific flag is defined for 8 bit parallel #if defined (TFT_PARALLEL_8_BIT) #if !defined (ESP32_PARALLEL) #define ESP32_PARALLEL @@ -380,12 +379,12 @@ SPI3_HOST = 2 #if defined (SSD1963_DRIVER) - // Write 18-bit color to TFT + // Write 18 bit color to TFT #define tft_Write_16(C) GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) (((C) & 0xF800)>> 8)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) (((C) & 0x07E0)>> 3)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) (((C) & 0x001F)<< 3)); WR_H - // 18-bit color write with swapped bytes + // 18 bit color write with swapped bytes #define tft_Write_16S(C) Cswap = ((C) >>8 | (C) << 8); tft_Write_16(Cswap) #else @@ -399,7 +398,7 @@ SPI3_HOST = 2 #define tft_Write_16(C) GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 0)); WR_H - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 8)); WR_H #endif @@ -412,13 +411,13 @@ SPI3_HOST = 2 GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 0)); WR_H - // Write two concatenated 16-bit values to TFT + // Write two concatenated 16 bit values to TFT #define tft_Write_32C(C,D) GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((D) >> 8)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((D) >> 0)); WR_H - // Write 16-bit value twice to TFT - used by drawPixel() + // Write 16 bit value twice to TFT - used by drawPixel() #define tft_Write_32D(C) GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) ((C) >> 8)); WR_H; \ @@ -447,12 +446,12 @@ SPI3_HOST = 2 //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to a SPI ILI948x TFT //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour // Write 8 bits to TFT #define tft_Write_8(C) spi.transfer(C) - // Convert 16-bit colour to 18-bit and write in 3 bytes + // Convert 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16(C) spi.transfer(((C) & 0xF800)>>8); \ spi.transfer(((C) & 0x07E0)>>3); \ spi.transfer(((C) & 0x001F)<<3) @@ -460,7 +459,7 @@ SPI3_HOST = 2 // Future option for transfer without wait #define tft_Write_16N(C) tft_Write_16(C) - // Convert swapped byte 16-bit colour to 18-bit and write in 3 bytes + // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16S(C) spi.transfer((C) & 0xF8); \ spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \ spi.transfer(((C) & 0x1F00)>>5) @@ -468,10 +467,10 @@ SPI3_HOST = 2 // Write 32 bits to TFT #define tft_Write_32(C) spi.write32(C) - // Write two concatenated 16-bit values to TFT + // Write two concatenated 16 bit values to TFT #define tft_Write_32C(C,D) spi.write32((C)<<16 | (D)) - // Write 16-bit value twice to TFT + // Write 16 bit value twice to TFT #define tft_Write_32D(C) spi.write32((C)<<16 | (C)) //////////////////////////////////////////////////////////////////////////////////////// @@ -479,7 +478,7 @@ SPI3_HOST = 2 //////////////////////////////////////////////////////////////////////////////////////// #elif defined (RPI_DISPLAY_TYPE) - // ESP32 low level SPI writes for 8, 16 and 32-bit values + // ESP32 low level SPI writes for 8, 16 and 32 bit values // to avoid the function call overhead #define TFT_WRITE_BITS(D, B) \ WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), B-1); \ @@ -490,7 +489,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS((C)<<8, 16) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Future option for transfer without wait @@ -514,7 +513,7 @@ SPI3_HOST = 2 //////////////////////////////////////////////////////////////////////////////////////// #else /* Old macros - // ESP32 low level SPI writes for 8, 16 and 32-bit values + // ESP32 low level SPI writes for 8, 16 and 32 bit values // to avoid the function call overhead #define TFT_WRITE_BITS(D, B) \ WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), B-1); \ @@ -525,7 +524,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS(C, 8) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Write 16 bits @@ -549,7 +548,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS(C, 8) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Future option for transfer without wait diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.c b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.c index 8c97a5fe..e33a5ac6 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.c +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.c @@ -93,7 +93,7 @@ void TFT_eSPI::end_SDA_Read(void) /*************************************************************************************** ** Function name: read byte - supports class functions -** Description: Read a byte from ESP32 8-bit data port +** Description: Read a byte from ESP32 8 bit data port ***************************************************************************************/ // Parallel bus MUST be set to input before calling this function! uint8_t TFT_eSPI::readByte(void) @@ -436,7 +436,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -449,7 +449,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) uint32_t r = (color & 0xF800)>>8; uint32_t g = (color & 0x07E0)<<5; uint32_t b = (color & 0x001F)<<19; - // Concatenate 4 pixels into three 32-bit blocks + // Concatenate 4 pixels into three 32 bit blocks uint32_t r0 = r<<24 | b | g | r; uint32_t r1 = r0>>8 | g<<16; uint32_t r2 = r1>>8 | b<<8; @@ -540,7 +540,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (TFT_PARALLEL_8_BIT) // Now the code for ESP32 8-bit parallel +#elif defined (TFT_PARALLEL_8_BIT) // Now the code for ESP32 8 bit parallel //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -806,10 +806,6 @@ bool TFT_eSPI::initDMA(bool ctrl_cs) .sclk_io_num = TFT_SCLK, .quadwp_io_num = -1, .quadhd_io_num = -1, - .data4_io_num = -1, - .data5_io_num = -1, - .data6_io_num = -1, - .data7_io_num = -1, .max_transfer_sz = TFT_WIDTH * TFT_HEIGHT * 2 + 8, // TFT screen size .flags = 0, .intr_flags = 0 diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.h b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.h index 6fa18585..ff535a62 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_C3.h @@ -17,7 +17,6 @@ // Include processor specific header #include "soc/spi_reg.h" #include "driver/spi_master.h" -#include "hal/gpio_ll.h" #if !defined(CONFIG_IDF_TARGET_ESP32C3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32) #define CONFIG_IDF_TARGET_ESP32 @@ -79,14 +78,14 @@ SPI3_HOST = 2 // Initialise processor specific SPI functions, used by init() #define INIT_TFT_DATA_BUS // Not used -// Define a generic flag for 8-bit parallel +// Define a generic flag for 8 bit parallel #if defined (ESP32_PARALLEL) // Specific to ESP32 for backwards compatibility #if !defined (TFT_PARALLEL_8_BIT) #define TFT_PARALLEL_8_BIT // Generic parallel flag #endif #endif -// Ensure ESP32 specific flag is defined for 8-bit parallel +// Ensure ESP32 specific flag is defined for 8 bit parallel #if defined (TFT_PARALLEL_8_BIT) #if !defined (ESP32_PARALLEL) #define ESP32_PARALLEL @@ -371,12 +370,12 @@ SPI3_HOST = 2 #if defined (SSD1963_DRIVER) - // Write 18-bit color to TFT + // Write 18 bit color to TFT #define tft_Write_16(C) GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) (((C) & 0xF800)>> 8)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) (((C) & 0x07E0)>> 3)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) (((C) & 0x001F)<< 3)); WR_H - // 18-bit color write with swapped bytes + // 18 bit color write with swapped bytes #define tft_Write_16S(C) Cswap = ((C) >>8 | (C) << 8); tft_Write_16(Cswap) #else @@ -390,7 +389,7 @@ SPI3_HOST = 2 #define tft_Write_16(C) GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 0)); WR_H - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 8)); WR_H #endif @@ -403,13 +402,13 @@ SPI3_HOST = 2 GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 0)); WR_H - // Write two concatenated 16-bit values to TFT + // Write two concatenated 16 bit values to TFT #define tft_Write_32C(C,D) GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((D) >> 8)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((D) >> 0)); WR_H - // Write 16-bit value twice to TFT - used by drawPixel() + // Write 16 bit value twice to TFT - used by drawPixel() #define tft_Write_32D(C) GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO.out_w1tc.val = GPIO_OUT_CLR_MASK; GPIO.out_w1ts.val = set_mask((uint8_t) ((C) >> 8)); WR_H; \ @@ -438,12 +437,12 @@ SPI3_HOST = 2 //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to a SPI ILI948x TFT //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour // Write 8 bits to TFT #define tft_Write_8(C) spi.transfer(C) - // Convert 16-bit colour to 18-bit and write in 3 bytes + // Convert 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16(C) spi.transfer(((C) & 0xF800)>>8); \ spi.transfer(((C) & 0x07E0)>>3); \ spi.transfer(((C) & 0x001F)<<3) @@ -451,7 +450,7 @@ SPI3_HOST = 2 // Future option for transfer without wait #define tft_Write_16N(C) tft_Write_16(C) - // Convert swapped byte 16-bit colour to 18-bit and write in 3 bytes + // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16S(C) spi.transfer((C) & 0xF8); \ spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \ spi.transfer(((C) & 0x1F00)>>5) @@ -459,10 +458,10 @@ SPI3_HOST = 2 // Write 32 bits to TFT #define tft_Write_32(C) spi.write32(C) - // Write two concatenated 16-bit values to TFT + // Write two concatenated 16 bit values to TFT #define tft_Write_32C(C,D) spi.write32((C)<<16 | (D)) - // Write 16-bit value twice to TFT + // Write 16 bit value twice to TFT #define tft_Write_32D(C) spi.write32((C)<<16 | (C)) //////////////////////////////////////////////////////////////////////////////////////// @@ -470,7 +469,7 @@ SPI3_HOST = 2 //////////////////////////////////////////////////////////////////////////////////////// #elif defined (RPI_DISPLAY_TYPE) - // ESP32 low level SPI writes for 8, 16 and 32-bit values + // ESP32 low level SPI writes for 8, 16 and 32 bit values // to avoid the function call overhead #define TFT_WRITE_BITS(D, B) \ WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), B-1); \ @@ -481,7 +480,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS((C)<<8, 16) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Future option for transfer without wait @@ -505,7 +504,7 @@ SPI3_HOST = 2 //////////////////////////////////////////////////////////////////////////////////////// #else /* Old macros - // ESP32 low level SPI writes for 8, 16 and 32-bit values + // ESP32 low level SPI writes for 8, 16 and 32 bit values // to avoid the function call overhead #define TFT_WRITE_BITS(D, B) \ WRITE_PERI_REG(SPI_MOSI_DLEN_REG(SPI_PORT), B-1); \ @@ -516,7 +515,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS(C, 8) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Write 16 bits @@ -548,7 +547,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS(C, 8) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Future option for transfer without wait diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c index d689e72a..5bc79140 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.c @@ -84,7 +84,7 @@ void TFT_eSPI::end_SDA_Read(void) /*************************************************************************************** ** Function name: read byte - supports class functions -** Description: Read a byte from ESP32 8-bit data port +** Description: Read a byte from ESP32 8 bit data port ***************************************************************************************/ // Parallel bus MUST be set to input before calling this function! uint8_t TFT_eSPI::readByte(void) @@ -426,7 +426,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -439,7 +439,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) uint32_t r = (color & 0xF800)>>8; uint32_t g = (color & 0x07E0)<<5; uint32_t b = (color & 0x001F)<<19; - // Concatenate 4 pixels into three 32-bit blocks + // Concatenate 4 pixels into three 32 bit blocks uint32_t r0 = r<<24 | b | g | r; uint32_t r1 = r0>>8 | g<<16; uint32_t r2 = r1>>8 | b<<8; @@ -530,7 +530,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (TFT_PARALLEL_8_BIT) // Now the code for ESP32 8-bit parallel +#elif defined (TFT_PARALLEL_8_BIT) // Now the code for ESP32 8 bit parallel //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -644,13 +644,10 @@ void TFT_eSPI::pushPixelsDMA(uint16_t* image, uint32_t len) // small transfers are performed using a blocking call until DMA capacity is reached. // User sketch can prevent blocking by managing pixel count and splitting into blocks // of 32768 pixels maximum. (equivalent to an area of ~320 x 100 pixels) - bool temp = _swapBytes; - _swapBytes = false; - while(len>0x4000) { // Transfer 16-bit pixels in blocks if len*2 over 65536 bytes + while(len>0x4000) { // Transfer 16 bit pixels in blocks if len*2 over 65536 bytes pushPixels(image, 0x400); len -= 0x400; image+= 0x400; // Arbitrarily send 1K pixel blocks (2Kbytes) } - _swapBytes = temp; esp_err_t ret; static spi_transaction_t trans; @@ -688,13 +685,10 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t // small transfers are performed using a blocking call until DMA capacity is reached. // User sketch can prevent blocking by managing pixel count and splitting into blocks // of 32768 pixels maximum. (equivalent to an area of ~320 x 100 pixels) - bool temp = _swapBytes; - _swapBytes = false; - while(len>0x4000) { // Transfer 16-bit pixels in blocks if len*2 over 65536 bytes + while(len>0x4000) { // Transfer 16 bit pixels in blocks if len*2 over 65536 bytes pushPixels(buffer, 0x400); len -= 0x400; buffer+= 0x400; // Arbitrarily send 1K pixel blocks (2Kbytes) } - _swapBytes = temp; esp_err_t ret; static spi_transaction_t trans; @@ -776,13 +770,10 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t // small transfers are performed using a blocking call until DMA capacity is reached. // User sketch can prevent blocking by managing pixel count and splitting into blocks // of 32768 pixels maximum. (equivalent to an area of ~320 x 100 pixels) - bool temp = _swapBytes; - _swapBytes = false; - while(len>0x4000) { // Transfer 16-bit pixels in blocks if len*2 over 65536 bytes + while(len>0x4000) { // Transfer 16 bit pixels in blocks if len*2 over 65536 bytes pushPixels(buffer, 0x400); len -= 0x400; buffer+= 0x400; // Arbitrarily send 1K pixel blocks (2Kbytes) } - _swapBytes = temp; esp_err_t ret; static spi_transaction_t trans; @@ -843,10 +834,6 @@ bool TFT_eSPI::initDMA(bool ctrl_cs) .sclk_io_num = TFT_SCLK, .quadwp_io_num = -1, .quadhd_io_num = -1, - .data4_io_num = -1, - .data5_io_num = -1, - .data6_io_num = -1, - .data7_io_num = -1, .max_transfer_sz = 65536, // ESP32 S3 max size is 64Kbytes .flags = 0, .intr_flags = 0 diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h index c1a9e101..f090f244 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP32_S3.h @@ -13,7 +13,6 @@ // Include processor specific header #include "soc/spi_reg.h" #include "driver/spi_master.h" -#include "hal/gpio_ll.h" #if !defined(CONFIG_IDF_TARGET_ESP32S3) && !defined(CONFIG_IDF_TARGET_ESP32S2) && !defined(CONFIG_IDF_TARGET_ESP32) #define CONFIG_IDF_TARGET_ESP32 @@ -93,14 +92,14 @@ SPI3_HOST = 2 // Initialise processor specific SPI functions, used by init() #define INIT_TFT_DATA_BUS // Not used -// Define a generic flag for 8-bit parallel +// Define a generic flag for 8 bit parallel #if defined (ESP32_PARALLEL) // Specific to ESP32 for backwards compatibility #if !defined (TFT_PARALLEL_8_BIT) #define TFT_PARALLEL_8_BIT // Generic parallel flag #endif #endif -// Ensure ESP32 specific flag is defined for 8-bit parallel +// Ensure ESP32 specific flag is defined for 8 bit parallel #if defined (TFT_PARALLEL_8_BIT) #if !defined (ESP32_PARALLEL) #define ESP32_PARALLEL @@ -376,7 +375,7 @@ SPI3_HOST = 2 if ( c & 0x20 ) xset_mask[c] |= (1 << (TFT_D5-MASK_OFFSET)); \ if ( c & 0x40 ) xset_mask[c] |= (1 << (TFT_D6-MASK_OFFSET)); \ if ( c & 0x80 ) xset_mask[c] |= (1 << (TFT_D7-MASK_OFFSET)); \ - } \ + } \ // Mask for the 8 data bits to set pin directions #define GPIO_DIR_MASK ((1 << (TFT_D0-MASK_OFFSET)) | (1 << (TFT_D1-MASK_OFFSET)) | (1 << (TFT_D2-MASK_OFFSET)) | (1 << (TFT_D3-MASK_OFFSET)) | (1 << (TFT_D4-MASK_OFFSET)) | (1 << (TFT_D5-MASK_OFFSET)) | (1 << (TFT_D6-MASK_OFFSET)) | (1 << (TFT_D7-MASK_OFFSET))) @@ -414,12 +413,12 @@ SPI3_HOST = 2 #if defined (SSD1963_DRIVER) - // Write 18-bit color to TFT + // Write 18 bit color to TFT #define tft_Write_16(C) GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) (((C) & 0xF800)>> 8)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) (((C) & 0x07E0)>> 3)); WR_H; \ GPIO.out_w1tc = GPIO_OUT_CLR_MASK; GPIO.out_w1ts = set_mask((uint8_t) (((C) & 0x001F)<< 3)); WR_H - // 18-bit color write with swapped bytes + // 18 bit color write with swapped bytes #define tft_Write_16S(C) Cswap = ((C) >>8 | (C) << 8); tft_Write_16(Cswap) #else @@ -433,7 +432,7 @@ SPI3_HOST = 2 #define tft_Write_16(C) GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 0)); WR_H - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 8)); WR_H #endif @@ -446,13 +445,13 @@ SPI3_HOST = 2 GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 0)); WR_H - // Write two concatenated 16-bit values to TFT + // Write two concatenated 16 bit values to TFT #define tft_Write_32C(C,D) GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((D) >> 8)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((D) >> 0)); WR_H - // Write 16-bit value twice to TFT - used by drawPixel() + // Write 16 bit value twice to TFT - used by drawPixel() #define tft_Write_32D(C) GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 8)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 0)); WR_H; \ GPIO_CLR_REG = GPIO_OUT_CLR_MASK; GPIO_SET_REG = set_mask((uint8_t) ((C) >> 8)); WR_H; \ @@ -481,12 +480,12 @@ SPI3_HOST = 2 //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to a SPI ILI948x TFT //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour // Write 8 bits to TFT #define tft_Write_8(C) spi.transfer(C) - // Convert 16-bit colour to 18-bit and write in 3 bytes + // Convert 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16(C) spi.transfer(((C) & 0xF800)>>8); \ spi.transfer(((C) & 0x07E0)>>3); \ spi.transfer(((C) & 0x001F)<<3) @@ -494,7 +493,7 @@ SPI3_HOST = 2 // Future option for transfer without wait #define tft_Write_16N(C) tft_Write_16(C) - // Convert swapped byte 16-bit colour to 18-bit and write in 3 bytes + // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16S(C) spi.transfer((C) & 0xF8); \ spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \ spi.transfer(((C) & 0x1F00)>>5) @@ -502,17 +501,17 @@ SPI3_HOST = 2 // Write 32 bits to TFT #define tft_Write_32(C) spi.write32(C) - // Write two concatenated 16-bit values to TFT + // Write two concatenated 16 bit values to TFT #define tft_Write_32C(C,D) spi.write32((C)<<16 | (D)) - // Write 16-bit value twice to TFT + // Write 16 bit value twice to TFT #define tft_Write_32D(C) spi.write32((C)<<16 | (C)) //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to an Raspberry Pi TFT //////////////////////////////////////////////////////////////////////////////////////// #elif defined (RPI_DISPLAY_TYPE) - // ESP32-S3 low level SPI writes for 8, 16 and 32-bit values + // ESP32-S3 low level SPI writes for 8, 16 and 32 bit values // to avoid the function call overhead #define TFT_WRITE_BITS(D, B) *_spi_mosi_dlen = B-1; \ *_spi_w = D; \ @@ -524,7 +523,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS((C)<<8, 16) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Future option for transfer without wait @@ -563,7 +562,7 @@ SPI3_HOST = 2 // Write 8 bits #define tft_Write_8(C) TFT_WRITE_BITS(C, 8) - // Write 16 bits with corrected endianness for 16-bit colours + // Write 16 bits with corrected endianness for 16 bit colours #define tft_Write_16(C) TFT_WRITE_BITS((C)<<8 | (C)>>8, 16) // Future option for transfer without wait diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.c b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.c index b49380a9..83939f9d 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.c +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.c @@ -109,7 +109,7 @@ void TFT_eSPI::pushSwapBytePixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -122,7 +122,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) uint8_t r = (color & 0xF800)>>8; uint8_t g = (color & 0x07E0)>>3; uint8_t b = (color & 0x001F)<<3; - // Concatenate 4 pixels into three 32-bit blocks + // Concatenate 4 pixels into three 32 bit blocks uint32_t r0 = r<<24 | b<<16 | g<<8 | r; uint32_t r1 = g<<24 | r<<16 | b<<8 | g; uint32_t r2 = b<<24 | g<<16 | r<<8 | b; diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.h b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.h index 1aacc1ee..c05d136f 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_ESP8266.h @@ -117,17 +117,17 @@ //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to a SPI ILI948x TFT //////////////////////////////////////////////////////////////////////////////////////// -#if defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#if defined (SPI_18BIT_DRIVER) // SPI 18 bit colour // Write 8 bits to TFT #define tft_Write_8(C) spi.transfer(C) - // Convert 16-bit colour to 18-bit and write in 3 bytes + // Convert 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16(C) spi.transfer(((C) & 0xF800)>>8); \ spi.transfer(((C) & 0x07E0)>>3); \ spi.transfer(((C) & 0x001F)<<3) - // Convert swapped byte 16-bit colour to 18-bit and write in 3 bytes + // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16S(C) spi.transfer((C) & 0xF8); \ spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \ spi.transfer(((C) & 0x1F00)>>5) @@ -148,7 +148,7 @@ // Command is 16 bits #define CMD_BITS 16 - // ESP8266 low level SPI writes for 8, 16 and 32-bit values + // ESP8266 low level SPI writes for 8, 16 and 32 bit values // to avoid the function call overhead #define TFT_WRITE_BITS(D, B) \ SPI1U1 = ((B-1) << SPILMOSI); \ diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.c b/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.c index 1c2287b3..14eda108 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.c +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.c @@ -172,7 +172,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -216,7 +216,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#else // Standard SPI 16-bit colour TFT +#else // Standard SPI 16 bit colour TFT //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.h b/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.h index df7981d3..8b316552 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_Generic.h @@ -3,7 +3,7 @@ //////////////////////////////////////////////////// // This is a generic driver for Arduino boards, it supports SPI interface displays -// 8-bit parallel interface to TFT is not supported for generic processors +// 8 bit parallel interface to TFT is not supported for generic processors #ifndef _TFT_eSPI_GENERICH_ #define _TFT_eSPI_GENERICH_ @@ -94,17 +94,17 @@ //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to a SPI ILI948x TFT //////////////////////////////////////////////////////////////////////////////////////// -#if defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#if defined (SPI_18BIT_DRIVER) // SPI 18 bit colour // Write 8 bits to TFT #define tft_Write_8(C) spi.transfer(C) - // Convert 16-bit colour to 18-bit and write in 3 bytes + // Convert 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16(C) spi.transfer(((C) & 0xF800)>>8); \ spi.transfer(((C) & 0x07E0)>>3); \ spi.transfer(((C) & 0x001F)<<3) - // Convert swapped byte 16-bit colour to 18-bit and write in 3 bytes + // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16S(C) spi.transfer((C) & 0xF8); \ spi.transfer(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \ spi.transfer(((C) & 0x1F00)>>5) @@ -121,7 +121,7 @@ // Macros to write commands/pixel colour data to other displays //////////////////////////////////////////////////////////////////////////////////////// #else - #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16-bit transfers + #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers #define tft_Write_8(C) spi.transfer(C); spi.transfer(C) #define tft_Write_16(C) spi.transfer((uint8_t)((C)>>8));spi.transfer((uint8_t)((C)>>0)) #define tft_Write_16S(C) spi.transfer((uint8_t)((C)>>0));spi.transfer((uint8_t)((C)>>8)) @@ -143,7 +143,7 @@ spi.transfer(0); spi.transfer((C)>>0) #else - #ifdef __AVR__ // AVR processors do not have 16-bit transfer + #ifdef __AVR__ // AVR processors do not have 16 bit transfer #define tft_Write_8(C) {SPDR=(C); while (!(SPSR&_BV(SPIF)));} #define tft_Write_16(C) tft_Write_8((uint8_t)((C)>>8));tft_Write_8((uint8_t)((C)>>0)) #define tft_Write_16S(C) tft_Write_8((uint8_t)((C)>>0));tft_Write_8((uint8_t)((C)>>8)) diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.c b/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.c index a6974271..6ca1fefe 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.c +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.c @@ -18,26 +18,26 @@ SPIClassRP2040 spi = SPIClassRP2040(SPI_X, TFT_MISO, -1, TFT_SCLK, TFT_MOSI); #endif -#else // PIO interface used (8-bit parallel or SPI) +#else // PIO interface used (8 bit parallel or SPI) #ifdef RP2040_PIO_SPI #if defined (SPI_18BIT_DRIVER) - // SPI PIO code for 18-bit colour transmit + // SPI PIO code for 18 bit colour transmit #include "pio_SPI_18bit.pio.h" #else - // SPI PIO code for 16-bit colour transmit + // SPI PIO code for 16 bit colour transmit #include "pio_SPI.pio.h" #endif #elif defined (TFT_PARALLEL_8_BIT) #if defined (SSD1963_DRIVER) - // PIO code for 8-bit parallel interface (18-bit colour) + // PIO code for 8 bit parallel interface (18 bit colour) #include "pio_8bit_parallel_18bpp.pio.h" #else - // PIO code for 8-bit parallel interface (16-bit colour) + // PIO code for 8 bit parallel interface (16 bit colour) #include "pio_8bit_parallel.pio.h" #endif #else // must be TFT_PARALLEL_16_BIT - // PIO code for 16-bit parallel interface (16-bit colour) + // PIO code for 16 bit parallel interface (16 bit colour) #include "pio_16bit_parallel.pio.h" #endif @@ -128,12 +128,24 @@ void TFT_eSPI::end_SDA_Read(void) #ifdef RP2040_PIO_SPI void pioinit(uint32_t clock_freq) { + // Find a free SM on one of the PIO's + tft_pio = pio0; + + /* + pio_sm = pio_claim_unused_sm(tft_pio, false); // false means don't panic + // Try pio1 if SM not found + if (pio_sm < 0) { + tft_pio = pio1; + pio_sm = pio_claim_unused_sm(tft_pio, true); // panic this time if no SM is free + } + */ + // Find enough free space on one of the PIO's tft_pio = pio0; if (!pio_can_add_program(tft_pio, &tft_io_program)) { tft_pio = pio1; if (!pio_can_add_program(tft_pio, &tft_io_program)) { - // Serial.println("No room for PIO program!"); + Serial.println("No room for PIO program!"); return; } } @@ -185,21 +197,29 @@ void pioinit(uint32_t clock_freq) { pio_instr_set_dc = pio_encode_set((pio_src_dest)0, 1); pio_instr_clr_dc = pio_encode_set((pio_src_dest)0, 0); } -#else // 8 or 16-bit parallel +#else // 8 or 16 bit parallel void pioinit(uint16_t clock_div, uint16_t fract_div) { + // Find a free SM on one of the PIO's + tft_pio = pio0; + pio_sm = pio_claim_unused_sm(tft_pio, false); // false means don't panic + // Try pio1 if SM not found + if (pio_sm < 0) { + tft_pio = pio1; + pio_sm = pio_claim_unused_sm(tft_pio, true); // panic this time if no SM is free + } +/* // Find enough free space on one of the PIO's tft_pio = pio0; - if (!pio_can_add_program(tft_pio, &tft_io_program)) { + if (!pio_can_add_program(tft_pio, &tft_io_program) { tft_pio = pio1; - if (!pio_can_add_program(tft_pio, &tft_io_program)) { - // Serial.println("No room for PIO program!"); + if (!pio_can_add_program(tft_pio, &tft_io_program) { + Serial.println("No room for PIO program!"); + while(1) delay(100); return; } } - - pio_sm = pio_claim_unused_sm(tft_pio, false); - +*/ #if defined (TFT_PARALLEL_8_BIT) uint8_t bits = 8; #else // must be TFT_PARALLEL_16_BIT @@ -458,7 +478,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -471,12 +491,12 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) uint16_t g = (color & 0x07E0)>>3; uint16_t b = (color & 0x001F)<<3; - // If more than 32 pixels then change to 16-bit transfers with concatenated pixels + // If more than 32 pixels then change to 16 bit transfers with concatenated pixels if (len > 32) { uint32_t rg = r<<8 | g; uint32_t br = b<<8 | r; uint32_t gb = g<<8 | b; - // Must wait before changing to 16-bit + // Must wait before changing to 16 bit while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); while ( len > 1 ) { @@ -485,7 +505,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) while (!spi_is_writable(SPI_X)){}; spi_get_hw(SPI_X)->dr = gb; len -= 2; } - // Must wait before changing back to 8-bit + // Must wait before changing back to 8 bit while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); } @@ -516,7 +536,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ } //////////////////////////////////////////////////////////////////////////////////////// -#else // Standard SPI 16-bit colour TFT +#else // Standard SPI 16 bit colour TFT //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -562,7 +582,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len){ //////////////////////////////////////////////////////////////////////////////////////// -#ifdef RP2040_DMA // DMA functions for 16-bit SPI and 8/16-bit parallel displays +#ifdef RP2040_DMA // DMA functions for 16 bit SPI and 8/16 bit parallel displays //////////////////////////////////////////////////////////////////////////////////////// /* These are created in header file: @@ -658,7 +678,7 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t } } // else, if a buffer pointer has been provided copy whole image to the buffer - else if (buffer != image) { + else if (buffer != image || _swapBytes) { memcpy(buffer, image, len*2); } diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.h b/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.h index f10058fe..08c1d140 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_RP2040.h @@ -3,7 +3,7 @@ //////////////////////////////////////////////////// // This is a generic driver for Arduino boards, it supports SPI interface displays -// 8-bit parallel interface to TFT is not supported for generic processors +// 8 bit parallel interface to TFT is not supported for generic processors #ifndef _TFT_eSPI_RP2040H_ #define _TFT_eSPI_RP2040H_ @@ -49,7 +49,7 @@ // Processor specific code used by SPI bus transaction begin/end_tft_write functions #define SET_BUS_WRITE_MODE spi_set_format(SPI_X, 8, (spi_cpol_t)(TFT_SPI_MODE >> 1), (spi_cpha_t)(TFT_SPI_MODE & 0x1), SPI_MSB_FIRST) - #define SET_BUS_READ_MODE spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST) + #define SET_BUS_READ_MODE // spi_set_format(SPI_X, 8, (spi_cpol_t)0, (spi_cpha_t)0, SPI_MSB_FIRST) #else // Processor specific code used by SPI bus transaction begin/end_tft_write functions #define SET_BUS_WRITE_MODE @@ -72,8 +72,8 @@ #if !defined (RP2040_PIO_INTERFACE) // SPI - #if defined (MHS_DISPLAY_TYPE) // High speed RPi TFT type always needs 16-bit transfers - // This swaps to 16-bit mode, used for commands so wait avoids clash with DC timing + #if defined (MHS_DISPLAY_TYPE) // High speed RPi TFT type always needs 16 bit transfers + // This swaps to 16 bit mode, used for commands so wait avoids clash with DC timing #define INIT_TFT_DATA_BUS hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS) #else // Initialise processor specific SPI functions, used by init() @@ -114,7 +114,7 @@ #define DIV_UNITS 3 // 96ns write cycle time #endif #define DIV_FRACT 0 - #else // 8-bit parallel mode default 64ns write cycle time + #else // 8 bit parallel mode default 64ns write cycle time #define DIV_UNITS 2 #define DIV_FRACT 0 // Note: Fractional values done with clock period dithering #endif @@ -166,10 +166,10 @@ tft_pio->sm[pio_sm].instr = pio_instr_clr_dc #ifndef RM68120_DRIVER - // Flush has happened before this and mode changed back to 16-bit + // Flush has happened before this and mode changed back to 16 bit #define DC_D tft_pio->sm[pio_sm].instr = pio_instr_set_dc #else - // Need to wait for stall since RM68120 commands are 16-bit + // Need to wait for stall since RM68120 commands are 16 bit #define DC_D WAIT_FOR_STALL; tft_pio->sm[pio_sm].instr = pio_instr_set_dc #endif #endif @@ -257,7 +257,7 @@ //////////////////////////////////////////////////////////////////////////////////////// #if !defined (RP2040_PIO_INTERFACE) // SPI - #if defined (SPI_18BIT_DRIVER) // SPI 18-bit colour + #if defined (SPI_18BIT_DRIVER) // SPI 18 bit colour // Write 8 bits to TFT #define tft_Write_8(C) spi_get_hw(SPI_X)->dr = (uint32_t)(C); \ @@ -267,17 +267,17 @@ #define tft_Write_8N(B) while (!spi_is_writable(SPI_X)){}; \ spi_get_hw(SPI_X)->dr = (uint8_t)(B) - // Convert 16-bit colour to 18-bit and write in 3 bytes + // Convert 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16(C) tft_Write_8N(((C) & 0xF800)>>8); \ tft_Write_8N(((C) & 0x07E0)>>3); \ tft_Write_8N(((C) & 0x001F)<<3) - // Convert 16-bit colour to 18-bit and write in 3 bytes + // Convert 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16N(C) tft_Write_8N(((C) & 0xF800)>>8); \ tft_Write_8N(((C) & 0x07E0)>>3); \ tft_Write_8N(((C) & 0x001F)<<3) - // Convert swapped byte 16-bit colour to 18-bit and write in 3 bytes + // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes #define tft_Write_16S(C) tft_Write_8N((C) & 0xF8); \ tft_Write_8N(((C) & 0xE000)>>11 | ((C) & 0x07)<<5); \ tft_Write_8N(((C) & 0x1F00)>>5) @@ -303,8 +303,8 @@ // Macros to write commands/pixel colour data to other displays //////////////////////////////////////////////////////////////////////////////////////// #else - #if defined (MHS_DISPLAY_TYPE) // High speed RPi TFT type always needs 16-bit transfers - // This swaps to 16-bit mode, used for commands so wait avoids clash with DC timing + #if defined (MHS_DISPLAY_TYPE) // High speed RPi TFT type always needs 16 bit transfers + // This swaps to 16 bit mode, used for commands so wait avoids clash with DC timing #define tft_Write_8(C) while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; \ hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); \ spi_get_hw(SPI_X)->dr = (uint32_t)((C) | ((C)<<8)); \ @@ -324,7 +324,7 @@ #define tft_Write_32D(C) spi_get_hw(SPI_X)->dr = (uint32_t)(C); spi_get_hw(SPI_X)->dr = (uint32_t)(C) - #elif defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16-bit transfers + #elif defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers #define tft_Write_8(C) spi.transfer(C); spi.transfer(C) #define tft_Write_16(C) spi.transfer((uint8_t)((C)>>8));spi.transfer((uint8_t)((C)>>0)) #define tft_Write_16N(C) spi.transfer((uint8_t)((C)>>8));spi.transfer((uint8_t)((C)>>0)) @@ -348,7 +348,7 @@ #elif defined (ILI9225_DRIVER) // Needs gaps between commands + data bytes, so use slower transfer functions - // Warning: these all end in 8-bit SPI mode! + // Warning: these all end in 8 bit SPI mode! #define tft_Write_8(C) spi.transfer(C); #define tft_Write_16(C) spi.transfer16(C) @@ -365,7 +365,7 @@ #else - // This swaps to 8-bit mode, then back to 16-bit mode + // This swaps to 8 bit mode, then back to 16 bit mode #define tft_Write_8(C) while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; \ hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); \ spi_get_hw(SPI_X)->dr = (uint32_t)(C); \ @@ -389,7 +389,7 @@ #endif // RPI_DISPLAY_TYPE #endif -#else // Parallel 8-bit or PIO SPI +#else // Parallel 8 bit or PIO SPI // Wait for the PIO to stall (SM pull request finds no data in TX FIFO) // This is used to detect when the SM is idle and hence ready for a jump instruction @@ -413,15 +413,15 @@ // Temporary - to be deleted #define GPIO_DIR_MASK 0 - #if defined (SPI_18BIT_DRIVER) || defined (SSD1963_DRIVER) // 18-bit colour (3 bytes) - // This writes 8 bits, then switches back to 16-bit mode automatically + #if defined (SPI_18BIT_DRIVER) || defined (SSD1963_DRIVER) // 18 bit colour (3 bytes) + // This writes 8 bits, then switches back to 16 bit mode automatically // Have already waited for pio stalled (last data write complete) when DC switched to command mode // The wait for stall allows DC to be changed immediately afterwards #define tft_Write_8(C) tft_pio->sm[pio_sm].instr = pio_instr_jmp8; \ TX_FIFO = (C); \ WAIT_FOR_STALL - // Used to send last byte for 32-bit macros below since PIO sends 24 bits + // Used to send last byte for 32 bit macros below since PIO sends 24 bits #define tft_Write_8L(C) WAIT_FOR_STALL; \ tft_pio->sm[pio_sm].instr = pio_instr_jmp8; \ TX_FIFO = (C) @@ -441,14 +441,14 @@ #define tft_Write_32D(C) WAIT_FOR_FIFO_FREE(2); TX_FIFO = (((C)<<8) | ((C)>>8)); tft_Write_8L(C) #else // PIO interface, SPI or parallel - // This writes 8 bits, then switches back to 16-bit mode automatically + // This writes 8 bits, then switches back to 16 bit mode automatically // Have already waited for pio stalled (last data write complete) when DC switched to command mode // The wait for stall allows DC to be changed immediately afterwards #if defined (TFT_PARALLEL_8_BIT) || defined (RP2040_PIO_SPI) #define tft_Write_8(C) tft_pio->sm[pio_sm].instr = pio_instr_jmp8; \ TX_FIFO = (C); \ WAIT_FOR_STALL - #else // For 16-bit parallel 16 bits are always sent + #else // For 16 bit parallel 16 bits are always sent #define tft_Write_8(C) TX_FIFO = (C); \ WAIT_FOR_STALL #endif diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.c b/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.c index a74dcbc2..950677c7 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.c +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.c @@ -24,6 +24,9 @@ DMA_HandleTypeDef dmaHal; #endif + // Buffer for SPI transmit byte padding and byte order manipulation + uint8_t spiBuffer[8]; + //////////////////////////////////////////////////////////////////////////////////////// #if defined (TFT_SDA_READ) && !defined (TFT_PARALLEL_8_BIT) //////////////////////////////////////////////////////////////////////////////////////// @@ -73,7 +76,7 @@ void TFT_eSPI::end_SDA_Read(void) //////////////////////////////////////////////////////////////////////////////////////// -#if defined (TFT_PARALLEL_8_BIT) // Code for STM32 8-bit parallel +#if defined (TFT_PARALLEL_8_BIT) // Code for STM32 8 bit parallel //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -283,7 +286,7 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) } //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -293,19 +296,34 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) #define BUF_SIZE 240*3 void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) { - //uint8_t col[BUF_SIZE]; + uint8_t col[BUF_SIZE]; // Always using swapped bytes is a peculiarity of this function... //color = color>>8 | color<<8; uint8_t r = (color & 0xF800)>>8; // Red uint8_t g = (color & 0x07E0)>>3; // Green uint8_t b = (color & 0x001F)<<3; // Blue - while(len--) { - TX_FIFO = (r); - TX_FIFO = (g); - TX_FIFO = (b); + if (len=BUF_SIZE/3 ) ; + // Send remaining pixels + if (len) HAL_SPI_Transmit(&spiHal, col, len*3, HAL_MAX_DELAY); //*/ } /*************************************************************************************** ** Function name: pushPixels - for STM32 and 3 byte RGB display @@ -315,29 +333,30 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) { uint16_t *data = (uint16_t*)data_in; - if(!_swapBytes) { + if(_swapBytes) { while ( len-- ) { // Split out the colours - TX_FIFO = (*data & 0xF8); // Red - TX_FIFO = (*data & 0xE000)>>11 | (*data & 0x07)<<5; // Green - TX_FIFO = (*data & 0x1F00)>>5; // Blue + spiBuffer[0] = (*data & 0xF8); // Red + spiBuffer[1] = (*data & 0xE000)>>11 | (*data & 0x07)<<5; // Green + spiBuffer[2] = (*data & 0x1F00)>>5; // Blue data++; + HAL_SPI_Transmit(&spiHal, spiBuffer, 3, HAL_MAX_DELAY); } } else { while ( len-- ) { // Split out the colours - TX_FIFO = (*data & 0xF800)>>8; // Red - TX_FIFO = (*data & 0x07E0)>>3; // Green - TX_FIFO = (*data & 0x001F)<<3; // Blue + spiBuffer[0] = (*data & 0xF800)>>8; // Red + spiBuffer[1] = (*data & 0x07E0)>>3; // Green + spiBuffer[2] = (*data & 0x001F)<<3; // Blue data++; + HAL_SPI_Transmit(&spiHal, spiBuffer, 3, HAL_MAX_DELAY); } } - SPI_BUSY_CHECK; } //////////////////////////////////////////////////////////////////////////////////////// -#else // Standard SPI 16-bit colour TFT All Tested +#else // Standard SPI 16 bit colour TFT All Tested //////////////////////////////////////////////////////////////////////////////////////// /*************************************************************************************** @@ -345,7 +364,6 @@ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) ** Description: Write a block of pixels of the same colour ***************************************************************************************/ #define BUF_SIZE 480 -/* void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) { uint16_t col[BUF_SIZE]; @@ -363,47 +381,7 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len) len -= BUF_SIZE; } while ( len>=BUF_SIZE ) ; // Send remaining pixels - if (len) HAL_SPI_Transmit(&spiHal, (uint8_t*)col, len<<1, HAL_MAX_DELAY); -} - //*/ -void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){ - // Loop unrolling improves speed dramatically graphics test 0.634s => 0.374s - while (len>31) { - #if !defined (SSD1963_DRIVER) - // 32D macro writes 16 bits twice - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - #else - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - #endif - len-=32; - } - - while (len>7) { - #if !defined (SSD1963_DRIVER) - tft_Write_32D(color); tft_Write_32D(color); - tft_Write_32D(color); tft_Write_32D(color); - #else - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); tft_Write_16(color); - #endif - len-=8; - } - - while (len--) {tft_Write_16(color);} + if (len) HAL_SPI_Transmit(&spiHal, (uint8_t*)col, len<<1, HAL_MAX_DELAY); //*/ } @@ -414,23 +392,26 @@ void TFT_eSPI::pushBlock(uint16_t color, uint32_t len){ void TFT_eSPI::pushPixels(const void* data_in, uint32_t len) { uint16_t *data = (uint16_t*)data_in; - if(_swapBytes) { - while ( len-- ) { - TX_FIFO = (uint8_t)(*data>>8); - TX_FIFO = (uint8_t)(*data); - data++; + uint16_t col[BUF_SIZE]; // Buffer for swapped bytes + while ( len>=BUF_SIZE ) { + for (uint32_t i = 0; i < BUF_SIZE; i++) { col[i] = (*data>>8) | (*data<<8); data++; } + HAL_SPI_Transmit(&spiHal, (uint8_t*)col, BUF_SIZE<<1, HAL_MAX_DELAY); + len -= BUF_SIZE; } + for (uint32_t i = 0; i < len; i++) { col[i] = (*data>>8) | (*data<<8); data++; } + HAL_SPI_Transmit(&spiHal, (uint8_t*)col, len<<1, HAL_MAX_DELAY); } else { - while ( len-- ) { - // Split out the colours - TX_FIFO = (uint8_t)(*data); - TX_FIFO = (uint8_t)(*data>>8); - data++; + // HAL byte count for transmit is only 16 bits maximum so to avoid this constraint + // transfers of small blocks are performed until HAL capacity is reached. + while(len>0x7FFF) { // Transfer 16 bit pixels in blocks if len*2 over 65534 bytes + HAL_SPI_Transmit(&spiHal, (uint8_t*)data, 0x800<<1, HAL_MAX_DELAY); + len -= 0x800; data+= 0x800; // Arbitrarily use 2KByte blocks } + // Send remaining pixels (max 65534 bytes) + HAL_SPI_Transmit(&spiHal, (uint8_t*)data, len<<1, HAL_MAX_DELAY); } - SPI_BUSY_CHECK; } //////////////////////////////////////////////////////////////////////////////////////// @@ -546,7 +527,7 @@ void TFT_eSPI::pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t // small transfers are performed using a blocking call until DMA capacity is reached. // User sketch can prevent blocking by managing pixel count and splitting into blocks // of 32767 pixels maximum. (equivalent to an area of ~320 x 100 pixels) - while(len>0x7FFF) { // Transfer 16-bit pixels in blocks if len*2 over 65534 bytes + while(len>0x7FFF) { // Transfer 16 bit pixels in blocks if len*2 over 65534 bytes HAL_SPI_Transmit(&spiHal, (uint8_t*)buffer, 0x800<<1, HAL_MAX_DELAY); len -= 0x800; buffer+= 0x800; // Arbitrarily send 1K pixel blocks (2Kbytes) } diff --git a/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.h b/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.h index 73a22cbf..82a829a6 100644 --- a/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.h +++ b/lib/TFT_eSPI/Processors/TFT_eSPI_STM32.h @@ -151,15 +151,6 @@ #define TFT_SPI_PORT 1 #endif - #if (TFT_SPI_PORT == 1) - #define SPIX SPI1 - #elif (TFT_SPI_PORT == 2) - #define SPIX SPI2 - #elif (TFT_SPI_PORT == 3) - #define SPIX SPI3 - #elif (TFT_SPI_PORT == 4) - #define SPIX SPI4 - #endif // Global define is _VARIANT_ARDUINO_STM32_, see board package stm32_def.h for specific variants #if defined (STM32F2xx) || defined (STM32F4xx) || defined (STM32F7xx) @@ -235,8 +226,8 @@ #define DC_PORT digitalPinToPort(TFT_DC) #define DC_PIN_MASK digitalPinToBitMask(TFT_DC) // Use bit set reset register - #define DC_C DC_DELAY; DC_PORT->BSRR = DC_PIN_MASK<<16 - #define DC_D DC_DELAY; DC_PORT->BSRR = DC_PIN_MASK + #define DC_C DC_PORT->BSRR = DC_PIN_MASK<<16 + #define DC_D DC_PORT->BSRR = DC_PIN_MASK #endif //////////////////////////////////////////////////////////////////////////////////////// @@ -410,7 +401,7 @@ #define D5_BSR_MASK(B) ((D5_PIN_MASK<<16)>>(((B)>> 1)&0x10)) #define D6_BSR_MASK(B) ((D6_PIN_MASK<<16)>>(((B)>> 2)&0x10)) #define D7_BSR_MASK(B) ((D7_PIN_MASK<<16)>>(((B)>> 3)&0x10)) - // Create bit set/reset mask for top byte of 16-bit value B + // Create bit set/reset mask for top byte of 16 bit value B #define D8_BSR_MASK(B) ((D0_PIN_MASK<<16)>>(((B)>> 4)&0x10)) #define D9_BSR_MASK(B) ((D1_PIN_MASK<<16)>>(((B)>> 5)&0x10)) #define D10_BSR_MASK(B) ((D2_PIN_MASK<<16)>>(((B)>> 6)&0x10)) @@ -429,7 +420,7 @@ #if defined (SSD1963_DRIVER) - // Write 18-bit color to TFT (untested) + // Write 18 bit color to TFT (untested) #define tft_Write_16(C) r6 = (((C) & 0xF800)>> 8); g6 = (((C) & 0x07E0)>> 3); b6 = (((C) & 0x001F)<< 3); \ GPIOA->BSRR = D0_BSR_MASK(r6) | D2_BSR_MASK(r6) | D7_BSR_MASK(r6); \ WR_L; \ @@ -447,7 +438,7 @@ GPIOB->BSRR = D3_BSR_MASK(b6) | D4_BSR_MASK(b6) | D5_BSR_MASK(b6) | D6_BSR_MASK(b6); \ WR_STB // Need to slow down strobe - // 18-bit color write with swapped bytes + // 18 bit color write with swapped bytes #define tft_Write_16S(C) Cswap = ((C) >>8 | (C) << 8); tft_Write_16(Cswap) #else @@ -463,7 +454,7 @@ GPIOB->BSRR = D3_BSR_MASK(C) | D4_BSR_MASK(C) | D5_BSR_MASK(C) | D6_BSR_MASK(C); \ WR_STB // Need to slow down strobe - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) GPIOA->BSRR = D0_BSR_MASK(C) | D2_BSR_MASK(C) | D7_BSR_MASK(C); \ WR_L; \ GPIOC->BSRR = D1_BSR_MASK(C); \ @@ -550,7 +541,7 @@ #define D5_BSR_MASK(B) ((D5_PIN_MASK<<16)>>(((B)>> 1)&0x10)) #define D6_BSR_MASK(B) ((D6_PIN_MASK<<16)>>(((B)>> 2)&0x10)) #define D7_BSR_MASK(B) ((D7_PIN_MASK<<16)>>(((B)>> 3)&0x10)) - // Create bit set/reset mask for top byte of 16-bit value B + // Create bit set/reset mask for top byte of 16 bit value B #define D8_BSR_MASK(B) ((D0_PIN_MASK<<16)>>(((B)>> 4)&0x10)) #define D9_BSR_MASK(B) ((D1_PIN_MASK<<16)>>(((B)>> 5)&0x10)) #define D10_BSR_MASK(B) ((D2_PIN_MASK<<16)>>(((B)>> 6)&0x10)) @@ -570,7 +561,7 @@ #if defined (SSD1963_DRIVER) - // Write 18-bit color to TFT (untested) + // Write 18 bit color to TFT (untested) #define tft_Write_16(C) r6 = (((C) & 0xF800)>> 8); g6 = (((C) & 0x07E0)>> 3); b6 = (((C) & 0x001F)<< 3); \ GPIOF->BSRR = D0_BSR_MASK(r6) | D2_BSR_MASK(r6) | D4_BSR_MASK(r6) | D7_BSR_MASK(r6); \ WR_L; \ @@ -588,7 +579,7 @@ GPIOE->BSRR = D3_BSR_MASK(b6) | D5_BSR_MASK(b6) | D6_BSR_MASK(b6); \ WR_STB // Need to slow down strobe - // 18-bit color write with swapped bytes + // 18 bit color write with swapped bytes #define tft_Write_16S(C) Cswap = ((C) >>8 | (C) << 8); tft_Write_16(Cswap) #else @@ -605,7 +596,7 @@ GPIOE->BSRR = D3_BSR_MASK(C) | D5_BSR_MASK(C) | D6_BSR_MASK(C); \ WR_STB - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) GPIOF->BSRR = D0_BSR_MASK(C) | D2_BSR_MASK(C) | D4_BSR_MASK(C) | D7_BSR_MASK(C); \ WR_L; \ GPIOD->BSRR = D1_BSR_MASK(C); \ @@ -668,7 +659,7 @@ #define D5_BSR_MASK(B) ((D5_PIN_MASK<<16)>>(((B)>> 1)&0x10)) #define D6_BSR_MASK(B) ((D6_PIN_MASK<<16)>>(((B)>> 2)&0x10)) #define D7_BSR_MASK(B) ((D7_PIN_MASK<<16)>>(((B)>> 3)&0x10)) - // Create bit set/reset mask for top byte of 16-bit value B + // Create bit set/reset mask for top byte of 16 bit value B #define D8_BSR_MASK(B) ((D0_PIN_MASK<<16)>>(((B)>> 4)&0x10)) #define D9_BSR_MASK(B) ((D1_PIN_MASK<<16)>>(((B)>> 5)&0x10)) #define D10_BSR_MASK(B) ((D2_PIN_MASK<<16)>>(((B)>> 6)&0x10)) @@ -701,7 +692,7 @@ GPIOE->BSRR = D3_BSR_MASK(C) | D4_BSR_MASK(C) | D5_BSR_MASK(C) | D6_BSR_MASK(C); \ WR_STB - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) GPIOF->BSRR = D0_BSR_MASK(C); \ GPIOG->BSRR = D2_BSR_MASK(C) | D7_BSR_MASK(C); \ WR_L; \ @@ -752,14 +743,14 @@ #if defined (SSD1963_DRIVER) - // Write 18-bit color to TFT (untested) + // Write 18 bit color to TFT (untested) #define tft_Write_16(C) r6 = (((C) & 0xF800)>> 8); g6 = (((C) & 0x07E0)>> 3); b6 = (((C) & 0x001F)<< 3); \ GPIOX->BSRR = (0x00FF0000 | (uint8_t)(r6)); WR_L; WR_STB; \ GPIOX->BSRR = (0x00FF0000 | (uint8_t)(g6)); WR_L; WR_STB; \ GPIOX->BSRR = (0x00FF0000 | (uint8_t)(b6)); WR_L; WR_STB - // 18-bit color write with swapped bytes + // 18 bit color write with swapped bytes #define tft_Write_16S(C) Cswap = ((C) >>8 | (C) << 8); tft_Write_16(Cswap) #else @@ -768,7 +759,7 @@ #define tft_Write_16(C) GPIOX->BSRR = (0x00FF0000 | (uint8_t)(C>>8)); WR_L; WR_STB; \ GPIOX->BSRR = (0x00FF0000 | (uint8_t)(C>>0)); WR_L; WR_STB - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) GPIOX->BSRR = (0x00FF0000 | (uint8_t)(C>>0)); WR_L; WR_STB; \ GPIOX->BSRR = (0x00FF0000 | (uint8_t)(C>>8)); WR_L; WR_STB #endif @@ -841,7 +832,7 @@ #define D5_BSR_MASK(B) ((D5_PIN_MASK<<16)>>(((B)>> 1)&0x10)) #define D6_BSR_MASK(B) ((D6_PIN_MASK<<16)>>(((B)>> 2)&0x10)) #define D7_BSR_MASK(B) ((D7_PIN_MASK<<16)>>(((B)>> 3)&0x10)) - // Create bit set/reset mask for top byte of 16-bit value B + // Create bit set/reset mask for top byte of 16 bit value B #define D8_BSR_MASK(B) ((D0_PIN_MASK<<16)>>(((B)>> 4)&0x10)) #define D9_BSR_MASK(B) ((D1_PIN_MASK<<16)>>(((B)>> 5)&0x10)) #define D10_BSR_MASK(B) ((D2_PIN_MASK<<16)>>(((B)>> 6)&0x10)) @@ -866,7 +857,7 @@ #if defined (SSD1963_DRIVER) - // Write 18-bit color to TFT (untested) + // Write 18 bit color to TFT (untested) #define tft_Write_16(C) r6 = (((C) & 0xF800)>> 8); g6 = (((C) & 0x07E0)>> 3); b6 = (((C) & 0x001F)<< 3); \ D0_PIN_PORT->BSRR = D8_BSR_MASK(r6); \ D1_PIN_PORT->BSRR = D9_BSR_MASK(r6); \ @@ -899,7 +890,7 @@ D7_PIN_PORT->BSRR = D7_BSR_MASK(b6); \ WR_STB - // 18-bit color write with swapped bytes + // 18 bit color write with swapped bytes #define tft_Write_16S(C) Cswap = ((C) >>8 | (C) << 8); tft_Write_16(Cswap) #else @@ -926,7 +917,7 @@ D7_PIN_PORT->BSRR = D7_BSR_MASK(C); \ WR_STB - // 16-bit write with swapped bytes + // 16 bit write with swapped bytes #define tft_Write_16S(C) D0_PIN_PORT->BSRR = D0_BSR_MASK(C); \ D1_PIN_PORT->BSRR = D1_BSR_MASK(C); \ D2_PIN_PORT->BSRR = D2_BSR_MASK(C); \ @@ -969,58 +960,66 @@ //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to a SPI ILI948x TFT //////////////////////////////////////////////////////////////////////////////////////// -#elif defined (SPI_18BIT_DRIVER) // SPI 18-bit colour +#elif defined (SPI_18BIT_DRIVER) // SPI 18 bit colour + + // Write 8 bits to TFT + #define tft_Write_8(C) \ + { spiBuffer[0] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 1, 10); } - #define SPI_TXE_CHECK while(!__HAL_SPI_GET_FLAG(&spiHal, SPI_FLAG_TXE)){} - //BSY check must allow for APB clock delay by checking TXE flag first - #define SPI_BUSY_CHECK SPI_TXE_CHECK; while( __HAL_SPI_GET_FLAG(&spiHal, SPI_FLAG_BSY)){} - #define TX_FIFO SPI_TXE_CHECK; *((__IO uint8_t *)&SPIX->DR) + // Convert 16 bit colour to 18 bit and write in 3 bytes + #define tft_Write_16(C) \ + { spiBuffer[0] = ((C) & 0xF800)>>8; spiBuffer[1] = ((C) & 0x07E0)>>3; spiBuffer[2] = ((C) & 0x001F)<<3; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 3, 10); } - //#define tft_Write_8(C) spi.transfer(C) - #define tft_Write_8(C) TX_FIFO = (C); SPI_BUSY_CHECK - #define tft_Write_16(C) TX_FIFO = ((C) & 0xF800)>>8; TX_FIFO = ((C) & 0x07E0)>>3; TX_FIFO = ((C) & 0x001F)<<3; SPI_BUSY_CHECK - #define tft_Write_16S(C) TX_FIFO = (C) & 0xF8; TX_FIFO = ((C) & 0xE000)>>11 | ((C) & 0x07)<<5; TX_FIFO = ((C) & 0x1F00)>>5; SPI_BUSY_CHECK - #define tft_Write_16N(C) TX_FIFO = ((C) & 0xF800)>>8; TX_FIFO = ((C) & 0x07E0)>>3; TX_FIFO = ((C) & 0x001F)<<3 + // Convert swapped byte 16 bit colour to 18 bit and write in 3 bytes + #define tft_Write_16S(C) \ + { spiBuffer[0] = (C) & 0xF8; spiBuffer[1] = ((C) & 0xE000)>>11 | ((C) & 0x07)<<5; spiBuffer[2] = ((C) & 0x1F00)>>5; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 3, 10); } + // Write 32 bits to TFT #define tft_Write_32(C) \ - TX_FIFO = (C)>>24; TX_FIFO = (C)>>16; \ - TX_FIFO = (C)>>8; TX_FIFO = (C); SPI_BUSY_CHECK + { spiBuffer[0] = (C)>>24; spiBuffer[1] = (C)>>16; spiBuffer[2] = (C)>>8; spiBuffer[3] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 4, 10); } + // Write two address coordinates #define tft_Write_32C(C,D) \ - TX_FIFO = (C)>>8; TX_FIFO = (C); \ - TX_FIFO = (D)>>8; TX_FIFO = (D); SPI_BUSY_CHECK + { spiBuffer[0] = (C)>>8; spiBuffer[1] = C; spiBuffer[2] = (D)>>8; spiBuffer[3] = D; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 4, 10); } + // Write same value twice #define tft_Write_32D(C) \ - TX_FIFO = (C)>>8; TX_FIFO = (C); \ - TX_FIFO = (C)>>8; TX_FIFO = (C); SPI_BUSY_CHECK + { spiBuffer[0] = spiBuffer[2] = (C)>>8; spiBuffer[1] = spiBuffer[3] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 4, 10); } //////////////////////////////////////////////////////////////////////////////////////// // Macros to write commands/pixel colour data to a SPI Raspberry Pi TFT //////////////////////////////////////////////////////////////////////////////////////// #elif defined (RPI_DISPLAY_TYPE) - #define SPI_TXE_CHECK while(!__HAL_SPI_GET_FLAG(&spiHal, SPI_FLAG_TXE)){} - //BSY check must allow for APB clock delay by checking TXE flag first - #define SPI_BUSY_CHECK SPI_TXE_CHECK; while( __HAL_SPI_GET_FLAG(&spiHal, SPI_FLAG_BSY)){} - #define TX_FIFO SPI_TXE_CHECK; *((__IO uint8_t *)&SPIX->DR) + #define tft_Write_8(C) \ + { spiBuffer[0] = 0; spiBuffer[1] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 2, 10); } - //#define tft_Write_8(C) spi.transfer(C) - #define tft_Write_8(C) TX_FIFO = (0); TX_FIFO = (C); SPI_BUSY_CHECK - #define tft_Write_16(C) TX_FIFO = (C)>>8; TX_FIFO = (C); SPI_BUSY_CHECK - #define tft_Write_16S(C) TX_FIFO = (C); TX_FIFO = (C)>>8; SPI_BUSY_CHECK - #define tft_Write_16N(C) TX_FIFO = (C)>>8; TX_FIFO = (C) + #define tft_Write_16(C) \ + { spiBuffer[0] = (C)>>8; spiBuffer[1] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 2, 10); } + + #define tft_Write_16S(C) \ + { spiBuffer[0] = C; spiBuffer[1] = (C)>>8; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 2, 10); } #define tft_Write_32(C) \ - TX_FIFO = (C)>>24; TX_FIFO = (C)>>16; \ - TX_FIFO = (C)>>8; TX_FIFO = (C); SPI_BUSY_CHECK + { spiBuffer[0] = (C)>>24; spiBuffer[1] = (C)>>16; spiBuffer[2] = (C)>>8; spiBuffer[3] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 4, 10); } #define tft_Write_32C(C,D) \ - TX_FIFO = (0); TX_FIFO = (C)>>8; TX_FIFO = (0); TX_FIFO = (C); \ - TX_FIFO = (0); TX_FIFO = (D)>>8; TX_FIFO = (0); TX_FIFO = (D); SPI_BUSY_CHECK + { spiBuffer[1] = ((C)>>8); spiBuffer[3] = (C); spiBuffer[5] = ((D)>>8); spiBuffer[7] = D; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 8, 10); } #define tft_Write_32D(C) \ - TX_FIFO = (0); TX_FIFO = (C)>>8; TX_FIFO = (0); TX_FIFO = (C); \ - TX_FIFO = (0); TX_FIFO = (C)>>8; TX_FIFO = (0); TX_FIFO = (C); SPI_BUSY_CHECK + { spiBuffer[1] = ((C)>>8); spiBuffer[3] = (C); spiBuffer[5] = ((C)>>8); spiBuffer[7] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 8, 10); } //////////////////////////////////////////////////////////////////////////////////////// // Macros for all other SPI displays @@ -1028,35 +1027,35 @@ #else - //#define DC_DELAY delayMicroseconds(1) // Premature BSY clear Hardware bug? + #if defined(ST7789_DRIVER) || defined(ST7789_2_DRIVER) + // Temporary workaround for issue #510 part 2 + #define tft_Write_8(C) spi.transfer(C) + #else + #define tft_Write_8(C) \ + { spiBuffer[0] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 1, 10); delayMicroseconds(1);} + #endif - #define SPI_TXE_CHECK while(!__HAL_SPI_GET_FLAG(&spiHal, SPI_FLAG_TXE)){} - //BSY check must allow for APB clock delay by checking TXE flag first - #define SPI_BUSY_CHECK SPI_TXE_CHECK; while( __HAL_SPI_GET_FLAG(&spiHal, SPI_FLAG_BSY)){} - #define TX_FIFO SPI_TXE_CHECK; *((__IO uint8_t *)&SPIX->DR) + #define tft_Write_16(C) \ + { spiBuffer[0] = (C)>>8; spiBuffer[1] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 2, 10); } - #define tft_Write_8(C) TX_FIFO = (C); SPI_BUSY_CHECK - #define tft_Write_16(C) TX_FIFO = (C)>>8; TX_FIFO = (C); SPI_BUSY_CHECK - #define tft_Write_16S(C) TX_FIFO = (C); TX_FIFO = (C)>>8; SPI_BUSY_CHECK - #define tft_Write_16N(C) TX_FIFO = (C)>>8; TX_FIFO = (C) + #define tft_Write_16S(C) \ + { spiBuffer[0] = C; spiBuffer[1] = (C)>>8; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 2, 10); } #define tft_Write_32(C) \ - TX_FIFO = (C)>>24; TX_FIFO = (C)>>16; \ - tft_Write_16((uint16_t) ((C)>>0)) + { spiBuffer[0] = (C)>>24; spiBuffer[1] = (C)>>16; spiBuffer[2] = (C)>>8; spiBuffer[3] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 4, 10); } #define tft_Write_32C(C,D) \ - TX_FIFO = (C)>>8; TX_FIFO = (C); \ - tft_Write_16((uint16_t) (D)) + { spiBuffer[0] = (C)>>8; spiBuffer[1] = C; spiBuffer[2] = (D)>>8; spiBuffer[3] = D; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 4, 10); } #define tft_Write_32D(C) \ - TX_FIFO = (C)>>8; TX_FIFO = (C); \ - tft_Write_16((uint16_t) (C)) - -#endif + { spiBuffer[0] = spiBuffer[2] = (C)>>8; spiBuffer[1] = spiBuffer[3] = C; \ + HAL_SPI_Transmit(&spiHal, spiBuffer, 4, 10); } -#ifndef DC_DELAY - //#define DC_DELAY delayMicroseconds(1) // Premature BSY clear hardware bug? - #define DC_DELAY #endif #ifndef tft_Write_16N diff --git a/lib/TFT_eSPI/Processors/pio_16bit_parallel.pio.h b/lib/TFT_eSPI/Processors/pio_16bit_parallel.pio.h index 655c1b13..c972add9 100644 --- a/lib/TFT_eSPI/Processors/pio_16bit_parallel.pio.h +++ b/lib/TFT_eSPI/Processors/pio_16bit_parallel.pio.h @@ -1,6 +1,6 @@ // -------------------------------------------------- // // This file is autogenerated by pioasm; do not edit! // -// 16-bit parallel // +// 16 bit parallel // // -------------------------------------------------- // #pragma once diff --git a/lib/TFT_eSPI/Processors/pio_8bit_parallel.pio.h b/lib/TFT_eSPI/Processors/pio_8bit_parallel.pio.h index b5d6a8cd..aab04e82 100644 --- a/lib/TFT_eSPI/Processors/pio_8bit_parallel.pio.h +++ b/lib/TFT_eSPI/Processors/pio_8bit_parallel.pio.h @@ -1,6 +1,6 @@ // -------------------------------------------------- // // This file is autogenerated by pioasm; do not edit! // -// 8-bit parallel // +// 8 bit parallel // // -------------------------------------------------- // #pragma once diff --git a/lib/TFT_eSPI/Processors/pio_SPI.pio.h b/lib/TFT_eSPI/Processors/pio_SPI.pio.h index 0848529b..277eeefc 100644 --- a/lib/TFT_eSPI/Processors/pio_SPI.pio.h +++ b/lib/TFT_eSPI/Processors/pio_SPI.pio.h @@ -1,6 +1,6 @@ // -------------------------------------------------- // // This file is autogenerated by pioasm; do not edit! // -// 8 + 16-bit SPI - no auto colour conversion // +// 8 + 16 bit SPI - no auto colour conversion // // -------------------------------------------------- // #pragma once diff --git a/lib/TFT_eSPI/Processors/pio_SPI_18bit.pio.h b/lib/TFT_eSPI/Processors/pio_SPI_18bit.pio.h index 09bbfeb0..e769073e 100644 --- a/lib/TFT_eSPI/Processors/pio_SPI_18bit.pio.h +++ b/lib/TFT_eSPI/Processors/pio_SPI_18bit.pio.h @@ -1,6 +1,6 @@ // -------------------------------------------------- // // This file is autogenerated by pioasm; do not edit! // -// 8 + 18-bit SPI - no auto colour conversion // +// 8 + 18 bit SPI - no auto colour conversion // // -------------------------------------------------- // #pragma once diff --git a/lib/TFT_eSPI/README.md b/lib/TFT_eSPI/README.md index 0c0c15bc..1a4b675e 100644 --- a/lib/TFT_eSPI/README.md +++ b/lib/TFT_eSPI/README.md @@ -1,10 +1,6 @@ A ["Discussions"](https://github.com/Bodmer/TFT_eSPI/discussions) facility has been added for Q&A etc. Use the ["Issues"](https://github.com/Bodmer/TFT_eSPI/issues) tab only for problems with the library. Thanks! # News -1. The Create_font Processing sketch has been updated to automatically create a complete C header file. The automatic opening of the font folder can also be disabled within the Processing sketch. (Thanks to Pierre-Loup Martin). - -2. New board setup files have been added for the Seeed XIAO with round display, LilyGo T-Embed S3, LilyGo_T_QT_Pro_S3, ESP32 S3 Box and ESP32_S3_Box_Lite. The "RPi" interface style boards are now supported with the ESP32 S3. - -3. New functions have been added to draw smooth (antialiased) arcs, circles, and rounded rectangle outlines. New sketches are provided in the "Smooth Graphics" examples folder. Arcs can be drawn with or without anti-aliasing (which will then render faster). The arc ends can be straight or rounded. The arc drawing algorithm uses an optimised fixed point sqrt() function to improve performance on processors that do not have a hardware Floating Point Unit (e.g. RP2040). Here are two demo images, on the left smooth (anti-aliased) arcs with rounded ends, the image to the right is the same resolution (grabbed from the same 240x240 TFT) with the smoothing diasbled (no anti-aliasing): +1. New functions have been added to draw smooth (antialiased) arcs, circles, and rounded rectangle outlines. New sketches are provided in the "Smooth Graphics" examples folder. Arcs can be drawn with or without anti-aliasing (which will then render faster). The arc ends can be straight or rounded. The arc drawing algorithm uses an optimised fixed point sqrt() function to improve performance on processors that do not have a hardware Floating Point Unit (e.g. RP2040). Here are two demo images, on the left smooth (anti-aliased) arcs with rounded ends, the image to the right is the same resolution (grabbed from the same 240x240 TFT) with the smoothing diasbled (no anti-aliasing): ![arcs](https://github.com/Bodmer/Github-images/blob/main/aa_arc_240x240.png) ![pixelated_arcs](https://github.com/Bodmer/Github-images/blob/main/no_aa_arc_240x240.png) @@ -12,17 +8,17 @@ A ["Discussions"](https://github.com/Bodmer/TFT_eSPI/discussions) facility has b ![arcs](https://github.com/Bodmer/Github-images/blob/main/xarc_meters_320x240.png) -4. An excellent new compatible library is available which can render TrueType fonts on a TFT screen (or into a sprite). This has been developed by [takkaO](https://github.com/takkaO/OpenFontRender). The library provides access to compact font files, with fully scaleable anti-aliased glyphs. Left, middle and right justified text can also be printed to the screen. I have added TFT_eSPI specific examples to the OpenFontRender library and tested on RP2040 and ESP32 processors, the ESP8266 does not have sufficient RAM due to the glyph render complexity. Here is a demo screen where a single 12kbyte font file binary was used to render fully anti-aliased glyphs of gradually increasing size on a 320x480 TFT screen: +2. An excellent new compatible library is available which can render TrueType fonts on a TFT screen (or into a sprite). This has been developed by [takkaO](https://github.com/takkaO/OpenFontRender), I have created a branch with some bug fixes [here](https://github.com/Bodmer/OpenFontRender). The library provides access to compact font files, with fully scaleable anti-aliased glyphs. Left, middle and right justified text can also be printed to the screen. I have added TFT_eSPI specific examples to the OpenFontRender library and tested on RP2040 and ESP32 processors, the ESP8266 does not have sufficient RAM due to the glyph render complexity. Here is a demo screen where a single 12kbyte font file binary was used to render fully anti-aliased glyphs of gradually increasing size on a 320x480 TFT screen: ![ttf_font_demo](https://i.imgur.com/bKkilIb.png) -5. New GUI examples have been added for sliders, buttons, graphs and meters. These examples require a new support library here: +3. New GUI examples have been added for sliders, buttons, graphs and meters. These examples require a new support library here: [TFT_eWidget](https://github.com/Bodmer/TFT_eWidget) -6. Support has been added in v2.4.70 for the RP2040 with 16-bit parallel displays. This has been tested and the screen update performance is very good (4ms to clear 320 x 480 screen with HC8357C). The use of the RP2040 PIO makes it easy to change the write cycle timing for different displays. DMA with 16-bit transfers is also supported. +4. Support has been added in v2.4.70 for the RP2040 with 16 bit parallel displays. This has been tested and the screen update performance is very good (4ms to clear 320 x 480 screen with HC8357C). The use of the RP2040 PIO makes it easy to change the write cycle timing for different displays. DMA with 16 bit transfers is also supported. -7. Support for the ESP32-S2, ESP32-S3 and ESP32-C3 has been added (DMA only on ESP32 S3 at the moment). Tested with v2.0.3 RC1 of the ESP32 board package. Example setups: +5. Support for the ESP32-S2, ESP32-S3 and ESP32-C3 has been added (DMA only on ESP32 S3 at the moment). Tested with v2.0.3 RC1 of the ESP32 board package. Example setups: [Setup70_ESP32_S2_ILI9341.h](https://github.com/Bodmer/TFT_eSPI/blob/master/User_Setups/Setup70_ESP32_S2_ILI9341.h) @@ -32,18 +28,18 @@ A ["Discussions"](https://github.com/Bodmer/TFT_eSPI/discussions) facility has b [Setup70d_ILI9488_S3_Parallel.h](https://github.com/Bodmer/TFT_eSPI/blob/master/User_Setups/Setup70d_ILI9488_S3_Parallel.h) -8. Smooth fonts can now be rendered direct to the TFT with very little flicker for quickly changing values. This is achieved by a line-by-line and block-by-block update of the glyph area without drawing pixels twice. This is a "breaking" change for some sketches because a new true/false parameter is needed to render the background. The default is false if the parameter is missing, Examples: +6. Smooth fonts can now be rendered direct to the TFT with very little flicker for quickly changing values. This is achieved by a line-by-line and block-by-block update of the glyph area without drawing pixels twice. This is a "breaking" change for some sketches because a new true/false parameter is needed to render the background. The default is false if the parameter is missing, Examples: tft.setTextColor(TFT_WHITE, TFT_BLUE, true); spr.setTextColor(TFT_BLUE, TFT_BLACK, true); Note: background rendering for Smooth fonts is also now available when using the print stream e.g. with: tft.println("Hello World"); -9. New anti-aliased graphics functions to draw lines, wedge shaped lines, circles and rounded rectangles. [Examples are included](https://github.com/Bodmer/TFT_eSPI/tree/master/examples/Smooth%20Graphics). Examples have also been added to [display PNG compressed images](https://github.com/Bodmer/TFT_eSPI/tree/master/examples/PNG%20Images) (note: requires ~40kbytes RAM). +7. New anti-aliased graphics functions to draw lines, wedge shaped lines, circles and rounded rectangles. [Examples are included](https://github.com/Bodmer/TFT_eSPI/tree/master/examples/Smooth%20Graphics). Examples have also been added to [display PNG compressed images](https://github.com/Bodmer/TFT_eSPI/tree/master/examples/PNG%20Images) (note: requires ~40kbytes RAM). -10. Users of PowerPoint experienced with running macros may be interested in the [pptm sketch generator here](https://github.com/Bodmer/PowerPoint_to_sketch), this converts graphics and tables drawn in PowerPoint slides into an Arduino sketch that renders the graphics on a 480x320 TFT. This is based on VB macros [created by Kris Kasprzak here](https://github.com/KrisKasprzak/Powerpoint-ILI9341_t3). +8. Users of PowerPoint experienced with running macros may be interested in the [pptm sketch generator here](https://github.com/Bodmer/PowerPoint_to_sketch), this converts graphics and tables drawn in PowerPoint slides into an Arduino sketch that renders the graphics on a 480x320 TFT. This is based on VB macros [created by Kris Kasprzak here](https://github.com/KrisKasprzak/Powerpoint-ILI9341_t3). -11. The library contains two new functions for rectangles filled with a horizontal or vertical coloured gradient: +9. The library contains two new functions for rectangles filled with a horizontal or vertical coloured gradient: tft.fillRectHGradient(x, y, w, h, color1, color2); @@ -51,14 +47,19 @@ Note: background rendering for Smooth fonts is also now available when using the ![Gradient](https://i.imgur.com/atR0DmP.png) -12. The RP2040 8-bit parallel interface uses the PIO. The PIO now manages the "setWindow" and "block fill" actions, releasing the processor for other tasks when areas of the screen are being filled with a colour. The PIO can optionally be used for SPI interface displays if #define RP2040_PIO_SPI is put in the setup file. Touch screens and pixel read operations are not supported when the PIO interface is used. +10. The RP2040 8 bit parallel interface uses the PIO. The PIO now manages the "setWindow" and "block fill" actions, releasing the processor for other tasks when areas of the screen are being filled with a colour. The PIO can optionally be used for SPI interface displays if #define RP2040_PIO_SPI is put in the setup file. Touch screens and pixel read operations are not supported when the PIO interface is used. The RP2040 PIO features only work with [Earle Philhower's board package](https://github.com/earlephilhower/arduino-pico), NOT the Arduino Mbed version. The use of PIO for SPI allows the RP2040 to be over-clocked (up to 250MHz works on my boards) in Earle's board package whilst still maintaining high SPI clock rates. +11. DMA can now be used with the Raspberry Pi Pico (RP2040) when used with 8/16 bit parallel and 16 bit colour SPI displays. See "Bouncy_Circles" sketch. + + ["Bouncing circles"](https://www.youtube.com/watch?v=njFXIzCTQ_Q&lc=UgymaUIwOIuihvYh-Qt4AaABAg) + + # TFT_eSPI -A feature rich Arduino IDE compatible graphics and fonts library for 32-bit processors. The library is targeted at 32-bit processors, it has been performance optimised for RP2040, STM32, ESP8266 and ESP32 types, other 32-bit processors may be used but will use the slower generic Arduino interface calls. The library can be loaded using the Arduino IDE's Library Manager. Direct Memory Access (DMA) can be used with the ESP32, RP2040 and STM32 processors with SPI interface displays to improve rendering performance. DMA with a parallel interface (8 and 16-bit) is only supported with the RP2040. +A feature rich Arduino IDE compatible graphics and fonts library for 32 bit processors. The library is targeted at 32 bit processors, it has been performance optimised for RP2040, STM32, ESP8266 and ESP32 types, other 32 bit processors may be used but will use the slower generic Arduino interface calls. The library can be loaded using the Arduino IDE's Library Manager. Direct Memory Access (DMA) can be used with the ESP32, RP2040 and STM32 processors with SPI interface displays to improve rendering performance. DMA with a parallel interface (8 and 16 bit) is only supported with the RP2040. The updates for the ESP32 S2/C3/S3 means that the library requires the ESP32 Arduino board package 2.x.x or later. @@ -75,7 +76,7 @@ Optimised drivers have been tested with the following processors: The library supports the following interface types for these processors: -| Processor | 4 wire SPI | 8-bit parallel | 16-bit parallel | DMA support | +| Processor | 4 wire SPI | 8 bit parallel | 16 bit parallel | DMA support | |-----------| :---: | :---: | :---: | :---: | | RP2040 | Yes | Yes | Yes | Yes (all) | | ESP32 | Yes | Yes | No | Yes (SPI only) | @@ -88,9 +89,7 @@ The library supports the following interface types for these processors: For other (generic) processors only SPI interface displays are supported and the slower Arduino SPI library functions are used by the library. Higher clock speed processors such as used for the Teensy 3.x and 4.x boards will still provide a very good performance with the generic Arduino SPI functions. -4 wire SPI means the display must have SPI interface comaptible signals and a "Data/Command" control signal, this signal line is sometimes labelled DC, RS or A0. - -Due to lack of GPIO pins the 8-bit parallel interface is NOT supported on the ESP8266. 8-bit parallel interface TFTs (e.g. UNO format mcufriend shields) can used with the STM32Fxxx Nucleo 64/144 range or the UNO format ESP32 (see below for ESP32). +Due to lack of GPIO pins the 8 bit parallel interface is NOT supported on the ESP8266. 8 bit parallel interface TFTs (e.g. UNO format mcufriend shields) can used with the STM32 Nucleo 64/144 range or the UNO format ESP32 (see below for ESP32). Support for the XPT2046 touch screen controller is built into the library and can be used with SPI interface displays. Third party touch support libraries are also available when using a display parallel interface. @@ -104,8 +103,8 @@ Displays using the following controllers are supported: * ILI9481 (DMA not supported with SPI) * ILI9486 (DMA not supported with SPI) * ILI9488 (DMA not supported with SPI) -* HX8357B (16-bit parallel tested with RP2040) -* HX8357C (16-bit parallel tested with RP2040) +* HX8357B (16 bit parallel tested with RP2040) +* HX8357C (16 bit parallel tested with RP2040) * HX8357D * R61581 * RM68120 (support files added but untested) @@ -119,25 +118,27 @@ Displays using the following controllers are supported: ILI9341 and ST7796 SPI based displays are recommended as starting point for experimenting with this library. -The library supports some TFT displays designed for the Raspberry Pi (RPi) that are based on a ILI9486 or ST7796 driver chip with a 480 x 320 pixel screen. The ILI9486 RPi display must be of the Waveshare design and use a 16-bit serial interface based on the 74HC04, 74HC4040 and 2 x 74HC4094 logic chips. Note that due to design variations between these displays not all RPi displays will work with this library, so purchasing a RPi display of these types solely for use with this library is NOT recommended. +The library supports some TFT displays designed for the Raspberry Pi (RPi) that are based on a ILI9486 or ST7796 driver chip with a 480 x 320 pixel screen. The ILI9486 RPi display must be of the Waveshare design and use a 16 bit serial interface based on the 74HC04, 74HC4040 and 2 x 74HC4094 logic chips. Note that due to design variations between these displays not all RPi displays will work with this library, so purchasing a RPi display of these types solely for use with this library is NOT recommended. A "good" RPi display is the [MHS-4.0 inch Display-B type ST7796](http://www.lcdwiki.com/MHS-4.0inch_Display-B) which provides good performance. This has a dedicated controller and can be clocked at up to 80MHz with the ESP32 (125MHz with overclocked RP2040, 55MHz with STM32 and 40MHz with ESP8266). The [MHS-3.5 inch RPi ILI9486](http://www.lcdwiki.com/MHS-3.5inch_RPi_Display) based display is also supported, however the MHS ILI9341 based display of the same type does NOT work with this library. Some displays permit the internal TFT screen RAM to be read, a few of the examples use this feature. The TFT_Screen_Capture example allows full screens to be captured and sent to a PC, this is handy to create program documentation. +The library supports Waveshare 2 and 3 colour ePaper displays using full frame buffers. This addition is relatively immature and thus only one example has been provided. + The library includes a "Sprite" class, this enables flicker free updates of complex graphics. Direct writes to the TFT with graphics functions are still available, so existing sketches do not need to be changed. # Sprites -A Sprite is notionally an invisible graphics screen that is kept in the processors RAM. Graphics can be drawn into the Sprite just as they can be drawn directly to the screen. Once the Sprite is completed it can be plotted onto the screen in any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. Sprites by default use 16-bit colours, the bit depth can be set to 8 bits (256 colours) , or 1 bit (any 2 colours) to reduce the RAM needed. On an ESP8266 the largest 16-bit colour Sprite that can be created is about 160x128 pixels, this consumes 40Kbytes of RAM. On an ESP32 the workspace RAM is more limited than the datasheet implies so a 16-bit colour Sprite is limited to about 200x200 pixels (~80Kbytes), an 8-bit sprite to 320x240 pixels (~76kbytes). A 1 bit per pixel Sprite requires only 9600 bytes for a full 320 x 240 screen buffer, this is ideal for supporting use with 2 colour bitmap fonts. +A Sprite is notionally an invisible graphics screen that is kept in the processors RAM. Graphics can be drawn into the Sprite just as they can be drawn directly to the screen. Once the Sprite is completed it can be plotted onto the screen in any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. Sprites by default use 16 bit colours, the bit depth can be set to 8 bits (256 colours) , or 1 bit (any 2 colours) to reduce the RAM needed. On an ESP8266 the largest 16 bit colour Sprite that can be created is about 160x128 pixels, this consumes 40Kbytes of RAM. On an ESP32 the workspace RAM is more limited than the datasheet implies so a 16 bit colour Sprite is limited to about 200x200 pixels (~80Kbytes), an 8 bit sprite to 320x240 pixels (~76kbytes). A 1 bit per pixel Sprite requires only 9600 bytes for a full 320 x 240 screen buffer, this is ideal for supporting use with 2 colour bitmap fonts. -One or more sprites can be created, a sprite can be any pixel width and height, limited only by available RAM. The RAM needed for a 16-bit colour depth Sprite is (2 x width x height) bytes, for a Sprite with 8-bit colour depth the RAM needed is (width x height) bytes. Sprites can be created and deleted dynamically as needed in the sketch, this means RAM can be freed up after the Sprite has been plotted on the screen, more RAM intensive WiFi based code can then be run and normal graphics operations still work. +One or more sprites can be created, a sprite can be any pixel width and height, limited only by available RAM. The RAM needed for a 16 bit colour depth Sprite is (2 x width x height) bytes, for a Sprite with 8 bit colour depth the RAM needed is (width x height) bytes. Sprites can be created and deleted dynamically as needed in the sketch, this means RAM can be freed up after the Sprite has been plotted on the screen, more RAM intensive WiFi based code can then be run and normal graphics operations still work. Drawing graphics into a sprite is very fast, for those familiar with the Adafruit "graphicstest" example, this whole test completes in 18ms in a 160x128 sprite. Examples of sprite use can be found in the "examples/Sprite" folder. Sprites can be plotted to the TFT with one colour being specified as "transparent", see Transparent_Sprite_Demo example. -If an ESP32 board has SPIRAM (i.e. PSRAM) fitted then Sprites will use the PSRAM memory and large full screen buffer Sprites can be created. Full screen Sprites take longer to render (~45ms for a 320 x 240 16-bit Sprite), so bear that in mind. +If an ESP32 board has SPIRAM (i.e. PSRAM) fitted then Sprites will use the PSRAM memory and large full screen buffer Sprites can be created. Full screen Sprites take longer to render (~45ms for a 320 x 240 16 bit Sprite), so bear that in mind. The "Animated_dial" example shows how dials can be created using a rotated Sprite for the needle. To run this example the TFT interface must support reading from the screen RAM (not all do). The dial rim and scale is a jpeg image, created using a paint program. @@ -157,7 +158,7 @@ The library supports SPI overlap on the ESP8266 so the TFT screen can share MOSI # Fonts -The library contains proportional fonts, different sizes can be enabled/disabled at compile time to optimise the use of FLASH memory. Anti-aliased (smooth) font files in vlw format stored in SPIFFS are supported. Any 16-bit Unicode character can be included and rendered, this means many language specific characters can be rendered to the screen. +The library contains proportional fonts, different sizes can be enabled/disabled at compile time to optimise the use of FLASH memory. Anti-aliased (smooth) font files in vlw format stored in SPIFFS are supported. Any 16 bit Unicode character can be included and rendered, this means many language specific characters can be rendered to the screen. The library is based on the Adafruit GFX and Adafruit driver libraries and the aim is to retain compatibility. Significant additions have been made to the library to boost the speed for the different processors (it is typically 3 to 10 times faster) and to add new features. The new graphics functions include different size proportional fonts and formatting features. There are lots of example sketches to demonstrate the different features and included functions. @@ -166,7 +167,7 @@ Configuration of the library font selections, pins used to interface with the TF # Anti-aliased Fonts -Anti-aliased (smooth) font files in "vlw" format are generated by the free [Processing IDE](https://processing.org/) using a sketch included in the library Tools folder. This sketch with the Processing IDE can be used to generate font files from your computer's font set or any TrueType (.ttf) font, the font file can include **any** combination of 16-bit Unicode characters. This means Greek, Japanese and any other UCS-2 glyphs can be used. Character arrays and Strings in UTF-8 format are supported. +Anti-aliased (smooth) font files in "vlw" format are generated by the free [Processing IDE](https://processing.org/) using a sketch included in the library Tools folder. This sketch with the Processing IDE can be used to generate font files from your computer's font set or any TrueType (.ttf) font, the font file can include **any** combination of 16 bit Unicode characters. This means Greek, Japanese and any other UCS-2 glyphs can be used. Character arrays and Strings in UTF-8 format are supported. The .vlw files must be uploaded to the processors FLASH filing system (SPIFFS, LittleFS or SD card) for use. Alternatively the .vlw files can be converted to C arrays (see "Smooth Font -> FLASH_Array" examples) and stored directly in FLASH as part of the compile process. The array based approach is convenient, provides performance improvements and is suitable where: either use of a filing system is undesirable, or the processor type (e.g. STM32) does not support a FLASH based filing system. @@ -188,9 +189,9 @@ Anti-aliased fonts can also be drawn over a gradient background with a callback Anti-aliased fonts cannot be scaled with setTextSize so you need to create a font for each size you need. See examples. -# 8-bit parallel support +# 8 bit parallel support -The common 8-bit "Mcufriend" shields are supported for the STM Nucleo 64/144 boards and ESP32 UNO style board. The STM32 "Blue/Black Pill" boards can also be used with 8-bit parallel displays. +The common 8 bit "Mcufriend" shields are supported for the STM Nucleo 64/144 boards and ESP32 UNO style board. The STM32 "Blue/Black Pill" boards can also be used with 8 bit parallel displays. The ESP32 board I have been using for testing has the following pinout: diff --git a/lib/TFT_eSPI/README.txt b/lib/TFT_eSPI/README.txt index 45eb4fbd..0b738e6e 100644 --- a/lib/TFT_eSPI/README.txt +++ b/lib/TFT_eSPI/README.txt @@ -3,5 +3,5 @@ and the TFT chip driver library. It supports the ESP8266, ESP32, STM32 and RP2040 processors with performance optimised code. Other Arduino IDE compatible boards are also supported but the library then uses generic functions which will be slower. The library uses -32-bit variables extensively so this will affect performance on 8 -and 16-bit processors. +32 bit variables extensively so this will affect performance on 8 +and 16 bit processors. diff --git a/lib/TFT_eSPI/TFT_Drivers/GC9A01_Defines.h b/lib/TFT_eSPI/TFT_Drivers/GC9A01_Defines.h index 4cb10952..b6c56483 100644 --- a/lib/TFT_eSPI/TFT_Drivers/GC9A01_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/GC9A01_Defines.h @@ -4,7 +4,7 @@ #define TFT_WIDTH 240 #endif #ifndef TFT_HEIGHT - #define TFT_HEIGHT 240 + #define TFT_HEIGHT 320 #endif // Delay between some initialisation commands @@ -14,15 +14,6 @@ #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_SLPIN 0x10 -#define TFT_SLPOUT 0x11 - -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -38,3 +29,6 @@ #define TFT_MAD_BGR 0x08 #define TFT_MAD_MH 0x04 #define TFT_MAD_RGB 0x00 + +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 diff --git a/lib/TFT_eSPI/TFT_Drivers/HX8357B_Init.h b/lib/TFT_eSPI/TFT_Drivers/HX8357B_Init.h index 7ca937c1..b5f8c2ea 100644 --- a/lib/TFT_eSPI/TFT_Drivers/HX8357B_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/HX8357B_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the HX8357B driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format diff --git a/lib/TFT_eSPI/TFT_Drivers/HX8357C_Init.h b/lib/TFT_eSPI/TFT_Drivers/HX8357C_Init.h index 807cadbe..35cde5c3 100644 --- a/lib/TFT_eSPI/TFT_Drivers/HX8357C_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/HX8357C_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the HX8357C driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format diff --git a/lib/TFT_eSPI/TFT_Drivers/HX8357D_Init.h b/lib/TFT_eSPI/TFT_Drivers/HX8357D_Init.h index 0e49d3f7..9b5f05a9 100644 --- a/lib/TFT_eSPI/TFT_Drivers/HX8357D_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/HX8357D_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the HX8357D driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format @@ -94,7 +94,7 @@ writedata(0x01); writecommand(HX8357_COLMOD); - writedata(0x55); // 16-bit + writedata(0x55); // 16 bit writecommand(HX8357_MADCTL); writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_COLOR_ORDER); diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9163_Defines.h b/lib/TFT_eSPI/TFT_Drivers/ILI9163_Defines.h index f1c63396..4abaa1dc 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9163_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9163_Defines.h @@ -42,12 +42,6 @@ #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -63,3 +57,6 @@ #define TFT_MAD_BGR 0x08 #define TFT_MAD_MH 0x04 #define TFT_MAD_RGB 0x00 + +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9341_Defines.h b/lib/TFT_eSPI/TFT_Drivers/ILI9341_Defines.h index 94ce1ef5..70e17624 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9341_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9341_Defines.h @@ -40,12 +40,6 @@ #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -72,6 +66,10 @@ #define TFT_MAD_COLOR_ORDER TFT_MAD_BGR #endif +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 + + // All ILI9341 specific commands some are used by init() #define ILI9341_NOP 0x00 #define ILI9341_SWRESET 0x01 diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h b/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h index 05a5dda3..05a703ef 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9341_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the ILI9341 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9481_Init.h b/lib/TFT_eSPI/TFT_Drivers/ILI9481_Init.h index a5f19b89..3ac9965b 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9481_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9481_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the ILI9481 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format @@ -64,9 +64,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) @@ -153,9 +153,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) @@ -242,9 +242,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) @@ -327,9 +327,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) @@ -415,9 +415,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) @@ -527,9 +527,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) @@ -605,9 +605,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) @@ -700,9 +700,9 @@ writecommand(0x3a); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9486_Defines.h b/lib/TFT_eSPI/TFT_Drivers/ILI9486_Defines.h index fcec0b86..31996e41 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9486_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9486_Defines.h @@ -39,12 +39,6 @@ #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -62,3 +56,6 @@ #define TFT_MAD_SS 0x02 #define TFT_MAD_GS 0x01 #define TFT_MAD_RGB 0x00 + +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9486_Init.h b/lib/TFT_eSPI/TFT_Drivers/ILI9486_Init.h index db0f7aa3..e96c4e43 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9486_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9486_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the ILI9486 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format @@ -16,9 +16,9 @@ writecommand(0x3A); #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour interface + writedata(0x55); // 16 bit colour interface #else - writedata(0x66); // 18-bit colour interface + writedata(0x66); // 18 bit colour interface #endif writecommand(0xC0); // 1100.0000 Power Control 1 diff --git a/lib/TFT_eSPI/TFT_Drivers/ILI9488_Init.h b/lib/TFT_eSPI/TFT_Drivers/ILI9488_Init.h index c1b20b6d..d487187d 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ILI9488_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/ILI9488_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the ILI9488 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format @@ -59,9 +59,9 @@ writecommand(0x3A); // Pixel Interface Format #if defined (TFT_PARALLEL_8_BIT) || defined (TFT_PARALLEL_16_BIT) || defined (RPI_DISPLAY_TYPE) - writedata(0x55); // 16-bit colour for parallel + writedata(0x55); // 16 bit colour for parallel #else - writedata(0x66); // 18-bit colour for SPI + writedata(0x66); // 18 bit colour for SPI #endif writecommand(0xB0); // Interface Mode Control diff --git a/lib/TFT_eSPI/TFT_Drivers/R61581_Init.h b/lib/TFT_eSPI/TFT_Drivers/R61581_Init.h index 1e9adeee..929d680a 100644 --- a/lib/TFT_eSPI/TFT_Drivers/R61581_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/R61581_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the R61581 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format diff --git a/lib/TFT_eSPI/TFT_Drivers/RM68120_Defines.h b/lib/TFT_eSPI/TFT_Drivers/RM68120_Defines.h index 50ed5a47..627e4670 100644 --- a/lib/TFT_eSPI/TFT_Drivers/RM68120_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/RM68120_Defines.h @@ -17,12 +17,6 @@ #define TFT_NOP 0x0000 #define TFT_SWRST 0x0100 -#define TFT_INVOFF 0x2000 -#define TFT_INVON 0x2100 - -#define TFT_DISPOFF 0x2800 -#define TFT_DISPON 0x2900 - #define TFT_CASET 0x2A00 #define TFT_PASET 0x2B00 #define TFT_RAMWR 0x2C00 @@ -50,3 +44,6 @@ #else #define TFT_MAD_COLOR_ORDER TFT_MAD_RGB #endif + +#define TFT_INVOFF 0x2000 +#define TFT_INVON 0x2100 diff --git a/lib/TFT_eSPI/TFT_Drivers/RM68140_Init.h b/lib/TFT_eSPI/TFT_Drivers/RM68140_Init.h index cc447195..e5df339f 100644 --- a/lib/TFT_eSPI/TFT_Drivers/RM68140_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/RM68140_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the RM68140 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format diff --git a/lib/TFT_eSPI/TFT_Drivers/S6D02A1_Defines.h b/lib/TFT_eSPI/TFT_Drivers/S6D02A1_Defines.h index 7806eb8b..96aea859 100644 --- a/lib/TFT_eSPI/TFT_Drivers/S6D02A1_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/S6D02A1_Defines.h @@ -35,12 +35,6 @@ #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -56,3 +50,6 @@ #define TFT_MAD_BGR 0x08 #define TFT_MAD_MH 0x04 #define TFT_MAD_RGB 0x00 + +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 diff --git a/lib/TFT_eSPI/TFT_Drivers/SSD1963_Defines.h b/lib/TFT_eSPI/TFT_Drivers/SSD1963_Defines.h index f3ca7d4a..1c3e9132 100644 --- a/lib/TFT_eSPI/TFT_Drivers/SSD1963_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/SSD1963_Defines.h @@ -26,12 +26,6 @@ #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -57,3 +51,6 @@ #else #define TFT_MAD_COLOR_ORDER TFT_MAD_BGR #endif + +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 diff --git a/lib/TFT_eSPI/TFT_Drivers/SSD1963_Init.h b/lib/TFT_eSPI/TFT_Drivers/SSD1963_Init.h index 87d4ee6e..f7859617 100644 --- a/lib/TFT_eSPI/TFT_Drivers/SSD1963_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/SSD1963_Init.h @@ -62,7 +62,7 @@ writedata(0x21 | TFT_MAD_COLOR_ORDER); writecommand(0xF0); //pixel data interface - writedata(0x00); //8-bit bus + writedata(0x00); //8 bit bus delay(1); @@ -166,7 +166,7 @@ writedata(0x21 | TFT_MAD_COLOR_ORDER); writecommand(0xF0); //pixel data interface - writedata(0x00); //8-bit bus + writedata(0x00); //8 bit bus delay(1); @@ -270,7 +270,7 @@ writedata(0x21 | TFT_MAD_COLOR_ORDER); // -- Set rotation writecommand(0xF0); //pixel data interface - writedata(0x00); //8-bit bus + writedata(0x00); //8 bit bus delay(10); @@ -371,7 +371,7 @@ //writedata(0x0050); //16-bit/pixel writecommand(0xF0); //pixel data interface - writedata(0x00); //000 = 8-bit bus, 011 = 16-bit, 110 = 9-bit + writedata(0x00); //000 = 8 bit bus, 011 = 16 bit, 110 = 9 bit writecommand(0xBC); writedata(0x40); //contrast value diff --git a/lib/TFT_eSPI/TFT_Drivers/ST7735_Defines.h b/lib/TFT_eSPI/TFT_Drivers/ST7735_Defines.h index b02ee15e..1c5c12f6 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ST7735_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/ST7735_Defines.h @@ -95,12 +95,6 @@ #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -131,6 +125,9 @@ #endif #endif +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 + // ST7735 specific commands used in init #define ST7735_NOP 0x00 #define ST7735_SWRESET 0x01 diff --git a/lib/TFT_eSPI/TFT_Drivers/ST7789_Init.h b/lib/TFT_eSPI/TFT_Drivers/ST7789_Init.h index b2ed7ebf..9fa2918b 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ST7789_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/ST7789_Init.h @@ -1,13 +1,12 @@ // This is the command sequence that initialises the ST7789 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format #ifndef INIT_SEQUENCE_3 { - fillScreen(TFT_RED); writecommand(ST7789_SLPOUT); // Sleep out delay(120); @@ -25,7 +24,7 @@ writecommand(ST7789_RAMCTRL); writedata(0x00); - writedata(0xE0); // 5 to 6-bit conversion: r0 = r5, b0 = b5 + writedata(0xE0); // 5 to 6 bit conversion: r0 = r5, b0 = b5 writecommand(ST7789_COLMOD); writedata(0x55); @@ -144,7 +143,7 @@ // writecommand(ST7789_RAMCTRL); // writedata(0x00); - // writedata(0xE0); // 5 to 6-bit conversion: r0 = r5, b0 = b5 + // writedata(0xE0); // 5 to 6 bit conversion: r0 = r5, b0 = b5 writecommand(ST7789_COLMOD); writedata(0x55); diff --git a/lib/TFT_eSPI/TFT_Drivers/ST7796_Defines.h b/lib/TFT_eSPI/TFT_Drivers/ST7796_Defines.h index d7009ac8..ab75c485 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ST7796_Defines.h +++ b/lib/TFT_eSPI/TFT_Drivers/ST7796_Defines.h @@ -1,23 +1,12 @@ // Change the width and height if required (defined in portrait mode) // or use the constructor to over-ride defaults -#ifndef TFT_WIDTH #define TFT_WIDTH 320 -#endif - -#ifndef TFT_HEIGHT #define TFT_HEIGHT 480 -#endif // Generic commands used by TFT_eSPI.cpp #define TFT_NOP 0x00 #define TFT_SWRST 0x01 -#define TFT_INVOFF 0x20 -#define TFT_INVON 0x21 - -#define TFT_DISPOFF 0x28 -#define TFT_DISPON 0x29 - #define TFT_CASET 0x2A #define TFT_PASET 0x2B #define TFT_RAMWR 0x2C @@ -42,6 +31,10 @@ #define TFT_MAD_COLOR_ORDER TFT_MAD_BGR #endif +#define TFT_INVOFF 0x20 +#define TFT_INVON 0x21 + + // ST7796 specific commands #define ST7796_NOP 0x00 #define ST7796_SWRESET 0x01 diff --git a/lib/TFT_eSPI/TFT_Drivers/ST7796_Init.h b/lib/TFT_eSPI/TFT_Drivers/ST7796_Init.h index c1d84210..a112815e 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ST7796_Init.h +++ b/lib/TFT_eSPI/TFT_Drivers/ST7796_Init.h @@ -1,7 +1,7 @@ // This is the command sequence that initialises the ST7796 driver // -// This setup information uses simple 8-bit SPI writecommand() and writedata() functions +// This setup information uses simple 8 bit SPI writecommand() and writedata() functions // // See ST7735_Setup.h file for an alternative format diff --git a/lib/TFT_eSPI/TFT_Drivers/ST7796_Rotation.h b/lib/TFT_eSPI/TFT_Drivers/ST7796_Rotation.h index c5f6ad69..4788538a 100644 --- a/lib/TFT_eSPI/TFT_Drivers/ST7796_Rotation.h +++ b/lib/TFT_eSPI/TFT_Drivers/ST7796_Rotation.h @@ -9,49 +9,21 @@ writedata(TFT_MAD_MX | TFT_MAD_COLOR_ORDER); _width = _init_width; _height = _init_height; -#ifdef CGRAM_OFFSET - if (_init_width == 222) - { - colstart = 49; - rowstart = 0; - } -#endif break; case 1: writedata(TFT_MAD_MV | TFT_MAD_COLOR_ORDER); _width = _init_height; _height = _init_width; -#ifdef CGRAM_OFFSET - if (_init_width == 222) - { - colstart = 0; - rowstart = 49; - } -#endif break; case 2: writedata(TFT_MAD_MY | TFT_MAD_COLOR_ORDER); _width = _init_width; _height = _init_height; -#ifdef CGRAM_OFFSET - if (_init_width == 222) - { - colstart = 49; - rowstart = 0; - } -#endif break; case 3: writedata(TFT_MAD_MX | TFT_MAD_MY | TFT_MAD_MV | TFT_MAD_COLOR_ORDER); _width = _init_height; _height = _init_width; -#ifdef CGRAM_OFFSET - if (_init_width == 222) - { - colstart = 0; - rowstart = 49; - } -#endif break; // These next rotations are for bottom up BMP drawing case 4: diff --git a/lib/TFT_eSPI/TFT_config.h b/lib/TFT_eSPI/TFT_config.h index a5c7090e..2607e248 100644 --- a/lib/TFT_eSPI/TFT_config.h +++ b/lib/TFT_eSPI/TFT_config.h @@ -23,14 +23,6 @@ #include "sdkconfig.h" -/*************************************************************************************** -** Others -***************************************************************************************/ - -#ifdef CONFIG_DISABLE_WARNINGS - #define DISABLE_ALL_LIBRARY_WARNINGS -#endif - /*************************************************************************************** ** TFT_eSPI Configuration defines ***************************************************************************************/ @@ -145,9 +137,7 @@ #endif #if CONFIG_TFT_RST == -1 - #if !defined(DISABLE_ALL_LIBRARY_WARNINGS) - #warning "Invalid Reset pin. Check TFT_eSPI configuration" - #endif + #error "Invalid Reset pin. Check TFT_eSPI configuration" #else #define TFT_RST CONFIG_TFT_RST #endif @@ -317,4 +307,12 @@ #define SPI_TOUCH_FREQUENCY CONFIG_SPI_TOUCH_FREQUENCY #endif +/*************************************************************************************** +** Section 6: Others +***************************************************************************************/ + +#ifdef CONFIG_DISABLE_WARNINGS + #define DISABLE_ALL_LIBRARY_WARNINGS +#endif + #endif // TFT_CONFIG_H diff --git a/lib/TFT_eSPI/TFT_eSPI.cpp b/lib/TFT_eSPI/TFT_eSPI.cpp index d537faeb..67bd87ea 100644 --- a/lib/TFT_eSPI/TFT_eSPI.cpp +++ b/lib/TFT_eSPI/TFT_eSPI.cpp @@ -1,5 +1,5 @@ /*************************************************** - Arduino TFT graphics library targeted at 32-bit + Arduino TFT graphics library targeted at 32 bit processors such as ESP32, ESP8266 and STM32. This is a stand-alone library that contains the @@ -17,9 +17,9 @@ #if defined (ESP32) #if defined(CONFIG_IDF_TARGET_ESP32S3) - #include "Processors/TFT_eSPI_ESP32_S3.c" // Tested with SPI and 8-bit parallel + #include "Processors/TFT_eSPI_ESP32_S3.c" // Tested with SPI and 8 bit parallel #elif defined(CONFIG_IDF_TARGET_ESP32C3) - #include "Processors/TFT_eSPI_ESP32_C3.c" // Tested with SPI (8-bit parallel will probably work too!) + #include "Processors/TFT_eSPI_ESP32_C3.c" // Tested with SPI (8 bit parallel will probably work too!) #else #include "Processors/TFT_eSPI_ESP32.c" #endif @@ -467,7 +467,7 @@ TFT_eSPI::TFT_eSPI(int16_t w, int16_t h) lockTransaction = false; // start/endWrite lock flag to allow sketch to keep SPI bus access open _booted = true; // Default attributes - _cp437 = false; // Legacy GLCD font bug fix disabled by default + _cp437 = true; // Legacy GLCD font bug fix _utf8 = true; // UTF8 decoding enabled #if defined (FONT_FS_AVAILABLE) && defined (SMOOTH_FONT) @@ -942,7 +942,7 @@ void TFT_eSPI::commandList (const uint8_t *addr) { writecommand(pgm_read_byte(addr++)); // Read, issue command numArgs = pgm_read_byte(addr++); // Number of args to follow - ms = numArgs & TFT_INIT_DELAY; // If high bit set, delay follows args + ms = numArgs & TFT_INIT_DELAY; // If hibit set, delay follows args numArgs &= ~TFT_INIT_DELAY; // Mask out delay bit while (numArgs--) // For each argument... @@ -974,7 +974,7 @@ void TFT_eSPI::spiwrite(uint8_t c) /*************************************************************************************** ** Function name: writecommand -** Description: Send an 8-bit command to the TFT +** Description: Send an 8 bit command to the TFT ***************************************************************************************/ #ifndef RM68120_DRIVER void TFT_eSPI::writecommand(uint8_t c) @@ -1038,7 +1038,7 @@ void TFT_eSPI::writeRegister16(uint16_t c, uint16_t d) /*************************************************************************************** ** Function name: writedata -** Description: Send a 8-bit data value to the TFT +** Description: Send a 8 bit data value to the TFT ***************************************************************************************/ void TFT_eSPI::writedata(uint8_t d) { @@ -1056,7 +1056,7 @@ void TFT_eSPI::writedata(uint8_t d) /*************************************************************************************** ** Function name: readcommand8 -** Description: Read a 8-bit data value from an indexed command register +** Description: Read a 8 bit data value from an indexed command register ***************************************************************************************/ uint8_t TFT_eSPI::readcommand8(uint8_t cmd_function, uint8_t index) { @@ -1099,7 +1099,7 @@ uint8_t TFT_eSPI::readcommand8(uint8_t cmd_function, uint8_t index) /*************************************************************************************** ** Function name: readcommand16 -** Description: Read a 16-bit data value from an indexed command register +** Description: Read a 16 bit data value from an indexed command register ***************************************************************************************/ uint16_t TFT_eSPI::readcommand16(uint8_t cmd_function, uint8_t index) { @@ -1114,7 +1114,7 @@ uint16_t TFT_eSPI::readcommand16(uint8_t cmd_function, uint8_t index) /*************************************************************************************** ** Function name: readcommand32 -** Description: Read a 32-bit data value from an indexed command register +** Description: Read a 32 bit data value from an indexed command register ***************************************************************************************/ uint32_t TFT_eSPI::readcommand32(uint8_t cmd_function, uint8_t index) { @@ -1157,12 +1157,12 @@ uint16_t TFT_eSPI::readPixel(int32_t x0, int32_t y0) readByte(); #endif - // Fetch the 16-bit BRG pixel + // Fetch the 16 bit BRG pixel //uint16_t rgb = (readByte() << 8) | readByte(); #if defined (ILI9341_DRIVER) || defined(ILI9341_2_DRIVER) || defined (ILI9488_DRIVER) || defined (SSD1963_DRIVER)// Read 3 bytes - // Read window pixel 24-bit RGB values and fill in LS bits + // Read window pixel 24 bit RGB values and fill in LS bits uint16_t rgb = ((readByte() & 0xF8) << 8) | ((readByte() & 0xFC) << 3) | (readByte() >> 3); if (!inTransaction) { CS_H; } // CS_H can be multi-statement @@ -1172,9 +1172,9 @@ uint16_t TFT_eSPI::readPixel(int32_t x0, int32_t y0) return rgb; - #else // ILI9481 or ILI9486 16-bit read + #else // ILI9481 or ILI9486 16 bit read - // Fetch the 16-bit BRG pixel + // Fetch the 16 bit BRG pixel uint16_t bgr = (readByte() << 8) | readByte(); if (!inTransaction) { CS_H; } // CS_H can be multi-statement @@ -1289,12 +1289,12 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da // Dummy read to throw away don't care value readByte(); - // Fetch the 24-bit RGB value + // Fetch the 24 bit RGB value while (dh--) { int32_t lw = dw; uint16_t* line = data; while (lw--) { - // Assemble the RGB 16-bit colour + // Assemble the RGB 16 bit colour uint16_t rgb = ((readByte() & 0xF8) << 8) | ((readByte() & 0xFC) << 3) | (readByte() >> 3); // Swapped byte order for compatibility with pushRect() @@ -1304,7 +1304,7 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da } #elif defined (SSD1963_DRIVER) - // Fetch the 18-bit BRG pixels + // Fetch the 18 bit BRG pixels while (dh--) { int32_t lw = dw; uint16_t* line = data; @@ -1324,16 +1324,16 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da // Dummy read to throw away don't care value readByte(); - // Fetch the 16-bit BRG pixels + // Fetch the 16 bit BRG pixels while (dh--) { int32_t lw = dw; uint16_t* line = data; while (lw--) { #if defined (ILI9486_DRIVER) || defined (ST7796_DRIVER) - // Read the RGB 16-bit colour + // Read the RGB 16 bit colour *line++ = readByte() | (readByte() << 8); #else - // Read the BRG 16-bit colour + // Read the BRG 16 bit colour uint16_t bgr = (readByte() << 8) | readByte(); // Swap Red and Blue (could check MADCTL setting to see if this is needed) uint16_t rgb = (bgr>>11) | (bgr<<11) | (bgr & 0x7E0); @@ -1372,7 +1372,7 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da // Dummy read to throw away don't care value tft_Read_8(); - // Read window pixel 24-bit RGB values + // Read window pixel 24 bit RGB values while (dh--) { int32_t lw = dw; uint16_t* line = data; @@ -1443,7 +1443,7 @@ void TFT_eSPI::pushRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da /*************************************************************************************** ** Function name: pushImage -** Description: plot 16-bit colour sprite or image onto TFT +** Description: plot 16 bit colour sprite or image onto TFT ***************************************************************************************/ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) { @@ -1473,7 +1473,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d /*************************************************************************************** ** Function name: pushImage -** Description: plot 16-bit sprite or image with 1 colour being transparent +** Description: plot 16 bit sprite or image with 1 colour being transparent ***************************************************************************************/ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data, uint16_t transp) { @@ -1532,11 +1532,11 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d /*************************************************************************************** ** Function name: pushImage - for FLASH (PROGMEM) stored images -** Description: plot 16-bit image +** Description: plot 16 bit image ***************************************************************************************/ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data) { - // Requires 32-bit aligned access, so use PROGMEM 16-bit word functions + // Requires 32 bit aligned access, so use PROGMEM 16 bit word functions PI_CLIP; begin_tft_write(); @@ -1562,11 +1562,11 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1 /*************************************************************************************** ** Function name: pushImage - for FLASH (PROGMEM) stored images -** Description: plot 16-bit image with 1 colour being transparent +** Description: plot 16 bit image with 1 colour being transparent ***************************************************************************************/ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint16_t *data, uint16_t transp) { - // Requires 32-bit aligned access, so use PROGMEM 16-bit word functions + // Requires 32 bit aligned access, so use PROGMEM 16 bit word functions PI_CLIP; begin_tft_write(); @@ -1618,7 +1618,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1 /*************************************************************************************** ** Function name: pushImage -** Description: plot 8-bit or 4-bit or 1 bit image or sprite using a line buffer +** Description: plot 8 bit or 4 bit or 1 bit image or sprite using a line buffer ***************************************************************************************/ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data, bool bpp8, uint16_t *cmap) { @@ -1637,7 +1637,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8 { _swapBytes = false; - uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5-bit colour lookup table + uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table _lastColor = -1; // Set to illegal value @@ -1751,7 +1751,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8 /*************************************************************************************** ** Function name: pushImage -** Description: plot 8-bit or 4-bit or 1 bit image or sprite using a line buffer +** Description: plot 8 bit or 4 bit or 1 bit image or sprite using a line buffer ***************************************************************************************/ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data, bool bpp8, uint16_t *cmap) { @@ -1770,7 +1770,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da { _swapBytes = false; - uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5-bit colour lookup table + uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table _lastColor = -1; // Set to illegal value @@ -1903,7 +1903,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da data += dx + dy * w; - uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5-bit colour lookup table + uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table _lastColor = -1; // Set to illegal value @@ -2089,7 +2089,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da /*************************************************************************************** ** Function name: pushMaskedImage -** Description: Render a 16-bit colour image to TFT with a 1bpp mask +** Description: Render a 16 bit colour image to TFT with a 1bpp mask ***************************************************************************************/ // Can be used with a 16bpp sprite and a 1bpp sprite for the mask void TFT_eSPI::pushMaskedImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *img, uint8_t *mask) @@ -2097,7 +2097,7 @@ void TFT_eSPI::pushMaskedImage(int32_t x, int32_t y, int32_t w, int32_t h, uint1 if (_vpOoB || w < 1 || h < 1) return; // To simplify mask handling the window clipping is done by the pushImage function - // Each mask image line assumed to be padded to an integer number of bytes & padding bits are 0 + // Each mask image line assumed to be padded to and integer number of bytes & padding bits are 0 begin_tft_write(); inTransaction = true; @@ -2158,7 +2158,6 @@ void TFT_eSPI::pushMaskedImage(int32_t x, int32_t y, int32_t w, int32_t h, uint1 xp += clearCount; clearCount = 0; pushImage(x + xp, y, setCount, 1, iptr + xp); // pushImage handles clipping - if (mptr >= eptr) break; xp += setCount; } } while (setCount || mptr < eptr); @@ -2175,7 +2174,7 @@ void TFT_eSPI::pushMaskedImage(int32_t x, int32_t y, int32_t w, int32_t h, uint1 /*************************************************************************************** ** Function name: setSwapBytes -** Description: Used by 16-bit pushImage() to swap byte order in colours +** Description: Used by 16 bit pushImage() to swap byte order in colours ***************************************************************************************/ void TFT_eSPI::setSwapBytes(bool swap) { @@ -2231,7 +2230,7 @@ void TFT_eSPI::readRectRGB(int32_t x0, int32_t y0, int32_t w, int32_t h, uint8_ // Dummy read to throw away don't care value tft_Read_8(); - // Read window pixel 24-bit RGB values, buffer must be set in sketch to 3 * w * h + // Read window pixel 24 bit RGB values, buffer must be set in sketch to 3 * w * h uint32_t len = w * h; while (len--) { @@ -2353,7 +2352,7 @@ void TFT_eSPI::drawCircleHelper( int32_t x0, int32_t y0, int32_t rr, uint8_t cor //begin_tft_write(); // Sprite class can use this function, avoiding begin_tft_write() inTransaction = true; - do + while (xe < rr--) { while (f < 0) { ++xe; @@ -2399,8 +2398,7 @@ void TFT_eSPI::drawCircleHelper( int32_t x0, int32_t y0, int32_t rr, uint8_t cor } } xs = xe; - } while (xe < rr--); - + } inTransaction = lockTransaction; end_tft_write(); // Does nothing if Sprite class uses this function } @@ -2867,7 +2865,7 @@ void TFT_eSPI::setCursor(int16_t x, int16_t y) ***************************************************************************************/ void TFT_eSPI::setCursor(int16_t x, int16_t y, uint8_t font) { - setTextFont(font); + textfont = font; cursor_x = x; cursor_y = y; } @@ -3140,7 +3138,7 @@ int16_t TFT_eSPI::textWidth(const char *string, uint8_t font) /*************************************************************************************** ** Function name: fontsLoaded -** Description: return an encoded 16-bit value showing the fonts loaded +** Description: return an encoded 16 bit value showing the fonts loaded ***************************************************************************************/ // Returns a value showing which fonts are loaded (bit N set = Font N loaded) uint16_t TFT_eSPI::fontsLoaded(void) @@ -3153,10 +3151,8 @@ uint16_t TFT_eSPI::fontsLoaded(void) ** Function name: fontHeight ** Description: return the height of a font (yAdvance for free fonts) ***************************************************************************************/ -int16_t TFT_eSPI::fontHeight(uint8_t font) +int16_t TFT_eSPI::fontHeight(int16_t font) { - if (font > 8) return 0; - #ifdef SMOOTH_FONT if(fontLoaded) return gFont.yAdvance; #endif @@ -3191,6 +3187,8 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32 #endif //>>>>>>>>>>>>>>>>>> + if (c > 255) return; + int32_t xd = x + _xDatum; int32_t yd = y + _yDatum; @@ -3200,9 +3198,6 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32 ((yd + 8 * size - 1) < _vpY)) // Clip top return; - if (c > 255) return; - if (!_cp437 && c > 175) c++; - bool fillbg = (bg != color); bool clip = xd < _vpX || xd + 6 * textsize >= _vpW || yd < _vpY || yd + 8 * textsize >= _vpH; @@ -3213,7 +3208,7 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32 setWindow(xd, yd, xd+5, yd+7); - for (int8_t i = 0; i < 5; i++ ) column[i] = pgm_read_byte(&font[0] + (c * 5) + i); + for (int8_t i = 0; i < 5; i++ ) column[i] = pgm_read_byte(font + (c * 5) + i); column[5] = 0; for (int8_t j = 0; j < 8; j++) { @@ -3236,7 +3231,7 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32 if (i == 5) line = 0x0; else - line = pgm_read_byte(&font[0] + (c * 5) + i); + line = pgm_read_byte(font + (c * 5) + i); if (size == 1 && !fillbg) { // default size for (int8_t j = 0; j < 8; j++) { @@ -3386,7 +3381,7 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) DC_D; // Temporary solution is to include the RP2040 code here #if (defined(ARDUINO_ARCH_RP2040) || defined (ARDUINO_ARCH_MBED)) && !defined(RP2040_PIO_INTERFACE) - // For ILI9225 and RP2040 the slower Arduino SPI transfer calls were used, so need to swap back to 16-bit mode + // For ILI9225 and RP2040 the slower Arduino SPI transfer calls were used, so need to swap back to 16 bit mode while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); #endif @@ -3417,12 +3412,12 @@ void TFT_eSPI::setWindow(int32_t x0, int32_t y0, int32_t x1, int32_t y1) // Temporary solution is to include the RP2040 optimised code here #if (defined(ARDUINO_ARCH_RP2040) || defined (ARDUINO_ARCH_MBED)) #if !defined(RP2040_PIO_INTERFACE) - // Use hardware SPI port, this code does not swap from 8 to 16-bit + // Use hardware SPI port, this code does not swap from 8 to 16 bit // to avoid the spi_set_format() call overhead while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; DC_C; #if !defined (SPI_18BIT_DRIVER) - #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16-bit transfers + #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); #else hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); @@ -3520,7 +3515,7 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h) // Temporary solution is to include the RP2040 optimised code here #if (defined(ARDUINO_ARCH_RP2040) || defined (ARDUINO_ARCH_MBED)) && !defined(RP2040_PIO_INTERFACE) - // Use hardware SPI port, this code does not swap from 8 to 16-bit + // Use hardware SPI port, this code does not swap from 8 to 16 bit // to avoid the spi_set_format() call overhead while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; DC_C; @@ -3643,7 +3638,7 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) #if !defined(RP2040_PIO_INTERFACE) while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; - #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16-bit transfers + #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers hw_write_masked(&spi_get_hw(SPI_X)->cr0, (16 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); #else hw_write_masked(&spi_get_hw(SPI_X)->cr0, (8 - 1) << SPI_SSPCR0_DSS_LSB, SPI_SSPCR0_DSS_BITS); @@ -3678,7 +3673,7 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) DC_C; spi_get_hw(SPI_X)->dr = (uint32_t)TFT_RAMWR; - #if defined (SPI_18BIT_DRIVER) // SPI 18-bit colour + #if defined (SPI_18BIT_DRIVER) // SPI 18 bit colour uint8_t r = (color & 0xF800)>>8; uint8_t g = (color & 0x07E0)>>3; uint8_t b = (color & 0x001F)<<3; @@ -3688,7 +3683,7 @@ void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color) #else while (spi_get_hw(SPI_X)->sr & SPI_SSPSR_BSY_BITS) {}; DC_D; - #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16-bit transfers + #if defined (RPI_DISPLAY_TYPE) // RPi TFT type always needs 16 bit transfers spi_get_hw(SPI_X)->dr = (uint32_t)color; #else spi_get_hw(SPI_X)->dr = (uint32_t)color>>8; @@ -3845,7 +3840,7 @@ void TFT_eSPI::writeColor(uint16_t color, uint32_t len) /*************************************************************************************** ** Function name: pushColors -** Description: push an array of pixels for 16-bit raw image drawing +** Description: push an array of pixels for 16 bit raw image drawing ***************************************************************************************/ // Assumed that setAddrWindow() has previously been called // len is number of bytes, not pixels @@ -3879,7 +3874,7 @@ void TFT_eSPI::pushColors(uint16_t *data, uint32_t len, bool swap) ** Function name: drawLine ** Description: draw a line between 2 arbitrary points ***************************************************************************************/ -// Bresenham's algorithm - thx Wikipedia - speed enhanced by Bodmer to use +// Bresenham's algorithm - thx wikipedia - speed enhanced by Bodmer to use // an efficient FastH/V Line draw routine for line segments of 2 pixels or more void TFT_eSPI::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color) { @@ -3959,7 +3954,7 @@ constexpr float deg2rad = 3.14159265359/180.0; uint16_t TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color, uint8_t alpha, uint32_t bg_color) { if (bg_color == 0x00FFFFFF) bg_color = readPixel(x, y); - color = fastBlend(alpha, color, bg_color); + color = alphaBlend(alpha, color, bg_color); drawPixel(x, y, color); return color; } @@ -4108,7 +4103,7 @@ void TFT_eSPI::drawArc(int32_t x, int32_t y, int32_t r, int32_t ir, float fabssin = fabsf(sinf(startAngle * deg2rad)); // U16.16 slope of arc start - uint32_t slope = (fabscos/(fabssin + minDivisor)) * (float)(1UL<<16); + uint32_t slope = (fabscos/(fabssin + minDivisor)) * (float)(1<<16); // Update slope table, add slope for arc start if (startAngle <= 90) { @@ -4132,7 +4127,7 @@ void TFT_eSPI::drawArc(int32_t x, int32_t y, int32_t r, int32_t ir, fabssin = fabsf(sinf(endAngle * deg2rad)); // U16.16 slope of arc end - slope = (uint32_t)((fabscos/(fabssin + minDivisor)) * (float)(1UL<<16)); + slope = (uint32_t)((fabscos/(fabssin + minDivisor)) * (float)(1<<16)); // Work out which quadrants will need to be drawn and add slope for arc end if (endAngle <= 90) { @@ -4200,7 +4195,7 @@ void TFT_eSPI::drawArc(int32_t x, int32_t y, int32_t r, int32_t ir, if (alpha < 16) continue; // Skip low alpha pixels // If background is read it must be done in each quadrant - uint16_t pcol = fastBlend(alpha, fg_color, bg_color); + uint16_t pcol = alphaBlend(alpha, fg_color, bg_color); // Check if an AA pixels need to be drawn slope = ((r - cy)<<16)/(r - cx); if (slope <= startSlope[0] && slope >= endSlope[0]) // BL @@ -4371,7 +4366,7 @@ void TFT_eSPI::drawSmoothRoundRect(int32_t x, int32_t y, int32_t r, int32_t ir, if (alpha < 16) continue; // Skip low alpha pixels // If background is read it must be done in each quadrant - TODO - uint16_t pcol = fastBlend(alpha, fg_color, bg_color); + uint16_t pcol = alphaBlend(alpha, fg_color, bg_color); if (quadrants & 0x8) drawPixel(x + cx - r, y - cy + r + h, pcol); // BL if (quadrants & 0x1) drawPixel(x + cx - r, y + cy - r, pcol); // TL if (quadrants & 0x2) drawPixel(x - cx + r + w, y + cy - r, pcol); // TR @@ -4527,12 +4522,11 @@ void TFT_eSPI::drawWedgeLine(float ax, float ay, float bx, float by, float ar, f bg = readPixel(xp, yp); swin = true; } #ifdef GC9A01_DRIVER - uint16_t pcol = fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg); + uint16_t pcol = alphaBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg); drawPixel(xp, yp, pcol); - swin = swin; #else if (swin) { setWindow(xp, yp, x1, yp); swin = false; } - pushColor(fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg)); + pushColor(alphaBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg)); #endif } } @@ -4565,12 +4559,11 @@ void TFT_eSPI::drawWedgeLine(float ax, float ay, float bx, float by, float ar, f bg = readPixel(xp, yp); swin = true; } #ifdef GC9A01_DRIVER - uint16_t pcol = fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg); + uint16_t pcol = alphaBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg); drawPixel(xp, yp, pcol); - swin = swin; #else if (swin) { setWindow(xp, yp, x1, yp); swin = false; } - pushColor(fastBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg)); + pushColor(alphaBlend((uint8_t)(alpha * PixelAlphaGain), fg_color, bg)); #endif } } @@ -4724,7 +4717,7 @@ void TFT_eSPI::fillRectVGradient(int16_t x, int16_t y, int16_t w, int16_t h, uin while (h--) { drawFastHLine(x, y++, w, color); alpha += delta; - color = fastBlend((uint8_t)alpha, color1, color2); + color = alphaBlend((uint8_t)alpha, color1, color2); } end_nin_write(); @@ -4762,7 +4755,7 @@ void TFT_eSPI::fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uin while (w--) { drawFastVLine(x++, y, h, color); alpha += delta; - color = fastBlend((uint8_t)alpha, color1, color2); + color = alphaBlend((uint8_t)alpha, color1, color2); } end_nin_write(); @@ -4771,7 +4764,7 @@ void TFT_eSPI::fillRectHGradient(int16_t x, int16_t y, int16_t w, int16_t h, uin /*************************************************************************************** ** Function name: color565 -** Description: convert three 8-bit RGB levels to a 16-bit colour value +** Description: convert three 8 bit RGB levels to a 16 bit colour value ***************************************************************************************/ uint16_t TFT_eSPI::color565(uint8_t r, uint8_t g, uint8_t b) { @@ -4781,7 +4774,7 @@ uint16_t TFT_eSPI::color565(uint8_t r, uint8_t g, uint8_t b) /*************************************************************************************** ** Function name: color16to8 -** Description: convert 16-bit colour to an 8-bit 332 RGB colour value +** Description: convert 16 bit colour to an 8 bit 332 RGB colour value ***************************************************************************************/ uint8_t TFT_eSPI::color16to8(uint16_t c) { @@ -4791,11 +4784,11 @@ uint8_t TFT_eSPI::color16to8(uint16_t c) /*************************************************************************************** ** Function name: color8to16 -** Description: convert 8-bit colour to a 16-bit 565 colour value +** Description: convert 8 bit colour to a 16 bit 565 colour value ***************************************************************************************/ uint16_t TFT_eSPI::color8to16(uint8_t color) { - uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5-bit colour lookup table + uint8_t blue[] = {0, 11, 21, 31}; // blue 2 to 5 bit colour lookup table uint16_t color16 = 0; // =====Green===== ===============Red============== @@ -4808,7 +4801,7 @@ uint16_t TFT_eSPI::color8to16(uint8_t color) /*************************************************************************************** ** Function name: color16to24 -** Description: convert 16-bit colour to a 24-bit 888 colour value +** Description: convert 16 bit colour to a 24 bit 888 colour value ***************************************************************************************/ uint32_t TFT_eSPI::color16to24(uint16_t color565) { @@ -4821,7 +4814,7 @@ uint32_t TFT_eSPI::color16to24(uint16_t color565) /*************************************************************************************** ** Function name: color24to16 -** Description: convert 24-bit colour to a 16-bit 565 colour value +** Description: convert 24 bit colour to a 16 bit 565 colour value ***************************************************************************************/ uint32_t TFT_eSPI::color24to16(uint32_t color888) { @@ -4902,26 +4895,26 @@ uint16_t TFT_eSPI::decodeUTF8(uint8_t c) { if (!_utf8) return c; - // 7-bit Unicode Code Point + // 7 bit Unicode Code Point if ((c & 0x80) == 0x00) { decoderState = 0; return c; } if (decoderState == 0) { - // 11-bit Unicode Code Point + // 11 bit Unicode Code Point if ((c & 0xE0) == 0xC0) { decoderBuffer = ((c & 0x1F)<<6); decoderState = 1; return 0; } - // 16-bit Unicode Code Point + // 16 bit Unicode Code Point if ((c & 0xF0) == 0xE0) { decoderBuffer = ((c & 0x0F)<<12); decoderState = 2; return 0; } - // 21-bit Unicode Code Point not supported so fall-back to extended ASCII + // 21 bit Unicode Code Point not supported so fall-back to extended ASCII // if ((c & 0xF8) == 0xF0) return c; } else { @@ -4954,24 +4947,21 @@ uint16_t TFT_eSPI::decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining) if (!_utf8) return c; - // 7-bit Unicode + // 7 bit Unicode if ((c & 0x80) == 0x00) return c; - // 11-bit Unicode + // 11 bit Unicode if (((c & 0xE0) == 0xC0) && (remaining > 1)) return ((c & 0x1F)<<6) | (buf[(*index)++]&0x3F); - // 16-bit Unicode + // 16 bit Unicode if (((c & 0xF0) == 0xE0) && (remaining > 2)) { c = ((c & 0x0F)<<12) | ((buf[(*index)++]&0x3F)<<6); return c | ((buf[(*index)++]&0x3F)); } - // 21-bit Unicode not supported so fall-back to extended ASCII - // if (((c & 0xF8) == 0xF0) && (remaining > 3)) { - // c = ((c & 0x07) << 18) | ((buf[(*index)++] & 0x03F) << 12); - // c |= ((buf[(*index)++] & 0x3F) << 6); - // return c | ((buf[(*index)++] & 0x3F)); + // 21 bit Unicode not supported so fall-back to extended ASCII + // if ((c & 0xF8) == 0xF0) return c; return c; // fall-back to extended ASCII } @@ -4981,12 +4971,12 @@ uint16_t TFT_eSPI::decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining) ** Function name: alphaBlend ** Description: Blend 16bit foreground and background *************************************************************************************x*/ -uint16_t TFT_eSPI::alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc) +inline uint16_t TFT_eSPI::alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc) { - // Split out and blend 5-bit red and blue channels + // Split out and blend 5 bit red and blue channels uint32_t rxb = bgc & 0xF81F; rxb += ((fgc & 0xF81F) - rxb) * (alpha >> 2) >> 6; - // Split out and blend 6-bit green channel + // Split out and blend 6 bit green channel uint32_t xgx = bgc & 0x07E0; xgx += ((fgc & 0x07E0) - xgx) * alpha >> 8; // Recombine channels @@ -5026,9 +5016,9 @@ uint32_t TFT_eSPI::alphaBlend24(uint8_t alpha, uint32_t fgc, uint32_t bgc, uint8 uint32_t rxx = bgc & 0xFF0000; rxx += ((fgc & 0xFF0000) - rxx) * alpha >> 8; uint32_t xgx = bgc & 0x00FF00; - xgx += ((fgc & 0x00FF00) - xgx) * alpha >> 8; + xgx += ((fgc & 0xFF0000) - xgx) * alpha >> 8; uint32_t xxb = bgc & 0x0000FF; - xxb += ((fgc & 0x0000FF) - xxb) * alpha >> 8; + xxb += ((fgc & 0xFF0000) - xxb) * alpha >> 8; return (rxx & 0xFF0000) | (xgx & 0x00FF00) | (xxb & 0x0000FF); } @@ -5357,7 +5347,7 @@ int16_t TFT_eSPI::drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font) uint8_t tnp = 0; // Temporary copy of np for while loop uint8_t ts = textsize - 1; // Temporary copy of textsize - // 16-bit pixel count so maximum font size is equivalent to 180x180 pixels in area + // 16 bit pixel count so maximum font size is equivalent to 180x180 pixels in area // w is total number of pixels to plot to fill character block while (pc < w) { line = pgm_read_byte((uint8_t *)flash_address); @@ -5503,8 +5493,6 @@ int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY) // With font number. Note: font number is over-ridden if a smooth font is loaded int16_t TFT_eSPI::drawString(const char *string, int32_t poX, int32_t poY, uint8_t font) { - if (font > 8) return 0; - int16_t sumX = 0; uint8_t padding = 1, baseline = 0; uint16_t cwidth = textWidth(string, font); // Find the pixel width of the string in the font @@ -5910,7 +5898,6 @@ void TFT_eSPI::setFreeFont(const GFXfont *f) void TFT_eSPI::setTextFont(uint8_t f) { textfont = (f > 0) ? f : 1; // Don't allow font 0 - textfont = (f > 8) ? 1 : f; // Don't allow font > 8 gfxFont = NULL; } @@ -5936,7 +5923,6 @@ void TFT_eSPI::setFreeFont(uint8_t font) void TFT_eSPI::setTextFont(uint8_t f) { textfont = (f > 0) ? f : 1; // Don't allow font 0 - textfont = (f > 8) ? 1 : f; // Don't allow font > 8 } #endif @@ -5945,7 +5931,7 @@ void TFT_eSPI::setTextFont(uint8_t f) ** Function name: getSPIinstance ** Description: Get the instance of the SPI class ***************************************************************************************/ -#if !defined (TFT_PARALLEL_8_BIT) && !defined (RP2040_PIO_INTERFACE) +#if !defined (TFT_PARALLEL_8_BIT) && ! defined (RP2040_PIO_INTERFACE) SPIClass& TFT_eSPI::getSPIinstance(void) { return spi; diff --git a/lib/TFT_eSPI/TFT_eSPI.h b/lib/TFT_eSPI/TFT_eSPI.h index 8ae23427..21a940bb 100644 --- a/lib/TFT_eSPI/TFT_eSPI.h +++ b/lib/TFT_eSPI/TFT_eSPI.h @@ -12,11 +12,11 @@ Last review/edit by Bodmer: 04/02/22 ****************************************************/ -// Stop fonts etc. being loaded multiple times +// Stop fonts etc being loaded multiple times #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "2.5.43" +#define TFT_ESPI_VERSION "2.5.23" // Bit level feature flags // Bit 0 set: viewport capability @@ -29,14 +29,13 @@ //Standard support #include #include -#if !defined (TFT_PARALLEL_8_BIT) && !defined (RP2040_PIO_INTERFACE) - #include -#endif +#include + /*************************************************************************************** ** Section 2: Load library and processor specific header files ***************************************************************************************/ // Include header file that defines the fonts loaded, the TFT drivers -// available and the pins to be used, etc. etc. +// available and the pins to be used, etc, etc #ifdef CONFIG_TFT_eSPI_ESPIDF #include "TFT_config.h" #endif @@ -327,12 +326,12 @@ const PROGMEM fontinfo fontdata [] = { #define TFT_SKYBLUE 0x867D /* 135, 206, 235 */ #define TFT_VIOLET 0x915C /* 180, 46, 226 */ -// Next is a special 16-bit colour value that encodes to 8 bits -// and will then decode back to the same 16-bit value. -// Convenient for 8-bit and 16-bit transparent sprites. +// Next is a special 16 bit colour value that encodes to 8 bits +// and will then decode back to the same 16 bit value. +// Convenient for 8 bit and 16 bit transparent sprites. #define TFT_TRANSPARENT 0x0120 // This is actually a dark green -// Default palette for 4-bit colour sprites +// Default palette for 4 bit colour sprites static const uint16_t default_4bit_palette[] PROGMEM = { TFT_BLACK, // 0 ^ TFT_BROWN, // 1 | @@ -505,7 +504,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac // Support for half duplex (bi-directional SDA) SPI bus where MOSI must be switched to input #ifdef TFT_SDA_READ #if defined (TFT_eSPI_ENABLE_8_BIT_READ) - uint8_t tft_Read_8(void); // Read 8-bit value from TFT command register + uint8_t tft_Read_8(void); // Read 8 bit value from TFT command register #endif void begin_SDA_Read(void); // Begin a read on a half duplex (bi-directional SDA) SPI bus - sets MOSI to input void end_SDA_Read(void); // Restore MOSI to output @@ -598,7 +597,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac getPivotY(void); // Get pivot y // The next functions can be used as a pair to copy screen blocks (or horizontal/vertical lines) to another location - // Read a block of pixels to a data buffer, buffer is 16-bit and the size must be at least w * h + // Read a block of pixels to a data buffer, buffer is 16 bit and the size must be at least w * h void readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data); // Write a block of pixels to the screen which have been read by readRect() void pushRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data); @@ -619,11 +618,11 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac // FLASH version void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t *data, bool bpp8, uint16_t *cmap = nullptr); - // Render a 16-bit colour image with a 1bpp mask + // Render a 16 bit colour image with a 1bpp mask void pushMaskedImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *img, uint8_t *mask); // This next function has been used successfully to dump the TFT screen to a PC for documentation purposes - // It reads a screen area and returns the 3 RGB 8-bit colour values of each pixel in the buffer + // It reads a screen area and returns the 3 RGB 8 bit colour values of each pixel in the buffer // Set w and h to 1 to read 1 pixel's colour. The data buffer must be at least w * h * 3 bytes void readRectRGB(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *data); @@ -650,7 +649,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac drawRightString(const String& string, int32_t x, int32_t y, uint8_t font); // Deprecated, use setTextDatum() and drawString() - // Text rendering and font handling support functions + // Text rendering and font handling support funtions void setCursor(int16_t x, int16_t y), // Set cursor for tft.print() setCursor(int16_t x, int16_t y, uint8_t font); // Set cursor and font number for tft.print() @@ -663,7 +662,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac void setTextWrap(bool wrapX, bool wrapY = false); // Turn on/off wrapping of text in TFT width and/or height - void setTextDatum(uint8_t datum); // Set text datum position (default is top left), see Section 5 above + void setTextDatum(uint8_t datum); // Set text datum position (default is top left), see Section 6 above uint8_t getTextDatum(void); void setTextPadding(uint16_t x_width); // Set text padding (background blanking/over-write) width in pixels @@ -681,8 +680,8 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac textWidth(const char *string), // Returns pixel width of string in current font textWidth(const String& string, uint8_t font), // As above for String types textWidth(const String& string), - fontHeight(uint8_t font), // Returns pixel height of specified font - fontHeight(void); // Returns pixel height of current font + fontHeight(int16_t font), // Returns pixel height of string in specified font + fontHeight(void); // Returns pixel width of string in current font // Used by library and Smooth font class to extract Unicode point codes from a UTF8 encoded string uint16_t decodeUTF8(uint8_t *buf, uint16_t *index, uint16_t remaining), @@ -701,11 +700,11 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac // Low level read/write void spiwrite(uint8_t); // legacy support only #ifdef RM68120_DRIVER - void writecommand(uint16_t c); // Send a 16-bit command, function resets DC/RS high ready for data - void writeRegister8(uint16_t c, uint8_t d); // Write 8-bit data data to 16-bit command register - void writeRegister16(uint16_t c, uint16_t d); // Write 16-bit data data to 16-bit command register + void writecommand(uint16_t c); // Send a 16 bit command, function resets DC/RS high ready for data + void writeRegister8(uint16_t c, uint8_t d); // Write 8 bit data data to 16 bit command register + void writeRegister16(uint16_t c, uint16_t d); // Write 16 bit data data to 16 bit command register #else - void writecommand(uint8_t c); // Send an 8-bit command, function resets DC/RS high ready for data + void writecommand(uint8_t c); // Send an 8 bit command, function resets DC/RS high ready for data #endif void writedata(uint8_t d); // Send data with DC/RS set high @@ -717,31 +716,30 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac // Colour conversion - // Convert 8-bit red, green and blue to 16 bits + // Convert 8 bit red, green and blue to 16 bits uint16_t color565(uint8_t red, uint8_t green, uint8_t blue); - // Convert 8-bit colour to 16 bits + // Convert 8 bit colour to 16 bits uint16_t color8to16(uint8_t color332); - // Convert 16-bit colour to 8 bits + // Convert 16 bit colour to 8 bits uint8_t color16to8(uint16_t color565); - // Convert 16-bit colour to/from 24-bit, R+G+B concatenated into LS 24 bits + // Convert 16 bit colour to/from 24 bit, R+G+B concatenated into LS 24 bits uint32_t color16to24(uint16_t color565); uint32_t color24to16(uint32_t color888); // Alpha blend 2 colours, see generic "alphaBlend_Test" example // alpha = 0 = 100% background colour // alpha = 255 = 100% foreground colour - uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc); - - // 16-bit colour alphaBlend with alpha dither (dither reduces colour banding) + inline uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc); + // 16 bit colour alphaBlend with alpha dither (dither reduces colour banding) uint16_t alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc, uint8_t dither); - // 24-bit colour alphaBlend with optional alpha dither + // 24 bit colour alphaBlend with optional alpha dither uint32_t alphaBlend24(uint8_t alpha, uint32_t fgc, uint32_t bgc, uint8_t dither = 0); // Direct Memory Access (DMA) support functions // These can be used for SPI writes when using the ESP32 (original) or STM32 processors. - // DMA also works on a RP2040 processor with PIO based SPI and parallel (8 and 16-bit) interfaces + // DMA also works on a RP2040 processor with PIO based SPI and parallel (8 and 16 bit) interfaces // Bear in mind DMA will only be of benefit in particular circumstances and can be tricky // to manage by noobs. The functions have however been designed to be noob friendly and // avoid a few DMA behaviour "gotchas". @@ -820,9 +818,8 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac bool verifySetupID(uint32_t id); // Global variables -#if !defined (TFT_PARALLEL_8_BIT) && !defined (RP2040_PIO_INTERFACE) static SPIClass& getSPIinstance(void); // Get SPI class handle -#endif + uint32_t textcolor, textbgcolor; // Text foreground and background colours uint32_t bitmap_fg, bitmap_bg; // Bitmap foreground (bit=1) and background (bit=0) colours @@ -939,7 +936,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac bool _booted; // init() or begin() has already run once // User sketch manages these via set/getAttribute() - bool _cp437; // If set, use correct CP437 charset (default is OFF) + 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 _psram_enable; // Enable PSRAM use for library functions (TBD) and Sprites @@ -963,7 +960,7 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac #ifdef TOUCH_CS #if defined (TFT_PARALLEL_8_BIT) || defined (RP2040_PIO_INTERFACE) #if !defined(DISABLE_ALL_LIBRARY_WARNINGS) - #error >>>>------>> Touch functions not supported in 8/16-bit parallel mode or with RP2040 PIO. + #error >>>>------>> Touch functions not supported in 8/16 bit parallel mode or with RP2040 PIO. #endif #else #include "Extensions/Touch.h" // Loaded if TOUCH_CS is defined by user @@ -985,20 +982,6 @@ class TFT_eSPI : public Print { friend class TFT_eSprite; // Sprite class has ac template static inline void transpose(T& a, T& b) { T t = a; a = b; b = t; } -// Fast alphaBlend -template static inline uint16_t -fastBlend(A alpha, F fgc, B bgc) -{ - // Split out and blend 5-bit red and blue channels - uint32_t rxb = bgc & 0xF81F; - rxb += ((fgc & 0xF81F) - rxb) * (alpha >> 2) >> 6; - // Split out and blend 6-bit green channel - uint32_t xgx = bgc & 0x07E0; - xgx += ((fgc & 0x07E0) - xgx) * alpha >> 8; - // Recombine channels - return (rxb & 0xF81F) | (xgx & 0x07E0); -} - /*************************************************************************************** ** Section 10: Additional extension classes ***************************************************************************************/ diff --git a/lib/TFT_eSPI/Tools/Create_Smooth_Font/Create_font/Create_font.pde b/lib/TFT_eSPI/Tools/Create_Smooth_Font/Create_font/Create_font.pde index 1a07c5cb..c8e55609 100644 --- a/lib/TFT_eSPI/Tools/Create_Smooth_Font/Create_font/Create_font.pde +++ b/lib/TFT_eSPI/Tools/Create_Smooth_Font/Create_font/Create_font.pde @@ -48,13 +48,13 @@ Software License Agreement (FreeBSD License) // >>>>>>>>>>>>>>>>>>>> INSTRUCTIONS <<<<<<<<<<<<<<<<<<<< // See comments below in code for specifying the font parameters (point size, -// unicode blocks to include etc.). Ranges of characters (glyphs) and specific +// unicode blocks to include etc). Ranges of characters (glyphs) and specific // individual glyphs can be included in the created "*.vlw" font file. // Created fonts are saved in the sketches "FontFiles" folder. Press Ctrl+K to // see that folder location. -// 16-bit Unicode point codes in the range 0x0000 - 0xFFFF are supported. +// 16 bit Unicode point codes in the range 0x0000 - 0xFFFF are supported. // Codes 0-31 are control codes such as "tab" and "carraige return" etc. // and 32 is a "space", these should NOT be included. @@ -134,17 +134,11 @@ String fontType = ".ttf"; // Define the font size in points for the TFT_eSPI font file -int fontSize = 28; +int fontSize = 20; // Font size to use in the Processing sketch display window that pops up (can be different to above) int displayFontSize = 28; -// Create a C header (.h file) ready to be used or copied in your sketch folder -boolean createHeaderFile = true; - -// Automaticely open the folder with created files when done -boolean openFolder = true; - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Next we specify which unicode blocks from the the Basic Multilingual Plane (BMP) are included in the final font file. // // Note: The ttf/otf font file MAY NOT contain all possible Unicode characters, refer to the fonts online documentation. // @@ -369,7 +363,7 @@ static final int[] specificUnicodes = { //////////////////////////////////////////////////////////////////////////////////////////////// -// Variable to hold the inclusive Unicode range (16-bit values only for this sketch) +// Variable to hold the inclusive Unicode range (16 bit values only for this sketch) int firstUnicode = 0; int lastUnicode = 0; @@ -398,7 +392,7 @@ void setup() { // Set the fontName from the array number or the defined fontName if (fontNumber >= 0) { -// fontName = fontList[fontNumber]; + fontName = fontList[fontNumber]; fontType = ""; } @@ -505,13 +499,11 @@ void setup() { println("Created font " + fontName + str(fontSize) + ".vlw"); - String fontFileName = "FontFiles/" + fontName + str(fontSize) + ".vlw"; - // creating file try { print("Saving to sketch FontFiles folder... "); - OutputStream output = createOutput(fontFileName); + OutputStream output = createOutput("FontFiles/" + fontName + str(fontSize) + ".vlw"); font.save(output); output.close(); @@ -521,50 +513,11 @@ void setup() { // Open up the FontFiles folder to access the saved file String path = sketchPath(); - if(openFolder){ - Desktop.getDesktop().open(new File(path+"/FontFiles")); - } + Desktop.getDesktop().open(new File(path+"/FontFiles")); System.err.println("All done! Note: Rectangles are displayed for non-existant characters."); } catch(IOException e) { println("Doh! Failed to create the file"); } - - if(!createHeaderFile) return; - // Now creating header file if the option was specified. - try{ - print("saving header file to FontFile folder..."); - - InputStream input = createInputRaw(fontFileName); - PrintWriter output = createWriter("FontFiles/" + fontName + str(fontSize) + ".h"); - - output.println("#include "); - output.println(); - output.println("const uint8_t " + fontName + str(fontSize) + "[] PROGMEM = {"); - - int i = 0; - int data = input.read(); - while(data != -1){ - output.print("0x"); - output.print(hex(data, 2)); - if(i++ < 15){ - output.print(", "); - } else { - output.println(","); - i = 0; - } - data = input.read(); - } -// font.save(output); - output.println("\n};"); - - output.close(); - input.close(); - - println("C header file created."); - - } catch(IOException e){ - println("Failed to create C header file"); - } } diff --git a/lib/TFT_eSPI/Tools/Create_Smooth_Font/Create_font/FontFiles/Final-Frontier28.vlw b/lib/TFT_eSPI/Tools/Create_Smooth_Font/Create_font/FontFiles/Final-Frontier28.vlw new file mode 100644 index 00000000..2872fd55 Binary files /dev/null and b/lib/TFT_eSPI/Tools/Create_Smooth_Font/Create_font/FontFiles/Final-Frontier28.vlw differ diff --git a/lib/TFT_eSPI/Tools/Screenshot_client/Screenshot_client.pde b/lib/TFT_eSPI/Tools/Screenshot_client/Screenshot_client.pde index 03c9eefd..537b108c 100644 --- a/lib/TFT_eSPI/Tools/Screenshot_client/Screenshot_client.pde +++ b/lib/TFT_eSPI/Tools/Screenshot_client/Screenshot_client.pde @@ -55,7 +55,7 @@ int max_allowed = 1000; // Maximum number of save images allowed before a resta // These are default values, this sketch obtains the actual values from the Arduino board int tft_width = 480; // default TFT width (automatic - sent by Arduino) int tft_height = 480; // default TFT height (automatic - sent by Arduino) -int color_bytes = 2; // 2 for 16-bit, 3 for three RGB bytes (automatic - sent by Arduino) +int color_bytes = 2; // 2 for 16 bit, 3 for three RGB bytes (automatic - sent by Arduino) import processing.serial.*; diff --git a/lib/TFT_eSPI/User_Setup.h b/lib/TFT_eSPI/User_Setup.h index a0123318..d1c85aa2 100644 --- a/lib/TFT_eSPI/User_Setup.h +++ b/lib/TFT_eSPI/User_Setup.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. @@ -28,15 +28,15 @@ //#define NUCLEO_64_TFT //#define NUCLEO_144_TFT -// STM32 8-bit parallel only: -// If STN32 Port A or B pins 0-7 are used for 8-bit parallel data bus bits 0-7 +// STM32 8 bit parallel only: +// If STN32 Port A or B pins 0-7 are used for 8 bit parallel data bus bits 0-7 // then this will improve rendering performance by a factor of ~8x //#define STM_PORTA_DATA_BUS //#define STM_PORTB_DATA_BUS // Tell the library to use parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT -//#defined TFT_PARALLEL_16_BIT // **** 16-bit parallel ONLY for RP2040 processor **** +//#defined TFT_PARALLEL_16_BIT // **** 16 bit parallel ONLY for RP2040 processor **** // Display type - only define if RPi display //#define RPI_DISPLAY_TYPE // 20MHz maximum SPI @@ -84,7 +84,6 @@ // #define TFT_WIDTH 80 // #define TFT_WIDTH 128 // #define TFT_WIDTH 172 // ST7789 172 x 320 -// #define TFT_WIDTH 170 // ST7789 170 x 320 // #define TFT_WIDTH 240 // ST7789 240 x 240 and 240 x 320 // #define TFT_HEIGHT 160 // #define TFT_HEIGHT 128 @@ -105,7 +104,7 @@ // #define ST7735_GREENTAB3 // #define ST7735_GREENTAB128 // For 128 x 128 display // #define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset) -// #define ST7735_ROBOTLCD // For some RobotLCD Arduino shields (128x160, BGR, https://docs.arduino.cc/retired/getting-started-guides/TFT) +// #define ST7735_ROBOTLCD // For some RobotLCD arduino shields (128x160, BGR, https://docs.arduino.cc/retired/getting-started-guides/TFT) // #define ST7735_REDTAB // #define ST7735_BLACKTAB // #define ST7735_REDTAB160x80 // For 160 x 80 display with 24 pixel offset @@ -167,15 +166,10 @@ // ###### EDIT THE PIN NUMBERS IN THE LINES FOLLOWING TO SUIT YOUR ESP8266 SETUP ###### // For NodeMCU - use pin numbers in the form PIN_Dx where Dx is the NodeMCU pin designation -#define TFT_MISO PIN_D6 // Automatically assigned with ESP8266 if not defined -#define TFT_MOSI PIN_D7 // Automatically assigned with ESP8266 if not defined -#define TFT_SCLK PIN_D5 // Automatically assigned with ESP8266 if not defined - -#define TFT_CS PIN_D8 // Chip select control pin D8 -#define TFT_DC PIN_D3 // Data Command control pin -#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line) -//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V - +#define TFT_CS PIN_D8 // Chip select control pin D8 +#define TFT_DC PIN_D3 // Data Command control pin +#define TFT_RST PIN_D4 // Reset pin (could connect to NodeMCU RST, see next line) +//#define TFT_RST -1 // Set TFT_RST to -1 if the display RESET is connected to NodeMCU RST or 3.3V //#define TFT_BL PIN_D1 // LED back-light (only for ST7789 with backlight control pin) @@ -242,7 +236,7 @@ // ###### EDIT THE PINs BELOW TO SUIT YOUR ESP32 PARALLEL TFT SETUP ###### -// The library supports 8-bit parallel TFTs with the ESP32, the pin +// The library supports 8 bit parallel TFTs with the ESP32, the pin // selection below is compatible with ESP32 boards in UNO format. // Wemos D32 boards need to be modified, see diagram in Tools folder. // Only ILI9481 and ILI9341 based displays have been tested! @@ -250,7 +244,7 @@ // Parallel bus is only supported for the STM32 and ESP32 // Example below is for ESP32 Parallel interface with UNO displays -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT // The ESP32 and TFT the pins used for testing are: @@ -330,11 +324,11 @@ // For RP2040 processor and SPI displays, uncomment the following line to use the PIO interface. //#define RP2040_PIO_SPI // Leave commented out to use standard RP2040 SPI port interface -// For RP2040 processor and 8 or 16-bit parallel displays: +// For RP2040 processor and 8 or 16 bit parallel displays: // The parallel interface write cycle period is derived from a division of the CPU clock // speed so scales with the processor clock. This means that the divider ratio may need -// to be increased when overclocking. It may also need to be adjusted dependant on the -// display controller type (ILI94341, HX8357C etc.). If RP2040_PIO_CLK_DIV is not defined +// to be increased when overclocking. I may also need to be adjusted dependant on the +// display controller type (ILI94341, HX8357C etc). If RP2040_PIO_CLK_DIV is not defined // the library will set default values which may not suit your display. // The display controller data sheet will specify the minimum write cycle period. The // controllers often work reliably for shorter periods, however if the period is too short diff --git a/lib/TFT_eSPI/User_Setup_Select.h b/lib/TFT_eSPI/User_Setup_Select.h index f61df74d..6f9a0822 100644 --- a/lib/TFT_eSPI/User_Setup_Select.h +++ b/lib/TFT_eSPI/User_Setup_Select.h @@ -12,8 +12,11 @@ // Create a shortcut to this file on your desktop to permit quick access for editing. // Re-compile and upload after making and saving any changes to this file. -// Example User_Setup files are stored in the "User_Setups" folder. These can be used -// unmodified or adapted for a particular hardware configuration. +// Customised User_Setup files are stored in the "User_Setups" folder. + +// It is also possible for the user tft settings to be included with the sketch, see +// the "Sketch_with_tft_setup" generic example. This may be more convenient for +// multiple projects. #ifndef USER_SETUP_LOADED // Lets PlatformIO users define settings in // platformio.ini, see notes in "Tools" folder. @@ -88,11 +91,9 @@ //#include // Setup file for LilyGo LilyPi with ILI9481 display //#include // Setup file for LilyGo LilyPi with ST7796 display -//#include // Setup file for RP2040 with SPI ILI9341 -//#include // Setup file for RP2040 with PIO SPI ILI9341 -//#include // Setup file for RP2040 with SPI ILI9341 - -//#include // Setup file for Seeed XIAO with GC9A01 240x240 +//#include // Setup file for RP2040 with SPI ILI9341 +//#include // Setup file for RP2040 with PIO SPI ILI9341 +//#include // Setup file for RP2040 with SPI ILI9341 //#include // Setup file for ESP32 S2 with SPI ILI9341 //#include // Setup file for ESP32 S3 with SPI ILI9341 @@ -102,16 +103,15 @@ //#include // Setup file for ESP32 S2 with ST7789 //#include // Setup file for ESP32 with ST7789 1.47" 172x320 -//#include // Setup file for Pico/RP2040 with 8-bit parallel ILI9488 -//#include // Setup file for Pico/RP2040 with 8-bit parallel ILI9481 -//#include // Setup file for Pico/RP2040 with 8-bit parallel ILI9341 -//#include // Setup file for Pico/RP2040 with 8-bit parallel ILI9486 -//#include // Setup file for Pico/RP2040 with 8-bit parallel ST7796 +//#include // Setup file for Pico/RP2040 with 8 bit parallel ILI9488 +//#include // Setup file for Pico/RP2040 with 8 bit parallel ILI9481 +//#include // Setup file for Pico/RP2040 with 8 bit parallel ILI9341 +//#include // Setup file for Pico/RP2040 with 8 bit parallel ILI9486 +//#include // Setup file for Pico/RP2040 with 8 bit parallel ST7796 -//#include // Setup file for RP2040 16-bit parallel display -//#include // Setup file for RP2040 16-bit parallel display -//#include // Setup file for RP2040 16-bit parallel display -//#include // Setup file for Waveshare RP2040 board with onboard ST7735 0.96" 160x80 display +//#include // Setup file for RP2040 16 bit parallel display +//#include // Setup file for RP2040 16 bit parallel display +//#include // Setup file for RP2040 16 bit parallel display //#include // Setup file for ESP8266 and ST7789 135 x 240 TFT @@ -134,11 +134,6 @@ #ifdef NERDMINERV2 #include #endif - -#ifdef SPOTPEAR -#include -#endif - #ifdef NERDMINER_S3_AMOLED #include //Just a stub. No driver implementation for S3 AMOLED in TFT_eSPI #endif @@ -146,6 +141,8 @@ #include // For the LilyGo T-HMI S3 based ESP32S3 with ST7789 240 x 320 TFT #endif //#include // For the ESP32 S3 Box Lite (may also work with ESP32 S3 Box) + +//#include // For the LilyGo T-Dongle S3 based ESP32 with ST7735 80 x 160 TFT #ifdef LILYGO_S3_T_EMBED #include // For the LilyGo T-Embed S3 based ESP32S3 with ST7789 170 x 320 TFT #endif @@ -161,32 +158,21 @@ #ifdef NERDMINER_S3_GEEK #include // Setup file for Waveshare Setup303_WaveShare ESP32S3_GEEK with ST7789 135*240 TFT #endif - -// #include // For the LilyGo T-PICO-Pro with ST7796 222 x 480 TFT -// #include // For the LilyGo T-BEAM V1.x with ST7796 222 x 480 TFT - -//#include // For the ESP32 S3 Box Lite -//#include // For the ESP32 S3 Box - - #ifdef M5STICK_C_PLUS2 #include // Setup file for ESP32 configured for ST7735 128 x 128 animated eyes #endif - //#include // Setup file for Bw16-based boards with ST7735 160 x 80 TFT -//#include // Setup file for Waveshare ESP32-S3-Touch-LCD-1.28 board with GC9A01 240*240 TFT //#include // Template file for a setup - -//#include // Setup file for Dustin Watts PCB with ILI9488 +//#include // Setup file for Dustin Watts PCB with ILI9488 //#include // Setup file for Dustin Watts PCB with ST7796 -//#include // Setup file for Dustin Watts Pico PCB with ST7796 -//#include // Setup file for Dustin Watts PCB with ST7789 240 x 240 on 3.3V adapter board -//#include // Setup file for Dustin Watts PCB with GC9A01 240 x 240 on 3.3V adapter board -//#include // Setup file for Dustin Watts PCB with GC9A01 240 x 240 on 3.3V adapter board -//#include // Setup file for Dustin Watts PCB with ST7789 240 x 240 on 3.3V adapter board -//#include // Setup file for Dustin Watts PCB with ILI9341 +//#include // Setup file for Dustin Watts Pico PCB with ST7796 +//#include // Setup file for Dustin Watts PCB with ST7789 240 x 240 on 3.3V adapter board +//#include // Setup file for Dustin Watts PCB with GC9A01 240 x 240 on 3.3V adapter board +//#include // Setup file for Dustin Watts PCB with GC9A01 240 x 240 on 3.3V adapter board +//#include // Setup file for Dustin Watts PCB with ST7789 240 x 240 on 3.3V adapter board +//#include // Setup file for Dustin Watts PCB with ILI9341 //#include #endif // USER_SETUP_LOADED @@ -201,7 +187,7 @@ ///////////////////////////////////////////////////////////////////////////////////// -// Identical looking TFT displays may have a different colour ordering in the 16-bit colour +// Identical looking TFT displays may have a different colour ordering in the 16 bit colour #define TFT_BGR 0 // Colour order Blue-Green-Red #define TFT_RGB 1 // Colour order Red-Green-Blue @@ -223,7 +209,7 @@ #endif #endif -// Invoke 18-bit colour for selected displays +// Invoke 18 bit colour for selected displays #if !defined (RPI_DISPLAY_TYPE) && !defined (TFT_PARALLEL_8_BIT) && !defined (TFT_PARALLEL_16_BIT) && !defined (ESP32_PARALLEL) #if defined (ILI9481_DRIVER) || defined (ILI9486_DRIVER) || defined (ILI9488_DRIVER) #define SPI_18BIT_DRIVER diff --git a/lib/TFT_eSPI/User_Setups/Setup100_RP2040_ILI9488_parallel.h b/lib/TFT_eSPI/User_Setups/Setup100_RP2040_ILI9488_parallel.h index dcec30ee..a28fa70e 100644 --- a/lib/TFT_eSPI/User_Setups/Setup100_RP2040_ILI9488_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup100_RP2040_ILI9488_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor only when used with 8-bit parallel displays +// This setup is for the RP2040 processor only when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 100 @@ -25,6 +25,8 @@ //#define TFT_RD -1 // Do not define, read pin permanently connected to 3V3 // Note: All the following pins are PIO hardware configured and driven +// The pins are hard-coded at the moment and must not be changed here +// Connections MUST use the pins below #define TFT_WR 22 // PIO requires these to be sequentially increasing - do not change diff --git a/lib/TFT_eSPI/User_Setups/Setup101_RP2040_ILI9481_parallel.h b/lib/TFT_eSPI/User_Setups/Setup101_RP2040_ILI9481_parallel.h index 714e5e14..f80fdefd 100644 --- a/lib/TFT_eSPI/User_Setups/Setup101_RP2040_ILI9481_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup101_RP2040_ILI9481_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor only when used with 8-bit parallel displays +// This setup is for the RP2040 processor only when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 101 @@ -25,6 +25,8 @@ //#define TFT_RD -1 // Do not define, read pin permanently connected to 3V3 // Note: All the following pins are PIO hardware configured and driven +// The pins are hard-coded at the moment and must not be changed here +// Connections MUST use the pins below #define TFT_WR 22 // PIO requires these to be sequentially increasing - do not change diff --git a/lib/TFT_eSPI/User_Setups/Setup102_RP2040_ILI9341_parallel.h b/lib/TFT_eSPI/User_Setups/Setup102_RP2040_ILI9341_parallel.h index ce133c80..844d2376 100644 --- a/lib/TFT_eSPI/User_Setups/Setup102_RP2040_ILI9341_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup102_RP2040_ILI9341_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor only when used with 8-bit parallel displays +// This setup is for the RP2040 processor only when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 102 @@ -25,6 +25,8 @@ //#define TFT_RD -1 // Do not define, read pin permanently connected to 3V3 // Note: All the following pins are PIO hardware configured and driven +// The pins are hard-coded at the moment and must not be changed here +// Connections MUST use the pins below #define TFT_WR 22 // PIO requires these to be sequentially increasing - do not change diff --git a/lib/TFT_eSPI/User_Setups/Setup103_RP2040_ILI9486_parallel.h b/lib/TFT_eSPI/User_Setups/Setup103_RP2040_ILI9486_parallel.h index 34bb7024..ca2084cb 100644 --- a/lib/TFT_eSPI/User_Setups/Setup103_RP2040_ILI9486_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup103_RP2040_ILI9486_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor only when used with 8-bit parallel displays +// This setup is for the RP2040 processor only when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 103 @@ -25,6 +25,8 @@ //#define TFT_RD -1 // Do not define, read pin permanently connected to 3V3 // Note: All the following pins are PIO hardware configured and driven +// The pins are hard-coded at the moment and must not be changed here +// Connections MUST use the pins below #define TFT_WR 22 // PIO requires these to be sequentially increasing - do not change diff --git a/lib/TFT_eSPI/User_Setups/Setup104_RP2040_ST7796_parallel.h b/lib/TFT_eSPI/User_Setups/Setup104_RP2040_ST7796_parallel.h index a76e4fcd..0a69d9da 100644 --- a/lib/TFT_eSPI/User_Setups/Setup104_RP2040_ST7796_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup104_RP2040_ST7796_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor only when used with 8-bit parallel displays +// This setup is for the RP2040 processor only when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 104 @@ -25,6 +25,8 @@ //#define TFT_RD -1 // Do not define, read pin permanently connected to 3V3 // Note: All the following pins are PIO hardware configured and driven +// The pins are hard-coded at the moment and must not be changed here +// Connections MUST use the pins below #define TFT_WR 22 // PIO requires these to be sequentially increasing - do not change diff --git a/lib/TFT_eSPI/User_Setups/Setup105_RP2040_ST7796_16bit_parallel.h b/lib/TFT_eSPI/User_Setups/Setup105_RP2040_ST7796_16bit_parallel.h index 82b506cf..e53afa66 100644 --- a/lib/TFT_eSPI/User_Setups/Setup105_RP2040_ST7796_16bit_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup105_RP2040_ST7796_16bit_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor only when used with 8-bit parallel displays +// This setup is for the RP2040 processor only when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 105 diff --git a/lib/TFT_eSPI/User_Setups/Setup106_RP2040_ILI9481_16bit_parallel.h b/lib/TFT_eSPI/User_Setups/Setup106_RP2040_ILI9481_16bit_parallel.h index 7273ba3d..0a1d75c0 100644 --- a/lib/TFT_eSPI/User_Setups/Setup106_RP2040_ILI9481_16bit_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup106_RP2040_ILI9481_16bit_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor when used with 8-bit parallel displays +// This setup is for the RP2040 processor when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 106 @@ -11,7 +11,7 @@ // The parallel interface write cycle period is derived from a division of the CPU clock // speed so scales with the processor clock. This means that the divider ratio may need // to be increased when overclocking. I may also need to be adjusted dependant on the -// display controller type (ILI94341, HX8357C etc.). If RP2040_PIO_CLK_DIV is not defined +// display controller type (ILI94341, HX8357C etc). If RP2040_PIO_CLK_DIV is not defined // the library will set default values which may not suit your display. // The display controller data sheet will specify the minimum write cycle period. The // controllers often work reliably for shorter periods, however if the period is too short diff --git a/lib/TFT_eSPI/User_Setups/Setup107_RP2040_ILI9341_16bit_parallel.h b/lib/TFT_eSPI/User_Setups/Setup107_RP2040_ILI9341_16bit_parallel.h index 384dc1cc..6b0d0f98 100644 --- a/lib/TFT_eSPI/User_Setups/Setup107_RP2040_ILI9341_16bit_parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup107_RP2040_ILI9341_16bit_parallel.h @@ -1,4 +1,4 @@ -// This setup is for the RP2040 processor only when used with 8-bit parallel displays +// This setup is for the RP2040 processor only when used with 8 bit parallel displays // See SetupX_Template.h for all options available #define USER_SETUP_ID 107 diff --git a/lib/TFT_eSPI/User_Setups/Setup201_WT32_SC01.h b/lib/TFT_eSPI/User_Setups/Setup201_WT32_SC01.h index 08f59533..7f034978 100644 --- a/lib/TFT_eSPI/User_Setups/Setup201_WT32_SC01.h +++ b/lib/TFT_eSPI/User_Setups/Setup201_WT32_SC01.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. diff --git a/lib/TFT_eSPI/User_Setups/Setup206_LilyGo_T_Display_S3.h b/lib/TFT_eSPI/User_Setups/Setup206_LilyGo_T_Display_S3.h index 7a58eca6..42678ace 100644 --- a/lib/TFT_eSPI/User_Setups/Setup206_LilyGo_T_Display_S3.h +++ b/lib/TFT_eSPI/User_Setups/Setup206_LilyGo_T_Display_S3.h @@ -17,8 +17,7 @@ #define TFT_WIDTH 170 #define TFT_HEIGHT 320 -#define TFT_CS 6 -#define TFT_DC 7 +#define TFT_DC 7 #define TFT_RST 5 #define TFT_WR 8 diff --git a/lib/TFT_eSPI/User_Setups/Setup207_LilyGo_T_HMI.h b/lib/TFT_eSPI/User_Setups/Setup207_LilyGo_T_HMI.h index 42d3f1a6..8606ef3d 100644 --- a/lib/TFT_eSPI/User_Setups/Setup207_LilyGo_T_HMI.h +++ b/lib/TFT_eSPI/User_Setups/Setup207_LilyGo_T_HMI.h @@ -8,7 +8,7 @@ #define TFT_WIDTH 240 #define TFT_HEIGHT 320 -// #define CGRAM_OFFSET +#define CGRAM_OFFSET // #define TFT_RGB_ORDER TFT_RGB // Colour order Red-Green-Blue #define TFT_RGB_ORDER TFT_BGR // Colour order Blue-Green-Red diff --git a/lib/TFT_eSPI/User_Setups/Setup27_RPi_ST7796_ESP32.h b/lib/TFT_eSPI/User_Setups/Setup27_RPi_ST7796_ESP32.h index ed053a41..8d2f54b5 100644 --- a/lib/TFT_eSPI/User_Setups/Setup27_RPi_ST7796_ESP32.h +++ b/lib/TFT_eSPI/User_Setups/Setup27_RPi_ST7796_ESP32.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. diff --git a/lib/TFT_eSPI/User_Setups/Setup28_RPi_ST7796_ESP8266.h b/lib/TFT_eSPI/User_Setups/Setup28_RPi_ST7796_ESP8266.h index e4ba57c6..4be82743 100644 --- a/lib/TFT_eSPI/User_Setups/Setup28_RPi_ST7796_ESP8266.h +++ b/lib/TFT_eSPI/User_Setups/Setup28_RPi_ST7796_ESP8266.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. diff --git a/lib/TFT_eSPI/User_Setups/Setup29_ILI9341_STM32.h b/lib/TFT_eSPI/User_Setups/Setup29_ILI9341_STM32.h index 61043a94..bb78e8e9 100644 --- a/lib/TFT_eSPI/User_Setups/Setup29_ILI9341_STM32.h +++ b/lib/TFT_eSPI/User_Setups/Setup29_ILI9341_STM32.h @@ -83,7 +83,7 @@ #define SMOOTH_FONT -// Nucleo-F767ZI has a ~216MHZ CPU clock, this is divided by 4, 8, 16 etc. +// Nucleo-F767ZI has a ~216MHZ CPU clock, this is divided by 4, 8, 16 etc #define SPI_FREQUENCY 27000000 // 27MHz SPI clock //#define SPI_FREQUENCY 55000000 // 55MHz is over-clocking ILI9341 but seems to work reliably! diff --git a/lib/TFT_eSPI/User_Setups/Setup30_ILI9341_Parallel_STM32.h b/lib/TFT_eSPI/User_Setups/Setup30_ILI9341_Parallel_STM32.h index 5b1b26df..e9a42214 100644 --- a/lib/TFT_eSPI/User_Setups/Setup30_ILI9341_Parallel_STM32.h +++ b/lib/TFT_eSPI/User_Setups/Setup30_ILI9341_Parallel_STM32.h @@ -14,7 +14,7 @@ #define NUCLEO_64_TFT //#define NUCLEO_144_TFT -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) #define TFT_PARALLEL_8_BIT // Define the display driver chip type @@ -31,7 +31,7 @@ #define TFT_WR A1 // Write strobe control pin #define TFT_RD A0 // Read pin -#define TFT_D0 D8 // 8-bit parallel bus to TFT +#define TFT_D0 D8 // 8 bit parallel bus to TFT #define TFT_D1 D9 #define TFT_D2 D2 #define TFT_D3 D3 diff --git a/lib/TFT_eSPI/User_Setups/Setup31_ST7796_Parallel_STM32.h b/lib/TFT_eSPI/User_Setups/Setup31_ST7796_Parallel_STM32.h index 0e26eaa3..0063e763 100644 --- a/lib/TFT_eSPI/User_Setups/Setup31_ST7796_Parallel_STM32.h +++ b/lib/TFT_eSPI/User_Setups/Setup31_ST7796_Parallel_STM32.h @@ -13,7 +13,7 @@ #define NUCLEO_64_TFT //#define NUCLEO_144_TFT -// Tell the library to use 8-bit parallel mode(otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode(otherwise SPI is assumed) #define TFT_PARALLEL_8_BIT // Define the display driver chip type @@ -30,7 +30,7 @@ #define TFT_WR A1 // Write strobe control pin #define TFT_RD A0 // Read pin -#define TFT_D0 D8 // 8-bit parallel bus to TFT +#define TFT_D0 D8 // 8 bit parallel bus to TFT #define TFT_D1 D9 #define TFT_D2 D2 #define TFT_D3 D3 diff --git a/lib/TFT_eSPI/User_Setups/Setup33_RPi_ILI9486_STM32.h b/lib/TFT_eSPI/User_Setups/Setup33_RPi_ILI9486_STM32.h index 5a1a8c8b..6def91d7 100644 --- a/lib/TFT_eSPI/User_Setups/Setup33_RPi_ILI9486_STM32.h +++ b/lib/TFT_eSPI/User_Setups/Setup33_RPi_ILI9486_STM32.h @@ -54,7 +54,7 @@ #define SMOOTH_FONT -// Nucleo-F767ZI has a ~216MHZ CPU clock, this is divided by 4, 8, 16 etc. +// Nucleo-F767ZI has a ~216MHZ CPU clock, this is divided by 4, 8, 16 etc #define SPI_FREQUENCY 20000000 // 27MHz SPI clock //#define SPI_FREQUENCY 55000000 // 55MHz is over-clocking ILI9341 but seems to work reliably! diff --git a/lib/TFT_eSPI/User_Setups/Setup34_ILI9481_Parallel_STM32.h b/lib/TFT_eSPI/User_Setups/Setup34_ILI9481_Parallel_STM32.h index 467a001c..9585a4fe 100644 --- a/lib/TFT_eSPI/User_Setups/Setup34_ILI9481_Parallel_STM32.h +++ b/lib/TFT_eSPI/User_Setups/Setup34_ILI9481_Parallel_STM32.h @@ -12,7 +12,7 @@ #define NUCLEO_64_TFT //#define NUCLEO_144_TFT -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) #define TFT_PARALLEL_8_BIT // Define the display driver chip type @@ -29,7 +29,7 @@ #define TFT_WR A1 // Write strobe control pin #define TFT_RD A0 // Read pin -#define TFT_D0 D8 // 8-bit parallel bus to TFT +#define TFT_D0 D8 // 8 bit parallel bus to TFT #define TFT_D1 D9 #define TFT_D2 D2 #define TFT_D3 D3 diff --git a/lib/TFT_eSPI/User_Setups/Setup35_ILI9341_STM32_Port_Bus.h b/lib/TFT_eSPI/User_Setups/Setup35_ILI9341_STM32_Port_Bus.h index 894948cb..eadec6ed 100644 --- a/lib/TFT_eSPI/User_Setups/Setup35_ILI9341_STM32_Port_Bus.h +++ b/lib/TFT_eSPI/User_Setups/Setup35_ILI9341_STM32_Port_Bus.h @@ -14,7 +14,7 @@ //#define STM_PORTC_DATA_BUS // Pins below must re re-allocated to use this option //#define STM_PORTD_DATA_BUS // Pins below must re re-allocated to use this option -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) #define TFT_PARALLEL_8_BIT // Define ONE of the the TFT display drivers @@ -30,7 +30,7 @@ #define TFT_WR PB9 // Write strobe control pin #define TFT_RD PB1 // Read pin -#define TFT_D0 PA0 // 8-bit Port A parallel bus to TFT +#define TFT_D0 PA0 // 8 bit Port A parallel bus to TFT #define TFT_D1 PA1 #define TFT_D2 PA2 #define TFT_D3 PA3 diff --git a/lib/TFT_eSPI/User_Setups/Setup50_SSD1963_Parallel.h b/lib/TFT_eSPI/User_Setups/Setup50_SSD1963_Parallel.h index d7265d7a..011fbd1d 100644 --- a/lib/TFT_eSPI/User_Setups/Setup50_SSD1963_Parallel.h +++ b/lib/TFT_eSPI/User_Setups/Setup50_SSD1963_Parallel.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. diff --git a/lib/TFT_eSPI/User_Setups/Setup60_RP2040_ILI9341.h b/lib/TFT_eSPI/User_Setups/Setup60_RP2040_ILI9341.h index c795e0e4..49522e16 100644 --- a/lib/TFT_eSPI/User_Setups/Setup60_RP2040_ILI9341.h +++ b/lib/TFT_eSPI/User_Setups/Setup60_RP2040_ILI9341.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. @@ -15,7 +15,7 @@ // // ################################################################################## -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT // Display type - only define if RPi display diff --git a/lib/TFT_eSPI/User_Setups/Setup62_RP2040_Nano_Connect_ILI9341.h b/lib/TFT_eSPI/User_Setups/Setup62_RP2040_Nano_Connect_ILI9341.h index 0e8a4a9c..6548062d 100644 --- a/lib/TFT_eSPI/User_Setups/Setup62_RP2040_Nano_Connect_ILI9341.h +++ b/lib/TFT_eSPI/User_Setups/Setup62_RP2040_Nano_Connect_ILI9341.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. @@ -15,7 +15,7 @@ // // ################################################################################## -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT // Display type - only define if RPi display diff --git a/lib/TFT_eSPI/User_Setups/SetupX_Template.h b/lib/TFT_eSPI/User_Setups/SetupX_Template.h index 00bf9a5d..4a42c840 100644 --- a/lib/TFT_eSPI/User_Setups/SetupX_Template.h +++ b/lib/TFT_eSPI/User_Setups/SetupX_Template.h @@ -1,5 +1,5 @@ // USER DEFINED SETTINGS -// Set driver type, fonts to be loaded, pins used and SPI control method etc. +// Set driver type, fonts to be loaded, pins used and SPI control method etc // // See the User_Setup_Select.h file if you wish to be able to define multiple // setups and then easily select which setup file is used by the compiler. @@ -27,15 +27,15 @@ //#define NUCLEO_64_TFT //#define NUCLEO_144_TFT -// STM32 8-bit parallel only: -// If STN32 Port A or B pins 0-7 are used for 8-bit parallel data bus bits 0-7 +// STM32 8 bit parallel only: +// If STN32 Port A or B pins 0-7 are used for 8 bit parallel data bus bits 0-7 // then this will improve rendering performance by a factor of ~8x //#define STM_PORTA_DATA_BUS //#define STM_PORTB_DATA_BUS -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT -//#define TFT_PARALLEL_16_BIT // **** 16-bit parallel ONLY with RP2040 processor **** +//#define TFT_PARALLEL_16_BIT // **** 16 bit parallel ONLY with RP2040 processor **** // Display type - only define if RPi display //#define RPI_DISPLAY_TYPE // 20MHz maximum SPI @@ -236,7 +236,7 @@ // ###### EDIT THE PINs BELOW TO SUIT YOUR ESP32 PARALLEL TFT SETUP ###### -// The library supports 8-bit parallel TFTs with the ESP32, the pin +// The library supports 8 bit parallel TFTs with the ESP32, the pin // selection below is compatible with ESP32 boards in UNO format. // Wemos D32 boards need to be modified, see diagram in Tools folder. // Only ILI9481 and ILI9341 based displays have been tested! @@ -244,7 +244,7 @@ // Parallel bus is only supported for the STM32 and ESP32 // Example below is for ESP32 Parallel interface with UNO displays -// Tell the library to use 8-bit parallel mode (otherwise SPI is assumed) +// Tell the library to use 8 bit parallel mode (otherwise SPI is assumed) //#define TFT_PARALLEL_8_BIT // The ESP32 and TFT the pins used for testing are: diff --git a/lib/TFT_eSPI/User_Setups/User_Custom_Fonts.h b/lib/TFT_eSPI/User_Setups/User_Custom_Fonts.h index 004ac54e..f2dc3d35 100644 --- a/lib/TFT_eSPI/User_Setups/User_Custom_Fonts.h +++ b/lib/TFT_eSPI/User_Setups/User_Custom_Fonts.h @@ -6,7 +6,7 @@ */ // Note: At the time of writing there is a last character code definition bug in the -// Squix font file format so do NOT try and print the tilde (~) symbol (ASCII 0x7E) +// Squix font file format so do NOT try and print the tilda (~) symbol (ASCII 0x7E) // Alternatively look at the end of the font header file and edit: 0x7E to read 0x7D /* e.g. vvvv (uint8_t *)Orbitron_Light_32Bitmaps,(GFXglyph *)Orbitron_Light_32Glyphs,0x20, 0x7D, 32}; @@ -16,7 +16,7 @@ // When font files are placed in the Custom folder (TFT_eSPI\Fonts\Custom) then they must // also be #included here: -// The CF_OL24 etc. are a shorthand reference, but this is not essential to use the fonts +// The CF_OL24 etc are a shorthand reference, but this is not essential to use the fonts #ifdef LOAD_GFXFF diff --git a/lib/TFT_eSPI/docs/ESP-IDF/Using ESP-IDF.txt b/lib/TFT_eSPI/docs/ESP-IDF/Using ESP-IDF.txt index a23a651c..18af8381 100644 --- a/lib/TFT_eSPI/docs/ESP-IDF/Using ESP-IDF.txt +++ b/lib/TFT_eSPI/docs/ESP-IDF/Using ESP-IDF.txt @@ -30,7 +30,7 @@ Steps to use: If your board is connected choose serial port. Leave ESP-IDF component directory blank and press Choose Template. - 4. In the drop-down choose Extension and select Arduino-as-component. (This is not mandatory. + 4. In the dropdown choose Extension and select Arduino-as-component. (This is not mandatory. You can try other templates if you want). This will create a blank project with a simple main source file in the "main" folder. diff --git a/lib/TFT_eSPI/docs/PlatformIO/Configuring options.txt b/lib/TFT_eSPI/docs/PlatformIO/Configuring options.txt index 26caeacd..c80259fd 100644 --- a/lib/TFT_eSPI/docs/PlatformIO/Configuring options.txt +++ b/lib/TFT_eSPI/docs/PlatformIO/Configuring options.txt @@ -29,7 +29,7 @@ build_flags = -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_DEBUG -DUSER_SETUP_LOADED=1 - ; Define the TFT driver, pins etc. here: + ; Define the TFT driver, pins etc here: -DST7789_DRIVER=1 -DTFT_WIDTH=128 -DTFT_HEIGHT=160 diff --git a/lib/TFT_eSPI/docs/PlatformIO/rp2040.txt b/lib/TFT_eSPI/docs/PlatformIO/rp2040.txt index f4208bd5..fc6ef3e9 100644 --- a/lib/TFT_eSPI/docs/PlatformIO/rp2040.txt +++ b/lib/TFT_eSPI/docs/PlatformIO/rp2040.txt @@ -33,7 +33,7 @@ board_build.f_cpu = 133000000L build_flags = -Os -DUSER_SETUP_LOADED=1 - ; Define the TFT driver, pins etc. here: + ; Define the TFT driver, pins etc here: -DTFT_PARALLEL_8_BIT=1 -DRM68120_DRIVER=1 -DRP2040_PIO_CLK_DIV=1 diff --git a/lib/TFT_eSPI/examples/160 x 128/TFT_Ellipse/TFT_Ellipse.ino b/lib/TFT_eSPI/examples/160 x 128/TFT_Ellipse/TFT_Ellipse.ino index f28bab94..1e8b86c3 100644 --- a/lib/TFT_eSPI/examples/160 x 128/TFT_Ellipse/TFT_Ellipse.ino +++ b/lib/TFT_eSPI/examples/160 x 128/TFT_Ellipse/TFT_Ellipse.ino @@ -20,7 +20,7 @@ void loop() { tft.fillScreen(TFT_BLACK); - // Draw some random filled ellipses + // Draw some random filled elipses for (int i = 0; i < 20; i++) { int rx = random(40); @@ -33,7 +33,7 @@ void loop() { delay(2000); tft.fillScreen(TFT_BLACK); - // Draw some random outline ellipses + // Draw some random outline elipses for (int i = 0; i < 20; i++) { int rx = random(40); diff --git a/lib/TFT_eSPI/examples/160 x 128/TFT_Meter_5/TFT_Meter_5.ino b/lib/TFT_eSPI/examples/160 x 128/TFT_Meter_5/TFT_Meter_5.ino index 0d4541ae..1f9c8eb3 100644 --- a/lib/TFT_eSPI/examples/160 x 128/TFT_Meter_5/TFT_Meter_5.ino +++ b/lib/TFT_eSPI/examples/160 x 128/TFT_Meter_5/TFT_Meter_5.ino @@ -73,7 +73,7 @@ void analogMeter() // Long scale tick length int tl = 15; - // Coordinates of tick to draw + // Coodinates of tick to draw float sx = cos((i - 90) * 0.0174532925); float sy = sin((i - 90) * 0.0174532925); uint16_t x0 = sx * (M_SIZE*100 + tl) + M_SIZE*120; diff --git a/lib/TFT_eSPI/examples/160 x 128/TFT_Print_Test/TFT_Print_Test.ino b/lib/TFT_eSPI/examples/160 x 128/TFT_Print_Test/TFT_Print_Test.ino index f6974587..8563c0d3 100644 --- a/lib/TFT_eSPI/examples/160 x 128/TFT_Print_Test/TFT_Print_Test.ino +++ b/lib/TFT_eSPI/examples/160 x 128/TFT_Print_Test/TFT_Print_Test.ino @@ -1,5 +1,5 @@ /* - Test the tft.print() viz. embedded tft.write() function + Test the tft.print() viz embedded tft.write() function This sketch used font 2, 4, 7 diff --git a/lib/TFT_eSPI/examples/160 x 128/TFT_Rainbow/TFT_Rainbow.ino b/lib/TFT_eSPI/examples/160 x 128/TFT_Rainbow/TFT_Rainbow.ino index 3ac49770..ce2bb161 100644 --- a/lib/TFT_eSPI/examples/160 x 128/TFT_Rainbow/TFT_Rainbow.ino +++ b/lib/TFT_eSPI/examples/160 x 128/TFT_Rainbow/TFT_Rainbow.ino @@ -96,7 +96,7 @@ void loop() { // The new larger fonts do not use the .setCursor call, coords are embedded tft.setTextColor(TFT_BLACK, TFT_BLACK); // Do not plot the background colour - // Overlay the black text on top of the rainbow plot (the advantage of not drawing the background colour!) + // Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!) tft.drawCentreString("Font size 2", 80, 14, 2); // Draw text centre at position 80, 12 using font 2 //tft.drawCentreString("Font size 2",81,12,2); // Draw text centre at position 80, 12 using font 2 diff --git a/lib/TFT_eSPI/examples/160 x 128/TFT_flash_jpg/TFT_flash_jpg.ino b/lib/TFT_eSPI/examples/160 x 128/TFT_flash_jpg/TFT_flash_jpg.ino index d4482d61..7179945d 100644 --- a/lib/TFT_eSPI/examples/160 x 128/TFT_flash_jpg/TFT_flash_jpg.ino +++ b/lib/TFT_eSPI/examples/160 x 128/TFT_flash_jpg/TFT_flash_jpg.ino @@ -1,7 +1,7 @@ // Sketch to display images on a 160 x 128 TFT // Renders images stored in an array in program (FLASH) -// The JPEG images are stored in header files (see jpeg1.h etc.) +// The JPEG images are stored in header files (see jpeg1.h etc) // As well as the TFT_eSPI library: // https://github.com/Bodmer/TFT_eSPI @@ -95,7 +95,7 @@ void drawArrayJpeg(const uint8_t arrayname[], uint32_t array_size, int xpos, int // fit totally on the screen are cropped to the nearest MCU size and may leave right/bottom borders. void renderJPEG(int xpos, int ypos) { - // retrieve information about the image + // retrieve infomration about the image uint16_t *pImg; uint16_t mcu_w = JpegDec.MCUWidth; uint16_t mcu_h = JpegDec.MCUHeight; @@ -193,7 +193,7 @@ void jpegInfo() { // Show the execution time (optional) //#################################################################################################### // WARNING: for UNO/AVR legacy reasons printing text to the screen with the Mega might not work for -// sketch sizes greater than ~70KBytes because 16-bit address pointers are used in some libraries. +// sketch sizes greater than ~70KBytes because 16 bit address pointers are used in some libraries. // The Due will work fine with the HX8357_Due library. diff --git a/lib/TFT_eSPI/examples/320 x 240/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino b/lib/TFT_eSPI/examples/320 x 240/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino index 7bb38589..dbbd6d45 100644 --- a/lib/TFT_eSPI/examples/320 x 240/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino +++ b/lib/TFT_eSPI/examples/320 x 240/All_Free_Fonts_Demo/All_Free_Fonts_Demo.ino @@ -376,7 +376,7 @@ void loop() { } // There follows a crude way of flagging that this example sketch needs fonts which -// have not been enabled in the User_Setup.h file inside the TFT_HX8357 library. +// have not been enbabled in the User_Setup.h file inside the TFT_HX8357 library. // // These lines produce errors during compile time if settings in User_Setup are not correct // diff --git a/lib/TFT_eSPI/examples/320 x 240/Free_Font_Demo/Free_Font_Demo.ino b/lib/TFT_eSPI/examples/320 x 240/Free_Font_Demo/Free_Font_Demo.ino index c0c3c083..2a4c63af 100644 --- a/lib/TFT_eSPI/examples/320 x 240/Free_Font_Demo/Free_Font_Demo.ino +++ b/lib/TFT_eSPI/examples/320 x 240/Free_Font_Demo/Free_Font_Demo.ino @@ -280,7 +280,7 @@ void drawDatumMarker(int x, int y) // There follows a crude way of flagging that this example sketch needs fonts which -// have not been enabled in the User_Setup.h file inside the TFT_HX8357 library. +// have not been enbabled in the User_Setup.h file inside the TFT_HX8357 library. // // These lines produce errors during compile time if settings in User_Setup are not correct // diff --git a/lib/TFT_eSPI/examples/320 x 240/Keypad_240x320/Keypad_240x320.ino b/lib/TFT_eSPI/examples/320 x 240/Keypad_240x320/Keypad_240x320.ino index 0866844c..e38e6f4a 100644 --- a/lib/TFT_eSPI/examples/320 x 240/Keypad_240x320/Keypad_240x320.ino +++ b/lib/TFT_eSPI/examples/320 x 240/Keypad_240x320/Keypad_240x320.ino @@ -3,8 +3,8 @@ button handling class, this sketch is based on the Arduin-o-phone example. - This example displays a keypad where numbers can be entered and - sent to the Serial Monitor window. + This example diplays a keypad where numbers can be entered and + send to the Serial Monitor window. The sketch has been tested on the ESP8266 (which supports SPIFFS) @@ -164,7 +164,7 @@ void loop(void) { // Update the number display field tft.setTextDatum(TL_DATUM); // Use top left corner as text coord datum - tft.setFreeFont(&FreeSans18pt7b); // Choose a nice font that fits box + tft.setFreeFont(&FreeSans18pt7b); // Choose a nicefont that fits box tft.setTextColor(DISP_TCOLOR); // Set the font colour // Draw the string, the value returned is the width in pixels @@ -209,7 +209,7 @@ void touch_calibrate() // check file system exists if (!SPIFFS.begin()) { - Serial.println("formatting file system"); + Serial.println("Formating file system"); SPIFFS.format(); SPIFFS.begin(); } diff --git a/lib/TFT_eSPI/examples/320 x 240/Read_ID_bitbash/Read_ID_bitbash.ino b/lib/TFT_eSPI/examples/320 x 240/Read_ID_bitbash/Read_ID_bitbash.ino index 51f4ea2f..599d3546 100644 --- a/lib/TFT_eSPI/examples/320 x 240/Read_ID_bitbash/Read_ID_bitbash.ino +++ b/lib/TFT_eSPI/examples/320 x 240/Read_ID_bitbash/Read_ID_bitbash.ino @@ -11,7 +11,7 @@ // Change the pin settings to suit your hardware -// UNO etc. +// UNO etc //#define TFT_MOSI 11 //#define TFT_SCK 13 //#define TFT_CS 9 @@ -116,7 +116,7 @@ void setup() { uint32_t ID = 0; Serial.begin(115200); - delay(4000); // Delay to allow USB to connect to a Leonardo etc. + delay(4000); // Delay to allow USB to connect to a Leonardo etc Serial.println("TFT driver register values:"); Serial.println("==========================="); diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_ArcFill/TFT_ArcFill.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_ArcFill/TFT_ArcFill.ino index cfeeab02..4ad06caf 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_ArcFill/TFT_ArcFill.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_ArcFill/TFT_ArcFill.ino @@ -11,7 +11,7 @@ TFT_eSPI tft = TFT_eSPI(); // Invoke custom library byte inc = 0; unsigned int col = 0; -byte red = 31; // Red is the top 5 bits of a 16-bit colour value +byte red = 31; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits byte state = 0; @@ -56,7 +56,7 @@ void loop() { // rx = x axis outer radius // ry = y axis outer radius // w = width (thickness) of arc in pixels -// colour = 16-bit colour value +// colour = 16 bit colour value // Note if rx and ry are the same then an arc of a circle is drawn void fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour) @@ -87,7 +87,7 @@ void fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour); tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour); - // Copy segment end to segment start for next segment + // Copy segment end to sgement start for next segment x0 = x2; y0 = y2; x1 = x3; @@ -96,7 +96,7 @@ void fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w } // ######################################################################### -// Return the 16-bit colour with brightness 0-100% +// Return the 16 bit colour with brightness 0-100% // ######################################################################### unsigned int brightness(unsigned int colour, int brightness) { @@ -112,7 +112,7 @@ unsigned int brightness(unsigned int colour, int brightness) } // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### unsigned int rainbow(byte value) { diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Custom_Fonts/TFT_Custom_Fonts.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Custom_Fonts/TFT_Custom_Fonts.ino index b6051234..6485e755 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Custom_Fonts/TFT_Custom_Fonts.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Custom_Fonts/TFT_Custom_Fonts.ino @@ -19,7 +19,7 @@ ######################################################################### */ -// Note the the tilde symbol ~ does not exist in some fonts at the moment +// Note the the tilda symbol ~ does not exist in some fonts at the moment #define TEXT "abc MWy 123 |" // Text that will be printed on screen in any font #include "SPI.h" diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_FillArcSpiral/TFT_FillArcSpiral.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_FillArcSpiral/TFT_FillArcSpiral.ino index 9ea0d7cb..83b8f609 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_FillArcSpiral/TFT_FillArcSpiral.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_FillArcSpiral/TFT_FillArcSpiral.ino @@ -13,7 +13,7 @@ int segment = 0; unsigned int col = 0; int delta = -1; - byte red = 31; // Red is the top 5 bits of a 16-bit colour value + byte red = 31; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits byte state = 0; @@ -48,7 +48,7 @@ void loop() { // rx = x axis radius // yx = y axis radius // w = width (thickness) of arc in pixels -// colour = 16-bit colour value +// colour = 16 bit colour value // Note if rx and ry are the same an arc of a circle is drawn void fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour) @@ -82,7 +82,7 @@ void fillArc(int x, int y, int start_angle, int seg_count, int rx, int ry, int w } // ######################################################################### -// Return a 16-bit colour with brightness 0 - 100% +// Return a 16 bit colour with brightness 0 - 100% // ######################################################################### unsigned int brightness(unsigned int colour, int brightness) { @@ -98,7 +98,7 @@ unsigned int brightness(unsigned int colour, int brightness) } // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### unsigned int rainbow(byte value) { diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Mandlebrot/TFT_Mandlebrot.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Mandlebrot/TFT_Mandlebrot.ino index c4911922..2a04556b 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Mandlebrot/TFT_Mandlebrot.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Mandlebrot/TFT_Mandlebrot.ino @@ -62,7 +62,7 @@ unsigned int rainbow(int value) // Value is expected to be in range 0-127 // The value is converted to a spectrum colour from 0 = blue through to red = blue - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Meter_linear/TFT_Meter_linear.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Meter_linear/TFT_Meter_linear.ino index aa9521da..9d624855 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Meter_linear/TFT_Meter_linear.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Meter_linear/TFT_Meter_linear.ino @@ -47,7 +47,7 @@ void setup(void) { void loop() { if (updateTime <= millis()) { - updateTime = millis() + 35; // Update meter every 35 milliseconds + updateTime = millis() + 35; // Update emter every 35 milliseconds // Create a Sine wave for testing d += 4; if (d >= 360) d = 0; @@ -75,7 +75,7 @@ void analogMeter() // Long scale tick length int tl = 15; - // Coordinates of tick to draw + // Coodinates of tick to draw float sx = cos((i - 90) * 0.0174532925); float sy = sin((i - 90) * 0.0174532925); uint16_t x0 = sx * (M_SIZE*100 + tl) + M_SIZE*120; @@ -175,7 +175,7 @@ void plotNeedle(int value, byte ms_delay) if (ms_delay == 0) old_analog = value; // Update immediately if delay is 0 float sdeg = map(old_analog, -10, 110, -150, -30); // Map value to angle - // Calculate tip of needle coords + // Calcualte tip of needle coords float sx = cos(sdeg * 0.0174532925); float sy = sin(sdeg * 0.0174532925); diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Meters/TFT_Meters.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Meters/TFT_Meters.ino index 094f476e..419b1f5c 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Meters/TFT_Meters.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Meters/TFT_Meters.ino @@ -95,7 +95,7 @@ void analogMeter() // Long scale tick length int tl = 15; - // Coordinates of tick to draw + // Coodinates of tick to draw float sx = cos((i - 90) * 0.0174532925); float sy = sin((i - 90) * 0.0174532925); uint16_t x0 = sx * (100 + tl) + 120; @@ -195,7 +195,7 @@ void plotNeedle(int value, byte ms_delay) if (ms_delay == 0) old_analog = value; // Update immediately id delay is 0 float sdeg = map(old_analog, -10, 110, -150, -30); // Map value to angle - // Calculate tip of needle coords + // Calcualte tip of needle coords float sx = cos(sdeg * 0.0174532925); float sy = sin(sdeg * 0.0174532925); diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Pie_Chart/TFT_Pie_Chart.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Pie_Chart/TFT_Pie_Chart.ino index cd4fdb2c..b2390494 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Pie_Chart/TFT_Pie_Chart.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Pie_Chart/TFT_Pie_Chart.ino @@ -44,7 +44,7 @@ void loop() { // start_angle = 0 - 359 // sub_angle = 0 - 360 = subtended angle // r = radius -// colour = 16-bit colour value +// colour = 16 bit colour value int fillSegment(int x, int y, int start_angle, int sub_angle, int r, unsigned int colour) { @@ -63,7 +63,7 @@ int fillSegment(int x, int y, int start_angle, int sub_angle, int r, unsigned in tft.fillTriangle(x1, y1, x2, y2, x, y, colour); - // Copy segment end to segment start for next segment + // Copy segment end to sgement start for next segment x1 = x2; y1 = y2; } @@ -71,7 +71,7 @@ int fillSegment(int x, int y, int start_angle, int sub_angle, int r, unsigned in // ######################################################################### -// Return the 16-bit colour with brightness 0-100% +// Return the 16 bit colour with brightness 0-100% // ######################################################################### unsigned int brightness(unsigned int colour, int brightness) { diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Print_Test/TFT_Print_Test.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Print_Test/TFT_Print_Test.ino index 03af064d..9caecbb1 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Print_Test/TFT_Print_Test.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Print_Test/TFT_Print_Test.ino @@ -1,5 +1,5 @@ /* - Test the tft.print() viz. embedded tft.write() function + Test the tft.print() viz embedded tft.write() function This sketch used font 2, 4, 7 diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Rainbow_one_lib/TFT_Rainbow_one_lib.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Rainbow_one_lib/TFT_Rainbow_one_lib.ino index 55cc3656..88180fd3 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Rainbow_one_lib/TFT_Rainbow_one_lib.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Rainbow_one_lib/TFT_Rainbow_one_lib.ino @@ -53,7 +53,7 @@ void loop() { // The new larger fonts do not need to use the .setCursor call, coords are embedded tft.setTextColor(TFT_BLACK); // Do not plot the background colour - // Overlay the black text on top of the rainbow plot (the advantage of not drawing the background colour!) + // Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!) tft.drawCentreString("Font size 2", 120, 14, 2); // Draw text centre at position 120, 14 using font 2 tft.drawCentreString("Font size 4", 120, 30, 4); // Draw text centre at position 120, 30 using font 4 tft.drawCentreString("12.34", 120, 54, 6); // Draw text centre at position 120, 54 using font 6 @@ -98,7 +98,7 @@ void loop() { // Fill screen with a rainbow pattern void rainbow_fill() { - // The colours and state are not initialised so the start colour changes each time the function is called + // The colours and state are not initialised so the start colour changes each time the funtion is called for (int i = 319; i > 0; i--) { // Draw a vertical line 1 pixel wide in the selected colour diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Read_Reg/TFT_Read_Reg.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Read_Reg/TFT_Read_Reg.ino index 4a433d6c..d622e44e 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Read_Reg/TFT_Read_Reg.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Read_Reg/TFT_Read_Reg.ino @@ -56,7 +56,7 @@ void loop() { printSubset(); // Print a useful subset of the readable registers - readTest(); // Test 8, 16 and 32-bit reads and index on the ID register + readTest(); // Test 8, 16 and 32 bit reads and index on the ID register //printRange32(0x00, 0xFF); // Print a range of registers (32 bits, index = 0) @@ -70,8 +70,8 @@ void loop() { void readTest(void) { - Serial.println(); Serial.println("Test 8, 16 and 32-bit reads and the index..."); - // Test 8, 16 and 32-bit reads and index + Serial.println(); Serial.println("Test 8, 16 and 32 bit reads and the index..."); + // Test 8, 16 and 32 bit reads and index // Note at index 0 the register values are typically undefined (Bxxxxxxxx) Serial.println(tft.readcommand8(ILI9341_RDID4, 2), HEX); Serial.println(tft.readcommand16(ILI9341_RDID4, 2), HEX); diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Spiro/TFT_Spiro.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Spiro/TFT_Spiro.ino index fddf0af5..3e7f8d7d 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Spiro/TFT_Spiro.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Spiro/TFT_Spiro.ino @@ -1,5 +1,5 @@ // Spiro -// Rainbow pattern generator +// Rainbow patern generator #include // Hardware-specific library #include @@ -67,7 +67,7 @@ unsigned int rainbow(int value) // Value is expected to be in range 0-127 // The value is converted to a spectrum colour from 0 = blue through to red = blue //int value = random (128); - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Starfield/TFT_Starfield.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Starfield/TFT_Starfield.ino index f8891f2c..1e721979 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Starfield/TFT_Starfield.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Starfield/TFT_Starfield.ino @@ -59,7 +59,7 @@ void loop() int old_screen_x = ((int)sx[i] - 160) * 256 / sz[i] + 160; int old_screen_y = ((int)sy[i] - 120) * 256 / sz[i] + 120; - // This is a faster pixel drawing function for occasions where many single pixels must be drawn + // This is a faster pixel drawing function for occassions where many single pixels must be drawn tft.drawPixel(old_screen_x, old_screen_y,TFT_BLACK); sz[i] -= 2; @@ -82,7 +82,7 @@ void loop() unsigned long t1 = micros(); //static char timeMicros[8] = {}; - // Calculate frames per second + // Calcualte frames per second Serial.println(1.0/((t1 - t0)/1000000.0)); } diff --git a/lib/TFT_eSPI/examples/320 x 240/TFT_Terminal/TFT_Terminal.ino b/lib/TFT_eSPI/examples/320 x 240/TFT_Terminal/TFT_Terminal.ino index bd6b69ea..27fb4f16 100644 --- a/lib/TFT_eSPI/examples/320 x 240/TFT_Terminal/TFT_Terminal.ino +++ b/lib/TFT_eSPI/examples/320 x 240/TFT_Terminal/TFT_Terminal.ino @@ -7,7 +7,7 @@ Connect GND to target board GND Connect RX line to TX line of target board Make sure the target and terminal have the same baud rate - and serial settings! + and serial stettings! The sketch works with the ILI9341 TFT 240x320 display and the called up libraries. diff --git a/lib/TFT_eSPI/examples/480 x 320/Free_Font_Demo/Free_Font_Demo.ino b/lib/TFT_eSPI/examples/480 x 320/Free_Font_Demo/Free_Font_Demo.ino index 569d4844..50c09c13 100644 --- a/lib/TFT_eSPI/examples/480 x 320/Free_Font_Demo/Free_Font_Demo.ino +++ b/lib/TFT_eSPI/examples/480 x 320/Free_Font_Demo/Free_Font_Demo.ino @@ -249,7 +249,7 @@ void drawDatum(int x, int y) // There follows a crude way of flagging that this example sketch needs fonts which -// have not been enabled in the User_Setup.h file inside the TFT_HX8357 library. +// have not been enbabled in the User_Setup.h file inside the TFT_HX8357 library. // // These lines produce errors during compile time if settings in User_Setup are not correct // diff --git a/lib/TFT_eSPI/examples/480 x 320/Keypad_480x320/Keypad_480x320.ino b/lib/TFT_eSPI/examples/480 x 320/Keypad_480x320/Keypad_480x320.ino index b2844aaa..9614d6a7 100644 --- a/lib/TFT_eSPI/examples/480 x 320/Keypad_480x320/Keypad_480x320.ino +++ b/lib/TFT_eSPI/examples/480 x 320/Keypad_480x320/Keypad_480x320.ino @@ -3,8 +3,8 @@ button handling class, this sketch is based on the Arduin-o-phone example. - This example displays a keypad where numbers can be entered and - sent to the Serial Monitor window. + This example diplays a keypad where numbers can be entered and + send to the Serial Monitor window. The sketch has been tested on the ESP8266 (which supports SPIFFS) @@ -167,7 +167,7 @@ void loop(void) { // Update the number display field tft.setTextDatum(TL_DATUM); // Use top left corner as text coord datum - tft.setFreeFont(&FreeSans18pt7b); // Choose a nice font that fits box + tft.setFreeFont(&FreeSans18pt7b); // Choose a nicefont that fits box tft.setTextColor(DISP_TCOLOR); // Set the font colour // Draw the string, the value returned is the width in pixels @@ -212,7 +212,7 @@ void touch_calibrate() // check file system exists if (!SPIFFS.begin()) { - Serial.println("formatting file system"); + Serial.println("Formating file system"); SPIFFS.format(); SPIFFS.begin(); } diff --git a/lib/TFT_eSPI/examples/480 x 320/TFT_Meter_4/TFT_Meter_4.ino b/lib/TFT_eSPI/examples/480 x 320/TFT_Meter_4/TFT_Meter_4.ino index 77a82cb5..11d00d21 100644 --- a/lib/TFT_eSPI/examples/480 x 320/TFT_Meter_4/TFT_Meter_4.ino +++ b/lib/TFT_eSPI/examples/480 x 320/TFT_Meter_4/TFT_Meter_4.ino @@ -49,7 +49,7 @@ void setup(void) { void loop() { if (updateTime <= millis()) { - updateTime = millis() + 35; // Update meter every 35 milliseconds + updateTime = millis() + 35; // Update emter every 35 milliseconds // Create a Sine wave for testing d += 4; if (d >= 360) d = 0; @@ -77,7 +77,7 @@ void analogMeter() // Long scale tick length int tl = 15; - // Coordinates of tick to draw + // Coodinates of tick to draw float sx = cos((i - 90) * 0.0174532925); float sy = sin((i - 90) * 0.0174532925); uint16_t x0 = sx * (M_SIZE*100 + tl) + M_SIZE*120; @@ -177,7 +177,7 @@ void plotNeedle(int value, byte ms_delay) if (ms_delay == 0) old_analog = value; // Update immediately if delay is 0 float sdeg = map(old_analog, -10, 110, -150, -30); // Map value to angle - // Calculate tip of needle coords + // Calcualte tip of needle coords float sx = cos(sdeg * 0.0174532925); float sy = sin(sdeg * 0.0174532925); diff --git a/lib/TFT_eSPI/examples/480 x 320/TFT_Meters/TFT_Meters.ino b/lib/TFT_eSPI/examples/480 x 320/TFT_Meters/TFT_Meters.ino index 007e9548..339fc329 100644 --- a/lib/TFT_eSPI/examples/480 x 320/TFT_Meters/TFT_Meters.ino +++ b/lib/TFT_eSPI/examples/480 x 320/TFT_Meters/TFT_Meters.ino @@ -97,7 +97,7 @@ void analogMeter() // Long scale tick length int tl = 15; - // Coordinates of tick to draw + // Coodinates of tick to draw float sx = cos((i - 90) * 0.0174532925); float sy = sin((i - 90) * 0.0174532925); uint16_t x0 = sx * (100 + tl) + 120; @@ -197,7 +197,7 @@ void plotNeedle(int value, byte ms_delay) if (ms_delay == 0) old_analog = value; // Update immediately id delay is 0 float sdeg = map(old_analog, -10, 110, -150, -30); // Map value to angle - // Calculate tip of needle coords + // Calcualte tip of needle coords float sx = cos(sdeg * 0.0174532925); float sy = sin(sdeg * 0.0174532925); diff --git a/lib/TFT_eSPI/examples/480 x 320/TFT_Print_Test/TFT_Print_Test.ino b/lib/TFT_eSPI/examples/480 x 320/TFT_Print_Test/TFT_Print_Test.ino index f1ee3f99..14f75b32 100644 --- a/lib/TFT_eSPI/examples/480 x 320/TFT_Print_Test/TFT_Print_Test.ino +++ b/lib/TFT_eSPI/examples/480 x 320/TFT_Print_Test/TFT_Print_Test.ino @@ -1,5 +1,5 @@ /* - Test the tft.print() viz. the libraries embedded write() function + Test the tft.print() viz the libraries embedded write() function This sketch used font 2, 4, 7 diff --git a/lib/TFT_eSPI/examples/480 x 320/TFT_Rainbow480/TFT_Rainbow480.ino b/lib/TFT_eSPI/examples/480 x 320/TFT_Rainbow480/TFT_Rainbow480.ino index e1d5f4c3..a2e1aa1c 100644 --- a/lib/TFT_eSPI/examples/480 x 320/TFT_Rainbow480/TFT_Rainbow480.ino +++ b/lib/TFT_eSPI/examples/480 x 320/TFT_Rainbow480/TFT_Rainbow480.ino @@ -50,7 +50,7 @@ void loop() { // The new larger fonts do not need to use the .setCursor call, coords are embedded tft.setTextColor(TFT_BLACK); // Do not plot the background colour - // Overlay the black text on top of the rainbow plot (the advantage of not drawing the background colour!) + // Overlay the black text on top of the rainbow plot (the advantage of not drawing the backgorund colour!) tft.drawCentreString("Font size 2", 160, 14, 2); // Draw text centre at position 120, 14 using font 2 tft.drawCentreString("Font size 4", 160, 30, 4); // Draw text centre at position 120, 30 using font 4 tft.drawCentreString("12.34", 160, 54, 6); // Draw text centre at position 120, 54 using font 6 @@ -100,7 +100,7 @@ void loop() { // Fill screen with a rainbow pattern void rainbow_fill() { - // The colours and state are not initialised so the start colour changes each time the function is called + // The colours and state are not initialised so the start colour changes each time the funtion is called for (int i = 479; i > 0; i--) { // Draw a vertical line 1 pixel wide in the selected colour diff --git a/lib/TFT_eSPI/examples/480 x 320/TFT_flash_jpg/TFT_flash_jpg.ino b/lib/TFT_eSPI/examples/480 x 320/TFT_flash_jpg/TFT_flash_jpg.ino index c00611b4..f8ebcb14 100644 --- a/lib/TFT_eSPI/examples/480 x 320/TFT_flash_jpg/TFT_flash_jpg.ino +++ b/lib/TFT_eSPI/examples/480 x 320/TFT_flash_jpg/TFT_flash_jpg.ino @@ -1,8 +1,8 @@ // Sketch to display images on a 480 x 320 ILI9486 Raspberry Pi 3.5" TFT (Waveshare design) -// which has a 16-bit serial interface based on 74HC04, 74HC4040 and 2 x 74HC4094 logic chips +// which has a 16 bit serial interface based on 74HC04, 74HC4040 and 2 x 74HC4094 logic chips // Renders images stored in an array in program (FLASH)JPEG images are stored in header files -// (see jpeg1.h etc.) +// (see jpeg1.h etc) // The sketch does not need the SD or sdFat libraries since it does not access an SD Card. @@ -108,7 +108,7 @@ void drawArrayJpeg(const uint8_t arrayname[], uint32_t array_size, int xpos, int // fit totally on the screen are cropped to the nearest MCU size and may leave right/bottom borders. void renderJPEG(int xpos, int ypos) { - // retrieve information about the image + // retrieve infomration about the image uint16_t *pImg; uint16_t mcu_w = JpegDec.MCUWidth; uint16_t mcu_h = JpegDec.MCUHeight; @@ -222,7 +222,7 @@ void jpegInfo() { // Show the execution time (optional) //#################################################################################################### // WARNING: for UNO/AVR legacy reasons printing text to the screen with the Mega might not work for -// sketch sizes greater than ~70KBytes because 16-bit address pointers are used in some libraries. +// sketch sizes greater than ~70KBytes because 16 bit address pointers are used in some libraries. // The Due will work fine with the HX8357_Due library. diff --git a/lib/TFT_eSPI/examples/480 x 320/TFT_ring_meter/TFT_ring_meter.ino b/lib/TFT_eSPI/examples/480 x 320/TFT_ring_meter/TFT_ring_meter.ino index bdd9bb37..bbd1834d 100644 --- a/lib/TFT_eSPI/examples/480 x 320/TFT_ring_meter/TFT_ring_meter.ino +++ b/lib/TFT_eSPI/examples/480 x 320/TFT_ring_meter/TFT_ring_meter.ino @@ -13,7 +13,7 @@ #define GREEN2RED 4 #define RED2GREEN 5 -#define TFT_GREY 0x2104 // Dark grey 16-bit colour +#define TFT_GREY 0x2104 // Dark grey 16 bit colour #include "Alert.h" // Out of range alert icon @@ -127,8 +127,8 @@ int ringMeter(int value, int vmin, int vmax, int x, int y, int r, const char *un case 1: colour = TFT_GREEN; break; // Fixed colour case 2: colour = TFT_BLUE; break; // Fixed colour case 3: colour = rainbow(map(i, -angle, angle, 0, 127)); break; // Full spectrum blue to red - case 4: colour = rainbow(map(i, -angle, angle, 70, 127)); break; // Green to red (high temperature etc.) - case 5: colour = rainbow(map(i, -angle, angle, 127, 63)); break; // Red to green (low battery etc.) + case 4: colour = rainbow(map(i, -angle, angle, 70, 127)); break; // Green to red (high temperature etc) + case 5: colour = rainbow(map(i, -angle, angle, 127, 63)); break; // Red to green (low battery etc) default: colour = TFT_BLUE; break; // Fixed colour } tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour); @@ -193,14 +193,14 @@ void drawAlert(int x, int y , int side, bool draw) } // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### unsigned int rainbow(byte value) { // Value is expected to be in range 0-127 // The value is converted to a spectrum colour from 0 = blue through to 127 = red - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/480 x 320/Touch_Controller_Demo/Touch_Controller_Demo.ino b/lib/TFT_eSPI/examples/480 x 320/Touch_Controller_Demo/Touch_Controller_Demo.ino index e339a329..f0b14d8a 100644 --- a/lib/TFT_eSPI/examples/480 x 320/Touch_Controller_Demo/Touch_Controller_Demo.ino +++ b/lib/TFT_eSPI/examples/480 x 320/Touch_Controller_Demo/Touch_Controller_Demo.ino @@ -23,7 +23,7 @@ void setup(void) { // check file system if (!SPIFFS.begin()) { - Serial.println("formatting file system"); + Serial.println("formating file system"); SPIFFS.format(); SPIFFS.begin(); diff --git a/lib/TFT_eSPI/examples/DMA test/Bouncy_Circles/Bouncy_Circles.ino b/lib/TFT_eSPI/examples/DMA test/Bouncy_Circles/Bouncy_Circles.ino index e2a661ea..43d10bb5 100644 --- a/lib/TFT_eSPI/examples/DMA test/Bouncy_Circles/Bouncy_Circles.ino +++ b/lib/TFT_eSPI/examples/DMA test/Bouncy_Circles/Bouncy_Circles.ino @@ -153,7 +153,7 @@ void drawUpdate (bool sel) { } // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### uint16_t rainbow(byte value) { @@ -163,7 +163,7 @@ uint16_t rainbow(byte value) value = value % 192; - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0; // Green is the middle 6 bits, but only top 5 bits used here byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/DMA test/SpriteRotatingCube/SpriteRotatingCube.ino b/lib/TFT_eSPI/examples/DMA test/SpriteRotatingCube/SpriteRotatingCube.ino index a57ed6bb..0b9590fc 100644 --- a/lib/TFT_eSPI/examples/DMA test/SpriteRotatingCube/SpriteRotatingCube.ino +++ b/lib/TFT_eSPI/examples/DMA test/SpriteRotatingCube/SpriteRotatingCube.ino @@ -2,7 +2,7 @@ // https://en.wikipedia.org/wiki/Direct_memory_access // Tested with ESP32, Nucleo 64 STM32F446RE and Nucleo 144 STM32F767ZI -// TFT's with SPI can use DMA, the sketch also works with 8-bit +// TFT's with SPI can use DMA, the sketch also works with 8 bit // parallel TFT's (tested with ILI9341 and ILI9481) // The sketch will run on processors without DMA and also parallel @@ -36,7 +36,7 @@ // Color depth has to be 16 bits if DMA is used to render image #define COLOR_DEPTH 16 -// 128x128 for a 16-bit colour Sprite (32Kbytes RAM) +// 128x128 for a 16 bit colour Sprite (32Kbytes RAM) // Maximum is 181x181 (64Kbytes) for DMA - restricted by processor design #define IWIDTH 128 #define IHEIGHT 128 diff --git a/lib/TFT_eSPI/examples/DMA test/boing_ball/boing_ball.ino b/lib/TFT_eSPI/examples/DMA test/boing_ball/boing_ball.ino index a6e5e707..36dbb777 100644 --- a/lib/TFT_eSPI/examples/DMA test/boing_ball/boing_ball.ino +++ b/lib/TFT_eSPI/examples/DMA test/boing_ball/boing_ball.ino @@ -19,7 +19,7 @@ // Blue Pill overclocked to 128MHz *no* DMA - 32MHz SPI 64 fps // Blue Pill overclocked to 128MHz with DMA - 32MHz SPI 116 fps -// ESP32 - 8-bit parallel 110 fps (no DMA) +// ESP32 - 8 bit parallel 110 fps (no DMA) // ESP32 - 40MHz SPI *no* DMA 93 fps // ESP32 - 40MHz SPI with DMA 112 fps diff --git a/lib/TFT_eSPI/examples/GUI Widgets/Buttons/Button_demo/Button_demo.ino b/lib/TFT_eSPI/examples/GUI Widgets/Buttons/Button_demo/Button_demo.ino index b8643385..47f54649 100644 --- a/lib/TFT_eSPI/examples/GUI Widgets/Buttons/Button_demo/Button_demo.ino +++ b/lib/TFT_eSPI/examples/GUI Widgets/Buttons/Button_demo/Button_demo.ino @@ -132,7 +132,7 @@ void touch_calibrate() // check file system exists if (!LittleFS.begin()) { - Serial.println("formatting file system"); + Serial.println("Formating file system"); LittleFS.format(); LittleFS.begin(); } diff --git a/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_1/Graph_demo_1.ino b/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_1/Graph_demo_1.ino index 5e9f74f2..e3020c4d 100644 --- a/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_1/Graph_demo_1.ino +++ b/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_1/Graph_demo_1.ino @@ -66,7 +66,7 @@ void loop() { if (gy < -500.0) delta = 10.0; gy += delta; - // If the end of the graph x axis is reached start a new trace at 0.0,0.0 + // If the end of the graph x ais is reached start a new trace at 0.0,0.0 if (gx > gxHigh) { gx = 0.0; gy = 0.0; diff --git a/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_2/Graph_demo_2.ino b/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_2/Graph_demo_2.ino index a7eb3cdd..ff540ca5 100644 --- a/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_2/Graph_demo_2.ino +++ b/lib/TFT_eSPI/examples/GUI Widgets/Graphs/Graph_demo_2/Graph_demo_2.ino @@ -1,4 +1,4 @@ -// Demonstrate graph widget functions with two independent trace instances +// Demonstrate graph widget functions with two independant trace instances // Multiple traces can be drawn at a time with multiple trace instances // Note: Traces are automatically clipped at graph boundaries by widget library diff --git a/lib/TFT_eSPI/examples/GUI Widgets/Sliders/Slider_demo/Slider_demo.ino b/lib/TFT_eSPI/examples/GUI Widgets/Sliders/Slider_demo/Slider_demo.ino index 7e8e6ce0..a31d9358 100644 --- a/lib/TFT_eSPI/examples/GUI Widgets/Sliders/Slider_demo/Slider_demo.ino +++ b/lib/TFT_eSPI/examples/GUI Widgets/Sliders/Slider_demo/Slider_demo.ino @@ -142,7 +142,7 @@ void touch_calibrate() // check file system exists if (!LittleFS.begin()) { - Serial.println("formatting file system"); + Serial.println("Formating file system"); LittleFS.format(); LittleFS.begin(); } diff --git a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/config.h b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/config.h index d601d648..b99db415 100644 --- a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/config.h +++ b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/config.h @@ -64,7 +64,7 @@ // JOYSTICK_X_PIN and JOYSTICK_Y_PIN specify analog input pins for manually // controlling the eye with an analog joystick. If set to -1 or if not // defined, the eye will move on its own. -// IRIS_PIN specifies an analog input pin for a photocell to make pupils +// IRIS_PIN speficies an analog input pin for a photocell to make pupils // react to light (or potentiometer for manual control). If set to -1 or // if not defined, the pupils will change on their own. // BLINK_PIN specifies an input pin for a button (to ground) that will diff --git a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/eye_functions.ino b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/eye_functions.ino index 2db27dc0..96a583ef 100644 --- a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/eye_functions.ino +++ b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_1/eye_functions.ino @@ -11,7 +11,7 @@ // boards and WILL NOT work on normal Arduino or other boards! // // SEE FILE "config.h" FOR MOST CONFIGURATION (graphics, pins, display type, -// etc.). Probably won't need to edit THIS file unless you're doing some +// etc). Probably won't need to edit THIS file unless you're doing some // extremely custom modifications. // // Adafruit invests time and resources providing this open source code, @@ -91,7 +91,7 @@ void updateEye (void) // EYE-RENDERING FUNCTION -------------------------------------------------- void drawEye( // Renders one eye. Inputs must be pre-clipped & valid. - // Use native 32-bit variables where possible as this is 10% faster! + // Use native 32 bit variables where possible as this is 10% faster! uint8_t e, // Eye array index; 0 or 1 for left/right uint32_t iScale, // Scale factor for iris uint32_t scleraX, // First pixel X offset into sclera image diff --git a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/config.h b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/config.h index d519c9ff..e7e29e26 100644 --- a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/config.h +++ b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/config.h @@ -64,7 +64,7 @@ // JOYSTICK_X_PIN and JOYSTICK_Y_PIN specify analog input pins for manually // controlling the eye with an analog joystick. If set to -1 or if not // defined, the eye will move on its own. -// IRIS_PIN specifies an analog input pin for a photocell to make pupils +// IRIS_PIN speficies an analog input pin for a photocell to make pupils // react to light (or potentiometer for manual control). If set to -1 or // if not defined, the pupils will change on their own. // BLINK_PIN specifies an input pin for a button (to ground) that will diff --git a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/eye_functions.ino b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/eye_functions.ino index 2db27dc0..96a583ef 100644 --- a/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/eye_functions.ino +++ b/lib/TFT_eSPI/examples/Generic/Animated_Eyes_2/eye_functions.ino @@ -11,7 +11,7 @@ // boards and WILL NOT work on normal Arduino or other boards! // // SEE FILE "config.h" FOR MOST CONFIGURATION (graphics, pins, display type, -// etc.). Probably won't need to edit THIS file unless you're doing some +// etc). Probably won't need to edit THIS file unless you're doing some // extremely custom modifications. // // Adafruit invests time and resources providing this open source code, @@ -91,7 +91,7 @@ void updateEye (void) // EYE-RENDERING FUNCTION -------------------------------------------------- void drawEye( // Renders one eye. Inputs must be pre-clipped & valid. - // Use native 32-bit variables where possible as this is 10% faster! + // Use native 32 bit variables where possible as this is 10% faster! uint8_t e, // Eye array index; 0 or 1 for left/right uint32_t iScale, // Scale factor for iris uint32_t scleraX, // First pixel X offset into sclera image diff --git a/lib/TFT_eSPI/examples/Generic/ESP32_SDcard_jpeg/ESP32_SDcard_jpeg.ino b/lib/TFT_eSPI/examples/Generic/ESP32_SDcard_jpeg/ESP32_SDcard_jpeg.ino index d64775c8..3c30f1d7 100644 --- a/lib/TFT_eSPI/examples/Generic/ESP32_SDcard_jpeg/ESP32_SDcard_jpeg.ino +++ b/lib/TFT_eSPI/examples/Generic/ESP32_SDcard_jpeg/ESP32_SDcard_jpeg.ino @@ -36,7 +36,7 @@ void setup() { tft.begin(); - if (!SD.begin(5, tft.getSPIinstance())) { + if (!SD.begin()) { Serial.println("Card Mount Failed"); return; } @@ -249,7 +249,7 @@ void jpegInfo() { // Show the execution time (optional) //#################################################################################################### // WARNING: for UNO/AVR legacy reasons printing text to the screen with the Mega might not work for -// sketch sizes greater than ~70KBytes because 16-bit address pointers are used in some libraries. +// sketch sizes greater than ~70KBytes because 16 bit address pointers are used in some libraries. // The Due will work fine with the HX8357_Due library. diff --git a/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/ESP8266_uncannyEyes.ino b/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/ESP8266_uncannyEyes.ino index 7cc3db2c..c78e0bff 100644 --- a/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/ESP8266_uncannyEyes.ino +++ b/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/ESP8266_uncannyEyes.ino @@ -120,7 +120,7 @@ void setup(void) { // EYE-RENDERING FUNCTION -------------------------------------------------- #define BUFFER_SIZE 256 // 64 to 512 seems optimum = 30 fps for default eye void drawEye( // Renders one eye. Inputs must be pre-clipped & valid. - // Use native 32-bit variables where possible as this is 10% faster! + // Use native 32 bit variables where possible as this is 10% faster! uint8_t e, // Eye array index; 0 or 1 for left/right uint32_t iScale, // Scale factor for iris uint32_t scleraX, // First pixel X offset into sclera image @@ -134,7 +134,7 @@ void drawEye( // Renders one eye. Inputs must be pre-clipped & valid. uint32_t d; uint32_t pixels = 0; - uint16_t pbuffer[BUFFER_SIZE]; // This one needs to be 16-bit + uint16_t pbuffer[BUFFER_SIZE]; // This one needs to be 16 bit // Set up raw pixel dump to entire screen. Although such writes can wrap // around automatically from end of rect back to beginning, the region is diff --git a/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/screenshotToConsole.ino b/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/screenshotToConsole.ino index 9dd98f3a..daa60ac6 100644 --- a/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/screenshotToConsole.ino +++ b/lib/TFT_eSPI/examples/Generic/ESP8266_uncannyEyes/screenshotToConsole.ino @@ -58,7 +58,7 @@ void screenshotToConsole() // Get first pixel to prime the Run Length Encoded // Function format is: tft.readRectRGB( x, y, width, height, buffer); - // color is a pointer to a buffer that the RGB 8-bit values are piped into + // color is a pointer to a buffer that the RGB 8 bit values are piped into // the buffer size must be >= (width * height * 3) bytes eye[e].tft.readRectRGB(0, 0, 1, 1, color); // 1 x 1 so reading 1 pixel at 0,0 diff --git a/lib/TFT_eSPI/examples/Generic/TFT_Flash_Bitmap/TFT_Flash_Bitmap.ino b/lib/TFT_eSPI/examples/Generic/TFT_Flash_Bitmap/TFT_Flash_Bitmap.ino index 14d52db9..cde4ecb9 100644 --- a/lib/TFT_eSPI/examples/Generic/TFT_Flash_Bitmap/TFT_Flash_Bitmap.ino +++ b/lib/TFT_eSPI/examples/Generic/TFT_Flash_Bitmap/TFT_Flash_Bitmap.ino @@ -1,4 +1,4 @@ -// Icon images are stored in tabs ^ e.g. Alert.h etc.above this line +// Icon images are stored in tabs ^ e.g. Alert.h etc above this line // more than one icon can be in a header file // Arrays containing FLASH images can be created with UTFT library tool: diff --git a/lib/TFT_eSPI/examples/Generic/TFT_SPIFFS_BMP/BMP_functions.ino b/lib/TFT_eSPI/examples/Generic/TFT_SPIFFS_BMP/BMP_functions.ino index 1d9de1e8..b3905e9d 100644 --- a/lib/TFT_eSPI/examples/Generic/TFT_SPIFFS_BMP/BMP_functions.ino +++ b/lib/TFT_eSPI/examples/Generic/TFT_SPIFFS_BMP/BMP_functions.ino @@ -46,7 +46,7 @@ void drawBmp(const char *filename, int16_t x, int16_t y) { bmpFS.read(lineBuffer, sizeof(lineBuffer)); uint8_t* bptr = lineBuffer; uint16_t* tptr = (uint16_t*)lineBuffer; - // Convert 24 to 16-bit colours + // Convert 24 to 16 bit colours for (uint16_t col = 0; col < w; col++) { b = *bptr++; diff --git a/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/processing_sketch.ino b/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/processing_sketch.ino index d657a080..3e71f41f 100644 --- a/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/processing_sketch.ino +++ b/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/processing_sketch.ino @@ -63,7 +63,7 @@ int max_allowed = 1000; // Maximum number of save images allowed before a resta // These are default values, this sketch obtains the actual values from the Arduino board int tft_width = 480; // default TFT width (automatic - sent by Arduino) int tft_height = 480; // default TFT height (automatic - sent by Arduino) -int color_bytes = 2; // 2 for 16-bit, 3 for three RGB bytes (automatic - sent by Arduino) +int color_bytes = 2; // 2 for 16 bit, 3 for three RGB bytes (automatic - sent by Arduino) import processing.serial.*; diff --git a/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/screenServer.ino b/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/screenServer.ino index 733c4ffc..82bbbd7d 100644 --- a/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/screenServer.ino +++ b/lib/TFT_eSPI/examples/Generic/TFT_Screen_Capture/screenServer.ino @@ -2,8 +2,8 @@ // over the serial port. Use a high baud rate, e.g. for an ESP8266: // Serial.begin(921600); -// At 921600 baud a 320 x 240 image with 16-bit colour transfers can be sent to the -// PC client in ~1.67s and 24-bit colour in ~2.5s which is close to the theoretical +// At 921600 baud a 320 x 240 image with 16 bit colour transfers can be sent to the +// PC client in ~1.67s and 24 bit colour in ~2.5s which is close to the theoretical // minimum transfer time. // This sketch has been created to work with the TFT_eSPI library here: @@ -40,7 +40,7 @@ // Number of pixels to send in a burst (minimum of 1), no benefit above 8 // NPIXELS values and render times: -// NPIXELS 1 = use readPixel() = >5s and 16-bit pixels only +// NPIXELS 1 = use readPixel() = >5s and 16 bit pixels only // NPIXELS >1 using rectRead() 2 = 1.75s, 4 = 1.68s, 8 = 1.67s #define NPIXELS 8 // Must be integer division of both TFT width and TFT height @@ -104,7 +104,7 @@ bool serialScreenServer(String filename) wait = false; // No need to wait anymore lastCmdTime = millis(); // Set last received command time - // Send screen size etc.using a simple header with delimiters for client checks + // Send screen size etc using a simple header with delimiters for client checks sendParameters(filename); } } @@ -169,7 +169,7 @@ bool serialScreenServer(String filename) } //==================================================================================== -// Send screen size etc.using a simple header with delimiters for client checks +// Send screen size etc using a simple header with delimiters for client checks //==================================================================================== void sendParameters(String filename) { @@ -183,7 +183,7 @@ void sendParameters(String filename) Serial.write('Y'); // Bits per pixel (16 or 24) if (NPIXELS > 1) Serial.write(BITS_PER_PIXEL); - else Serial.write(16); // readPixel() only provides 16-bit values + else Serial.write(16); // readPixel() only provides 16 bit values Serial.write('?'); // Filename next Serial.print(filename); diff --git a/lib/TFT_eSPI/examples/Generic/Viewport_Demo/Viewport_Demo.ino b/lib/TFT_eSPI/examples/Generic/Viewport_Demo/Viewport_Demo.ino index 07d43df6..83916520 100644 --- a/lib/TFT_eSPI/examples/Generic/Viewport_Demo/Viewport_Demo.ino +++ b/lib/TFT_eSPI/examples/Generic/Viewport_Demo/Viewport_Demo.ino @@ -10,7 +10,7 @@ // Viewports have a number of potential uses: // - create a "virtual" TFT screen smaller than the actual TFT screen -// - render GUI items (menus etc.) in a viewport, erase GUI item by redrawing whole screen, +// - render GUI items (menus etc) in a viewport, erase GUI item by redrawing whole screen, // this will be fast because only the viewport will be refreshed (e.g. clearing menu) // - limit screen refresh to a particular area, e.g. changing numbers, icons or graph plotting // - showing a small portion of a larger image or sprite, this allows panning and scrolling diff --git a/lib/TFT_eSPI/examples/Generic/alphaBlend_Test/alphaBlend_Test.ino b/lib/TFT_eSPI/examples/Generic/alphaBlend_Test/alphaBlend_Test.ino index a436dcc5..f267195f 100644 --- a/lib/TFT_eSPI/examples/Generic/alphaBlend_Test/alphaBlend_Test.ino +++ b/lib/TFT_eSPI/examples/Generic/alphaBlend_Test/alphaBlend_Test.ino @@ -6,7 +6,7 @@ blendedColor = tft.alphaBlend(alpha, fg_color, bg_color); - The alphaBlend() function operates on 16-bit colours only + The alphaBlend() function operates on 16 bit colours only A test is included where the colours are mapped to 8 bits after blending Information on alpha blending is here @@ -43,7 +43,7 @@ void setup(void) { // ------------------------------------------------------------------------- void loop() { - // 16-bit colours (5 bits red, 6 bits green, 5 bits blue) + // 16 bit colours (5 bits red, 6 bits green, 5 bits blue) // Blend from white to full spectrum for (int a = 0; a < 256; a+=2) // Alpha 0 = 100% background, alpha 255 = 100% foreground { @@ -79,18 +79,18 @@ void loop() delay(4000); //* - // Decrease to 8-bit colour (3 bits red, 3 bits green, 2 bits blue) + // Decrease to 8 bit colour (3 bits red, 3 bits green, 2 bits blue) // Blend from white to full spectrum for (int a = 0; a < 256; a+=2) // Alpha 0 = 100% background, alpha 255 = 100% foreground { - // Convert blended 16-bit colour to 8 bits to reduce colour resolution, then map back to 16 bits for displaying + // Convert blended 16 bit colour to 8 bits to reduce colour resolution, then map back to 16 bits for displaying for (int c = 0; c < 192; c++) tft.drawPixel(c, a/2, tft.color8to16(tft.color16to8(tft.alphaBlend(a, rainbow(c), 0xFFFF)))); } // Blend from full spectrum to black for (int a = 255; a > 2; a-=2) { - // Convert blended 16-bit colour to 8 bits to reduce colour resolution, then map back to 16 bits for displaying + // Convert blended 16 bit colour to 8 bits to reduce colour resolution, then map back to 16 bits for displaying for (int c = 0; c < 192; c++) tft.drawPixel(c, 128 + (255-a)/2, tft.color8to16(tft.color16to8(tft.alphaBlend(a, rainbow(c), 0)))); } @@ -108,7 +108,7 @@ void loop() //*/ /* - // 16-bit colours (5 bits red, 6 bits green, 5 bits blue) + // 16 bit colours (5 bits red, 6 bits green, 5 bits blue) for (int a = 0; a < 256; a+=2) // Alpha 0 = 100% background, alpha 255 = 100% foreground { for (int c = 0; c < 192; c++) tft.drawPixel(c, a/2, tft.alphaBlend(a, rainbow(c), TFT_CYAN)); @@ -137,7 +137,7 @@ void loop() // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### unsigned int rainbow(byte value) { @@ -147,7 +147,7 @@ unsigned int rainbow(byte value) value = value%192; - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0; // Green is the middle 6 bits, but only top 5 bits used here byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/PNG Images/Flash_PNG/Flash_PNG.ino b/lib/TFT_eSPI/examples/PNG Images/Flash_PNG/Flash_PNG.ino index 91d71bf2..ca05753b 100644 --- a/lib/TFT_eSPI/examples/PNG Images/Flash_PNG/Flash_PNG.ino +++ b/lib/TFT_eSPI/examples/PNG Images/Flash_PNG/Flash_PNG.ino @@ -2,10 +2,6 @@ // This example renders a png file that is stored in a FLASH array // using the PNGdec library (available via library manager). -// Note: The PNGDEC required lots of RAM to work (~40kbytes) so -// this sketch is will not run on smaller memory processors (e.g. -// ESP8266, STM32F103 etc.) - // Image files can be converted to arrays using the tool here: // https://notisrac.github.io/FileToCArray/ // To use this tool: @@ -18,9 +14,9 @@ // Include the PNG decoder library #include -#include "panda.h" // Image is stored here in an 8-bit array +#include "panda.h" // Image is stored here in an 8 bit array -PNG png; // PNG decoder instance +PNG png; // PNG decoder inatance #define MAX_IMAGE_WIDTH 240 // Adjust for your images diff --git a/lib/TFT_eSPI/examples/PNG Images/Flash_transparent_PNG/Flash_transparent_PNG.ino b/lib/TFT_eSPI/examples/PNG Images/Flash_transparent_PNG/Flash_transparent_PNG.ino index 366e3296..39e09a66 100644 --- a/lib/TFT_eSPI/examples/PNG Images/Flash_transparent_PNG/Flash_transparent_PNG.ino +++ b/lib/TFT_eSPI/examples/PNG Images/Flash_transparent_PNG/Flash_transparent_PNG.ino @@ -2,10 +2,6 @@ // This example renders a png file that is stored in a FLASH array // using the PNGdec library (available via library manager). -// Note: The PNGDEC required lots of RAM to work (~40kbytes) so -// this sketch is will not run on smaller memory processors (e.g. -// ESP8266, STM32F103 etc.) - // The example png is encoded as ARGB 8 bits per pixel with indexed colour // It was created using GIMP and has a transparent background area. diff --git a/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG/LittleFS_PNG.ino b/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG/LittleFS_PNG.ino index 18040b8a..9af73b85 100644 --- a/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG/LittleFS_PNG.ino +++ b/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG/LittleFS_PNG.ino @@ -3,10 +3,6 @@ // ESP32, ESP8266). It renders a png file that is stored in LittleFS // using the PNGdec library (available via library manager). -// Note: The PNGDEC required lots of RAM to work (~40kbytes) so -// this sketch is will not run on smaller memory processors (e.g. -// ESP8266, STM32F103 etc.) - // The test image is in the sketch "data" folder (press Ctrl+K to see it). // You must upload the image to LittleFS using the Arduino IDE Tools Data // Upload menu option (you may need to install extra tools for that). diff --git a/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG_DMA/LittleFS_PNG_DMA.ino b/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG_DMA/LittleFS_PNG_DMA.ino index f40cdfe7..5f751c1d 100644 --- a/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG_DMA/LittleFS_PNG_DMA.ino +++ b/lib/TFT_eSPI/examples/PNG Images/LittleFS_PNG_DMA/LittleFS_PNG_DMA.ino @@ -3,10 +3,6 @@ // ESP32, ESP8266). It renders a png file that is stored in LittleFS // using the PNGdec library (available via library manager). -// Note: The PNGDEC required lots of RAM to work (~40kbytes) so -// this sketch is will not run on smaller memory processors (e.g. -// ESP8266, STM32F103 etc.) - // It uses DMA to send image data to the TFT while the decoding takes // place. The processor and display combination must support DMA to // run this sketch! The decode time dominates so DMA is mainly an advantage diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_3_Array/Font_Demo_3_Array.ino b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_3_Array/Font_Demo_3_Array.ino index 038cfd42..a15ee443 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_3_Array/Font_Demo_3_Array.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_3_Array/Font_Demo_3_Array.ino @@ -11,7 +11,7 @@ This sketch uses method 3, the font characters are first plotted in a Sprite, then the Sprite is pushed to the screen. This method is very flexible and the Sprite can be created, deleted, resized as needed. To render anti-aliased fonts well the Sprite - needs to be 16-bit. The fonts will render in 1 bit per pixel sprites but there + needs to be 16 bit. The fonts will render in 1 bit per pixel sprites but there will then be no anti-aliasing. Using 1 bit per pixel Sprites is however useful to use the extended Unicode range in fonts on mono displays like ePaper. @@ -50,7 +50,7 @@ void setup(void) { tft.setRotation(1); - spr.setColorDepth(16); // 16-bit colour needed to show antialiased fonts + spr.setColorDepth(16); // 16 bit colour needed to show antialiased fonts } void loop() { @@ -93,7 +93,7 @@ void loop() { tft.fillScreen(TFT_BLACK); - // Beware: Sprites are a different "class" to TFT, so different fonts can be loaded + // Beware: Sprites are a differerent "class" to TFT, so different fonts can be loaded // in the tft and sprite instances, so load the font in the class instance you use! // In this example this means the spr. instance. @@ -181,7 +181,7 @@ void button(int x, int y, int num ) #define IWIDTH 40 #define IHEIGHT 25 - // Create a 16-bit sprite 40 pixels wide, 25 high (2000 bytes of RAM needed) + // Create a 16 bit sprite 40 pixels wide, 25 high (2000 bytes of RAM needed) spr.setColorDepth(16); spr.createSprite(IWIDTH, IHEIGHT); diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_4_Array/Font_Demo_4_Array.ino b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_4_Array/Font_Demo_4_Array.ino index de2eab99..225ae962 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_4_Array/Font_Demo_4_Array.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Font_Demo_4_Array/Font_Demo_4_Array.ino @@ -58,7 +58,7 @@ void setup(void) { tft.setRotation(1); - spr.setColorDepth(16); // 16-bit colour needed to show anti-aliased fonts + spr.setColorDepth(16); // 16 bit colour needed to show anti-aliased fonts } void loop() { diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Print_Smooth_Font/Print_Smooth_Font.ino b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Print_Smooth_Font/Print_Smooth_Font.ino index 4af307f6..16c53ce1 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Print_Smooth_Font/Print_Smooth_Font.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Print_Smooth_Font/Print_Smooth_Font.ino @@ -8,7 +8,7 @@ sketch in the library Tools folder. The Processing sketch can convert TrueType fonts in *.ttf or *.otf files. - The library supports 16-bit Unicode characters: + The library supports 16 bit unicode characters: https://en.wikipedia.org/wiki/Unicode_font The characters supported are in the in the Basic Multilingual Plane: diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Smooth_font_reading_TFT/Smooth_font_reading_TFT.ino b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Smooth_font_reading_TFT/Smooth_font_reading_TFT.ino index 669e9371..ec6cb732 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Smooth_font_reading_TFT/Smooth_font_reading_TFT.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Smooth_font_reading_TFT/Smooth_font_reading_TFT.ino @@ -83,7 +83,7 @@ unsigned int colour = red << 11; // Colour order is RGB 5+6+5 bits each void rainbow_fill() { - // The colours and state are not initialised so the start colour changes each time the function is called + // The colours and state are not initialised so the start colour changes each time the funtion is called for (int i = 319; i >= 0; i--) { // Draw a vertical line 1 pixel wide in the selected colour diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Unicode_test/Unicode_test.ino b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Unicode_test/Unicode_test.ino index 9b523813..a36c3689 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Unicode_test/Unicode_test.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/FLASH_Array/Unicode_test/Unicode_test.ino @@ -8,14 +8,14 @@ The library expects strings to be in UTF-8 encoded format: https://www.fileformat.info/info/unicode/utf8.htm - Creating variables needs to be done with care when using character arrays: + Creating varaibles needs to be done with care when using character arrays: char c = 'µ'; // Wrong char bad[4] = "5µA"; // Wrong char good[] = "5µA"; // Good String okay = "5µA"; // Good This is because UTF-8 characters outside the basic Latin set occupy more than - 1 byte per character! A 16-bit Unicode character occupies 3 bytes! + 1 byte per character! A 16 bit Unicode character occupies 3 bytes! */ @@ -89,7 +89,7 @@ void loop() //---------------------------------------------------------------------------- // We can have any random mix of characters in the font - String test2 = "仝倀"; // Unicode 0x4EDD, 0x5000 + String test2 = "仝倀"; // Unicodes 0x4EDD, 0x5000 tft.loadFont(Unicode_Test_72); diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_3/Font_Demo_3.ino b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_3/Font_Demo_3.ino index df8ac13e..312e4a73 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_3/Font_Demo_3.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_3/Font_Demo_3.ino @@ -4,7 +4,7 @@ This sketch uses method 3, the font characters are first plotted in a Sprite, then the Sprite is pushed to the screen. This method is very flexible and the Sprite can be created, deleted, resized as needed. To render anti-aliased fonts well the Sprite - needs to be 16-bit. The fonts will render in 1 bit per pixel sprites but there + needs to be 16 bit. The fonts will render in 1 bit per pixel sprites but there will then be no anti-aliasing. Using 1 bit per pixel Sprites is however useful to use the extended Unicode range in fonts on mono displays like ePaper. @@ -51,7 +51,7 @@ void setup(void) { tft.setRotation(1); - spr.setColorDepth(16); // 16-bit colour needed to show antialiased fonts + spr.setColorDepth(16); // 16 bit colour needed to show antialiased fonts if (!LittleFS.begin()) { Serial.println("Flash FS initialisation failed!"); @@ -200,7 +200,7 @@ void button(int x, int y, int num ) #define IWIDTH 40 #define IHEIGHT 25 - // Create a 16-bit sprite 40 pixels wide, 25 high (2000 bytes of RAM needed) + // Create a 16 bit sprite 40 pixels wide, 25 high (2000 bytes of RAM needed) spr.setColorDepth(16); spr.createSprite(IWIDTH, IHEIGHT); diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_4/Font_Demo_4.ino b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_4/Font_Demo_4.ino index edc14865..eb4ce044 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_4/Font_Demo_4.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Font_Demo_4/Font_Demo_4.ino @@ -61,7 +61,7 @@ void setup(void) { tft.setRotation(1); - spr.setColorDepth(16); // 16-bit colour needed to show anti-aliased fonts + spr.setColorDepth(16); // 16 bit colour needed to show anti-aliased fonts if (!LittleFS.begin()) { Serial.println("Flash FS initialisation failed!"); diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Print_Smooth_Font/Print_Smooth_Font.ino b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Print_Smooth_Font/Print_Smooth_Font.ino index ff3807a2..1b4f1c29 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Print_Smooth_Font/Print_Smooth_Font.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Print_Smooth_Font/Print_Smooth_Font.ino @@ -12,7 +12,7 @@ sketch in the library Tools folder. The Processing sketch can convert TrueType fonts in *.ttf or *.otf files. - The library supports 16-bit Unicode characters: + The library supports 16 bit Unicode characters: https://en.wikipedia.org/wiki/Unicode_font The characters supported are in the in the Basic Multilingual Plane: diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Unicode_test/Unicode_test.ino b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Unicode_test/Unicode_test.ino index 0f236531..530ae5b2 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Unicode_test/Unicode_test.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/LittleFS/Unicode_test/Unicode_test.ino @@ -15,7 +15,7 @@ String okay = "5µA"; // Good This is because UTF-8 characters outside the basic Latin set occupy more than - 1 byte per character! A 16-bit Unicode character occupies 3 bytes! + 1 byte per character! A 16 bit Unicode character occupies 3 bytes! */ diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/SD_Card/ESP32_Smooth_Font_SD/ESP32_Smooth_Font_SD.ino b/lib/TFT_eSPI/examples/Smooth Fonts/SD_Card/ESP32_Smooth_Font_SD/ESP32_Smooth_Font_SD.ino index 5f3b961f..8013a5c7 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/SD_Card/ESP32_Smooth_Font_SD/ESP32_Smooth_Font_SD.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/SD_Card/ESP32_Smooth_Font_SD/ESP32_Smooth_Font_SD.ino @@ -10,7 +10,7 @@ Load the font file onto the root directory of the SD Card. The font files used by this sketch can be found in the Data folder, press Ctrl+K to see it. - The library supports 16-bit Unicode characters: + The library supports 16 bit Unicode characters: https://en.wikipedia.org/wiki/Unicode_font The characters supported are in the in the Basic Multilingual Plane: diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_3/Font_Demo_3.ino b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_3/Font_Demo_3.ino index 6d18100a..6cbaca22 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_3/Font_Demo_3.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_3/Font_Demo_3.ino @@ -4,7 +4,7 @@ This sketch uses method 3, the font characters are first plotted in a Sprite, then the Sprite is pushed to the screen. This method is very flexible and the Sprite can be created, deleted, resized as needed. To render anti-aliased fonts well the Sprite - needs to be 16-bit. The fonts will render in 1 bit per pixel sprites but there + needs to be 16 bit. The fonts will render in 1 bit per pixel sprites but there will then be no anti-aliasing. Using 1 bit per pixel Sprites is however useful to use the extended Unicode range in fonts on mono displays like ePaper. @@ -50,7 +50,7 @@ void setup(void) { tft.setRotation(1); - spr.setColorDepth(16); // 16-bit colour needed to show anti aliased fonts + spr.setColorDepth(16); // 16 bit colour needed to show anti aliased fonts if (!SPIFFS.begin()) { Serial.println("SPIFFS initialisation failed!"); @@ -200,7 +200,7 @@ void button(int x, int y, int num ) #define IWIDTH 40 #define IHEIGHT 25 - // Create a 16-bit sprite 40 pixels wide, 25 high (2000 bytes of RAM needed) + // Create a 16 bit sprite 40 pixels wide, 25 high (2000 bytes of RAM needed) spr.setColorDepth(16); spr.createSprite(IWIDTH, IHEIGHT); diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_4/Font_Demo_4.ino b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_4/Font_Demo_4.ino index e86fa888..8259723f 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_4/Font_Demo_4.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Font_Demo_4/Font_Demo_4.ino @@ -61,7 +61,7 @@ void setup(void) { tft.setRotation(1); - spr.setColorDepth(16); // 16-bit colour needed to show anti-aliased fonts + spr.setColorDepth(16); // 16 bit colour needed to show anti-aliased fonts if (!SPIFFS.begin()) { Serial.println("SPIFFS initialisation failed!"); diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Print_Smooth_Font/Print_Smooth_Font.ino b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Print_Smooth_Font/Print_Smooth_Font.ino index 007da700..d142d511 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Print_Smooth_Font/Print_Smooth_Font.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Print_Smooth_Font/Print_Smooth_Font.ino @@ -15,7 +15,7 @@ Note: SPIFFS does not accept an underscore _ in filenames! - The library supports 16-bit Unicode characters: + The library supports 16 bit Unicode characters: https://en.wikipedia.org/wiki/Unicode_font The characters supported are in the in the Basic Multilingual Plane: diff --git a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Unicode_test/Unicode_test.ino b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Unicode_test/Unicode_test.ino index 5f97248a..26567d6c 100644 --- a/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Unicode_test/Unicode_test.ino +++ b/lib/TFT_eSPI/examples/Smooth Fonts/SPIFFS/Unicode_test/Unicode_test.ino @@ -15,7 +15,7 @@ String okay = "5µA"; // Good This is because UTF-8 characters outside the basic Latin set occupy more than - 1 byte per character! A 16-bit Unicode character occupies 3 bytes! + 1 byte per character! A 16 bit Unicode character occupies 3 bytes! */ diff --git a/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/Anti-aliased_Clock.ino b/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/Anti-aliased_Clock.ino index 9cc6a1fe..b4181f33 100644 --- a/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/Anti-aliased_Clock.ino +++ b/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/Anti-aliased_Clock.ino @@ -74,7 +74,7 @@ void setup() { tft.fillScreen(TFT_BLACK); // Create the clock face sprite - //face.setColorDepth(8); // 8-bit will work, but reduces effectiveness of anti-aliasing + //face.setColorDepth(8); // 8 bit will work, but reduces effectiveness of anti-aliasing face.createSprite(FACE_W, FACE_H); // Only 1 font used in the sprite, so can remain loaded diff --git a/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/NTP_Time.h b/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/NTP_Time.h index faadede8..bb72e327 100644 --- a/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/NTP_Time.h +++ b/lib/TFT_eSPI/examples/Smooth Graphics/Anti-aliased_Clock/NTP_Time.h @@ -4,7 +4,7 @@ // Time library: // https://github.com/PaulStoffregen/Time -#include +#include // Time zone correction library: // https://github.com/JChristensen/Timezone @@ -31,16 +31,16 @@ WiFiUDP udp; // Settings //==================================================================================== -#define TIMEZONE UK // See below for other "Zone references", UK, usMT etc. +#define TIMEZONE UK // See below for other "Zone references", UK, usMT etc #ifdef ESP32 // Temporary fix, ESP8266 fails to communicate with some servers... -// Try to use pool URL instead so the server IP address is looked up from those available +// Try to use pool url instead so the server IP address is looked up from those available // (use a pool server in your own country to improve response time and reliability) //const char* ntpServerName = "time.nist.gov"; //const char* ntpServerName = "pool.ntp.org"; const char* ntpServerName = "time.google.com"; #else -// Try to use pool URL instead so the server IP address is looked up from those available +// Try to use pool url instead so the server IP address is looked up from those available // (use a pool server in your own country to improve response time and reliability) // const char* ntpServerName = "time.nist.gov"; const char* ntpServerName = "pool.ntp.org"; diff --git a/lib/TFT_eSPI/examples/Smooth Graphics/Arc_meter_demo/Arc_meter_demo.ino b/lib/TFT_eSPI/examples/Smooth Graphics/Arc_meter_demo/Arc_meter_demo.ino index 1ce4cfb7..69f04a67 100644 --- a/lib/TFT_eSPI/examples/Smooth Graphics/Arc_meter_demo/Arc_meter_demo.ino +++ b/lib/TFT_eSPI/examples/Smooth Graphics/Arc_meter_demo/Arc_meter_demo.ino @@ -43,7 +43,7 @@ OpenFontRender ofr; uint32_t runTime = 0; // time for next update int reading = 0; // Value to be displayed -int d = 0; // Variable used for the sine wave test waveform +int d = 0; // Variable used for the sinewave test waveform bool range_error = 0; int8_t ramp = 1; @@ -109,12 +109,12 @@ void loop() { } #ifdef DRAW_DIGITS - ofr.unloadFont(); // Recover space used by font metrics etc. + ofr.unloadFont(); // Recover space used by font metrics etc #endif } // ######################################################################### -// Draw the meter on the screen, returns x coord of right-hand side +// Draw the meter on the screen, returns x coord of righthand side // ######################################################################### // x,y is centre of meter, r the radius, val a number in range 0-100 // units is the meter scale label @@ -154,10 +154,10 @@ void ringMeter(int x, int y, int r, int val, const char *units) // The OpenFontRender library only has simple print functions... - // Digit jiggle for changing values often happens with proportional fonts because + // Digit jiggle for chaging values often happens with proportional fonts because // digit glyph width varies ( 1 narrower that 4 for example). This code prints up to // 3 digits with even spacing. - // A few experimental fudge factors are used here to position the + // A few experiemntal fudge factors are used here to position the // digits in the sprite... // Create a sprite to draw the digits into uint8_t w = ofr.getTextWidth("444"); @@ -167,12 +167,12 @@ void ringMeter(int x, int y, int r, int val, const char *units) char str_buf[8]; // Buffed for string itoa (val, str_buf, 10); // Convert value to string (null terminated) uint8_t ptr = 0; // Pointer to a digit character - uint8_t dx = 4; // x offset for cursor position + uint8_t dx = 4; // x offfset for cursor position if (val < 100) dx = ofr.getTextWidth("4") / 2; // Adjust cursor x for 2 digits if (val < 10) dx = ofr.getTextWidth("4"); // Adjust cursor x for 1 digit while ((uint8_t)str_buf[ptr] != 0) ptr++; // Count the characters while (ptr) { - ofr.setCursor(w - dx - w / 20, -h / 2.5); // Offset cursor position in sprite + ofr.setCursor(w - dx - w / 20, -h / 2.5); // Offset cursor position in sprtie ofr.rprintf(str_buf + ptr - 1); // Draw a character str_buf[ptr - 1] = 0; // Replace character with a null dx += 1 + w / 3; // Adjust cursor for next character @@ -190,7 +190,7 @@ void ringMeter(int x, int y, int r, int val, const char *units) } #endif - //ofr.unloadFont(); // Recover space used by font metrics etc. + //ofr.unloadFont(); // Recover space used by font metrics etc // Allocate a value to the arc thickness dependant of radius uint8_t thickness = r / 5; diff --git a/lib/TFT_eSPI/examples/Smooth Graphics/Draw_Smooth_Circles/Draw_Smooth_Circles.ino b/lib/TFT_eSPI/examples/Smooth Graphics/Draw_Smooth_Circles/Draw_Smooth_Circles.ino index 32aa156b..ea49d65d 100644 --- a/lib/TFT_eSPI/examples/Smooth Graphics/Draw_Smooth_Circles/Draw_Smooth_Circles.ino +++ b/lib/TFT_eSPI/examples/Smooth Graphics/Draw_Smooth_Circles/Draw_Smooth_Circles.ino @@ -44,7 +44,7 @@ void loop() // ------------------------------------------------------------------------- -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ------------------------------------------------------------------------- unsigned int rainbow(byte value) { @@ -54,7 +54,7 @@ unsigned int rainbow(byte value) value = value%192; - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0; // Green is the middle 6 bits, but only top 5 bits used here byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/Smooth Graphics/Smooth_Graphics_Demo/Smooth_Graphics_Demo.ino b/lib/TFT_eSPI/examples/Smooth Graphics/Smooth_Graphics_Demo/Smooth_Graphics_Demo.ino index 63073f08..b8638e91 100644 --- a/lib/TFT_eSPI/examples/Smooth Graphics/Smooth_Graphics_Demo/Smooth_Graphics_Demo.ino +++ b/lib/TFT_eSPI/examples/Smooth Graphics/Smooth_Graphics_Demo/Smooth_Graphics_Demo.ino @@ -1,4 +1,4 @@ -// Sketch to demonstrate smooth (anti-aliased) graphics functions: +// Sketch to demonstrate smooth (anti-aliased) graphics funtions: // Smooth graphics result in less pixel resolution jaggedness. #include // Master copy here: https://github.com/Bodmer/TFT_eSPI @@ -35,7 +35,7 @@ void loop() { // drawSpot is for small anti-aliased circles, coordinates and radius are // floating point to allow sub-pixel positioning (large circles will // be slow to draw). Use fillSmoothCircle() for large circles. - // In this case black is the background colour for the anti-aliasing + // In this case black is the backgorund colour for the anti-aliasing float x = 10.5; float y = 10.5; float r = 8.6; @@ -43,7 +43,7 @@ void loop() { // Fill sprite with a colour spr.fillSprite(TFT_RED); - // Draw spot in sprite, the background colour is omitted so function + // Draw spot in sprite, the backgorund colour is ommitted so function // reads background colour for aliasing. (To use this method with direct write // to TFT (tft.drawSpot...) requires the capability to read data from the TFT!) spr.drawSpot(x, y, r, TFT_WHITE); @@ -144,14 +144,14 @@ void getCoord(int16_t x, int16_t y, float *xp1, float *yp1, float *xp2, float *y } // ========================================================================= -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ========================================================================= unsigned int rainbow(byte value) { // Value is expected to be in range 0-127 // The value is converted to a spectrum colour from 0 = blue through to 127 = red - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/Sprite/One_bit_Sprite_Demo/One_bit_Sprite_Demo.ino b/lib/TFT_eSPI/examples/Sprite/One_bit_Sprite_Demo/One_bit_Sprite_Demo.ino index 33ce9bb5..dacf64fe 100644 --- a/lib/TFT_eSPI/examples/Sprite/One_bit_Sprite_Demo/One_bit_Sprite_Demo.ino +++ b/lib/TFT_eSPI/examples/Sprite/One_bit_Sprite_Demo/One_bit_Sprite_Demo.ino @@ -12,7 +12,7 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 1-bit Sprite occupies (width * height)/8 bytes in RAM. So, + A 1 bit Sprite occupies (width * height)/8 bytes in RAM. So, for example, a 320 x 240 pixel Sprite occupies 9600 bytes. */ // A new setBitmapColor(fg_color, bg_color) function allows diff --git a/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_1/Rotated_Sprite_1.ino b/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_1/Rotated_Sprite_1.ino index 83ded139..a6a0a6a1 100644 --- a/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_1/Rotated_Sprite_1.ino +++ b/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_1/Rotated_Sprite_1.ino @@ -10,7 +10,7 @@ // screen very simple. The rotation is clockwise with increasing angle. The angle is in // degrees, an angle of 0 means no Sprite rotation. -// The pushRotated() function works with 1, 4, 8 and 16-bit per pixel (bpp) Sprites. +// The pushRotated() function works with 1, 4, 8 and 16 bit per pixel (bpp) Sprites. // The original Sprite is unchanged so can be plotted again at a different angle. @@ -20,7 +20,7 @@ // For 1 bpp Sprites the foreground and background colours are defined with the // function spr.setBitmapColor(foregroundColor, backgroundColor). -// For 4 bpp Sprites the colour map index is used instead of the 16-bit colour +// For 4 bpp Sprites the colour map index is used instead of the 16 bit colour // e.g. spr.setTextColor(5); // Green text in default colour map // See "Transparent_Sprite_Demo_4bit" example for default colour map details diff --git a/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_2/Rotated_Sprite_2.ino b/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_2/Rotated_Sprite_2.ino index e9fccb30..bb27922e 100644 --- a/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_2/Rotated_Sprite_2.ino +++ b/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_2/Rotated_Sprite_2.ino @@ -14,7 +14,7 @@ // The rotation angle is in degrees, an angle of 0 means no Sprite rotation. -// The pushRotated() function works with 1, 8 and 16-bit per pixel (bpp) Sprites. +// The pushRotated() function works with 1, 8 and 16 bit per pixel (bpp) Sprites. // For 1 bpp Sprites the foreground and background colours are defined with the // member function setBitmapColor(foregroundColor, backgroundColor). diff --git a/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_3/Rotated_Sprite_3.ino b/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_3/Rotated_Sprite_3.ino index 5341be95..2b93dc9f 100644 --- a/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_3/Rotated_Sprite_3.ino +++ b/lib/TFT_eSPI/examples/Sprite/Rotated_Sprite_3/Rotated_Sprite_3.ino @@ -80,7 +80,7 @@ void setup() // Send jpeg info to serial port fex.jpegInfo("/Eye_80x64.jpg"); - // Draw jpeg image in Sprite spr at 0,0 + // Draw jpeg iamge in Sprite spr at 0,0 fex.drawJpeg("/Eye_80x64.jpg", 0 , 0, &spr); } @@ -105,7 +105,7 @@ void loop() delay(1000); // Push copies of Sprite rotated through increasing angles 0-360 degrees - // with 45 degree increments + // with 45 fegree increments for (int16_t angle = 0; angle <= 360; angle += 45) { spr.pushRotated(angle); delay(500); diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino index 406f0c08..9d6cf8e8 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino @@ -9,7 +9,7 @@ ######################################################################### */ -// Specify sprite 160 x 128 pixels (needs 40Kbytes of RAM for 16-bit colour) +// Specify sprite 160 x 128 pixels (needs 40Kbytes of RAM for 16 bit colour) #define IWIDTH 160 #define IHEIGHT 128 diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_draw/Sprite_draw.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_draw/Sprite_draw.ino index ce3b06b5..e167d680 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_draw/Sprite_draw.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_draw/Sprite_draw.ino @@ -14,12 +14,12 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 16-bit Sprite occupies (2 * width * height) bytes in RAM. + A 16 bit Sprite occupies (2 * width * height) bytes in RAM. On a ESP8266 Sprite sizes up to 126 x 160 can be accommodated, - this size requires 40kBytes of RAM for a 16-bit colour depth. + this size requires 40kBytes of RAM for a 16 bit colour depth. - When 8-bit colour depth sprites are created they occupy + When 8 bit colour depth sprites are created they occupy (width * height) bytes in RAM, so larger sprites can be created, or the RAM required is halved. diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_draw_4bit/Sprite_draw_4bit.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_draw_4bit/Sprite_draw_4bit.ino index e4b27433..ca3ebe4b 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_draw_4bit/Sprite_draw_4bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_draw_4bit/Sprite_draw_4bit.ino @@ -1,9 +1,9 @@ /* - Sketch to show how a 4-bit Sprite is created, how to draw pixels + Sketch to show how a 4 bit Sprite is created, how to draw pixels and text within the Sprite and then push the Sprite onto the display screen. - The advantage of 4-bit sprites is: + The advantage of 4 bit sprites is: 1. Small memory footprint 2. Any set of 16 colours can be specified 3. Colours can be changed without redrawing in Sprite @@ -21,7 +21,7 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 4-bit Sprite occupies (width * height)/2 bytes in RAM. + A 4 bit Sprite occupies (width * height)/2 bytes in RAM. */ @@ -64,7 +64,7 @@ void loop(void) // Fill the whole sprite with color 0 (Sprite is in memory so not visible yet) spr.fillSprite(0); - // create a color map with known colors (16 maximum for 4-bit Sprite + // create a color map with known colors (16 maximum for 4 bit Sprite uint16_t cmap[16]; diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_image_4bit/Sprite_image_4bit.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_image_4bit/Sprite_image_4bit.ino index 63fa854b..53bd4fa2 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_image_4bit/Sprite_image_4bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_image_4bit/Sprite_image_4bit.ino @@ -14,12 +14,12 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 16-bit Sprite occupies (2 * width * height) bytes in RAM. + A 16 bit Sprite occupies (2 * width * height) bytes in RAM. On a ESP8266 Sprite sizes up to 126 x 160 can be accommodated, - this size requires 40kBytes of RAM for a 16-bit color depth. + this size requires 40kBytes of RAM for a 16 bit color depth. - When 8-bit color depth sprites are created they occupy + When 8 bit color depth sprites are created they occupy (width * height) bytes in RAM, so larger sprites can be created, or the RAM required is halved. @@ -39,7 +39,7 @@ TFT_eSPI tft = TFT_eSPI(); // Declare object "tft" TFT_eSprite spr = TFT_eSprite(&tft); // Declare Sprite object "spr" with pointer to "tft" object -byte red = 31; // Red is the top 5 bits of a 16-bit colour value +byte red = 31; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits byte state = 0; @@ -99,7 +99,7 @@ void loop(void) } // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### unsigned int rainbow() { diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll/Sprite_scroll.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll/Sprite_scroll.ino index 61166be5..1968849a 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll/Sprite_scroll.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll/Sprite_scroll.ino @@ -14,9 +14,9 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 16-bit Sprite occupies (2 * width * height) bytes in RAM. + A 16 bit Sprite occupies (2 * width * height) bytes in RAM. - An 8-bit Sprite occupies (width * height) bytes in RAM. + An 8 bit Sprite occupies (width * height) bytes in RAM. */ diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino index f0cf1f42..2ffbc531 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino @@ -126,7 +126,7 @@ void numberBox(int num, int x, int y) // Fill it with black img.fillSprite(TFT_BLACK); - // Draw a background of 2 filled triangles + // Draw a backgorund of 2 filled triangles img.fillTriangle( 0, 0, 0, 49, 40, 25, TFT_RED); img.fillTriangle( 79, 0, 79, 49, 40, 25, TFT_DARKGREEN); @@ -150,14 +150,14 @@ void numberBox(int num, int x, int y) // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### unsigned int rainbow(byte value) { // Value is expected to be in range 0-127 // The value is converted to a spectrum colour from 0 = red through to 127 = blue - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_1bit/Sprite_scroll_1bit.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_1bit/Sprite_scroll_1bit.ino index d79e4b8b..dfdee88c 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_1bit/Sprite_scroll_1bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_1bit/Sprite_scroll_1bit.ino @@ -3,7 +3,7 @@ This sketch scrolls a 1 bit per pixel (1 bpp) Sprite. - In a 1-bit Sprite any colour except TFT_BLACK turns a pixel "ON" + In a 1 bit Sprite any colour except TFT_BLACK turns a pixel "ON" TFT_BLACK turns a pixel "OFF". ON and OFF pixels can be set to any two colours before @@ -24,7 +24,7 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 1-bit Sprite occupies (width * height)/8 bytes in RAM. + A 1 bit Sprite occupies (width * height)/8 bytes in RAM. */ diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_4bit/Sprite_scroll_4bit.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_4bit/Sprite_scroll_4bit.ino index b198c859..aa29948e 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_4bit/Sprite_scroll_4bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_4bit/Sprite_scroll_4bit.ino @@ -1,5 +1,5 @@ /* - Sketch to show scrolling of the graphics in 4-bit sprites. + Sketch to show scrolling of the graphics in 4 bit sprites. Scrolling in this way moves the pixels in a defined rectangle within the Sprite. By default the whole sprite is scrolled. The gap left by scrolling is filled with a defined colour. @@ -14,7 +14,7 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 4-bit Sprite occupies (width * height)/2 bytes in RAM. + A 4 bit Sprite occupies (width * height)/2 bytes in RAM. */ #include diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_8bit/Sprite_scroll_8bit.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_8bit/Sprite_scroll_8bit.ino index 551f8755..a843589f 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_8bit/Sprite_scroll_8bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_8bit/Sprite_scroll_8bit.ino @@ -1,7 +1,7 @@ /* Display "flicker free" scrolling text and updating number - This sketch uses 8-bit colour sprites to save RAM. + This sketch uses 8 bit colour sprites to save RAM. Example for library: https://github.com/Bodmer/TFT_eSPI @@ -16,15 +16,15 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 16-bit colour Sprite occupies (2 * width * height) bytes. + A 16 bit colour Sprite occupies (2 * width * height) bytes. - An 8-bit colour Sprite occupies (width * height) bytes. + An 8 bit colour Sprite occupies (width * height) bytes. - On a ESP8266, 16-bit Sprite sizes up to 128 x 160 can be accommodated, + On a ESP8266, 16 bit Sprite sizes up to 128 x 160 can be accommodated, this size requires 128*160*2 bytes (40kBytes) of RAM. This sketch sets the colour depth to 8 bits so larger sprites can be - created. 8-bit colour sprites use half amount of RAM. If the colour + created. 8 bit colour sprites use half amount of RAM. If the colour depth is not specified then 16 bits is assumed. You need to make the sprite small enough to fit, with RAM spare for @@ -137,7 +137,7 @@ void numberBox(int num, int x, int y) // Fill it with black img.fillSprite(TFT_BLACK); - // Draw a background of 2 filled triangles + // Draw a backgorund of 2 filled triangles img.fillTriangle( 0, 0, 0, 49, 40, 25, TFT_RED); img.fillTriangle( 79, 0, 79, 49, 40, 25, TFT_DARKGREEN); @@ -161,14 +161,14 @@ void numberBox(int num, int x, int y) // ######################################################################### -// Return a 16-bit rainbow colour +// Return a 16 bit rainbow colour // ######################################################################### unsigned int rainbow(byte value) { // Value is expected to be in range 0-127 // The value is converted to a spectrum colour from 0 = red through to 127 = blue - byte red = 0; // Red is the top 5 bits of a 16-bit colour value + byte red = 0; // Red is the top 5 bits of a 16 bit colour value byte green = 0;// Green is the middle 6 bits byte blue = 0; // Blue is the bottom 5 bits diff --git a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_wrap_1bit/Sprite_scroll_wrap_1bit.ino b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_wrap_1bit/Sprite_scroll_wrap_1bit.ino index d97d58b5..76fcfc63 100644 --- a/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_wrap_1bit/Sprite_scroll_wrap_1bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Sprite_scroll_wrap_1bit/Sprite_scroll_wrap_1bit.ino @@ -1,5 +1,5 @@ // This **ONLY** works for 1 bpp Sprites due to lack of bounds checking in the -// Sprite pushImage() function for 8 and 16-bit Sprites (it is on the TO DO list) +// Sprite pushImage() function for 8 and 16 bit Sprites (it is on the TO DO list) // Wrapping scroll example by Bodmer for the TFT_eSPI library diff --git a/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo/Transparent_Sprite_Demo.ino b/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo/Transparent_Sprite_Demo.ino index e492ab68..37615acd 100644 --- a/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo/Transparent_Sprite_Demo.ino +++ b/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo/Transparent_Sprite_Demo.ino @@ -12,12 +12,12 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 16-bit Sprite occupies (2 * width * height) bytes in RAM. + A 16 bit Sprite occupies (2 * width * height) bytes in RAM. On a ESP8266 Sprite sizes up to 126 x 160 can be accommodated, - this size requires 40kBytes of RAM for a 16-bit colour depth. + this size requires 40kBytes of RAM for a 16 bit colour depth. - When 8-bit colour depth sprites are created they occupy + When 8 bit colour depth sprites are created they occupy (width * height) bytes in RAM, so larger sprites can be created, or the RAM required is halved. */ @@ -76,7 +76,7 @@ void loop() { // ######################################################################### void drawStar(int x, int y, int star_color) { - // Create an 8-bit sprite 70x 80 pixels (uses 5600 bytes of RAM) + // Create an 8 bit sprite 70x 80 pixels (uses 5600 bytes of RAM) img.setColorDepth(8); img.createSprite(70, 80); @@ -113,7 +113,7 @@ void numberBox(int x, int y, float num ) #define IWIDTH 80 #define IHEIGHT 35 - // Create a 8-bit sprite 80 pixels wide, 35 high (2800 bytes of RAM needed) + // Create a 8 bit sprite 80 pixels wide, 35 high (2800 bytes of RAM needed) img.setColorDepth(8); img.createSprite(IWIDTH, IHEIGHT); diff --git a/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo_4bit/Transparent_Sprite_Demo_4bit.ino b/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo_4bit/Transparent_Sprite_Demo_4bit.ino index 0840648c..c116ed4b 100644 --- a/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo_4bit/Transparent_Sprite_Demo_4bit.ino +++ b/lib/TFT_eSPI/examples/Sprite/Transparent_Sprite_Demo_4bit/Transparent_Sprite_Demo_4bit.ino @@ -1,5 +1,5 @@ /* - Sketch to show creation of a 4-bit sprite with a transparent + Sketch to show creation of a 4 bit sprite with a transparent background, then plot it on the TFT. The palette setup and palette update functions are also shown in this example. @@ -13,11 +13,11 @@ any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - A 4-bit Sprite occupies (width * height)/2 bytes in RAM. + A 4 bit Sprite occupies (width * height)/2 bytes in RAM. For example the "star" 70x80 Sprite uses 2800 bytes. */ -// This is the default palette for 4-bit colour sprites +// This is the default palette for 4 bit colour sprites // which is built into the library. You can create your // own palette (use a different array name!). The palette // is captured and stored in RAM by the Sprite class so a @@ -80,25 +80,25 @@ void loop() { // spr.createPalette(default_4bit_palette, 12); // After rendering a Sprite you can change the palette to increase the range of colours - // plotted to the screen to the full 16-bit set. + // plotted to the screen to the full 16 bit set. // Change palette colour 11 to violet spr.setPaletteColor(11, TFT_VIOLET); - uint16_t color15 = spr.getPaletteColor(15); // The 16-bit colour in a palette can be read back + uint16_t color15 = spr.getPaletteColor(15); // The 16 bit colour in a palette can be read back // Draw 50 sprites containing a "transparent" colour for (int i = 0; i < 50; i++) { int x = random(tft.width() - 70); int y = random(tft.height() - 80); - int c = random(15); // Random colour 0-14 (4-bit index into color map). Leave 15 for transparent. + int c = random(15); // Random colour 0-14 (4 bit index into color map). Leave 15 for transparent. drawStar(x, y, c); } delay(2000); - // Change the palette to a 16-bit grey scale colour + // Change the palette to a 16 bit grey scale colour for (uint8_t i = 0; i < 16; i++) { // (i*16+i) produces a value in range 0-255 for the RGB colours // Red Green Blue diff --git a/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg.ino b/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg.ino index 4c8adbba..a856d696 100644 --- a/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg.ino +++ b/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg.ino @@ -106,7 +106,7 @@ void loop() { frame.fillSprite(PAPER); - // Draw 8-bit grey-scale bitmap using Floyd-Steinberg dithering at x,y + // Draw 8 bit grey-scale bitmap using Floyd-Steinberg dithering at x,y // /File name x y //drawFSBmp("/TestCard.bmp", 0, 0); // 176 x 264 pixels diff --git a/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg_BMP.ino b/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg_BMP.ino index 414365d3..e52dbe07 100644 --- a/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg_BMP.ino +++ b/lib/TFT_eSPI/examples/ePaper/Floyd_Steinberg/Floyd_Steinberg_BMP.ino @@ -27,14 +27,14 @@ SOFTWARE. Note: drawFSBmp() is a simplified function and does not handle all possible - BMP file header variants. It works OK with 8-bit per pixel grey-scale images + BMP file header variants. It works OK with 8 bit per pixel grey-scale images generated by MS Paint and IrfanView. */ // https://github.com/Bodmer/TFT_eSPI //==================================================================================== -// Draw an 8-bit grey-scale bitmap (*.BMP) on a Monochrome display using dithering +// Draw an 8 bit grey-scale bitmap (*.BMP) on a Monochrome display using dithering //==================================================================================== // Uses RAM for buffers (3 * width + 4) ( 532 bytes for 176 pixels) @@ -102,10 +102,10 @@ void drawFSBmp(const char *filename, int16_t x, int16_t y) { uint16_t padding = (4 - (w & 3)) & 3; // Calculate the BMP line padding - // Create an zero an 8-bit pixel line buffer + // Create an zero an 8 bit pixel line buffer uint8_t* lineBuffer = ( uint8_t*) calloc(w , sizeof(uint8_t)); - // Create a 16-bit signed line buffer for the quantisation error + // Create a 16 bit signed line buffer for the quantisation error // Diffusion spreads to x-1 and x+1 so w + 2 avoids a bounds check int16_t* qerrBuffer = ( int16_t*) calloc((w + 2)<<1, sizeof(uint8_t)); @@ -174,7 +174,7 @@ void drawFSBmp(const char *filename, int16_t x, int16_t y) { } //==================================================================================== -// Read a 16-bit value from the filing system +// Read a 16 bit value from the filing system //==================================================================================== uint16_t read16(fs::File &f) { uint16_t result; @@ -184,7 +184,7 @@ uint16_t read16(fs::File &f) { } //==================================================================================== -// Read a 32-bit value from the filing system +// Read a 32 bit value from the filing system //==================================================================================== uint32_t read32(fs::File &f) { uint32_t result; diff --git a/lib/TFT_eSPI/library.json b/lib/TFT_eSPI/library.json index f590f3ec..9fc3a837 100644 --- a/lib/TFT_eSPI/library.json +++ b/lib/TFT_eSPI/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.5.43", + "version": "2.5.23", "keywords": "Arduino, tft, display, ttgo, LilyPi, WT32-SC01, ePaper, display, Pico, RP2040 Nano Connect, RP2040, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9481, ILI9486, ILI9488, ST7789, ST7796, RM68140, SSD1351, SSD1963, ILI9225, HX8357D, GC9A01, R61581", "description": "A TFT and ePaper (SPI or parallel interface) graphics library with optimisation for Raspberry Pi Pico, RP2040, ESP8266, ESP32 and STM32 processors", "repository": diff --git a/lib/TFT_eSPI/library.properties b/lib/TFT_eSPI/library.properties index 319d4ec6..b5dff03b 100644 --- a/lib/TFT_eSPI/library.properties +++ b/lib/TFT_eSPI/library.properties @@ -1,9 +1,9 @@ name=TFT_eSPI -version=2.5.43 +version=2.5.23 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for RP2040, STM32, ESP8266 and ESP32 -paragraph=Supports TFT displays using drivers (ILI9341 etc.) that operate with hardware SPI or 8/16-bit parallel. +paragraph=Supports TFT displays using drivers (ILI9341 etc) that operate with hardware SPI or 8/16 bit parallel. category=Display url=https://github.com/Bodmer/TFT_eSPI architectures=* diff --git a/lib/TFT_eSPI/license.txt b/lib/TFT_eSPI/license.txt index e0b40d2c..61a62a58 100644 --- a/lib/TFT_eSPI/license.txt +++ b/lib/TFT_eSPI/license.txt @@ -94,9 +94,9 @@ graphics. In 2018 anti-aliased fonts were added along with a Processing font conversion sketch. -In 2019 the library was adapted to be able to use it with any 32-bit Arduino -compatible processor. It will run on 8-bit and 16-bit processors but will be -slow due to extensive use of 32-bit variables. +In 2019 the library was adapted to be able to use it with any 32 bit Arduino +compatible processor. It will run on 8 bit and 16 bit processors but will be +slow due to extensive use of 32 bit variables. Many of the example sketches are original work that contain code created for my own projects. For all the original code the FreeBSD licence applies diff --git a/lib/hansolov2/CMakeLists.txt b/lib/hansolov2/CMakeLists.txt index 32fb7fa3..3bad3ac0 100644 --- a/lib/hansolov2/CMakeLists.txt +++ b/lib/hansolov2/CMakeLists.txt @@ -2,13 +2,13 @@ SET(SOURCES screens/ui_SplashScreen.c screens/ui_HomeScreen.c screens/ui_StatsScreen.c screens/ui_ClockScreen.c - screens/ui_SettingsScreen.c ui.c components/ui_comp_hook.c ui_helpers.c - images/ui_img_back_splash_png.c - images/ui_img_back_back_png.c + ui_events.c + images/ui_img_sky_png.c images/ui_img_1552732429.c + images/ui_img_metal2_png.c fonts/ui_font_calculator128.c fonts/ui_font_calculator16.c fonts/ui_font_calculator24.c diff --git a/lib/hansolov2/filelist.txt b/lib/hansolov2/filelist.txt index 5bf966c0..a93b5e71 100644 --- a/lib/hansolov2/filelist.txt +++ b/lib/hansolov2/filelist.txt @@ -2,13 +2,13 @@ screens/ui_SplashScreen.c screens/ui_HomeScreen.c screens/ui_StatsScreen.c screens/ui_ClockScreen.c -screens/ui_SettingsScreen.c ui.c components/ui_comp_hook.c ui_helpers.c -images/ui_img_back_splash_png.c -images/ui_img_back_back_png.c +ui_events.c +images/ui_img_sky_png.c images/ui_img_1552732429.c +images/ui_img_metal2_png.c fonts/ui_font_calculator128.c fonts/ui_font_calculator16.c fonts/ui_font_calculator24.c diff --git a/lib/hansolov2/images/ui_img_1552732429.c b/lib/hansolov2/images/ui_img_1552732429.c index 57afe260..7167f4b5 100644 --- a/lib/hansolov2/images/ui_img_1552732429.c +++ b/lib/hansolov2/images/ui_img_1552732429.c @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 diff --git a/lib/hansolov2/screens/ui_ClockScreen.c b/lib/hansolov2/screens/ui_ClockScreen.c index bed1f49a..53a44e5f 100644 --- a/lib/hansolov2/screens/ui_ClockScreen.c +++ b/lib/hansolov2/screens/ui_ClockScreen.c @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -9,36 +9,24 @@ void ui_ClockScreen_screen_init(void) { ui_ClockScreen = lv_obj_create(NULL); lv_obj_clear_flag(ui_ClockScreen, LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_bg_img_src(ui_ClockScreen, &ui_img_back_back_png, LV_PART_MAIN | LV_STATE_DEFAULT); - - lv_obj_set_style_bg_img_src(ui_ClockScreen, &ui_img_back_back_png, LV_PART_SCROLLBAR | LV_STATE_DEFAULT); - - ui_Label14 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_Label14, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label14, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label14, 8); - lv_obj_set_y(ui_Label14, -4); - lv_label_set_text(ui_Label14, "Clock"); - lv_obj_set_style_text_color(ui_Label14, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label14, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label14, &ui_font_star32, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblclock2 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_lblclock2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblclock2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblclock2, -6); - lv_obj_set_y(ui_lblclock2, -28); - lv_obj_set_align(ui_lblclock2, LV_ALIGN_CENTER); - lv_label_set_text(ui_lblclock2, "00:00"); - lv_obj_set_style_text_color(ui_lblclock2, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblclock2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblclock2, &ui_font_calculator128, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_ClockScreen, &ui_img_sky_png, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label18 = lv_label_create(ui_ClockScreen); + lv_obj_set_width(ui_Label18, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label18, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label18, -177); + lv_obj_set_y(ui_Label18, -131); + lv_obj_set_align(ui_Label18, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label18, "Clock"); + lv_obj_set_style_text_color(ui_Label18, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label18, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label18, &ui_font_star32, LV_PART_MAIN | LV_STATE_DEFAULT); ui_btnpre3 = lv_btn_create(ui_ClockScreen); lv_obj_set_width(ui_btnpre3, 100); lv_obj_set_height(ui_btnpre3, 50); - lv_obj_set_x(ui_btnpre3, -181); - lv_obj_set_y(ui_btnpre3, 121); + lv_obj_set_x(ui_btnpre3, -177); + lv_obj_set_y(ui_btnpre3, 124); lv_obj_set_align(ui_btnpre3, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnpre3, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnpre3, LV_OBJ_FLAG_SCROLLABLE); /// Flags @@ -48,8 +36,8 @@ void ui_ClockScreen_screen_init(void) ui_btnconfirm3 = lv_btn_create(ui_ClockScreen); lv_obj_set_width(ui_btnconfirm3, 100); lv_obj_set_height(ui_btnconfirm3, 50); - lv_obj_set_x(ui_btnconfirm3, -63); - lv_obj_set_y(ui_btnconfirm3, 121); + lv_obj_set_x(ui_btnconfirm3, -59); + lv_obj_set_y(ui_btnconfirm3, 124); lv_obj_set_align(ui_btnconfirm3, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnconfirm3, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnconfirm3, LV_OBJ_FLAG_SCROLLABLE); /// Flags @@ -60,7 +48,7 @@ void ui_ClockScreen_screen_init(void) lv_obj_set_width(ui_btnpost3, 100); lv_obj_set_height(ui_btnpost3, 50); lv_obj_set_x(ui_btnpost3, 60); - lv_obj_set_y(ui_btnpost3, 122); + lv_obj_set_y(ui_btnpost3, 124); lv_obj_set_align(ui_btnpost3, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnpost3, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnpost3, LV_OBJ_FLAG_SCROLLABLE); /// Flags @@ -71,115 +59,45 @@ void ui_ClockScreen_screen_init(void) lv_obj_set_width(ui_btndelete3, 100); lv_obj_set_height(ui_btndelete3, 50); lv_obj_set_x(ui_btndelete3, 183); - lv_obj_set_y(ui_btndelete3, 122); + lv_obj_set_y(ui_btndelete3, 124); lv_obj_set_align(ui_btndelete3, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btndelete3, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btndelete3, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_color(ui_btndelete3, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_btndelete3, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_lblclock2 = lv_label_create(ui_ClockScreen); + lv_obj_set_width(ui_lblclock2, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_lblclock2, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_lblclock2, -6); + lv_obj_set_y(ui_lblclock2, -28); + lv_obj_set_align(ui_lblclock2, LV_ALIGN_CENTER); + lv_label_set_text(ui_lblclock2, "00:00:00"); + lv_obj_set_style_text_color(ui_lblclock2, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_lblclock2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_lblclock2, &ui_font_calculator128, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label15 = lv_label_create(ui_ClockScreen); + lv_obj_set_width(ui_Label15, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label15, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label15, -179); + lv_obj_set_y(ui_Label15, 126); + lv_obj_set_align(ui_Label15, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label15, "Pre"); + lv_obj_set_style_text_color(ui_Label15, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label15, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Label17 = lv_label_create(ui_ClockScreen); lv_obj_set_width(ui_Label17, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_Label17, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label17, -185); - lv_obj_set_y(ui_Label17, 121); + lv_obj_set_x(ui_Label17, 59); + lv_obj_set_y(ui_Label17, 126); lv_obj_set_align(ui_Label17, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label17, "Home"); + lv_label_set_text(ui_Label17, "Post"); lv_obj_set_style_text_color(ui_Label17, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_Label17, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - ui_Label21 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_Label21, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label21, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label21, -64); - lv_obj_set_y(ui_Label21, 121); - lv_obj_set_align(ui_Label21, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label21, "Stats"); - lv_obj_set_style_text_color(ui_Label21, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label21, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label24 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_Label24, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label24, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label24, 57); - lv_obj_set_y(ui_Label24, 122); - lv_obj_set_align(ui_Label24, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label24, "Clock"); - lv_obj_set_style_text_color(ui_Label24, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label24, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label27 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_Label27, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label27, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label27, 183); - lv_obj_set_y(ui_Label27, 122); - lv_obj_set_align(ui_Label27, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label27, "Settings"); - lv_obj_set_style_text_color(ui_Label27, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label27, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblHeight2 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_lblHeight2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblHeight2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblHeight2, -6); - lv_obj_set_y(ui_lblHeight2, -96); - lv_obj_set_align(ui_lblHeight2, LV_ALIGN_CENTER); - lv_label_set_text(ui_lblHeight2, "000000"); - lv_obj_set_style_text_color(ui_lblHeight2, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblHeight2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblHeight2, &ui_font_calculator48, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label37 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_Label37, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label37, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label37, -171); - lv_obj_set_y(ui_Label37, -54); - lv_obj_set_align(ui_Label37, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label37, "UTC"); - lv_obj_set_style_text_color(ui_Label37, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label37, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label37, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label38 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_Label38, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label38, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label38, -157); - lv_obj_set_y(ui_Label38, -92); - lv_obj_set_align(ui_Label38, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label38, "Height"); - lv_obj_set_style_text_color(ui_Label38, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label38, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label38, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label40 = lv_label_create(ui_ClockScreen); - lv_obj_set_width(ui_Label40, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label40, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label40, -149); - lv_obj_set_y(ui_Label40, 36); - lv_obj_set_align(ui_Label40, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label40, "Halving"); - lv_obj_set_style_text_color(ui_Label40, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label40, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label40, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_barhalving = lv_bar_create(ui_ClockScreen); - lv_bar_set_value(ui_barhalving, 20, LV_ANIM_OFF); - lv_bar_set_start_value(ui_barhalving, 0, LV_ANIM_OFF); - lv_obj_set_width(ui_barhalving, 457); - lv_obj_set_height(ui_barhalving, 17); - lv_obj_set_x(ui_barhalving, -2); - lv_obj_set_y(ui_barhalving, 63); - lv_obj_set_align(ui_barhalving, LV_ALIGN_CENTER); - lv_obj_set_style_bg_color(ui_barhalving, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_bg_opa(ui_barhalving, 50, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_anim_time(ui_barhalving, 500, LV_PART_MAIN | LV_STATE_DEFAULT); - - lv_obj_set_style_bg_color(ui_barhalving, lv_color_hex(0xFAFF20), LV_PART_INDICATOR | LV_STATE_DEFAULT); - lv_obj_set_style_bg_opa(ui_barhalving, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT); - lv_obj_add_event_cb(ui_btnpre3, ui_event_btnpre3, LV_EVENT_ALL, NULL); - lv_obj_add_event_cb(ui_btnconfirm3, ui_event_btnconfirm3, LV_EVENT_ALL, NULL); lv_obj_add_event_cb(ui_btnpost3, ui_event_btnpost3, LV_EVENT_ALL, NULL); - lv_obj_add_event_cb(ui_btndelete3, ui_event_btndelete3, LV_EVENT_ALL, NULL); } diff --git a/lib/hansolov2/screens/ui_HomeScreen.c b/lib/hansolov2/screens/ui_HomeScreen.c index 2870f728..60dd4167 100644 --- a/lib/hansolov2/screens/ui_HomeScreen.c +++ b/lib/hansolov2/screens/ui_HomeScreen.c @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -9,26 +9,13 @@ void ui_HomeScreen_screen_init(void) { ui_HomeScreen = lv_obj_create(NULL); lv_obj_clear_flag(ui_HomeScreen, LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_bg_img_src(ui_HomeScreen, &ui_img_back_back_png, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container1 = lv_obj_create(ui_HomeScreen); - lv_obj_remove_style_all(ui_Container1); - lv_obj_set_width(ui_Container1, 211); - lv_obj_set_height(ui_Container1, 63); - lv_obj_set_x(ui_Container1, 126); - lv_obj_set_y(ui_Container1, 51); - lv_obj_set_align(ui_Container1, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container1, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_bg_color(ui_Container1, lv_color_hex(0xFFFFFF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_bg_opa(ui_Container1, 50, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container1, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container1, LV_BORDER_SIDE_FULL, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_HomeScreen, &ui_img_sky_png, LV_PART_MAIN | LV_STATE_DEFAULT); ui_btnconfirm = lv_btn_create(ui_HomeScreen); lv_obj_set_width(ui_btnconfirm, 100); lv_obj_set_height(ui_btnconfirm, 50); - lv_obj_set_x(ui_btnconfirm, -63); - lv_obj_set_y(ui_btnconfirm, 121); + lv_obj_set_x(ui_btnconfirm, -59); + lv_obj_set_y(ui_btnconfirm, 124); lv_obj_set_align(ui_btnconfirm, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnconfirm, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnconfirm, LV_OBJ_FLAG_SCROLLABLE); /// Flags @@ -39,21 +26,31 @@ void ui_HomeScreen_screen_init(void) lv_obj_set_width(ui_btnpost, 100); lv_obj_set_height(ui_btnpost, 50); lv_obj_set_x(ui_btnpost, 60); - lv_obj_set_y(ui_btnpost, 122); + lv_obj_set_y(ui_btnpost, 124); lv_obj_set_align(ui_btnpost, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnpost, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnpost, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_color(ui_btnpost, lv_color_hex(0xFF9400), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_btnpost, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Image1 = lv_img_create(ui_HomeScreen); + lv_img_set_src(ui_Image1, &ui_img_1552732429); + lv_obj_set_width(ui_Image1, LV_SIZE_CONTENT); /// 100 + lv_obj_set_height(ui_Image1, LV_SIZE_CONTENT); /// 100 + lv_obj_set_x(ui_Image1, 189); + lv_obj_set_y(ui_Image1, -110); + lv_obj_set_align(ui_Image1, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_Image1, LV_OBJ_FLAG_ADV_HITTEST); /// Flags + lv_obj_clear_flag(ui_Image1, LV_OBJ_FLAG_SCROLLABLE); /// Flags + ui_barhashrate = lv_bar_create(ui_HomeScreen); - lv_bar_set_range(ui_barhashrate, 0, 250); - lv_bar_set_value(ui_barhashrate, 20, LV_ANIM_OFF); + lv_bar_set_range(ui_barhashrate, 0, 1000); + lv_bar_set_value(ui_barhashrate, 800, LV_ANIM_OFF); lv_bar_set_start_value(ui_barhashrate, 0, LV_ANIM_OFF); lv_obj_set_width(ui_barhashrate, 363); lv_obj_set_height(ui_barhashrate, 17); - lv_obj_set_x(ui_barhashrate, -47); - lv_obj_set_y(ui_barhashrate, -88); + lv_obj_set_x(ui_barhashrate, -52); + lv_obj_set_y(ui_barhashrate, -74); lv_obj_set_align(ui_barhashrate, LV_ALIGN_CENTER); lv_obj_set_style_bg_color(ui_barhashrate, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_barhashrate, 50, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -62,24 +59,79 @@ void ui_HomeScreen_screen_init(void) lv_obj_set_style_bg_color(ui_barhashrate, lv_color_hex(0xFAFF20), LV_PART_INDICATOR | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_barhashrate, 255, LV_PART_INDICATOR | LV_STATE_DEFAULT); + ui_Label6 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label6, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label6, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label6, 65); + lv_obj_set_y(ui_Label6, -46); + lv_obj_set_align(ui_Label6, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label6, "Best difficulty"); + lv_obj_set_style_text_color(ui_Label6, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label6, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label6, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label4 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label4, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label4, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label4, -47); + lv_obj_set_y(ui_Label4, -128); + lv_obj_set_align(ui_Label4, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label4, "Hashrate KH/s"); + lv_obj_set_style_text_color(ui_Label4, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label4, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label4, &ui_font_star32, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label7 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label7, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label7, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label7, -173); + lv_obj_set_y(ui_Label7, -47); + lv_obj_set_align(ui_Label7, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label7, "valid blocks"); + lv_obj_set_style_text_color(ui_Label7, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label7, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label7, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_btndelete = lv_btn_create(ui_HomeScreen); lv_obj_set_width(ui_btndelete, 100); lv_obj_set_height(ui_btndelete, 50); lv_obj_set_x(ui_btndelete, 183); - lv_obj_set_y(ui_btndelete, 122); + lv_obj_set_y(ui_btndelete, 124); lv_obj_set_align(ui_btndelete, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btndelete, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btndelete, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_color(ui_btndelete, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_btndelete, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Label8 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label8, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label8, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label8, -154); + lv_obj_set_y(ui_Label8, -14); + lv_obj_set_align(ui_Label8, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label8, "block templates"); + lv_obj_set_style_text_color(ui_Label8, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label8, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label8, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label10 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label10, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label10, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label10, 75); + lv_obj_set_y(ui_Label10, -13); + lv_obj_set_align(ui_Label10, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label10, "32bits shares"); + lv_obj_set_style_text_color(ui_Label10, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label10, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label10, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_lblhashrate = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_lblhashrate, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblhashrate, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblhashrate, 16); - lv_obj_set_y(ui_lblhashrate, -138); + lv_obj_set_x(ui_lblhashrate, 8); + lv_obj_set_y(ui_lblhashrate, -126); lv_obj_set_align(ui_lblhashrate, LV_ALIGN_CENTER); - lv_label_set_text(ui_lblhashrate, "000.00"); + lv_label_set_text(ui_lblhashrate, "00.00"); lv_obj_set_style_text_color(ui_lblhashrate, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lblhashrate, 255, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_font(ui_lblhashrate, &ui_font_calculator48, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -87,8 +139,8 @@ void ui_HomeScreen_screen_init(void) ui_lblbestdiff = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_lblbestdiff, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblbestdiff, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblbestdiff, 397); - lv_obj_set_y(ui_lblbestdiff, 89); + lv_obj_set_x(ui_lblbestdiff, 392); + lv_obj_set_y(ui_lblbestdiff, 95); lv_label_set_text(ui_lblbestdiff, "0"); lv_obj_set_style_text_color(ui_lblbestdiff, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lblbestdiff, 255, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -97,8 +149,8 @@ void ui_HomeScreen_screen_init(void) ui_lbltemplates = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_lbltemplates, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lbltemplates, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lbltemplates, 181); - lv_obj_set_y(ui_lbltemplates, 118); + lv_obj_set_x(ui_lbltemplates, 178); + lv_obj_set_y(ui_lbltemplates, 129); lv_label_set_text(ui_lbltemplates, "0"); lv_obj_set_style_text_color(ui_lbltemplates, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lbltemplates, 255, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -107,8 +159,8 @@ void ui_HomeScreen_screen_init(void) ui_lblvalid = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_lblvalid, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblvalid, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblvalid, 181); - lv_obj_set_y(ui_lblvalid, 89); + lv_obj_set_x(ui_lblvalid, 178); + lv_obj_set_y(ui_lblvalid, 96); lv_label_set_text(ui_lblvalid, "0"); lv_obj_set_style_text_color(ui_lblvalid, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lblvalid, 255, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -117,8 +169,8 @@ void ui_HomeScreen_screen_init(void) ui_lblshares32 = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_lblshares32, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblshares32, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblshares32, 397); - lv_obj_set_y(ui_lblshares32, 117); + lv_obj_set_x(ui_lblshares32, 392); + lv_obj_set_y(ui_lblshares32, 129); lv_label_set_text(ui_lblshares32, "0"); lv_obj_set_style_text_color(ui_lblshares32, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lblshares32, 255, LV_PART_MAIN | LV_STATE_DEFAULT); @@ -135,32 +187,65 @@ void ui_HomeScreen_screen_init(void) lv_obj_set_style_text_opa(ui_lblclock, 255, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_font(ui_lblclock, &ui_font_calculator48, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Label2 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label2, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label2, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label2, 12); + lv_obj_set_y(ui_Label2, 68); + lv_obj_set_align(ui_Label2, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label2, "uptime"); + lv_obj_set_style_text_color(ui_Label2, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label2, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_btnpre = lv_btn_create(ui_HomeScreen); lv_obj_set_width(ui_btnpre, 100); lv_obj_set_height(ui_btnpre, 50); - lv_obj_set_x(ui_btnpre, -181); - lv_obj_set_y(ui_btnpre, 121); + lv_obj_set_x(ui_btnpre, -177); + lv_obj_set_y(ui_btnpre, 124); lv_obj_set_align(ui_btnpre, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnpre, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnpre, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_color(ui_btnpre, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_btnpre, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Label11 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label11, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label11, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label11, -156); + lv_obj_set_y(ui_Label11, 19); + lv_obj_set_align(ui_Label11, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label11, "Total hashrate "); + lv_obj_set_style_text_color(ui_Label11, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label11, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label11, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_lbltotalhashrate = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_lbltotalhashrate, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lbltotalhashrate, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lbltotalhashrate, 181); - lv_obj_set_y(ui_lbltotalhashrate, 148); + lv_obj_set_x(ui_lbltotalhashrate, 178); + lv_obj_set_y(ui_lbltotalhashrate, 160); lv_label_set_text(ui_lbltotalhashrate, "0"); lv_obj_set_style_text_color(ui_lbltotalhashrate, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lbltotalhashrate, 255, LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_font(ui_lbltotalhashrate, &ui_font_calculator32, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Label19 = lv_label_create(ui_HomeScreen); + lv_obj_set_width(ui_Label19, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label19, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label19, -172); + lv_obj_set_y(ui_Label19, 68); + lv_obj_set_align(ui_Label19, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label19, "Temperature"); + lv_obj_set_style_text_color(ui_Label19, lv_color_hex(0xFF9A00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label19, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label19, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_lbltemperature = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_lbltemperature, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lbltemperature, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lbltemperature, 181); - lv_obj_set_y(ui_lbltemperature, 65); + lv_obj_set_x(ui_lbltemperature, 179); + lv_obj_set_y(ui_lbltemperature, 67); lv_obj_set_align(ui_lbltemperature, LV_ALIGN_LEFT_MID); lv_label_set_text(ui_lbltemperature, "00"); lv_obj_set_style_text_color(ui_lbltemperature, lv_color_hex(0xFF9A00), LV_PART_MAIN | LV_STATE_DEFAULT); @@ -170,172 +255,24 @@ void ui_HomeScreen_screen_init(void) ui_Label5 = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_Label5, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_Label5, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label5, -185); - lv_obj_set_y(ui_Label5, 121); + lv_obj_set_x(ui_Label5, -179); + lv_obj_set_y(ui_Label5, 126); lv_obj_set_align(ui_Label5, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label5, "Home"); + lv_label_set_text(ui_Label5, "Pre"); lv_obj_set_style_text_color(ui_Label5, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_Label5, 255, LV_PART_MAIN | LV_STATE_DEFAULT); ui_Label9 = lv_label_create(ui_HomeScreen); lv_obj_set_width(ui_Label9, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_Label9, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label9, 57); - lv_obj_set_y(ui_Label9, 122); + lv_obj_set_x(ui_Label9, 59); + lv_obj_set_y(ui_Label9, 126); lv_obj_set_align(ui_Label9, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label9, "Clock"); + lv_label_set_text(ui_Label9, "Post"); lv_obj_set_style_text_color(ui_Label9, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_Label9, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - ui_Label3 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label3, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label3, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label3, 8); - lv_obj_set_y(ui_Label3, -4); - lv_label_set_text(ui_Label3, "Hashrate kH/s"); - lv_obj_set_style_text_color(ui_Label3, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label3, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label3, &ui_font_star32, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label4 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label4, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label4, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label4, -170); - lv_obj_set_y(ui_Label4, -50); - lv_obj_set_align(ui_Label4, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label4, "Valid blocks"); - lv_obj_set_style_text_color(ui_Label4, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label4, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label4, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label6 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label6, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label6, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label6, -148); - lv_obj_set_y(ui_Label6, -21); - lv_obj_set_align(ui_Label6, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label6, "Block templates"); - lv_obj_set_style_text_color(ui_Label6, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label6, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label6, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label7 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label7, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label7, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label7, -158); - lv_obj_set_y(ui_Label7, 10); - lv_obj_set_align(ui_Label7, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label7, "Total hashrate"); - lv_obj_set_style_text_color(ui_Label7, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label7, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label7, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label8 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label8, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label8, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label8, -112); - lv_obj_set_y(ui_Label8, 69); - lv_obj_set_align(ui_Label8, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label8, "Temperature °C"); - lv_obj_set_style_text_color(ui_Label8, lv_color_hex(0xFF9A00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label8, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label8, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label10 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label10, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label10, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label10, 80); - lv_obj_set_y(ui_Label10, -49); - lv_obj_set_align(ui_Label10, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label10, "Best difficulty"); - lv_obj_set_style_text_color(ui_Label10, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label10, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label10, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label11 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label11, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label11, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label11, 76); - lv_obj_set_y(ui_Label11, -20); - lv_obj_set_align(ui_Label11, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label11, "32Bits shares"); - lv_obj_set_style_text_color(ui_Label11, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label11, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label11, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label12 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label12, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label12, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label12, 64); - lv_obj_set_y(ui_Label12, 34); - lv_obj_set_align(ui_Label12, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label12, "UPTIME"); - lv_obj_set_style_text_color(ui_Label12, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label12, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label12, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container2 = lv_obj_create(ui_HomeScreen); - lv_obj_remove_style_all(ui_Container2); - lv_obj_set_width(ui_Container2, 464); - lv_obj_set_height(ui_Container2, 17); - lv_obj_set_x(ui_Container2, -1); - lv_obj_set_y(ui_Container2, -47); - lv_obj_set_align(ui_Container2, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container2, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container2, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container2, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container2, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container2, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container3 = lv_obj_create(ui_HomeScreen); - lv_obj_remove_style_all(ui_Container3); - lv_obj_set_width(ui_Container3, 464); - lv_obj_set_height(ui_Container3, 17); - lv_obj_set_x(ui_Container3, -1); - lv_obj_set_y(ui_Container3, -18); - lv_obj_set_align(ui_Container3, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container3, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container3, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container3, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container3, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container3, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container4 = lv_obj_create(ui_HomeScreen); - lv_obj_remove_style_all(ui_Container4); - lv_obj_set_width(ui_Container4, 464); - lv_obj_set_height(ui_Container4, 17); - lv_obj_set_x(ui_Container4, -1); - lv_obj_set_y(ui_Container4, 12); - lv_obj_set_align(ui_Container4, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container4, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container4, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container4, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container4, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container4, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label13 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label13, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label13, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label13, -64); - lv_obj_set_y(ui_Label13, 121); - lv_obj_set_align(ui_Label13, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label13, "Stats"); - lv_obj_set_style_text_color(ui_Label13, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label13, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label18 = lv_label_create(ui_HomeScreen); - lv_obj_set_width(ui_Label18, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label18, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label18, 183); - lv_obj_set_y(ui_Label18, 122); - lv_obj_set_align(ui_Label18, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label18, "Settings"); - lv_obj_set_style_text_color(ui_Label18, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label18, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - lv_obj_add_event_cb(ui_btnconfirm, ui_event_btnconfirm, LV_EVENT_ALL, NULL); lv_obj_add_event_cb(ui_btnpost, ui_event_btnpost, LV_EVENT_ALL, NULL); - lv_obj_add_event_cb(ui_btndelete, ui_event_btndelete, LV_EVENT_ALL, NULL); lv_obj_add_event_cb(ui_btnpre, ui_event_btnpre, LV_EVENT_ALL, NULL); } diff --git a/lib/hansolov2/screens/ui_SplashScreen.c b/lib/hansolov2/screens/ui_SplashScreen.c index f03e0f1c..72c60608 100644 --- a/lib/hansolov2/screens/ui_SplashScreen.c +++ b/lib/hansolov2/screens/ui_SplashScreen.c @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -9,38 +9,59 @@ void ui_SplashScreen_screen_init(void) { ui_SplashScreen = lv_obj_create(NULL); lv_obj_clear_flag(ui_SplashScreen, LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_bg_img_src(ui_SplashScreen, &ui_img_back_splash_png, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_SplashScreen, &ui_img_sky_png, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label3 = lv_label_create(ui_SplashScreen); + lv_obj_set_width(ui_Label3, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label3, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label3, -84); + lv_obj_set_y(ui_Label3, -128); + lv_obj_set_align(ui_Label3, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label3, "Han Solominer"); + lv_obj_set_style_text_color(ui_Label3, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label3, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label3, &ui_font_star32, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label1 = lv_label_create(ui_SplashScreen); + lv_obj_set_width(ui_Label1, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label1, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label1, -72); + lv_obj_set_y(ui_Label1, -93); + lv_obj_set_align(ui_Label1, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label1, "The rise of hashrate"); + lv_obj_set_style_text_color(ui_Label1, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label1, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label1, &ui_font_star24, LV_PART_MAIN | LV_STATE_DEFAULT); ui_lblpassword = lv_label_create(ui_SplashScreen); lv_obj_set_width(ui_lblpassword, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblpassword, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblpassword, 137); - lv_obj_set_y(ui_lblpassword, 283); + lv_obj_set_x(ui_lblpassword, 7); + lv_obj_set_y(ui_lblpassword, 286); lv_label_set_text(ui_lblpassword, "password"); lv_obj_set_style_text_color(ui_lblpassword, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lblpassword, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblpassword, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_lblpassword, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); ui_lblssid = lv_label_create(ui_SplashScreen); lv_obj_set_width(ui_lblssid, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblssid, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblssid, 78); - lv_obj_set_y(ui_lblssid, 247); + lv_obj_set_x(ui_lblssid, 8); + lv_obj_set_y(ui_lblssid, 259); lv_label_set_text(ui_lblssid, "ssid"); lv_obj_set_style_text_color(ui_lblssid, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lblssid, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblssid, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_lblssid, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); ui_lblversion = lv_label_create(ui_SplashScreen); lv_obj_set_width(ui_lblversion, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_lblversion, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblversion, 279); - lv_obj_set_y(ui_lblversion, 280); + lv_obj_set_x(ui_lblversion, -5); + lv_obj_set_y(ui_lblversion, 284); + lv_obj_set_align(ui_lblversion, LV_ALIGN_TOP_RIGHT); lv_label_set_text(ui_lblversion, "version "); lv_obj_set_style_text_color(ui_lblversion, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_lblversion, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblversion, &lv_font_montserrat_16, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_bg_img_src(ui_lblversion, &ui_img_back_back_png, LV_PART_MAIN | LV_STATE_DEFAULT); - + lv_obj_set_style_text_font(ui_lblversion, &ui_font_start16, LV_PART_MAIN | LV_STATE_DEFAULT); } diff --git a/lib/hansolov2/screens/ui_StatsScreen.c b/lib/hansolov2/screens/ui_StatsScreen.c index 328cc342..e733b051 100644 --- a/lib/hansolov2/screens/ui_StatsScreen.c +++ b/lib/hansolov2/screens/ui_StatsScreen.c @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -9,36 +9,13 @@ void ui_StatsScreen_screen_init(void) { ui_StatsScreen = lv_obj_create(NULL); lv_obj_clear_flag(ui_StatsScreen, LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_bg_img_src(ui_StatsScreen, &ui_img_back_back_png, LV_PART_MAIN | LV_STATE_DEFAULT); - - lv_obj_set_style_bg_img_src(ui_StatsScreen, &ui_img_back_back_png, LV_PART_SCROLLBAR | LV_STATE_DEFAULT); - - ui_Label2 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label2, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label2, 8); - lv_obj_set_y(ui_Label2, -4); - lv_label_set_text(ui_Label2, "Statistics"); - lv_obj_set_style_text_color(ui_Label2, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label2, &ui_font_star32, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_btnpre2 = lv_btn_create(ui_StatsScreen); - lv_obj_set_width(ui_btnpre2, 100); - lv_obj_set_height(ui_btnpre2, 50); - lv_obj_set_x(ui_btnpre2, -181); - lv_obj_set_y(ui_btnpre2, 121); - lv_obj_set_align(ui_btnpre2, LV_ALIGN_CENTER); - lv_obj_add_flag(ui_btnpre2, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags - lv_obj_clear_flag(ui_btnpre2, LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_bg_color(ui_btnpre2, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_bg_opa(ui_btnpre2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_img_src(ui_StatsScreen, &ui_img_sky_png, LV_PART_MAIN | LV_STATE_DEFAULT); ui_btnconfirm2 = lv_btn_create(ui_StatsScreen); lv_obj_set_width(ui_btnconfirm2, 100); lv_obj_set_height(ui_btnconfirm2, 50); - lv_obj_set_x(ui_btnconfirm2, -63); - lv_obj_set_y(ui_btnconfirm2, 121); + lv_obj_set_x(ui_btnconfirm2, -59); + lv_obj_set_y(ui_btnconfirm2, 124); lv_obj_set_align(ui_btnconfirm2, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnconfirm2, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnconfirm2, LV_OBJ_FLAG_SCROLLABLE); /// Flags @@ -49,269 +26,77 @@ void ui_StatsScreen_screen_init(void) lv_obj_set_width(ui_btnpost2, 100); lv_obj_set_height(ui_btnpost2, 50); lv_obj_set_x(ui_btnpost2, 60); - lv_obj_set_y(ui_btnpost2, 122); + lv_obj_set_y(ui_btnpost2, 124); lv_obj_set_align(ui_btnpost2, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btnpost2, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btnpost2, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_color(ui_btnpost2, lv_color_hex(0xFF9400), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_btnpost2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Image2 = lv_img_create(ui_StatsScreen); + lv_img_set_src(ui_Image2, &ui_img_1552732429); + lv_obj_set_width(ui_Image2, LV_SIZE_CONTENT); /// 100 + lv_obj_set_height(ui_Image2, LV_SIZE_CONTENT); /// 100 + lv_obj_set_x(ui_Image2, -10); + lv_obj_set_y(ui_Image2, -13); + lv_obj_set_align(ui_Image2, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_Image2, LV_OBJ_FLAG_ADV_HITTEST); /// Flags + lv_obj_clear_flag(ui_Image2, LV_OBJ_FLAG_SCROLLABLE); /// Flags + ui_btndelete2 = lv_btn_create(ui_StatsScreen); lv_obj_set_width(ui_btndelete2, 100); lv_obj_set_height(ui_btndelete2, 50); lv_obj_set_x(ui_btndelete2, 183); - lv_obj_set_y(ui_btndelete2, 122); + lv_obj_set_y(ui_btndelete2, 124); lv_obj_set_align(ui_btndelete2, LV_ALIGN_CENTER); lv_obj_add_flag(ui_btndelete2, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags lv_obj_clear_flag(ui_btndelete2, LV_OBJ_FLAG_SCROLLABLE); /// Flags lv_obj_set_style_bg_color(ui_btndelete2, lv_color_hex(0xFF0000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_bg_opa(ui_btndelete2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_btnpre2 = lv_btn_create(ui_StatsScreen); + lv_obj_set_width(ui_btnpre2, 100); + lv_obj_set_height(ui_btnpre2, 50); + lv_obj_set_x(ui_btnpre2, -177); + lv_obj_set_y(ui_btnpre2, 124); + lv_obj_set_align(ui_btnpre2, LV_ALIGN_CENTER); + lv_obj_add_flag(ui_btnpre2, LV_OBJ_FLAG_SCROLL_ON_FOCUS); /// Flags + lv_obj_clear_flag(ui_btnpre2, LV_OBJ_FLAG_SCROLLABLE); /// Flags + lv_obj_set_style_bg_color(ui_btnpre2, lv_color_hex(0x2EFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_bg_opa(ui_btnpre2, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label13 = lv_label_create(ui_StatsScreen); + lv_obj_set_width(ui_Label13, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label13, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label13, -51); + lv_obj_set_y(ui_Label13, -128); + lv_obj_set_align(ui_Label13, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label13, "Stats (To Be Done)"); + lv_obj_set_style_text_color(ui_Label13, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label13, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_font(ui_Label13, &ui_font_star32, LV_PART_MAIN | LV_STATE_DEFAULT); + + ui_Label14 = lv_label_create(ui_StatsScreen); + lv_obj_set_width(ui_Label14, LV_SIZE_CONTENT); /// 1 + lv_obj_set_height(ui_Label14, LV_SIZE_CONTENT); /// 1 + lv_obj_set_x(ui_Label14, -179); + lv_obj_set_y(ui_Label14, 126); + lv_obj_set_align(ui_Label14, LV_ALIGN_CENTER); + lv_label_set_text(ui_Label14, "Pre"); + lv_obj_set_style_text_color(ui_Label14, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); + lv_obj_set_style_text_opa(ui_Label14, 255, LV_PART_MAIN | LV_STATE_DEFAULT); + ui_Label16 = lv_label_create(ui_StatsScreen); lv_obj_set_width(ui_Label16, LV_SIZE_CONTENT); /// 1 lv_obj_set_height(ui_Label16, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label16, -185); - lv_obj_set_y(ui_Label16, 121); + lv_obj_set_x(ui_Label16, 59); + lv_obj_set_y(ui_Label16, 126); lv_obj_set_align(ui_Label16, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label16, "Home"); + lv_label_set_text(ui_Label16, "Post"); lv_obj_set_style_text_color(ui_Label16, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); lv_obj_set_style_text_opa(ui_Label16, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - ui_Label20 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label20, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label20, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label20, -64); - lv_obj_set_y(ui_Label20, 121); - lv_obj_set_align(ui_Label20, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label20, "Stats"); - lv_obj_set_style_text_color(ui_Label20, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label20, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label23 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label23, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label23, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label23, 57); - lv_obj_set_y(ui_Label23, 122); - lv_obj_set_align(ui_Label23, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label23, "Clock"); - lv_obj_set_style_text_color(ui_Label23, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label23, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label26 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label26, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label26, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label26, 183); - lv_obj_set_y(ui_Label26, 122); - lv_obj_set_align(ui_Label26, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label26, "Settings"); - lv_obj_set_style_text_color(ui_Label26, lv_color_hex(0x000000), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label26, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container10 = lv_obj_create(ui_StatsScreen); - lv_obj_remove_style_all(ui_Container10); - lv_obj_set_width(ui_Container10, 464); - lv_obj_set_height(ui_Container10, 17); - lv_obj_set_x(ui_Container10, -1); - lv_obj_set_y(ui_Container10, -47); - lv_obj_set_align(ui_Container10, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container10, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container10, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container10, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container10, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container10, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container11 = lv_obj_create(ui_StatsScreen); - lv_obj_remove_style_all(ui_Container11); - lv_obj_set_width(ui_Container11, 464); - lv_obj_set_height(ui_Container11, 17); - lv_obj_set_x(ui_Container11, -1); - lv_obj_set_y(ui_Container11, -18); - lv_obj_set_align(ui_Container11, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container11, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container11, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container11, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container11, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container11, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container12 = lv_obj_create(ui_StatsScreen); - lv_obj_remove_style_all(ui_Container12); - lv_obj_set_width(ui_Container12, 464); - lv_obj_set_height(ui_Container12, 17); - lv_obj_set_x(ui_Container12, -1); - lv_obj_set_y(ui_Container12, 12); - lv_obj_set_align(ui_Container12, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container12, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container12, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container12, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container12, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container12, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container9 = lv_obj_create(ui_StatsScreen); - lv_obj_remove_style_all(ui_Container9); - lv_obj_set_width(ui_Container9, 464); - lv_obj_set_height(ui_Container9, 17); - lv_obj_set_x(ui_Container9, -1); - lv_obj_set_y(ui_Container9, 43); - lv_obj_set_align(ui_Container9, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container9, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container9, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container9, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container9, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container9, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Container13 = lv_obj_create(ui_StatsScreen); - lv_obj_remove_style_all(ui_Container13); - lv_obj_set_width(ui_Container13, 464); - lv_obj_set_height(ui_Container13, 17); - lv_obj_set_x(ui_Container13, -1); - lv_obj_set_y(ui_Container13, 72); - lv_obj_set_align(ui_Container13, LV_ALIGN_CENTER); - lv_obj_clear_flag(ui_Container13, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE); /// Flags - lv_obj_set_style_border_color(ui_Container13, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_opa(ui_Container13, 100, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_width(ui_Container13, 1, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_border_side(ui_Container13, LV_BORDER_SIDE_BOTTOM, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label34 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label34, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label34, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label34, -81); - lv_obj_set_y(ui_Label34, -51); - lv_obj_set_align(ui_Label34, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label34, "Global hashrate EH/s"); - lv_obj_set_style_text_color(ui_Label34, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label34, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label34, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label35 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label35, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label35, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label35, -199); - lv_obj_set_y(ui_Label35, -91); - lv_obj_set_align(ui_Label35, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label35, "Price"); - lv_obj_set_style_text_color(ui_Label35, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label35, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label35, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblPrice = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_lblPrice, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblPrice, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblPrice, 103); - lv_obj_set_y(ui_lblPrice, 42); - lv_label_set_text(ui_lblPrice, "0"); - lv_obj_set_style_text_color(ui_lblPrice, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblPrice, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblPrice, &ui_font_calculator48, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblGlobalHashrate = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_lblGlobalHashrate, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblGlobalHashrate, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblGlobalHashrate, 187); - lv_obj_set_y(ui_lblGlobalHashrate, 88); - lv_label_set_text(ui_lblGlobalHashrate, "0000"); - lv_obj_set_style_text_color(ui_lblGlobalHashrate, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblGlobalHashrate, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblGlobalHashrate, &ui_font_calculator32, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblDifficulty = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_lblDifficulty, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblDifficulty, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblDifficulty, 118); - lv_obj_set_y(ui_lblDifficulty, 118); - lv_label_set_text(ui_lblDifficulty, "0"); - lv_obj_set_style_text_color(ui_lblDifficulty, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblDifficulty, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblDifficulty, &ui_font_calculator32, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label32 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label32, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label32, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label32, -181); - lv_obj_set_y(ui_Label32, -21); - lv_obj_set_align(ui_Label32, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label32, "Difficulty"); - lv_obj_set_style_text_color(ui_Label32, lv_color_hex(0xFAFF00), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label32, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label32, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label33 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label33, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label33, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label33, -152); - lv_obj_set_y(ui_Label33, 9); - lv_obj_set_align(ui_Label33, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label33, "My pool cluster"); - lv_obj_set_style_text_color(ui_Label33, lv_color_hex(0x00D4FF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label33, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label33, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label36 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label36, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label36, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label36, 63); - lv_obj_set_y(ui_Label36, 9); - lv_obj_set_align(ui_Label36, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label36, "Workers"); - lv_obj_set_style_text_color(ui_Label36, lv_color_hex(0x00D4FF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label36, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label36, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label39 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label39, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label39, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label39, -157); - lv_obj_set_y(ui_Label39, 39); - lv_obj_set_align(ui_Label39, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label39, "Total hashrate"); - lv_obj_set_style_text_color(ui_Label39, lv_color_hex(0x00D4FF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label39, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label39, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_Label41 = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_Label41, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_Label41, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_Label41, -159); - lv_obj_set_y(ui_Label41, 69); - lv_obj_set_align(ui_Label41, LV_ALIGN_CENTER); - lv_label_set_text(ui_Label41, "Max difficulty"); - lv_obj_set_style_text_color(ui_Label41, lv_color_hex(0x00D4FF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_Label41, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_Label41, &lv_font_montserrat_20, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblWorkers = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_lblWorkers, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblWorkers, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblWorkers, 357); - lv_obj_set_y(ui_lblWorkers, 148); - lv_label_set_text(ui_lblWorkers, "0"); - lv_obj_set_style_text_color(ui_lblWorkers, lv_color_hex(0x00D4FF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblWorkers, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblWorkers, &ui_font_calculator32, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblTotHashrate = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_lblTotHashrate, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblTotHashrate, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblTotHashrate, 189); - lv_obj_set_y(ui_lblTotHashrate, 179); - lv_label_set_text(ui_lblTotHashrate, "0"); - lv_obj_set_style_text_color(ui_lblTotHashrate, lv_color_hex(0x00D4FF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblTotHashrate, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblTotHashrate, &ui_font_calculator32, LV_PART_MAIN | LV_STATE_DEFAULT); - - ui_lblMaxDifficulty = lv_label_create(ui_StatsScreen); - lv_obj_set_width(ui_lblMaxDifficulty, LV_SIZE_CONTENT); /// 1 - lv_obj_set_height(ui_lblMaxDifficulty, LV_SIZE_CONTENT); /// 1 - lv_obj_set_x(ui_lblMaxDifficulty, 189); - lv_obj_set_y(ui_lblMaxDifficulty, 208); - lv_label_set_text(ui_lblMaxDifficulty, "0"); - lv_obj_set_style_text_color(ui_lblMaxDifficulty, lv_color_hex(0x00D4FF), LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_opa(ui_lblMaxDifficulty, 255, LV_PART_MAIN | LV_STATE_DEFAULT); - lv_obj_set_style_text_font(ui_lblMaxDifficulty, &ui_font_calculator32, LV_PART_MAIN | LV_STATE_DEFAULT); - - lv_obj_add_event_cb(ui_btnpre2, ui_event_btnpre2, LV_EVENT_ALL, NULL); - lv_obj_add_event_cb(ui_btnconfirm2, ui_event_btnconfirm2, LV_EVENT_ALL, NULL); lv_obj_add_event_cb(ui_btnpost2, ui_event_btnpost2, LV_EVENT_ALL, NULL); - lv_obj_add_event_cb(ui_btndelete2, ui_event_btndelete2, LV_EVENT_ALL, NULL); + lv_obj_add_event_cb(ui_btnpre2, ui_event_btnpre2, LV_EVENT_ALL, NULL); } diff --git a/lib/hansolov2/ui.c b/lib/hansolov2/ui.c index 820c7793..a3206607 100644 --- a/lib/hansolov2/ui.c +++ b/lib/hansolov2/ui.c @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -12,151 +12,75 @@ // SCREEN: ui_SplashScreen void ui_SplashScreen_screen_init(void); lv_obj_t * ui_SplashScreen; +lv_obj_t * ui_Label3; +lv_obj_t * ui_Label1; lv_obj_t * ui_lblpassword; lv_obj_t * ui_lblssid; lv_obj_t * ui_lblversion; -// CUSTOM VARIABLES // SCREEN: ui_HomeScreen void ui_HomeScreen_screen_init(void); lv_obj_t * ui_HomeScreen; -lv_obj_t * ui_Container1; -void ui_event_btnconfirm(lv_event_t * e); lv_obj_t * ui_btnconfirm; void ui_event_btnpost(lv_event_t * e); lv_obj_t * ui_btnpost; +lv_obj_t * ui_Image1; lv_obj_t * ui_barhashrate; -void ui_event_btndelete(lv_event_t * e); +lv_obj_t * ui_Label6; +lv_obj_t * ui_Label4; +lv_obj_t * ui_Label7; lv_obj_t * ui_btndelete; +lv_obj_t * ui_Label8; +lv_obj_t * ui_Label10; lv_obj_t * ui_lblhashrate; lv_obj_t * ui_lblbestdiff; lv_obj_t * ui_lbltemplates; lv_obj_t * ui_lblvalid; lv_obj_t * ui_lblshares32; lv_obj_t * ui_lblclock; +lv_obj_t * ui_Label2; void ui_event_btnpre(lv_event_t * e); lv_obj_t * ui_btnpre; +lv_obj_t * ui_Label11; lv_obj_t * ui_lbltotalhashrate; +lv_obj_t * ui_Label19; lv_obj_t * ui_lbltemperature; lv_obj_t * ui_Label5; lv_obj_t * ui_Label9; -lv_obj_t * ui_Label3; -lv_obj_t * ui_Label4; -lv_obj_t * ui_Label6; -lv_obj_t * ui_Label7; -lv_obj_t * ui_Label8; -lv_obj_t * ui_Label10; -lv_obj_t * ui_Label11; -lv_obj_t * ui_Label12; -lv_obj_t * ui_Container2; -lv_obj_t * ui_Container3; -lv_obj_t * ui_Container4; -lv_obj_t * ui_Label13; -lv_obj_t * ui_Label18; -// CUSTOM VARIABLES // SCREEN: ui_StatsScreen void ui_StatsScreen_screen_init(void); lv_obj_t * ui_StatsScreen; -lv_obj_t * ui_Label2; -void ui_event_btnpre2(lv_event_t * e); -lv_obj_t * ui_btnpre2; -void ui_event_btnconfirm2(lv_event_t * e); lv_obj_t * ui_btnconfirm2; void ui_event_btnpost2(lv_event_t * e); lv_obj_t * ui_btnpost2; -void ui_event_btndelete2(lv_event_t * e); +lv_obj_t * ui_Image2; lv_obj_t * ui_btndelete2; +void ui_event_btnpre2(lv_event_t * e); +lv_obj_t * ui_btnpre2; +lv_obj_t * ui_Label13; +lv_obj_t * ui_Label14; lv_obj_t * ui_Label16; -lv_obj_t * ui_Label20; -lv_obj_t * ui_Label23; -lv_obj_t * ui_Label26; -lv_obj_t * ui_Container10; -lv_obj_t * ui_Container11; -lv_obj_t * ui_Container12; -lv_obj_t * ui_Container9; -lv_obj_t * ui_Container13; -lv_obj_t * ui_Label34; -lv_obj_t * ui_Label35; -lv_obj_t * ui_lblPrice; -lv_obj_t * ui_lblGlobalHashrate; -lv_obj_t * ui_lblDifficulty; -lv_obj_t * ui_Label32; -lv_obj_t * ui_Label33; -lv_obj_t * ui_Label36; -lv_obj_t * ui_Label39; -lv_obj_t * ui_Label41; -lv_obj_t * ui_lblWorkers; -lv_obj_t * ui_lblTotHashrate; -lv_obj_t * ui_lblMaxDifficulty; -// CUSTOM VARIABLES // SCREEN: ui_ClockScreen void ui_ClockScreen_screen_init(void); lv_obj_t * ui_ClockScreen; -lv_obj_t * ui_Label14; -lv_obj_t * ui_lblclock2; +lv_obj_t * ui_Label18; void ui_event_btnpre3(lv_event_t * e); lv_obj_t * ui_btnpre3; -void ui_event_btnconfirm3(lv_event_t * e); lv_obj_t * ui_btnconfirm3; void ui_event_btnpost3(lv_event_t * e); lv_obj_t * ui_btnpost3; -void ui_event_btndelete3(lv_event_t * e); lv_obj_t * ui_btndelete3; -lv_obj_t * ui_Label17; -lv_obj_t * ui_Label21; -lv_obj_t * ui_Label24; -lv_obj_t * ui_Label27; -lv_obj_t * ui_lblHeight2; -lv_obj_t * ui_Label37; -lv_obj_t * ui_Label38; -lv_obj_t * ui_Label40; -lv_obj_t * ui_barhalving; -// CUSTOM VARIABLES - - -// SCREEN: ui_SettingsScreen -void ui_SettingsScreen_screen_init(void); -lv_obj_t * ui_SettingsScreen; +lv_obj_t * ui_lblclock2; lv_obj_t * ui_Label15; -void ui_event_btnpre4(lv_event_t * e); -lv_obj_t * ui_btnpre4; -void ui_event_btnconfirm4(lv_event_t * e); -lv_obj_t * ui_btnconfirm4; -void ui_event_btnpost4(lv_event_t * e); -lv_obj_t * ui_btnpost4; -void ui_event_btndelete4(lv_event_t * e); -lv_obj_t * ui_btndelete4; -lv_obj_t * ui_Label19; -lv_obj_t * ui_Label22; -lv_obj_t * ui_Label25; -lv_obj_t * ui_Label28; -void ui_event_btndelete1(lv_event_t * e); -lv_obj_t * ui_btndelete1; -lv_obj_t * ui_Label1; -lv_obj_t * ui_Container6; -lv_obj_t * ui_Container7; -lv_obj_t * ui_Container8; -lv_obj_t * ui_Label30; -lv_obj_t * ui_Label29; -lv_obj_t * ui_Label31; -lv_obj_t * ui_Container5; -lv_obj_t * ui_lblIp; -lv_obj_t * ui_lblPool; -lv_obj_t * ui_lblAddress; -lv_obj_t * ui_lblversion2; -lv_obj_t * ui_Label42; -// CUSTOM VARIABLES - -// EVENTS +lv_obj_t * ui_Label17; lv_obj_t * ui____initial_actions0; - -// IMAGES AND IMAGE SETS const lv_img_dsc_t * ui_imgset_2063710799[1] = {&ui_img_1552732429}; +const lv_img_dsc_t * ui_imgset_metal[1] = {&ui_img_metal2_png}; ///////////////////// TEST LVGL SETTINGS //////////////////// #if LV_COLOR_DEPTH != 16 @@ -169,159 +93,55 @@ const lv_img_dsc_t * ui_imgset_2063710799[1] = {&ui_img_1552732429}; ///////////////////// ANIMATIONS //////////////////// ///////////////////// FUNCTIONS //////////////////// -void ui_event_btnconfirm(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_StatsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_StatsScreen_screen_init); - } -} - void ui_event_btnpost(lv_event_t * e) { lv_event_code_t event_code = lv_event_get_code(e); - + lv_obj_t * target = lv_event_get_target(e); if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_ClockScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_ClockScreen_screen_init); - } -} - -void ui_event_btndelete(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_SettingsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_SettingsScreen_screen_init); + _ui_screen_change(&ui_StatsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_StatsScreen_screen_init); } } - void ui_event_btnpre(lv_event_t * e) { lv_event_code_t event_code = lv_event_get_code(e); - + lv_obj_t * target = lv_event_get_target(e); if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_HomeScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_HomeScreen_screen_init); - } -} - -void ui_event_btnpre2(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_HomeScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_HomeScreen_screen_init); - } -} - -void ui_event_btnconfirm2(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_StatsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_StatsScreen_screen_init); + _ui_screen_change(&ui_ClockScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_ClockScreen_screen_init); } } - void ui_event_btnpost2(lv_event_t * e) { lv_event_code_t event_code = lv_event_get_code(e); - + lv_obj_t * target = lv_event_get_target(e); if(event_code == LV_EVENT_CLICKED) { _ui_screen_change(&ui_ClockScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_ClockScreen_screen_init); } } - -void ui_event_btndelete2(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_SettingsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_SettingsScreen_screen_init); - } -} - -void ui_event_btnpre3(lv_event_t * e) +void ui_event_btnpre2(lv_event_t * e) { lv_event_code_t event_code = lv_event_get_code(e); - + lv_obj_t * target = lv_event_get_target(e); if(event_code == LV_EVENT_CLICKED) { _ui_screen_change(&ui_HomeScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_HomeScreen_screen_init); } } - -void ui_event_btnconfirm3(lv_event_t * e) +void ui_event_btnpre3(lv_event_t * e) { lv_event_code_t event_code = lv_event_get_code(e); - + lv_obj_t * target = lv_event_get_target(e); if(event_code == LV_EVENT_CLICKED) { _ui_screen_change(&ui_StatsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_StatsScreen_screen_init); } } - void ui_event_btnpost3(lv_event_t * e) { lv_event_code_t event_code = lv_event_get_code(e); - + lv_obj_t * target = lv_event_get_target(e); if(event_code == LV_EVENT_CLICKED) { _ui_screen_change(&ui_ClockScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_ClockScreen_screen_init); } } -void ui_event_btndelete3(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_SettingsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_SettingsScreen_screen_init); - } -} - -void ui_event_btnpre4(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_HomeScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_HomeScreen_screen_init); - } -} - -void ui_event_btnconfirm4(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_StatsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_StatsScreen_screen_init); - } -} - -void ui_event_btnpost4(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_ClockScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_ClockScreen_screen_init); - } -} - -void ui_event_btndelete4(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_CLICKED) { - _ui_screen_change(&ui_SettingsScreen, LV_SCR_LOAD_ANIM_FADE_ON, 500, 0, &ui_SettingsScreen_screen_init); - } -} - -void ui_event_btndelete1(lv_event_t * e) -{ - lv_event_code_t event_code = lv_event_get_code(e); - - if(event_code == LV_EVENT_LONG_PRESSED) { - reset_configuration_event(e); - } -} - ///////////////////// SCREENS //////////////////// void ui_init(void) @@ -334,7 +154,6 @@ void ui_init(void) ui_HomeScreen_screen_init(); ui_StatsScreen_screen_init(); ui_ClockScreen_screen_init(); - ui_SettingsScreen_screen_init(); ui____initial_actions0 = lv_obj_create(NULL); lv_disp_load_scr(ui_SplashScreen); } diff --git a/lib/hansolov2/ui.h b/lib/hansolov2/ui.h index de093dbf..947cef5a 100644 --- a/lib/hansolov2/ui.h +++ b/lib/hansolov2/ui.h @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -18,151 +18,75 @@ extern "C" { // SCREEN: ui_SplashScreen void ui_SplashScreen_screen_init(void); extern lv_obj_t * ui_SplashScreen; +extern lv_obj_t * ui_Label3; +extern lv_obj_t * ui_Label1; extern lv_obj_t * ui_lblpassword; extern lv_obj_t * ui_lblssid; extern lv_obj_t * ui_lblversion; -// CUSTOM VARIABLES - // SCREEN: ui_HomeScreen void ui_HomeScreen_screen_init(void); extern lv_obj_t * ui_HomeScreen; -extern lv_obj_t * ui_Container1; -void ui_event_btnconfirm(lv_event_t * e); extern lv_obj_t * ui_btnconfirm; void ui_event_btnpost(lv_event_t * e); extern lv_obj_t * ui_btnpost; +extern lv_obj_t * ui_Image1; extern lv_obj_t * ui_barhashrate; -void ui_event_btndelete(lv_event_t * e); +extern lv_obj_t * ui_Label6; +extern lv_obj_t * ui_Label4; +extern lv_obj_t * ui_Label7; extern lv_obj_t * ui_btndelete; +extern lv_obj_t * ui_Label8; +extern lv_obj_t * ui_Label10; extern lv_obj_t * ui_lblhashrate; extern lv_obj_t * ui_lblbestdiff; extern lv_obj_t * ui_lbltemplates; extern lv_obj_t * ui_lblvalid; extern lv_obj_t * ui_lblshares32; extern lv_obj_t * ui_lblclock; +extern lv_obj_t * ui_Label2; void ui_event_btnpre(lv_event_t * e); extern lv_obj_t * ui_btnpre; +extern lv_obj_t * ui_Label11; extern lv_obj_t * ui_lbltotalhashrate; +extern lv_obj_t * ui_Label19; extern lv_obj_t * ui_lbltemperature; extern lv_obj_t * ui_Label5; extern lv_obj_t * ui_Label9; -extern lv_obj_t * ui_Label3; -extern lv_obj_t * ui_Label4; -extern lv_obj_t * ui_Label6; -extern lv_obj_t * ui_Label7; -extern lv_obj_t * ui_Label8; -extern lv_obj_t * ui_Label10; -extern lv_obj_t * ui_Label11; -extern lv_obj_t * ui_Label12; -extern lv_obj_t * ui_Container2; -extern lv_obj_t * ui_Container3; -extern lv_obj_t * ui_Container4; -extern lv_obj_t * ui_Label13; -extern lv_obj_t * ui_Label18; -// CUSTOM VARIABLES - // SCREEN: ui_StatsScreen void ui_StatsScreen_screen_init(void); extern lv_obj_t * ui_StatsScreen; -extern lv_obj_t * ui_Label2; -void ui_event_btnpre2(lv_event_t * e); -extern lv_obj_t * ui_btnpre2; -void ui_event_btnconfirm2(lv_event_t * e); extern lv_obj_t * ui_btnconfirm2; void ui_event_btnpost2(lv_event_t * e); extern lv_obj_t * ui_btnpost2; -void ui_event_btndelete2(lv_event_t * e); +extern lv_obj_t * ui_Image2; extern lv_obj_t * ui_btndelete2; +void ui_event_btnpre2(lv_event_t * e); +extern lv_obj_t * ui_btnpre2; +extern lv_obj_t * ui_Label13; +extern lv_obj_t * ui_Label14; extern lv_obj_t * ui_Label16; -extern lv_obj_t * ui_Label20; -extern lv_obj_t * ui_Label23; -extern lv_obj_t * ui_Label26; -extern lv_obj_t * ui_Container10; -extern lv_obj_t * ui_Container11; -extern lv_obj_t * ui_Container12; -extern lv_obj_t * ui_Container9; -extern lv_obj_t * ui_Container13; -extern lv_obj_t * ui_Label34; -extern lv_obj_t * ui_Label35; -extern lv_obj_t * ui_lblPrice; -extern lv_obj_t * ui_lblGlobalHashrate; -extern lv_obj_t * ui_lblDifficulty; -extern lv_obj_t * ui_Label32; -extern lv_obj_t * ui_Label33; -extern lv_obj_t * ui_Label36; -extern lv_obj_t * ui_Label39; -extern lv_obj_t * ui_Label41; -extern lv_obj_t * ui_lblWorkers; -extern lv_obj_t * ui_lblTotHashrate; -extern lv_obj_t * ui_lblMaxDifficulty; -// CUSTOM VARIABLES - // SCREEN: ui_ClockScreen void ui_ClockScreen_screen_init(void); extern lv_obj_t * ui_ClockScreen; -extern lv_obj_t * ui_Label14; -extern lv_obj_t * ui_lblclock2; +extern lv_obj_t * ui_Label18; void ui_event_btnpre3(lv_event_t * e); extern lv_obj_t * ui_btnpre3; -void ui_event_btnconfirm3(lv_event_t * e); extern lv_obj_t * ui_btnconfirm3; void ui_event_btnpost3(lv_event_t * e); extern lv_obj_t * ui_btnpost3; -void ui_event_btndelete3(lv_event_t * e); extern lv_obj_t * ui_btndelete3; -extern lv_obj_t * ui_Label17; -extern lv_obj_t * ui_Label21; -extern lv_obj_t * ui_Label24; -extern lv_obj_t * ui_Label27; -extern lv_obj_t * ui_lblHeight2; -extern lv_obj_t * ui_Label37; -extern lv_obj_t * ui_Label38; -extern lv_obj_t * ui_Label40; -extern lv_obj_t * ui_barhalving; -// CUSTOM VARIABLES - -// SCREEN: ui_SettingsScreen -void ui_SettingsScreen_screen_init(void); -extern lv_obj_t * ui_SettingsScreen; +extern lv_obj_t * ui_lblclock2; extern lv_obj_t * ui_Label15; -void ui_event_btnpre4(lv_event_t * e); -extern lv_obj_t * ui_btnpre4; -void ui_event_btnconfirm4(lv_event_t * e); -extern lv_obj_t * ui_btnconfirm4; -void ui_event_btnpost4(lv_event_t * e); -extern lv_obj_t * ui_btnpost4; -void ui_event_btndelete4(lv_event_t * e); -extern lv_obj_t * ui_btndelete4; -extern lv_obj_t * ui_Label19; -extern lv_obj_t * ui_Label22; -extern lv_obj_t * ui_Label25; -extern lv_obj_t * ui_Label28; -void ui_event_btndelete1(lv_event_t * e); -extern lv_obj_t * ui_btndelete1; -extern lv_obj_t * ui_Label1; -extern lv_obj_t * ui_Container6; -extern lv_obj_t * ui_Container7; -extern lv_obj_t * ui_Container8; -extern lv_obj_t * ui_Label30; -extern lv_obj_t * ui_Label29; -extern lv_obj_t * ui_Label31; -extern lv_obj_t * ui_Container5; -extern lv_obj_t * ui_lblIp; -extern lv_obj_t * ui_lblPool; -extern lv_obj_t * ui_lblAddress; -extern lv_obj_t * ui_lblversion2; -extern lv_obj_t * ui_Label42; -// CUSTOM VARIABLES - -// EVENTS +extern lv_obj_t * ui_Label17; extern lv_obj_t * ui____initial_actions0; -// IMAGES AND IMAGE SETS -LV_IMG_DECLARE(ui_img_back_splash_png); // assets/Back/splash.png -LV_IMG_DECLARE(ui_img_back_back_png); // assets/Back/back.png + +LV_IMG_DECLARE(ui_img_sky_png); // assets/sky.png LV_IMG_DECLARE(ui_img_1552732429); // assets/bitcoin-btc-logo-100.png +LV_IMG_DECLARE(ui_img_metal2_png); // assets/metal2.png + + -// FONTS LV_FONT_DECLARE(ui_font_calculator128); LV_FONT_DECLARE(ui_font_calculator16); LV_FONT_DECLARE(ui_font_calculator24); @@ -172,7 +96,8 @@ LV_FONT_DECLARE(ui_font_star24); LV_FONT_DECLARE(ui_font_star32); LV_FONT_DECLARE(ui_font_start16); -// UI INIT + + void ui_init(void); #ifdef __cplusplus diff --git a/lib/hansolov2/ui_events.h b/lib/hansolov2/ui_events.h index 274e730a..54f58999 100644 --- a/lib/hansolov2/ui_events.h +++ b/lib/hansolov2/ui_events.h @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -10,8 +10,6 @@ extern "C" { #endif -void reset_configuration_event(lv_event_t * e); - #ifdef __cplusplus } /*extern "C"*/ #endif diff --git a/lib/hansolov2/ui_helpers.c b/lib/hansolov2/ui_helpers.c index b1ded26c..e9b74b02 100644 --- a/lib/hansolov2/ui_helpers.c +++ b/lib/hansolov2/ui_helpers.c @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -19,6 +19,7 @@ void _ui_basic_set_property(lv_obj_t * target, int id, int val) if(id == _UI_BASIC_PROPERTY_HEIGHT) lv_obj_set_height(target, val); } + void _ui_dropdown_set_property(lv_obj_t * target, int id, int val) { if(id == _UI_DROPDOWN_PROPERTY_SELECTED) lv_dropdown_set_selected(target, val); @@ -34,6 +35,7 @@ void _ui_label_set_property(lv_obj_t * target, int id, const char * val) if(id == _UI_LABEL_PROPERTY_TEXT) lv_label_set_text(target, val); } + void _ui_roller_set_property(lv_obj_t * target, int id, int val) { if(id == _UI_ROLLER_PROPERTY_SELECTED_WITH_ANIM) lv_roller_set_selected(target, val, LV_ANIM_ON); @@ -46,6 +48,7 @@ void _ui_slider_set_property(lv_obj_t * target, int id, int val) if(id == _UI_SLIDER_PROPERTY_VALUE) lv_slider_set_value(target, val, LV_ANIM_OFF); } + void _ui_screen_change(lv_obj_t ** target, lv_scr_load_anim_t fademode, int spd, int delay, void (*target_init)(void)) { if(*target == NULL) @@ -105,8 +108,11 @@ void _ui_state_modify(lv_obj_t * target, int32_t state, int value) else lv_obj_clear_state(target, state); } + void _ui_textarea_move_cursor(lv_obj_t * target, int val) + { + if(val == UI_MOVE_CURSOR_UP) lv_textarea_cursor_up(target); if(val == UI_MOVE_CURSOR_RIGHT) lv_textarea_cursor_right(target); if(val == UI_MOVE_CURSOR_DOWN) lv_textarea_cursor_down(target); @@ -115,10 +121,13 @@ void _ui_textarea_move_cursor(lv_obj_t * target, int val) } void scr_unloaded_delete_cb(lv_event_t * e) + { + lv_obj_t ** var = lv_event_get_user_data(e); lv_obj_del(*var); (*var) = NULL; + } void _ui_opacity_set(lv_obj_t * target, int val) @@ -133,115 +142,178 @@ void _ui_anim_callback_free_user_data(lv_anim_t * a) } void _ui_anim_callback_set_x(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; lv_obj_set_x(usr->target, v); + } + void _ui_anim_callback_set_y(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; lv_obj_set_y(usr->target, v); + } + void _ui_anim_callback_set_width(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; lv_obj_set_width(usr->target, v); + } + void _ui_anim_callback_set_height(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; lv_obj_set_height(usr->target, v); + } + void _ui_anim_callback_set_opacity(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; lv_obj_set_style_opa(usr->target, v, 0); + } + void _ui_anim_callback_set_image_zoom(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; lv_img_set_zoom(usr->target, v); + } + void _ui_anim_callback_set_image_angle(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; lv_img_set_angle(usr->target, v); + } + void _ui_anim_callback_set_image_frame(lv_anim_t * a, int32_t v) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; usr->val = v; + if(v < 0) v = 0; if(v >= usr->imgset_size) v = usr->imgset_size - 1; lv_img_set_src(usr->target, usr->imgset[v]); } int32_t _ui_anim_callback_get_x(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return lv_obj_get_x_aligned(usr->target); + } + int32_t _ui_anim_callback_get_y(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return lv_obj_get_y_aligned(usr->target); + } + int32_t _ui_anim_callback_get_width(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return lv_obj_get_width(usr->target); + } + int32_t _ui_anim_callback_get_height(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return lv_obj_get_height(usr->target); + } + int32_t _ui_anim_callback_get_opacity(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return lv_obj_get_style_opa(usr->target, 0); + } int32_t _ui_anim_callback_get_image_zoom(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return lv_img_get_zoom(usr->target); + } int32_t _ui_anim_callback_get_image_angle(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return lv_img_get_angle(usr->target); + } int32_t _ui_anim_callback_get_image_frame(lv_anim_t * a) + { + ui_anim_user_data_t * usr = (ui_anim_user_data_t *)a->user_data; return usr->val; + } void _ui_arc_set_text_value(lv_obj_t * trg, lv_obj_t * src, const char * prefix, const char * postfix) { char buf[_UI_TEMPORARY_STRING_BUFFER_SIZE]; + lv_snprintf(buf, sizeof(buf), "%s%d%s", prefix, (int)lv_arc_get_value(src), postfix); + lv_label_set_text(trg, buf); } void _ui_slider_set_text_value(lv_obj_t * trg, lv_obj_t * src, const char * prefix, const char * postfix) { char buf[_UI_TEMPORARY_STRING_BUFFER_SIZE]; + lv_snprintf(buf, sizeof(buf), "%s%d%s", prefix, (int)lv_slider_get_value(src), postfix); + lv_label_set_text(trg, buf); } void _ui_checked_set_text_value(lv_obj_t * trg, lv_obj_t * src, const char * txt_on, const char * txt_off) @@ -250,18 +322,26 @@ void _ui_checked_set_text_value(lv_obj_t * trg, lv_obj_t * src, const char * txt else lv_label_set_text(trg, txt_off); } + void _ui_spinbox_step(lv_obj_t * target, int val) + { + if(val > 0) lv_spinbox_increment(target); + else lv_spinbox_decrement(target); + lv_event_send(target, LV_EVENT_VALUE_CHANGED, 0); } void _ui_switch_theme(int val) + { + #ifdef UI_THEME_ACTIVE ui_theme_set(val); #endif } + diff --git a/lib/hansolov2/ui_helpers.h b/lib/hansolov2/ui_helpers.h index a2a526b6..5c2600d4 100644 --- a/lib/hansolov2/ui_helpers.h +++ b/lib/hansolov2/ui_helpers.h @@ -1,5 +1,5 @@ // This file was generated by SquareLine Studio -// SquareLine Studio version: SquareLine Studio 1.5.0 +// SquareLine Studio version: SquareLine Studio 1.4.0 // LVGL version: 8.3.6 // Project name: han-wt32 @@ -69,6 +69,7 @@ void _ui_state_modify(lv_obj_t * target, int32_t state, int value); void _ui_textarea_move_cursor(lv_obj_t * target, int val) ; + void scr_unloaded_delete_cb(lv_event_t * e); void _ui_opacity_set(lv_obj_t * target, int val); @@ -90,30 +91,41 @@ void _ui_anim_callback_set_width(lv_anim_t * a, int32_t v); void _ui_anim_callback_set_height(lv_anim_t * a, int32_t v); + void _ui_anim_callback_set_opacity(lv_anim_t * a, int32_t v); + void _ui_anim_callback_set_image_zoom(lv_anim_t * a, int32_t v); + void _ui_anim_callback_set_image_angle(lv_anim_t * a, int32_t v); + void _ui_anim_callback_set_image_frame(lv_anim_t * a, int32_t v); + int32_t _ui_anim_callback_get_x(lv_anim_t * a); int32_t _ui_anim_callback_get_y(lv_anim_t * a); int32_t _ui_anim_callback_get_width(lv_anim_t * a); + int32_t _ui_anim_callback_get_height(lv_anim_t * a); + int32_t _ui_anim_callback_get_opacity(lv_anim_t * a); + int32_t _ui_anim_callback_get_image_zoom(lv_anim_t * a); + int32_t _ui_anim_callback_get_image_angle(lv_anim_t * a); + int32_t _ui_anim_callback_get_image_frame(lv_anim_t * a); + void _ui_arc_set_text_value(lv_obj_t * trg, lv_obj_t * src, const char * prefix, const char * postfix); void _ui_slider_set_text_value(lv_obj_t * trg, lv_obj_t * src, const char * prefix, const char * postfix); @@ -123,9 +135,12 @@ void _ui_checked_set_text_value(lv_obj_t * trg, lv_obj_t * src, const char * txt void _ui_spinbox_step(lv_obj_t * target, int val) ; + void _ui_switch_theme(int val) ; + + #ifdef __cplusplus } /*extern "C"*/ #endif diff --git a/platformio.ini b/platformio.ini index 8f8b9f24..602e4eea 100644 --- a/platformio.ini +++ b/platformio.ini @@ -11,25 +11,12 @@ [platformio] globallib_dir = lib -default_envs = NerdminerV2, NerdminerV2-T-HMI, wt32-sc01, wt32-sc01-plus, han_m5stack, M5Stick-C, M5Stick-C-Plus2, M5Stick-CPlus, esp32cam, ESP32-2432S028R, ESP32_2432S028_2USB, ESP32-2432S024, Lilygo-T-Embed, ESP32-devKitv1, NerdminerV2-S3-DONGLE, NerdminerV2-S3-GEEK, NerdminerV2-S3-AMOLED, NerdminerV2-S3-AMOLED-TOUCH, NerdminerV2-T-QT, NerdminerV2-T-Display_V1, TTGO-T-Display, M5-StampS3, ESP32-S3-devKitv1, ESP32-S3-mini-wemos, ESP32-S2-mini-wemos, ESP32-S3-mini-weact, ESP32-D0WD-V3-weact, ESP32-C3-super-mini, ESP32-C3-devKitmv1, ESP32-C3-042-OLED, ESP32-S3-042-OLED, ESP32-C3-spotpear, esp32-s3-devkitc1-n32r8 - -; Global configuration for all environments -[env] -monitor_eol = CRLF -monitor_echo = yes -monitor_filters = - esp32_exception_decoder - time - log2file - send_on_enter +default_envs = NerdminerV2-T-HMI, wt32-sc01, wt32-sc01-plus, han_m5stack, M5Stick-C, esp32cam, ESP32-2432S028R, ESP32_2432S028_2USB, NerdminerV2, Lilygo-T-Embed, ESP32-devKitv1, NerdminerV2-S3-DONGLE, NerdminerV2-S3-GEEK, NerdminerV2-S3-AMOLED, NerdminerV2-S3-AMOLED-TOUCH, NerdminerV2-T-QT, NerdminerV2-T-Display_V1, ESP32-2432S028R, M5-StampS3, ESP32-S3-devKitv1, ESP32-S3-mini-wemos, ESP32-S2-mini-wemos, ESP32-S3-mini-weact, ESP32-D0WD-V3-weact, ESP32-C3-devKitmv1, ESP32-C3-super-mini [env:M5Stick-C-Plus2] platform = espressif32@6.6.0 board = m5stick-c-plus2 framework = arduino -extra_scripts = - pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -57,14 +44,12 @@ lib_ignore = ;-------------------------------------------------------------------- - [env:M5Stick-C] platform = espressif32@6.6.0 board = m5stick-c framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -96,9 +81,6 @@ lib_ignore = platform = espressif32@6.6.0 board = m5stick-c framework = arduino -extra_scripts = - pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -133,7 +115,6 @@ board = esp-wrover-kit framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -168,7 +149,6 @@ board = esp32-s3-devkitc-1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -206,7 +186,6 @@ board = lolin_s3_mini framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -241,7 +220,6 @@ board = m5stack-core-esp32 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -274,7 +252,6 @@ board = lolin_s2_mini framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -306,7 +283,6 @@ board = lolin_s3_mini framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -321,6 +297,8 @@ build_flags = -D ARDUINO_USB_CDC_ON_BOOT=1 -D ESP32RGB=1 -D RGB_LED_PIN=48 + ; -D WIFI_MANAGER_COUNTRY=\"BR\" + -D WIFI_CONNECT_RETRIES=8 ;-D DEBUG_MINING=1 lib_deps = https://github.com/takkaO/OpenFontRender#v1.2 @@ -332,7 +310,10 @@ lib_deps = lib_ignore = TFT_eSPI HANSOLOminerv2 - + + + + ;-------------------------------------------------------------------- [env:ESP32-D0WD-V3-weact] @@ -341,7 +322,6 @@ board = esp32dev framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -373,7 +353,6 @@ board = seeed_xiao_esp32c3 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -406,7 +385,6 @@ board = esp32-c3-devkitm-1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -438,9 +416,6 @@ lib_ignore = platform = espressif32@6.6.0 board = esp32-c3-devkitm-1 framework = arduino -extra_scripts = - pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -470,9 +445,6 @@ lib_ignore = platform = espressif32@6.6.0 board = esp32-s3-0.42oled framework = arduino -extra_scripts = - pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -498,43 +470,12 @@ lib_ignore = ;-------------------------------------------------------------------- -[env:ESP32-C3-spotpear] -platform = espressif32@6.6.0 -board = seeed_xiao_esp32c3 -framework = arduino -monitor_filters = - esp32_exception_decoder - time - log2file -monitor_speed = 115200 -upload_speed = 115200 -board_build.partitions = huge_app.csv -build_flags = - -D ARDUINO_USB_MODE=1 - -D ARDUINO_USB_CDC_ON_BOOT=1 - -D SPOTPEAR=1 - -D PIN_BUTTON_1=8 - -D LED_PIN=11 - -D DISABLE_ALL_LIBRARY_WARNINGS - ;-D DEBUG_MINING=1 -lib_deps = - https://github.com/takkaO/OpenFontRender#v1.2 - bblanchon/ArduinoJson@^6.21.5 - https://github.com/tzapu/WiFiManager.git#v2.0.17 - mathertel/OneButton@^2.5.0 - arduino-libraries/NTPClient@^3.2.1 -lib_ignore = - HANSOLOminerv2 - -;-------------------------------------------------------------------- - [env:ESP32-S3-devKitv1] platform = espressif32@6.6.0 board = esp32-s3-devkitc-1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -561,40 +502,6 @@ lib_ignore = TFT_eSPI HANSOLOminerv2 -;----------------------------------------------------------------------- -[env:esp32-s3-devkitc1-n32r8] -platform = espressif32@6.6.0 -board = esp32-s3-devkitc1-n32r8 -framework = arduino - -extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py - -monitor_speed = 115200 -upload_speed = 115200 -monitor_filters = esp32_exception_decoder, time, log2file - -board_build.partitions = huge_app.csv -board_build.filesystem = LittleFS - -build_flags = - -D BOARD_HAS_PSRAM - -D ARDUINO_USB_MODE=1 - -D ARDUINO_USB_CDC_ON_BOOT=1 - -D ESP32RGB=1 - -D RGB_LED_PIN=38 - ;-D DEBUG_MINING=1 - -lib_deps = - https://github.com/takkaO/OpenFontRender#v1.2 - bblanchon/ArduinoJson@^6.21.5 - https://github.com/tzapu/WiFiManager.git#v2.0.17 - mathertel/oneButton@^2.6.1 - arduino-libraries/NTPClient@^3.2.1 - fastled/FastLED@3.7.8 - -lib_ignore = TFT_eSPI, HANSOLOminerv2 - ;-------------------------------------------------------------------- [env:NerdminerV2] @@ -603,8 +510,6 @@ board = esp32-s3-devkitc-1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py -board_build.f_cpu = 240000000L monitor_filters = esp32_exception_decoder time @@ -617,16 +522,20 @@ upload_speed = 115200 ;board_build.partitions = default_8MB.csv board_build.partitions = huge_app.csv ;board_build.partitions = default.csv +build_unflags = + -Os + -fno-lto build_flags = -D LV_LVGL_H_INCLUDE_SIMPLE -D BOARD_HAS_PSRAM - -D ARDUINO_USB_MODE=1 - -D ARDUINO_USB_CDC_ON_BOOT=1 -D NERDMINERV2=1 - -D CORE_DEBUG_LEVEL=0 - -D CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL=0 + -D MONITOR_TASK_PRIORITY=3 + -O3 + -flto + -funroll-loops + -fomit-frame-pointer + -D NDEBUG ;-D DEBUG_MINING=1 - ;To enable I2C mining in future: -D ENABLE_I2C_MINING=1 lib_deps = https://github.com/takkaO/OpenFontRender#v1.2 bblanchon/ArduinoJson@^6.21.5 @@ -644,7 +553,6 @@ board = esp32-s3-devkitc-1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -681,7 +589,6 @@ board = esp32dev framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -691,8 +598,17 @@ monitor_speed = 115200 upload_speed = 921600 # 2 x 4.5MB app, 6.875MB SPIFFS board_build.partitions = huge_app.csv +board_build.f_cpu = 240000000L +build_unflags = + -Os + -fno-lto build_flags = -D DEVKITV1=1 + -O3 + -flto + -funroll-loops + -fomit-frame-pointer + -D NDEBUG ;-D DEBUG_MINING=1 lib_deps = https://github.com/takkaO/OpenFontRender#v1.2 @@ -711,7 +627,6 @@ board = esp32dev ;esp-wrover-kit framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -744,7 +659,6 @@ board = lilygo-t-amoled framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py board_build.partitions = huge_app.csv build_flags = -DNERDMINER_S3_AMOLED @@ -769,7 +683,6 @@ board = lilygo-t-amoled framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py board_build.partitions = huge_app.csv build_flags = -DNERDMINER_S3_AMOLED @@ -794,7 +707,6 @@ board = esp32-s3-devkitc-1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py board_build.partitions = huge_app.csv build_flags = -DNERDMINER_S3_DONGLE @@ -820,7 +732,6 @@ board = esp32-s3-devkitc-1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py board_build.partitions = huge_app.csv build_flags = -DNERDMINER_S3_GEEK @@ -849,7 +760,6 @@ board = esp32cam framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -881,7 +791,6 @@ board = esp32-s3-t-qt-pro framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -913,7 +822,6 @@ board = esp32dev framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_speed = 115200 upload_speed = 921600 ;build_type = debug @@ -964,7 +872,6 @@ board = esp32dev framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_speed = 115200 monitor_filters = esp32_exception_decoder @@ -1014,69 +921,12 @@ lib_ignore = ;-------------------------------------------------------------------- -[env:ESP32-2432S024] -platform = espressif32@6.6.0 -board = esp32dev -framework = arduino -extra_scripts = - pre:auto_firmware_version.py - post:post_build_merge.py -monitor_speed = 115200 -monitor_filters = - esp32_exception_decoder - time - colorize - ;debug -upload_speed = 921600 -;build_type = debug -board_build.partitions = huge_app.csv -build_flags = - ;-DDEBUG_MEMORY=1 - -D ESP32_2432S028R=1 - -DUSER_SETUP_LOADED=1 - -DILI9341_2_DRIVER=1 - -DTFT_WIDTH=240 - -DTFT_HEIGHT=320 - -DTFT_BACKLIGHT_ON=HIGH - -DTFT_MOSI=13 - -DTFT_SCLK=14 - -DTFT_CS=15 - -DTFT_DC=2 - -DTFT_RST=12 - -DTFT_BL=27 - -DETOUCH_CS=33 - -DTOUCH_CLK=25 - -DTOUCH_MISO=39 - -DTOUCH_MOSI=32 - -DTOUCH_IRQ=36 - -DLOAD_GLCD=1 - -DLOAD_FONT2=1 - -DLOAD_GFXFF=1 - -DSMOOTH_FONT=1 - -DSPI_FREQUENCY=55000000 - -DSPI_READ_FREQUENCY=20000000 - -DSPI_TOUCH_FREQUENCY=2500000 - -lib_deps = - https://github.com/takkaO/OpenFontRender#v1.2 - bblanchon/ArduinoJson@^6.21.5 - https://github.com/tzapu/WiFiManager.git#v2.0.17 - mathertel/oneButton@^2.6.1 - arduino-libraries/NTPClient@^3.2.1 - bodmer/TFT_eSPI@^2.5.43 - https://github.com/achillhasler/TFT_eTouch -lib_ignore = - HANSOLOminerv2 - -;-------------------------------------------------------------------- - [env:NerdminerV2-T-HMI] platform = espressif32@6.6.0 board = lilygo-t-hmi framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py board_build.partitions = default_16MB.csv monitor_filters = esp32_exception_decoder @@ -1116,7 +966,6 @@ board = ttgo-lora32-v1 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_speed = 115200 upload_speed = 115200 board_build.partitions = huge_app.csv @@ -1140,7 +989,6 @@ board = m5stack-stamps3 framework = arduino extra_scripts = pre:auto_firmware_version.py - post:post_build_merge.py monitor_filters = esp32_exception_decoder time @@ -1166,5 +1014,29 @@ lib_ignore = SPI HANSOLOminerv2 - - +;-------------------------------------------------------------------- +; I2C hash cluster profiles (single WiFi master + multiple hash slaves) +[env:ESP32-devKitv1-I2C-master] +extends = env:ESP32-devKitv1 +build_flags = + ${env:ESP32-devKitv1.build_flags} + -D I2C_HASH_MASTER=1 + -D I2C_HASH_CLOCK_HZ=1000000 + -D I2C_BOOT_SCAN_ROUNDS=20 + -D I2C_BOOT_SCAN_DELAY_MS=250 + -D I2C_RUNTIME_RESCAN_MS=0 + -D I2C_LOSS_RESCAN_MAX_ATTEMPTS=3 + -D I2C_MASTER_CYCLE_MS=15 + -D I2C_MASTER_POST_HIT_DELAY_MS=0 + -D I2C_MASTER_IDLE_MS=5 + -D I2C_MASTER_DIAG_LOG=0 + -D I2C_MASTER_DIAG_LOG_MS=10000 + +[env:ESP32-devKitv1-I2C-slave] +extends = env:ESP32-devKitv1 +build_flags = + ${env:ESP32-devKitv1.build_flags} + -D I2C_HASH_SLAVE=1 + -D I2C_HASH_CLOCK_HZ=1000000 + -D I2C_SLAVE_LINK_TIMEOUT_MS=1300 + -D I2C_HASH_SLAVE_ADDRESS=0x23 diff --git a/src/NerdMinerV2.ino.cpp b/src/NerdMinerV2.ino.cpp index 548740c8..dc4634be 100644 --- a/src/NerdMinerV2.ino.cpp +++ b/src/NerdMinerV2.ino.cpp @@ -13,9 +13,22 @@ #include "monitor.h" #include "drivers/displays/display.h" #include "drivers/storage/SDCard.h" -#include "ShaTests/nerdSHA_HWTest.h" #include "timeconst.h" +#include "i2c_hash_config.h" + +#if defined(I2C_HASH_SLAVE) +#ifndef I2C_SLAVE_SW_CORE +#define I2C_SLAVE_SW_CORE 0 +#endif +#ifndef I2C_SLAVE_TASK_PRIORITY +#define I2C_SLAVE_TASK_PRIORITY 5 +#endif +#ifndef I2C_SLAVE_SW_TASK_PRIORITY +#define I2C_SLAVE_SW_TASK_PRIORITY 2 +#endif +#endif + #ifdef TOUCH_ENABLE #include "TouchHandler.h" #endif @@ -27,6 +40,12 @@ #define WDT_TIMEOUT 3 //15 minutes WDT for miner task #define WDT_MINER_TIMEOUT 900 +#ifndef MINER_CPU_FREQ_MHZ +#define MINER_CPU_FREQ_MHZ 240 +#endif +#ifndef MONITOR_TASK_PRIORITY +#define MONITOR_TASK_PRIORITY 5 +#endif #ifdef PIN_BUTTON_1 OneButton button1(PIN_BUTTON_1); @@ -53,8 +72,540 @@ extern monitor_data mMonitor; unsigned long start = millis(); const char* ntpServer = "pool.ntp.org"; + //void runMonitor(void *name); +#ifdef HW_SHA256_TEST + +#include +#include "ShaTests/nerdSHA256plus.h" +#include "mbedtls/sha256.h" +#include +#include +#include +#include +#include +#include +#include +#include + +static const uint8_t s_test_buffer[128] = +{ + 0x00, 0x00, 0x00, 0x22, 0x99, 0x44, 0xbb, 0xff, 0xbb, 0x00, 0x00, 0x77, 0x44, 0xcc, 0x11, 0x77, + 0x88, 0x55, 0xbb, 0x44, 0x55, 0x00, 0x77, 0x88, 0x99, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xbb, 0xbb, 0x66, 0x11, 0x88, 0x33, 0x44, 0x99, 0xcc, 0x33, 0xff, 0x22, + 0x11, 0xaa, 0x77, 0xee, 0xbb, 0x66, 0xee, 0xcc, 0xee, 0x66, 0xee, 0xdd, 0x77, 0x55, 0x22, 0x22, + 0xcc, 0xcc, 0x66, 0xee, 0x22, 0xdd, 0x99, 0x66, 0x66, 0x88, 0x00, 0x11, 0x2e, 0x33, 0x41, 0x19, + + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x80 +}; + +static const uint8_t s_test_buffer_aligned[128] __attribute__((aligned(256))) = +{ + 0x00, 0x00, 0x00, 0x22, 0x99, 0x44, 0xbb, 0xff, 0xbb, 0x00, 0x00, 0x77, 0x44, 0xcc, 0x11, 0x77, + 0x88, 0x55, 0xbb, 0x44, 0x55, 0x00, 0x77, 0x88, 0x99, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0xbb, 0xbb, 0x66, 0x11, 0x88, 0x33, 0x44, 0x99, 0xcc, 0x33, 0xff, 0x22, + 0x11, 0xaa, 0x77, 0xee, 0xbb, 0x66, 0xee, 0xcc, 0xee, 0x66, 0xee, 0xdd, 0x77, 0x55, 0x22, 0x22, + 0xcc, 0xcc, 0x66, 0xee, 0x22, 0xdd, 0x99, 0x66, 0x66, 0x88, 0x00, 0x11, 0x2e, 0x33, 0x41, 0x19, + + 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x80 +}; + +static uint8_t interResult_aligned[64] __attribute__((aligned(256))); +static uint8_t midstate_aligned[32] __attribute__((aligned(256))); +static uint8_t hash_aligned[64] __attribute__((aligned(256))); + +#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) +static inline void nerd_sha_hal_wait_idle() +{ + while (REG_READ(SHA_BUSY_REG)) + {} +} + +static inline void nerd_sha_ll_fill_text_block_sha256(const void *input_text) +{ + uint32_t *data_words = (uint32_t *)input_text; + uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE); + + REG_WRITE(®_addr_buf[0], data_words[0]); + REG_WRITE(®_addr_buf[1], data_words[1]); + REG_WRITE(®_addr_buf[2], data_words[2]); + REG_WRITE(®_addr_buf[3], data_words[3]); + REG_WRITE(®_addr_buf[4], data_words[4]); + REG_WRITE(®_addr_buf[5], data_words[5]); + REG_WRITE(®_addr_buf[6], data_words[6]); + REG_WRITE(®_addr_buf[7], data_words[7]); + REG_WRITE(®_addr_buf[8], data_words[8]); + REG_WRITE(®_addr_buf[9], data_words[9]); + REG_WRITE(®_addr_buf[10], data_words[10]); + REG_WRITE(®_addr_buf[11], data_words[11]); + REG_WRITE(®_addr_buf[12], data_words[12]); + REG_WRITE(®_addr_buf[13], data_words[13]); + REG_WRITE(®_addr_buf[14], data_words[14]); + REG_WRITE(®_addr_buf[15], data_words[15]); +} + +static inline void nerd_sha_ll_write_digest_sha256(void *digest_state) +{ + uint32_t *digest_state_words = (uint32_t *)digest_state; + uint32_t *reg_addr_buf = (uint32_t *)(SHA_H_BASE); + + REG_WRITE(®_addr_buf[0], digest_state_words[0]); + REG_WRITE(®_addr_buf[1], digest_state_words[1]); + REG_WRITE(®_addr_buf[2], digest_state_words[2]); + REG_WRITE(®_addr_buf[3], digest_state_words[3]); + REG_WRITE(®_addr_buf[4], digest_state_words[4]); + REG_WRITE(®_addr_buf[5], digest_state_words[5]); + REG_WRITE(®_addr_buf[6], digest_state_words[6]); + REG_WRITE(®_addr_buf[7], digest_state_words[7]); +} + +//void IRAM_ATTR esp_dport_access_read_buffer(uint32_t *buff_out, uint32_t address, uint32_t num_words) +static inline void nerd_sha_ll_read_digest(void* ptr) +{ + DPORT_INTERRUPT_DISABLE(); +#if 0 + for (uint32_t i = 0; i < 256 / 32; ++i) + { + ((uint32_t*)ptr)[i] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + i * 4); + } +#else + ((uint32_t*)ptr)[0] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 0 * 4); + ((uint32_t*)ptr)[1] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 1 * 4); + ((uint32_t*)ptr)[2] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 2 * 4); + ((uint32_t*)ptr)[3] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 3 * 4); + ((uint32_t*)ptr)[4] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 4 * 4); + ((uint32_t*)ptr)[5] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 5 * 4); + ((uint32_t*)ptr)[6] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 6 * 4); + ((uint32_t*)ptr)[7] = DPORT_SEQUENCE_REG_READ(SHA_H_BASE + 7 * 4); +#endif + DPORT_INTERRUPT_RESTORE(); +} + +static IRAM_ATTR uint8_t dma_buffer[128] __attribute__((aligned(32))); +static IRAM_ATTR uint8_t dma_inter[64] __attribute__((aligned(32))); +static IRAM_ATTR uint8_t dma_hash[32] __attribute__((aligned(32))); +static DRAM_ATTR lldesc_t s_dma_descr_input; +static DRAM_ATTR lldesc_t s_dma_descr_buf; +static DRAM_ATTR lldesc_t s_dma_descr_inter; + +#endif + +#if defined(CONFIG_IDF_TARGET_ESP32) +static inline void nerd_sha_ll_read_digest_swap(void* ptr) +{ + DPORT_INTERRUPT_DISABLE(); + ((uint32_t*)ptr)[0] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 0 * 4)); + ((uint32_t*)ptr)[1] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 1 * 4)); + ((uint32_t*)ptr)[2] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 2 * 4)); + ((uint32_t*)ptr)[3] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 3 * 4)); + ((uint32_t*)ptr)[4] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 4 * 4)); + ((uint32_t*)ptr)[5] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 5 * 4)); + ((uint32_t*)ptr)[6] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 6 * 4)); + ((uint32_t*)ptr)[7] = __builtin_bswap32(DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 7 * 4)); + DPORT_INTERRUPT_RESTORE(); +} + +static inline void nerd_sha_ll_read_digest(void* ptr) +{ + DPORT_INTERRUPT_DISABLE(); + ((uint32_t*)ptr)[0] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 0 * 4); + ((uint32_t*)ptr)[1] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 1 * 4); + ((uint32_t*)ptr)[2] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 2 * 4); + ((uint32_t*)ptr)[3] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 3 * 4); + ((uint32_t*)ptr)[4] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 4 * 4); + ((uint32_t*)ptr)[5] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 5 * 4); + ((uint32_t*)ptr)[6] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 6 * 4); + ((uint32_t*)ptr)[7] = DPORT_SEQUENCE_REG_READ(SHA_TEXT_BASE + 7 * 4); + DPORT_INTERRUPT_RESTORE(); +} + +static inline void nerd_sha_hal_wait_idle() +{ + while (DPORT_REG_READ(SHA_256_BUSY_REG)) + {} +} + +static inline void nerd_sha_ll_fill_text_block_sha256(const void *input_text) +{ + uint32_t *data_words = (uint32_t *)input_text; + uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE); + + reg_addr_buf[0] = data_words[0]; + reg_addr_buf[1] = data_words[1]; + reg_addr_buf[2] = data_words[2]; + reg_addr_buf[3] = data_words[3]; + reg_addr_buf[4] = data_words[4]; + reg_addr_buf[5] = data_words[5]; + reg_addr_buf[6] = data_words[6]; + reg_addr_buf[7] = data_words[7]; + reg_addr_buf[8] = data_words[8]; + reg_addr_buf[9] = data_words[9]; + reg_addr_buf[10] = data_words[10]; + reg_addr_buf[11] = data_words[11]; + reg_addr_buf[12] = data_words[12]; + reg_addr_buf[13] = data_words[13]; + reg_addr_buf[14] = data_words[14]; + reg_addr_buf[15] = data_words[15]; +} + +static inline void nerd_sha_ll_fill_text_block_sha256_swap(const void *input_text) +{ + uint32_t *data_words = (uint32_t *)input_text; + uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE); + + reg_addr_buf[0] = __builtin_bswap32(data_words[0]); + reg_addr_buf[1] = __builtin_bswap32(data_words[1]); + reg_addr_buf[2] = __builtin_bswap32(data_words[2]); + reg_addr_buf[3] = __builtin_bswap32(data_words[3]); + reg_addr_buf[4] = __builtin_bswap32(data_words[4]); + reg_addr_buf[5] = __builtin_bswap32(data_words[5]); + reg_addr_buf[6] = __builtin_bswap32(data_words[6]); + reg_addr_buf[7] = __builtin_bswap32(data_words[7]); + reg_addr_buf[8] = __builtin_bswap32(data_words[8]); + reg_addr_buf[9] = __builtin_bswap32(data_words[9]); + reg_addr_buf[10] = __builtin_bswap32(data_words[10]); + reg_addr_buf[11] = __builtin_bswap32(data_words[11]); + reg_addr_buf[12] = __builtin_bswap32(data_words[12]); + reg_addr_buf[13] = __builtin_bswap32(data_words[13]); + reg_addr_buf[14] = __builtin_bswap32(data_words[14]); + reg_addr_buf[15] = __builtin_bswap32(data_words[15]); +} + +static inline void nerd_sha_ll_fill_text_block_sha256_double(const void *input_text) +{ + uint32_t *data_words = (uint32_t *)input_text; + uint32_t *reg_addr_buf = (uint32_t *)(SHA_TEXT_BASE); + +#if 0 + //No change + reg_addr_buf[0] = data_words[0]; + reg_addr_buf[1] = data_words[1]; + reg_addr_buf[2] = data_words[2]; + reg_addr_buf[3] = data_words[3]; + reg_addr_buf[4] = data_words[4]; + reg_addr_buf[5] = data_words[5]; + reg_addr_buf[6] = data_words[6]; + reg_addr_buf[7] = data_words[7]; +#endif + reg_addr_buf[8] = 0x80000000; + reg_addr_buf[9] = 0x00000000; + reg_addr_buf[10] = 0x00000000; + reg_addr_buf[11] = 0x00000000; + reg_addr_buf[12] = 0x00000000; + reg_addr_buf[13] = 0x00000000; + reg_addr_buf[14] = 0x00000000; + reg_addr_buf[15] = 0x00000100; +} +#endif + +IRAM_ATTR void HwShaTest() +{ + uint8_t interResult[64]; + uint8_t midstate[32]; + uint8_t hash[64]; + memset(interResult, 0, sizeof(interResult)); + interResult[32] = 0x80; + interResult[62] = 0x01; + interResult[63] = 0x00; + + memset(interResult_aligned, 0, sizeof(interResult_aligned)); + interResult_aligned[32] = 0x80; + interResult_aligned[62] = 0x01; + interResult_aligned[63] = 0x00; + + uint32_t bake[16]; + + uint32_t time_start = micros(); + int test_count = 1000000; + +#if 0 + //Generic software + //esp32s3 16KH/s + //esp32D 9.5KH/s + test_count = 20000; + mbedtls_sha256_context ctx; + mbedtls_sha256_init(&ctx); + for (int i = 0; i < test_count; ++i) + { + mbedtls_sha256_starts_ret(&ctx,0); + mbedtls_sha256_update_ret(&ctx, s_test_buffer, 80); + mbedtls_sha256_finish_ret(&ctx, interResult); + + mbedtls_sha256_starts_ret(&ctx,0); + mbedtls_sha256_update_ret(&ctx, interResult, 32); + mbedtls_sha256_finish_ret(&ctx, hash); + } + mbedtls_sha256_free(&ctx); +#endif + +#if 1 + //nerdSha256 + //ESP32 39KH/s + //ESP32S3 39.01KH/s + test_count = 100000; + nerdSHA256_context ctx; + nerd_mids(ctx.digest, s_test_buffer); + for (int i = 0; i < test_count; ++i) + { + nerd_sha256d(&ctx, s_test_buffer+64, hash); + } +#endif + +#if 0 + //nerdSha256 bake + //ESP32 : 41KH/s + //ESP32S3 : 42.32KH/s + test_count = 100000; + nerdSHA256_context ctx; + nerd_mids(&ctx, s_test_buffer); + nerd_sha256_bake(ctx.digest, s_test_buffer+64, bake); //15 words + for (int i = 0; i < test_count; ++i) + { + nerd_sha256d_baked(ctx.digest, s_test_buffer+64, bake, hash); + } +#endif + +#if 0 + //Hardware high level 62KH/s + esp_sha_acquire_hardware(); + for (int i = 0; i < test_count; ++i) + { + esp_sha_dma(SHA2_256, s_test_buffer+64, 64, s_test_buffer, 64, true); + esp_sha_read_digest_state(SHA2_256, interResult); + esp_sha_dma(SHA2_256, 0, 0, interResult, 64, true); + esp_sha_read_digest_state(SHA2_256, hash); + } + esp_sha_release_hardware(); +#endif + +#if 0 + //ESP32D 5.50KH/s + test_count = 40000; + //esp_sha_lock_engine(SHA2_256); + for (int i = 0; i < test_count; ++i) + { + esp_sha(SHA2_256, s_test_buffer, 80, interResult); + esp_sha(SHA2_256, interResult, 32, hash); + } + //esp_sha_unlock_engine(SHA2_256); +#endif + +#if 0 + //ESP32D + //Invalid result!! + test_count = 100000; + esp_sha_lock_engine(SHA2_256); + for (int i = 0; i < test_count; ++i) + { + esp_sha_block(SHA2_256, s_test_buffer, true); + esp_sha_block(SHA2_256, s_test_buffer+64, false); + esp_sha_read_digest_state(SHA2_256, interResult); + esp_sha_block(SHA2_256, interResult, true); + esp_sha_read_digest_state(SHA2_256, hash); + } + esp_sha_unlock_engine(SHA2_256); +#endif + +#if 0 + //ESP32D Hardware SHA ~200KH/s + test_count = 50000; + periph_module_enable(PERIPH_SHA_MODULE); + uint8_t buffer_swap[128]; + for (int i = 0; i < 32; ++i) + ((uint32_t*)buffer_swap)[i] = __builtin_bswap32(((const uint32_t*)s_test_buffer)[i]); + + uint8_t inter_swap[64]; + for (int i = 0; i < 16; ++i) + ((uint32_t*)inter_swap)[i] = __builtin_bswap32(((const uint32_t*)interResult)[i]); + + for (int i = 0; i < test_count; ++i) + { + //sha_hal_hash_block(SHA2_256, s_test_buffer, 64/4, true); + nerd_sha_hal_wait_idle(); + nerd_sha_ll_fill_text_block_sha256(buffer_swap); + sha_ll_start_block(SHA2_256); + + //sha_hal_hash_block(SHA2_256, s_test_buffer+64, 64/4, false); + nerd_sha_hal_wait_idle(); + nerd_sha_ll_fill_text_block_sha256(buffer_swap+64); + sha_ll_continue_block(SHA2_256); + + nerd_sha_hal_wait_idle(); + sha_ll_load(SHA2_256); + //nerd_sha_ll_read_digest_swap(interResult); + + //sha_hal_hash_block(SHA2_256, interResult, 64/4, true); + nerd_sha_hal_wait_idle(); + nerd_sha_ll_fill_text_block_sha256_double(inter_swap); + sha_ll_start_block(SHA2_256); + + nerd_sha_hal_wait_idle(); + sha_ll_load(SHA2_256); + nerd_sha_ll_read_digest_swap(hash); + } +#endif + +#if 0 + //Hardware low level + midstate 156KH/s + esp_sha_acquire_hardware(); + sha_hal_hash_block(SHA2_256, s_test_buffer, 64/4, true); + sha_hal_read_digest(SHA2_256, midstate); + for (int i = 0; i < test_count; ++i) + { + sha_hal_write_digest(SHA2_256, midstate); + sha_hal_hash_block(SHA2_256, s_test_buffer+64, 64/4, false); + sha_hal_read_digest(SHA2_256, interResult); + sha_hal_hash_block(SHA2_256, interResult, 64/4, true); + sha_hal_read_digest(SHA2_256, hash); + } + esp_sha_release_hardware(); +#endif + +#if 0 + //Hardware low level + midstate + aligned 156KH/s (No sense) + esp_sha_acquire_hardware(); + sha_hal_hash_block(SHA2_256, s_test_buffer_aligned, 64/4, true); + sha_hal_read_digest(SHA2_256, midstate_aligned); + for (int i = 0; i < test_count; ++i) + { + sha_hal_write_digest(SHA2_256, midstate_aligned); + sha_hal_hash_block(SHA2_256, s_test_buffer_aligned+64, 64/4, false); + sha_hal_read_digest(SHA2_256, interResult_aligned); + sha_hal_hash_block(SHA2_256, interResult_aligned, 64/4, true); + sha_hal_read_digest(SHA2_256, hash_aligned); + } + esp_sha_release_hardware(); + memcpy(hash, hash_aligned, sizeof(hash_aligned)); +#endif + +#if 0 + //Hardware LL 162.43KH/s + esp_sha_acquire_hardware(); + //sha_hal_hash_block(SHA2_256, s_test_buffer, 64/4, true); + sha_hal_wait_idle(); + sha_ll_fill_text_block(s_test_buffer, 64/4); + sha_ll_start_block(SHA2_256); + + //sha_hal_read_digest(SHA2_256, midstate); + sha_ll_load(SHA2_256); + sha_hal_wait_idle(); + sha_ll_read_digest(SHA2_256, midstate, 256 / 32); + + for (int i = 0; i < test_count; ++i) + { + //sha_hal_write_digest(SHA2_256, midstate); + sha_ll_write_digest(SHA2_256, midstate, 256 / 32); + //nerd_sha_ll_write_digest_sha256(midstate); + + //sha_hal_hash_block(SHA2_256, s_test_buffer+64, 64/4, false); + //sha_hal_wait_idle(); + nerd_sha_hal_wait_idle(); + //sha_ll_fill_text_block(s_test_buffer+64, 64/4); + nerd_sha_ll_fill_text_block_sha256(s_test_buffer+64); + sha_ll_continue_block(SHA2_256); + + //sha_hal_read_digest(SHA2_256, interResult); + sha_ll_load(SHA2_256); + //sha_hal_wait_idle(); + nerd_sha_hal_wait_idle(); + //sha_ll_read_digest(SHA2_256, interResult, 256 / 32); + nerd_sha_ll_read_digest(interResult); + + //sha_hal_hash_block(SHA2_256, interResult, 64/4, true); + //sha_hal_wait_idle(); + nerd_sha_hal_wait_idle(); + //sha_ll_fill_text_block(interResult, 64/4); + nerd_sha_ll_fill_text_block_sha256(interResult); + sha_ll_start_block(SHA2_256); + + //sha_hal_read_digest(SHA2_256, hash); + sha_ll_load(SHA2_256); + //sha_hal_wait_idle(); + nerd_sha_hal_wait_idle(); + //sha_ll_read_digest(SHA2_256, hash, 256 / 32); + nerd_sha_ll_read_digest(hash); + } + esp_sha_release_hardware(); +#endif + +#if 0 + //DMA hash + uint8_t* dma_cap_buf = (uint8_t*)heap_caps_malloc(128, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); + memcpy(dma_cap_buf, s_test_buffer, 128); + + uint8_t* dma_cap_inter = (uint8_t*)heap_caps_malloc(64, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); + memcpy(dma_cap_inter, interResult, 64); + + uint8_t* dma_cap_hash = (uint8_t*)heap_caps_malloc(32, MALLOC_CAP_8BIT|MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); + + memset(&s_dma_descr_input, 0, sizeof(lldesc_t)); + memset(&s_dma_descr_buf, 0, sizeof(lldesc_t)); + memset(&s_dma_descr_inter, 0, sizeof(lldesc_t)); + + + s_dma_descr_input.length = 64; + s_dma_descr_input.size = 64; + s_dma_descr_input.owner = 1; + s_dma_descr_input.eof = 1; + s_dma_descr_input.buf = dma_cap_buf+64; + + s_dma_descr_buf.length = 64; + s_dma_descr_buf.size = 64; + s_dma_descr_buf.owner = 1; + s_dma_descr_buf.buf = dma_cap_buf; + s_dma_descr_buf.eof = 0; + s_dma_descr_buf.empty = (uint32_t)(&s_dma_descr_input); + + s_dma_descr_inter.length = 64; + s_dma_descr_inter.size = 64; + s_dma_descr_inter.owner = 1; + s_dma_descr_inter.buf = dma_cap_inter; + s_dma_descr_inter.eof = 1; + + //49.83KH/s + esp_sha_acquire_hardware(); + for (int i = 0; i < test_count; ++i) + { + esp_crypto_shared_gdma_start(&s_dma_descr_buf, NULL, GDMA_TRIG_PERIPH_SHA); + sha_hal_hash_dma(SHA2_256, 2, true); + sha_hal_wait_idle(); + esp_sha_read_digest_state(SHA2_256, dma_cap_inter); + + esp_crypto_shared_gdma_start(&s_dma_descr_inter, NULL, GDMA_TRIG_PERIPH_SHA); + sha_hal_hash_dma(SHA2_256, 1, true); + sha_hal_wait_idle(); + esp_sha_read_digest_state(SHA2_256, hash); + } + esp_sha_release_hardware(); +#endif + + uint32_t time_end = micros(); + double hash_rate = ((double)test_count * 1000000) / (double)(time_end - time_start); + Serial.print("Hashrate="); + Serial.print(hash_rate/1000); + Serial.println("KH/s"); + + Serial.print("interResult: "); + for (size_t i = 0; i < 32; i++) + Serial.printf("%02x", interResult[i]); + Serial.println(""); + + Serial.print("hash: "); + for (size_t i = 0; i < 32; i++) + Serial.printf("%02x", hash[i]); + Serial.println(""); + + //should be + //54cd9f1ebc3db9a626688e5bb91d808abbd4079b2cba7f43fa08bfced300ef19 + //6fa464b007f2d577edfa5dfe9dfc3f9209f36d1a6711d314ea68ccdd03000000 +} + +#endif /********* INIT *****/ void setup() @@ -74,13 +625,24 @@ void setup() Serial.setTimeout(0); delay(SECOND_MS/10); +#if defined(ARDUINO_ARCH_ESP32) + if (MINER_CPU_FREQ_MHZ > 0) + { + bool freq_ok = setCpuFrequencyMhz(MINER_CPU_FREQ_MHZ); + Serial.printf("[POWER] CPU frequency set to %d MHz (%s)\n", MINER_CPU_FREQ_MHZ, freq_ok ? "ok" : "failed"); + } +#endif + esp_task_wdt_init(WDT_MINER_TIMEOUT, true); // Idle task that would reset WDT never runs, because core 0 gets fully utilized disableCore0WDT(); //disableCore1WDT(); #ifdef HW_SHA256_TEST - while (1) HwShaTest(); + while (1) + { + HwShaTest(); + } #endif // Setup the buttons @@ -123,32 +685,39 @@ void setup() #endif /******** INIT WIFI ************/ + #if !defined(I2C_HASH_SLAVE) init_WifiManager(); + #else + Serial.println("[I2C-SLAVE] WiFi disabled for hashboard mode."); + mMonitor.NerdStatus = NM_hashing; + #endif /******** CREATE TASK TO PRINT SCREEN *****/ //tft.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); // Higher prio monitor task Serial.println(""); Serial.println("Initiating tasks..."); - static const char monitor_name[] = "(Monitor)"; - #if defined(CONFIG_IDF_TARGET_ESP32) - // Increased stack for ESP32 classic due to NVS operations - BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 9500, (void*)monitor_name, 5, NULL,1); - #else - BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 10000, (void*)monitor_name, 5, NULL,1); + + initMiningQueues(); + + #if !defined(I2C_HASH_SLAVE) + BaseType_t res1 = xTaskCreatePinnedToCore(runMonitor, "Monitor", 10000, (void*)"(Monitor)", MONITOR_TASK_PRIORITY, NULL, 0); + (void)res1; #endif /******** CREATE STRATUM TASK *****/ - static const char stratum_name[] = "(Stratum)"; - #if defined(CONFIG_IDF_TARGET_ESP32) && !defined(ESP32_2432S028R) && !defined(ESP32_2432S028_2USB) - // Reduced stack for ESP32 classic to save memory - BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 12000, (void*)stratum_name, 4, NULL,1); - #elif defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB) + #if !defined(I2C_HASH_SLAVE) + #if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB) // Free a little bit of the heap to the screen - BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 13500, (void*)stratum_name, 4, NULL,1); - #else - BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)stratum_name, 4, NULL,1); - #endif + BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 13500, (void*)"(Stratum)", 4, NULL, 0); + #else + BaseType_t res2 = xTaskCreatePinnedToCore(runStratumWorker, "Stratum", 15000, (void*)"(Stratum)", 4, NULL, 0); + #endif + (void)res2; + #else + BaseType_t res2 = xTaskCreatePinnedToCore(runI2cSlaveWorker, "I2C-Slave", 12000, (void*)"(I2C-Slave)", I2C_SLAVE_TASK_PRIORITY, NULL, 0); + (void)res2; + #endif /******** CREATE MINER TASKS *****/ //for (size_t i = 0; i < THREADS; i++) { @@ -159,34 +728,35 @@ void setup() //BaseType_t res = xTaskCreate(runWorker, name, 35000, (void*)name, 1, NULL); TaskHandle_t minerTask1, minerTask2 = NULL; #ifdef HARDWARE_SHA265 - #if defined(CONFIG_IDF_TARGET_ESP32) - xTaskCreate(minerWorkerHw, "MinerHw-0", 3584, (void*)0, 3, &minerTask1); // Reduced for ESP32 classic - //xTaskCreate(minerWorkerSw, "MinerSw-0", 5000, (void*)0, 1, &minerTask1); // Reduced for ESP32 classic - #else - xTaskCreate(minerWorkerHw, "MinerHw-0", 4096, (void*)0, 3, &minerTask1); - #endif + // Keep HW miner on core 1. + xTaskCreatePinnedToCore(minerWorkerHw, "MinerHw-0", 4096, (void*)0, 4, &minerTask1, 1); #else - #if defined(CONFIG_IDF_TARGET_ESP32) - xTaskCreate(minerWorkerSw, "MinerSw-0", 5000, (void*)0, 1, &minerTask1); // Reduced for ESP32 classic + #if defined(I2C_HASH_SLAVE) + xTaskCreatePinnedToCore(minerWorkerSw, "MinerSw-0", 6000, (void*)0, I2C_SLAVE_SW_TASK_PRIORITY, &minerTask1, 1); #else - xTaskCreate(minerWorkerSw, "MinerSw-0", 6000, (void*)0, 1, &minerTask1); + xTaskCreatePinnedToCore(minerWorkerSw, "MinerSw-0", 6000, (void*)0, 3, &minerTask1, 1); #endif #endif esp_task_wdt_add(minerTask1); #if (SOC_CPU_CORES_NUM >= 2) - #if defined(CONFIG_IDF_TARGET_ESP32) - xTaskCreate(minerWorkerSw, "MinerSw-1", 5000, (void*)1, 1, &minerTask2); // Reduced for ESP32 classic + #if defined(I2C_HASH_SLAVE) + constexpr BaseType_t swCore = I2C_SLAVE_SW_CORE; + constexpr UBaseType_t swPrio = I2C_SLAVE_SW_TASK_PRIORITY; #else - xTaskCreate(minerWorkerSw, "MinerSw-1", 6000, (void*)1, 1, &minerTask2); + constexpr BaseType_t swCore = 1; + constexpr UBaseType_t swPrio = 3; #endif + xTaskCreatePinnedToCore(minerWorkerSw, "MinerSw-1", 6000, (void*)1, swPrio, &minerTask2, swCore); esp_task_wdt_add(minerTask2); #endif vTaskPrioritySet(NULL, 4); /******** MONITOR SETUP *****/ + #if !defined(I2C_HASH_SLAVE) setup_monitor(); + #endif } void app_error_fault_handler(void *arg) { @@ -213,7 +783,9 @@ void loop() { #ifdef TOUCH_ENABLE touchHandler.isTouched(); #endif + #if !defined(I2C_HASH_SLAVE) wifiManagerProcess(); // avoid delays() in loop when non-blocking and other long running code + #endif vTaskDelay(50 / portTICK_PERIOD_MS); } diff --git a/src/ShaTests/nerdSHA256plus.cpp b/src/ShaTests/nerdSHA256plus.cpp index 4260fdbf..a7935efb 100644 --- a/src/ShaTests/nerdSHA256plus.cpp +++ b/src/ShaTests/nerdSHA256plus.cpp @@ -24,7 +24,7 @@ #include #include -//#pragma GCC optimize ("Ofast") +#pragma GCC optimize ("Ofast") //#pragma GCC optimize ("jump-tables") //#pragma GCC optimize ("tree-switch-conversion") //#pragma GCC optimize ("no-stack-check") @@ -486,13 +486,13 @@ IRAM_ATTR void nerd_sha256_bake(const uint32_t* digest, const uint8_t* dataIn, u } -IRAM_ATTR bool nerd_sha256d_baked(const uint32_t* digest, const uint8_t* dataIn, const uint32_t* bake, uint8_t* doubleHash) +static IRAM_ATTR bool nerd_sha256d_baked_core(const uint32_t* digest, uint32_t nonce_be, const uint32_t* bake, uint8_t* doubleHash) { uint32_t temp1, temp2; //*********** Init 1rst SHA *********** //W0 W1 W2 is same !! - uint32_t W[64] = { bake[0], bake[1], bake[2], GET_UINT32_BE(dataIn, 12), + uint32_t W[64] = { bake[0], bake[1], bake[2], nonce_be, 0x80000000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 640 }; W[16] = bake[3]; @@ -742,3 +742,13 @@ IRAM_ATTR bool nerd_sha256d_baked(const uint32_t* digest, const uint8_t* dataIn, #endif return true; } + +IRAM_ATTR bool nerd_sha256d_baked_nonce(const uint32_t* digest, uint32_t nonce, const uint32_t* bake, uint8_t* doubleHash) +{ + return nerd_sha256d_baked_core(digest, __builtin_bswap32(nonce), bake, doubleHash); +} + +IRAM_ATTR bool nerd_sha256d_baked(const uint32_t* digest, const uint8_t* dataIn, const uint32_t* bake, uint8_t* doubleHash) +{ + return nerd_sha256d_baked_core(digest, GET_UINT32_BE(dataIn, 12), bake, doubleHash); +} diff --git a/src/ShaTests/nerdSHA256plus.h b/src/ShaTests/nerdSHA256plus.h index 3d7872ef..fc1db33b 100644 --- a/src/ShaTests/nerdSHA256plus.h +++ b/src/ShaTests/nerdSHA256plus.h @@ -31,7 +31,8 @@ IRAM_ATTR bool nerd_sha256d(nerdSHA256_context* midstate, const uint8_t* dataIn, IRAM_ATTR void nerd_sha256_bake(const uint32_t* digest, const uint8_t* dataIn, uint32_t* bake); //15 words IRAM_ATTR bool nerd_sha256d_baked(const uint32_t* digest, const uint8_t* dataIn, const uint32_t* bake, uint8_t* doubleHash); +IRAM_ATTR bool nerd_sha256d_baked_nonce(const uint32_t* digest, uint32_t nonce, const uint32_t* bake, uint8_t* doubleHash); void ByteReverseWords(uint32_t* out, const uint32_t* in, uint32_t byteCount); -#endif /* nerdSHA256plus_H_ */ \ No newline at end of file +#endif /* nerdSHA256plus_H_ */ diff --git a/src/drivers/devices/device.h b/src/drivers/devices/device.h index 49ec045f..645f0a25 100644 --- a/src/drivers/devices/device.h +++ b/src/drivers/devices/device.h @@ -51,8 +51,7 @@ #include "waveshareS3Geek.h" #elif defined(NERDMINER_T_HMI) #include "lilygoT_HMI.h" -#elif defined(SPOTPEAR) -#include "spotpearKeychain.h" + #else #error "No device defined" diff --git a/src/drivers/displays/display.cpp b/src/drivers/displays/display.cpp index 5c559b83..6aaf610a 100644 --- a/src/drivers/displays/display.cpp +++ b/src/drivers/displays/display.cpp @@ -1,4 +1,5 @@ #include "display.h" +#include #ifdef NO_DISPLAY DisplayDriver *currentDisplayDriver = &noDisplayDriver; @@ -60,10 +61,6 @@ DisplayDriver *currentDisplayDriver = &m5stickCPlusDriver; DisplayDriver *currentDisplayDriver = &t_hmiDisplayDriver; #endif -#ifdef ST7735S_DISPLAY -DisplayDriver *currentDisplayDriver = &sp_kcDisplayDriver; -#endif - // Initialize the display void initDisplay() @@ -119,6 +116,19 @@ void animateCurrentScreen(unsigned long frame) currentDisplayDriver->animateCurrentScreen(frame); } +bool isDisplayActive() +{ +#if defined(TFT_BL) +#if defined(TFT_BACKLIGHT_ON) + return digitalRead(TFT_BL) == TFT_BACKLIGHT_ON; +#else + return digitalRead(TFT_BL) != LOW; +#endif +#else + return true; +#endif +} + // Do LED stuff void doLedStuff(unsigned long frame) { diff --git a/src/drivers/displays/display.h b/src/drivers/displays/display.h index f1d321ba..1e9ebfee 100644 --- a/src/drivers/displays/display.h +++ b/src/drivers/displays/display.h @@ -14,6 +14,7 @@ void drawLoadingScreen(); void drawSetupScreen(); void drawCurrentScreen(unsigned long mElapsed); void animateCurrentScreen(unsigned long frame); +bool isDisplayActive(); void doLedStuff(unsigned long frame); #endif // DISPLAY_H diff --git a/src/drivers/displays/displayDriver.h b/src/drivers/displays/displayDriver.h index 9594ea19..2ca83121 100644 --- a/src/drivers/displays/displayDriver.h +++ b/src/drivers/displays/displayDriver.h @@ -42,7 +42,6 @@ extern DisplayDriver tDisplayV1Driver; extern DisplayDriver m5stickCDriver; extern DisplayDriver m5stickCPlusDriver; extern DisplayDriver t_hmiDisplayDriver; -extern DisplayDriver sp_kcDisplayDriver; #define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/src/drivers/displays/esp23_2432s028r.cpp b/src/drivers/displays/esp23_2432s028r.cpp index 45370cf3..98fe9860 100644 --- a/src/drivers/displays/esp23_2432s028r.cpp +++ b/src/drivers/displays/esp23_2432s028r.cpp @@ -473,7 +473,7 @@ void esp32_2432S028R_BTCprice(unsigned long mElapsed) // Delete sprite to free the memory heap background.deleteSprite(); - createBackgroundSprite(180,105); + createBackgroundSprite(169,105); // Print background screen background.pushImage(-130, -3, priceScreenWidth, priceScreenHeight, priceScreen); diff --git a/src/drivers/displays/noDisplayDriver.cpp b/src/drivers/displays/noDisplayDriver.cpp index f4ef86c2..bae3f38d 100644 --- a/src/drivers/displays/noDisplayDriver.cpp +++ b/src/drivers/displays/noDisplayDriver.cpp @@ -7,7 +7,7 @@ #include "wManager.h" extern monitor_data mMonitor; -bool ledOn = true; +bool ledOn = false; void noDisplay_Init(void) { @@ -27,7 +27,42 @@ void noDisplay_AlternateRotation(void) void noDisplay_NoScreen(unsigned long mElapsed) { - mining_data data = getMiningData(mElapsed); + static unsigned long lastPrint = 0; + static unsigned long elapsedAccum = 0; + static String lastShares; + static String lastKHashes; + static String lastHashrate; + static String lastTemplates; + static String lastBestDiff; + static String lastStales; + elapsedAccum += mElapsed; + + const unsigned long now = millis(); + if (now - lastPrint < 5000) + return; + lastPrint = now; + + mining_data data = getMiningData(elapsedAccum); + elapsedAccum = 0; + + bool changed = false; + if (data.completedShares != lastShares) changed = true; + if (data.totalKHashes != lastKHashes) changed = true; + if (data.currentHashRate != lastHashrate) changed = true; + if (data.templates != lastTemplates) changed = true; + if (data.bestDiff != lastBestDiff) changed = true; + if (data.stales != lastStales) changed = true; + + // Always print at least every 60s, otherwise only on changes. + if (!changed && (now - lastPrint < 60000)) + return; + + lastShares = data.completedShares; + lastKHashes = data.totalKHashes; + lastHashrate = data.currentHashRate; + lastTemplates = data.templates; + lastBestDiff = data.bestDiff; + lastStales = data.stales; // Print hashrate to serial Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", @@ -38,6 +73,7 @@ void noDisplay_NoScreen(unsigned long mElapsed) Serial.printf(">>> Block templates: %s\n", data.templates.c_str()); Serial.printf(">>> Best difficulty: %s\n", data.bestDiff.c_str()); Serial.printf(">>> 32Bit shares: %s\n", data.completedShares.c_str()); + Serial.printf(">>> Stales: %s\n", data.stales.c_str()); Serial.printf(">>> Temperature: %s\n", data.temp.c_str()); Serial.printf(">>> Total MHashes: %s\n", data.totalMHashes.c_str()); Serial.printf(">>> Time mining: %s\n", data.timeMining.c_str()); diff --git a/src/drivers/displays/tDisplayDriver.cpp b/src/drivers/displays/tDisplayDriver.cpp index 3bab4a28..e3a04647 100644 --- a/src/drivers/displays/tDisplayDriver.cpp +++ b/src/drivers/displays/tDisplayDriver.cpp @@ -50,7 +50,6 @@ void tDisplay_Init(void) void tDisplay_AlternateScreenState(void) { int screen_state = digitalRead(TFT_BL); - Serial.println("Switching display state"); digitalWrite(TFT_BL, !screen_state); } @@ -66,9 +65,6 @@ void tDisplay_MinerScreen(unsigned long mElapsed) // Print background screen background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - // Hashrate render.setFontSize(35); render.setCursor(19, 118); @@ -116,9 +112,6 @@ void tDisplay_ClockScreen(unsigned long mElapsed) // Print background screen background.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen); - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - // Hashrate render.setFontSize(25); render.setCursor(19, 122); @@ -154,9 +147,6 @@ void tDisplay_GlobalHashScreen(unsigned long mElapsed) // Print background screen background.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen); - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - // Print BTC Price background.setFreeFont(FSSB9); background.setTextSize(1); @@ -217,9 +207,6 @@ void tDisplay_BTCprice(unsigned long mElapsed) // Print background screen background.pushImage(0, 0, priceScreenWidth, priceScreenHeight, priceScreen); - Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", - data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); - // Hashrate render.setFontSize(25); render.setCursor(19, 122); diff --git a/src/drivers/displays/tDisplayV1Driver.cpp b/src/drivers/displays/tDisplayV1Driver.cpp index ccb0bd83..c13c43bd 100644 --- a/src/drivers/displays/tDisplayV1Driver.cpp +++ b/src/drivers/displays/tDisplayV1Driver.cpp @@ -206,7 +206,7 @@ void tDisplay_BTCprice(unsigned long mElapsed) // Hashrate render.setFontSize(25); - render.setCursor(19, 120); + render.setCursor(19, 122); render.setFontColor(TFT_BLACK); render.rdrawString(data.currentHashRate.c_str(), 70, 103, TFT_BLACK); @@ -222,11 +222,11 @@ void tDisplay_BTCprice(unsigned long mElapsed) background.drawString(data.currentTime.c_str(), 148, 1, GFXFF); // Print BTC Price - background.setFreeFont(FF23); - background.setTextDatum(TL_DATUM); + background.setFreeFont(FF24); + background.setTextDatum(TR_DATUM); background.setTextSize(1); background.setTextColor(0xDEDB, TFT_BLACK); - background.drawString(data.btcPrice.c_str(), 82, 50, GFXFF); + background.drawString(data.btcPrice.c_str(), 70, 25, GFXFF); // Push prepared background to screen background.pushSprite(0, 0); @@ -253,7 +253,7 @@ void tDisplay_DoLedStuff(unsigned long frame) { } -CyclicScreenFunction tDisplayCyclicScreens[] = {tDisplay_MinerScreen, tDisplay_ClockScreen, tDisplay_GlobalHashScreen, tDisplay_BTCprice}; +CyclicScreenFunction tDisplayCyclicScreens[] = {tDisplay_MinerScreen, tDisplay_ClockScreen, tDisplay_GlobalHashScreen}; DisplayDriver tDisplayV1Driver = { tDisplay_Init, diff --git a/src/drivers/displays/wt32DisplayDriver.cpp b/src/drivers/displays/wt32DisplayDriver.cpp index 81558f5e..ed6b3790 100644 --- a/src/drivers/displays/wt32DisplayDriver.cpp +++ b/src/drivers/displays/wt32DisplayDriver.cpp @@ -295,8 +295,6 @@ void wt32Display_AlternateRotation(void) { } -static unsigned long ulTime = millis() - 100000; - void wt32Display_NoScreen(unsigned long mElapsed) { mining_data data = getMiningData(mElapsed); @@ -307,7 +305,7 @@ void wt32Display_NoScreen(unsigned long mElapsed) //Serial.printf(">>> Temperature: %s\n", data.temp.c_str()); lv_label_set_text(ui_lblhashrate, data.currentHashRate.c_str()); - lv_bar_set_value(ui_barhashrate, data.currentHashRate.toInt(), LV_ANIM_ON); + lv_bar_set_value(ui_barhashrate, data.currentHashRate.toInt() * 10, LV_ANIM_ON); lv_label_set_text(ui_lblvalid, data.valids.c_str()); lv_label_set_text(ui_lbltemplates, data.templates.c_str()); lv_label_set_text(ui_lbltotalhashrate, data.totalKHashes.c_str()); @@ -315,43 +313,21 @@ void wt32Display_NoScreen(unsigned long mElapsed) lv_label_set_text(ui_lblshares32, data.completedShares.c_str()); lv_label_set_text(ui_lblclock, data.timeMining.c_str()); lv_label_set_text(ui_lbltemperature, data.temp.c_str()); - lv_label_set_text(ui_lblclock2, data.currentTime.c_str()); - lv_label_set_text(ui_lblIp, WiFi.localIP().toString().c_str()); - lv_label_set_text(ui_lblAddress, String(Settings.BtcWallet).c_str()); - - if(millis() - ulTime > 1000 * 60) { - ulTime = millis(); - - coin_data cdata = getCoinData(mElapsed); - - lv_label_set_text(ui_lblPrice, cdata.btcPrice.c_str()); - lv_label_set_text(ui_lblGlobalHashrate, cdata.globalHashRate.c_str()); - lv_label_set_text(ui_lblDifficulty, cdata.netwrokDifficulty.c_str()); - lv_bar_set_value(ui_barhalving, cdata.progressPercent, LV_ANIM_ON); - lv_label_set_text(ui_lblHeight2, cdata.blockHeight.c_str()); - - pool_data pdata = getPoolData(); - - lv_label_set_text(ui_lblWorkers, String(pdata.workersCount).c_str()); - lv_label_set_text(ui_lblMaxDifficulty, pdata.bestDifficulty.c_str()); - lv_label_set_text(ui_lblTotHashrate, pdata.workersHash.c_str()); - } + /* + M5.Lcd.print("Pool: "); M5.Lcd.setTextColor(GREENYELLOW); M5.Lcd.print(Settings.PoolAddress); M5.Lcd.print(":"); M5.Lcd.println(Settings.PoolPort); M5.Lcd.setTextColor(WHITE); + M5.Lcd.print("IP : "); M5.Lcd.setTextColor(GREENYELLOW); M5.Lcd.println(WiFi.localIP()); M5.Lcd.setTextColor(WHITE); + */ } - void wt32Display_LoadingScreen(void) { Serial.println("Initializing..."); Serial.print("Firmware Version: "); Serial.println(AUTO_VERSION); - lv_label_set_text(ui_lblssid, "HanSoloAP"); - lv_label_set_text(ui_lblpassword, "MineYourCoins"); + lv_label_set_text(ui_lblssid, "SSID HanSoloAP"); + lv_label_set_text(ui_lblpassword, "Password MineYourCoins"); lv_label_set_text(ui_lblversion, AUTO_VERSION); - lv_label_set_text(ui_lblversion2, AUTO_VERSION); - - lv_label_set_text(ui_lblPool, (String(Settings.PoolAddress)+":"+String(Settings.PoolPort)).c_str()); - _ui_screen_change(&ui_HomeScreen, LV_SCR_LOAD_ANIM_FADE_ON, 2000, 0, &ui_HomeScreen_screen_init); } @@ -386,12 +362,4 @@ DisplayDriver wt32DisplayDriver = { 0, 0, }; - -// LVGL Events -#include "wManager.h" - -void reset_configuration_event(lv_event_t * e){ - reset_configuration(); -} - #endif diff --git a/src/drivers/storage/SDCard.cpp b/src/drivers/storage/SDCard.cpp index c8c579d3..e92eaf5a 100644 --- a/src/drivers/storage/SDCard.cpp +++ b/src/drivers/storage/SDCard.cpp @@ -1,12 +1,26 @@ #include #include #include +#include #include "storage.h" #include "nvMemory.h" #include "../devices/device.h" #include "SDCard.h" +static void copyCString(char *dst, size_t dstSize, const char *src) +{ + if (dst == nullptr || dstSize == 0) + return; + if (src == nullptr) + { + dst[0] = '\0'; + return; + } + strncpy(dst, src, dstSize - 1); + dst[dstSize - 1] = '\0'; +} + #if defined (BUILD_SDMMC_1) || defined(BUILD_SDMMC_4) #include #elif defined (BUILD_SDSPI) @@ -115,8 +129,8 @@ bool SDCard::loadConfigFile(TSettings* Settings) Settings->WifiPW = json[JSON_KEY_PASW] | Settings->WifiPW; } Settings->PoolAddress = json[JSON_KEY_POOLURL] | Settings->PoolAddress; - strcpy(Settings->PoolPassword, json[JSON_KEY_POOLPASS] | Settings->PoolPassword); - strcpy(Settings->BtcWallet, json[JSON_KEY_WALLETID] | Settings->BtcWallet); + copyCString(Settings->PoolPassword, sizeof(Settings->PoolPassword), json[JSON_KEY_POOLPASS] | Settings->PoolPassword); + copyCString(Settings->BtcWallet, sizeof(Settings->BtcWallet), json[JSON_KEY_WALLETID] | Settings->BtcWallet); if (json.containsKey(JSON_KEY_POOLPORT)) Settings->PoolPort = json[JSON_KEY_POOLPORT].as(); if (json.containsKey(JSON_KEY_TIMEZONE)) diff --git a/src/drivers/storage/nvMemory.cpp b/src/drivers/storage/nvMemory.cpp index f71ee225..1d760b32 100644 --- a/src/drivers/storage/nvMemory.cpp +++ b/src/drivers/storage/nvMemory.cpp @@ -5,10 +5,24 @@ #include #include #include +#include #include "../devices/device.h" #include "storage.h" +static void copyCString(char *dst, size_t dstSize, const char *src) +{ + if (dst == nullptr || dstSize == 0) + return; + if (src == nullptr) + { + dst[0] = '\0'; + return; + } + strncpy(dst, src, dstSize - 1); + dst[dstSize - 1] = '\0'; +} + nvMemory::nvMemory() : Initialized_(false){}; nvMemory::~nvMemory() @@ -91,8 +105,8 @@ bool nvMemory::loadConfig(TSettings* Settings) if (!error) { Settings->PoolAddress = json[JSON_SPIFFS_KEY_POOLURL] | Settings->PoolAddress; - strcpy(Settings->PoolPassword, json[JSON_SPIFFS_KEY_POOLPASS] | Settings->PoolPassword); - strcpy(Settings->BtcWallet, json[JSON_SPIFFS_KEY_WALLETID] | Settings->BtcWallet); + copyCString(Settings->PoolPassword, sizeof(Settings->PoolPassword), json[JSON_SPIFFS_KEY_POOLPASS] | Settings->PoolPassword); + copyCString(Settings->BtcWallet, sizeof(Settings->BtcWallet), json[JSON_SPIFFS_KEY_WALLETID] | Settings->BtcWallet); if (json.containsKey(JSON_SPIFFS_KEY_POOLPORT)) Settings->PoolPort = json[JSON_SPIFFS_KEY_POOLPORT].as(); if (json.containsKey(JSON_SPIFFS_KEY_TIMEZONE)) @@ -166,4 +180,4 @@ bool nvMemory::deleteConfig() { return false; } bool nvMemory::init() { return false; } -#endif //NVMEM_TYPE \ No newline at end of file +#endif //NVMEM_TYPE diff --git a/src/drivers/storage/storage.h b/src/drivers/storage/storage.h index 4a0fa6ce..844e97c8 100644 --- a/src/drivers/storage/storage.h +++ b/src/drivers/storage/storage.h @@ -13,10 +13,13 @@ #endif #define DEFAULT_WIFIPW "MineYourCoins" #define DEFAULT_POOLURL "public-pool.io" +// #define DEFAULT_POOLURL "sha256.na.mine.zpool.ca" #define DEFAULT_POOLPASS "x" +// #define DEFAULT_POOLPASS "2,c=LTC" +// #define DEFAULT_POOLPASS "1,c=DGB" #define DEFAULT_WALLETID "yourBtcAddress" -#define DEFAULT_POOLPORT 21496 -#define DEFAULT_TIMEZONE 2 +#define DEFAULT_POOLPORT 3333 +#define DEFAULT_TIMEZONE -3 #define DEFAULT_SAVESTATS false #define DEFAULT_INVERTCOLORS false #define DEFAULT_BRIGHTNESS 250 diff --git a/src/i2c_hash_config.h b/src/i2c_hash_config.h new file mode 100644 index 00000000..1b5d0ab2 --- /dev/null +++ b/src/i2c_hash_config.h @@ -0,0 +1,74 @@ +#pragma once + +// Centralized I2C hash-cluster configuration. +// +// How to use (code-only, without platformio.ini): +// - Set NM_I2C_HASH_ROLE to one of the values below and rebuild. +// - For slaves, also set NM_I2C_HASH_SLAVE_ADDRESS (each slave must have a unique address on the bus). +// +// Build-flag precedence: +// - If platformio.ini already defines I2C_HASH_MASTER/I2C_HASH_SLAVE (or pins/clock/address), those take precedence +// over the NM_* values here. + +#define NM_I2C_HASH_ROLE_OFF 0 +#define NM_I2C_HASH_ROLE_MASTER 1 +#define NM_I2C_HASH_ROLE_SLAVE 2 + +#ifndef NM_I2C_HASH_ROLE +// Default: normal (non-cluster) build. +#define NM_I2C_HASH_ROLE NM_I2C_HASH_ROLE_OFF +#endif + +// Backwards compatibility: historical I2C_SLAVE define meant "I2C master feeding slaves". +#if defined(I2C_SLAVE) && !defined(I2C_HASH_MASTER) +#define I2C_HASH_MASTER 1 +#endif + +// If the role wasn't set by build flags, allow enabling it here. +#if !defined(I2C_HASH_MASTER) && !defined(I2C_HASH_SLAVE) +#if (NM_I2C_HASH_ROLE == NM_I2C_HASH_ROLE_MASTER) +#define I2C_HASH_MASTER 1 +#elif (NM_I2C_HASH_ROLE == NM_I2C_HASH_ROLE_SLAVE) +#define I2C_HASH_SLAVE 1 +#endif +#endif + +#if defined(I2C_HASH_MASTER) && defined(I2C_HASH_SLAVE) +#error "Define only one: I2C_HASH_MASTER or I2C_HASH_SLAVE" +#endif + +// Default I2C bus parameters (override per-board if needed). +#ifndef NM_I2C_HASH_BUS_PORT +#define NM_I2C_HASH_BUS_PORT 0 +#endif +#ifndef NM_I2C_HASH_SDA_PIN +#define NM_I2C_HASH_SDA_PIN 21 +#endif +#ifndef NM_I2C_HASH_SCL_PIN +#define NM_I2C_HASH_SCL_PIN 22 +#endif +#ifndef NM_I2C_HASH_CLOCK_HZ +// 100kHz is the most tolerant setting across boards/wiring. You can bump to 400000 if stable. +#define NM_I2C_HASH_CLOCK_HZ 100000 +#endif +#ifndef NM_I2C_HASH_SLAVE_ADDRESS +#define NM_I2C_HASH_SLAVE_ADDRESS 0x24 +#endif + +// Map NM_* defaults into the existing macros used by the code, but only if build_flags didn't already set them. +#ifndef I2C_HASH_BUS_PORT +#define I2C_HASH_BUS_PORT NM_I2C_HASH_BUS_PORT +#endif +#ifndef I2C_HASH_SDA_PIN +#define I2C_HASH_SDA_PIN NM_I2C_HASH_SDA_PIN +#endif +#ifndef I2C_HASH_SCL_PIN +#define I2C_HASH_SCL_PIN NM_I2C_HASH_SCL_PIN +#endif +#ifndef I2C_HASH_CLOCK_HZ +#define I2C_HASH_CLOCK_HZ NM_I2C_HASH_CLOCK_HZ +#endif +#ifndef I2C_HASH_SLAVE_ADDRESS +#define I2C_HASH_SLAVE_ADDRESS NM_I2C_HASH_SLAVE_ADDRESS +#endif + diff --git a/src/i2c_master.cpp b/src/i2c_master.cpp index 08a95d18..192d51c8 100644 --- a/src/i2c_master.cpp +++ b/src/i2c_master.cpp @@ -1,184 +1,284 @@ -#include "i2c_master.h" -#include -#include - -#define I2C_MASTER_NUM_PORT 0 -#define PIN_I2C_SDA 21 -#define PIN_I2C_SCL 22 -#define I2C_MASTER_TX_BUF_LEN 1024 -#define I2C_MASTER_RX_BUF_LEN 1024 - -static i2c_config_t s_i2c_config; - -#define I2C_CMD_FEED 0xA1 -#define I2C_CMD_REQUEST_RESULT 0xA9 -#define I2C_CMD_SLAVE_RESULT 0xAA - -struct __attribute__((__packed__)) JobI2cRequest -{ - //84 bytes - uint8_t cmd; - uint8_t crc; - uint8_t id; - uint8_t nonce_start; - float difficulty; - uint8_t buffer[76]; -}; - -struct __attribute__((__packed__)) JobI2cResult -{ - //11 bytes - uint8_t cmd; - uint8_t crc; - uint8_t id; - uint32_t nonce; - uint32_t processed_nonce; -}; - -const uint8_t s_crc8_table[256] = -{ - 0x00, 0x31, 0x62, 0x53, 0xC4, 0xF5, 0xA6, 0x97, - 0xB9, 0x88, 0xDB, 0xEA, 0x7D, 0x4C, 0x1F, 0x2E, - 0x43, 0x72, 0x21, 0x10, 0x87, 0xB6, 0xE5, 0xD4, - 0xFA, 0xCB, 0x98, 0xA9, 0x3E, 0x0F, 0x5C, 0x6D, - 0x86, 0xB7, 0xE4, 0xD5, 0x42, 0x73, 0x20, 0x11, - 0x3F, 0x0E, 0x5D, 0x6C, 0xFB, 0xCA, 0x99, 0xA8, - 0xC5, 0xF4, 0xA7, 0x96, 0x01, 0x30, 0x63, 0x52, - 0x7C, 0x4D, 0x1E, 0x2F, 0xB8, 0x89, 0xDA, 0xEB, - 0x3D, 0x0C, 0x5F, 0x6E, 0xF9, 0xC8, 0x9B, 0xAA, - 0x84, 0xB5, 0xE6, 0xD7, 0x40, 0x71, 0x22, 0x13, - 0x7E, 0x4F, 0x1C, 0x2D, 0xBA, 0x8B, 0xD8, 0xE9, - 0xC7, 0xF6, 0xA5, 0x94, 0x03, 0x32, 0x61, 0x50, - 0xBB, 0x8A, 0xD9, 0xE8, 0x7F, 0x4E, 0x1D, 0x2C, - 0x02, 0x33, 0x60, 0x51, 0xC6, 0xF7, 0xA4, 0x95, - 0xF8, 0xC9, 0x9A, 0xAB, 0x3C, 0x0D, 0x5E, 0x6F, - 0x41, 0x70, 0x23, 0x12, 0x85, 0xB4, 0xE7, 0xD6, - 0x7A, 0x4B, 0x18, 0x29, 0xBE, 0x8F, 0xDC, 0xED, - 0xC3, 0xF2, 0xA1, 0x90, 0x07, 0x36, 0x65, 0x54, - 0x39, 0x08, 0x5B, 0x6A, 0xFD, 0xCC, 0x9F, 0xAE, - 0x80, 0xB1, 0xE2, 0xD3, 0x44, 0x75, 0x26, 0x17, - 0xFC, 0xCD, 0x9E, 0xAF, 0x38, 0x09, 0x5A, 0x6B, - 0x45, 0x74, 0x27, 0x16, 0x81, 0xB0, 0xE3, 0xD2, - 0xBF, 0x8E, 0xDD, 0xEC, 0x7B, 0x4A, 0x19, 0x28, - 0x06, 0x37, 0x64, 0x55, 0xC2, 0xF3, 0xA0, 0x91, - 0x47, 0x76, 0x25, 0x14, 0x83, 0xB2, 0xE1, 0xD0, - 0xFE, 0xCF, 0x9C, 0xAD, 0x3A, 0x0B, 0x58, 0x69, - 0x04, 0x35, 0x66, 0x57, 0xC0, 0xF1, 0xA2, 0x93, - 0xBD, 0x8C, 0xDF, 0xEE, 0x79, 0x48, 0x1B, 0x2A, - 0xC1, 0xF0, 0xA3, 0x92, 0x05, 0x34, 0x67, 0x56, - 0x78, 0x49, 0x1A, 0x2B, 0xBC, 0x8D, 0xDE, 0xEF, - 0x82, 0xB3, 0xE0, 0xD1, 0x46, 0x77, 0x24, 0x15, - 0x3B, 0x0A, 0x59, 0x68, 0xFF, 0xCE, 0x9D, 0xAC -}; - -static uint8_t CommandCrc8(const void* data, size_t len) -{ - const uint8_t* ptr = (const uint8_t*)data; - uint8_t crc = 0xFF; - crc = s_crc8_table[crc ^ ptr[0]]; - for (size_t n = 2; n < len; ++n) - crc = s_crc8_table[crc ^ ptr[n]]; - return crc; -} - -int i2c_master_start() -{ - memset(&s_i2c_config, 0, sizeof(s_i2c_config)); - s_i2c_config.mode = I2C_MODE_MASTER; - s_i2c_config.sda_io_num = PIN_I2C_SDA; - s_i2c_config.scl_io_num = PIN_I2C_SCL; - s_i2c_config.sda_pullup_en = GPIO_PULLUP_ENABLE; - s_i2c_config.scl_pullup_en = GPIO_PULLUP_ENABLE; - s_i2c_config.master.clk_speed = 50000; - - esp_err_t err = i2c_param_config(I2C_MASTER_NUM_PORT, &s_i2c_config); - if (err != ESP_OK) - return err; - - return i2c_driver_install(I2C_MASTER_NUM_PORT, s_i2c_config.mode, I2C_MASTER_TX_BUF_LEN, I2C_MASTER_RX_BUF_LEN, 0); -} - -std::vector i2c_master_scan(uint8_t start, uint8_t end) -{ - std::vector vec; +#include "i2c_master.h" +#include "i2c_hash_config.h" +#include +#include +#include "i2c_protocol.h" + +#ifndef I2C_HASH_BUS_PORT +#define I2C_HASH_BUS_PORT 0 +#endif +#ifndef I2C_HASH_SDA_PIN +#define I2C_HASH_SDA_PIN 21 +#endif +#ifndef I2C_HASH_SCL_PIN +#define I2C_HASH_SCL_PIN 22 +#endif +#ifndef I2C_HASH_CLOCK_HZ +#define I2C_HASH_CLOCK_HZ 100000 +#endif +#ifndef I2C_MASTER_DIAG_IMMEDIATE_LOG +#define I2C_MASTER_DIAG_IMMEDIATE_LOG 0 +#endif +#define I2C_MASTER_TX_BUF_LEN 0 +#define I2C_MASTER_RX_BUF_LEN 0 + +static i2c_config_t s_i2c_config; +static I2cMasterDiagSnapshot s_i2c_diag = {}; + +static inline void i2c_diag_mark_err(esp_err_t err, uint8_t addr) +{ + s_i2c_diag.last_err = (int32_t)err; + s_i2c_diag.last_err_addr = addr; + s_i2c_diag.last_err_ms = millis(); +} + +void i2c_master_diag_reset() +{ + memset(&s_i2c_diag, 0, sizeof(s_i2c_diag)); +} + +void i2c_master_diag_snapshot(I2cMasterDiagSnapshot &snapshot) +{ + snapshot = s_i2c_diag; +} + +static bool i2c_probe_hash_slave(uint8_t addr) +{ + uint8_t request[2] = {I2C_CMD_REQUEST_RESULT, 0}; + request[1] = i2cCommandCrc8(request, sizeof(request)); + + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (addr << 1) | I2C_MASTER_WRITE, true); + i2c_master_write(cmd, request, sizeof(request), true); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_HASH_BUS_PORT, cmd, 20 / portTICK_PERIOD_MS); + i2c_cmd_link_delete(cmd); + if (ret != ESP_OK) + return false; + + JobI2cResult result{}; + cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (addr << 1) | I2C_MASTER_READ, true); + i2c_master_read(cmd, (uint8_t *)&result, sizeof(result), I2C_MASTER_LAST_NACK); + i2c_master_stop(cmd); + ret = i2c_master_cmd_begin(I2C_HASH_BUS_PORT, cmd, 20 / portTICK_PERIOD_MS); + i2c_cmd_link_delete(cmd); + if (ret != ESP_OK) + return false; + + if (result.cmd != I2C_CMD_SLAVE_RESULT) + return false; + return i2cCommandCrc8(&result, sizeof(result)) == result.crc; +} + +int i2c_master_start() +{ + memset(&s_i2c_config, 0, sizeof(s_i2c_config)); + s_i2c_config.mode = I2C_MODE_MASTER; + s_i2c_config.sda_io_num = I2C_HASH_SDA_PIN; + s_i2c_config.scl_io_num = I2C_HASH_SCL_PIN; + s_i2c_config.sda_pullup_en = GPIO_PULLUP_ENABLE; + s_i2c_config.scl_pullup_en = GPIO_PULLUP_ENABLE; + s_i2c_config.master.clk_speed = I2C_HASH_CLOCK_HZ; + + esp_err_t err = i2c_param_config(I2C_HASH_BUS_PORT, &s_i2c_config); + if (err != ESP_OK) + return err; + + err = i2c_driver_install(I2C_HASH_BUS_PORT, s_i2c_config.mode, I2C_MASTER_TX_BUF_LEN, I2C_MASTER_RX_BUF_LEN, 0); + if (err == ESP_ERR_INVALID_STATE) + return ESP_OK; // Bus already initialized by another component (e.g. display) + return err; +} + +std::vector i2c_master_scan(uint8_t start, uint8_t end) +{ + std::vector vec; for (int addr = start; addr < end; ++addr) { i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (addr << 1) | I2C_MASTER_WRITE, true); - //i2c_master_write(cmd, data_wr, size, true); - i2c_master_stop(cmd); - esp_err_t ret = i2c_master_cmd_begin(I2C_MASTER_NUM_PORT, cmd, 50 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - if (ret == ESP_OK) - vec.push_back(addr); - } - return vec; -} - -void i2c_feed_slaves(const std::vector& slaves, uint8_t id, uint8_t nonce_start, float difficulty, const uint8_t* buffer) -{ - JobI2cRequest request; - request.cmd = I2C_CMD_FEED; - request.id = id; - request.difficulty = difficulty; - memcpy(request.buffer, buffer, sizeof(request.buffer)); - - for (size_t n = 0; n < slaves.size(); ++n) - { - request.nonce_start = nonce_start; - nonce_start += 0x10; - request.crc = CommandCrc8(&request, sizeof(request)); - - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (slaves[n] << 1) | I2C_MASTER_WRITE, true); - i2c_master_write(cmd, (const uint8_t*)&request, sizeof(request), true); - i2c_master_stop(cmd); - i2c_master_cmd_begin(I2C_MASTER_NUM_PORT, cmd, 5 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - } -} - - -void i2c_hit_slaves(const std::vector& slaves) -{ - uint8_t request[2]; - request[0] = I2C_CMD_REQUEST_RESULT; - request[1] = CommandCrc8(request, 2); - for (size_t n = 0; n < slaves.size(); ++n) - { - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (slaves[n] << 1) | I2C_MASTER_WRITE, true); - i2c_master_write(cmd, request, sizeof(request), true); - i2c_master_stop(cmd); - i2c_master_cmd_begin(I2C_MASTER_NUM_PORT, cmd, 5 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - } -} - -std::vector i2c_harvest_slaves(const std::vector& slaves, uint8_t id, uint32_t &total_procesed_nonce) -{ - std::vector nonce_vector; - JobI2cResult result; - for (size_t n = 0; n < slaves.size(); ++n) - { - i2c_cmd_handle_t cmd = i2c_cmd_link_create(); - i2c_master_start(cmd); - i2c_master_write_byte(cmd, (slaves[n] << 1) | I2C_MASTER_READ, true); - i2c_master_read(cmd, (uint8_t*)&result, sizeof(result), I2C_MASTER_LAST_NACK); - i2c_master_stop(cmd); - i2c_master_cmd_begin(I2C_MASTER_NUM_PORT, cmd, 5 / portTICK_RATE_MS); - i2c_cmd_link_delete(cmd); - - uint8_t crc = CommandCrc8(&result, sizeof(result)); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (addr << 1) | I2C_MASTER_WRITE, true); + //i2c_master_write(cmd, data_wr, size, true); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_HASH_BUS_PORT, cmd, 25 / portTICK_PERIOD_MS); + i2c_cmd_link_delete(cmd); + if (ret == ESP_OK && i2c_probe_hash_slave((uint8_t)addr)) + vec.push_back(addr); + } + return vec; +} - if (crc != result.crc) - continue; - if (result.nonce != 0xFFFFFFFF) - nonce_vector.push_back(result.nonce); - total_procesed_nonce += result.processed_nonce; - } - return nonce_vector; -} +void i2c_feed_slaves(const std::vector& slaves, uint8_t id, const std::vector& nonce_starts, uint32_t nonce_stride, float difficulty, const uint8_t* buffer) +{ + if (slaves.empty()) + return; + + JobI2cRequest request{}; + request.cmd = I2C_CMD_FEED; + request.id = id; + request.difficulty = difficulty; + request.nonce_stride = nonce_stride == 0 ? 1 : nonce_stride; + memcpy(request.buffer, buffer, sizeof(request.buffer)); + + uint32_t fallback_start = 0x20000000u; + for (size_t n = 0; n < slaves.size(); ++n) + { + if (n < nonce_starts.size()) + request.nonce_start = nonce_starts[n]; + else + request.nonce_start = fallback_start; + fallback_start += request.nonce_stride; + request.crc = i2cCommandCrc8(&request, sizeof(request)); + + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (slaves[n] << 1) | I2C_MASTER_WRITE, true); + i2c_master_write(cmd, (const uint8_t*)&request, sizeof(request), true); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_HASH_BUS_PORT, cmd, 10 / portTICK_PERIOD_MS); + i2c_cmd_link_delete(cmd); + if (ret == ESP_OK) + { + s_i2c_diag.feed_tx_ok++; + } + else + { + s_i2c_diag.feed_tx_err++; + i2c_diag_mark_err(ret, slaves[n]); + #if I2C_MASTER_DIAG_IMMEDIATE_LOG + Serial.printf("[I2C-MASTER][diag] FEED write failed addr=0x%02X err=%d\n", (unsigned)slaves[n], (int)ret); + #endif + } + } +} + +void i2c_feed_slaves(const std::vector& slaves, uint8_t id, uint32_t nonce_start, uint32_t nonce_stride, float difficulty, const uint8_t* buffer) +{ + std::vector nonce_starts; + nonce_starts.reserve(slaves.size()); + uint32_t current = nonce_start; + uint32_t step = nonce_stride == 0 ? 1 : nonce_stride; + for (size_t n = 0; n < slaves.size(); ++n) + { + nonce_starts.push_back(current); + current += step; + } + i2c_feed_slaves(slaves, id, nonce_starts, step, difficulty, buffer); +} + + +void i2c_hit_slaves(const std::vector& slaves) +{ + uint8_t request[2]; + request[0] = I2C_CMD_REQUEST_RESULT; + request[1] = i2cCommandCrc8(request, 2); + for (size_t n = 0; n < slaves.size(); ++n) + { + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (slaves[n] << 1) | I2C_MASTER_WRITE, true); + i2c_master_write(cmd, request, sizeof(request), true); + i2c_master_stop(cmd); + esp_err_t ret = i2c_master_cmd_begin(I2C_HASH_BUS_PORT, cmd, 10 / portTICK_PERIOD_MS); + i2c_cmd_link_delete(cmd); + if (ret == ESP_OK) + { + s_i2c_diag.hit_tx_ok++; + } + else + { + s_i2c_diag.hit_tx_err++; + i2c_diag_mark_err(ret, slaves[n]); + #if I2C_MASTER_DIAG_IMMEDIATE_LOG + Serial.printf("[I2C-MASTER][diag] HIT write failed addr=0x%02X err=%d\n", (unsigned)slaves[n], (int)ret); + #endif + } + } +} + +void i2c_harvest_slaves(const std::vector& slaves, uint8_t id, std::vector& results) +{ + results.clear(); + if (results.capacity() < slaves.size()) + results.reserve(slaves.size()); + + JobI2cResult result{}; + for (size_t n = 0; n < slaves.size(); ++n) + { + result = {}; + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (slaves[n] << 1) | I2C_MASTER_READ, true); + i2c_master_read(cmd, (uint8_t*)&result, sizeof(result), I2C_MASTER_LAST_NACK); + i2c_master_stop(cmd); + uint32_t rx_t0 = millis(); + esp_err_t ret = i2c_master_cmd_begin(I2C_HASH_BUS_PORT, cmd, 10 / portTICK_PERIOD_MS); + uint32_t rx_ms = (uint32_t)(millis() - rx_t0); + if (rx_ms > s_i2c_diag.max_rx_ms) + s_i2c_diag.max_rx_ms = rx_ms; + i2c_cmd_link_delete(cmd); + if (ret != ESP_OK) + { + s_i2c_diag.harvest_rx_err++; + i2c_diag_mark_err(ret, slaves[n]); + #if I2C_MASTER_DIAG_IMMEDIATE_LOG + Serial.printf("[I2C-MASTER][diag] RX read failed addr=0x%02X err=%d\n", (unsigned)slaves[n], (int)ret); + #endif + continue; + } + + uint8_t crc = i2cCommandCrc8(&result, sizeof(result)); + + if (crc != result.crc) + { + s_i2c_diag.harvest_crc_err++; + continue; + } + if (result.cmd != I2C_CMD_SLAVE_RESULT) + { + s_i2c_diag.harvest_cmd_err++; + continue; + } + if (result.id != id) + { + s_i2c_diag.harvest_id_err++; + continue; + } + + I2cSlaveHarvest item{}; + item.address = slaves[n]; + item.nonce = result.nonce; + item.processed_nonce = result.processed_nonce; + item.has_nonce = (result.nonce != kI2cInvalidNonce); + results.push_back(item); + s_i2c_diag.harvest_rx_ok++; + } +} + +std::vector i2c_harvest_slaves(const std::vector& slaves, uint8_t id) +{ + std::vector results; + results.reserve(slaves.size()); + i2c_harvest_slaves(slaves, id, results); + return results; +} + +std::vector i2c_harvest_slaves(const std::vector& slaves, uint8_t id, uint32_t &total_procesed_nonce) +{ + std::vector nonce_vector; + std::vector records; + records.reserve(slaves.size()); + i2c_harvest_slaves(slaves, id, records); + total_procesed_nonce = 0; + nonce_vector.reserve(records.size()); + for (size_t i = 0; i < records.size(); ++i) + { + total_procesed_nonce += records[i].processed_nonce; + if (records[i].has_nonce) + nonce_vector.push_back(records[i].nonce); + } + return nonce_vector; +} diff --git a/src/i2c_master.h b/src/i2c_master.h index 8ea73e43..e593fca6 100644 --- a/src/i2c_master.h +++ b/src/i2c_master.h @@ -1,9 +1,39 @@ -#include -#include -#pragma once - -int i2c_master_start(); -std::vector i2c_master_scan(uint8_t start, uint8_t end); -void i2c_feed_slaves(const std::vector& slaves, uint8_t id, uint8_t nonce_start, float difficulty, const uint8_t* buffer); -void i2c_hit_slaves(const std::vector& slaves); -std::vector i2c_harvest_slaves(const std::vector& slaves, uint8_t id, uint32_t &total_procesed_nonce); \ No newline at end of file +#include +#include +#pragma once + +struct I2cSlaveHarvest +{ + uint8_t address; + uint32_t nonce; + uint32_t processed_nonce; + bool has_nonce; +}; + +struct I2cMasterDiagSnapshot +{ + uint32_t feed_tx_ok; + uint32_t feed_tx_err; + uint32_t hit_tx_ok; + uint32_t hit_tx_err; + uint32_t harvest_rx_ok; + uint32_t harvest_rx_err; + uint32_t harvest_crc_err; + uint32_t harvest_cmd_err; + uint32_t harvest_id_err; + uint32_t max_rx_ms; + uint32_t last_err_ms; + int32_t last_err; + uint8_t last_err_addr; +}; + +int i2c_master_start(); +std::vector i2c_master_scan(uint8_t start, uint8_t end); +void i2c_feed_slaves(const std::vector& slaves, uint8_t id, const std::vector& nonce_starts, uint32_t nonce_stride, float difficulty, const uint8_t* buffer); +void i2c_feed_slaves(const std::vector& slaves, uint8_t id, uint32_t nonce_start, uint32_t nonce_stride, float difficulty, const uint8_t* buffer); +void i2c_hit_slaves(const std::vector& slaves); +void i2c_harvest_slaves(const std::vector& slaves, uint8_t id, std::vector& results); +std::vector i2c_harvest_slaves(const std::vector& slaves, uint8_t id); +std::vector i2c_harvest_slaves(const std::vector& slaves, uint8_t id, uint32_t &total_procesed_nonce); +void i2c_master_diag_reset(); +void i2c_master_diag_snapshot(I2cMasterDiagSnapshot &snapshot); diff --git a/src/i2c_protocol.h b/src/i2c_protocol.h new file mode 100644 index 00000000..09cf1fac --- /dev/null +++ b/src/i2c_protocol.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include + +#define I2C_CMD_FEED 0xA1 +#define I2C_CMD_REQUEST_RESULT 0xA9 +#define I2C_CMD_SLAVE_RESULT 0xAA + +static constexpr uint32_t kI2cInvalidNonce = 0xFFFFFFFFu; +static constexpr uint8_t kI2cNoJobId = 0xFFu; + +struct __attribute__((__packed__)) JobI2cRequest +{ + // 91 bytes + uint8_t cmd; + uint8_t crc; + uint8_t id; + uint32_t nonce_start; + uint32_t nonce_stride; + float difficulty; + uint8_t buffer[76]; +}; + +struct __attribute__((__packed__)) JobI2cResult +{ + // 11 bytes + uint8_t cmd; + uint8_t crc; + uint8_t id; + uint32_t nonce; + uint32_t processed_nonce; +}; + +static inline uint8_t i2cCommandCrc8(const void *data, size_t len) +{ + static const uint8_t table[256] = { + 0x00, 0x31, 0x62, 0x53, 0xC4, 0xF5, 0xA6, 0x97, + 0xB9, 0x88, 0xDB, 0xEA, 0x7D, 0x4C, 0x1F, 0x2E, + 0x43, 0x72, 0x21, 0x10, 0x87, 0xB6, 0xE5, 0xD4, + 0xFA, 0xCB, 0x98, 0xA9, 0x3E, 0x0F, 0x5C, 0x6D, + 0x86, 0xB7, 0xE4, 0xD5, 0x42, 0x73, 0x20, 0x11, + 0x3F, 0x0E, 0x5D, 0x6C, 0xFB, 0xCA, 0x99, 0xA8, + 0xC5, 0xF4, 0xA7, 0x96, 0x01, 0x30, 0x63, 0x52, + 0x7C, 0x4D, 0x1E, 0x2F, 0xB8, 0x89, 0xDA, 0xEB, + 0x3D, 0x0C, 0x5F, 0x6E, 0xF9, 0xC8, 0x9B, 0xAA, + 0x84, 0xB5, 0xE6, 0xD7, 0x40, 0x71, 0x22, 0x13, + 0x7E, 0x4F, 0x1C, 0x2D, 0xBA, 0x8B, 0xD8, 0xE9, + 0xC7, 0xF6, 0xA5, 0x94, 0x03, 0x32, 0x61, 0x50, + 0xBB, 0x8A, 0xD9, 0xE8, 0x7F, 0x4E, 0x1D, 0x2C, + 0x02, 0x33, 0x60, 0x51, 0xC6, 0xF7, 0xA4, 0x95, + 0xF8, 0xC9, 0x9A, 0xAB, 0x3C, 0x0D, 0x5E, 0x6F, + 0x41, 0x70, 0x23, 0x12, 0x85, 0xB4, 0xE7, 0xD6, + 0x7A, 0x4B, 0x18, 0x29, 0xBE, 0x8F, 0xDC, 0xED, + 0xC3, 0xF2, 0xA1, 0x90, 0x07, 0x36, 0x65, 0x54, + 0x39, 0x08, 0x5B, 0x6A, 0xFD, 0xCC, 0x9F, 0xAE, + 0x80, 0xB1, 0xE2, 0xD3, 0x44, 0x75, 0x26, 0x17, + 0xFC, 0xCD, 0x9E, 0xAF, 0x38, 0x09, 0x5A, 0x6B, + 0x45, 0x74, 0x27, 0x16, 0x81, 0xB0, 0xE3, 0xD2, + 0xBF, 0x8E, 0xDD, 0xEC, 0x7B, 0x4A, 0x19, 0x28, + 0x06, 0x37, 0x64, 0x55, 0xC2, 0xF3, 0xA0, 0x91, + 0x47, 0x76, 0x25, 0x14, 0x83, 0xB2, 0xE1, 0xD0, + 0xFE, 0xCF, 0x9C, 0xAD, 0x3A, 0x0B, 0x58, 0x69, + 0x04, 0x35, 0x66, 0x57, 0xC0, 0xF1, 0xA2, 0x93, + 0xBD, 0x8C, 0xDF, 0xEE, 0x79, 0x48, 0x1B, 0x2A, + 0xC1, 0xF0, 0xA3, 0x92, 0x05, 0x34, 0x67, 0x56, + 0x78, 0x49, 0x1A, 0x2B, 0xBC, 0x8D, 0xDE, 0xEF, + 0x82, 0xB3, 0xE0, 0xD1, 0x46, 0x77, 0x24, 0x15, + 0x3B, 0x0A, 0x59, 0x68, 0xFF, 0xCE, 0x9D, 0xAC}; + + if (data == nullptr || len == 0) + return 0; + const uint8_t *ptr = (const uint8_t *)data; + uint8_t crc = 0xFF; + crc = table[crc ^ ptr[0]]; + for (size_t n = 2; n < len; ++n) + crc = table[crc ^ ptr[n]]; + return crc; +} diff --git a/src/mining.cpp b/src/mining.cpp index 8fd73163..d397296a 100644 --- a/src/mining.cpp +++ b/src/mining.cpp @@ -13,17 +13,167 @@ #include "timeconst.h" #include "drivers/displays/display.h" #include "drivers/storage/storage.h" -#include -#include -#include +#include +#include +#include +#include "freertos/FreeRTOS.h" +#include "freertos/queue.h" #include "mbedtls/sha256.h" +#include "lwip/sockets.h" +#include "lwip/tcp.h" #include "i2c_master.h" +#include "i2c_protocol.h" + +#include "i2c_hash_config.h" +#if defined(I2C_HASH_SLAVE) +#include +#endif + +#ifndef I2C_BOOT_SCAN_ROUNDS +#define I2C_BOOT_SCAN_ROUNDS 12 +#endif +#ifndef I2C_BOOT_SCAN_DELAY_MS +#define I2C_BOOT_SCAN_DELAY_MS 300 +#endif +#ifndef I2C_RUNTIME_RESCAN_MS +#define I2C_RUNTIME_RESCAN_MS 0 +#endif +#ifndef I2C_SLAVE_LOSS_POLL_THRESHOLD +#define I2C_SLAVE_LOSS_POLL_THRESHOLD 64 +#endif +#ifndef I2C_LOSS_RESCAN_MAX_ATTEMPTS +#define I2C_LOSS_RESCAN_MAX_ATTEMPTS 2 +#endif +#ifndef I2C_LOSS_RESCAN_INTERVAL_MS +#define I2C_LOSS_RESCAN_INTERVAL_MS 1200 +#endif +#ifndef I2C_MASTER_CYCLE_MS +#define I2C_MASTER_CYCLE_MS 120 +#endif +#ifndef I2C_MASTER_IDLE_MS +#define I2C_MASTER_IDLE_MS 50 +#endif +#ifndef I2C_MASTER_POST_HIT_DELAY_MS +#define I2C_MASTER_POST_HIT_DELAY_MS 2 +#endif +#ifndef I2C_REBALANCE_DEBUG +#define I2C_REBALANCE_DEBUG 0 +#endif +#ifndef I2C_MASTER_DIAG_LOG +#define I2C_MASTER_DIAG_LOG 0 +#endif +#ifndef I2C_MASTER_DIAG_LOG_MS +#define I2C_MASTER_DIAG_LOG_MS 10000 +#endif +#ifndef I2C_MASTER_DIAG_WARN_CYCLE_MS +#define I2C_MASTER_DIAG_WARN_CYCLE_MS 120 +#endif +#ifndef WIFI_RECONNECT_INTERVAL_MS +#define WIFI_RECONNECT_INTERVAL_MS 10000 +#endif +#ifndef WIFI_FORCE_RECONNECT_INTERVAL_MS +#define WIFI_FORCE_RECONNECT_INTERVAL_MS 30000 +#endif +#ifndef POOL_TCP_KEEPIDLE_S +#define POOL_TCP_KEEPIDLE_S 60 +#endif +#ifndef POOL_TCP_KEEPINTVL_S +#define POOL_TCP_KEEPINTVL_S 15 +#endif +#ifndef POOL_TCP_KEEPCNT +#define POOL_TCP_KEEPCNT 3 +#endif +#ifndef POOL_STREAM_TIMEOUT_MS +#define POOL_STREAM_TIMEOUT_MS 2000 +#endif +#ifndef MINER_POWER_SMOOTHING_SW_JOB_INTERVAL +#define MINER_POWER_SMOOTHING_SW_JOB_INTERVAL 0 +#endif +#ifndef MINER_POWER_SMOOTHING_HW_JOB_INTERVAL +#define MINER_POWER_SMOOTHING_HW_JOB_INTERVAL 0 +#endif +#ifndef MINER_POWER_SMOOTHING_DELAY_MS +#define MINER_POWER_SMOOTHING_DELAY_MS 1 +#endif +#ifndef ADAPTIVE_SUGGEST_DIFFICULTY +#define ADAPTIVE_SUGGEST_DIFFICULTY 1 +#endif +#ifndef STRATUM_LOOP_DELAY_BUSY_MS +#define STRATUM_LOOP_DELAY_BUSY_MS 2 +#endif +#ifndef STRATUM_LOOP_DELAY_ACTIVE_MS +#define STRATUM_LOOP_DELAY_ACTIVE_MS 8 +#endif +#ifndef STRATUM_LOOP_DELAY_IDLE_MS +#define STRATUM_LOOP_DELAY_IDLE_MS 20 +#endif +#ifndef MINER_SHARE_LOG +#define MINER_SHARE_LOG 0 +#endif +#ifndef SUGGEST_DIFF_FIXED_VALUE +#define SUGGEST_DIFF_FIXED_VALUE 16384.0 +#endif +#ifndef SUGGEST_DIFF_TARGET_SHARE_TIME_S +#define SUGGEST_DIFF_TARGET_SHARE_TIME_S 30.0 +#endif +#ifndef SUGGEST_DIFF_MIN +#define SUGGEST_DIFF_MIN 0.0001 +#endif +#ifndef SUGGEST_DIFF_MAX +#define SUGGEST_DIFF_MAX 131072.0 +#endif +#ifndef SUGGEST_DIFF_SMOOTH_ALPHA_PCT +#define SUGGEST_DIFF_SMOOTH_ALPHA_PCT 40 +#endif +#ifndef MINER_HEARTBEAT_LOG +#define MINER_HEARTBEAT_LOG 0 +#endif + +#ifndef ADAPTIVE_TARGET_MS_DEFAULT +#if defined(I2C_HASH_SLAVE) +#define ADAPTIVE_TARGET_MS_DEFAULT 180 +#else +#define ADAPTIVE_TARGET_MS_DEFAULT 150 +#endif +#endif +#ifndef ADAPTIVE_TARGET_MS_MIN +#define ADAPTIVE_TARGET_MS_MIN 80 +#endif +#ifndef ADAPTIVE_TARGET_MS_MAX +#define ADAPTIVE_TARGET_MS_MAX 350 +#endif //10 Jobs per second -#define NONCE_PER_JOB_SW 4096 -#define NONCE_PER_JOB_HW 16*1024 +#if defined(CONFIG_IDF_TARGET_ESP32) +#define NONCE_PER_JOB_SW (32 * 1024) +#define NONCE_PER_JOB_HW (128 * 1024) +#elif defined(CONFIG_IDF_TARGET_ESP32S3) +#define NONCE_PER_JOB_SW (24 * 1024) +#define NONCE_PER_JOB_HW (96 * 1024) +#else +#define NONCE_PER_JOB_SW (16 * 1024) +#define NONCE_PER_JOB_HW (64 * 1024) +#endif +static constexpr uint32_t kAdaptiveTargetMsDefault = ADAPTIVE_TARGET_MS_DEFAULT; +static constexpr uint32_t kAdaptiveTargetMsMin = ADAPTIVE_TARGET_MS_MIN; +static constexpr uint32_t kAdaptiveTargetMsMax = ADAPTIVE_TARGET_MS_MAX; +static constexpr uint32_t kAdaptiveTargetStepDown = 20; +static constexpr uint32_t kAdaptiveTargetStepUp = 10; +static constexpr uint32_t kAdaptiveTargetWindowMs = 30000; +static volatile uint32_t s_adaptive_target_ms = kAdaptiveTargetMsDefault; +#if defined(CONFIG_IDF_TARGET_ESP32S3) +static constexpr uint32_t kAdaptiveMinSw = 8 * 1024; +static constexpr uint32_t kAdaptiveMaxSw = 192 * 1024; +static constexpr uint32_t kAdaptiveMinHw = 32 * 1024; +static constexpr uint32_t kAdaptiveMaxHw = 384 * 1024; +#else +static constexpr uint32_t kAdaptiveMinSw = 4 * 1024; +static constexpr uint32_t kAdaptiveMaxSw = 128 * 1024; +static constexpr uint32_t kAdaptiveMinHw = 16 * 1024; +static constexpr uint32_t kAdaptiveMaxHw = 256 * 1024; +#endif -//#define I2C_SLAVE +// Legacy alias kept for compatibility: I2C_SLAVE -> I2C_HASH_MASTER //#define SHA256_VALIDATE //#define RANDOM_NONCE @@ -51,6 +201,7 @@ uint64_t upTime = 0; volatile uint32_t shares; // increase if blockhash has 32 bits of zeroes volatile uint32_t valids; // increased if blockhash <= target +volatile uint32_t stales; // stale/late shares reported by pool // Track best diff double best_diff = 0.0; @@ -69,11 +220,112 @@ mining_job mJob; monitor_data mMonitor; static bool volatile isMinerSuscribed = false; unsigned long mLastTXtoPool = millis(); +unsigned long mLastRXfromPool = millis(); +static String s_last_subscribe_session_id; +static bool s_resume_subscribe_enabled = true; +static constexpr double kDiffOneHashes = 4294967296.0; // 2^32 hashes for difficulty 1 +static double s_suggest_diff_smoothed = -1.0; +static uint64_t s_suggest_hashes_last = 0; +static uint32_t s_suggest_ms_last = 0; int saveIntervals[7] = {5 * 60, 15 * 60, 30 * 60, 1 * 3600, 3 * 3600, 6 * 3600, 12 * 3600}; int saveIntervalsSize = sizeof(saveIntervals)/sizeof(saveIntervals[0]); int currentIntervalIndex = 0; +static void copyCString(char *dst, size_t dstSize, const char *src) +{ + if (dst == nullptr || dstSize == 0) + return; + if (src == nullptr) + { + dst[0] = '\0'; + return; + } + strncpy(dst, src, dstSize - 1); + dst[dstSize - 1] = '\0'; +} + +static void configurePoolSocket(WiFiClient &poolClient) +{ + poolClient.setNoDelay(true); + // Stream timeout is in milliseconds; keep it long enough to read full JSON lines. + poolClient.setTimeout(POOL_STREAM_TIMEOUT_MS); + + int on = 1; + poolClient.setSocketOption(SOL_SOCKET, SO_KEEPALIVE, &on, sizeof(on)); + +#if defined(TCP_KEEPIDLE) + int keepidle = POOL_TCP_KEEPIDLE_S; + poolClient.setSocketOption(IPPROTO_TCP, TCP_KEEPIDLE, &keepidle, sizeof(keepidle)); +#endif +#if defined(TCP_KEEPINTVL) + int keepintvl = POOL_TCP_KEEPINTVL_S; + poolClient.setSocketOption(IPPROTO_TCP, TCP_KEEPINTVL, &keepintvl, sizeof(keepintvl)); +#endif +#if defined(TCP_KEEPCNT) + int keepcnt = POOL_TCP_KEEPCNT; + poolClient.setSocketOption(IPPROTO_TCP, TCP_KEEPCNT, &keepcnt, sizeof(keepcnt)); +#endif +} + +static inline double clamp_double(double v, double lo, double hi) +{ + if (v < lo) return lo; + if (v > hi) return hi; + return v; +} + +static inline uint64_t get_total_hashes_snapshot() +{ + return (uint64_t)Mhashes * 1000000ULL + (uint64_t)hashes; +} + +static double calculateSuggestedDifficulty() +{ +#if ADAPTIVE_SUGGEST_DIFFICULTY + const uint32_t now = millis(); + const uint64_t total_hashes = get_total_hashes_snapshot(); + + if (s_suggest_ms_last == 0 || now <= s_suggest_ms_last || total_hashes < s_suggest_hashes_last) + { + s_suggest_ms_last = now; + s_suggest_hashes_last = total_hashes; + if (s_suggest_diff_smoothed < 0.0) + return SUGGEST_DIFF_MIN; + return clamp_double(s_suggest_diff_smoothed, SUGGEST_DIFF_MIN, SUGGEST_DIFF_MAX); + } + + const uint32_t elapsed_ms = now - s_suggest_ms_last; + const uint64_t hash_delta = total_hashes - s_suggest_hashes_last; + if (elapsed_ms >= 1000 && hash_delta > 0) + { + const double hps = ((double)hash_delta * 1000.0) / (double)elapsed_ms; + double sample_diff = (hps * SUGGEST_DIFF_TARGET_SHARE_TIME_S) / kDiffOneHashes; + sample_diff = clamp_double(sample_diff, SUGGEST_DIFF_MIN, SUGGEST_DIFF_MAX); + + if (s_suggest_diff_smoothed < 0.0) + { + s_suggest_diff_smoothed = sample_diff; + } + else + { + double alpha = (double)SUGGEST_DIFF_SMOOTH_ALPHA_PCT / 100.0; + alpha = clamp_double(alpha, 0.0, 1.0); + s_suggest_diff_smoothed = (1.0 - alpha) * s_suggest_diff_smoothed + alpha * sample_diff; + } + + s_suggest_ms_last = now; + s_suggest_hashes_last = total_hashes; + } + + if (s_suggest_diff_smoothed < 0.0) + return SUGGEST_DIFF_MIN; + return clamp_double(s_suggest_diff_smoothed, SUGGEST_DIFF_MIN, SUGGEST_DIFF_MAX); +#else + return SUGGEST_DIFF_FIXED_VALUE; +#endif +} + bool checkPoolConnection(void) { if (client.connected()) { @@ -86,18 +338,29 @@ bool checkPoolConnection(void) { //Resolve first time pool DNS and save IP if(serverIP == IPAddress(1,1,1,1)) { - WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP); - Serial.printf("Resolved DNS and save ip (first time) got: %s\n", serverIP.toString()); + if (!WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP)) + { + Serial.printf("Failed to resolve pool DNS for: %s\n", Settings.PoolAddress.c_str()); + return false; + } + Serial.printf("Resolved DNS and saved IP (first time): %s\n", serverIP.toString().c_str()); } //Try connecting pool IP if (!client.connect(serverIP, Settings.PoolPort)) { Serial.println("Imposible to connect to : " + Settings.PoolAddress); - WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP); - Serial.printf("Resolved DNS got: %s\n", serverIP.toString()); + if (WiFi.hostByName(Settings.PoolAddress.c_str(), serverIP)) + Serial.printf("Resolved DNS retry got: %s\n", serverIP.toString().c_str()); + else + Serial.printf("DNS retry failed for: %s\n", Settings.PoolAddress.c_str()); return false; } + configurePoolSocket(client); + uint32_t now = millis(); + mLastTXtoPool = now; + mLastRXfromPool = now; + Serial.printf("Connected to pool %s:%d\n", serverIP.toString().c_str(), Settings.PoolPort); return true; } @@ -105,113 +368,1410 @@ bool checkPoolConnection(void) { //checks if pool is not sending any data to reconnect again. //Even connection could be alive, pool could stop sending new job NOTIFY unsigned long mStart0Hashrate = 0; -bool checkPoolInactivity(unsigned int keepAliveTime, unsigned long inactivityTime){ +bool checkPoolInactivity(unsigned int keepAliveTime, unsigned long inactivityTime, double currentDifficulty){ unsigned long currentKHashes = (Mhashes*1000) + hashes/1000; unsigned long elapsedKHs = currentKHashes - totalKHashes; uint32_t time_now = millis(); + if (!isMinerSuscribed) + return false; - // If no shares sent to pool - // send something to pool to hold socket oppened + // Heartbeat by TX idle time: + // if we spend too long without sending anything (e.g. no shares), push a light keepalive. if (time_now < mLastTXtoPool) //32bit wrap mLastTXtoPool = time_now; - if ( time_now > mLastTXtoPool + keepAliveTime) + if (time_now < mLastRXfromPool) //32bit wrap + mLastRXfromPool = time_now; + + bool tx_idle = ((uint32_t)(time_now - mLastTXtoPool) >= keepAliveTime); + if (tx_idle) { - mLastTXtoPool = time_now; - Serial.println(" Sending : KeepAlive suggest_difficulty"); - //if (client.print("{}\n") == 0) { - tx_suggest_difficulty(client, DEFAULT_DIFFICULTY); - /*if(tx_suggest_difficulty(client, DEFAULT_DIFFICULTY)){ - Serial.println(" Sending keepAlive to pool -> Detected client disconnected"); + double suggest_diff = calculateSuggestedDifficulty(); + #if MINER_HEARTBEAT_LOG + Serial.println(" Sending : Heartbeat (suggest_difficulty)"); + #endif + if (!tx_suggest_difficulty(client, suggest_diff)) { + #if MINER_HEARTBEAT_LOG + Serial.println(" Sending heartbeat to pool -> Detected client disconnected"); + #endif return true; - }*/ + } + mLastTXtoPool = time_now; } - if(elapsedKHs == 0){ - //Check if hashrate is 0 during inactivityTIme - if(mStart0Hashrate == 0) mStart0Hashrate = time_now; - if((time_now-mStart0Hashrate) > inactivityTime) { mStart0Hashrate=0; return true;} - return false; + // RX idle watchdog: reconnect if pool stops sending data/notify lines. + bool rx_idle = ((uint32_t)(time_now - mLastRXfromPool) >= inactivityTime); + if (rx_idle) + { + Serial.printf(" No data from stratum for %lu s. Reconnecting...\n", inactivityTime / 1000UL); + return true; } - mStart0Hashrate = 0; - return false; + (void)currentDifficulty; + (void)elapsedKHs; + mStart0Hashrate = 0; + return false; } -struct JobRequest +struct JobData { uint32_t id; - uint32_t nonce_start; - uint32_t nonce_count; double difficulty; - uint8_t sha_buffer[128]; + uint8_t pool_target_le[32]; + uint8_t sha_buffer_sw[128]; + uint8_t sha_buffer_hw[128]; uint32_t midstate[8]; uint32_t bake[16]; + uint32_t hw_midstate[8]; +}; + +struct JobRequest +{ + JobData *data; + uint32_t nonce_start; + uint32_t nonce_stride; + uint32_t nonce_count; +}; + +struct JobResult +{ + uint32_t id; + uint32_t nonce; + uint32_t nonce_count; + double difficulty; + uint8_t hash[32]; +}; + +#if defined(CONFIG_IDF_TARGET_ESP32) +static constexpr UBaseType_t kJobQueueDepth = 12; +static constexpr UBaseType_t kJobQueueTargetDepth = 6; +static constexpr UBaseType_t kResultQueueDepth = 24; +#else +static constexpr UBaseType_t kJobQueueDepth = 8; +static constexpr UBaseType_t kJobQueueTargetDepth = 4; +static constexpr UBaseType_t kResultQueueDepth = 16; +#endif +static constexpr size_t kJobResultsMax = 32; +static constexpr size_t kMaxPendingSubmissions = 64; +static constexpr size_t kStratumLineBufferSize = BUFFER_JSON_DOC + 512; + +static QueueHandle_t s_job_queue_sw = nullptr; +#ifdef HARDWARE_SHA265 +static QueueHandle_t s_job_queue_hw = nullptr; +#endif +static QueueHandle_t s_result_queue = nullptr; + +static StaticQueue_t s_job_queue_sw_struct; +static uint8_t s_job_queue_sw_storage[kJobQueueDepth * sizeof(JobRequest)]; +#ifdef HARDWARE_SHA265 +static StaticQueue_t s_job_queue_hw_struct; +static uint8_t s_job_queue_hw_storage[kJobQueueDepth * sizeof(JobRequest)]; +#endif +static StaticQueue_t s_result_queue_struct; +static uint8_t s_result_queue_storage[kResultQueueDepth * sizeof(JobResult)]; +static volatile uint8_t s_working_current_job_id = 0xFF; +static volatile uint32_t s_sw_hashes_per_ms = 0; +static volatile uint32_t s_hw_hashes_per_ms = 0; +static constexpr uint8_t kJobDataPoolSize = 4; +static JobData s_job_data_pool[kJobDataPoolSize]; +static uint8_t s_job_data_index = 0; +static JobData *s_current_job_data = nullptr; +static portMUX_TYPE s_local_hashes_lock = portMUX_INITIALIZER_UNLOCKED; +static volatile uint32_t s_local_hashes_pending = 0; + +static inline void mining_add_local_processed_hashes(uint32_t hashes_done) +{ + if (hashes_done == 0) + return; + taskENTER_CRITICAL(&s_local_hashes_lock); + s_local_hashes_pending += hashes_done; + taskEXIT_CRITICAL(&s_local_hashes_lock); +} + +static inline uint32_t mining_take_local_processed_hashes() +{ + taskENTER_CRITICAL(&s_local_hashes_lock); + uint32_t out = s_local_hashes_pending; + s_local_hashes_pending = 0; + taskEXIT_CRITICAL(&s_local_hashes_lock); + return out; +} + +static inline void mining_reset_local_processed_hashes() +{ + taskENTER_CRITICAL(&s_local_hashes_lock); + s_local_hashes_pending = 0; + taskEXIT_CRITICAL(&s_local_hashes_lock); +} + +static inline uint32_t clamp_u32(uint32_t v, uint32_t lo, uint32_t hi) +{ + if (v < lo) return lo; + if (v > hi) return hi; + return v; +} + +static inline uint32_t nonce_stride_advance_u32(uint32_t cursor, uint32_t stride, uint32_t nonce_count) +{ + if (nonce_count == 0) + return cursor; + uint32_t step = stride == 0 ? 1 : stride; + uint64_t adv = (uint64_t)step * (uint64_t)nonce_count; + return (uint32_t)(cursor + adv); +} + +static inline uint32_t calc_nonce_per_job_sw() +{ + uint32_t hpm = s_sw_hashes_per_ms; + if (hpm == 0) + return NONCE_PER_JOB_SW; + uint32_t n = hpm * s_adaptive_target_ms; + return clamp_u32(n, kAdaptiveMinSw, kAdaptiveMaxSw); +} + +static inline uint32_t calc_nonce_per_job_hw() +{ + uint32_t hpm = s_hw_hashes_per_ms; + if (hpm == 0) + return NONCE_PER_JOB_HW; + uint32_t n = hpm * s_adaptive_target_ms; + return clamp_u32(n, kAdaptiveMinHw, kAdaptiveMaxHw); +} + +static inline void update_hashrate(volatile uint32_t &rate, uint32_t hashes, uint32_t elapsed_us) +{ + if (elapsed_us == 0) + return; + uint32_t sample = (uint32_t)((uint64_t)hashes * 1000ULL / (uint64_t)elapsed_us); + if (sample == 0) + return; + uint32_t prev = rate; + if (prev == 0) + rate = sample; + else + rate = (prev * 7 + sample) / 8; +} + +static inline void apply_power_smoothing(uint32_t interval, uint32_t &counter) +{ + if (interval == 0) + return; + + counter++; + if (counter < interval) + return; + + counter = 0; + const TickType_t delay_ticks = MINER_POWER_SMOOTHING_DELAY_MS / portTICK_PERIOD_MS; + if (delay_ticks > 0) + vTaskDelay(delay_ticks); + else + taskYIELD(); +} +static uint32_t mac_nonce_offset() +{ + static uint32_t cached = 0; + if (cached != 0) + return cached; + uint64_t mac = ESP.getEfuseMac(); + uint32_t lo = (uint32_t)mac; + uint32_t hi = (uint32_t)(mac >> 32); + uint32_t mix = lo ^ hi; + mix ^= (mix >> 16); + mix *= 0x7feb352dU; + mix ^= (mix >> 15); + mix *= 0x846ca68bU; + mix ^= (mix >> 16); + if (mix == 0) + mix = 1; + cached = mix; + return cached; +} + +static bool is_stale_error_doc(const JsonDocument &doc) +{ + if (!doc.containsKey("error")) + return false; + if (doc["error"].isNull()) + return false; + int code = doc["error"][0] | 0; + const char *msg = doc["error"][1] | ""; + if (code == 21) + return true; + if (msg && (strstr(msg, "stale") || strstr(msg, "Stale") || strstr(msg, "job not found") || strstr(msg, "Job not found"))) + return true; + return false; +} + +static inline bool stratumLineHasContent(const char *line, size_t len) +{ + for (size_t i = 0; i < len; ++i) + { + if (!isspace((unsigned char)line[i])) + return true; + } + return false; +} + +static inline int hashCompareLe(const uint8_t *lhs, const uint8_t *rhs) +{ + for (int i = 31; i >= 0; --i) + { + if (lhs[i] < rhs[i]) + return -1; + if (lhs[i] > rhs[i]) + return 1; + } + return 0; +} + +static inline bool hashMeetsTargetLe(const uint8_t *hash_le, const uint8_t *target_le) +{ + return hashCompareLe(hash_le, target_le) <= 0; +} + +static void poolTargetFromDifficulty(double difficulty, uint8_t out_target_le[32]) +{ + if (out_target_le == nullptr) + return; + + if (!(difficulty > 0.0) || !isfinite(difficulty)) + { + memset(out_target_le, 0xFF, 32); + return; + } + + // difficulty 1 target (Bitcoin): 0x00000000FFFF0000000000000000000000000000000000000000000000000000 + static const long double kTrueDiffOne = 26959535291011309493156476344723991336010898738574164086137773096960.0L; + static const long double kTwoPow256 = 1.1579208923731619542357098500868790785326998466564056403945758400791312964e77L; + + long double target = kTrueDiffOne / (long double)difficulty; + if (!isfinite((double)target) || target <= 1.0L) + { + memset(out_target_le, 0, 32); + out_target_le[0] = 1; + return; + } + if (target >= kTwoPow256) + { + memset(out_target_le, 0xFF, 32); + return; + } + + memset(out_target_le, 0, 32); + for (int i = 0; i < 32; ++i) + { + long double byte_val = fmodl(target, 256.0L); + if (byte_val < 0.0L) + byte_val = 0.0L; + out_target_le[i] = (uint8_t)byte_val; + target = floorl(target / 256.0L); + if (target <= 0.0L) + break; + } +} + +void initMiningQueues() +{ + if (s_job_queue_sw != nullptr) + return; + + s_job_queue_sw = xQueueCreateStatic(kJobQueueDepth, sizeof(JobRequest), + s_job_queue_sw_storage, &s_job_queue_sw_struct); +#ifdef HARDWARE_SHA265 + s_job_queue_hw = xQueueCreateStatic(kJobQueueDepth, sizeof(JobRequest), + s_job_queue_hw_storage, &s_job_queue_hw_struct); +#endif + s_result_queue = xQueueCreateStatic(kResultQueueDepth, sizeof(JobResult), + s_result_queue_storage, &s_result_queue_struct); +} + +static bool JobPush(QueueHandle_t queue, JobData *data, uint32_t nonce_start, uint32_t nonce_count, uint32_t nonce_stride = 1) +{ + if (queue == nullptr) + return false; + + JobRequest job{}; + job.data = data; + job.nonce_start = nonce_start; + job.nonce_stride = nonce_stride == 0 ? 1 : nonce_stride; + job.nonce_count = nonce_count; + return xQueueSend(queue, &job, 0) == pdTRUE; +} + +struct SubmissionState +{ + double diff; + bool is32bit; + bool isValid; +}; + +struct SubmissionEntry +{ + bool used; + uint32_t id; + uint32_t stamp; + SubmissionState state; +}; + +struct SubmissionTracker +{ + SubmissionEntry entries[kMaxPendingSubmissions]; + uint32_t next_stamp; }; -struct JobResult -{ - uint32_t id; - uint32_t nonce; - uint32_t nonce_count; - double difficulty; - uint8_t hash[32]; -}; +static void submissionTrackerClear(SubmissionTracker &tracker) +{ + memset(&tracker, 0, sizeof(tracker)); +} + +static bool submissionTrackerTake(SubmissionTracker &tracker, uint32_t id, SubmissionState &state) +{ + for (size_t i = 0; i < kMaxPendingSubmissions; ++i) + { + SubmissionEntry &entry = tracker.entries[i]; + if (entry.used && entry.id == id) + { + state = entry.state; + entry.used = false; + return true; + } + } + return false; +} + +static void submissionTrackerPut(SubmissionTracker &tracker, uint32_t id, const SubmissionState &state) +{ + int free_index = -1; + int oldest_index = -1; + uint32_t oldest_stamp = UINT32_MAX; + + for (size_t i = 0; i < kMaxPendingSubmissions; ++i) + { + SubmissionEntry &entry = tracker.entries[i]; + if (entry.used) + { + if (entry.id == id) + { + entry.state = state; + if (++tracker.next_stamp == 0) + tracker.next_stamp = 1; + entry.stamp = tracker.next_stamp; + return; + } + if (entry.stamp < oldest_stamp) + { + oldest_stamp = entry.stamp; + oldest_index = (int)i; + } + } + else if (free_index < 0) + { + free_index = (int)i; + } + } + + int index = free_index >= 0 ? free_index : oldest_index; + if (index < 0) + return; + + if (++tracker.next_stamp == 0) + tracker.next_stamp = 1; + + SubmissionEntry &target = tracker.entries[index]; + target.used = true; + target.id = id; + target.stamp = tracker.next_stamp; + target.state = state; +} + +static void resetMiningQueuesOnly() +{ + if (s_result_queue) + xQueueReset(s_result_queue); + if (s_job_queue_sw) + xQueueReset(s_job_queue_sw); + #ifdef HARDWARE_SHA265 + if (s_job_queue_hw) + xQueueReset(s_job_queue_hw); + #endif + mining_reset_local_processed_hashes(); + s_working_current_job_id = 0xFF; +} + +#ifdef I2C_HASH_MASTER +static void i2c_master_clear_active_job(); +#endif + +static void MiningJobStop(uint32_t &job_pool, SubmissionTracker &submission_tracker) +{ + resetMiningQueuesOnly(); +#ifdef I2C_HASH_MASTER + i2c_master_clear_active_job(); +#endif + job_pool = 0xFFFFFFFF; + submissionTrackerClear(submission_tracker); +} + +#ifdef RANDOM_NONCE +uint64_t s_random_state = 1; +static uint32_t RandomGet() +{ + s_random_state += 0x9E3779B97F4A7C15ull; + uint64_t z = s_random_state; + z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull; + z = (z ^ (z >> 27)) * 0x94D049BB133111EBull; + return z ^ (z >> 31); +} + +#endif + +#if defined(I2C_HASH_SLAVE) + +#ifndef I2C_HASH_BUS_PORT +#define I2C_HASH_BUS_PORT 0 +#endif +#ifndef I2C_HASH_SDA_PIN +#define I2C_HASH_SDA_PIN 21 +#endif +#ifndef I2C_HASH_SCL_PIN +#define I2C_HASH_SCL_PIN 22 +#endif +#ifndef I2C_HASH_SLAVE_ADDRESS +#define I2C_HASH_SLAVE_ADDRESS 0x21 +#endif +#ifndef I2C_HASH_CLOCK_HZ +#define I2C_HASH_CLOCK_HZ 100000 +#endif +#ifndef I2C_SLAVE_DEBUG +#define I2C_SLAVE_DEBUG 0 +#endif +#ifndef I2C_SLAVE_ACTIVE_DELAY_MS +#define I2C_SLAVE_ACTIVE_DELAY_MS 1 +#endif +#ifndef I2C_SLAVE_IDLE_DELAY_MS +#define I2C_SLAVE_IDLE_DELAY_MS 3 +#endif +#ifndef I2C_SLAVE_LINK_TIMEOUT_MS +#define I2C_SLAVE_LINK_TIMEOUT_MS 45000 +#endif +#ifndef I2C_SLAVE_READY_BEACON_MS +#define I2C_SLAVE_READY_BEACON_MS 5000 +#endif + +static constexpr int kI2cSlaveRxBufLen = 256; +static constexpr int kI2cSlaveTxBufLen = 256; + +struct I2cNonceStrideState +{ + uint32_t cursor; + uint32_t stride; +}; + +static inline void i2c_stride_advance(I2cNonceStrideState &state, uint32_t nonce_count) +{ + if (nonce_count == 0) + return; + uint32_t step = state.stride == 0 ? 1 : state.stride; + uint64_t adv = (uint64_t)step * (uint64_t)nonce_count; + state.cursor = (uint32_t)(state.cursor + adv); +} + +static int i2c_slave_start_worker() +{ + i2c_config_t config{}; + config.mode = I2C_MODE_SLAVE; + config.sda_io_num = I2C_HASH_SDA_PIN; + config.scl_io_num = I2C_HASH_SCL_PIN; + config.sda_pullup_en = GPIO_PULLUP_ENABLE; + config.scl_pullup_en = GPIO_PULLUP_ENABLE; + config.slave.addr_10bit_en = 0; + config.slave.slave_addr = I2C_HASH_SLAVE_ADDRESS; + + esp_err_t err = i2c_param_config((i2c_port_t)I2C_HASH_BUS_PORT, &config); + if (err != ESP_OK) + return err; + return i2c_driver_install((i2c_port_t)I2C_HASH_BUS_PORT, config.mode, kI2cSlaveRxBufLen, kI2cSlaveTxBufLen, 0); +} + +static void i2c_slave_refill_job_queues(JobData *job_data, I2cNonceStrideState &nonce_state) +{ + if (job_data == nullptr) + return; + + const uint32_t sw_nonce_count = calc_nonce_per_job_sw(); + while (s_job_queue_sw && uxQueueMessagesWaiting(s_job_queue_sw) < kJobQueueTargetDepth) + { + if (!JobPush(s_job_queue_sw, job_data, nonce_state.cursor, sw_nonce_count, nonce_state.stride)) + break; + i2c_stride_advance(nonce_state, sw_nonce_count); + } + + #ifdef HARDWARE_SHA265 + const uint32_t hw_nonce_count = calc_nonce_per_job_hw(); + while (s_job_queue_hw && uxQueueMessagesWaiting(s_job_queue_hw) < kJobQueueTargetDepth) + { + if (!JobPush(s_job_queue_hw, job_data, nonce_state.cursor, hw_nonce_count, nonce_state.stride)) + break; + i2c_stride_advance(nonce_state, hw_nonce_count); + } + #endif +} + +static void i2c_slave_prepare_job(const JobI2cRequest &request, JobData *job_data, I2cNonceStrideState &nonce_state) +{ + if (job_data == nullptr) + return; + + resetMiningQueuesOnly(); + + memset(job_data, 0, sizeof(*job_data)); + job_data->id = request.id; + job_data->difficulty = request.difficulty; + poolTargetFromDifficulty(job_data->difficulty, job_data->pool_target_le); + + memcpy(job_data->sha_buffer_sw, request.buffer, sizeof(request.buffer)); + memset(job_data->sha_buffer_sw + 80, 0, sizeof(job_data->sha_buffer_sw) - 80); + job_data->sha_buffer_sw[80] = 0x80; + job_data->sha_buffer_sw[126] = 0x02; + job_data->sha_buffer_sw[127] = 0x80; + + nerd_mids(job_data->midstate, job_data->sha_buffer_sw); + nerd_sha256_bake(job_data->midstate, job_data->sha_buffer_sw + 64, job_data->bake); + + #if defined(CONFIG_IDF_TARGET_ESP32) + for (int i = 0; i < 32; ++i) + ((uint32_t *)job_data->sha_buffer_hw)[i] = __builtin_bswap32(((const uint32_t *)job_data->sha_buffer_sw)[i]); + #else + memcpy(job_data->sha_buffer_hw, job_data->sha_buffer_sw, sizeof(job_data->sha_buffer_hw)); + #endif + + #ifdef HARDWARE_SHA265 + #if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) + esp_sha_acquire_hardware(); + sha_hal_hash_block(SHA2_256, job_data->sha_buffer_sw, 64 / 4, true); + sha_hal_read_digest(SHA2_256, job_data->hw_midstate); + esp_sha_release_hardware(); + #else + memset(job_data->hw_midstate, 0, sizeof(job_data->hw_midstate)); + #endif + #else + memset(job_data->hw_midstate, 0, sizeof(job_data->hw_midstate)); + #endif + + s_current_job_data = job_data; + s_working_current_job_id = request.id; + + nonce_state.cursor = request.nonce_start; + nonce_state.stride = request.nonce_stride == 0 ? 1 : request.nonce_stride; + i2c_slave_refill_job_queues(job_data, nonce_state); +} + +static JobI2cResult i2c_slave_collect_result(uint8_t active_job_id, JobData *job_data, I2cNonceStrideState &nonce_state) +{ + JobI2cResult out{}; + out.cmd = I2C_CMD_SLAVE_RESULT; + out.id = active_job_id; + out.nonce = kI2cInvalidNonce; + out.processed_nonce = mining_take_local_processed_hashes(); + hashes += out.processed_nonce; + + double best_found_diff = -1.0; + if (s_result_queue && job_data) + { + JobResult res{}; + while (xQueueReceive(s_result_queue, &res, 0) == pdTRUE) + { + if ((uint8_t)(res.id & 0xFF) != active_job_id) + continue; + if (res.nonce != kI2cInvalidNonce && res.difficulty > best_found_diff) + { + best_found_diff = res.difficulty; + out.nonce = res.nonce; + } + } + } + + i2c_slave_refill_job_queues(job_data, nonce_state); + out.crc = i2cCommandCrc8(&out, sizeof(out)); + return out; +} + +static void i2c_slave_publish_result(const JobI2cResult &result) +{ + JobI2cResult msg = result; + msg.crc = i2cCommandCrc8(&msg, sizeof(msg)); + i2c_slave_write_buffer((i2c_port_t)I2C_HASH_BUS_PORT, (uint8_t *)&msg, sizeof(msg), 10 / portTICK_PERIOD_MS); +} + +void runI2cSlaveWorker(void *name) +{ + Serial.println(""); + Serial.printf("\n[I2C-SLAVE] Started. Running %s on core %d\n", (char *)name, xPortGetCoreID()); + + initMiningQueues(); + mMonitor.NerdStatus = NM_hashing; + + int err = i2c_slave_start_worker(); + if (err != ESP_OK) + { + Serial.printf("[I2C-SLAVE] Failed to start bus, error=%d\n", err); + while (1) + vTaskDelay(1000 / portTICK_PERIOD_MS); + } + + Serial.printf("[I2C-SLAVE] Ready on address 0x%02X (SDA=%d, SCL=%d)\n", I2C_HASH_SLAVE_ADDRESS, I2C_HASH_SDA_PIN, I2C_HASH_SCL_PIN); + + JobData *job_data = nullptr; + I2cNonceStrideState nonce_state{}; + nonce_state.cursor = 0; + nonce_state.stride = 1; + uint8_t active_job_id = kI2cNoJobId; + + JobI2cResult idle{}; + idle.cmd = I2C_CMD_SLAVE_RESULT; + idle.id = kI2cNoJobId; + idle.nonce = kI2cInvalidNonce; + idle.processed_nonce = 0; + i2c_slave_publish_result(idle); + + uint8_t rx_chunk[96] = {0}; + uint8_t rx_buffer[256] = {0}; + size_t rx_buffer_len = 0; + uint32_t wdt_counter = 0; + uint32_t feed_count = 0; + uint32_t req_count = 0; + uint32_t crc_fail_count = 0; + uint32_t invalid_cmd_count = 0; + uint32_t rx_overflow_count = 0; + uint32_t last_status_ms = millis(); + uint32_t last_master_contact_ms = millis(); + uint32_t last_ready_beacon_ms = 0; + while (1) + { + int rx_len = i2c_slave_read_buffer((i2c_port_t)I2C_HASH_BUS_PORT, rx_chunk, sizeof(rx_chunk), 20 / portTICK_PERIOD_MS); + if (rx_len > 0) + { + if (rx_buffer_len + (size_t)rx_len > sizeof(rx_buffer)) + { + rx_overflow_count++; + rx_buffer_len = 0; + #if I2C_SLAVE_DEBUG + Serial.printf("[I2C-SLAVE] RX overflow len=%d overflow=%u\n", rx_len, (unsigned)rx_overflow_count); + #endif + } + else + { + memcpy(rx_buffer + rx_buffer_len, rx_chunk, (size_t)rx_len); + rx_buffer_len += (size_t)rx_len; + } + + size_t offset = 0; + while (rx_buffer_len - offset >= 2) + { + const uint8_t cmd = rx_buffer[offset]; + size_t frame_len = 0; + if (cmd == I2C_CMD_REQUEST_RESULT) + frame_len = 2; + else if (cmd == I2C_CMD_FEED) + frame_len = sizeof(JobI2cRequest); + else + { + invalid_cmd_count++; + #if I2C_SLAVE_DEBUG + Serial.printf("[I2C-SLAVE] Ignored cmd=0x%02X at offset=%u invalid=%u\n", + (unsigned)cmd, (unsigned)offset, (unsigned)invalid_cmd_count); + #endif + offset += 1; + continue; + } + + if (rx_buffer_len - offset < frame_len) + break; // wait more bytes + + const uint8_t *frame = rx_buffer + offset; + if (i2cCommandCrc8(frame, frame_len) != frame[1]) + { + crc_fail_count++; + #if I2C_SLAVE_DEBUG + Serial.printf("[I2C-SLAVE] CRC error cmd=0x%02X frame_len=%u crc_fail=%u\n", + (unsigned)cmd, (unsigned)frame_len, (unsigned)crc_fail_count); + #endif + offset += 1; // resync stream + continue; + } + + if (cmd == I2C_CMD_FEED) + { + JobI2cRequest request{}; + memcpy(&request, frame, sizeof(request)); + JobData *slot = &s_job_data_pool[s_job_data_index++ % kJobDataPoolSize]; + i2c_slave_prepare_job(request, slot, nonce_state); + job_data = slot; + active_job_id = request.id; + JobI2cResult result = i2c_slave_collect_result(active_job_id, job_data, nonce_state); + i2c_slave_publish_result(result); + feed_count++; + #if I2C_SLAVE_DEBUG + Serial.printf("[I2C-SLAVE] FEED #%u id=%u nonce_start=0x%08lX stride=%lu diff=%.9f\n", + (unsigned)feed_count, (unsigned)request.id, + (unsigned long)request.nonce_start, + (unsigned long)request.nonce_stride, + request.difficulty); + #endif + } + else + { + req_count++; + if (job_data && active_job_id != kI2cNoJobId) + { + JobI2cResult result = i2c_slave_collect_result(active_job_id, job_data, nonce_state); + i2c_slave_publish_result(result); + #if I2C_SLAVE_DEBUG + if (result.processed_nonce > 0 || result.nonce != kI2cInvalidNonce) + { + Serial.printf("[I2C-SLAVE] RESULT req=%u id=%u processed=%u nonce=0x%08lX\n", + (unsigned)req_count, (unsigned)result.id, (unsigned)result.processed_nonce, (unsigned long)result.nonce); + } + #endif + } + else + { + i2c_slave_publish_result(idle); + } + } + + last_master_contact_ms = millis(); + last_ready_beacon_ms = 0; + + offset += frame_len; + } + + if (offset > 0) + { + if (offset < rx_buffer_len) + memmove(rx_buffer, rx_buffer + offset, rx_buffer_len - offset); + rx_buffer_len -= offset; + } + } + else if (job_data && active_job_id != kI2cNoJobId) + { + uint32_t now_ms = millis(); + if ((uint32_t)(now_ms - last_master_contact_ms) >= I2C_SLAVE_LINK_TIMEOUT_MS) + { + Serial.printf("[I2C-SLAVE] Link timeout (%lu ms). Returning to ready mode.\n", + (unsigned long)I2C_SLAVE_LINK_TIMEOUT_MS); + resetMiningQueuesOnly(); + job_data = nullptr; + active_job_id = kI2cNoJobId; + s_current_job_data = nullptr; + s_working_current_job_id = 0xFF; + nonce_state.cursor = 0; + nonce_state.stride = 1; + i2c_slave_publish_result(idle); + last_ready_beacon_ms = now_ms; + if (I2C_SLAVE_IDLE_DELAY_MS > 0) + vTaskDelay(I2C_SLAVE_IDLE_DELAY_MS / portTICK_PERIOD_MS); + else + taskYIELD(); + continue; + } + + i2c_slave_refill_job_queues(job_data, nonce_state); + if (I2C_SLAVE_ACTIVE_DELAY_MS > 0) + vTaskDelay(I2C_SLAVE_ACTIVE_DELAY_MS / portTICK_PERIOD_MS); + else + taskYIELD(); + } + else + { + uint32_t now_ms = millis(); + if (last_ready_beacon_ms == 0 || (uint32_t)(now_ms - last_ready_beacon_ms) >= I2C_SLAVE_READY_BEACON_MS) + { + i2c_slave_publish_result(idle); + last_ready_beacon_ms = now_ms; + } + if (I2C_SLAVE_IDLE_DELAY_MS > 0) + vTaskDelay(I2C_SLAVE_IDLE_DELAY_MS / portTICK_PERIOD_MS); + else + taskYIELD(); + } + + wdt_counter++; + if (wdt_counter >= 8) + { + wdt_counter = 0; + esp_task_wdt_reset(); + } + + #if I2C_SLAVE_DEBUG + uint32_t now_ms = millis(); + if (now_ms - last_status_ms >= 5000) + { + last_status_ms = now_ms; + uint32_t swq = s_job_queue_sw ? uxQueueMessagesWaiting(s_job_queue_sw) : 0; + uint32_t hwq = 0; + #ifdef HARDWARE_SHA265 + hwq = s_job_queue_hw ? uxQueueMessagesWaiting(s_job_queue_hw) : 0; + #endif + Serial.printf("[I2C-SLAVE] status id=%u feeds=%u req=%u crc_fail=%u ovf=%u swq=%u hwq=%u nonce_pool=0x%08lX\n", + (unsigned)active_job_id, + (unsigned)feed_count, + (unsigned)req_count, + (unsigned)crc_fail_count, + (unsigned)rx_overflow_count, + (unsigned)swq, + (unsigned)hwq, + (unsigned long)nonce_state.cursor); + } + #endif + } +} + +#else + +void runI2cSlaveWorker(void *name) +{ + (void)name; + vTaskDelete(nullptr); +} + +#endif + +#if defined(I2C_HASH_MASTER) + +struct I2cMasterJobShared +{ + bool active; + uint8_t job_id; + uint8_t local_nonce_lanes; + uint8_t total_nonce_lanes; + uint32_t full_job_id; + uint32_t nonce_seed; + double difficulty; + uint8_t header76[76]; + uint8_t sha_tail[64]; + uint32_t midstate[8]; + uint32_t bake[16]; + uint32_t generation; +}; + +struct I2cMasterJobSnapshot +{ + uint8_t job_id; + uint8_t local_nonce_lanes; + uint8_t total_nonce_lanes; + uint32_t full_job_id; + uint32_t nonce_seed; + double difficulty; + uint8_t header76[76]; + uint8_t sha_tail[64]; + uint32_t midstate[8]; + uint32_t bake[16]; + uint32_t generation; +}; + +static portMUX_TYPE s_i2c_master_lock = portMUX_INITIALIZER_UNLOCKED; +static I2cMasterJobShared s_i2c_master_job{}; +static volatile uint32_t s_i2c_master_hashes_pending = 0; +static volatile uint8_t s_i2c_master_slave_count = 0; +static volatile bool s_i2c_master_boot_scan_done = false; + +static bool i2c_master_has_workers() +{ + return s_i2c_master_slave_count > 0; +} + +static uint8_t i2c_master_worker_count() +{ + return s_i2c_master_slave_count; +} + +static void i2c_master_add_processed_hashes(uint32_t hashes_done) +{ + if (hashes_done == 0) + return; + taskENTER_CRITICAL(&s_i2c_master_lock); + s_i2c_master_hashes_pending += hashes_done; + taskEXIT_CRITICAL(&s_i2c_master_lock); +} + +static uint32_t i2c_master_take_processed_hashes() +{ + taskENTER_CRITICAL(&s_i2c_master_lock); + uint32_t out = s_i2c_master_hashes_pending; + s_i2c_master_hashes_pending = 0; + taskEXIT_CRITICAL(&s_i2c_master_lock); + return out; +} + +static void i2c_master_set_active_job(uint32_t full_job_id, + double difficulty, + uint32_t nonce_seed, + uint8_t local_nonce_lanes, + uint8_t total_nonce_lanes, + const uint8_t *blockheader, + const uint32_t *midstate, + const uint32_t *bake) +{ + if (blockheader == nullptr || midstate == nullptr || bake == nullptr) + return; + + taskENTER_CRITICAL(&s_i2c_master_lock); + uint32_t next_generation = s_i2c_master_job.generation + 1; + if (next_generation == 0) + next_generation = 1; + s_i2c_master_job.active = true; + s_i2c_master_job.job_id = (uint8_t)(full_job_id & 0xFF); + s_i2c_master_job.local_nonce_lanes = local_nonce_lanes == 0 ? 1 : local_nonce_lanes; + if (total_nonce_lanes < s_i2c_master_job.local_nonce_lanes) + total_nonce_lanes = s_i2c_master_job.local_nonce_lanes; + s_i2c_master_job.total_nonce_lanes = total_nonce_lanes; + s_i2c_master_job.full_job_id = full_job_id; + s_i2c_master_job.nonce_seed = nonce_seed; + s_i2c_master_job.difficulty = difficulty; + memcpy(s_i2c_master_job.header76, blockheader, sizeof(s_i2c_master_job.header76)); + memcpy(s_i2c_master_job.sha_tail, blockheader + 64, sizeof(s_i2c_master_job.sha_tail)); + memcpy(s_i2c_master_job.midstate, midstate, sizeof(s_i2c_master_job.midstate)); + memcpy(s_i2c_master_job.bake, bake, sizeof(s_i2c_master_job.bake)); + s_i2c_master_job.generation = next_generation; + s_i2c_master_hashes_pending = 0; + taskEXIT_CRITICAL(&s_i2c_master_lock); +} + +static void i2c_master_clear_active_job() +{ + taskENTER_CRITICAL(&s_i2c_master_lock); + uint32_t next_generation = s_i2c_master_job.generation + 1; + if (next_generation == 0) + next_generation = 1; + s_i2c_master_job.active = false; + s_i2c_master_job.generation = next_generation; + s_i2c_master_hashes_pending = 0; + taskEXIT_CRITICAL(&s_i2c_master_lock); +} + +static bool i2c_master_read_job_snapshot(I2cMasterJobSnapshot &snapshot) +{ + bool active = false; + taskENTER_CRITICAL(&s_i2c_master_lock); + active = s_i2c_master_job.active; + if (active) + { + snapshot.job_id = s_i2c_master_job.job_id; + snapshot.local_nonce_lanes = s_i2c_master_job.local_nonce_lanes; + snapshot.total_nonce_lanes = s_i2c_master_job.total_nonce_lanes; + snapshot.full_job_id = s_i2c_master_job.full_job_id; + snapshot.nonce_seed = s_i2c_master_job.nonce_seed; + snapshot.difficulty = s_i2c_master_job.difficulty; + memcpy(snapshot.header76, s_i2c_master_job.header76, sizeof(snapshot.header76)); + memcpy(snapshot.sha_tail, s_i2c_master_job.sha_tail, sizeof(snapshot.sha_tail)); + memcpy(snapshot.midstate, s_i2c_master_job.midstate, sizeof(snapshot.midstate)); + memcpy(snapshot.bake, s_i2c_master_job.bake, sizeof(snapshot.bake)); + snapshot.generation = s_i2c_master_job.generation; + } + taskEXIT_CRITICAL(&s_i2c_master_lock); + return active; +} + +static void i2c_master_assign_nonce_starts(const std::vector &slaves, + std::vector &nonce_starts, + uint32_t &nonce_stride, + uint32_t seed, + uint8_t local_nonce_lanes, + uint8_t total_nonce_lanes) +{ + nonce_starts.clear(); + if (slaves.empty()) + { + nonce_stride = 1; + return; + } + + uint32_t local_lanes = local_nonce_lanes == 0 ? 1 : (uint32_t)local_nonce_lanes; + uint32_t total_lanes = total_nonce_lanes; + if (total_lanes <= local_lanes) + total_lanes = local_lanes + (uint32_t)slaves.size(); + nonce_stride = total_lanes; + if (nonce_stride == 0) + nonce_stride = 1; + uint32_t slave_lanes = nonce_stride > local_lanes ? (nonce_stride - local_lanes) : 1; + + nonce_starts.resize(slaves.size(), 0); + for (size_t i = 0; i < slaves.size(); ++i) + { + uint32_t lane = (uint32_t)i; + if (lane >= slave_lanes) + lane %= slave_lanes; + nonce_starts[i] = seed + local_lanes + lane; + } +} + +void runI2cMasterWorker(void *name) +{ + Serial.println(""); + Serial.printf("\n[I2C-MASTER] Started. Running %s on core %d\n", (char *)name, xPortGetCoreID()); + s_i2c_master_boot_scan_done = false; + + std::vector i2c_slave_vector; + std::vector i2c_slave_nonce_starts; + std::vector i2c_harvest_buffer; + uint32_t i2c_slave_nonce_stride = 1; + bool i2c_master_ready = false; + uint32_t i2c_last_scan = 0; + uint32_t last_feed_generation = 0; + uint32_t wdt_counter = 0; + uint8_t slave_miss_polls[128] = {0}; + bool slave_lost_reported[128] = {false}; + uint32_t slave_nonce_cursor[128] = {0}; + bool slave_nonce_cursor_valid[128] = {false}; + bool force_refeed_current_job = false; + bool loss_recovery_pending = false; + uint8_t loss_recovery_attempts = 0; + uint32_t loss_recovery_next_scan = 0; + #if I2C_MASTER_DIAG_LOG + uint32_t diag_last_log_ms = millis(); + uint32_t diag_cycle_count = 0; + uint64_t diag_cycle_total_ms = 0; + uint32_t diag_cycle_max_ms = 0; + uint32_t diag_resp_total = 0; + uint32_t diag_expected_total = 0; + uint32_t diag_empty_cycles = 0; + i2c_master_diag_reset(); + #endif + + auto scan_i2c_workers = [&](bool verbose) + { + if (!i2c_master_ready) + { + int err = i2c_master_start(); + if (err != ESP_OK) + { + s_i2c_master_slave_count = 0; + if (verbose) + Serial.printf("[I2C-MASTER] bus init failed, err=%d\n", err); + return; + } + i2c_master_ready = true; + verbose = true; + } + + std::vector found = i2c_master_scan(0x08, 0x78); + bool changed = (found != i2c_slave_vector); + + i2c_slave_vector = std::move(found); + s_i2c_master_slave_count = (uint8_t)i2c_slave_vector.size(); + i2c_last_scan = millis(); + + if (verbose || changed) + { + Serial.printf("[I2C-MASTER] Found %d slave workers\n", i2c_slave_vector.size()); + if (!i2c_slave_vector.empty()) + { + Serial.print("[I2C-MASTER] Workers: "); + for (size_t n = 0; n < i2c_slave_vector.size(); ++n) + Serial.printf("0x%02X,", (uint32_t)i2c_slave_vector[n]); + Serial.println(""); + } + } + bool present[128] = {false}; + for (size_t n = 0; n < i2c_slave_vector.size(); ++n) + { + present[(uint8_t)i2c_slave_vector[n]] = true; + } + for (uint16_t addr = 0; addr < 128; ++addr) + { + if (!present[addr]) + { + slave_miss_polls[addr] = 0; + slave_lost_reported[addr] = false; + } + } + if (changed) + { + i2c_slave_nonce_starts.clear(); + i2c_slave_nonce_stride = 1; + force_refeed_current_job = true; + } + }; + + auto has_lost_worker = [&]() -> bool + { + for (size_t i = 0; i < i2c_slave_vector.size(); ++i) + { + if (slave_lost_reported[(uint8_t)i2c_slave_vector[i]]) + return true; + } + return false; + }; + + uint32_t boot_scan_rounds = I2C_BOOT_SCAN_ROUNDS; + if (boot_scan_rounds == 0) + boot_scan_rounds = 1; + for (uint32_t round = 0; round < boot_scan_rounds; ++round) + { + Serial.printf("[I2C-MASTER] Boot scan %u/%u\n", (unsigned)(round + 1), (unsigned)boot_scan_rounds); + scan_i2c_workers(round == 0 || round + 1 == boot_scan_rounds); + if (round + 1 < boot_scan_rounds && I2C_BOOT_SCAN_DELAY_MS > 0) + vTaskDelay(I2C_BOOT_SCAN_DELAY_MS / portTICK_PERIOD_MS); + } + s_i2c_master_boot_scan_done = true; + Serial.println("[I2C-MASTER] Boot scan complete."); + + while (1) + { + #if (I2C_RUNTIME_RESCAN_MS > 0) + { + uint32_t now_scan = millis(); + if (now_scan < i2c_last_scan || (now_scan - i2c_last_scan >= I2C_RUNTIME_RESCAN_MS)) + { + scan_i2c_workers(i2c_slave_vector.empty()); + } + } + #endif + + if (loss_recovery_pending && I2C_LOSS_RESCAN_MAX_ATTEMPTS > 0) + { + uint32_t now_scan = millis(); + bool due = (loss_recovery_next_scan == 0) || ((uint32_t)(now_scan - loss_recovery_next_scan) < 0x80000000u); + if (due) + { + loss_recovery_attempts++; + Serial.printf("[I2C-MASTER] Loss recovery rescan attempt %u/%u\n", + (unsigned)loss_recovery_attempts, + (unsigned)I2C_LOSS_RESCAN_MAX_ATTEMPTS); + scan_i2c_workers(true); + if (!has_lost_worker()) + { + Serial.println("[I2C-MASTER] Loss recovery: topology stabilized."); + loss_recovery_pending = false; + loss_recovery_attempts = 0; + loss_recovery_next_scan = 0; + } + else if (loss_recovery_attempts >= I2C_LOSS_RESCAN_MAX_ATTEMPTS) + { + Serial.println("[I2C-MASTER] Loss recovery: max attempts reached, stopping rescans."); + loss_recovery_pending = false; + } + else + { + loss_recovery_next_scan = now_scan + I2C_LOSS_RESCAN_INTERVAL_MS; + } + } + } + + I2cMasterJobSnapshot job{}; + bool has_job = i2c_master_read_job_snapshot(job); + if (has_job && job.generation != last_feed_generation) + { + memset(slave_nonce_cursor_valid, 0, sizeof(slave_nonce_cursor_valid)); + } + + if (has_job && !i2c_slave_vector.empty()) + { + if (job.generation != last_feed_generation || force_refeed_current_job) + { + i2c_master_assign_nonce_starts(i2c_slave_vector, + i2c_slave_nonce_starts, + i2c_slave_nonce_stride, + job.nonce_seed, + job.local_nonce_lanes, + job.total_nonce_lanes); + for (size_t i = 0; i < i2c_slave_vector.size(); ++i) + { + uint8_t addr = i2c_slave_vector[i]; + if (slave_nonce_cursor_valid[addr]) + { + i2c_slave_nonce_starts[i] = slave_nonce_cursor[addr]; + } + else + { + slave_nonce_cursor[addr] = i2c_slave_nonce_starts[i]; + slave_nonce_cursor_valid[addr] = true; + } + } + i2c_feed_slaves(i2c_slave_vector, job.job_id, i2c_slave_nonce_starts, i2c_slave_nonce_stride, (float)job.difficulty, job.header76); + #if I2C_REBALANCE_DEBUG + Serial.printf("[I2C-MASTER] Stride starts (stride=%lu, local=%u): ", + (unsigned long)i2c_slave_nonce_stride, + (unsigned)job.local_nonce_lanes); + for (size_t i = 0; i < i2c_slave_vector.size(); ++i) + { + uint32_t start = (i < i2c_slave_nonce_starts.size()) ? i2c_slave_nonce_starts[i] : 0; + Serial.printf("0x%02X=>0x%08lX ", (uint32_t)i2c_slave_vector[i], (unsigned long)start); + } + Serial.println(""); + #endif + last_feed_generation = job.generation; + force_refeed_current_job = false; + } + + uint32_t time_start = millis(); + i2c_hit_slaves(i2c_slave_vector); + if (I2C_MASTER_POST_HIT_DELAY_MS > 0) + vTaskDelay(I2C_MASTER_POST_HIT_DELAY_MS / portTICK_PERIOD_MS); + i2c_harvest_slaves(i2c_slave_vector, job.job_id, i2c_harvest_buffer); + uint32_t time_end = millis(); -static std::mutex s_job_mutex; -std::list> s_job_request_list_sw; -#ifdef HARDWARE_SHA265 -std::list> s_job_request_list_hw; -#endif -std::list> s_job_result_list; -static volatile uint8_t s_working_current_job_id = 0xFF; + bool responded[128] = {false}; + for (size_t i = 0; i < i2c_harvest_buffer.size(); ++i) + { + responded[(uint8_t)i2c_harvest_buffer[i].address] = true; + } + for (size_t i = 0; i < i2c_slave_vector.size(); ++i) + { + uint8_t addr = i2c_slave_vector[i]; + if (responded[addr]) + { + if (slave_lost_reported[addr]) + { + Serial.printf("[I2C-MASTER] Slave 0x%02X recovered after %u missed polls\n", + (unsigned)addr, + (unsigned)slave_miss_polls[addr]); + } + slave_miss_polls[addr] = 0; + slave_lost_reported[addr] = false; + } + else + { + if (slave_miss_polls[addr] < 255) + slave_miss_polls[addr]++; + if (!slave_lost_reported[addr] && slave_miss_polls[addr] >= I2C_SLAVE_LOSS_POLL_THRESHOLD) + { + Serial.printf("[I2C-MASTER] WARN slave 0x%02X no response for %u polls (possible disconnect)\n", + (unsigned)addr, + (unsigned)slave_miss_polls[addr]); + slave_lost_reported[addr] = true; + if (I2C_LOSS_RESCAN_MAX_ATTEMPTS > 0 && !loss_recovery_pending) + { + loss_recovery_pending = true; + loss_recovery_attempts = 0; + loss_recovery_next_scan = 0; + } + } + } + } -static void JobPush(std::list> &job_list, uint32_t id, uint32_t nonce_start, uint32_t nonce_count, double difficulty, - const uint8_t* sha_buffer, const uint32_t* midstate, const uint32_t* bake) -{ - std::shared_ptr job = std::make_shared(); - job->id = id; - job->nonce_start = nonce_start; - job->nonce_count = nonce_count; - job->difficulty = difficulty; - memcpy(job->sha_buffer, sha_buffer, sizeof(job->sha_buffer)); - memcpy(job->midstate, midstate, sizeof(job->midstate)); - memcpy(job->bake, bake, sizeof(job->bake)); - job_list.push_back(job); -} + uint32_t nonces_done = 0; + for (size_t i = 0; i < i2c_harvest_buffer.size(); ++i) + { + const I2cSlaveHarvest &item = i2c_harvest_buffer[i]; + nonces_done += item.processed_nonce; + if (slave_nonce_cursor_valid[item.address]) + { + slave_nonce_cursor[item.address] = nonce_stride_advance_u32(slave_nonce_cursor[item.address], + i2c_slave_nonce_stride, + item.processed_nonce); + } + if (s_result_queue && item.has_nonce) + { + JobResult result{}; + if (nerd_sha256d_baked_nonce(job.midstate, item.nonce, job.bake, result.hash)) + { + result.id = job.full_job_id; + result.nonce = item.nonce; + result.nonce_count = 0; + result.difficulty = diff_from_target(result.hash); + xQueueSend(s_result_queue, &result, 0); + } + } + } + i2c_master_add_processed_hashes(nonces_done); + uint32_t elapsed = 0; + if (time_end > time_start) + elapsed = time_end - time_start; + + #if I2C_MASTER_DIAG_LOG + diag_cycle_count++; + diag_cycle_total_ms += elapsed; + if (elapsed > diag_cycle_max_ms) + diag_cycle_max_ms = elapsed; + diag_resp_total += (uint32_t)i2c_harvest_buffer.size(); + diag_expected_total += (uint32_t)i2c_slave_vector.size(); + if (i2c_harvest_buffer.empty()) + diag_empty_cycles++; + if (I2C_MASTER_DIAG_WARN_CYCLE_MS > 0 && elapsed >= I2C_MASTER_DIAG_WARN_CYCLE_MS) + { + Serial.printf("[I2C-MASTER][diag] Slow cycle %lu ms, responded %u/%u\n", + (unsigned long)elapsed, + (unsigned)i2c_harvest_buffer.size(), + (unsigned)i2c_slave_vector.size()); + } + #endif -struct Submition -{ - double diff; - bool is32bit; - bool isValid; -}; + if (time_end > time_start) + { + if (I2C_MASTER_CYCLE_MS > 0 && elapsed < I2C_MASTER_CYCLE_MS) + vTaskDelay((I2C_MASTER_CYCLE_MS - elapsed) / portTICK_PERIOD_MS); + } + else if (I2C_MASTER_CYCLE_MS > 0) + { + vTaskDelay(I2C_MASTER_CYCLE_MS / portTICK_PERIOD_MS); + } + } + else + { + if (I2C_MASTER_IDLE_MS > 0) + vTaskDelay(I2C_MASTER_IDLE_MS / portTICK_PERIOD_MS); + else + vTaskDelay(1); + } -static void MiningJobStop(uint32_t &job_pool, std::map> & submition_map) -{ - { - std::lock_guard lock(s_job_mutex); - s_job_result_list.clear(); - s_job_request_list_sw.clear(); - #ifdef HARDWARE_SHA265 - s_job_request_list_hw.clear(); + #if I2C_MASTER_DIAG_LOG + uint32_t now_diag_ms = millis(); + if ((uint32_t)(now_diag_ms - diag_last_log_ms) >= I2C_MASTER_DIAG_LOG_MS) + { + I2cMasterDiagSnapshot diag{}; + i2c_master_diag_snapshot(diag); + const uint32_t cycle_avg_ms = (diag_cycle_count > 0) ? (uint32_t)(diag_cycle_total_ms / diag_cycle_count) : 0; + const uint32_t resp_x10 = (diag_expected_total > 0) ? (uint32_t)(((uint64_t)diag_resp_total * 1000ULL) / (uint64_t)diag_expected_total) : 0; + + Serial.printf("[I2C-MASTER][diag] cycle avg/max=%lu/%lu ms, resp=%lu/%lu (%lu.%lu%%), empty=%lu, " + "feed ok/err=%lu/%lu, hit ok/err=%lu/%lu, rx ok/err=%lu/%lu, crc=%lu, cmd=%lu, id=%lu, max_rx=%lu ms, stales=%lu\n", + (unsigned long)cycle_avg_ms, + (unsigned long)diag_cycle_max_ms, + (unsigned long)diag_resp_total, + (unsigned long)diag_expected_total, + (unsigned long)(resp_x10 / 10), + (unsigned long)(resp_x10 % 10), + (unsigned long)diag_empty_cycles, + (unsigned long)diag.feed_tx_ok, + (unsigned long)diag.feed_tx_err, + (unsigned long)diag.hit_tx_ok, + (unsigned long)diag.hit_tx_err, + (unsigned long)diag.harvest_rx_ok, + (unsigned long)diag.harvest_rx_err, + (unsigned long)diag.harvest_crc_err, + (unsigned long)diag.harvest_cmd_err, + (unsigned long)diag.harvest_id_err, + (unsigned long)diag.max_rx_ms, + (unsigned long)stales); + if (diag.last_err != 0) + { + Serial.printf("[I2C-MASTER][diag] last i2c err=%ld at 0x%02X (%lu ms ago)\n", + (long)diag.last_err, + (unsigned)diag.last_err_addr, + (unsigned long)((uint32_t)(now_diag_ms - diag.last_err_ms))); + } + i2c_master_diag_reset(); + diag_cycle_count = 0; + diag_cycle_total_ms = 0; + diag_cycle_max_ms = 0; + diag_resp_total = 0; + diag_expected_total = 0; + diag_empty_cycles = 0; + diag_last_log_ms = now_diag_ms; + } #endif - } - s_working_current_job_id = 0xFF; - job_pool = 0xFFFFFFFF; - submition_map.clear(); -} -#ifdef RANDOM_NONCE -uint64_t s_random_state = 1; -static uint32_t RandomGet() -{ - s_random_state += 0x9E3779B97F4A7C15ull; - uint64_t z = s_random_state; - z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9ull; - z = (z ^ (z >> 27)) * 0x94D049BB133111EBull; - return z ^ (z >> 31); + wdt_counter++; + if (wdt_counter >= 8) + { + wdt_counter = 0; + esp_task_wdt_reset(); + } + } } #endif @@ -223,49 +1783,117 @@ void runStratumWorker(void *name) { Serial.println(""); Serial.printf("\n[WORKER] Started. Running %s on core %d\n", (char *)name, xPortGetCoreID()); + initMiningQueues(); + #ifdef DEBUG_MEMORY Serial.printf("### [Total Heap / Free heap / Min free heap]: %d / %d / %d \n", ESP.getHeapSize(), ESP.getFreeHeap(), ESP.getMinFreeHeap()); #endif - std::map> s_submition_map; + SubmissionTracker s_submission_tracker{}; + submissionTrackerClear(s_submission_tracker); -#ifdef I2C_SLAVE - std::vector i2c_slave_vector; - - //scan for i2c slaves - if (i2c_master_start() == 0) - i2c_slave_vector = i2c_master_scan(0x0, 0x80); - Serial.printf("Found %d slave workers\n", i2c_slave_vector.size()); - if (!i2c_slave_vector.empty()) +#ifdef I2C_HASH_MASTER + static bool s_i2c_master_task_started = false; + if (!s_i2c_master_task_started) { - Serial.print(" Workers: "); - for (size_t n = 0; n < i2c_slave_vector.size(); ++n) - Serial.printf("0x%02X,", (uint32_t)i2c_slave_vector[n]); - Serial.println(""); + BaseType_t res = xTaskCreatePinnedToCore(runI2cMasterWorker, "I2C-Master", 7000, (void *)"(I2C-Master)", 3, nullptr, 0); + if (res == pdPASS) + { + s_i2c_master_task_started = true; + } + else + { + Serial.println("[I2C-MASTER] Failed to start worker task"); + } + } + if (s_i2c_master_task_started) + { + Serial.println("[I2C-MASTER] Waiting boot scan before starting stratum..."); + while (!s_i2c_master_boot_scan_done) + vTaskDelay(20 / portTICK_PERIOD_MS); + Serial.println("[I2C-MASTER] Boot scan finished. Continuing stratum startup."); } #endif // connect to pool double currentPoolDifficulty = DEFAULT_DIFFICULTY; uint32_t nonce_pool = 0; + bool use_partitioned_nonce_ranges = false; +#ifdef HARDWARE_SHA265 + constexpr uint8_t local_nonce_lanes = 2; +#else + constexpr uint8_t local_nonce_lanes = 1; +#endif + uint8_t current_total_nonce_lanes = local_nonce_lanes; + uint32_t sw_nonce_cursor = 0; + uint32_t sw_nonce_stride = 1; +#ifdef HARDWARE_SHA265 + uint32_t hw_nonce_cursor = 0; + uint32_t hw_nonce_stride = 1; +#endif uint32_t job_pool = 0xFFFFFFFF; uint32_t last_job_time = millis(); + uint32_t hw_midstate[8] = {0}; + uint32_t diget_mid[8] = {0}; + uint32_t bake[16] = {0}; + #if defined(CONFIG_IDF_TARGET_ESP32) + uint8_t sha_buffer_swap[128] = {0}; + #endif + static StaticJsonDocument stratum_doc; + static char stratum_line_buffer[kStratumLineBufferSize]; + static size_t stratum_line_len = 0; + static bool stratum_line_overflow = false; + + auto resetStratumLineState = [&]() + { + stratum_line_len = 0; + stratum_line_overflow = false; + }; + + auto isDuplicateNotify = [&](const mining_job &incoming) -> bool + { + if (job_pool == 0xFFFFFFFF) + return false; + return (strcmp(mJob.job_id, incoming.job_id) == 0) && + (strcmp(mJob.ntime, incoming.ntime) == 0) && + (strcmp(mJob.prev_block_hash, incoming.prev_block_hash) == 0); + }; while(true) { - if(WiFi.status() != WL_CONNECTED){ - // WiFi is disconnected, so reconnect now + wl_status_t wifi_status = WiFi.status(); + if(wifi_status != WL_CONNECTED){ + // WiFi is disconnected. mMonitor.NerdStatus = NM_Connecting; - MiningJobStop(job_pool, s_submition_map); - WiFi.reconnect(); + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); + static uint32_t last_wifi_reconnect = 0; + uint32_t now = millis(); + if (now < last_wifi_reconnect) // wrap + last_wifi_reconnect = 0; + // Keep auto reconnect in control; force reconnect only if stuck for a while. + bool allow_force_reconnect = + (wifi_status == WL_DISCONNECTED) || + (wifi_status == WL_CONNECTION_LOST) || + (wifi_status == WL_CONNECT_FAILED) || + (wifi_status == WL_NO_SSID_AVAIL); + if (allow_force_reconnect && now - last_wifi_reconnect >= WIFI_FORCE_RECONNECT_INTERVAL_MS) + { + WiFi.reconnect(); + last_wifi_reconnect = now; + } vTaskDelay(5000 / portTICK_PERIOD_MS); continue; } + if (!client.connected()) + resetStratumLineState(); + if(!checkPoolConnection()){ //If server is not reachable add random delay for connection retries //Generate value between 1 and 60 secs - MiningJobStop(job_pool, s_submition_map); + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); vTaskDelay(((1 + rand() % 60) * 1000) / portTICK_PERIOD_MS); continue; } @@ -276,34 +1904,60 @@ void runStratumWorker(void *name) { mWorker = init_mining_subscribe(); // STEP 1: Pool server connection (SUBSCRIBE) - if(!tx_mining_subscribe(client, mWorker)) { - client.stop(); - MiningJobStop(job_pool, s_submition_map); - continue; + bool resume_attempt = s_resume_subscribe_enabled && s_last_subscribe_session_id.length() > 0; + if(!tx_mining_subscribe(client, mWorker, resume_attempt ? s_last_subscribe_session_id.c_str() : nullptr)) { + if (resume_attempt) + { + Serial.println("[WORKER] Resume subscribe failed, trying fresh subscribe"); + s_resume_subscribe_enabled = false; + if (!tx_mining_subscribe(client, mWorker, nullptr)) + { + client.stop(); + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); + continue; + } + } + else + { + client.stop(); + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); + continue; + } } + s_last_subscribe_session_id = mWorker.sub_details; + mLastRXfromPool = millis(); - strcpy(mWorker.wName, Settings.BtcWallet); - strcpy(mWorker.wPass, Settings.PoolPassword); + copyCString(mWorker.wName, sizeof(mWorker.wName), Settings.BtcWallet); + copyCString(mWorker.wPass, sizeof(mWorker.wPass), Settings.PoolPassword); + if (strlen(Settings.PoolPassword) >= sizeof(mWorker.wPass)) + { + Serial.printf("[WORKER] Pool password truncated to %u chars\n", (unsigned)(sizeof(mWorker.wPass) - 1)); + } // STEP 2: Pool authorize work (Block Info) tx_mining_auth(client, mWorker.wName, mWorker.wPass); //Don't verifies authoritzation, TODO //tx_mining_auth2(client, mWorker.wName, mWorker.wPass); //Don't verifies authoritzation, TODO // STEP 3: Suggest pool difficulty - tx_suggest_difficulty(client, currentPoolDifficulty); + tx_suggest_difficulty(client, calculateSuggestedDifficulty()); isMinerSuscribed=true; uint32_t time_now = millis(); mLastTXtoPool = time_now; last_job_time = time_now; + resetStratumLineState(); } - //Check if pool is down for almost 5minutes and then restart connection with pool (1min=600000ms) - if(checkPoolInactivity(KEEPALIVE_TIME_ms, POOLINACTIVITY_TIME_ms)){ + // Reconnect if pool stops sending data beyond configured inactivity window. + if(checkPoolInactivity(KEEPALIVE_TIME_ms, POOLINACTIVITY_TIME_ms, currentPoolDifficulty)){ //Restart connection - Serial.println(" Detected more than 2 min without data form stratum server. Closing socket and reopening..."); + Serial.printf(" Detected more than %lu s without data from stratum server. Closing socket and reopening...\n", + POOLINACTIVITY_TIME_ms / 1000UL); client.stop(); isMinerSuscribed=false; - MiningJobStop(job_pool, s_submition_map); + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); continue; } @@ -315,39 +1969,76 @@ void runStratumWorker(void *name) { { client.stop(); isMinerSuscribed=false; - MiningJobStop(job_pool, s_submition_map); + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); continue; } } - uint32_t hw_midstate[8]; - uint32_t diget_mid[8]; - uint32_t bake[16]; - #if defined(CONFIG_IDF_TARGET_ESP32) - uint8_t sha_buffer_swap[128]; - #endif + bool processed_pool_message = false; - //Read pending messages from pool + // Read pending messages from pool (single JSON parse per line). while(client.connected() && client.available()) { - String line = client.readStringUntil('\n'); - //Serial.println(" Received message from pool"); - stratum_method result = parse_mining_method(line); + int ch = client.read(); + if (ch < 0) + break; + if (ch == '\r') + continue; + if (ch != '\n') + { + if (stratum_line_overflow) + continue; + if (stratum_line_len + 1 < kStratumLineBufferSize) + stratum_line_buffer[stratum_line_len++] = (char)ch; + else + stratum_line_overflow = true; + continue; + } + + if (stratum_line_overflow) + { + resetStratumLineState(); + continue; + } + if (!stratumLineHasContent(stratum_line_buffer, stratum_line_len)) + { + stratum_line_len = 0; + continue; + } + + processed_pool_message = true; + mLastRXfromPool = millis(); + stratum_doc.clear(); + DeserializationError parse_error = deserializeJson(stratum_doc, stratum_line_buffer, stratum_line_len); + stratum_line_len = 0; + bool doc_valid = (parse_error == DeserializationError::Ok); + stratum_method result = STRATUM_PARSE_ERROR; + if (doc_valid) + result = parse_mining_method_doc(stratum_doc); + switch (result) { - case MINING_NOTIFY: if(parse_mining_notify(line, mJob)) - { + case MINING_NOTIFY: { + mining_job next_job{}; + if(parse_mining_notify_doc(stratum_doc, next_job)) + { + if (isDuplicateNotify(next_job)) { - std::lock_guard lock(s_job_mutex); - s_job_request_list_sw.clear(); - #ifdef HARDWARE_SHA265 - s_job_request_list_hw.clear(); - #endif + last_job_time = millis(); + break; } + + mJob = next_job; + if (mJob.clean_jobs || job_pool == 0xFFFFFFFF) + resetMiningQueuesOnly(); + else if (s_result_queue) + xQueueReset(s_result_queue); + //Increse templates readed templates++; job_pool++; - s_working_current_job_id = job_pool & 0xFF; //Terminate current job in thread + s_working_current_job_id = job_pool & 0xFF; last_job_time = millis(); mLastTXtoPool = last_job_time; @@ -381,203 +2072,277 @@ void runStratumWorker(void *name) { ((uint32_t*)sha_buffer_swap)[i] = __builtin_bswap32(((const uint32_t*)(mMiner.bytearray_blockheader))[i]); #endif + uint32_t nonce_seed = 0; #ifdef RANDOM_NONCE - nonce_pool = RandomGet() & RANDOM_NONCE_MASK; + nonce_seed = RandomGet() & RANDOM_NONCE_MASK; #else - #ifdef I2C_SLAVE - if (!i2c_slave_vector.empty()) - nonce_pool = 0x10000000; + const uint32_t mac_offset = mac_nonce_offset() & 0x0FFFFFFF; + #ifdef I2C_HASH_MASTER + if (i2c_master_has_workers()) + nonce_seed = 0x10000000 + mac_offset; else #endif - nonce_pool = 0xDA54E700; //nonce 0x00000000 is not possible, start from some random nonce + nonce_seed = 0xDA54E700 + mac_offset; //nonce 0x00000000 is not possible, start from some random nonce + #endif + nonce_pool = nonce_seed; + use_partitioned_nonce_ranges = false; + current_total_nonce_lanes = local_nonce_lanes; + sw_nonce_cursor = nonce_seed; + sw_nonce_stride = 1; + #ifdef HARDWARE_SHA265 + hw_nonce_cursor = nonce_seed + 1; + hw_nonce_stride = 1; + #endif + #ifdef I2C_HASH_MASTER + uint8_t active_slave_count = i2c_master_worker_count(); + if (active_slave_count > 0) + { + uint32_t total_stride = (uint32_t)local_nonce_lanes + (uint32_t)active_slave_count; + if (total_stride == 0) + total_stride = 1; + if (total_stride > 255) + total_stride = 255; + use_partitioned_nonce_ranges = true; + current_total_nonce_lanes = (uint8_t)total_stride; + sw_nonce_cursor = nonce_seed; + sw_nonce_stride = total_stride; + #ifdef HARDWARE_SHA265 + hw_nonce_cursor = nonce_seed + 1; + hw_nonce_stride = total_stride; + #endif + } #endif + JobData *job_data = &s_job_data_pool[s_job_data_index++ % kJobDataPoolSize]; + job_data->id = job_pool; + job_data->difficulty = currentPoolDifficulty; + poolTargetFromDifficulty(job_data->difficulty, job_data->pool_target_le); + memcpy(job_data->sha_buffer_sw, mMiner.bytearray_blockheader, sizeof(job_data->sha_buffer_sw)); + #if defined(CONFIG_IDF_TARGET_ESP32) + memcpy(job_data->sha_buffer_hw, sha_buffer_swap, sizeof(job_data->sha_buffer_hw)); + #else + memcpy(job_data->sha_buffer_hw, mMiner.bytearray_blockheader, sizeof(job_data->sha_buffer_hw)); + #endif + memcpy(job_data->midstate, diget_mid, sizeof(job_data->midstate)); + memcpy(job_data->bake, bake, sizeof(job_data->bake)); + #ifdef HARDWARE_SHA265 + memcpy(job_data->hw_midstate, hw_midstate, sizeof(job_data->hw_midstate)); + #else + memset(job_data->hw_midstate, 0, sizeof(job_data->hw_midstate)); + #endif + s_current_job_data = job_data; + + const uint32_t sw_nonce_count = calc_nonce_per_job_sw(); + #ifdef HARDWARE_SHA265 + const uint32_t hw_nonce_count = calc_nonce_per_job_hw(); + #endif + for (uint32_t i = 0; i < kJobQueueTargetDepth; ++i) { - std::lock_guard lock(s_job_mutex); - for (int i = 0; i < 4; ++ i) + if (use_partitioned_nonce_ranges) { - #if 1 - JobPush( s_job_request_list_sw, job_pool, nonce_pool, NONCE_PER_JOB_SW, currentPoolDifficulty, mMiner.bytearray_blockheader, diget_mid, bake); - #ifdef RANDOM_NONCE - nonce_pool = RandomGet() & RANDOM_NONCE_MASK; - #else - nonce_pool += NONCE_PER_JOB_SW; - #endif - #endif + JobPush(s_job_queue_sw, job_data, sw_nonce_cursor, sw_nonce_count, sw_nonce_stride); + sw_nonce_cursor = nonce_stride_advance_u32(sw_nonce_cursor, sw_nonce_stride, sw_nonce_count); #ifdef HARDWARE_SHA265 - #if defined(CONFIG_IDF_TARGET_ESP32) - JobPush( s_job_request_list_hw, job_pool, nonce_pool, NONCE_PER_JOB_HW, currentPoolDifficulty, sha_buffer_swap, hw_midstate, bake); - #else - JobPush( s_job_request_list_hw, job_pool, nonce_pool, NONCE_PER_JOB_HW, currentPoolDifficulty, mMiner.bytearray_blockheader, hw_midstate, bake); - #endif - #ifdef RANDOM_NONCE - nonce_pool = RandomGet() & RANDOM_NONCE_MASK; - #else - nonce_pool += NONCE_PER_JOB_HW; + JobPush(s_job_queue_hw, job_data, hw_nonce_cursor, hw_nonce_count, hw_nonce_stride); + hw_nonce_cursor = nonce_stride_advance_u32(hw_nonce_cursor, hw_nonce_stride, hw_nonce_count); #endif + } + else + { + JobPush(s_job_queue_sw, job_data, nonce_pool, sw_nonce_count); + nonce_pool += sw_nonce_count; + #ifdef HARDWARE_SHA265 + JobPush(s_job_queue_hw, job_data, nonce_pool, hw_nonce_count); + nonce_pool += hw_nonce_count; #endif } } - #ifdef I2C_SLAVE - //Nonce for nonce_pool starts from 0x10000000 - //For i2c slave we give nonces from 0x20000000, that is 0x10000000 nonces per slave - i2c_feed_slaves(i2c_slave_vector, job_pool & 0xFF, 0x20, currentPoolDifficulty, mMiner.bytearray_blockheader); + #ifdef I2C_HASH_MASTER + i2c_master_set_active_job(job_pool, + currentPoolDifficulty, + nonce_seed, + local_nonce_lanes, + current_total_nonce_lanes, + mMiner.bytearray_blockheader, + diget_mid, + bake); #endif - } else - { - Serial.println("Parsing error, need restart"); - client.stop(); - isMinerSuscribed=false; - MiningJobStop(job_pool, s_submition_map); + } else + { + Serial.println("Parsing error, need restart"); + client.stop(); + isMinerSuscribed=false; + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); + } } break; - case MINING_SET_DIFFICULTY: parse_mining_set_difficulty(line, currentPoolDifficulty); + case MINING_SET_DIFFICULTY: parse_mining_set_difficulty_doc(stratum_doc, currentPoolDifficulty); break; case STRATUM_SUCCESS: { - unsigned long id = parse_extract_id(line); - auto itt = s_submition_map.find(id); - if (itt != s_submition_map.end()) + unsigned long id = parse_extract_id_doc(stratum_doc); + SubmissionState sub{}; + if (submissionTrackerTake(s_submission_tracker, id, sub)) { - if (itt->second->diff > best_diff) - best_diff = itt->second->diff; - if (itt->second->is32bit) + if (sub.diff > best_diff) + best_diff = sub.diff; + if (sub.is32bit) shares++; - if (itt->second->isValid) + if (sub.isValid) { Serial.println("CONGRATULATIONS! Valid block found"); valids++; } - s_submition_map.erase(itt); } } break; case STRATUM_PARSE_ERROR: { - unsigned long id = parse_extract_id(line); - auto itt = s_submition_map.find(id); - if (itt != s_submition_map.end()) + unsigned long id = doc_valid ? parse_extract_id_doc(stratum_doc) : 0; + if (doc_valid && is_stale_error_doc(stratum_doc)) + stales++; + SubmissionState removed{}; + if (submissionTrackerTake(s_submission_tracker, id, removed)) { Serial.printf("Refuse submition %d\n", id); - s_submition_map.erase(itt); } } break; - default: Serial.println(" Parsed JSON: unknown"); break; + default: + #ifdef DEBUG_MINING + Serial.println(" Parsed JSON: unknown"); + #endif + break; } } - std::list> job_result_list; - #ifdef I2C_SLAVE - if (i2c_slave_vector.empty() || job_pool == 0xFFFFFFFF) - { - vTaskDelay(50 / portTICK_PERIOD_MS); //Small delay - } else - { - uint32_t time_start = millis(); - i2c_hit_slaves(i2c_slave_vector); - vTaskDelay(5 / portTICK_PERIOD_MS); - uint32_t nonces_done = 0; - std::vector nonce_vector = i2c_harvest_slaves(i2c_slave_vector, job_pool & 0xFF, nonces_done); - hashes += nonces_done; - for (size_t n = 0; n < nonce_vector.size(); ++n) - { - std::shared_ptr result = std::make_shared(); - ((uint32_t*)(mMiner.bytearray_blockheader+64+12))[0] = nonce_vector[n]; - if (nerd_sha256d_baked(diget_mid, mMiner.bytearray_blockheader+64, bake, result->hash)) - { - result->id = job_pool; - result->nonce = nonce_vector[n]; - result->nonce_count = 0; - result->difficulty = diff_from_target(result->hash); - job_result_list.push_back(result); - } - } - uint32_t time_end = millis(); - //if (nonces_done > 16384) - //Serial.printf("Harvest slaves in %dms hashes=%d\n", time_end - time_start, nonces_done); - if (time_end > time_start) - { - uint32_t elapsed = time_end - time_start; - if (elapsed < 50) - vTaskDelay((50 - elapsed) / portTICK_PERIOD_MS); - } else - vTaskDelay(40 / portTICK_PERIOD_MS); - } - #else - vTaskDelay(50 / portTICK_PERIOD_MS); //Small delay - #endif + static JobResult job_results[kJobResultsMax]; + size_t job_results_count = 0; - if (job_pool != 0xFFFFFFFF) { - std::lock_guard lock(s_job_mutex); - job_result_list.insert(job_result_list.end(), s_job_result_list.begin(), s_job_result_list.end()); - s_job_result_list.clear(); - -#if 1 - while (s_job_request_list_sw.size() < 4) + hashes += mining_take_local_processed_hashes(); + #ifdef I2C_HASH_MASTER + hashes += i2c_master_take_processed_hashes(); + #endif + if (s_result_queue) { - JobPush( s_job_request_list_sw, job_pool, nonce_pool, NONCE_PER_JOB_SW, currentPoolDifficulty, mMiner.bytearray_blockheader, diget_mid, bake); - #ifdef RANDOM_NONCE - nonce_pool = RandomGet() & RANDOM_NONCE_MASK; - #else - nonce_pool += NONCE_PER_JOB_SW; - #endif + JobResult res{}; + while (job_results_count < kJobResultsMax && xQueueReceive(s_result_queue, &res, 0) == pdTRUE) + { + job_results[job_results_count++] = res; + } } -#endif - #ifdef HARDWARE_SHA265 - while (s_job_request_list_hw.size() < 4) + const uint32_t sw_nonce_count = calc_nonce_per_job_sw(); + JobData *job_data = s_current_job_data; + if (job_data) { - #if defined(CONFIG_IDF_TARGET_ESP32) - JobPush( s_job_request_list_hw, job_pool, nonce_pool, NONCE_PER_JOB_HW, currentPoolDifficulty, sha_buffer_swap, hw_midstate, bake); - #else - JobPush( s_job_request_list_hw, job_pool, nonce_pool, NONCE_PER_JOB_HW, currentPoolDifficulty, mMiner.bytearray_blockheader, hw_midstate, bake); - #endif - #ifdef RANDOM_NONCE - nonce_pool = RandomGet() & RANDOM_NONCE_MASK; - #else - nonce_pool += NONCE_PER_JOB_HW; + while (s_job_queue_sw && uxQueueMessagesWaiting(s_job_queue_sw) < kJobQueueTargetDepth) + { + bool pushed = false; + if (use_partitioned_nonce_ranges) + { + pushed = JobPush(s_job_queue_sw, job_data, sw_nonce_cursor, sw_nonce_count, sw_nonce_stride); + if (pushed) + sw_nonce_cursor = nonce_stride_advance_u32(sw_nonce_cursor, sw_nonce_stride, sw_nonce_count); + } + else + { + pushed = JobPush(s_job_queue_sw, job_data, nonce_pool, sw_nonce_count); + if (pushed) + nonce_pool += sw_nonce_count; + } + if (!pushed) + break; + } + #ifdef HARDWARE_SHA265 + const uint32_t hw_nonce_count = calc_nonce_per_job_hw(); + while (s_job_queue_hw && uxQueueMessagesWaiting(s_job_queue_hw) < kJobQueueTargetDepth) + { + bool pushed = false; + if (use_partitioned_nonce_ranges) + { + pushed = JobPush(s_job_queue_hw, job_data, hw_nonce_cursor, hw_nonce_count, hw_nonce_stride); + if (pushed) + hw_nonce_cursor = nonce_stride_advance_u32(hw_nonce_cursor, hw_nonce_stride, hw_nonce_count); + } + else + { + pushed = JobPush(s_job_queue_hw, job_data, nonce_pool, hw_nonce_count); + if (pushed) + nonce_pool += hw_nonce_count; + } + if (!pushed) + break; + } #endif } - #endif } - while (!job_result_list.empty()) + for (size_t r = 0; r < job_results_count; ++r) { - std::shared_ptr res = job_result_list.front(); - job_result_list.pop_front(); + JobResult *res = &job_results[r]; - hashes += res->nonce_count; if (res->difficulty > currentPoolDifficulty && job_pool == res->id && res->nonce != 0xFFFFFFFF) { if (!client.connected()) break; unsigned long sumbit_id = 0; - tx_mining_submit(client, mWorker, mJob, res->nonce, sumbit_id); + if (!tx_mining_submit(client, mWorker, mJob, res->nonce, sumbit_id)) + { + client.stop(); + isMinerSuscribed = false; + MiningJobStop(job_pool, s_submission_tracker); + resetStratumLineState(); + break; + } + #if MINER_SHARE_LOG Serial.print(" - Current diff share: "); Serial.println(res->difficulty,12); Serial.print(" - Current pool diff : "); Serial.println(currentPoolDifficulty,12); Serial.print(" - TX SHARE: "); for (size_t i = 0; i < 32; i++) Serial.printf("%02x", res->hash[i]); Serial.println(""); + #endif mLastTXtoPool = millis(); - std::shared_ptr submition = std::make_shared(); - submition->diff = res->difficulty; - submition->is32bit = (res->hash[29] == 0 && res->hash[28] == 0); - if (submition->is32bit) + SubmissionState sub{}; + sub.diff = res->difficulty; + sub.is32bit = (res->hash[29] == 0 && res->hash[28] == 0); + if (sub.is32bit) { - submition->isValid = checkValid(res->hash, mMiner.bytearray_target); - } else - submition->isValid = false; - - s_submition_map.insert(std::make_pair(sumbit_id, submition)); - if (s_submition_map.size() > 32) - s_submition_map.erase(s_submition_map.begin()); + sub.isValid = checkValid(res->hash, mMiner.bytearray_target); + } + else + { + sub.isValid = false; + } + submissionTrackerPut(s_submission_tracker, sumbit_id, sub); } } + + uint32_t loop_delay_ms = STRATUM_LOOP_DELAY_IDLE_MS; + if (client.connected() && client.available()) + loop_delay_ms = STRATUM_LOOP_DELAY_BUSY_MS; + else if (processed_pool_message || job_results_count > 0) + loop_delay_ms = STRATUM_LOOP_DELAY_BUSY_MS; + else if (job_pool != 0xFFFFFFFF) + loop_delay_ms = STRATUM_LOOP_DELAY_ACTIVE_MS; + + if (loop_delay_ms > 0) + { + TickType_t delay_ticks = loop_delay_ms / portTICK_PERIOD_MS; + if (delay_ticks > 0) + vTaskDelay(delay_ticks); + else + taskYIELD(); + } + else + { + taskYIELD(); + } } } @@ -588,57 +2353,63 @@ void minerWorkerSw(void * task_id) unsigned int miner_id = (uint32_t)task_id; Serial.printf("[MINER] %d Started minerWorkerSw Task!\n", miner_id); - std::shared_ptr job; - std::shared_ptr result; + JobRequest job{}; + JobResult result{}; uint8_t hash[32]; uint32_t wdt_counter = 0; + uint32_t smooth_counter = 0; while (1) { + if (s_job_queue_sw && xQueueReceive(s_job_queue_sw, &job, 0) == pdTRUE) { - std::lock_guard lock(s_job_mutex); - if (result) - { - if (s_job_result_list.size() < 16) - s_job_result_list.push_back(result); - result.reset(); - } - if (!s_job_request_list_sw.empty()) - { - job = s_job_request_list_sw.front(); - s_job_request_list_sw.pop_front(); - } else - job.reset(); - } - if (job) - { - result = std::make_shared(); - result->difficulty = job->difficulty; - result->nonce = 0xFFFFFFFF; - result->id = job->id; - result->nonce_count = job->nonce_count; - uint8_t job_in_work = job->id & 0xFF; - for (uint32_t n = 0; n < job->nonce_count; ++n) + result = {}; + result.difficulty = job.data->difficulty; + result.nonce = 0xFFFFFFFF; + result.id = job.data->id; + result.nonce_count = job.nonce_count; + + const uint32_t start_us = micros(); + const uint32_t *midstate = job.data->midstate; + const uint32_t *bake = job.data->bake; + const uint32_t nonce_base = job.nonce_start; + const uint32_t nonce_step = job.nonce_stride == 0 ? 1 : job.nonce_stride; + const uint8_t job_in_work = job.data->id & 0xFF; + uint32_t nonce = nonce_base; + + for (uint32_t n = 0; n < job.nonce_count; ++n) { - ((uint32_t*)(job->sha_buffer+64+12))[0] = job->nonce_start+n; - if (nerd_sha256d_baked(job->midstate, job->sha_buffer+64, job->bake, hash)) + if (nerd_sha256d_baked_nonce(midstate, nonce, bake, hash)) { - double diff_hash = diff_from_target(hash); - if (diff_hash > result->difficulty) + if (hashMeetsTargetLe(hash, job.data->pool_target_le)) { - result->difficulty = diff_hash; - result->nonce = job->nonce_start+n; - memcpy(result->hash, hash, 32); + if (result.nonce == 0xFFFFFFFF || hashCompareLe(hash, result.hash) < 0) + { + result.nonce = nonce; + memcpy(result.hash, hash, 32); + } } } - if ( (uint16_t)(n & 0xFF) == 0 &&s_working_current_job_id != job_in_work) + if ((uint16_t)(n & 0xFF) == 0 && s_working_current_job_id != job_in_work) { - result->nonce_count = n+1; + result.nonce_count = n + 1; break; } + nonce += nonce_step; } - } else + + if (result.nonce != 0xFFFFFFFF) + result.difficulty = diff_from_target(result.hash); + update_hashrate(s_sw_hashes_per_ms, result.nonce_count, micros() - start_us); + mining_add_local_processed_hashes(result.nonce_count); + if (s_result_queue && result.nonce != 0xFFFFFFFF) + xQueueSend(s_result_queue, &result, 0); + apply_power_smoothing(MINER_POWER_SMOOTHING_SW_JOB_INTERVAL, smooth_counter); + } + else + { vTaskDelay(2 / portTICK_PERIOD_MS); + } wdt_counter++; if (wdt_counter >= 8) @@ -757,9 +2528,9 @@ static inline bool nerd_sha_ll_read_digest_if(void* ptr) return true; } -static inline void nerd_sha_ll_write_digest(void *digest_state) +static inline void nerd_sha_ll_write_digest(const void *digest_state) { - uint32_t *digest_state_words = (uint32_t *)digest_state; + const uint32_t *digest_state_words = (const uint32_t *)digest_state; uint32_t *reg_addr_buf = (uint32_t *)(SHA_H_BASE); REG_WRITE(®_addr_buf[0], digest_state_words[0]); @@ -784,13 +2555,11 @@ void minerWorkerHw(void * task_id) unsigned int miner_id = (uint32_t)task_id; Serial.printf("[MINER] %d Started minerWorkerHw Task!\n", miner_id); - std::shared_ptr job; - std::shared_ptr result; - uint8_t interResult[64]; + JobRequest job{}; + JobResult result{}; uint8_t hash[32]; - uint8_t digest_mid[32]; - uint8_t sha_buffer[64]; uint32_t wdt_counter = 0; + uint32_t smooth_counter = 0; #ifdef VALIDATION uint8_t doubleHash[32]; @@ -800,45 +2569,30 @@ void minerWorkerHw(void * task_id) while (1) { + if (s_job_queue_hw && xQueueReceive(s_job_queue_hw, &job, 0) == pdTRUE) { - std::lock_guard lock(s_job_mutex); - if (result) - { - if (s_job_result_list.size() < 16) - s_job_result_list.push_back(result); - result.reset(); - } - if (!s_job_request_list_hw.empty()) - { - job = s_job_request_list_hw.front(); - s_job_request_list_hw.pop_front(); - } else - job.reset(); - } - if (job) - { - result = std::make_shared(); - result->id = job->id; - result->nonce = 0xFFFFFFFF; - result->nonce_count = job->nonce_count; - result->difficulty = job->difficulty; - uint8_t job_in_work = job->id & 0xFF; - memcpy(digest_mid, job->midstate, sizeof(digest_mid)); - memcpy(sha_buffer, job->sha_buffer+64, sizeof(sha_buffer)); -#ifdef VALIDATION - nerd_mids(diget_mid, job->sha_buffer); - nerd_sha256_bake(diget_mid, job->sha_buffer+64, bake); -#endif - + result = {}; + result.id = job.data->id; + result.nonce = 0xFFFFFFFF; + result.nonce_count = job.nonce_count; + result.difficulty = job.data->difficulty; + + const uint8_t *sha_buffer = job.data->sha_buffer_hw + 64; + const uint32_t *hw_midstate = job.data->hw_midstate; + const uint32_t nonce_base = job.nonce_start; + const uint32_t nonce_step = job.nonce_stride == 0 ? 1 : job.nonce_stride; + const uint8_t job_in_work = job.data->id & 0xFF; + + const uint32_t start_us = micros(); esp_sha_acquire_hardware(); REG_WRITE(SHA_MODE_REG, SHA2_256); - uint32_t nend = job->nonce_start + job->nonce_count; - for (uint32_t n = job->nonce_start; n < nend; ++n) + uint32_t nonce = nonce_base; + for (uint32_t i = 0; i < job.nonce_count; ++i) { //nerd_sha_hal_wait_idle(); - nerd_sha_ll_write_digest(digest_mid); + nerd_sha_ll_write_digest(hw_midstate); //nerd_sha_hal_wait_idle(); - nerd_sha_ll_fill_text_block_sha256(sha_buffer, n); + nerd_sha_ll_fill_text_block_sha256(sha_buffer, nonce); //sha_ll_continue_block(SHA2_256); REG_WRITE(SHA_CONTINUE_REG, 1); @@ -851,11 +2605,10 @@ void minerWorkerHw(void * task_id) nerd_sha_hal_wait_idle(); if (nerd_sha_ll_read_digest_if(hash)) { - //Serial.printf("Hw 16bit Share, nonce=0x%X\n", n); + //Serial.printf("Hw 16bit Share, nonce=0x%X\n", nonce); #ifdef VALIDATION //Validation - ((uint32_t*)(job->sha_buffer+64+12))[0] = n; - nerd_sha256d_baked(diget_mid, job->sha_buffer+64, bake, doubleHash); + nerd_sha256d_baked_nonce(job.data->midstate, nonce, job.data->bake, doubleHash); for (int i = 0; i < 32; ++i) { if (hash[i] != doubleHash[i]) @@ -865,29 +2618,40 @@ void minerWorkerHw(void * task_id) } } #endif - //~5 per second - double diff_hash = diff_from_target(hash); - if (diff_hash > result->difficulty) + if (hashMeetsTargetLe(hash, job.data->pool_target_le)) { if (isSha256Valid(hash)) { - result->difficulty = diff_hash; - result->nonce = n; - memcpy(result->hash, hash, sizeof(hash)); + if (result.nonce == 0xFFFFFFFF || hashCompareLe(hash, result.hash) < 0) + { + result.nonce = nonce; + memcpy(result.hash, hash, sizeof(hash)); + } } } } if ( - (uint8_t)(n & 0xFF) == 0 && + (uint8_t)(i & 0xFF) == 0 && s_working_current_job_id != job_in_work) { - result->nonce_count = n-job->nonce_start+1; + result.nonce_count = i + 1; break; } + nonce += nonce_step; } esp_sha_release_hardware(); - } else + if (result.nonce != 0xFFFFFFFF) + result.difficulty = diff_from_target(result.hash); + update_hashrate(s_hw_hashes_per_ms, result.nonce_count, micros() - start_us); + mining_add_local_processed_hashes(result.nonce_count); + if (s_result_queue && result.nonce != 0xFFFFFFFF) + xQueueSend(s_result_queue, &result, 0); + apply_power_smoothing(MINER_POWER_SMOOTHING_HW_JOB_INTERVAL, smooth_counter); + } + else + { vTaskDelay(2 / portTICK_PERIOD_MS); + } wdt_counter++; if (wdt_counter >= 8) @@ -1034,42 +2798,31 @@ void minerWorkerHw(void * task_id) unsigned int miner_id = (uint32_t)task_id; Serial.printf("[MINER] %d Started minerWorkerHwEsp32D Task!\n", miner_id); - std::shared_ptr job; - std::shared_ptr result; + JobRequest job{}; + JobResult result{}; uint8_t hash[32]; - uint8_t sha_buffer[128]; + uint32_t smooth_counter = 0; while (1) { + if (s_job_queue_hw && xQueueReceive(s_job_queue_hw, &job, 0) == pdTRUE) { - std::lock_guard lock(s_job_mutex); - if (result) - { - if (s_job_result_list.size() < 16) - s_job_result_list.push_back(result); - result.reset(); - } - if (!s_job_request_list_hw.empty()) - { - job = s_job_request_list_hw.front(); - s_job_request_list_hw.pop_front(); - } else - job.reset(); - } - if (job) - { - result = std::make_shared(); - result->id = job->id; - result->nonce = 0xFFFFFFFF; - result->nonce_count = job->nonce_count; - result->difficulty = job->difficulty; - uint8_t job_in_work = job->id & 0xFF; - memcpy(sha_buffer, job->sha_buffer, 80); - + result = {}; + result.id = job.data->id; + result.nonce = 0xFFFFFFFF; + result.nonce_count = job.nonce_count; + result.difficulty = job.data->difficulty; + const uint8_t *sha_buffer = job.data->sha_buffer_hw; + const uint8_t *sha_upper = sha_buffer + 64; + uint32_t nonce = job.nonce_start; + const uint32_t nonce_step = job.nonce_stride == 0 ? 1 : job.nonce_stride; + const uint8_t job_in_work = job.data->id & 0xFF; + + const uint32_t start_us = micros(); esp_sha_lock_engine(SHA2_256); - for (uint32_t n = 0; n < job->nonce_count; ++n) + for (uint32_t n = 0; n < job.nonce_count; ++n) { - //((uint32_t*)(sha_buffer+64+12))[0] = __builtin_bswap32(job->nonce_start+n); + //((uint32_t*)(sha_buffer+64+12))[0] = __builtin_bswap32(nonce); //sha_hal_hash_block(SHA2_256, s_test_buffer, 64/4, true); //nerd_sha_hal_wait_idle(); @@ -1078,7 +2831,7 @@ void minerWorkerHw(void * task_id) //sha_hal_hash_block(SHA2_256, s_test_buffer+64, 64/4, false); nerd_sha_hal_wait_idle(); - nerd_sha_ll_fill_text_block_sha256_upper(sha_buffer+64, job->nonce_start+n); + nerd_sha_ll_fill_text_block_sha256_upper(sha_upper, nonce); sha_ll_continue_block(SHA2_256); nerd_sha_hal_wait_idle(); @@ -1093,15 +2846,15 @@ void minerWorkerHw(void * task_id) sha_ll_load(SHA2_256); if (nerd_sha_ll_read_digest_swap_if(hash)) { - //~5 per second - double diff_hash = diff_from_target(hash); - if (diff_hash > result->difficulty) + if (hashMeetsTargetLe(hash, job.data->pool_target_le)) { if (isSha256Valid(hash)) { - result->difficulty = diff_hash; - result->nonce = job->nonce_start+n; - memcpy(result->hash, hash, sizeof(hash)); + if (result.nonce == 0xFFFFFFFF || hashCompareLe(hash, result.hash) < 0) + { + result.nonce = nonce; + memcpy(result.hash, hash, sizeof(hash)); + } } } } @@ -1109,13 +2862,24 @@ void minerWorkerHw(void * task_id) (uint8_t)(n & 0xFF) == 0 && s_working_current_job_id != job_in_work) { - result->nonce_count = n+1; + result.nonce_count = n + 1; break; } + nonce += nonce_step; } esp_sha_unlock_engine(SHA2_256); - } else + if (result.nonce != 0xFFFFFFFF) + result.difficulty = diff_from_target(result.hash); + update_hashrate(s_hw_hashes_per_ms, result.nonce_count, micros() - start_us); + mining_add_local_processed_hashes(result.nonce_count); + if (s_result_queue && result.nonce != 0xFFFFFFFF) + xQueueSend(s_result_queue, &result, 0); + apply_power_smoothing(MINER_POWER_SMOOTHING_HW_JOB_INTERVAL, smooth_counter); + } + else + { vTaskDelay(2 / portTICK_PERIOD_MS); + } esp_task_wdt_reset(); } @@ -1197,7 +2961,7 @@ void saveStat() { void resetStat() { Serial.printf("[MONITOR] Resetting NVS stats\n"); - templates = hashes = Mhashes = totalKHashes = elapsedKHs = upTime = shares = valids = 0; + templates = hashes = Mhashes = totalKHashes = elapsedKHs = upTime = shares = valids = stales = 0; best_diff = 0.0; saveStat(); } @@ -1225,6 +2989,7 @@ void runMonitor(void *name) uint32_t now_millis = millis(); if (now_millis < last_update_millis) now_millis = last_update_millis; + bool display_active = isDisplayActive(); uint32_t mElapsed = now_millis - mLastCheck; if (mElapsed >= 1000) @@ -1242,15 +3007,21 @@ void runMonitor(void *name) upTime ++; } - drawCurrentScreen(mElapsed); + if (display_active) + drawCurrentScreen(mElapsed); // Monitor state when hashrate is 0.0 if (elapsedKHs == 0) { - Serial.printf(">>> [i] Miner: newJob>%s / inRun>%s) - Client: connected>%s / subscribed>%s / wificonnected>%s\n", - "true",//(1) ? "true" : "false", - isMinerSuscribed ? "true" : "false", - client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false"); + static uint32_t last_zero_hash_log_ms = 0; + if (now_millis - last_zero_hash_log_ms >= 5000) + { + Serial.printf(">>> [i] Miner: newJob>%s / inRun>%s) - Client: connected>%s / subscribed>%s / wificonnected>%s\n", + (s_working_current_job_id != 0xFF) ? "true" : "false", + isMinerSuscribed ? "true" : "false", + client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false"); + last_zero_hash_log_ms = now_millis; + } } #ifdef DEBUG_MEMORY @@ -1267,9 +3038,45 @@ void runMonitor(void *name) currentIntervalIndex++; } } - animateCurrentScreen(frame); + if (display_active) + animateCurrentScreen(frame); doLedStuff(frame); + // Adapt target batch time based on stale shares + static uint32_t last_stales = 0; + static uint32_t last_adjust_ms = 0; + static uint8_t stable_windows = 0; + if (now_millis - last_adjust_ms >= kAdaptiveTargetWindowMs) + { + uint32_t current_stales = stales; + uint32_t delta = current_stales - last_stales; + last_stales = current_stales; + last_adjust_ms = now_millis; + + if (delta > 0) + { + stable_windows = 0; + if (s_adaptive_target_ms > kAdaptiveTargetMsMin) + { + uint32_t next = s_adaptive_target_ms - kAdaptiveTargetStepDown; + if (next < kAdaptiveTargetMsMin) + next = kAdaptiveTargetMsMin; + s_adaptive_target_ms = next; + } + } + else + { + stable_windows++; + if (stable_windows >= 3 && s_adaptive_target_ms < kAdaptiveTargetMsMax) + { + uint32_t next = s_adaptive_target_ms + kAdaptiveTargetStepUp; + if (next > kAdaptiveTargetMsMax) + next = kAdaptiveTargetMsMax; + s_adaptive_target_ms = next; + stable_windows = 0; + } + } + } vTaskDelay(DELAY / portTICK_PERIOD_MS); frame++; } diff --git a/src/mining.h b/src/mining.h index 86c010fe..f0e1071b 100644 --- a/src/mining.h +++ b/src/mining.h @@ -8,7 +8,7 @@ #define TARGET_NONCE 471136297U #define DEFAULT_DIFFICULTY 0.00015 #define KEEPALIVE_TIME_ms 30000 -#define POOLINACTIVITY_TIME_ms 60000 +#define POOLINACTIVITY_TIME_ms 360000 //#if defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(CONFIG_IDF_TARGET_ESP32C3) #define HARDWARE_SHA265 @@ -19,7 +19,9 @@ void runMonitor(void *name); void runStratumWorker(void *name); +void runI2cSlaveWorker(void *name); void runMiner(void *name); +void initMiningQueues(); void minerWorkerSw(void * task_id); void minerWorkerHw(void * task_id); @@ -36,4 +38,4 @@ typedef struct{ } miner_data; -#endif // UTILS_API_H \ No newline at end of file +#endif // UTILS_API_H diff --git a/src/monitor.cpp b/src/monitor.cpp index f9db1bb3..0f3e85e3 100644 --- a/src/monitor.cpp +++ b/src/monitor.cpp @@ -5,12 +5,20 @@ #include #include #include +#include #include "mining.h" #include "utils.h" #include "monitor.h" #include "drivers/storage/storage.h" #include "drivers/devices/device.h" +#ifndef MONITOR_NTP_LOG +#define MONITOR_NTP_LOG 0 +#endif +#ifndef MONITOR_NTP_RETRY_MS +#define MONITOR_NTP_RETRY_MS 60000UL +#endif + extern uint32_t templates; extern uint32_t hashes; extern uint32_t Mhashes; @@ -20,6 +28,7 @@ extern uint64_t upTime; extern uint32_t shares; // increase if blockhash has 32 bits of zeroes extern uint32_t valids; // increased if blockhash <= targethalfshares +extern uint32_t stales; // stale/late shares reported by pool extern double best_diff; // track best diff @@ -64,7 +73,6 @@ void updateGlobalData(void){ //Make first API call to get global hash and current difficulty HTTPClient http; - http.setTimeout(10000); try { http.begin(getGlobalHash); int httpCode = http.GET(); @@ -72,7 +80,7 @@ void updateGlobalData(void){ if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); - StaticJsonDocument<1024> doc; + DynamicJsonDocument doc(1024); deserializeJson(doc, payload); String temp = ""; if (doc.containsKey("currentHashrate")) temp = String(doc["currentHashrate"].as()); @@ -97,7 +105,7 @@ void updateGlobalData(void){ if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); - StaticJsonDocument<1024> doc; + DynamicJsonDocument doc(1024); deserializeJson(doc, payload); String temp = ""; if (doc.containsKey("halfHourFee")) gData.halfHourFee = doc["halfHourFee"].as(); @@ -114,7 +122,6 @@ void updateGlobalData(void){ http.end(); } catch(...) { - Serial.println("Global data HTTP error caught"); http.end(); } } @@ -129,7 +136,6 @@ String getBlockHeight(void){ if (WiFi.status() != WL_CONNECTED) return current_block; HTTPClient http; - http.setTimeout(10000); try { http.begin(getHeightAPI); int httpCode = http.GET(); @@ -144,7 +150,6 @@ String getBlockHeight(void){ } http.end(); } catch(...) { - Serial.println("Height HTTP error caught"); http.end(); } } @@ -158,16 +163,9 @@ String getBTCprice(void){ if((mBTCUpdate == 0) || (millis() - mBTCUpdate > UPDATE_BTC_min * 60 * 1000)){ - if (WiFi.status() != WL_CONNECTED) { - static char price_buffer[16]; - snprintf(price_buffer, sizeof(price_buffer), "$%u", bitcoin_price); - return String(price_buffer); - } + if (WiFi.status() != WL_CONNECTED) return "$" + String(bitcoin_price); HTTPClient http; - http.setTimeout(10000); - bool priceUpdated = false; - try { http.begin(getBTCAPI); int httpCode = http.GET(); @@ -175,12 +173,9 @@ String getBTCprice(void){ if (httpCode == HTTP_CODE_OK) { String payload = http.getString(); - StaticJsonDocument<1024> doc; + DynamicJsonDocument doc(1024); deserializeJson(doc, payload); - - if (doc.containsKey("bitcoin") && doc["bitcoin"].containsKey("usd")) { - bitcoin_price = doc["bitcoin"]["usd"]; - } + if (doc.containsKey("data") && doc["data"].containsKey("amount")) bitcoin_price = doc["data"]["amount"]; doc.clear(); @@ -189,33 +184,49 @@ String getBTCprice(void){ http.end(); } catch(...) { - Serial.println("BTC price HTTP error caught"); http.end(); } - } + } - static char price_buffer[16]; - snprintf(price_buffer, sizeof(price_buffer), "$%u", bitcoin_price); - return String(price_buffer); + return "$" + String(bitcoin_price); } unsigned long mTriggerUpdate = 0; unsigned long initialMillis = millis(); unsigned long initialTime = 0; unsigned long mPoolUpdate = 0; +static unsigned long mLastNtpAttempt = 0; void getTime(unsigned long* currentHours, unsigned long* currentMinutes, unsigned long* currentSeconds){ //Check if need an NTP call to check current time - if((mTriggerUpdate == 0) || (millis() - mTriggerUpdate > UPDATE_PERIOD_h * 60 * 60 * 1000)){ //60 sec. * 60 min * 1000ms + const unsigned long now = millis(); + const bool needs_initial_sync = (mTriggerUpdate == 0); + const bool needs_periodic_sync = (!needs_initial_sync) && ((now - mTriggerUpdate) > UPDATE_PERIOD_h * 60 * 60 * 1000UL); + const bool retry_window_elapsed = (mLastNtpAttempt == 0) || ((now - mLastNtpAttempt) > MONITOR_NTP_RETRY_MS); + if ((needs_periodic_sync || needs_initial_sync) && retry_window_elapsed) + { + mLastNtpAttempt = now; if(WiFi.status() == WL_CONNECTED) { - if(timeClient.update()) mTriggerUpdate = millis(); //NTP call to get current time - initialTime = timeClient.getEpochTime(); // Guarda la hora inicial (en segundos desde 1970) - Serial.print("TimeClient NTPupdateTime "); + if (timeClient.update()) + { + mTriggerUpdate = now; + initialTime = timeClient.getEpochTime(); // Guarda la hora inicial (en segundos desde 1970) + #if MONITOR_NTP_LOG + Serial.println("TimeClient NTPupdateTime"); + #endif + } + else + { + #if MONITOR_NTP_LOG + Serial.println("TimeClient NTP update failed"); + #endif + } } } - unsigned long elapsedTime = (millis() - mTriggerUpdate) / 1000; // Tiempo transcurrido en segundos + const unsigned long time_base = (mTriggerUpdate == 0) ? now : mTriggerUpdate; + unsigned long elapsedTime = (now - time_base) / 1000; // Tiempo transcurrido en segundos unsigned long currentTime = initialTime + elapsedTime; // La hora actual // convierte la hora actual en horas, minutos y segundos @@ -230,14 +241,12 @@ String getDate(){ unsigned long currentTime = initialTime + elapsedTime; // La hora actual // Convierte la hora actual (epoch time) en una estructura tm - struct tm *tm = localtime((time_t *)¤tTime); - - int year = tm->tm_year + 1900; // tm_year es el número de años desde 1900 - int month = tm->tm_mon + 1; // tm_mon es el mes del año desde 0 (enero) hasta 11 (diciembre) - int day = tm->tm_mday; // tm_mday es el día del mes - + time_t now_epoch = (time_t)currentTime; + struct tm tm_buf{}; + if (localtime_r(&now_epoch, &tm_buf) == nullptr) + return String("00/00/0000"); char currentDate[20]; - sprintf(currentDate, "%02d/%02d/%04d", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900); + sprintf(currentDate, "%02d/%02d/%04d", tm_buf.tm_mday, tm_buf.tm_mon + 1, tm_buf.tm_year + 1900); return String(currentDate); } @@ -249,7 +258,6 @@ String getTime(void){ char LocalHour[10]; sprintf(LocalHour, "%02d:%02d", currentHours, currentMinutes); - String mystring(LocalHour); return LocalHour; } @@ -336,6 +344,7 @@ mining_data getMiningData(unsigned long mElapsed) sprintf(timeMining, "%01d %02d:%02d:%02d", days, hours, mins, secs); data.completedShares = shares; + data.stales = stales; data.totalMHashes = Mhashes; data.totalKHashes = totalKHashes; data.currentHashRate = getCurrentHashRate(mElapsed); @@ -411,7 +420,7 @@ String getPoolAPIUrl(void) { poolAPIUrl = "https://public-pool.io:40557/api/client/"; } else { - if (Settings.PoolAddress == "pool.nerdminers.org") { + if (Settings.PoolAddress == "nerdminers.org") { poolAPIUrl = "https://pool.nerdminers.org/users/"; } else { @@ -419,8 +428,6 @@ String getPoolAPIUrl(void) { case 3333: if (Settings.PoolAddress == "pool.sethforprivacy.com") poolAPIUrl = "https://pool.sethforprivacy.com/api/client/"; - if (Settings.PoolAddress == "pool.solomining.de") - poolAPIUrl = "https://pool.solomining.de/api/client/"; // Add more cases for other addresses with port 3333 if needed break; case 2018: @@ -442,7 +449,7 @@ pool_data getPoolData(void){ if (WiFi.status() != WL_CONNECTED) return pData; //Make first API call to get global hash and current difficulty HTTPClient http; - http.setTimeout(10000); + http.setReuse(true); try { String btcWallet = Settings.BtcWallet; // Serial.println(btcWallet); @@ -462,7 +469,7 @@ pool_data getPoolData(void){ filter["workersCount"] = true; filter["workers"][0]["sessionId"] = true; filter["workers"][0]["hashRate"] = true; - StaticJsonDocument<2048> doc; + DynamicJsonDocument doc(2048); deserializeJson(doc, payload, DeserializationOption::Filter(filter)); //Serial.println(serializeJsonPretty(doc, Serial)); if (doc.containsKey("workersCount")) pData.workersCount = doc["workersCount"].as(); @@ -513,3 +520,4 @@ pool_data getPoolData(void){ } return pData; } + diff --git a/src/monitor.h b/src/monitor.h index 94ef3767..07f4de54 100644 --- a/src/monitor.h +++ b/src/monitor.h @@ -13,11 +13,7 @@ #define UPDATE_PERIOD_h 5 //API BTC price (Update to USDT cus it's more liquidity and flow price updade) - -//#define getBTCAPI "https://api.coindesk.com/v1/bpi/currentprice.json" -- doesn't work anymore -//#define getBTCAPI "https://api.blockchain.com/v3/exchange/tickers/BTC-USDT" -- updates infrequently -#define getBTCAPI "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd" - +#define getBTCAPI "https://api.coinbase.com/v2/prices/BTC-USD/spot" #define UPDATE_BTC_min 1 //API Block height @@ -69,6 +65,7 @@ typedef struct{ typedef struct { String completedShares; String totalMHashes; + String stales; String totalKHashes; String currentHashRate; String templates; diff --git a/src/stratum.cpp b/src/stratum.cpp index 49c2422a..4b3a57ea 100644 --- a/src/stratum.cpp +++ b/src/stratum.cpp @@ -4,17 +4,40 @@ #include "stratum.h" #include "cJSON.h" #include +#include #include #include "esp_log.h" #include "lwip/sockets.h" #include "utils.h" #include "version.h" +#ifndef STRATUM_SUBSCRIBE_TIMEOUT_MS +#define STRATUM_SUBSCRIBE_TIMEOUT_MS 8000 +#endif +#ifndef STRATUM_SUBSCRIBE_POLL_MS +#define STRATUM_SUBSCRIBE_POLL_MS 20 +#endif +#ifndef STRATUM_VERBOSE_LOG +#define STRATUM_VERBOSE_LOG 0 +#endif StaticJsonDocument doc; unsigned long id = 1; +static inline void copyCString(char *dst, size_t dst_size, const char *src) +{ + if (dst == nullptr || dst_size == 0) + return; + if (src == nullptr) + { + dst[0] = '\0'; + return; + } + strncpy(dst, src, dst_size - 1); + dst[dst_size - 1] = '\0'; +} + //Get next JSON RPC Id unsigned long getNextId(unsigned long id) { if (id == ULONG_MAX) { @@ -25,59 +48,153 @@ unsigned long getNextId(unsigned long id) { } //Verify Payload doesn't has zero lenght -bool verifyPayload (String* line){ - if(line->length() == 0) return false; +bool verifyPayload(String* line){ + if (!line) return false; line->trim(); - if(line->isEmpty()) return false; - return true; - + return line->length() > 0; } -bool checkError(const StaticJsonDocument doc) { +static inline bool lineHasContent(const char *line, size_t len) +{ + for (size_t i = 0; i < len; ++i) + { + if (!isspace((unsigned char)line[i])) + return true; + } + return false; +} + +bool checkError(const StaticJsonDocument &doc) { if (!doc.containsKey("error")) return false; - if (doc["error"].size() == 0) return false; - - Serial.printf("ERROR: %d | reason: %s \n", (const int) doc["error"][0], (const char*) doc["error"][1]); + if (doc["error"].size() == 0 || doc["error"].isNull()) return false; + + const int code = (const int)doc["error"][0]; + const char *reason = (const char*)doc["error"][1]; + bool stale_like = (code == 21); + if (reason != nullptr) + { + stale_like = stale_like || strstr(reason, "stale") || strstr(reason, "Stale") || + strstr(reason, "job not found") || strstr(reason, "Job not found"); + } + if (!stale_like || STRATUM_VERBOSE_LOG) + Serial.printf("ERROR: %d | reason: %s \n", code, reason ? reason : ""); return true; } +static bool parse_mining_subscribe_doc(const StaticJsonDocument &doc, mining_subscribe& mSubscribe) +{ + if (checkError(doc)) + return false; + if (!doc.containsKey("result")) + return false; + + const char *sub_details = doc["result"][0][0][1] | ""; + const char *extranonce1 = doc["result"][1] | ""; + copyCString(mSubscribe.sub_details, sizeof(mSubscribe.sub_details), sub_details); + copyCString(mSubscribe.extranonce1, sizeof(mSubscribe.extranonce1), extranonce1); + mSubscribe.extranonce2_size = doc["result"][2]; + return true; +} + // STEP 1: Pool server connection (SUBSCRIBE) // Docs: // - https://cs.braiins.com/stratum-v1/docs // - https://github.com/aeternity/protocol/blob/master/STRATUM.md#mining-subscribe -bool tx_mining_subscribe(WiFiClient& client, mining_subscribe& mSubscribe) +bool tx_mining_subscribe(WiFiClient& client, mining_subscribe& mSubscribe, const char *resume_id) { char payload[BUFFER] = {0}; + static char line_buffer[BUFFER_JSON_DOC + 256]; + size_t line_len = 0; + bool line_overflow = false; // Subscribe id = 1; //Initialize id messages + const bool use_resume = (resume_id != nullptr && resume_id[0] != '\0'); #ifndef HAN - sprintf(payload, "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"NerdMinerV2/%s\"]}\n", id, CURRENT_VERSION); + if (use_resume) + // snprintf(payload, sizeof(payload), "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"NerdMinerV2/%s\", \"%s\"]}\n", id, CURRENT_VERSION, resume_id); + snprintf(payload, sizeof(payload), "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"MYMinerV2/%s\", \"%s\"]}\n", id, CURRENT_VERSION, resume_id); + else + // snprintf(payload, sizeof(payload), "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"NerdMinerV2/%s\"]}\n", id, CURRENT_VERSION); + snprintf(payload, sizeof(payload), "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"MYMinerV2/%s\"]}\n", id, CURRENT_VERSION); #else - sprintf(payload, "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"HAN_SOLOminer/%s\"]}\n", id, CURRENT_VERSION); + if (use_resume) + snprintf(payload, sizeof(payload), "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"HAN_SOLOminer/%s\", \"%s\"]}\n", id, CURRENT_VERSION, resume_id); + else + snprintf(payload, sizeof(payload), "{\"id\": %u, \"method\": \"mining.subscribe\", \"params\": [\"HAN_SOLOminer/%s\"]}\n", id, CURRENT_VERSION); #endif - Serial.printf("[WORKER] ==> Mining subscribe\n"); + Serial.printf("[WORKER] ==> Mining subscribe%s\n", use_resume ? " (resume)" : ""); Serial.print(" Sending : "); Serial.println(payload); client.print(payload); - vTaskDelay(200 / portTICK_PERIOD_MS); //Small delay - - String line = client.readStringUntil('\n'); - if(!parse_mining_subscribe(line, mSubscribe)) return false; + uint32_t started = millis(); + while ((uint32_t)(millis() - started) < STRATUM_SUBSCRIBE_TIMEOUT_MS) + { + if (!client.connected()) + return false; + + if (!client.available()) + { + vTaskDelay(STRATUM_SUBSCRIBE_POLL_MS / portTICK_PERIOD_MS); + continue; + } + + while (client.available()) + { + int ch = client.read(); + if (ch < 0) + break; + if (ch == '\r') + continue; + if (ch != '\n') + { + if (line_overflow) + continue; + if (line_len + 1 < sizeof(line_buffer)) + line_buffer[line_len++] = (char)ch; + else + line_overflow = true; + continue; + } + + if (line_overflow) + { + line_overflow = false; + line_len = 0; + continue; + } + if (!lineHasContent(line_buffer, line_len)) + { + line_len = 0; + continue; + } + + doc.clear(); + DeserializationError error = deserializeJson(doc, line_buffer, line_len); + line_len = 0; + if (!error && parse_mining_subscribe_doc(doc, mSubscribe)) + break; + } + if (mSubscribe.extranonce1[0] != '\0') + break; + } + + if (mSubscribe.extranonce1[0] == '\0') + return false; Serial.print(" sub_details: "); Serial.println(mSubscribe.sub_details); Serial.print(" extranonce1: "); Serial.println(mSubscribe.extranonce1); Serial.print(" extranonce2_size: "); Serial.println(mSubscribe.extranonce2_size); - if((mSubscribe.extranonce1.length() == 0) ) { + if (mSubscribe.extranonce1[0] == '\0') { Serial.printf("[WORKER] >>>>>>>>> Work aborted\n"); - Serial.printf("extranonce1 length: %u \n", mSubscribe.extranonce1.length()); + Serial.printf("extranonce1 length: %u \n", (unsigned)strlen(mSubscribe.extranonce1)); doc.clear(); doc.garbageCollect(); return false; @@ -88,30 +205,21 @@ bool tx_mining_subscribe(WiFiClient& client, mining_subscribe& mSubscribe) bool parse_mining_subscribe(String line, mining_subscribe& mSubscribe) { if(!verifyPayload(&line)) return false; + #if STRATUM_VERBOSE_LOG Serial.print(" Receiving: "); Serial.println(line); + #endif DeserializationError error = deserializeJson(doc, line); - if (error || checkError(doc)) return false; - if (!doc.containsKey("result")) return false; - - mSubscribe.sub_details = String((const char*) doc["result"][0][0][1]); - mSubscribe.extranonce1 = String((const char*) doc["result"][1]); - mSubscribe.extranonce2_size = doc["result"][2]; - - return true; + if (error) + return false; + return parse_mining_subscribe_doc(doc, mSubscribe); } mining_subscribe init_mining_subscribe(void) { - mining_subscribe new_mSub; - - new_mSub.extranonce1 = ""; - new_mSub.extranonce2 = ""; + mining_subscribe new_mSub{}; new_mSub.extranonce2_size = 0; - new_mSub.sub_details = ""; - - return new_mSub; } @@ -141,24 +249,38 @@ bool tx_mining_auth(WiFiClient& client, const char * user, const char * pass) stratum_method parse_mining_method(String line) { if(!verifyPayload(&line)) return STRATUM_PARSE_ERROR; + #if STRATUM_VERBOSE_LOG Serial.print(" Receiving: "); Serial.println(line); + #endif DeserializationError error = deserializeJson(doc, line); + if (error) + return STRATUM_PARSE_ERROR; - if (error || checkError(doc)) return STRATUM_PARSE_ERROR; + return parse_mining_method_doc(doc); +} - if (!doc.containsKey("method")) { +stratum_method parse_mining_method_doc(const StaticJsonDocument& doc) +{ + if (checkError(doc)) + return STRATUM_PARSE_ERROR; + + if (!doc.containsKey("method")) + { // "error":null means success if (doc["error"].isNull()) return STRATUM_SUCCESS; - else - return STRATUM_UNKNOWN; + return STRATUM_UNKNOWN; } + const char *method = doc["method"]; + if (method == nullptr) + return STRATUM_UNKNOWN; + stratum_method result = STRATUM_UNKNOWN; - if (strcmp("mining.notify", (const char*) doc["method"]) == 0) { + if (strcmp("mining.notify", method) == 0) { result = MINING_NOTIFY; - } else if (strcmp("mining.set_difficulty", (const char*) doc["method"]) == 0) { + } else if (strcmp("mining.set_difficulty", method) == 0) { result = MINING_SET_DIFFICULTY; } @@ -167,22 +289,39 @@ stratum_method parse_mining_method(String line) bool parse_mining_notify(String line, mining_job& mJob) { - Serial.println(" Parsing Method [MINING NOTIFY]"); if(!verifyPayload(&line)) return false; + #if STRATUM_VERBOSE_LOG + Serial.println(" Parsing Method [MINING NOTIFY]"); + #endif DeserializationError error = deserializeJson(doc, line); + if (error) + return false; + + return parse_mining_notify_doc(doc, mJob); +} - if (error) return false; - if (!doc.containsKey("params")) return false; +bool parse_mining_notify_doc(StaticJsonDocument& doc, mining_job& mJob) +{ + if (!doc.containsKey("params")) + return false; - mJob.job_id = String((const char*) doc["params"][0]); - mJob.prev_block_hash = String((const char*) doc["params"][1]); - mJob.coinb1 = String((const char*) doc["params"][2]); - mJob.coinb2 = String((const char*) doc["params"][3]); + const char *job_id = doc["params"][0] | ""; + const char *prev_hash = doc["params"][1] | ""; + const char *coinb1 = doc["params"][2] | ""; + const char *coinb2 = doc["params"][3] | ""; + const char *version = doc["params"][5] | ""; + const char *nbits = doc["params"][6] | ""; + const char *ntime = doc["params"][7] | ""; + + copyCString(mJob.job_id, sizeof(mJob.job_id), job_id); + copyCString(mJob.prev_block_hash, sizeof(mJob.prev_block_hash), prev_hash); + copyCString(mJob.coinb1, sizeof(mJob.coinb1), coinb1); + copyCString(mJob.coinb2, sizeof(mJob.coinb2), coinb2); mJob.merkle_branch = doc["params"][4]; - mJob.version = String((const char*) doc["params"][5]); - mJob.nbits = String((const char*) doc["params"][6]); - mJob.ntime = String((const char*) doc["params"][7]); + copyCString(mJob.version, sizeof(mJob.version), version); + copyCString(mJob.nbits, sizeof(mJob.nbits), nbits); + copyCString(mJob.ntime, sizeof(mJob.ntime), ntime); mJob.clean_jobs = doc["params"][8]; //bool #ifdef DEBUG_MINING @@ -205,9 +344,11 @@ bool parse_mining_notify(String line, mining_job& mJob) } -bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job mJob, unsigned long nonce, unsigned long &submit_id) +bool tx_mining_submit(WiFiClient& client, const mining_subscribe& mWorker, const mining_job& mJob, unsigned long nonce, unsigned long &submit_id) { char payload[BUFFER] = {0}; + char nonce_hex[9] = {0}; + snprintf(nonce_hex, sizeof(nonce_hex), "%08lx", nonce); // Submit id = getNextId(id); @@ -215,12 +356,14 @@ bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job m sprintf(payload, "{\"id\":%u,\"method\":\"mining.submit\",\"params\":[\"%s\",\"%s\",\"%s\",\"%s\",\"%s\"]}\n", id, mWorker.wName,//"bc1qvv469gmw4zz6qa4u4dsezvrlmqcqszwyfzhgwj", //mWorker.name, - mJob.job_id.c_str(), - mWorker.extranonce2.c_str(), - mJob.ntime.c_str(), - String(nonce, HEX).c_str() + mJob.job_id, + mWorker.extranonce2, + mJob.ntime, + nonce_hex ); + #if STRATUM_VERBOSE_LOG Serial.print(" Sending : "); Serial.print(payload); + #endif client.print(payload); //Serial.print(" Receiving: "); Serial.println(client.readStringUntil('\n')); @@ -229,15 +372,26 @@ bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job m bool parse_mining_set_difficulty(String line, double& difficulty) { - Serial.println(" Parsing Method [SET DIFFICULTY]"); if(!verifyPayload(&line)) return false; + #if STRATUM_VERBOSE_LOG + Serial.println(" Parsing Method [SET DIFFICULTY]"); + #endif DeserializationError error = deserializeJson(doc, line); + if (error) + return false; - if (error) return false; - if (!doc.containsKey("params")) return false; + return parse_mining_set_difficulty_doc(doc, difficulty); +} +bool parse_mining_set_difficulty_doc(const StaticJsonDocument& doc, double& difficulty) +{ + if (!doc.containsKey("params")) + return false; + + #if STRATUM_VERBOSE_LOG Serial.print(" difficulty: "); Serial.println((double)doc["params"][0],12); + #endif difficulty = (double)doc["params"][0]; return true; @@ -250,22 +404,27 @@ bool tx_suggest_difficulty(WiFiClient& client, double difficulty) id = getNextId(id); sprintf(payload, "{\"id\":%d,\"method\":\"mining.suggest_difficulty\",\"params\":[%.10g]}\n", id, difficulty); + #if STRATUM_VERBOSE_LOG Serial.print(" Sending : "); Serial.print(payload); + #endif return client.print(payload); } -unsigned long parse_extract_id(const String &line) +unsigned long parse_extract_id(String line) { DeserializationError error = deserializeJson(doc, line); if (error) return 0; - - if (!doc.containsKey("id")) - return 0; - unsigned long id = doc["id"]; + return parse_extract_id_doc(doc); +} + +unsigned long parse_extract_id_doc(const StaticJsonDocument& doc) +{ + if (!doc.containsKey("id")) + return 0; - return id; -} \ No newline at end of file + return doc["id"]; +} diff --git a/src/stratum.h b/src/stratum.h index 7012bcfd..144ceba5 100644 --- a/src/stratum.h +++ b/src/stratum.h @@ -9,31 +9,38 @@ #define MAX_MERKLE_BRANCHES 32 #define HASH_SIZE 32 -#define COINBASE_SIZE 100 -#define COINBASE2_SIZE 128 +#define COINBASE_SIZE 384 +#define COINBASE2_SIZE 384 +#define STRATUM_SUB_DETAILS_SIZE 96 +#define STRATUM_EXTRANONCE1_SIZE 64 +#define STRATUM_EXTRANONCE2_SIZE 64 +#define STRATUM_JOB_ID_SIZE 96 +#define STRATUM_VERSION_SIZE 16 +#define STRATUM_NBITS_SIZE 16 +#define STRATUM_NTIME_SIZE 16 #define BUFFER_JSON_DOC 4096 #define BUFFER 1024 typedef struct { - String sub_details; - String extranonce1; - String extranonce2; + char sub_details[STRATUM_SUB_DETAILS_SIZE]; + char extranonce1[STRATUM_EXTRANONCE1_SIZE]; + char extranonce2[STRATUM_EXTRANONCE2_SIZE]; int extranonce2_size; char wName[80]; - char wPass[20]; + char wPass[80]; } mining_subscribe; typedef struct { - String job_id; - String prev_block_hash; - String coinb1; - String coinb2; - String nbits; + char job_id[STRATUM_JOB_ID_SIZE]; + char prev_block_hash[(HASH_SIZE * 2) + 1]; + char coinb1[COINBASE_SIZE]; + char coinb2[COINBASE2_SIZE]; + char nbits[STRATUM_NBITS_SIZE]; JsonArray merkle_branch; - String version; + char version[STRATUM_VERSION_SIZE]; uint32_t target; - String ntime; + char ntime[STRATUM_NTIME_SIZE]; bool clean_jobs; } mining_job; @@ -46,26 +53,30 @@ typedef enum { } stratum_method; unsigned long getNextId(unsigned long id); -bool verifyPayload (String* line); -bool checkError(const StaticJsonDocument doc); +bool verifyPayload(String* line); +bool checkError(const StaticJsonDocument &doc); //Method Mining.subscribe mining_subscribe init_mining_subscribe(void); -bool tx_mining_subscribe(WiFiClient& client, mining_subscribe& mSubscribe); +bool tx_mining_subscribe(WiFiClient& client, mining_subscribe& mSubscribe, const char *resume_id = nullptr); bool parse_mining_subscribe(String line, mining_subscribe& mSubscribe); //Method Mining.authorise bool tx_mining_auth(WiFiClient& client, const char * user, const char * pass); stratum_method parse_mining_method(String line); +stratum_method parse_mining_method_doc(const StaticJsonDocument& doc); bool parse_mining_notify(String line, mining_job& mJob); +bool parse_mining_notify_doc(StaticJsonDocument& doc, mining_job& mJob); //Method Mining.submit -bool tx_mining_submit(WiFiClient& client, mining_subscribe mWorker, mining_job mJob, unsigned long nonce, unsigned long &submit_id); +bool tx_mining_submit(WiFiClient& client, const mining_subscribe& mWorker, const mining_job& mJob, unsigned long nonce, unsigned long &submit_id); //Difficulty Methods bool tx_suggest_difficulty(WiFiClient& client, double difficulty); bool parse_mining_set_difficulty(String line, double& difficulty); +bool parse_mining_set_difficulty_doc(const StaticJsonDocument& doc, double& difficulty); -unsigned long parse_extract_id(const String &line); +unsigned long parse_extract_id(String line); +unsigned long parse_extract_id_doc(const StaticJsonDocument& doc); -#endif // STRATUM_API_H \ No newline at end of file +#endif // STRATUM_API_H diff --git a/src/utils.cpp b/src/utils.cpp index 3120e8a2..512f2e6c 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -8,6 +8,10 @@ #include #include +#ifndef MINER_JOB_DEBUG_LOG +#define MINER_JOB_DEBUG_LOG 0 +#endif + #ifndef bswap_16 #define bswap_16(a) ((((uint16_t) (a) << 8) & 0xff00) | (((uint16_t) (a) >> 8) & 0xff)) #endif @@ -36,7 +40,7 @@ int to_byte_array(const char *in, size_t in_size, uint8_t *out) { if (!*in) return count; *out = (*out << 4) | hex(*in++); - *out++; + out++; count++; } return count; @@ -49,6 +53,35 @@ int to_byte_array(const char *in, size_t in_size, uint8_t *out) { } } +static inline void copyCString(char *dst, size_t dst_size, const char *src) +{ + if (dst == nullptr || dst_size == 0) + return; + if (src == nullptr) + { + dst[0] = '\0'; + return; + } + strncpy(dst, src, dst_size - 1); + dst[dst_size - 1] = '\0'; +} + +static inline size_t appendCString(char *dst, size_t dst_size, size_t offset, const char *src) +{ + if (dst == nullptr || dst_size == 0 || offset >= dst_size) + return offset; + if (src == nullptr) + src = ""; + + size_t src_len = strlen(src); + size_t room = dst_size - offset - 1; + size_t copy_len = (src_len < room) ? src_len : room; + if (copy_len > 0) + memcpy(dst + offset, src, copy_len); + dst[offset + copy_len] = '\0'; + return offset + copy_len; +} + void swap_endian_words(const char * hex_words, uint8_t * output) { size_t hex_length = strlen(hex_words); if (hex_length % 8 != 0) { @@ -77,9 +110,8 @@ void reverse_bytes(uint8_t * data, size_t len) { static const double truediffone = 26959535291011309493156476344723991336010898738574164086137773096960.0; /* Converts a little endian 256 bit value to a double */ -double le256todouble(const void *target) +double le256todouble(const void *target) { - const uint64_t *data64; double dcut64; @@ -95,7 +127,7 @@ double le256todouble(const void *target) data64 = (const uint64_t *)(target); dcut64 += *data64; - return dcut64; + return dcut64; } double diff_from_target(void *target) @@ -122,18 +154,24 @@ bool isSha256Valid(const void* sha256) /****************** PREMINING CALCULATIONS ********************/ -bool checkValid(unsigned char* hash, unsigned char* target) { +bool checkValid(const unsigned char* hash, const unsigned char* target) { + if (hash == nullptr || target == nullptr) + return false; + bool valid = true; unsigned char diff_target[32]; - memcpy(diff_target, &target, 32); + memcpy(diff_target, target, sizeof(diff_target)); //convert target to little endian for comparison - reverse_bytes(diff_target, 32); + reverse_bytes(diff_target, sizeof(diff_target)); - for(uint8_t i=31; i>=0; i--) { + for(int i = 31; i >= 0; --i) { if(hash[i] > diff_target[i]) { valid = false; break; } + if(hash[i] < diff_target[i]) { + break; + } } #ifdef DEBUG_MINING @@ -186,18 +224,37 @@ miner_data init_miner_data(void){ return newMinerData; } -miner_data calculateMiningData(mining_subscribe& mWorker, mining_job mJob){ +miner_data calculateMiningData(mining_subscribe& mWorker, const mining_job& mJob){ miner_data mMiner = init_miner_data(); // calculate target - target = (nbits[2:]+'00'*(int(nbits[:2],16) - 3)).zfill(64) - char target[TARGET_BUFFER_SIZE+1]; + char target[TARGET_BUFFER_SIZE + 1]; memset(target, '0', TARGET_BUFFER_SIZE); - int zeros = (int) strtol(mJob.nbits.substring(0, 2).c_str(), 0, 16) - 3; - memcpy(target + zeros - 2, mJob.nbits.substring(2).c_str(), mJob.nbits.length() - 2); target[TARGET_BUFFER_SIZE] = 0; + + char nbits_exp[3] = {0, 0, 0}; + if (mJob.nbits[0] != '\0') + nbits_exp[0] = mJob.nbits[0]; + if (mJob.nbits[1] != '\0') + nbits_exp[1] = mJob.nbits[1]; + int zeros = (int)strtol(nbits_exp, nullptr, 16) - 3; + int target_offset = zeros - 2; + if (target_offset < 0) + target_offset = 0; + if (target_offset > TARGET_BUFFER_SIZE) + target_offset = TARGET_BUFFER_SIZE; + size_t nbits_len = strnlen(mJob.nbits, sizeof(mJob.nbits)); + size_t nbits_tail_len = (nbits_len > 2) ? (nbits_len - 2) : 0; + size_t copy_len = nbits_tail_len; + if ((size_t)target_offset + copy_len > TARGET_BUFFER_SIZE) + copy_len = TARGET_BUFFER_SIZE - (size_t)target_offset; + if (copy_len > 0) + memcpy(target + target_offset, mJob.nbits + 2, copy_len); + #if MINER_JOB_DEBUG_LOG Serial.print(" target: "); Serial.println(target); + #endif // bytearray target size_t size_target = to_byte_array(target, 32, mMiner.bytearray_target); @@ -209,38 +266,37 @@ miner_data calculateMiningData(mining_subscribe& mWorker, mining_job mJob){ } // get extranonce2 - extranonce2 = hex(random.randint(0,2**32-1))[2:].zfill(2*extranonce2_size) - //To review - //char extranonce2_char[2 * mWorker.extranonce2_size+1]; - //mWorker.extranonce2.toCharArray(extranonce2_char, 2 * mWorker.extranonce2_size + 1); - //getNextExtranonce2(mWorker.extranonce2_size, extranonce2_char); if (mWorker.extranonce2_size == 2) - mWorker.extranonce2 = "0001"; + copyCString(mWorker.extranonce2, sizeof(mWorker.extranonce2), "0001"); else if (mWorker.extranonce2_size == 4) - mWorker.extranonce2 = "00000001"; + copyCString(mWorker.extranonce2, sizeof(mWorker.extranonce2), "00000001"); else if (mWorker.extranonce2_size == 8) - mWorker.extranonce2 = "0000000000000001"; + copyCString(mWorker.extranonce2, sizeof(mWorker.extranonce2), "0000000000000001"); else { Serial.println("Unknown extranonce2"); - mWorker.extranonce2 = "00000001"; + copyCString(mWorker.extranonce2, sizeof(mWorker.extranonce2), "00000001"); } - //mWorker.extranonce2 = "00000002"; - - //get coinbase - coinbase_hash_bin = hashlib.sha256(hashlib.sha256(binascii.unhexlify(coinbase)).digest()).digest() - // Use char buffer instead of String concatenation to avoid memory leaks - static char coinbase_buffer[512]; // Static buffer to avoid repeated allocation - snprintf(coinbase_buffer, sizeof(coinbase_buffer), "%s%s%s%s", - mJob.coinb1.c_str(), mWorker.extranonce1.c_str(), - mWorker.extranonce2.c_str(), mJob.coinb2.c_str()); - Serial.print(" coinbase: "); Serial.println(coinbase_buffer); - size_t str_len = strlen(coinbase_buffer)/2; - uint8_t bytearray[str_len]; - - size_t res = to_byte_array(coinbase_buffer, str_len*2, bytearray); + + // get coinbase - coinbase_hash_bin = hashlib.sha256(hashlib.sha256(binascii.unhexlify(coinbase)).digest()).digest() + char coinbase[COINBASE_SIZE + STRATUM_EXTRANONCE1_SIZE + STRATUM_EXTRANONCE2_SIZE + COINBASE2_SIZE + 1]; + size_t coinbase_len = 0; + coinbase[0] = '\0'; + coinbase_len = appendCString(coinbase, sizeof(coinbase), coinbase_len, mJob.coinb1); + coinbase_len = appendCString(coinbase, sizeof(coinbase), coinbase_len, mWorker.extranonce1); + coinbase_len = appendCString(coinbase, sizeof(coinbase), coinbase_len, mWorker.extranonce2); + coinbase_len = appendCString(coinbase, sizeof(coinbase), coinbase_len, mJob.coinb2); + #if MINER_JOB_DEBUG_LOG + Serial.print(" coinbase: "); Serial.println(coinbase); + #endif + size_t str_len = coinbase_len / 2; + uint8_t bytearray[(sizeof(coinbase) - 1) / 2]; + + size_t res = to_byte_array(coinbase, coinbase_len, bytearray); #ifdef DEBUG_MINING Serial.print(" extranonce2: "); Serial.println(mWorker.extranonce2); - Serial.print(" coinbase: "); Serial.println(coinbase_buffer); + Serial.print(" coinbase: "); Serial.println(coinbase); Serial.print(" coinbase bytes - size: "); Serial.println(res); for (size_t i = 0; i < res; i++) Serial.printf("%02x", bytearray[i]); @@ -254,7 +310,7 @@ miner_data calculateMiningData(mining_subscribe& mWorker, mining_job mJob){ byte shaResult[32]; // 256 bit mbedtls_sha256_starts_ret(&ctx,0); - mbedtls_sha256_update_ret(&ctx, bytearray, str_len); + mbedtls_sha256_update_ret(&ctx, bytearray, res); mbedtls_sha256_finish_ret(&ctx, interResult); mbedtls_sha256_starts_ret(&ctx,0); @@ -315,22 +371,35 @@ miner_data calculateMiningData(mining_subscribe& mWorker, mining_job mJob){ } // merkle root from merkle_result + char merkle_root[65] = {0}; + #if MINER_JOB_DEBUG_LOG Serial.print(" merkle sha : "); - char merkle_root[65]; + #endif for (int i = 0; i < 32; i++) { + #if MINER_JOB_DEBUG_LOG Serial.printf("%02x", mMiner.merkle_result[i]); + #endif snprintf(&merkle_root[i*2], 3, "%02x", mMiner.merkle_result[i]); } - merkle_root[65] = 0; + #if MINER_JOB_DEBUG_LOG Serial.println(""); + #endif // calculate blockheader // j.block_header = ''.join([j.version, j.prevhash, merkle_root, j.ntime, j.nbits]) - String blockheader = mJob.version + mJob.prev_block_hash + String(merkle_root) + mJob.ntime + mJob.nbits + "00000000"; - str_len = blockheader.length()/2; - + char blockheader[161]; + size_t blockheader_len = 0; + blockheader[0] = '\0'; + blockheader_len = appendCString(blockheader, sizeof(blockheader), blockheader_len, mJob.version); + blockheader_len = appendCString(blockheader, sizeof(blockheader), blockheader_len, mJob.prev_block_hash); + blockheader_len = appendCString(blockheader, sizeof(blockheader), blockheader_len, merkle_root); + blockheader_len = appendCString(blockheader, sizeof(blockheader), blockheader_len, mJob.ntime); + blockheader_len = appendCString(blockheader, sizeof(blockheader), blockheader_len, mJob.nbits); + blockheader_len = appendCString(blockheader, sizeof(blockheader), blockheader_len, "00000000"); + str_len = blockheader_len / 2; + //uint8_t bytearray_blockheader[str_len]; - res = to_byte_array(blockheader.c_str(), str_len*2, mMiner.bytearray_blockheader); + res = to_byte_array(blockheader, blockheader_len, mMiner.bytearray_blockheader); #ifdef DEBUG_MINING Serial.println(" blockheader: "); Serial.print(blockheader); @@ -520,7 +589,6 @@ void suffix_string(double val, char *buf, size_t bufsiz, int sigdigits) } - static const uint32_t s_crc32_table[256] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, @@ -605,4 +673,3 @@ uint32_t crc32_finish(uint32_t crc32) { return crc32 ^ 0xFFFFFFFF; } - diff --git a/src/utils.h b/src/utils.h index 467d35ce..4dcd7038 100644 --- a/src/utils.h +++ b/src/utils.h @@ -21,8 +21,8 @@ int to_byte_array(const char *in, size_t in_size, uint8_t *out); double le256todouble(const void *target); double diff_from_target(void *target); bool isSha256Valid(const void* sha256); -miner_data calculateMiningData(mining_subscribe& mWorker, mining_job mJob); -bool checkValid(unsigned char* hash, unsigned char* target); +miner_data calculateMiningData(mining_subscribe& mWorker, const mining_job& mJob); +bool checkValid(const unsigned char* hash, const unsigned char* target); void suffix_string(double val, char *buf, size_t bufsiz, int sigdigits); uint32_t crc32_reset(); @@ -31,4 +31,4 @@ uint32_t crc32_finish(uint32_t crc32); -#endif // UTILS_API_H \ No newline at end of file +#endif // UTILS_API_H diff --git a/src/wManager.cpp b/src/wManager.cpp index d812981b..71a23f4f 100644 --- a/src/wManager.cpp +++ b/src/wManager.cpp @@ -4,8 +4,11 @@ //#include ".h" #include +#include "esp_event.h" +#include "esp_wifi.h" #include +#include #include "wManager.h" #include "monitor.h" @@ -16,8 +19,18 @@ #include "mining.h" #include "timeconst.h" -#include -#include +#ifndef WIFI_DISABLE_MODEM_SLEEP +#define WIFI_DISABLE_MODEM_SLEEP 1 +#endif +#ifndef WIFI_CONNECT_RETRIES +#define WIFI_CONNECT_RETRIES 3 +#endif +#ifndef WIFI_MANAGER_COUNTRY +#define WIFI_MANAGER_COUNTRY "" +#endif +#ifndef WIFI_TX_POWER_LEVEL +#define WIFI_TX_POWER_LEVEL WIFI_POWER_19_5dBm +#endif // Flag for saving data @@ -33,62 +46,63 @@ extern monitor_data mMonitor; nvMemory nvMem; extern SDCard SDCrd; +static volatile uint8_t s_last_wifi_disc_reason = 0xFF; -String readCustomAPName() { - Serial.println("DEBUG: Attempting to read custom AP name from flash at 0x3F0000..."); - - // Leer directamente desde flash - const size_t DATA_SIZE = 128; - uint8_t buffer[DATA_SIZE]; - memset(buffer, 0, DATA_SIZE); // Clear buffer - - // Leer desde 0x3F0000 - esp_err_t result = esp_flash_read(NULL, buffer, 0x3F0000, DATA_SIZE); - if (result != ESP_OK) { - Serial.printf("DEBUG: Flash read error: %s\n", esp_err_to_name(result)); - return ""; +static const char *wifiDisconnectReasonText(uint8_t reason) +{ + // Numeric fallbacks keep logs useful across core/IDF versions where reason macros differ. + switch (reason) + { + case 2: return "AUTH_EXPIRE"; + case 4: return "ASSOC_EXPIRE"; + case 15: return "4WAY_HANDSHAKE_TIMEOUT"; + case 200: return "BEACON_TIMEOUT"; + case 201: return "NO_AP_FOUND"; + case 202: return "AUTH_FAIL"; + case 203: return "ASSOC_FAIL"; + case 204: return "HANDSHAKE_TIMEOUT"; + case 205: return "CONNECTION_FAIL"; + default: break; } - - Serial.println("DEBUG: Successfully read from flash"); - String data = String((char*)buffer); - - // Debug: show raw data read - Serial.printf("DEBUG: Raw flash data: '%s'\n", data.c_str()); - - if (data.startsWith("WEBFLASHER_CONFIG:")) { - Serial.println("DEBUG: Found WEBFLASHER_CONFIG marker"); - String jsonPart = data.substring(18); // Después del marcador "WEBFLASHER_CONFIG:" - - Serial.printf("DEBUG: JSON part: '%s'\n", jsonPart.c_str()); - - DynamicJsonDocument doc(256); - DeserializationError error = deserializeJson(doc, jsonPart); - - if (error == DeserializationError::Ok) { - Serial.println("DEBUG: JSON parsed successfully"); - - if (doc.containsKey("apname")) { - String customAP = doc["apname"].as(); - customAP.trim(); - - if (customAP.length() > 0 && customAP.length() < 32) { - Serial.printf("✅ Custom AP name from webflasher: %s\n", customAP.c_str()); - return customAP; - } else { - Serial.printf("DEBUG: AP name invalid length: %d\n", customAP.length()); - } - } else { - Serial.println("DEBUG: 'apname' key not found in JSON"); - } - } else { - Serial.printf("DEBUG: JSON parse error: %s\n", error.c_str()); - } - } else { - Serial.println("DEBUG: WEBFLASHER_CONFIG marker not found - no custom config"); + + switch (reason) + { +#ifdef WIFI_REASON_AUTH_EXPIRE + case WIFI_REASON_AUTH_EXPIRE: return "AUTH_EXPIRE"; +#endif +#ifdef WIFI_REASON_AUTH_FAIL + case WIFI_REASON_AUTH_FAIL: return "AUTH_FAIL"; +#endif +#ifdef WIFI_REASON_ASSOC_EXPIRE + case WIFI_REASON_ASSOC_EXPIRE: return "ASSOC_EXPIRE"; +#endif +#ifdef WIFI_REASON_ASSOC_FAIL + case WIFI_REASON_ASSOC_FAIL: return "ASSOC_FAIL"; +#endif +#ifdef WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT + case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT: return "4WAY_TIMEOUT"; +#endif +#ifdef WIFI_REASON_HANDSHAKE_TIMEOUT + case WIFI_REASON_HANDSHAKE_TIMEOUT: return "HANDSHAKE_TIMEOUT"; +#endif +#ifdef WIFI_REASON_CONNECTION_FAIL + case WIFI_REASON_CONNECTION_FAIL: return "CONNECTION_FAIL"; +#endif + default: return "UNKNOWN"; } - - Serial.println("DEBUG: Using default AP name"); - return ""; +} + +static void copyCString(char *dst, size_t dstSize, const char *src) +{ + if (dst == nullptr || dstSize == 0) + return; + if (src == nullptr) + { + dst[0] = '\0'; + return; + } + strncpy(dst, src, dstSize - 1); + dst[dstSize - 1] = '\0'; } void saveConfigCallback() @@ -128,6 +142,32 @@ void reset_configuration() ESP.restart(); } + +static void onWiFiEvent(WiFiEvent_t event, WiFiEventInfo_t info) +{ +#if defined(ARDUINO_EVENT_WIFI_STA_DISCONNECTED) + if (event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED) + { + s_last_wifi_disc_reason = info.wifi_sta_disconnected.reason; + Serial.printf("[WiFi] Disconnected, reason: %d (%s)\n", + info.wifi_sta_disconnected.reason, + wifiDisconnectReasonText(info.wifi_sta_disconnected.reason)); + } +#endif +} + +static void onWifiEventIdf(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) +{ + if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) + { + wifi_event_sta_disconnected_t *disc = (wifi_event_sta_disconnected_t *)event_data; + s_last_wifi_disc_reason = disc->reason; + Serial.printf("[WiFi] Disconnected (IDF), reason: %d (%s)\n", + disc->reason, + wifiDisconnectReasonText(disc->reason)); + } +} + void init_WifiManager() { #ifdef MONITOR_SPEED @@ -136,10 +176,6 @@ void init_WifiManager() Serial.begin(115200); #endif //MONITOR_SPEED //Serial.setTxTimeoutMs(10); - - // Check for custom AP name from flasher config, otherwise use default - String customAPName = readCustomAPName(); - const char* apName = customAPName.length() > 0 ? customAPName.c_str() : DEFAULT_SSID; //Init pin 15 to eneble 5V external power (LilyGo bug) #ifdef PIN_ENABLE5V @@ -160,6 +196,15 @@ void init_WifiManager() #endif // Explicitly set WiFi mode WiFi.mode(WIFI_STA); +#if WIFI_DISABLE_MODEM_SLEEP + WiFi.setSleep(false); +#endif + WiFi.persistent(false); + WiFi.setAutoReconnect(true); + WiFi.onEvent(onWiFiEvent); + WiFi.setTxPower((wifi_power_t)WIFI_TX_POWER_LEVEL); + Serial.printf("[WiFi] TX power level: %d\n", (int)WIFI_TX_POWER_LEVEL); + esp_event_handler_instance_register(WIFI_EVENT, WIFI_EVENT_STA_DISCONNECTED, &onWifiEventIdf, nullptr, nullptr); if (!nvMem.loadConfig(&Settings)) { @@ -195,7 +240,15 @@ void init_WifiManager() //Advanced settings wm.setConfigPortalBlocking(false); //Hacemos que el portal no bloquee el firmware wm.setConnectTimeout(40); // how long to try to connect for before continuing + wm.setConnectRetries(WIFI_CONNECT_RETRIES); wm.setConfigPortalTimeout(180); // auto close configportal after n seconds + wm.setCleanConnect(false); // Disconnect before reconnect attempts; helps avoid auth loops. + wm.setWiFiAutoReconnect(true); + if (strlen(WIFI_MANAGER_COUNTRY) == 2) + { + wm.setCountry(String(WIFI_MANAGER_COUNTRY)); + Serial.printf("[WiFi] WiFi country set to: %s\n", WIFI_MANAGER_COUNTRY); + } // wm.setCaptivePortalEnable(false); // disable captive portal redirection // wm.setAPClientCheck(true); // avoid timeout if client connected to softap //wm.setTimeout(120); @@ -208,20 +261,17 @@ void init_WifiManager() // Need to convert numerical input to string to display the default value. char convertedValue[6]; - sprintf(convertedValue, "%d", Settings.PoolPort); + snprintf(convertedValue, sizeof(convertedValue), "%d", Settings.PoolPort); // Text box (Number) - 7 characters maximum WiFiManagerParameter port_text_box_num("Poolport", "Pool port", convertedValue, 7); - // Text box (String) - 80 characters maximum - //WiFiManagerParameter password_text_box("Poolpassword", "Pool password (Optional)", Settings.PoolPassword, 80); - // Text box (String) - 80 characters maximum WiFiManagerParameter addr_text_box("btcAddress", "Your BTC address", Settings.BtcWallet, 80); // Text box (Number) - 2 characters maximum char charZone[6]; - sprintf(charZone, "%d", Settings.Timezone); + snprintf(charZone, sizeof(charZone), "%d", Settings.Timezone); WiFiManagerParameter time_text_box_num("TimeZone", "TimeZone fromUTC (-12/+12)", charZone, 3); WiFiManagerParameter features_html("

"); @@ -233,7 +283,7 @@ void init_WifiManager() } WiFiManagerParameter save_stats_to_nvs("SaveStatsToNVS", "Save mining statistics to flash memory.", "T", 2, checkboxParams, WFM_LABEL_AFTER); // Text box (String) - 80 characters maximum - WiFiManagerParameter password_text_box("Poolpassword - Optional", "Pool password", Settings.PoolPassword, 80); + WiFiManagerParameter password_text_box("Poolpassword", "Pool password (Optional)", Settings.PoolPassword, 80); // Add all defined parameters wm.addParameter(&pool_text_box); @@ -253,8 +303,8 @@ void init_WifiManager() wm.addParameter(&invertColors); #endif #if defined(ESP32_2432S028R) || defined(ESP32_2432S028_2USB) - char brightnessConvValue[2]; - sprintf(brightnessConvValue, "%d", Settings.Brightness); + char brightnessConvValue[4]; + snprintf(brightnessConvValue, sizeof(brightnessConvValue), "%d", Settings.Brightness); // Text box (Number) - 3 characters maximum WiFiManagerParameter brightness_text_box_num("Brightness", "Screen backlight Duty Cycle (0-255)", brightnessConvValue, 3); wm.addParameter(&brightness_text_box_num); @@ -268,16 +318,14 @@ void init_WifiManager() wm.setConfigPortalBlocking(true); //Hacemos que el portal SI bloquee el firmware drawSetupScreen(); mMonitor.NerdStatus = NM_Connecting; - wm.startConfigPortal(apName, DEFAULT_WIFIPW); - - if (shouldSaveConfig) + if (!wm.startConfigPortal(DEFAULT_SSID, DEFAULT_WIFIPW)) { //Could be break forced after edditing, so save new config Serial.println("failed to connect and hit timeout"); Settings.PoolAddress = pool_text_box.getValue(); Settings.PoolPort = atoi(port_text_box_num.getValue()); - strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword)); - strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); + copyCString(Settings.PoolPassword, sizeof(Settings.PoolPassword), password_text_box.getValue()); + copyCString(Settings.BtcWallet, sizeof(Settings.BtcWallet), addr_text_box.getValue()); Settings.Timezone = atoi(time_text_box_num.getValue()); //Serial.println(save_stats_to_nvs.getValue()); Settings.saveStats = (strncmp(save_stats_to_nvs.getValue(), "T", 1) == 0); @@ -302,15 +350,15 @@ void init_WifiManager() wm.setConfigPortalBlocking(true); wm.setEnableConfigPortal(true); // if (!wm.autoConnect(Settings.WifiSSID.c_str(), Settings.WifiPW.c_str())) - if (!wm.autoConnect(apName, DEFAULT_WIFIPW)) + if (!wm.autoConnect(DEFAULT_SSID, DEFAULT_WIFIPW)) { Serial.println("Failed to connect to configured WIFI, and hit timeout"); if (shouldSaveConfig) { // Save new config Settings.PoolAddress = pool_text_box.getValue(); Settings.PoolPort = atoi(port_text_box_num.getValue()); - strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword)); - strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); + copyCString(Settings.PoolPassword, sizeof(Settings.PoolPassword), password_text_box.getValue()); + copyCString(Settings.BtcWallet, sizeof(Settings.BtcWallet), addr_text_box.getValue()); Settings.Timezone = atoi(time_text_box_num.getValue()); // Serial.println(save_stats_to_nvs.getValue()); Settings.saveStats = (strncmp(save_stats_to_nvs.getValue(), "T", 1) == 0); @@ -335,7 +383,6 @@ void init_WifiManager() Serial.print("IP address: "); Serial.println(WiFi.localIP()); - // Lets deal with the user config values // Copy the string value @@ -350,12 +397,12 @@ void init_WifiManager() Serial.println(Settings.PoolPort); // Copy the string value - strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword)); + copyCString(Settings.PoolPassword, sizeof(Settings.PoolPassword), password_text_box.getValue()); Serial.print("poolPassword: "); Serial.println(Settings.PoolPassword); // Copy the string value - strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); + copyCString(Settings.BtcWallet, sizeof(Settings.BtcWallet), addr_text_box.getValue()); Serial.print("btcString: "); Serial.println(Settings.BtcWallet); @@ -378,40 +425,6 @@ void init_WifiManager() } - // Lets deal with the user config values - - // Copy the string value - Settings.PoolAddress = pool_text_box.getValue(); - //strncpy(Settings.PoolAddress, pool_text_box.getValue(), sizeof(Settings.PoolAddress)); - Serial.print("PoolString: "); - Serial.println(Settings.PoolAddress); - - //Convert the number value - Settings.PoolPort = atoi(port_text_box_num.getValue()); - Serial.print("portNumber: "); - Serial.println(Settings.PoolPort); - - // Copy the string value - strncpy(Settings.PoolPassword, password_text_box.getValue(), sizeof(Settings.PoolPassword)); - Serial.print("poolPassword: "); - Serial.println(Settings.PoolPassword); - - // Copy the string value - strncpy(Settings.BtcWallet, addr_text_box.getValue(), sizeof(Settings.BtcWallet)); - Serial.print("btcString: "); - Serial.println(Settings.BtcWallet); - - //Convert the number value - Settings.Timezone = atoi(time_text_box_num.getValue()); - Serial.print("TimeZone fromUTC: "); - Serial.println(Settings.Timezone); - - #ifdef ESP32_2432S028R - Settings.invertColors = (strncmp(invertColors.getValue(), "T", 1) == 0); - Serial.print("Invert Colors: "); - Serial.println(Settings.invertColors); - #endif - // Save the custom parameters to FS if (shouldSaveConfig) { @@ -439,6 +452,11 @@ void wifiManagerProcess() { } else { Serial.print("[Error] - current status: "); Serial.println(newStatus); + if (s_last_wifi_disc_reason != 0xFF) + { + Serial.print("[WiFi] Last disconnect reason: "); + Serial.println(s_last_wifi_disc_reason); + } } oldStatus = newStatus; }