//Jump to DFU bootloader
static int _F2_Handler (void)
{
	printf_P(PSTR("Jumping to bootloader. A manual reset will be required\nPress 'y' to continue..."));
	
	if(WaitForAnyKey() == 'y')
	{
		printf_P(PSTR("Jump\n"));
		DelayMS(100);
		Jump_To_Bootloader();
	}
	
	printf_P(PSTR("Canceled\n"));
	return 0;
}
void
init_lowlevel(void)
{
    Leds_init();
    Leds_off();

        if (checkForFinger()) {
			if(bootloader_is_present())
				Jump_To_Bootloader();
#ifdef WINXPSP2
				usb_mode = mass_storage;
#else
                fingerPresent = 1;
#endif
        }

 return;

}
Exemple #3
0
int main(void) {
	CPU_PRESCALE(0);			
	Jump_To_Bootloader();
}
Exemple #4
0
void actions_reset(struct keystroke *keystroke, const __flash struct action *source_action)
{
    if (keystroke->execution_mode == KEYSTROKE_BEGIN)
        Jump_To_Bootloader();
}
Exemple #5
0
int main(void) {
	// Set clock @ 16Mhz
	CPU_PRESCALE(0);		

	//Set initial pin states.  These are adjusted based on eeprom settings.
    DDRB=0x00;
    DDRC=0x00;
    DDRD=0x00;
    PORTB=0xFF;
    PORTC=0xFF;
    PORTD=0xFF;
	
	//dpad and pad restrictions
	uint8_t	u=0, d=0, l=0, r=0, pu=0, pd=0, pl=0, pr=0;
	
	//pin assignments and button states
	uint8_t	pos=0, cnt=0;
	uint8_t ass[40], state[20];
	
	//handle shift and shift lock
	uint8_t shift=0, shift_last=0, shift_count=0, shift_lock=0;
	
	//handle settings
	uint8_t invert, restrict4;
	uint8_t setting_delay;
	uint8_t autofire, auto_toggle=1;
	uint8_t active=0, delay_power=0;
	
    //Flash LEDs
	#include "../shared/disco.c"

	//read first 40 eeprom into an array (pins + shifted pins)
	for(cnt=0;cnt<40;cnt++){	
		ass[cnt]=read_eeprom_byte(cnt);
		
		//set output pins
		if ((ass[cnt]==28)||(ass[cnt]==29)){
			#include "../shared/outputs.c"		
		}
		if (ass[cnt]==29){delay_power=1;}
		
	}
	//Read other settings (40+ in Eeprom) 
	setting_delay=read_eeprom_byte(41);

	//wait for specified delay time (allow 2 secs for led flash)
	if ((delay_power==1)&&(setting_delay>0)){
		for(cnt=0;cnt<=setting_delay-3;cnt++){
			_delay_ms(1000);
		}
		active=1;
		for(cnt=0;cnt<40;cnt++){	
			if (ass[cnt]==29){
				#include "../shared/showleds.c"
			}
		}
	}

	// Init USB pad emulation
	vs_init(true);

	// Pins polling and gamepad status updates
	for (;;) {
		vs_reset_watchdog();
		
		//read KADE pin states into an array
		#include "../shared/state.c"		
		
		//set shifted status and detect shift lock (double click)
		#include "../shared/shift.c"		

		//set default button states
		//reset direction to centre
		gamepad_state.direction=8;
		gamepad_state.l_y_axis=0x80;
		gamepad_state.l_x_axis=0x80;

		gamepad_state.square_btn=0x00;
		gamepad_state.cross_btn=0x00;
		gamepad_state.circle_btn=0x00;
		gamepad_state.triangle_btn=0x00;
		gamepad_state.l1_btn=0x00;
		gamepad_state.r1_btn=0x00;					
		gamepad_state.l2_btn=0x00;
		gamepad_state.r2_btn=0x00;
		gamepad_state.l3_btn=0x00;
		gamepad_state.r3_btn=0x00;
		gamepad_state.select_btn=0x00;
		gamepad_state.start_btn=0x00;
		gamepad_state.ps_btn=0x00;
		invert=0;
		restrict4=0;
		autofire=0;		
		
		//pre-loop to deal with any switches/toggles		
		pu=u; pd=d; pl=l; pr=r;
		u=0; d=0; l=0; r=0;
		for(cnt=0;cnt<20;cnt++) {
			if (!(state[cnt])) {
				//there is input on this pin, also account for shifted input
				pos = cnt;
				if (shift==1){pos=pos+20;}
				
				if ((ass[cnt]==23)||(ass[pos]==23)){invert=1;}     //invert Y axis
				if ((ass[cnt]==22)||(ass[pos]==22)){restrict4=1;}  //restrict dPad 4-way
				if ((ass[pos]>=24)&&(ass[pos]<=27)){autofire=1;}   //autofire mode
				if ((ass[pos]>=30)&&(ass[pos]<=38)){autofire=1;}   //extra autofire mode
				if (ass[pos]==1){u=1;}
				if (ass[pos]==2){d=1;}				
				if (ass[pos]==3){l=1;}
				if (ass[pos]==4){r=1;}
			}
			
			//Show the shift status LED(s) and power up externals with delay
			if (ass[cnt]==28){
				active = shift;
				#include "../shared/showleds.c"								
			}
		}			

		//invert Y axis on DPAD (if we want to do this)
		//if (invert==1){
		//	if (u==1){d=1; u=0;} 
		//	else if (d==1){d=0; u=1;}
		//}

		//autofire toggle
		if(autofire==1){
			auto_toggle = auto_toggle * -1;
		}

		//Handle dpad and restricted movement
		if(restrict4==1){
			if (u==1){gamepad_state.direction=0;}
			if (d==1){gamepad_state.direction=4;}
			if (l==1){gamepad_state.direction=6;}
			if (r==1){gamepad_state.direction=2;}
		} else {				
			//left and right directions
			if (l==1){gamepad_state.direction=6;}  //Left
			if (r==1){gamepad_state.direction=2;}	//Right						
			
			//up, down and diagonal directions
			if (u==1){								//Up
				if (l==1){							//left
					gamepad_state.direction=7;		//up-left
				}
				else if (r==1){    					//right
					gamepad_state.direction=1;		//up-right
				} else {
					gamepad_state.direction=0;		//up
				}		
			}
			if (d==1){								//down
				if (l==1){							//left
					gamepad_state.direction=5;		//down-left
				}
				else if (r==1){   	 				//right
					gamepad_state.direction=3;		//down-right
				} else {
					gamepad_state.direction=4;		//down
				}
			}		
		}

		//loop through pins checking for inputs from those that are assigned a function
		for(cnt=0;cnt<20;cnt++) {
			pos=cnt;					
			if (!(state[cnt])) {
				//there is input on this pin
				if (shift==1){pos=pos+20;}  //+20 if this is shifted input
				
				if (ass[pos]>0) {
					//there is an assignment to a function

					//A, B, X, Y
					if (ass[pos]==5){gamepad_state.square_btn=0xFF;}
					if (ass[pos]==6){gamepad_state.cross_btn=0xFF;}
					if (ass[pos]==7){gamepad_state.circle_btn=0xFF;}
					if (ass[pos]==8){gamepad_state.triangle_btn=0xFF;}
					
					//Autofire
					if (autofire==1){
						if(auto_toggle==1){
							if (ass[pos]==24){gamepad_state.square_btn=0xFF;}
							if (ass[pos]==25){gamepad_state.cross_btn=0xFF;}
							if (ass[pos]==26){gamepad_state.circle_btn=0xFF;}
							if (ass[pos]==27){gamepad_state.triangle_btn=0xFF;}
						}
						_delay_ms(15);
					}
					
					//PS3 Triggers
					if (ass[pos]==9){gamepad_state.l1_btn=0xFF;}   		    //L1
					if (ass[pos]==10){gamepad_state.r1_btn=0xFF;}  		    //R1					
					if (ass[pos]==11){gamepad_state.l2_btn=0xFF;}  		    //L2
					if (ass[pos]==12){gamepad_state.r2_btn=0xFF;}   			//R2
					if (ass[pos]==15){gamepad_state.l3_btn=0xFF;}  		    //L3
					if (ass[pos]==16){gamepad_state.r3_btn=0xFF;}				//R3
					
					//PS3 Special
					if (ass[pos]==13){gamepad_state.select_btn=0xFF;}			//L3
					if (ass[pos]==14){gamepad_state.start_btn=0xFF;}			//R3
					if (ass[pos]==17){gamepad_state.ps_btn=0xFF;}				//PS Button
					
					//Analog Stick
					if (ass[pos]==18+invert){gamepad_state.l_y_axis = 0x00;} 	//Analog Up
					if (ass[pos]==19-invert){gamepad_state.l_y_axis = 0xff;} 	//Analog Down
					if (ass[pos]==20){gamepad_state.l_x_axis = 0x00;} 			//Analog Left
					if (ass[pos]==21){gamepad_state.l_x_axis = 0xff;} 			//Analog Right
					
					//Enter programming mode
					if (ass[pos]==39){Jump_To_Bootloader();}					//Program mode					
										
				}
			}
		}

		_delay_ms(10);  //debounce
		vs_send_pad_state();
		
	}
}