Created
May 5, 2016 00:04
-
-
Save sonyhome/6eb46c623a33e6aa395a0879f7ed848e to your computer and use it in GitHub Desktop.
Attempt to vectorize memory access while writing pixels to 8 ports.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<FAB_TDEF> | |
inline void | |
avrBitbangLedStrip<FAB_TVAR>::eightPortSoftwareSendBytes(const uint16_t count, const uint8_t * array) | |
{ | |
const uint16_t blockSize = count / 8; | |
uint8_t r0 __asm__("r2") = 0; | |
uint8_t r1 __asm__("r3") = 0; | |
uint8_t r2 __asm__("r4") = 0; | |
uint8_t r3 __asm__("r5") = 0; | |
uint8_t r4 __asm__("r6") = 0; | |
uint8_t r5 __asm__("r7") = 0; | |
uint8_t r6 __asm__("r8") = 0; | |
uint8_t r7 __asm__("r9") = 0; | |
for(register uint16_t c = 0; c < blockSize + 8; c++) { | |
for(register int8_t b = 7; b >= 0; b--) { | |
uint8_t bitmask __asm__("r10"); | |
// bitmask |= r0 & 1 ; r0 >>= 1; | |
// bitmask |= (r1 & 1) << 1; r1 >>= 1; | |
// bitmask |= (r2 & 1) << 2; r2 >>= 1; | |
// bitmask |= (r3 & 1) << 3; r3 >>= 1; | |
// bitmask |= (r4 & 1) << 4; r4 >>= 1; | |
// bitmask |= (r5 & 1) << 5; r5 >>= 1; | |
bitmask |= (r6 & 1) << 6; r6 >>= 1; | |
bitmask |= (r7 & 1) << 7; r7 >>= 1; | |
// Load ONE byte per iter. | |
// Skip end condition check to reduce CPU cycles. | |
// It is expected that the LED strip won't have extra pixels. | |
switch (b) { | |
/* | |
case 0: | |
// if (c < blockSize) | |
r0 = array[c]; | |
break; | |
case 1: | |
// if (c < blockSize+1) | |
r1 = array[c + 1 * blockSize]; | |
break; | |
case 2: | |
r2 = array[c + 2 * blockSize]; | |
break; | |
case 3: | |
r3 = array[c + 3 * blockSize]; | |
break; | |
case 4: | |
r4 = array[c + 4 * blockSize]; | |
break; | |
case 5: | |
r5 = array[c + 5 * blockSize]; | |
break; | |
*/ | |
case 6: | |
r6 = array[c + 6 * blockSize]; | |
break; | |
case 7: | |
r7 = array[c + 7 * blockSize]; | |
break; | |
} | |
// Set all HIGH, set LOW all zeros, set LOW zeros and ones. | |
FAB_PORT(dataPortId, 0xFF); | |
DELAY_CYCLES(4); //high0 - sbiCycles); | |
// FAB_PORT(dataPortId, bitmask); | |
AVR_PORT(dataPortId) &= bitmask; | |
DELAY_CYCLES(4); //high1 - sbiCycles - high0); | |
FAB_PORT(dataPortId, 0x00); | |
// Let's assume we'll spend enough time doing math to not need to wait | |
//DELAY_CYCLES(20); //low0 - cbiCycles); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment