void write(uint8_t address, uint8_t value) { RESET(P_NCS); spi_exch(address|0x80); _delay_us(50); // wait t_SWW / t_SWR spi_exch(value); SET(P_NCS); }
void getMotionBurst(uint8_t *burst) { RESET(P_NCS); spi_exch(MOTION_BURST); _delay_us(75); // wait t_SRAD-MOT // read all 7 bytes (Motion, Delta_X, Delta_Y, SQUAL, Shutter_Upper, Shutter_Lower, Maximum Pixels) for(uint8_t i=0; i<7; i++) { burst[i] = spi_exch(0x00); } SET(P_NCS); _delay_us(1); }
uint8_t read(uint8_t address) { RESET(P_NCS); spi_exch(address); if (address == 0x02) // is motion read? { _delay_us(75); // wait t_SRAD-MOT } else { _delay_us(50); // wait t_SRAD } uint8_t ret = spi_exch(0x00); SET(P_NCS); _delay_us(1); // wait t_SRR = 250ns return ret; }
void getFrameBurst(uint8_t *image) { uint8_t regValue; write(FRAME_CAPTURE,0x83); // wait 3 frame periods + 10 us for frame to be captured // min frame speed is 2000 frames/second so 1 frame = 500 us. so 500 x 3 + 10 = 1510 _delay_us(1510); // wait t_CAPTURE RESET(P_NCS); spi_exch(PIXEL_BURST); _delay_us(50); // wait t_SRAD for(int i=0; i<900; i++) // max. 1536 Pixels { regValue = spi_exch(0x00); image[i] = (regValue << 2); _delay_us(10); // wait t_LOAD } SET(P_NCS); _delay_us(4); // wait t_BEXIT }
int main (void) { char current_message=0; //Indicates which string we should be displaying char change_message=1; //Flag to notify firmware we've finished displaying the current message and we need to get the next one char *message='\0'; //Pointer to the string we want to display ioinit(); //Boot up defaults and configure Bluetooth connection while(1){ //Check to see if we need to get a new message to display if(change_message){ change_message=0; //Reset the flag //Grab the appropriate message if(current_message==0)message=&message_1[0]; if(current_message==1)message=&message_2[0]; if(current_message==2)message=&message_3[0]; } //Each time through this loop, we'll send an image to the RGB backpack. The scroll index will tell put_char() the row index of character start position on the matrix //After running through the entirety of this loop, the current message character will have scrolled across the RGB matrix one row at a time, and the //next character will currently be on the matrix. for(int scroll_index=-1; scroll_index >=-8; scroll_index--){ //Put the current character, offset by scroll_index, into the frame_data[] buffer putchar_frame(message, scroll_index, text_color); cbi(PORTB, CS); //Putting the CS line low will start the communication sequence for(int LED=0; LED<64; LED++){ //Send 64 bytes to the RGB serial backpack. One byte is sent for each LED. The format of the byte is RRRGGGBB. spi_exch(frame_data[LED]); //*See ioinit() for SPI Hardware Setup } sbi(PORTB, CS); //Setting the CS line high will terminate the communication sequence. delay_ms(10); //Pause before sending the next set of data } //If we've reached the end of the current message, it's time to get the next one if(*(message+1)=='\0'){ current_message+=1; if(current_message==3)current_message=0; change_message=1; } //If we haven't reached the end of the current message, increment to get the next character else message+=1; } while(1); return (0); }