I managed to display RGB full color bitmap from PC - actually a 8x32pixels chunk.
However the picture looks very very bright - seems like colors need calibration - I think it is contrast and saturation.
I must check that later
Here is the code that may help to experiment with SPI and WS281B matrix:
spi_bus_config_t buscfg={
.flags = SPICOMMON_BUSFLAG_MASTER | SPICOMMON_BUSFLAG_MOSI | SPICOMMON_BUSFLAG_SCLK,
.miso_io_num = -1,
.mosi_io_num = PIN_NUM_MOSI,
.sclk_io_num = PIN_NUM_CLK, // - not used !
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = 0
};
spi_device_interface_config_t devcfg={
.clock_speed_hz = 2.86*1000*1000, // 1,000,000 / 0.35us ( 2,857,142.857142... ~ 2.86Mhz)
.mode = 0,
.spics_io_num = -1,
.duty_cycle_pos = 255,
.queue_size = 1,
.pre_cb = 0,
.flags = 0
};
ESP_ERROR_CHECK( spi_bus_initialize(HSPI_HOST, &buscfg, 1) );
ESP_ERROR_CHECK( spi_bus_add_device(HSPI_HOST, &devcfg, &spi) );
Transmission code:
const int stride=DISPLAY_WIDTH*3;
const int n_block_size = DISPLAY_WIDTH*DISPLAY_HEIGHT*3;
static uint8_t* data = NULL;
static uint8_t* pixels = NULL;
static spi_transaction_t t =
{
.addr = 0,
.cmd = 0,
.flags = 0,
.length = 0,
.rxlength = 0,
.user = NULL,
.rx_buffer = NULL,
.tx_buffer = NULL
};
if(data==NULL) data = (uint8_t*)malloc(n_block_size);
if(pixels==NULL) pixels = (uint8_t*)malloc(n_block_size*12);
// HERE LOADYOUR RGB BITMAP TO *data BUFFER
t.length=32*8 * 12*8;
t.tx_buffer=pixels;
int x=0;
for(int offset=0; offset<stride;)
{
for(int row=7; row>=0; row--)
{
int n = (row*stride) + offset;
uint32_t pixel = (((uint32_t)data[n+1])<<16) | (((uint32_t)data[n+2])<<8) | ((uint32_t)data[n]);
// 210 - byte order in data
// RGB
// GRB
for(int k=23; k>0; k-=2)
pixels[x++] = (((pixel>>(k-1))&1) ? 0x0E : 0x08) | (((pixel>>k)&1) ? 0xE0 : 0x80 );
//pixels[x++] = (((pixel>>(k-1))&1) ? 0b1110 : 0b1000) | (((pixel>>k)&1) ? 0b11100000 : 0b10000000 );
}
offset+=3;
for(int row=0; row<8; row++)
{
int n = (row*stride) + offset;
uint32_t pixel = (((uint32_t)data[n+1])<<16) | (((uint32_t)data[n+2])<<8) | ((uint32_t)data[n]);
for(int k=23; k>0; k-=2)
pixels[x++] = (((pixel>>(k-1))&1) ? 0x0E : 0x08) | (((pixel>>k)&1) ? 0xE0 : 0x80 );
}
offset+=3;
}
This is for zigzag 8*32 led matrix (going from 8-down to next 8-up left to right pixels)
It works good but maybe there is some catch with colors. It uses 2 color bits per 1 byte so 12bytes gives a 24bit RGB (GRB) pixel
If anyone experiments - please share the results