Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sendSerial() {
- uint32_t nBitsSent = 0;
- /* Padding: we need to pre-pad
- We will send 15 12-bit values (180 bits) which is 22.5 8-bit SPI 8-bit bytes
- For every TLC5490 we actually need to send 16 12-bit values (192 bits in total)
- because that's what the TLC5490 serial comms expect.
- Since we are using only 15 of the output lines,
- the 16th value is unnecessary (we are not using OUT15)
- We also need to pad for the extra nibble (22.5 SPI above)
- So if we start by sending the empty 12-bit value, we are OK
- This padding needs to be done for every chip
- */
- //~ padSPI(0);
- SPDR = 0; // First 8 bits of the empty 12-bit data
- while(!(SPSR & (1<<SPIF))) {
- // Wait for the transfer to finish
- }
- SPDR = 0; // Last 4 bits of the empty 12-bit data
- // plus the empty 4 high bits of the first intensity data
- while(!(SPSR & (1<<SPIF))) {
- // Wait for the transfer to finish
- }
- nBitsSent += 16;
- uint8_t idxNextSendType = 2; // The next send type is type 2
- // so we indicate that
- // Different curColDatas are not implemented yet
- //~ uint8_t * curColData = nColumnData[idxUnit];
- uint8_t idxChannel = 0;
- uint8_t nPixelsSent = 0;
- uint8_t dataByte = (idxChannel==0)?0xFF:0x00;
- uint8_t toSPDR = dataByte;
- for (;;) { // Send bytes loop
- SPDR = toSPDR; // Send the byte
- nBitsSent += 8;
- while(!(SPSR & (1<<SPIF))) {
- // Wait for the transfer to finish
- }
- #define PADDING
- #ifdef PADDING
- if (nBitsSent % 192 == 0) {
- if (nBitsSent >= 192 *3)
- break;
- SPDR = 0; // First 8 bits of the empty 12-bit data
- while(!(SPSR & (1<<SPIF))) {
- // Wait for the transfer to finish
- }
- SPDR = 0; // Last 4 bits of the empty 12-bit data
- // plus the empty 4 high bits of the first intensity data
- while(!(SPSR & (1<<SPIF))) {
- // Wait for the transfer to finish
- }
- idxNextSendType = 1; // It will get incremented first
- // so the first byte will actually be
- // idxNextSendType = 2
- nBitsSent += 16;
- }
- #endif
- // Update the send type
- if (++idxNextSendType>2) { idxNextSendType = 0; }
- //~ ++idxNextSendType %= 4;
- // Prepare the next one for loading
- if (idxNextSendType==1) {
- // Case 1: Need to send the low nibble + padding
- toSPDR = dataByte<<4;
- } else {
- // Either way we need another new data in dataByte
- //
- if (idxChannel==0) {
- // Load next palette index
- nPixelsSent++;
- }
- dataByte = (idxChannel==0)?0xFF:0x00;
- if (++idxChannel>2) idxChannel = 0;
- //~ This fails: ++idxChannel %= 3;
- if (idxNextSendType) {
- // idxSendType == 2
- // Case 2: Need to send pure data
- toSPDR = dataByte;
- } else {
- // idxSendType == 0
- // Case 0: Need to send padding + high nibble
- toSPDR = dataByte >> 4;
- }
- }
- while(!(SPSR & (1<<SPIF))) // Wait for the transfer to finish
- ;
- } // End of send bytes loop
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement