void arduinoDueSlave() { int16_t byte ; uint16_t address ; // Initialise serial at 100K baud DDRE &= ~(1 << DDE0) ; // set RXD0 pin as input PORTE &= ~(1 << PORTE0) ; // disable pullup on RXD0 pin UCSR0A &= ~(1 << U2X0) ; // disable double speed operation. UBRR0L = 4 ; // 200000 baud UBRR0H = 0 ; // set 8 N1 UCSR0B = 0 | (0 << RXCIE0) | (0 << TXCIE0) | (0 << UDRIE0) | (0 << RXEN0) | (0 << TXEN0) | (0 << UCSZ02) ; UCSR0C = 0 | (1 << UCSZ01) | (1 << UCSZ00) ; while (UCSR0A & (1 << RXC0)) UDR0 ; // flush receive buffer UCSR0B |= (1 << RXEN0); // enable RX UCSR0B |= (1 << RXCIE0); // enable Interrupt UCSR0B |= (1 << TXEN0) ; // enable TX, but not interrupt yet Arduino = 1 ; lcd_clear() ; lcd_puts_Pleft( 24, PSTR("Arduino Slave") ) ; refreshDiplay(); for(;;) { static uint8_t lastTMR ; wdt_reset() ; while ( ( byte = get_fifo64( &Arduino_fifo ) ) != -1 ) { processSlaveByte( byte ) ; if (SlaveActionRequired) { SlaveActionRequired = 0 ; if ( SlaveType < 16) { SlaveDisplayRefresh = 1 ; } else { switch ( SlaveType ) { case 0x10 : // Protocol + channels Protocol = SlaveTempReceiveBuffer[0] ; SubProtocol = SlaveTempReceiveBuffer[1] ; { uint8_t i ; uint8_t index = 0 ; for ( i = 2 ; i < 34 ; i += 2 ) { // May need cli/sei round this Channels[index] = SlaveTempReceiveBuffer[i] | ( SlaveTempReceiveBuffer[i+1] << 8 ) ; index += 1 ; } } break ; case 0x12 : // 0x01, 0x12, 16 bit address, 0x01 - send 32 bytes EEPROM data @ address address = SlaveTempReceiveBuffer[0] | ( SlaveTempReceiveBuffer[1] << 8 ) ; EepromAddress = address ; EepromRequested = 1 ; break ; } } } } uint8_t t10ms ; t10ms = g_tmr10ms ; tick10ms = t10ms - lastTMR ; lastTMR = t10ms ; if(tick10ms) //make sure the rest happen only every 10ms. { ControlsRequested = 1 ; if ( SlaveDisplayRefresh ) { SlaveDisplayRefresh = 0 ; refreshDiplay() ; } } if ( TxBusy == 0 ) { if ( EepromRequested ) { sendEeprom( EepromAddress ) ; EepromRequested = 0 ; } else if ( ControlsRequested ) { sendControls() ; ControlsRequested = 0 ; } } } }
// Will be called approx 30 times per second C_RESULT update_gamepad(void) { sendControls(); return C_OK; }