예제 #1
0
void bootmagic_lite(void)
{
	// The lite version of TMK's bootmagic.
	// 100% less potential for accidentally making the
	// keyboard do stupid things.

	// We need multiple scans because debouncing can't be turned off.
	matrix_scan();
	wait_ms(DEBOUNCING_DELAY);
	matrix_scan();

	// If the Esc and space bar are held down on power up,
	// reset the EEPROM valid state and jump to bootloader.
	// Assumes Esc is at [0,0] and spacebar is at [4,7].
	// This isn't very generalized, but we need something that doesn't
	// rely on user's keymaps in firmware or EEPROM.
	if ( ( matrix_get_row(0) & (1<<0) ) &&
		( matrix_get_row(4) & (1<<7) ) )
	{
		// Set the Zeal60 specific EEPROM state as invalid.
		eeprom_set_valid(false);
		// Set the TMK/QMK EEPROM state as invalid.
		eeconfig_disable();
		// Jump to bootloader.
		bootloader_jump();
	}
}
예제 #2
0
void bootmagic_lite(void) {
  // The lite version of TMK's bootmagic based on Wilba.
  // 100% less potential for accidentally making the
  // keyboard do stupid things.

  // We need multiple scans because debouncing can't be turned off.
  matrix_scan();
  #if defined(DEBOUNCING_DELAY) && DEBOUNCING_DELAY > 0
    wait_ms(DEBOUNCING_DELAY * 2);
  #elif defined(DEBOUNCE) && DEBOUNCE > 0
    wait_ms(DEBOUNCE * 2);
  #else
    wait_ms(30);
  #endif
  matrix_scan();

  // If the Esc and space bar are held down on power up,
  // reset the EEPROM valid state and jump to bootloader.
  // Assumes Esc is at [0,0].
  // This isn't very generalized, but we need something that doesn't
  // rely on user's keymaps in firmware or EEPROM.
  if (matrix_get_row(BOOTMAGIC_LITE_ROW) & (1 << BOOTMAGIC_LITE_COLUMN)) {
    eeconfig_disable();
    // Jump to bootloader.
    bootloader_jump();
  }
}
예제 #3
0
/*
 * Do keyboard routine jobs: scan mantrix, light LEDs, ...
 * This is repeatedly called as fast as possible.
 */
