void shiftbrite_push_image(unsigned char * img, unsigned int x, unsigned int y) { int col, row; // Just for clarity: col ranges from 0 to x-1, row ranges from 0 to y-1. // These three parameters determine mirroring and rotation: int rowDir = -1; int colDir = -1; int rotate90 = 0; col = colDir > 0 ? 0 : x-1; row = rowDir > 0 ? 0 : y-1; while(col >= 0 && col < x) { unsigned char * offset = img; if (rotate90) { offset += 3*(y*col + row); } else { offset += 3*(x*row + col); } shiftbrite_command(0, offset[0], offset[1], offset[2]); row += rowDir; // If we're at the end of a column, change direction (for we are // using a zigzag pattern) and move to the next column. if (row >= y || row < 0) { rowDir = -rowDir; col += colDir; row += rowDir; } } shiftbrite_delay_latch(x*y); shiftbrite_latch(); }
void shiftbrite_delay_latch(int lights) { //float usec = 20.0/1000 + 5.0/1000.0 * lights; //SysCtlDelay(delay_usec * ceil(usec)); // Just screw it and delay a microsecond since we control the clock anyway delayMicroseconds(1); shiftbrite_latch(); }
int main() { ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); //LEDs ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, LED_RED|LED_BLUE|LED_GREEN); //Shifty ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_BASE, LATCH_PIN|ENABLE_PIN|CLOCK_PIN); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, DATA_PIN); port_pin D,L,E,C; D.port = GPIO_PORTB_BASE; D.pin = DATA_PIN; L.port = GPIO_PORTA_BASE; L.pin = LATCH_PIN; E.port = GPIO_PORTA_BASE; E.pin = ENABLE_PIN; C.port = GPIO_PORTA_BASE; C.pin = CLOCK_PIN; shiftbrite_init(&sb, D, // Data pin : 1.4 L, // Latch pin : 1.5 E, // Enable pin : 1.6 C ); // Clock pin : 1.7 //for( int i = 0; i<5; i++ ) //{ shiftbrite_configure( &sb, 120, 100, 100, CLOCK_800MHZ ); //} // At startup, the module is disabled. Enable it. shiftbrite_enable(&sb); shiftbrite_latch(&sb); for (;;) { // set the red LED pin high, others low //ROM_GPIOPinWrite(GPIO_PORTF_BASE, LED_RED|LED_GREEN|LED_BLUE, LED_RED|LED_BLUE); for( int i = 0; i < 128; i++ ) { shiftbrite_rgb( &sb, i, 0, 0 ); shiftbrite_latch( &sb ); ROM_SysCtlDelay(100000); } for( int i = 127; i >= 0; i-- ) { shiftbrite_rgb( &sb, i, 0, 0 ); shiftbrite_latch( &sb ); ROM_SysCtlDelay(100000); } ROM_SysCtlDelay(5000000); } }