diff --git a/index.html b/index.html index e686b13..7e28015 100644 --- a/index.html +++ b/index.html @@ -290,6 +290,13 @@ +
+
+
+ + Uses uint8_t instead of unsigned char and drops PROGMEM, which is a no-op on ESP32. +
+
diff --git a/js/script.js b/js/script.js index bf1249e..c35e454 100644 --- a/js/script.js +++ b/js/script.js @@ -22,6 +22,7 @@ const settings = { outputComments: true, invertColors: false, rotation: 0, + esp32Format: false, }; function bitswap(b) { @@ -432,6 +433,13 @@ function hexToBinary(s) { return { valid: true, result: ret }; } +// The plain byte type, independent of drawMode (used by output formats, +// like adafruit_gfx, that are always byte-packed regardless of the current +// conversion function). +function getByteType() { + return settings.esp32Format ? 'uint8_t' : 'unsigned char'; +} + // get the type (in arduino code) of the output image // this is a bit of a hack, it's better to make this a property of the conversion function (should probably turn it into objects) function getImageType() { @@ -440,7 +448,14 @@ function getImageType() { } if (settings.conversionFunction === ConversionFunctions.horizontal888) { return 'unsigned long'; } - return 'unsigned char'; + return getByteType(); +} + +// PROGMEM is an AVR-ism: it's a no-op on ESP32 (flash is memory-mapped +// there), so the ESP32 output toggle drops it instead of emitting a keyword +// that does nothing. +function progmemKeyword() { + return settings.esp32Format ? '' : ' PROGMEM'; } // Use the horizontally oriented list to draw the image @@ -870,7 +885,7 @@ function generateOutputString() { const varname = getIdentifier() + (image.glyph ? `_${image.glyph.replace(/[^a-zA-Z0-9]/g, '_')}` : ''); varQuickArray.push(varname); - code = `${comment}const ${getImageType()} ${varname} [] PROGMEM = {\n${code}};\n`; + code = `${comment}const ${getImageType()} ${varname} []${progmemKeyword()} = {\n${code}};\n`; outputString += code; }); @@ -879,7 +894,8 @@ function generateOutputString() { outputString += '\n'; } if (settings.outputComments) { - outputString += `// Array of all bitmaps for convenience. (Total bytes used to store images in PROGMEM = ${bytesUsed})\n`; + const storageNote = settings.esp32Format ? '' : ' in PROGMEM'; + outputString += `// Array of all bitmaps for convenience. (Total bytes used to store images${storageNote} = ${bytesUsed})\n`; } outputString += `const int ${getIdentifier()}_allArray_LEN = ${varQuickArray.length};\n`; outputString += `const ${getImageType()}* ${getIdentifier()}_allArray[${varQuickArray.length}] = {\n\t${varQuickArray.join(',\n\t')}\n};\n`; @@ -899,7 +915,7 @@ function generateOutputString() { outputString = `const ${getImageType()} ${ getIdentifier() - } [] PROGMEM = {` + } []${progmemKeyword()} = {` + `\n${outputString}\n};`; break; } @@ -918,14 +934,14 @@ function generateOutputString() { }); outputString = outputString.replace(/,\s*$/, ''); - outputString = `const unsigned char ${ + outputString = `const ${getByteType()} ${ getIdentifier() }Bitmap` - + ' [] PROGMEM = {' + + ` []${progmemKeyword()} = {` + `\n${outputString}\n};\n\n` + `const GFXbitmapGlyph ${ getIdentifier() - }Glyphs [] PROGMEM = {\n`; + }Glyphs []${progmemKeyword()} = {\n`; let firstAschiiChar = document.getElementById('first-ascii-char').value; const xAdvance = parseInt(document.getElementById('x-advance').value); @@ -955,7 +971,7 @@ function generateOutputString() { // GFXbitmapFont outputString += `\nconst GFXbitmapFont ${ getIdentifier() - }Font PROGMEM = {\n` + }Font${progmemKeyword()} = {\n` + `\t(uint8_t *)${ getIdentifier()}Bitmap,\n` + `\t(GFXbitmapGlyph *)${ diff --git a/tests/golden/output_adafruit_gfx_esp32.txt b/tests/golden/output_adafruit_gfx_esp32.txt new file mode 100644 index 0000000..dc7d45a --- /dev/null +++ b/tests/golden/output_adafruit_gfx_esp32.txt @@ -0,0 +1,19 @@ +const uint8_t epd_bitmapBitmap [] = { + // 'test_pattern', 32x24px + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x0f, 0x0f, 0x7f, 0xff, 0x0f, 0x0f, 0xbf, 0xff, 0x0f, 0x0f, 0xdf, 0xff, 0x0f, 0x0f, 0xef, 0xff, + 0x0f, 0x0f, 0xf7, 0xff, 0x0f, 0x0f, 0xfb, 0xff, 0x0f, 0x0f, 0xfd, 0xff, 0x0f, 0x0f, 0xfe, 0xff, + 0x0f, 0x0f, 0xff, 0x7f, 0x0f, 0x0f, 0xff, 0xbf, 0x0f, 0x0f, 0xff, 0xdf, 0x0f, 0x0f, 0xff, 0xee +}; + +const GFXbitmapGlyph epd_bitmapGlyphs [] = { + { 0, 32, 24, 0, '0' }// 'test_pattern' +}; + +const GFXbitmapFont epd_bitmapFont = { + (uint8_t *)epd_bitmapBitmap, + (GFXbitmapGlyph *)epd_bitmapGlyphs, + 1 +}; diff --git a/tests/golden/output_arduino_esp32.txt b/tests/golden/output_arduino_esp32.txt new file mode 100644 index 0000000..450b6d2 --- /dev/null +++ b/tests/golden/output_arduino_esp32.txt @@ -0,0 +1,15 @@ +// 'test_pattern', 32x24px +const uint8_t epd_bitmap_test_pattern [] = { + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x0f, 0x0f, 0x7f, 0xff, 0x0f, 0x0f, 0xbf, 0xff, 0x0f, 0x0f, 0xdf, 0xff, 0x0f, 0x0f, 0xef, 0xff, + 0x0f, 0x0f, 0xf7, 0xff, 0x0f, 0x0f, 0xfb, 0xff, 0x0f, 0x0f, 0xfd, 0xff, 0x0f, 0x0f, 0xfe, 0xff, + 0x0f, 0x0f, 0xff, 0x7f, 0x0f, 0x0f, 0xff, 0xbf, 0x0f, 0x0f, 0xff, 0xdf, 0x0f, 0x0f, 0xff, 0xee +}; + +// Array of all bitmaps for convenience. (Total bytes used to store images = 112) +const int epd_bitmap_allArray_LEN = 1; +const uint8_t* epd_bitmap_allArray[1] = { + epd_bitmap_test_pattern +}; diff --git a/tests/golden/output_arduino_esp32_565.txt b/tests/golden/output_arduino_esp32_565.txt new file mode 100644 index 0000000..e41ec4f --- /dev/null +++ b/tests/golden/output_arduino_esp32_565.txt @@ -0,0 +1,57 @@ +// 'test_pattern', 32x24px +const uint16_t epd_bitmap_test_pattern [] = { + 0xf800, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, 0xffff, 0xffff, 0x0000, 0x0000, + 0x0000, 0x1082, 0x2104, 0x3186, 0x4228, 0x52aa, 0x632c, 0x73ae, 0x8c51, 0x9cd3, 0xad55, 0xbdd7, 0xce79, 0xdefb, 0xef7d, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, + 0xf800, 0xf800, 0xf800, 0xf800, 0x07e0, 0x07e0, 0x07e0, 0x07e0, 0x001f, 0x001f, 0x001f, 0x001f, 0xffff, 0xffff, 0xffff, 0xffff, + 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x0000, 0xffff, 0xffff, 0xffff, 0x001f +}; + +// Array of all bitmaps for convenience. (Total bytes used to store images = 784) +const int epd_bitmap_allArray_LEN = 1; +const uint16_t* epd_bitmap_allArray[1] = { + epd_bitmap_test_pattern +}; diff --git a/tests/golden/output_arduino_single_esp32.txt b/tests/golden/output_arduino_single_esp32.txt new file mode 100644 index 0000000..400c530 --- /dev/null +++ b/tests/golden/output_arduino_single_esp32.txt @@ -0,0 +1,9 @@ +const uint8_t epd_bitmap [] = { + // 'test_pattern', 32x24px + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x33, 0x33, 0x00, 0xff, 0x33, 0x33, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, 0xcc, 0xcc, 0x00, 0xff, + 0x0f, 0x0f, 0x7f, 0xff, 0x0f, 0x0f, 0xbf, 0xff, 0x0f, 0x0f, 0xdf, 0xff, 0x0f, 0x0f, 0xef, 0xff, + 0x0f, 0x0f, 0xf7, 0xff, 0x0f, 0x0f, 0xfb, 0xff, 0x0f, 0x0f, 0xfd, 0xff, 0x0f, 0x0f, 0xfe, 0xff, + 0x0f, 0x0f, 0xff, 0x7f, 0x0f, 0x0f, 0xff, 0xbf, 0x0f, 0x0f, 0xff, 0xdf, 0x0f, 0x0f, 0xff, 0xee +}; \ No newline at end of file diff --git a/tests/test_conversions.py b/tests/test_conversions.py index 59d856d..2a4cffe 100644 --- a/tests/test_conversions.py +++ b/tests/test_conversions.py @@ -45,6 +45,7 @@ BASE_SETTINGS = { "bitswap": False, "prefix": "0x", "separator": ", ", + "esp32Format": False, } OUTPUT_FORMAT_IDS = { @@ -64,6 +65,18 @@ SCENARIOS = [ ("output_arduino", {"outputFormat": "arduino"}, None), ("output_arduino_single", {"outputFormat": "arduino_single"}, None), ("output_adafruit_gfx", {"outputFormat": "adafruit_gfx"}, None), + ("output_arduino_esp32", {"outputFormat": "arduino", "esp32Format": True}, None), + ( + "output_arduino_single_esp32", + {"outputFormat": "arduino_single", "esp32Format": True}, + None, + ), + ("output_adafruit_gfx_esp32", {"outputFormat": "adafruit_gfx", "esp32Format": True}, None), + ( + "output_arduino_esp32_565", + {"outputFormat": "arduino", "drawMode": "horizontal565", "esp32Format": True}, + None, + ), ("invert_colors", {"invertColors": True}, None), ("flip_horizontal", {"flipHorizontally": True}, None), ("flip_vertical", {"flipVertically": True}, None), @@ -194,6 +207,10 @@ def apply_settings(page, settings): set_checkbox(page, "#bitswap", settings["bitswap"]) page.fill("#prefix", settings["prefix"]) page.fill("#separator", settings["separator"]) + # esp32Format checkbox only exists in the DOM (visible) for non-plain + # output formats; plain output has no type/PROGMEM declarations to affect. + if settings["outputFormat"] != "plain": + set_checkbox(page, "#esp32Format", settings["esp32Format"]) def set_checkbox(page, selector, checked):