Ejemplo n.º 1
0
int main() {
  init();
  //blink(1);
  while(1) {
    //DEBUG("\r\n");
    clear_keys();
    //debounce(DEBOUNCE_PASSES);
    scan_keys();
    cool_down_inactive_layers();
    pre_invoke_functions();
    calculate_presses();
    //b();
    //clear_screen();
    //debug_state();
    //debug_layers();
    usb_keyboard_send();
  };
};
Ejemplo n.º 2
0
 //Sends a keyboard report depending on active protocol
 void keyboard_send_report( )
 {
	//Debug toggle bluetooth status
	//Check to see if USB active
	if(bluefruit_configured())
	{
		//Send keyboard report using Bluetooth
		bluefruit_keyboard_send();
		print("Sent Bluetooth Report!\n");
	}
	else
	{
		//Send keyboard report using USB
		usb_keyboard_send();
		//bluefruit_keyboard_send(); //debug also send bluetooth report
		print("Sent USB Report!\n");
	}
 }
void usb_keyboard_press_keycode(uint16_t n)
{
	uint8_t key, mod, msb, modrestore=0;
	KEYCODE_TYPE keycode;
	#ifdef DEADKEYS_MASK
	KEYCODE_TYPE deadkeycode;
	#endif

	msb = n >> 8;
	if (msb >= 0xC2 && msb <= 0xDF) {
		n = (n & 0x3F) | ((uint16_t)(msb & 0x1F) << 6);
	} else
	if (msb == 0x80) {
		usb_keyboard_press_key(0, n);
		return;
	} else
	if (msb == 0x40) {
		usb_keyboard_press_key(n, 0);
		return;
	}
	keycode = unicode_to_keycode(n);
	if (!keycode) return;
	#ifdef DEADKEYS_MASK
	deadkeycode = deadkey_to_keycode(keycode);
	if (deadkeycode) {
		modrestore = keyboard_modifier_keys;
		if (modrestore) {
			keyboard_modifier_keys = 0;
			usb_keyboard_send();
		}
		// TODO: test if operating systems recognize
		// deadkey sequences when other keys are held
		mod = keycode_to_modifier(deadkeycode);
		key = keycode_to_key(deadkeycode);
		usb_keyboard_press_key(key, mod);
		usb_keyboard_release_key(key, mod);
	}
	#endif
	mod = keycode_to_modifier(keycode);
	key = keycode_to_key(keycode);
	usb_keyboard_press_key(key, mod | modrestore);
}
static void usb_keyboard_release_key(uint8_t key, uint8_t modifier)
{
	int i, send_required = 0;

	if (modifier) {
		if ((keyboard_modifier_keys & modifier) != 0) {
			keyboard_modifier_keys &= ~modifier;
			send_required = 1;
		}
	}
	if (key) {
		for (i=0; i < 6; i++) {
			if (keyboard_keys[i] == key) {
				keyboard_keys[i] = 0;
				send_required = 1;
			}
		}
	}
	if (send_required) usb_keyboard_send();
}
Ejemplo n.º 5
0
void pokerMode(){
	while (1) {
		for (r = 0; r < ROWS; r++) {
			pullDownRows(r);
			read_cols(r);
			unselect_rows();
		}
		for (r = 0; r < ROWS; r++) {
			for (c = 0; c < COLS; c++) {
				if (keystate[r][c] > 0x08) {
					if (keytype[r][c] == 0x01) {
						if (FN == 0x00)
							presskey(hexaKeys[r][c]);
						else if (FN == 0x01)
							presskey(hexaKeys2[r][c]);
					} else if (keytype[r][c] == 0x02) {
						pressModifierKeys(hexaKeys[r][c]);
					} else if (keytype[r][c] == 0x04 && FN == 0x00) {
						FN = 0x02;
					}
				} else {
					if (keytype[r][c] == 0x01) {
						if (FN == 0x00)
							releasekey(hexaKeys[r][c]);
						else if (FN == 0x01)
							releasekey(hexaKeys2[r][c]);
					} else if (keytype[r][c] == 0x02) {
						releaseModifierKeys(hexaKeys[r][c]);
					} else if (keytype[r][c] == 0x04 && FN == 0x01) {
						FN = 0x04;
					}
				}

			}
		}
		  if(FN==0x02){FN=0x01;releaseAll();}
		  else if(FN==0x04){FN=0x00;releaseAll();}
		  usb_keyboard_send();
			///////////////////////////////////
		}
}
Ejemplo n.º 6
0
void osuMode(){

	 DDRD |= (1 << 0);
						PORTD &= ~(1 << 0);
						DDRD |= (1 << 1);
						PORTD &= ~(1 << 1);
						DDRD |= (1 << 2);
						PORTD &= ~(1 << 2);
						DDRD |= (1 << 3);
						PORTD &= ~(1 << 3);
						DDRD |= (1 << 5);
						PORTD &= ~(1 << 5);
						while (1) {
							 if(PINF & (1 << 0)){keyboard_keys[0] = 0;}else{keyboard_keys[0]=KEY_ESC;}
							 if(PINE & (1 << 6)){keyboard_keys[1] = 0;}else{keyboard_keys[1]=KEY_Z;}
							 if(PINC & (1 << 7)){keyboard_keys[2] = 0;}else{keyboard_keys[2]=KEY_X;}
							 if(PINB & (1 << 7)){keyboard_keys[3] = 0;}else{keyboard_keys[3]=KEY_SPACE;}
							 if(PINB & (1 << 3)){keyboard_keys[4] = 0;}else{keyboard_keys[4]=KEY_ENTER;}
							 usb_keyboard_send();
						}
}
Ejemplo n.º 7
0
void _kbfun_combo_normal_press_release_once(keycode combo_key, keycode key, bool is_pressed) {
  // FIXME this should be cleaner when we have actual key repeats

  if (is_pressed) {
    // avoid messing with independently pressed modifiers
    bool mod_already_pressed = _kbfun_modifier_is_pressed(combo_key);

    if (!mod_already_pressed) {
      _kbfun_modifier_press_release(combo_key, true);
    }

    kbfun_normal_press_release(key, true);

    if (!mod_already_pressed) {
      // we force a keyboard send to prevent the modifier from bleeding into the next key press
      usb_keyboard_send();
      _kbfun_modifier_press_release(combo_key, false);
    }
  } else {
    kbfun_normal_press_release(key, false);
  }
}
Ejemplo n.º 8
0
//Main Program
int main(void)
{
	uint8_t b_prev=0xFF, c_prev=0xFF, d_prev=0xFF;

	// set for 16 MHz clock
	CLKPR = 0x80, CLKPR = 0;

	// Configure all ports as inputs with pullup resistors.
	DDRB = 0x00;
	DDRC = 0x00;
	DDRD = 0x00; 
	PORTB = 0xFF; 
	PORTC = 0xFF;
	PORTD = 0xFF;

	//Initialise LED timings (added v1.1)
	clock_prescale_set(clock_div_1);
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	//Read eeprom to get active group and mode
	ee_byte=read_eeprom_byte(1);
	set_active_mode();

	// Initialize the USB
	usb_init();

    //flash them leds
	#include "../shared/disco.c"

	while(!usb_configured());

	// Wait for host to load drivers
	//_delay_ms(500);

	while(1) {
		uint8_t b = PINB;
		uint8_t c = PINC;
		uint8_t d = PIND;

		if(b != b_prev || c != c_prev || d != d_prev ) {
		  keycount = 0;
		  modecount = 0;  //HWB to toggle active mode

		  //if(!(c & 0x10)) //Pin B10 can be connected to external LED indicator
		  
		  if(!(c & 0x20)) { keyboard_keys[keycount++] = map[18]; } //PIN B9
		  if(!(c & 0x40)) { keyboard_keys[keycount++] = map[17]; } //PIN B8
		  if(!(c & 0x80)) { keyboard_keys[keycount++] = map[16]; } //PIN B7
		  if(!(b & 0x80)) { keyboard_keys[keycount++] = map[15]; } //PIN B6
		  if(!(b & 0x40)) { keyboard_keys[keycount++] = map[14]; } //PIN B5
		  if(!(b & 0x20)) { keyboard_keys[keycount++] = map[13]; } //PIN B4
		  if(!(b & 0x10)) { keyboard_keys[keycount++] = map[12]; } //PIN B3
		  if(!(b & 0x08)) { keyboard_keys[keycount++] = map[11]; } //PIN B2
		  if(!(b & 0x04)) { keyboard_keys[keycount++] = map[10]; } //PIN B1
		  if(!(b & 0x02)) { keyboard_keys[keycount++] = map[9]; }  //PIN A10
		  if(!(b & 0x01)) { keyboard_keys[keycount++] = map[8]; }  //PIN A9
		  if(!(d & 0x40)) { keyboard_keys[keycount++] = map[7]; }  //PIN A8
		  if(!(d & 0x20)) { keyboard_keys[keycount++] = map[6]; }  //PIN A7
		  if(!(d & 0x10)) { keyboard_keys[keycount++] = map[5]; }  //PIN A6
		  if(!(d & 0x08)) { keyboard_keys[keycount++] = map[4]; }  //PIN A5
		  if(!(d & 0x04)) { keyboard_keys[keycount++] = map[3]; }  //PIN A4
		  if(!(d & 0x02)) { keyboard_keys[keycount++] = map[2]; }  //PIN A3
		  if(!(d & 0x01)) { keyboard_keys[keycount++] = map[1]; }  //PIN A2
		  if(!(c & 0x04)) { keyboard_keys[keycount++] = map[0]; }  //PIN A1
		  
		  if(!(d & 0x80)) {                                         //HWB PIN 
			  modecount++;
		  }                        			  
			  
		  while(keycount < sizeof(keyboard_keys)) {
			keyboard_keys[keycount++] = KEY_NONE;
		  }

		  usb_keyboard_send();

		  b_prev = b;
		  c_prev = c;
		  d_prev = d;
		  
		  if (modecount>0){
			switch_mode();
		  }	  

		}
		_delay_ms(2); // Debounce
	}
}
Ejemplo n.º 9
0
//Main Program
int main(void)
{
	// set for 16 MHz clock
	CLKPR = 0x80, CLKPR = 0;

	//Initialise LED timings (added v1.1)
	clock_prescale_set(clock_div_1);

	//Set initial pin states.  These are adjusted based on eeprom settings.
    DDRB=0x00;
    DDRC=0x00;
    DDRD=0x00;
    PORTB=0xFF;
    PORTC=0xFF;
    PORTD=0xFF;

	//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;
	
	//extended mode flags - use to detect if key combos are pressed
	uint8_t p1, p2, p3, p4;
	uint8_t ext_inputs, ext_func_block, ext_func;
	
    //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"		
		}*/		
	}
	

	// Initialize the USB
	usb_init();

	while(!usb_configured());

	while(1) {
		//read KADE pin states into an array
		#include "..\shared\state.c"		
		
		//set shifted status and detect shift lock (double click)
		#include "..\shared\shift.c"
	
		//check for extended mode inputs
		p1=0; p2=0; p3=0; p4=0;		
		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) {
					if (ass[pos]==3 ||ass[pos]==4 ){ p1 += 1; }
					if (ass[pos]==5 ||ass[pos]==6 ){ p1 += 3; }
					if (ass[pos]==17||ass[pos]==18){ p2 += 1; }
					if (ass[pos]==19||ass[pos]==20){ p2 += 3; }
					if (ass[pos]==31||ass[pos]==32){ p3 += 1; }
					if (ass[pos]==33||ass[pos]==34){ p3 += 3; }
					if (ass[pos]==43||ass[pos]==44){ p4 += 1; }
					if (ass[pos]==45||ass[pos]==46){ p4 += 3; }
				}				
			}
		}
   
		//Cycle players and process extended maps
		//ext_func_block: sets the start position of the extended functions read from eeprom
		//ext_inputs:     the calculated combo value between 0 and 8.
		//         0:     .
		//         1:     .
		//         2:     up+down
		//         3:     .
		//         4:     .
		//         5:     up+down
		//         6:     left+right
		//         7:     left+right
		//         8:     up+down+left+right
		keycount = 0;		
		for(cnt=0;cnt<4;cnt++) {
			if(cnt==0){ext_inputs = p1; ext_func_block = 69;} 
			if(cnt==1){ext_inputs = p2; ext_func_block = 72;} 
			if(cnt==2){ext_inputs = p3; ext_func_block = 75;} 
			if(cnt==3){ext_inputs = p4; ext_func_block = 78;} 
			if (ext_inputs==2||ext_inputs>=5){ 
				//extended combo is detected
				if (ext_inputs==8)
					{ext_func=ext_func_block+2;}	//(u+d+l+r)
				else if (ext_inputs==2||ext_inputs==5)
					{ext_func=ext_func_block;}		//(u+d)
				else if (ext_inputs==6||ext_inputs==7)
					{ext_func=ext_func_block+1;}	//(l+r)
				
				//shifted function are higher in eeprom
				if (shift==1){ext_func=ext_func+12;}
				
				ass[pos] = read_eeprom_byte(ext_func);
				#include "keymaps.c"
			}
		}


		//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
					#include "keymaps_extended.c"
				}				
			}
		}


   
		while(keycount < sizeof(keyboard_keys)) {
			keyboard_keys[keycount++] = KEY_NONE;
		}

		usb_keyboard_send();
		_delay_ms(2); // Debounce
	}
}
Ejemplo n.º 10
0
void
send_keys(uint8_t* state)
{
  // Report all currently pressed keys to the host.  This function
  // will be called when a change of state has been detected.
  
  uint8_t local = 0;
  uint8_t caps_lock_pressed = 0;
  const uint8_t* keymap = keymap_normal;

 retry:
  // If we detect that we are in f-mode, we need to translate the
  // pressed keys with the f-mode translation table.  Detection of
  // f-mode happens while decoding the shift register.  When the
  // f-mode key is detected as being pressed, the translation table is
  // switched and the decoding process is restarted.
  {
    uint8_t key_index = 0;
    uint8_t map_index = 0;
    keyboard_modifier_keys = 0;
    memset(keyboard_keys, 0, sizeof keyboard_keys);

    for (int i = 0; i < 16; i++) {
      uint8_t buf = state[i];
      for (int j = 0; j < 8; j++, map_index++) {
        uint8_t mapped = pgm_read_byte(&keymap[map_index]);
        uint8_t pressed = (buf & 1);
#if defined(DEBUG)
        if (pressed) {
          print("key ");
          phex(map_index - 1);
          print(" pressed, mapped to ");
          phex(mapped);
          print("\n");
        }
#endif
        // Handle firmware update key combination Local+Abort

        if (pressed) {
          if (map_index == 0x01) {
            local = 1;                                      // Local key is pressed
          } else if (map_index == 0x1e && local) {
            jump_to_loader();                               // Abort key is pressed
          }
        }            

        if (pressed && mapped) {
          if (mapped & 0x80) {
            int num = mapped & 0x7F;
            switch (num) {

            case NUM_KEY_LEFT_CTRL:
            case NUM_KEY_LEFT_SHIFT:
            case NUM_KEY_LEFT_ALT:
            case NUM_KEY_LEFT_GUI:
            case NUM_KEY_RIGHT_CTRL:
            case NUM_KEY_RIGHT_SHIFT:
            case NUM_KEY_RIGHT_ALT:
            case NUM_KEY_RIGHT_GUI:
              keyboard_modifier_keys |= 1 << num;
              break;

            case NUM_KEY_F_MODE:
              if (keymap == keymap_normal) {
                keymap = keymap_f_mode;
                goto retry;
              }
              break;

            case NUM_KEY_CAPS_LOCK:
              caps_lock_pressed = 1;
              break;

            }
          } else {
            if (key_index < sizeof keyboard_keys) {
              keyboard_keys[key_index++] = mapped;
            }
          }
        }
        buf >>= 1;
      }
    }
  }
  
#if !defined(DEBUG)
  usb_keyboard_send();
#endif

  {
    // Process caps lock key.  This key is a switch on the Symbolics
    // keyboard, so we must make sure that the current switch setting
    // always matches the caps lock state of the host.

    // If the host set LED 2, it indicates that caps lock has been
    // pressed.  If the caps lock state reported by the host does not
    // match the caps lock key state of the Symbolics keyboard, send a
    // "caps lock" key press and release to the host to make the two
    // match.  As a result, if caps lock is depressed on another
    // keyboard connected to the host, it will quickly be cleared
    // again.

    uint8_t prev_caps_lock_pressed = (keyboard_leds & 2) ? 1 : 0;
    if (caps_lock_pressed ^ prev_caps_lock_pressed) {
      usb_keyboard_press(KEY_CAPS_LOCK, 0);
    }
  }
}
Ejemplo n.º 11
0
int main(void)
{
  uint8_t values[3];
	uint8_t i;
  uint8_t temp;

	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Configure all port B and port D pins as inputs with pullup resistors
	// See the "Using I/O Pins" page for details.
	// http://www.pjrc.com/teensy/pins.html
  //DDRD
	DDRD = 0x00;
	DDRB = 0x00;
	PORTB = 0xFF;
	PORTD = 0xFF;
  DDRE=0x00;
  PORTE=0xFF;

  //set left/right pins to output low
  if (left_out.port==OUTPUT_E)
  {
    DDRE|=left_out.pin;
    PORTE&=~left_out.pin;
  }
  else
  {//wtf
  }

  if (right_out.port==OUTPUT_E)
  {
    DDRE|=right_out.pin;
    PORTE&=~right_out.pin;
  }
  else
  {//wtf
  }

	// Initialize the USB, and then wait for the host to set configuration.
	// If the Teensy is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

   // Initialize the keyboard state to nothing pressed.
   keyboard_modifier_keys = 0;
   for (i=0; i < 5; i++)
      keyboard_keys[i] = 0;

 	while (1) {
		// read all port B and port D pins
      values[0] = PINB;
      values[1] = PIND;
      values[2] = PORTE;

      for (i=0; i<NUM_BUTTONS; i++)
      {
         // Shift the debounce value for this button to the left one bit
         debounce[i] <<= 1;
         if (values[keyPort[i]] & keyMask[i])
         {
            // Because we're using a pullup resistor, the value of the pin will be high
            // if the button doesn't tie the pin to ground.  So set the bottom bit to 1
            debounce[i] |= 1;
         } else {
            // Because we're using a pullup resistor, the value of the pin will be low
            // if the button is pressed and ties the pin to ground.  So set the bottom bit to 0
            debounce[i] &= 0xFE;
         }
         // If the key has been pressed down for eight loop iterations (8 bits in a byte), send the keydown.
         if (debounce[i] == 0x00)
         {
            // Set key down
            keyboard_keys[keyIndex[i]] = key[i];
            //turn on IO pin for left/right down
            if (key[i]==KEY_S) {//left
              values[left_out.port]|=left_out.pin;
            }
            if (key[i]==KEY_F) {//right
              values[right_out.port]|=right_out.pin;
            }

         } else {
            // If the key has been released for eight loop iterations, send keyup (if this key is currently marked as down)
           if (debounce[i] == 0xFF)
           {
             // Set key up
             if (keyboard_keys[keyIndex[i]] == key[i])
               keyboard_keys[keyIndex[i]] = 0;
             //turn off IO pin for left/right down
             if (key[i]==KEY_S) {//left
               values[left_out.port]&=~left_out.pin;
             }
             if (key[i]==KEY_F) {//right
               values[right_out.port]&=~right_out.pin;
             }
           }
         }
      }
      //set output ports to updated values
      PORTE=values[2];
      // Send keyboard_keys and keyboard_modifier_keys to host pc
      usb_keyboard_send();
	}
}
Ejemplo n.º 12
0
int main(void) {
	kb_init();  // does controller initialization too

	kb_led_state_power_on();

	usb_init();
	while (!usb_configured());
	kb_led_delay_usb_init();  // give the OS time to load drivers, etc.

	kb_led_state_ready();

	for (;;) {
		static uint8_t current_layer = 0;

		// swap `kb_is_pressed` and `kb_was_pressed`, then update
		bool (*temp)[KB_ROWS][KB_COLUMNS] = kb_was_pressed;
		kb_was_pressed = kb_is_pressed;
		kb_is_pressed = temp;

		kb_update_matrix(*kb_is_pressed);

		// call the appropriate function for each key, then send the usb report
		// if necessary
		// - everything else is the key function's responsibility; see the
		//   keyboard layout file ("keyboard/ergodox/layout/*.c") for which key
		//   is assigned which function (per layer), and "lib/key-functions.c"
		//   for their definitions
		for (uint8_t row=0; row<KB_ROWS; row++) {
			for (uint8_t col=0; col<KB_COLUMNS; col++) {
				bool is_pressed = (*kb_is_pressed)[row][col];
				bool was_pressed = (*kb_was_pressed)[row][col];
				if (is_pressed != was_pressed) {
					if (is_pressed) {
						kbfun_funptr_t press_function =
								kb_layout_press_get(current_layer, row, col);
						if (press_function) {
							(*press_function)(
									kb_layout_get(current_layer, row, col),
									&current_layer, &row, &col );
						}
					} else {
						kbfun_funptr_t release_function =
								kb_layout_release_get(current_layer, row, col);
						if (release_function) {
							(*release_function)(
									kb_layout_get(current_layer, row, col),
									&current_layer, &row, &col );
						}
					}

					usb_keyboard_send();
					_delay_ms(KB_DEBOUNCE_TIME);
				}
			}
		}

		// update LEDs
		if (keyboard_leds & (1<<0)) { kb_led_num_on(); }
		else { kb_led_num_off(); }
		if (keyboard_leds & (1<<1)) { kb_led_caps_on(); }
		else { kb_led_caps_off(); }
		if (keyboard_leds & (1<<2)) { kb_led_scroll_on(); }
		else { kb_led_scroll_off(); }
		if (keyboard_leds & (1<<3)) { kb_led_compose_on(); }
		else { kb_led_compose_off(); }
		if (keyboard_leds & (1<<4)) { kb_led_kana_on(); }
		else { kb_led_kana_off(); }
	}

	return 0;
}
Ejemplo n.º 13
0
int main()
{
	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Configure all port B and port D pins as inputs with pullup resistors.
	DDRD = 0x00;
	DDRB = 0x00;
	PORTB = 0xFF;
	PORTD = 0xFF;

    // Turn the LED on during the configuration
    LED_CONFIG;
    LED_ON;

	// Initialize the USB, and then wait for the host to set configuration.
	usb_init();
	while (!usb_configured());

    // Initialize the gamepad interface
    gamepad_init();

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);

    // Timer 0 configuration (~60Hz)
	TCCR0A = 0x00;  // Normal mode
	TCCR0B = 0x05;  // Clock/1024
	TIMSK0 = (1<<TOIE0);

    LED_OFF;

	while (1) {
        while (!ready);  // Block until the next cycle (~60Hz)
        cli();
        ready = 0;
        sei();

        // Read pressed buttons from gamepad interface
        gamepad_read();

        // Reset key array
        reset_keys();

        // Special functions
        // - Software reboot
        if (PRESSED_REBOOT) {
            reboot();
        }

        // 6 keys can be sent at a time, with any number of modifiers.
        //
        // - Buttons A, B, X and Y have their own position in the key array.
        // - Up/down and left/right pairs share one position, as they are
        //     mutually exclusive (you cannot pres up AND down).
        // - L and R use the left and right Shift modifiers.
        // - Select and Start use the left and right Ctrl modifiers.

        if (PRESSED_A) press_key(KEY_Z, 0);
        if (PRESSED_B) press_key(KEY_X, 1);
        if (PRESSED_X) press_key(KEY_A, 2);
        if (PRESSED_Y) press_key(KEY_S, 3);

        if (PRESSED_UP) {
            press_key(KEY_UP, 4);
        } else if (PRESSED_DOWN){
            press_key(KEY_DOWN, 4);
        }

        if (PRESSED_LEFT) {
            press_key(KEY_LEFT, 5);
        } else if (PRESSED_RIGHT){
            press_key(KEY_RIGHT, 5);
        }

        if (PRESSED_L) press_modifier(KEY_LEFT_SHIFT);
        if (PRESSED_R) press_modifier(KEY_RIGHT_SHIFT);
        if (PRESSED_SELECT) press_modifier(KEY_LEFT_CTRL);
        if (PRESSED_START) press_modifier(KEY_RIGHT_CTRL);

        usb_keyboard_send();
	}
}
Ejemplo n.º 14
0
Archivo: main.c Proyecto: HexTank/KADE
//Main Program
int main(void)
{
    #include "mappings.c"
	uint8_t b_prev=0xFF, c_prev=0xFF, d_prev=0xFF;

	// set for 16 MHz clock
	CLKPR = 0x80, CLKPR = 0;

	// Configure all ports as inputs with pullup resistors.
	DDRB = 0x00;
	DDRC = 0x00;
	DDRD = 0x60; // D5,D6 - OUTPUT (LED)
	PORTB = 0xFF;
	PORTC = 0xFF;
	PORTD = 0xFF;

	//Initialise LED timings (added v1.1)
	clock_prescale_set(clock_div_1);
	MCUSR &= ~(1 << WDRF);
	wdt_disable();

	// Initialize the USB
	usb_init();

    //flash them leds
	#include "../shared/disco.c"

	while(!usb_configured());

//	// Wait for host to load drivers
//	_delay_ms(500);

	while(1) {
		uint8_t b = PINB;
		uint8_t c = PINC;
		uint8_t d = PIND;

		keycount = 0;

		//down
		if((!(c & 0x40))&&((c_prev & 0x40))) { keyboard_keys[keycount++] = map[17]; } //PIN B8
		if((!(c & 0x80))&&((c_prev & 0x80))) { keyboard_keys[keycount++] = map[16]; } //PIN B7
		if((!(b & 0x80))&&((b_prev & 0x80))) { keyboard_keys[keycount++] = map[15]; } //PIN B6
		if((!(b & 0x40))&&((b_prev & 0x40))) { keyboard_keys[keycount++] = map[14]; } //PIN B5
		if((!(b & 0x20))&&((b_prev & 0x20))) { keyboard_keys[keycount++] = map[13]; } //PIN B4
		if((!(b & 0x10))&&((b_prev & 0x10))) { keyboard_keys[keycount++] = map[12]; } //PIN B3
		if((!(b & 0x08))&&((b_prev & 0x08))) { keyboard_keys[keycount++] = map[11]; } //PIN B2
		if((!(b & 0x04))&&((b_prev & 0x04))) { keyboard_keys[keycount++] = map[10]; } //PIN B1
		if((!(d & 0x04))&&((d_prev & 0x04))) { keyboard_keys[keycount++] = map[3]; }  //PIN A4
		if((!(d & 0x02))&&((d_prev & 0x02))) { keyboard_keys[keycount++] = map[2]; }  //PIN A3
		if((!(d & 0x01))&&((d_prev & 0x01))) { keyboard_keys[keycount++] = map[1]; }  //PIN A2
		if((!(c & 0x04))&&((c_prev & 0x04))) { keyboard_keys[keycount++] = map[0]; }  //PIN A1

		//up
		if(((c & 0x40))&&(!(c_prev & 0x40))) { keyboard_keys[keycount++] = map[37]; } //PIN B8
		if(((c & 0x80))&&(!(c_prev & 0x80))) { keyboard_keys[keycount++] = map[36]; } //PIN B7
		if(((b & 0x80))&&(!(b_prev & 0x80))) { keyboard_keys[keycount++] = map[35]; } //PIN B6
		if(((b & 0x40))&&(!(b_prev & 0x40))) { keyboard_keys[keycount++] = map[34]; } //PIN B5
		if(((b & 0x20))&&(!(b_prev & 0x20))) { keyboard_keys[keycount++] = map[33]; } //PIN B4
		if(((b & 0x10))&&(!(b_prev & 0x10))) { keyboard_keys[keycount++] = map[32]; } //PIN B3
		if(((b & 0x08))&&(!(b_prev & 0x08))) { keyboard_keys[keycount++] = map[31]; } //PIN B2
		if(((b & 0x04))&&(!(b_prev & 0x04))) { keyboard_keys[keycount++] = map[30]; } //PIN B1
		if(((d & 0x04))&&(!(d_prev & 0x04))) { keyboard_keys[keycount++] = map[23]; }  //PIN A4
		if(((d & 0x02))&&(!(d_prev & 0x02))) { keyboard_keys[keycount++] = map[22]; }  //PIN A3
		if(((d & 0x01))&&(!(d_prev & 0x01))) { keyboard_keys[keycount++] = map[21]; }  //PIN A2
		if(((c & 0x04))&&(!(c_prev & 0x04))) { keyboard_keys[keycount++] = map[20]; }  //PIN A1
  			  
		while(keycount < sizeof(keyboard_keys)) {
			keyboard_keys[keycount++] = KEY_NONE;
		}

		usb_keyboard_send();


		b_prev = b;
		c_prev = c;
		d_prev = d;
		  
		_delay_ms(10); // Debounce
	}
}
Ejemplo n.º 15
0
int main(void)
{
	uint8_t b, d, mask, i, reset_idle;
	uint8_t b_prev=0xFF;

	// set for 16 MHz clock
	CPU_PRESCALE(0);

	// Configure all port B and port D pins as inputs with pullup resistors.
	// See the "Using I/O Pins" page for details.
	// http://www.pjrc.com/teensy/pins.html
	DDRB = 0x00;
	PORTB = 0xFF;
	DDRD = 0xFF;
	PORTD = 0x00;

	// Initialize the USB, and then wait for the host to set configuration.
	// If the Teensy is powered without a PC connected to the USB port,
	// this will wait forever.
	usb_init();
	while (!usb_configured()) /* wait */ ;

	// Wait an extra second for the PC's operating system to load drivers
	// and do whatever it does to actually be ready for input
	_delay_ms(1000);
    
    // Check if the last two switches are already shorted:
    // read all port B pins
    b = PINB;
    // check if any pins are low, if so mark them as shorted (0), if they are still high, mark them as open (1)
   
    for (i=0; i<sizeof(pns); i++) {
        if (((b & pns[i]) == 0)) {
            pnsActive[i] = 0;
        } else {
            pnsActive[i] = 1;
        }
    }

    
    // for ports that are active (not shorted) on B, light corresponding LEDs on D
    for (i=0; i<sizeof(pns); i++) {
        if (pnsActive[i] == 0) {
            PORTD &= ~(pns[i]);
        } else {
            PORTD |= (pns[i]);
        }
    }
    
    

	while (1) {
		// read all port B pins
		b = PINB;
		// if the pins were not shorted on boot, check if any pins are low, but were high previously
		for (i=0; i<sizeof(pns); i++) {
			if (pnsActive[i] && (((b & pns[i]) == 0) && (b_prev & pns[i]) != 0)) {
//				usb_keyboard_press(buttons[i], 0);
                keyboard_modifier_keys = 0;
                keyboard_keys[0] = buttons[i];
                usb_keyboard_send();
                _delay_ms(10);
                keyboard_keys[0] = 0;
                usb_keyboard_send();			}
		}

		// now the current pins will be the previous, and
		// wait a short delay so we're not highly sensitive
		// to mechanical "bounce".
		b_prev = b;
		_delay_ms(2);
	}
}
Ejemplo n.º 16
0
/*
 * main()
 */
