Exemple #1
0
uint8_t _matrix_scan(void)
{
    // Right hand is stored after the left in the matirx so, we need to offset it
    int offset = isLeftHand ? 0 : (ROWS_PER_HAND);

    for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
        select_row(i);
        _delay_us(30);  // without this wait read unstable value.
        matrix_row_t cols = read_cols();
        if (matrix_debouncing[i+offset] != cols) {
            matrix_debouncing[i+offset] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < ROWS_PER_HAND; i++) {
                matrix[i+offset] = matrix_debouncing[i+offset];
            }
        }
    }

    return 1;
}
Exemple #2
0
uint8_t matrix_scan(void)
{

    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        select_row(i);
        _delay_us(30);  // without this wait read unstable value.
        matrix_row_t cols = read_cols();
        if (matrix_debouncing[i] != cols) {
            matrix_debouncing[i] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    return 1;
}
AbstractQoreNode *command::read_rows(Placeholders *placeholder_list, bool list, ExceptionSink* xsink) {
   if (ensure_colinfo(xsink)) return 0;

   // setup hash of lists if necessary
   if (!list) {
      if (!placeholder_list) {
	 return read_cols(0, xsink);
      }
      return read_cols(placeholder_list, xsink);
   } else {
      if (!placeholder_list) {
	 return read_rows(0, xsink);
      }
      return read_rows(placeholder_list, xsink);
   }
}
Exemple #4
0
uint8_t matrix_scan(void) {
    static matrix_row_t debouncing_matrix[MATRIX_ROWS];
    for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
        toggle_row(r);
        matrix_row_t state = read_cols();
        if (debouncing_matrix[r] != state) {
            debouncing_matrix[r] = state;
            debouncing_delay = DEBOUNCING_DELAY;
        }
        toggle_row(r);
    }
    if (debouncing_delay >= 0) {
        dprintf("Debouncing delay remaining: %X\n", debouncing_delay);
        --debouncing_delay;
        if (debouncing_delay >= 0) {
            wait_ms(1);
        }
        else {
            for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
                matrix[r] = debouncing_matrix[r];
            }
        }
    }
    matrix_scan_quantum();
    return 1;
}
Exemple #5
0
uint8_t matrix_scan(void)
{
    if (mcp23018_status) { // if there was an error
        if (++mcp23018_reset_loop == 0) {
            // since mcp23018_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans
            // this will be approx bit more frequent than once per second
            print("trying to reset mcp23018\n");
            mcp23018_status = init_mcp23018();
            if (mcp23018_status) {
                print("left side not responding\n");
            } else {
                print("left side attached\n");
                frenchdev_blink_all_leds();
            }
        }
    }

#ifdef DEBUG_MATRIX_SCAN_RATE
    matrix_scan_count++;

    uint32_t timer_now = timer_read32();
    if (TIMER_DIFF_32(timer_now, matrix_timer)>1000) {
        print("matrix scan frequency: ");
        pdec(matrix_scan_count);
        print("\n");

        matrix_timer = timer_now;
        matrix_scan_count = 0;
    }
#endif

    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        select_row(i);
        wait_us(30);  // without this wait read unstable value.
        matrix_row_t cols = read_cols(i);
        if (matrix_debouncing[i] != cols) {
            matrix_debouncing[i] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            wait_us(1);
            // this should be wait_ms(1) but has been left as-is at EZ's request
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    matrix_scan_quantum();

    return 1;
}
Exemple #6
0
uint8_t matrix_scan(void)
{
	for (uint8_t row = 0; row < MATRIX_ROWS; row++)
	{
		select_row(row);
		_delay_us(15);  // without this wait it will read unstable value. 10? 50?
		matrix_row_t cols = read_cols();

		if (cols)
			LedInfo1_On();
		else
			LedInfo1_Off();

		if (matrix_debouncing[row] != cols)
		{
			//dprintf("bounce %u\r\n", row);

			matrix_debouncing[row] = cols;
			debouncing_times[row] = timer_read();
			debouncing[row] = true;
		}

		unselect_rows();
	}

	for (uint8_t row = 0; row < MATRIX_ROWS; row++)
	{
		if (debouncing[row])
		{
			LedInfo2_On();

			if (timer_elapsed(debouncing_times[row]) > DEBOUNCE_TIME)
			{
				//dprintf("bounced %u\r\n", row);

				matrix[row] = matrix_debouncing[row];
				debouncing[row] = false;

				send_row_to_other_side(row, matrix[row]);
				mcpu_send_typematrix_row(row, matrix[row]);
				animation_typematrix_row(row, matrix[row]);
			}
		}
		else
		{
			LedInfo2_Off();
		}
	}

	splitbrain_communication_task();

#ifdef BACKLIGHT_ENABLE
	animate();
#endif

	return 1;
}
Exemple #7
0
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row) {
  // Store last value of row prior to reading
  matrix_row_t last_row_value = current_matrix[current_row];

  // Clear data in matrix row
  current_matrix[current_row] = 0;

  // Select row and wait for row selecton to stabilize
  select_row(current_row);
  wait_us(30);

  current_matrix[current_row] = read_cols();

  // No need to Unselect row as the next `select_row` will blank everything

  return (last_row_value != current_matrix[current_row]);
}
Exemple #8
0
uint8_t matrix_scan() {

    // Update LED states if necessary:
#ifdef LED_CONTROLLER_ENABLE
    led_update();
#endif

    for ( uint8_t i = 0; i < MATRIX_ROWS; i++ ) {

        select_row( i );
        _delay_us( 30 );  // without this wait read unstable value.

        matrix_row_t cols = read_cols();

        if ( matrix_debouncing[ i ] != cols ) {

            matrix_debouncing[ i ] = cols;

            if ( debouncing ) {

                debug("bounce!: ");
                debug_hex( debouncing );
                debug( "\n" );
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if ( debouncing ) {

        if ( --debouncing ) {

            _delay_ms( 1 );

        } else {

            for ( uint8_t i = 0; i < MATRIX_ROWS; i++ ) {
                matrix[ i ] = matrix_debouncing[ i ];
            }
        }
    }

    return 1;
}
Exemple #9
0
uint8_t matrix_scan(void)
{
    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        select_row(i);
        _delay_us(30);  // without this wait read unstable value.
        matrix_row_t cols = read_cols();
        if (matrix_debouncing[i] != cols) {
            matrix_debouncing[i] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    uint8_t layer = biton32(layer_state);
    switch (layer) {
        case 1:
        case 2:
            DDRC |= (1<<7);
            PORTC |= (1<<7);
            break;
        case 0:
            DDRC &= ~(1<<7);
            PORTC &= ~(1<<7);
            break;
    }

    return 1;
}
Exemple #10
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();
			///////////////////////////////////
		}
}
// Get the pressed key. returns 1 if a key was found to be pressed and 0 otherwise.
int get_key(char * key){	
	
	int i, j;
	
	for (i = 0; i < NUM_ROWS; i++){
		// reset the row bits and then set to a new possible row pattern.
		GPIO_ResetBits(GPIOE, ALL_ROW_PINS);
		GPIO_SetBits(GPIOE, row_pins[i]);
		
		uint8_t col_value = read_cols();	
		
		// iterate through all the possible column values (or stop early if a match was found).
		for (j = 0; j < NUM_COLS; j++){
			if (col_values[j] == col_value){
				*key = keys[i][j];	
				
				return 1;
			}	
		}
	}	
	*key = DUMMY_KEY;
	
	return 0;
}
Exemple #12
0
uint8_t matrix_scan(void)
{
#if DIODE_DIRECTION == COL2ROW
    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        select_row(i);
        _delay_us(30);  // without this wait read unstable value.
        matrix_row_t cols = read_cols();
        if (matrix_debouncing[i] != cols) {
            matrix_debouncing[i] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }
#else
    for (uint8_t i = 0; i < MATRIX_COLS; i++) {
        select_row(i);
        _delay_us(30);  // without this wait read unstable value.
        matrix_row_t rows = read_cols();
        if (matrix_reversed_debouncing[i] != rows) {
            matrix_reversed_debouncing[i] = rows;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_COLS; i++) {
                matrix_reversed[i] = matrix_reversed_debouncing[i];
            }
        }
    }
    for (uint8_t y = 0; y < MATRIX_ROWS; y++) {
        matrix_row_t row = 0;
        for (uint8_t x = 0; x < MATRIX_COLS; x++) {
            row |= ((matrix_reversed[x] & (1<<y)) >> y) << x;
        }
        matrix[y] = row;
    }
#endif

    return 1;
}
Exemple #13
0
uint8_t matrix_scan(void)
{
    if (mcp23018_status) { // if there was an error
        if (++mcp23018_reset_loop == 0) {
            // since mcp23018_reset_loop is 8 bit - we'll try to reset once in 255 matrix scans
            // this will be approx bit more frequent than once per second
            print("trying to reset mcp23018\n");
            mcp23018_status = init_mcp23018();
            if (mcp23018_status) {
                print("left side not responding\n");
            } else {
                print("left side attached\n");
                ergodox_blink_all_leds();
            }
        }
    }

#ifdef DEBUG_MATRIX_FREQ
    matrix_scan_count++;

    uint32_t timer_now = timer_read32();
    if (TIMER_DIFF_32(timer_now, matrix_timer)>1000) {
        print("matrix scan frequency: ");
        pdec(matrix_scan_count);
        print("\n");

        matrix_timer = timer_now;
        matrix_scan_count = 0;
    }
#endif

#ifdef KEYMAP_CUB
    uint8_t layer = biton32(layer_state);

    ergodox_board_led_off();
    ergodox_left_led_1_off();
    ergodox_left_led_2_off();
    ergodox_left_led_3_off();
    switch (layer) {
        case 1:
            // all
            ergodox_left_led_1_on();
            ergodox_left_led_2_on();
            ergodox_left_led_3_on();
            break;
        case 2:
            // blue
            ergodox_left_led_2_on();
            break;
        case 8:
            // blue and green
            ergodox_left_led_2_on();
            // break missed intentionally
        case 3:
            // green
            ergodox_left_led_3_on();
            break;
        case 6:
            ergodox_board_led_on();
            // break missed intentionally
        case 4:
        case 5:
        case 7:
            // red
            ergodox_left_led_1_on();
            break;
        default:
            // none
            break;
    }

    mcp23018_status = ergodox_left_leds_update();
#endif

#ifdef KEYMAP_SIMON
    uint8_t layer = biton32(layer_state);

    ergodox_board_led_off();
    switch (layer) {
        case 0:
// none

            break;
        default:
            ergodox_board_led_on();
            break;
    }
#endif

    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        select_row(i);
        matrix_row_t cols = read_cols(i);
        if (matrix_debouncing[i] != cols) {
            matrix_debouncing[i] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows();
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    return 1;
}
Exemple #14
0
uint8_t matrix_scan(void)
{
#ifdef ERGODOX_LEFT_LEDS
    uint8_t layer = biton32(layer_state);

    if (layer == 1) {
        ergodox_left_led_1_on();
        ergodox_left_led_2_off();
        ergodox_left_led_3_off();
    } else if (layer == 2) {
        ergodox_left_led_1_off();
        ergodox_left_led_2_on();
        ergodox_left_led_3_off();
    } else if (layer == 3) {
        ergodox_left_led_1_off();
        ergodox_left_led_2_off();
        ergodox_left_led_3_on();
    } else if (layer == 4) {
        ergodox_left_led_1_on();
        ergodox_left_led_2_off();
        ergodox_left_led_3_on();
    } else if (layer == 5) {
        ergodox_left_led_1_on();
        ergodox_left_led_2_on();
        ergodox_left_led_3_off();
    } else if (layer == 6) {
        ergodox_left_led_1_off();
        ergodox_left_led_2_on();
        ergodox_left_led_3_on();
    } else if (layer == 7) {
        ergodox_left_led_1_on();
        ergodox_left_led_2_on();
        ergodox_left_led_3_on();
    } else {
        ergodox_left_led_1_off();
        ergodox_left_led_2_off();
        ergodox_left_led_3_off();
    }

    // not actually needed because we already calling init_mcp23018() in next line
    // ergodox_left_leds_update();

#endif

    uint8_t mcp23018_status = init_mcp23018();

    for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
        select_row(mcp23018_status, i);
        _delay_us(30);  // without this wait read unstable value.
        matrix_row_t cols = read_cols(mcp23018_status, i);
        if (matrix_debouncing[i] != cols) {
            matrix_debouncing[i] = cols;
            if (debouncing) {
                debug("bounce!: "); debug_hex(debouncing); debug("\n");
            }
            debouncing = DEBOUNCE;
        }
        unselect_rows(mcp23018_status);
    }

    if (debouncing) {
        if (--debouncing) {
            _delay_ms(1);
        } else {
            for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                matrix[i] = matrix_debouncing[i];
            }
        }
    }

    return 1;
}
Exemple #15
0
int main(void) {
     /* pin map:
      *
      * PB0 hardware shift (r/l, TODO: split r/l)
      * PB1 row data out (to 74HC595)
      * PB2 row shift (same)
      * PB3 row X8 direct output
      * PB4 col in  Y9
      * PB5 col in  Y8
      * PB6 XTAL
      * PB7 XTAL
      *
      * PC0 col in  Y5
      * PC1 col in  Y0
      * PC2 col in  Y1
      * PC3 col in  Y2
      * PC4 col in  Y3
      * PC5 col in  Y4
      * PC6 !RESET
      *
      * PD0 RXD
      * PD1 TXD
      * PD2 col in  Y6
      * PD3 col in  Y7
      * PD4 NC
      * PD5 NC
      * PD6 NC
      * PD7 NC
      *
      * We're not un-scrambling the rows here, we are just using them directly to index the lookup table.
      *
      * The device outputs 9N1 (!) data on its uart. The 9th bit indicates key press (1) or release (0), the remaining 8
      * bits the USB HID keycode.
      */
    DDRB   = 0x0f; /* row outputs, shift */

    /* uart setup */
    DDRD  |= 0x02;
    UBRR0  = F_CPU/16/(BAUDRATE-1);
    UCSR0B = (1<<TXEN0) | (1<<UCSZ02);
    UCSR0C = (1<<UCSZ01) | (1<<UCSZ00);

    int ridx = 0;
    reset_row();
    while (23) {
        uint16_t cols = read_cols();

        uint8_t cidx = ridx;
        if (ridx == 30)
            cols |= (PINB&1)<<1; /* map hard shift to keycode 0x1f (31) */
        while (cidx < ridx+10) {
            if (keystate[cidx] > 1) {
                keystate[cidx]--;
            } else if (keystate[cidx] < 0) {
                keystate[cidx]++;
            } else {
                uint8_t c = keymap[cidx];
                if (cols & 1) {
                    if (!keystate[cidx]) {
                        keystate[cidx] = DEBOUNCE_TIME;
                        report_down(c);
                    }
                } else {
                    if (keystate[cidx]) {
                        keystate[cidx] = -DEBOUNCE_TIME;
                        report_up(c);
                    }
                }
            }
            cidx ++;
            cols >>= 1;
        }

        if (ridx == 80) {
            ridx = 0;
            reset_row();
        } else {
            ridx += 10;
            next_row();
        }
        _delay_us(100);
    }
}
Exemple #16
0
uint8_t matrix_scan(void)
{
#ifdef DEBUG_SHOW_SCAN_LED
	LedInfo2_On();
#endif

    for (uint8_t row = 0; row < MATRIX_ROWS; row++)
    {
        select_row(row);
        _delay_us(15); // without this wait read unstable value.
        matrix_row_t cols = read_cols();

#ifndef DEBUG_SHOW_SCAN_LED
        if (cols)
            LedInfo2_On();
        else
            LedInfo2_Off();
#endif

        if (matrix_debouncing[row] != cols)
        {
            // dprintf("bounce %u\r\n", row);

            matrix_debouncing[row] = cols;
            debouncing_times[row] = timer_read();
            debouncing[row] = true;
        }

        unselect_rows();
    }

#if 0
    if (debouncing)
    {
        LedInfo1_On();

    	if (timer_elapsed(debouncing_time) > DEBOUNCE_TIME)
    	{
			for (int i = 0; i < MATRIX_ROWS; i++)
			{
				matrix[i] = matrix_debouncing[i];
			}

			debouncing = false;
    	}
    }
    else
    {
        LedInfo1_Off();
    }
#endif

    for (uint8_t row = 0; row < MATRIX_ROWS; row++)
    {
        if (debouncing[row])
        {
            LedInfo1_On();

            if (timer_elapsed(debouncing_times[row]) > DEBOUNCE_TIME)
            {
                // dprintf("bounced %u\r\n", row);

                matrix[row] = matrix_debouncing[row];
                debouncing[row] = false;

                animation_typematrix_row(row, matrix[row]);
            }
        }
        else
        {
            LedInfo1_Off();
        }
    }

#ifdef BACKLIGHT_ENABLE
    animate();
#endif

#ifdef DEBUG_SHOW_SCAN_LED
    LedInfo2_Off();
#endif

    return 1;
}