emgoz / HUB08SPI

An Arduino Uno library for LED Matrices using the HUB08 Interface
MIT License
26 stars 8 forks source link

Port for ESP8266 #4

Open a1aw opened 7 years ago

a1aw commented 7 years ago

Hi,

I am trying to port the code for ESP8266. Do you have any schematics about the HUB08's LED Matrix boards? Or how you control the board?

I don't understand the following code. What I understand has commented below.

uint16_t r = -2000;  //timeout ??
while (!(PIND & (1<<3)) && ++r); //?? Wait for OE to LOW?
uint8_t t = (PIND & 0x0F) | (row <<4); //?? Select row by binary? e.g. 1 -> A or 3 -> A,B or 5 -> A,C?
PORTD = t;
PIND = 1<<2;  //toggle latch?? PIND does not allow to write. How you toggle the latch here?
PIND = 1<<2;
row = (row + 1) & 0x0F; //?? Why 0x0F is necessary here?

Any help would be appreciated. Thanks!

emgoz commented 7 years ago

Ok, I hope I can answer your questions. It's been a while since I write this code.

uint16_t r = -2000;  //timeout. If something is wrong with the connection, we do not want to wait forever. This value is incremented each cycle of the blocking wait - while loop to bail out evantually, when OE never goes HIGH.

while (!(PIND & (1<<3)) && ++r); // Wait for OE to go HIGH or Timeout (r == 0)

uint8_t t = (PIND & 0x0F) | (row <<4); //?? Select row by binary? e.g. 1 -> A or 3 -> A,B or 5 -> A,C? yes, exactly. I shift row by 4 and or it to the output to make row appear on the upper half of Port D. the lower half must remain the same.

PORTD = t;

PIND = 1<<2;  //toggle latch. It's a lesser known feature of the atmega controllers. Writing to PINx toggles the output in only one processor cycle

PIND = 1<<2;

row = (row + 1) & 0x0F; // Everytime this function is called, it scans the next line. Lines only range from 0 to 15. "& 0xF" equals "% 16", so it wraps back to 0 after reaching 15.