Skip to content

Commit

Permalink
Support for RGBW and parallel led data lanes
Browse files Browse the repository at this point in the history
  • Loading branch information
bitluni committed Jun 18, 2020
1 parent 222d953 commit a939653
Show file tree
Hide file tree
Showing 17 changed files with 566 additions and 60 deletions.
5 changes: 0 additions & 5 deletions .vscode/arduino.json

This file was deleted.

17 changes: 0 additions & 17 deletions .vscode/c_cpp_properties.json

This file was deleted.

8 changes: 0 additions & 8 deletions .vscode/settings.json

This file was deleted.

16 changes: 14 additions & 2 deletions Utilities/SpriteEditor.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@
var rf, rshift, gf, gshift, bf, bshift, af, ashift, type, bytesPerPixel;
switch(pixelformat)
{
case "R8G8B8A8":
{
rf = gf = bf = af = 255.;
rshift = 0;
gshift = 8;
bshift = 16;
ashift = 24;
type = "unsigned long";
bytesPerPixel = 4;
break;
}
case "R2G2B2A2":
{
rf = gf = bf = af = 3.;
Expand Down Expand Up @@ -274,8 +285,8 @@
var b = s[j + 2];
var a = s[j + 3];
var c = 0;
c = (Math.round(r / 255. * rf) << rshift) + (Math.round(g / 255. * gf) << gshift) + (Math.round(b / 255. * bf) << bshift) + (Math.round(a / 255. * af) << ashift);
text += c + ", ";
c = ((Math.round(r / 255. * rf) << rshift) + (Math.round(g / 255. * gf) << gshift) + (Math.round(b / 255. * bf) << bshift) + (Math.round(a / 255. * af) << ashift)) >>> 0;
text += "0x" + c.toString(16) + ", ";
k++;
if((k & 31) == 0)
text += "\n";
Expand Down Expand Up @@ -601,6 +612,7 @@ <h1>bitluni's Sprite Editor</h1>
<input id="addimages" type="file" onchange="addFiles(event)" accept="image/*" multiple hidden>
<button title="Export sprite header" onclick="saveHeader();" style="font-size: 15px; font-weight:bold">.h</button>
<select id="pixelformat" title="Export pixel format">
<option vlaue="R8G8B8A8">R8G8B8A8</option>
<option vlaue="R2G2B2A2">R2G2B2A2</option>
<option vlaue="R5G5B4A2">R5G5B4A2</option>
<option vlaue="R4G4B4A4">R4G4B4A4</option>
Expand Down
14 changes: 14 additions & 0 deletions src/Composite/Composite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ bool Composite::init(const ModeComposite &mode, const int *pinMap, const int bit
return true;
}

void Composite::getClockSetting(long *sampleRate, int *n, int *a, int *b, int *div)
{
if(sampleRate)
*sampleRate = mode.pixelClock;
if(n)
*n = 2;
if(a)
*a = 1;
if(b)
*b = 0;
if(div)
*div = 6;
}

int Composite::burst(int sampleNumber, bool even)
{
return blankLevel;
Expand Down
1 change: 1 addition & 0 deletions src/Composite/Composite.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Composite : public I2S
virtual void allocateLineBuffers() = 0;
virtual void allocateLineBuffers(void **frameBuffer);
virtual void propagateResolution(const int xres, const int yres) = 0;
virtual void getClockSetting(long *sampleRate, int *n, int *a, int *b, int *div);

protected:
virtual void interrupt();
Expand Down
2 changes: 2 additions & 0 deletions src/ESP32Lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <Composite/CompositePAL8.h>

#include <LED/SerialLED.h>
#include <LED/ParallelLED.h>
#include <LED/ParallelLEDGraphics.h>

#include <Graphics/Sprites.h>
#include <Graphics/Mesh.h>
Expand Down
74 changes: 74 additions & 0 deletions src/Graphics/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,80 @@ class Graphics: public ImageDrawer
return RGBA(r, g, b, a);
}

virtual Color R4G4B4A4ToColor(unsigned short c)
{
int r = (((c << 1) & 0x1e) * 255 + 1) / 0x1e;
int g = (((c >> 3) & 0x1e) * 255 + 1) / 0x1e;
int b = (((c >> 7) & 0x1e) * 255 + 1) / 0x1e;
int a = (((c >> 11) & 0x1e) * 255 + 1) / 0x1e;
return RGBA(r, g, b, a);
}

virtual Color R8G8B8A8ToColor(unsigned long c)
{
return RGBA(c & 255, (c >> 8) & 255, (c >> 16) & 255, (c >> 24) & 255);
}

virtual void imageR8G8B8A8(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
for (int py = 0; py < srcYres; py++)
{
int i = srcX + (py + srcY) * image.xres;
for (int px = 0; px < srcXres; px++)
dot(px + x, py + y, R8G8B8A8ToColor(((unsigned long*)image.pixels)[i++]));
}
}

virtual void imageAddR8G8B8A8(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
for (int py = 0; py < srcYres; py++)
{
int i = srcX + (py + srcY) * image.xres;
for (int px = 0; px < srcXres; px++)
dotAdd(px + x, py + y, R8G8B8A8ToColor(((unsigned long*)image.pixels)[i++]));
}
}

virtual void imageMixR8G8B8A8(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
for (int py = 0; py < srcYres; py++)
{
int i = srcX + (py + srcY) * image.xres;
for (int px = 0; px < srcXres; px++)
dotMix(px + x, py + y, R8G8B8A8ToColor(((unsigned long*)image.pixels)[i++]));
}
}

virtual void imageR4G4B4A4(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
for (int py = 0; py < srcYres; py++)
{
int i = srcX + (py + srcY) * image.xres;
for (int px = 0; px < srcXres; px++)
dot(px + x, py + y, R4G4B4A4ToColor(((unsigned short*)image.pixels)[i++]));
}
}

virtual void imageAddR4G4B4A4(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
for (int py = 0; py < srcYres; py++)
{
int i = srcX + (py + srcY) * image.xres;
for (int px = 0; px < srcXres; px++)
dotAdd(px + x, py + y, R4G4B4A4ToColor(((unsigned short*)image.pixels)[i++]));
}
}

virtual void imageMixR4G4B4A4(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
for (int py = 0; py < srcYres; py++)
{
int i = srcX + (py + srcY) * image.xres;
for (int px = 0; px < srcXres; px++)
dotMix(px + x, py + y, R4G4B4A4ToColor(((unsigned short*)image.pixels)[i++]));
}
}

virtual void imageR5G5B4A2(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
for (int py = 0; py < srcYres; py++)
Expand Down
42 changes: 42 additions & 0 deletions src/Graphics/ImageDrawer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,35 @@
class ImageDrawer
{
public:
virtual void imageR8G8B8A8(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageAddR8G8B8A8(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageMixR8G8B8A8(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageR5G5B4A2(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageAddR5G5B4A2(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageMixR5G5B4A2(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageR2G2B2A2(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageAddR2G2B2A2(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageMixR2G2B2A2(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageR4G4B4A4(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageAddR4G4B4A4(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;
virtual void imageMixR4G4B4A4(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres) = 0;

void image(Image &image, int x, int y, int srcX, int srcY, int srcXres, int srcYres)
{
switch(image.pixelFormat)
{
case Image::R8G8B8A8:
imageR8G8B8A8(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R5G5B4A2:
imageR5G5B4A2(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R2G2B2A2:
imageR2G2B2A2(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R4G4B4A4:
imageR4G4B4A4(image, x, y, srcX, srcY, srcXres, srcYres);
break;
default:
break;
}
Expand All @@ -40,12 +52,18 @@ class ImageDrawer
{
switch(image.pixelFormat)
{
case Image::R8G8B8A8:
imageAddR8G8B8A8(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R5G5B4A2:
imageAddR5G5B4A2(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R2G2B2A2:
imageAddR2G2B2A2(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R4G4B4A4:
imageAddR4G4B4A4(image, x, y, srcX, srcY, srcXres, srcYres);
break;
default:
break;
}
Expand All @@ -55,12 +73,18 @@ class ImageDrawer
{
switch(image.pixelFormat)
{
case Image::R8G8B8A8:
imageMixR8G8B8A8(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R5G5B4A2:
imageMixR5G5B4A2(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R2G2B2A2:
imageMixR2G2B2A2(image, x, y, srcX, srcY, srcXres, srcYres);
break;
case Image::R4G4B4A4:
imageMixR4G4B4A4(image, x, y, srcX, srcY, srcXres, srcYres);
break;
default:
break;
}
Expand All @@ -70,12 +94,18 @@ class ImageDrawer
{
switch(image.pixelFormat)
{
case Image::R8G8B8A8:
imageR8G8B8A8(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R5G5B4A2:
imageR5G5B4A2(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R2G2B2A2:
imageR2G2B2A2(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R4G4B4A4:
imageR4G4B4A4(image, x, y, 0, 0, image.xres, image.yres);
break;
default:
break;
}
Expand All @@ -85,12 +115,18 @@ class ImageDrawer
{
switch(image.pixelFormat)
{
case Image::R8G8B8A8:
imageAddR8G8B8A8(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R5G5B4A2:
imageAddR5G5B4A2(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R2G2B2A2:
imageAddR2G2B2A2(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R4G4B4A4:
imageAddR4G4B4A4(image, x, y, 0, 0, image.xres, image.yres);
break;
default:
break;
}
Expand All @@ -100,12 +136,18 @@ class ImageDrawer
{
switch(image.pixelFormat)
{
case Image::R8G8B8A8:
imageMixR8G8B8A8(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R5G5B4A2:
imageMixR5G5B4A2(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R2G2B2A2:
imageMixR2G2B2A2(image, x, y, 0, 0, image.xres, image.yres);
break;
case Image::R4G4B4A4:
imageMixR4G4B4A4(image, x, y, 0, 0, image.xres, image.yres);
break;
default:
break;
}
Expand Down
31 changes: 24 additions & 7 deletions src/I2S/I2S.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ bool I2S::useInterrupt()
return false;
};

void I2S::getClockSetting(long *sampleRate, int *n, int *a, int *b, int *div)
{
if(sampleRate)
*sampleRate = 2000000;
if(n)
*n = 2;
if(a)
*a = 1;
if(b)
*b = 0;
if(div)
*div = 1;
}


bool I2S::initParallelInputMode(const int *pinMap, long sampleRate, const int bitCount, int wordSelect, int baseClock)
{
volatile i2s_dev_t &i2s = *i2sDevices[i2sIndex];
Expand Down Expand Up @@ -223,7 +238,7 @@ bool I2S::initParallelOutputMode(const int *pinMap, long sampleRate, const int b
{
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pinMap[i]], PIN_FUNC_GPIO);
gpio_set_direction((gpio_num_t)pinMap[i], (gpio_mode_t)GPIO_MODE_DEF_OUTPUT);
rtc_gpio_set_drive_capability((gpio_num_t)pinMap[i], (gpio_drive_cap_t)GPIO_DRIVE_CAP_3 );
//rtc_gpio_set_drive_capability((gpio_num_t)pinMap[i], (gpio_drive_cap_t)GPIO_DRIVE_CAP_3 );
if(i2sIndex == 1)
{
if(bitCount == 16)
Expand Down Expand Up @@ -265,7 +280,9 @@ bool I2S::initParallelOutputMode(const int *pinMap, long sampleRate, const int b
i2s.sample_rate_conf.val = 0;
i2s.sample_rate_conf.tx_bits_mod = bitCount;
//clock setup

int clockN = 2, clockA = 1, clockB = 0, clockDiv = 1;
if(sampleRate == 0)
getClockSetting(&sampleRate, &clockN, &clockA, &clockB, &clockDiv);
if(sampleRate > 0)
{
//xtal is 40M
Expand Down Expand Up @@ -299,11 +316,11 @@ bool I2S::initParallelOutputMode(const int *pinMap, long sampleRate, const int b
}

i2s.clkm_conf.val = 0;
i2s.clkm_conf.clka_en = 1;
i2s.clkm_conf.clkm_div_num = 2; //clockN;
i2s.clkm_conf.clkm_div_a = 1; //clockA;
i2s.clkm_conf.clkm_div_b = 0; //clockB;
i2s.sample_rate_conf.tx_bck_div_num = 1;//1;
i2s.clkm_conf.clka_en = sampleRate > 0 ? 1 : 0;
i2s.clkm_conf.clkm_div_num = clockN;
i2s.clkm_conf.clkm_div_a = clockA;
i2s.clkm_conf.clkm_div_b = clockB;
i2s.sample_rate_conf.tx_bck_div_num = clockDiv;

i2s.fifo_conf.val = 0;
i2s.fifo_conf.tx_fifo_mod_force_en = 1;
Expand Down
1 change: 1 addition & 0 deletions src/I2S/I2S.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class I2S

void allocateDMABuffers(int count, int bytes);
void deleteDMABuffers();
virtual void getClockSetting(long *sampleRate, int *n, int *a, int *b, int *div);

protected:
virtual void interrupt() = 0;
Expand Down
Loading

0 comments on commit a939653

Please sign in to comment.