MCPcopy Create free account
hub / github.com/2dom/PxMatrix / writeRegister

Method writeRegister

PxMatrix.h:421–479  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419}
420#else
421inline void PxMATRIX::writeRegister(uint16_t reg_value, uint8_t reg_position)
422{
423 if (_driver_chip == FM6124 || _driver_chip == FM6126A){
424
425 if (_driver_chip == FM6124) {
426 Serial.println("\nFM6124 - REG: " + String(reg_position));
427 } else {
428 Serial.println("\nFM6126A - REG: " + String(reg_position));
429 }
430
431 // All FM6126A code is based on the excellent guesswork by shades66 in https://github.com/hzeller/rpi-rgb-led-matrix/issues/746
432 // Register 12 - brightness/gain settings, three 6bit values, aaaaaabbbbbbcccccc a= darkness?
433 // seems to add red to the background when the leds are off, b=main brightness c=finer brightness
434 // (i'm not sure if b & c are actually as 12 bit value but with b set to all 1's the value in c doesn't seem to make much difference)
435
436 // Register 13 - not sure what it's doing yet, just that 1 specific bit within seems to be an overall enable function.
437
438 // Now set all the values at the top to the same value for each of register 12/13 to get the same settings across the panel, the current code loads different settings into each 32 columns.
439 // clocking in the register is simply clocking in the value (i've 2 panels so 128bits of data) and for the last 12/13 bits depending on the register setting the latch to high. the final drop of latch to low clocks in the configuration. this is done by sending the same value to r1/r2/g1/g2/b1/b2 at the same time to load the config into all the FM6126 chips
440
441 // Some necessary magic bit fields
442 // b12 - 1 adds red tinge
443 // b12 - 9/8/7/6/5 = 4 bit brightness
444 // b13 - 9 =1 screen on
445 // b13 - 6 =1 screen off
446 pinMode(_SPI_CLK,OUTPUT);
447 pinMode(_SPI_MOSI,OUTPUT);
448 digitalWrite(_SPI_CLK,HIGH); // CCK LOW
449 digitalWrite(_OE_PIN,LOW);
450 digitalWrite(_LATCH_PIN,HIGH);
451 digitalWrite(_A_PIN,HIGH);
452 digitalWrite(_B_PIN,LOW);
453 digitalWrite(_C_PIN,LOW);
454 digitalWrite(_D_PIN,LOW);
455
456 uint8_t reg_bit=0;
457 for (uint32_t bit_counter=0; bit_counter < _send_buffer_size*8; bit_counter++)
458 {
459 reg_bit=bit_counter%16;
460 if ((reg_value>>reg_bit)&1)
461 digitalWrite(_SPI_MOSI,HIGH);
462 else
463 digitalWrite(_SPI_MOSI,LOW);
464
465 delay(1);
466 digitalWrite(_SPI_CLK,LOW); // CLK HIGH
467 delay(1);
468 digitalWrite(_SPI_CLK,HIGH); // CLK LOW
469 delay(1);
470 if ((bit_counter == (_send_buffer_size*8 - reg_position-1)))
471 {
472 digitalWrite(_LATCH_PIN,LOW);
473 }
474 }
475 digitalWrite(_LATCH_PIN,HIGH);
476 }
477 digitalWrite(_OE_PIN,HIGH);
478

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected