Example #1
0
static void FA_NOINLINE( Delay_1024 ) ( uint16_t time )
{
    set_bit( GTCCR, PSRSYNC ) ;			// reset prescaler

    ResetTM( 1, time ) ;			// set timer

    for ( ; ! TMexp( 1 ) ; )			// wait until timer expired
	;
}
Example #2
0
int FA_NORETURN( main ) ( void )
{
    uint8_t
	sw_sendrep ;

    // Initialize..

    init_hw() ;					// hardware. Note: defined as naked !

    sw_reportsz =				// report size
	(sw_id == SW_ID_3DP ? SW_REPSZ_3DP : SW_REPSZ_FFP) + ADDED_REPORT_DATA_SIZE;

    usb_init() ;				// USB stack

    sei() ;					// Enable interrupts

    SetTMPS( 1, 64 ) ;				// Set T1 prescaler to /64
    SetTMPS( 0, 1024 ) ;			// Set T0 prescaler to / 1024 for delay

    sw_sendrep = sw_repchg() ;			// Init send report flag, saved report

	WaitMs(1000);

	FfbInitMidi();

    wdt_enable( WDTO_500MS ) ;			// Unleash watchdog

	uint8_t ffb_init_sent = 0, ffb_test_sent = 0, ffb_pause_sent = 0;

    for ( ;; )					// Forever..
    {
	wdt_reset() ;				// Calm watchdog

	if ( usb_configuration )
	{
	    if ( TMexp( 0 ) )			// Time to read the stick
	    {
		SetTMPS( 0, 64 ) ;		// Set T0 prescaler to / 64 for query
		getdata() ;			// read 3DP data

		SetTMPS( 0, 1024 ) ;		// Set T0 prescaler to / 1024 for delay
		ResetTM( 0, READ_DEL ) ;

		// Read the additional controls
		// ???? TODO: read pedals and trims
		sw_report[sw_reportsz-1] = 5;	// ???? test a rudder position

		if ( sw_repchg() )		// Report changed,
		    sw_sendrep = TRUE ;		// need to send it
	    }

	    if ( TMexp( 1 ) )			// Idle timed out
	    {
		ResetTM( 1, IDLE_DEL ) ;

		if ( ! --idle_cnt && idle_rate )// Idle counter expired, rate not indef.
		    sw_sendrep = TRUE ;		// need to send current report
	    }

	    if ( sw_sendrep && ! usb_IN_busy() )
	    {
		LED_on() ;

		// ???? Test FFB: when certain buttons are pressed
		//	-------0 -------1 -------2 -------3 -------4 -------5
		//	XXXXXXXX YYYYYYXX HHHHYYYY BBRRRRRR TBBBBBBB 00TTTTTT
		//	76543210 54321098 32109876 21543210 09876543   654321
		
		if (sw_report[3] & 0b01000000)	// Button 1
			{
			if (ffb_init_sent == 0)
				{
				ffb_init_sent = 1;
				FfbInitMidi();
				}
			}
		else
			ffb_init_sent = 0;

		if (sw_report[3] & 0b10000000)	// button 2
			{
			if (ffb_test_sent == 0)
				{
				ffb_test_sent = 1;
				FfbTest();
				}
			}
		else
			ffb_test_sent = 0;

		if (sw_report[4] & 0b00000001)	// Button 3
			{
			if (ffb_pause_sent == 0)
				{
				ffb_pause_sent = 1;
				FfbSendDisable();
				}
			}
		else
			ffb_pause_sent = 0;

		usb_send_IN( sw_report, sw_reportsz ) ;

		sw_sendrep = FALSE ;		// reset send report flag
		idle_cnt   = idle_rate ;	// reset idle counter
		ResetTM( 1, IDLE_DEL ) ;	// reset idle timer

		LED_off() ;
	    }
	}
	else
	{
	    ResetTM( 1, IDLE_DEL ) ;		// reset idle timer
	    ResetTM( 0, READ_DEL ) ;		// reset SW timer
	}
    }
}