int main(void) {
	kb_init();  // does controller initialization too

	kb_led_state_power_on();

	usb_init();
	while (!usb_configured());
	kb_led_delay_usb_init();  // give the OS time to load drivers, etc.

	kb_led_state_ready();

	for (;;) {
		// swap `main_kb_is_pressed` and `main_kb_was_pressed`, then update
		bool (*temp)[KB_ROWS][KB_COLUMNS] = main_kb_was_pressed;
		main_kb_was_pressed = main_kb_is_pressed;
		main_kb_is_pressed = temp;

		kb_update_matrix(*main_kb_is_pressed);

		// this loop is responsible to
		// - "execute" keys when they change state
		// - keep track of which layers the keys were on when they were pressed
		//   (so they can be released using the function from that layer)
		//
		// note
		// - everything else is the key function's responsibility
		//   - see the keyboard layout file ("keyboard/ergodox/layout/*.c") for
		//     which key is assigned which function (per layer)
		//   - see "lib/key-functions/public/*.c" for the function definitions
		#define row          main_loop_row
		#define col          main_loop_col
		#define layer        main_arg_layer
		#define is_pressed   main_arg_is_pressed
		#define was_pressed  main_arg_was_pressed
		for (row=0; row<KB_ROWS; row++) {
			for (col=0; col<KB_COLUMNS; col++) {
				is_pressed = (*main_kb_is_pressed)[row][col];
				was_pressed = (*main_kb_was_pressed)[row][col];

				if (is_pressed != was_pressed) {
					if (is_pressed) {
						layer = main_layers_peek(0);
						main_layers_pressed[row][col] = layer;
						main_arg_trans_key_pressed = false;
					} else {
						layer = main_layers_pressed[row][col];
						main_arg_trans_key_pressed = main_kb_was_transparent[row][col];
					}

					// set remaining vars, and "execute" key
					main_arg_row          = row;
					main_arg_col          = col;
					main_arg_layer_offset = 0;
					main_exec_key();
					main_kb_was_transparent[row][col] = main_arg_trans_key_pressed;
				}
			}
		}
		#undef row
		#undef col
		#undef layer
		#undef is_pressed
		#undef was_pressed

		// send the USB report (even if nothing's changed)
		usb_keyboard_send();
		usb_extra_consumer_send();
		_delay_ms(MAKEFILE_DEBOUNCE_TIME);

		// update LEDs
		/*if (keyboard_leds & (1<<0)) { kb_led_num_on(); }*/
		/*else { kb_led_num_off(); }*/
		if (keyboard_leds & (1<<1)) { kb_led_caps_on(); }
		else { kb_led_caps_off(); }
		if (keyboard_leds & (1<<2)) { kb_led_scroll_on(); }
		else { kb_led_scroll_off(); }
		if (keyboard_leds & (1<<3)) { kb_led_compose_on(); }
		else { kb_led_compose_off(); }
		if (keyboard_leds & (1<<4)) { kb_led_kana_on(); }
		else { kb_led_kana_off(); }
		if (layers_head != 0) { kb_led_num_on(); }
		else { kb_led_num_off(); }
	}

	return 0;
}
Ejemplo n.º 17
0
static inline void numpad_toggle_numlock(void) {
	_kbfun_press_release(true, KEY_LockingNumLock);
	usb_keyboard_send();
	_kbfun_press_release(false, KEY_LockingNumLock);
	usb_keyboard_send();
}