void keyboard_task(void)
{
    static matrix_row_t matrix_prev[MATRIX_ROWS];
    static uint8_t led_status = 0;
    matrix_row_t matrix_row = 0;
    matrix_row_t matrix_change = 0;

    matrix_scan();
    for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
        matrix_row = matrix_get_row(r);
        matrix_change = matrix_row ^ matrix_prev[r];
        if (matrix_change) {
            if (debug_matrix) matrix_print();
#ifdef MATRIX_HAS_GHOST
            if (has_ghost_in_row(r)) {
                matrix_prev[r] = matrix_row;
                continue;
            }
#endif
            for (uint8_t c = 0; c < MATRIX_COLS; c++) {
                if (matrix_change & ((matrix_row_t)1<<c)) {
                    action_exec((keyevent_t){
                        .key = (key_t){ .row = r, .col = c },
                        .pressed = (matrix_row & ((matrix_row_t)1<<c)),
                        .time = (timer_read() | 1) /* time should not be 0 */
                    });
                    // record a processed key
                    matrix_prev[r] ^= ((matrix_row_t)1<<c);
                    // process a key per task call
                    goto MATRIX_LOOP_END;
                }
            }
예제 #4
0
void keystrokes_task(void)
{
    struct keystroke keystroke;
    keystrokes_fulfill_irqs(INTERRUPT_UNCONDITIONAL, &keystroke);
    matrix_scan();
    leader_key_task();
}
예제 #5
0
bool suspend_wakeup_condition(void)
{
    matrix_scan();
    for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
        if (matrix_get_row(r)) return true;
    }
    return false;
}
예제 #6
0
 //Keyboard main function
 //Handles all keyboard related tasks
 void keyboard_main( )
 {
	//Update LEDs if USB in use (bluetooth uses different method)
	if(!bluefruit_configured())
		update_leds(keyboard_leds);
	
	uint8_t needs_debounce = 0; // For determining if matrix needs debouncing
	uint16_t matrix_changed = 0;
	matrix_scan();
	// Now that we have scanned the matrix, determine if any actions need to be done
	for (uint8_t row = 0; row < NUMROWS; row++)
	{
		//Check to see if switches in this row has changed
		if ((matrix_changed = matrix_rows[row] ^ matrix_last[row]))
		{
			//At least one switch has changed in this row
			needs_debounce = 1; //We need to debounce
			for (int col = 0; col < NUMCOLS; col++)
			{
				//Find out which columns have changed and act
				if(matrix_changed & ((uint16_t)1<< col))
				{
					//This switch has changed, do whatever the switch was programmed to do
					if(matrix_rows[row] & ((uint16_t)1<< col))
					{
						//Keydown event
						key_execute(get_keycode(row,col),KEY_IS_DOWN);
						//phex(get_keycode(row,col).type);
						//print(":");
						//phex(get_keycode(row,col).code);
						//print(" key is down\n");
					}
					else
					{
						//Keyup event
						key_execute(get_keycode(row,col),KEY_IS_UP);
						//phex(get_keycode(row,col).type);
						//print(":");
						//phex(get_keycode(row,col).code);
						//print(" key is up\n");
					}
					
				}
			}
			matrix_last[row] = matrix_rows[row]; //Row has been dealt with
		}
		else
		{
			//Nothing has changed, do nothing?
		}
	}
	//Allow switch state to stabilize if an edge is detected.
	if (needs_debounce)
		_delay_us(DEBOUNCE_TIME);
 }
예제 #7
0
파일: keyboard.c 프로젝트: mxkl/gh60
/** Main program entry point. This routine contains the overall program flow, including initial
 *  setup of all components and the main program loop.
 */
int main(void)
{
  GlobalInterruptEnable();

  initialize_hardware();

  while (true) {
    matrix_scan();
    HID_Device_USBTask(&Keyboard_HID_Interface);
    USB_USBTask();
  }
}
예제 #8
0
/*
 * Do keyboard routine jobs: scan matrix, light LEDs, ...
 * This is repeatedly called as fast as possible.
 */
void keyboard_task(void)
{
    static matrix_row_t matrix_prev[MATRIX_ROWS];
#ifdef MATRIX_HAS_GHOST
  //  static matrix_row_t matrix_ghost[MATRIX_ROWS];
#endif
    static uint8_t led_status = 0;
    matrix_row_t matrix_row = 0;
    matrix_row_t matrix_change = 0;
#ifdef QMK_KEYS_PER_SCAN
    uint8_t keys_processed = 0;
#endif

    matrix_scan();
    if (is_keyboard_master()) {
        for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
            matrix_row = matrix_get_row(r);
            matrix_change = matrix_row ^ matrix_prev[r];
            if (matrix_change) {
#ifdef MATRIX_HAS_GHOST
                if (has_ghost_in_row(r, matrix_row)) {
                    /* Keep track of whether ghosted status has changed for
                    * debugging. But don't update matrix_prev until un-ghosted, or
                    * the last key would be lost.
                    */
                    //if (debug_matrix && matrix_ghost[r] != matrix_row) {
                    //    matrix_print();
                    //}
                    //matrix_ghost[r] = matrix_row;
                    continue;
                }
                //matrix_ghost[r] = matrix_row;
#endif
                if (debug_matrix) matrix_print();
                for (uint8_t c = 0; c < MATRIX_COLS; c++) {
                    if (matrix_change & ((matrix_row_t)1<<c)) {
                        action_exec((keyevent_t){
                            .key = (keypos_t){ .row = r, .col = c },
                            .pressed = (matrix_row & ((matrix_row_t)1<<c)),
                            .time = (timer_read() | 1) /* time should not be 0 */
                        });
                        // record a processed key
                        matrix_prev[r] ^= ((matrix_row_t)1<<c);
#ifdef QMK_KEYS_PER_SCAN
                        // only jump out if we have processed "enough" keys.
                        if (++keys_processed >= QMK_KEYS_PER_SCAN)
#endif
                        // process a key per task call
                        goto MATRIX_LOOP_END;
                    }
                }
            }
예제 #9
0
void keyboard_post_init_rgb(void) {
#if defined(RGBLIGHT_ENABLE) && defined(RGBLIGHT_STARTUP_ANIMATION)
    if (userspace_config.rgb_layer_change) { rgblight_enable_noeeprom(); }
    if (rgblight_config.enable) {
        layer_state_set_user(layer_state);
        uint16_t old_hue = rgblight_config.hue;
        rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
        for (uint16_t i = 255; i > 0; i--) {
            rgblight_sethsv_noeeprom( ( i + old_hue) % 255, 255, 255);
            matrix_scan();
            wait_ms(10);
        }
    }
#endif
    layer_state_set_user(layer_state);
}
예제 #10
0
int main(void)
{
    DEBUG_LED_CONFIG;
    DEBUG_LED_OFF;

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

    // 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 */ ;

    keyboard_init();
    matrix_scan();
    if (matrix_key_count() >= 3) {
#ifdef DEBUG_LED
        for (int i = 0; i < 6; i++) {
            DEBUG_LED_CONFIG;
            DEBUG_LED_ON;
            _delay_ms(500);
            DEBUG_LED_OFF;
            _delay_ms(500);
        }
#else
        _delay_ms(5000);
#endif
        print_enable = true;
        debug_enable = true;
        debug_matrix = true;
        debug_keyboard = true;
        debug_mouse = true;
        print("debug enabled.\n");
    }
    if (matrix_key_count() >= 4) {
        print("jump to bootloader...\n");
        _delay_ms(1000);
        bootloader_jump(); // not return
    }


    host_set_driver(pjrc_driver());
    while (1) {
       keyboard_proc(); 
    }
}
예제 #11
0
/*
 * Do keyboard routine jobs: scan mantrix, light LEDs, ...
 * This is repeatedly called as fast as possible.
 */
void keyboard_task(void)
{
    static matrix_col_t matrix_prev[MATRIX_COLS];
#ifdef MATRIX_HAS_GHOST
    static matrix_col_t matrix_ghost[MATRIX_COLS];
#endif
    static uint8_t led_status = 0;
    matrix_col_t matrix_col = 0;
    matrix_col_t matrix_change = 0;

    matrix_scan();
    for (uint8_t c = 0; c < MATRIX_COLS; c++) {
        matrix_col = matrix_get_col(c);
        matrix_change = matrix_col ^ matrix_prev[c];
        if (matrix_change) {
#ifdef MATRIX_HAS_GHOST
            if (has_ghost_in_col(c)) {
                /* Keep track of whether ghosted status has changed for
                 * debugging. But don't update matrix_prev until un-ghosted, or
                 * the last key would be lost.
                 */
                if (debug_matrix && matrix_ghost[c] != matrix_col) {
                    matrix_print();
                }
                matrix_ghost[c] = matrix_col;
                continue;
            }
            matrix_ghost[c] = matrix_col;
#endif
            if (debug_matrix) matrix_print();
            for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
                if (matrix_change & ((matrix_col_t)1<<r)) {
                    keyevent_t e = (keyevent_t){
                        .key = (keypos_t){ .row = r, .col = c },
                        .pressed = (matrix_col & ((matrix_col_t)1<<r)),
                        .time = (timer_read() | 1) /* time should not be 0 */
                    };
                    action_exec(e);
                    hook_matrix_change(e);
                    // record a processed key
                    matrix_prev[c] ^= ((matrix_col_t)1<<r);
                    // process a key per task call
                    goto MATRIX_LOOP_END;
                }
            }
        }
    }
예제 #12
0
/*
 * Do keyboard routine jobs: scan mantrix, light LEDs, ...
 * This is repeatedly called as fast as possible.
 */
 void keyboard_task(void)
{
	static uint8_t led_status = 0;
	static matrix_row_t matrix_prev[MATRIX_ROWS];
	matrix_row_t matrix_row = 0;
    matrix_row_t matrix_change = 0;

	matrix_scan();
//	TRANS();

	for(uint8_t r = 0; r < MATRIX_ROWS; r++)
	{
		matrix_row = CODE[r];
		matrix_change = matrix_row ^ matrix_prev[r];
		if(matrix_change)
		{
			for(uint8_t c = 0; c < MATRIX_COLS; c++)
			{
				if(matrix_change & ((matrix_row_t)1<<c))
				{
					action_exec
					(
						(keyevent_t)
						{
							.key = (key_t)
								{
									.row = r, .col = c
								},
							.pressed = (matrix_row & ((matrix_row_t)1<<c)),
							.time = (timer_read() | 1)
						}
					);
					//record a processed key
					matrix_prev[r] ^= ((matrix_row_t)1<<c);
					//process a key per task call
					goto MATRIX_LOOP_END;
				}
			}
예제 #13
0
파일: main.c 프로젝트: ksrm/redox
int main() {

    uint8_t i, change;
    uint8_t hand;
    uint32_t timeout = 0;

    uart_init();
    xdev_out(uart_putchar);

    // Determine which hand this is from PE2
    // Left is hand 0, right is hand 1
    PORTE = (1 << 2);
    DDRE = 0;
    hand = (PINE & 0x04) ? 0 : 1;
    xprintf("\r\nHand %d\r\n", hand);
    
    // Initialise NRF24
    // Set the last byte of the address to the hand ID
    rx_address[4] = hand;
    nrf24_init();
    nrf24_config(CHANNEL, sizeof msg);
    nrf24_tx_address(tx_address);
    nrf24_rx_address(rx_address);

    matrix_init();

    msg[0] = hand & 0x01;
    msg[1] = 0;
    msg[2] = 0;

    // Set up LED and flash it briefly
    DDRE |= 1<<6;
    PORTE = 1<<6;
    _delay_ms(500);
    PORTE = 0;

    get_voltage();
    check_voltage();

    // Scan the matrix and detect any changes.
    // Modified rows are sent to the receiver.
    while (1) {  
        timeout++;
        matrix_scan();

        for (i=0; i<ROWS; i++) {
            change = matrix_prev[i] ^ matrix[i];

            // If this row has changed, send the row number and its current state
            if (change) {
                if (DEBUG) xprintf("%d %08b -> %08b   %ld\r\n", i, matrix_prev[i], matrix[i], timeout);
                msg[1] = i;
                msg[2] = matrix[i];

                nrf24_send(msg);
                while (nrf24_isSending());
                timeout = 0;
            }

            matrix_prev[i] = matrix[i];
        }

        // Sleep if there has been no activity for a while
        if (timeout > SLEEP_TIMEOUT) {
            timeout = 0;
            enter_sleep_mode();
        }
    }

}
예제 #14
0
void bootmagic(void)
{
    /* check signature */
    if (!eeconfig_is_enabled()) {
        eeconfig_init();
    }

    /* do scans in case of bounce */
    print("bootmagic scan: ... ");
    uint8_t scan = 100;
    while (scan--) { matrix_scan(); wait_ms(10); }
    print("done.\n");

    /* bootmagic skip */
    if (bootmagic_scan_key(BOOTMAGIC_KEY_SKIP)) {
        return;
    }

    /* eeconfig clear */
    if (bootmagic_scan_key(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
        eeconfig_init();
#ifdef KEYMAP_IN_EEPROM_ENABLE
        write_keymap_to_eeprom();
#endif
#ifdef LEDMAP_IN_EEPROM_ENABLE
        write_ledmap_to_eeprom();
#endif
    }

    /* bootloader */
    if (bootmagic_scan_key(BOOTMAGIC_KEY_BOOTLOADER)) {
        bootloader_jump();
    }

    /* user-defined checks */
    hook_bootmagic();

    /* debug enable */
    debug_config.raw = eeconfig_read_debug();
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
        if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
            debug_config.matrix = !debug_config.matrix;
        } else if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
            debug_config.keyboard = !debug_config.keyboard;
        } else if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
            debug_config.mouse = !debug_config.mouse;
        } else {
            debug_config.enable = !debug_config.enable;
        }
    }
    eeconfig_write_debug(debug_config.raw);

    /* keymap config */
    keymap_config.raw = eeconfig_read_keymap();
    if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
        keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
    }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
        keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
    }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
        keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
    }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
        keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
    }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_NO_GUI)) {
        keymap_config.no_gui = !keymap_config.no_gui;
    }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
        keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
    }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
        keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
    }
    if (bootmagic_scan_key(BOOTMAGIC_HOST_NKRO)) {
        keymap_config.nkro = !keymap_config.nkro;
    }
    eeconfig_write_keymap(keymap_config.raw);

#ifdef NKRO_ENABLE
    keyboard_nkro = keymap_config.nkro;
#endif

    /* default layer */
    uint8_t default_layer = 0;
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
    if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
    if (default_layer) {
        eeconfig_write_default_layer(default_layer);
        default_layer_set((uint32_t)default_layer);
    } else {
        default_layer = eeconfig_read_default_layer();
        default_layer_set((uint32_t)default_layer);
    }
}