diff options
| author | Jack Humbert <jack.humb@gmail.com> | 2016-07-05 23:27:10 -0400 |
|---|---|---|
| committer | Jack Humbert <jack.humb@gmail.com> | 2016-07-05 23:27:10 -0400 |
| commit | d707738616c140f8d9c8eded7b64e5fc806f4b24 (patch) | |
| tree | f8aaebebb526903bb49283aa9fa53242c4bf793b | |
| parent | 96f44e120295e677d21d3dbb9dc4bf642ba2af09 (diff) | |
| download | qmk_firmware-d707738616c140f8d9c8eded7b64e5fc806f4b24.tar.gz qmk_firmware-d707738616c140f8d9c8eded7b64e5fc806f4b24.zip | |
i2c working
20 files changed, 1827 insertions, 21 deletions
diff --git a/keyboards/lets-split/lets-split.h b/keyboards/lets-split/lets-split.h deleted file mode 100644 index c82b95a37..000000000 --- a/keyboards/lets-split/lets-split.h +++ /dev/null | |||
| @@ -1,4 +0,0 @@ | |||
| 1 | #include "quantum.h" | ||
| 2 | #include <avr/wdt.h> | ||
| 3 | |||
| 4 | void promicro_bootloader_jmp(bool program); \ No newline at end of file | ||
diff --git a/keyboards/lets-split/Makefile b/keyboards/lets_split/Makefile index 247f978f0..d8e283896 100644 --- a/keyboards/lets-split/Makefile +++ b/keyboards/lets_split/Makefile | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | 1 | SRC += matrix.c \ | |
| 2 | i2c.c \ | ||
| 3 | split_util.c | ||
| 2 | 4 | ||
| 3 | # MCU name | 5 | # MCU name |
| 4 | #MCU = at90usb1287 | 6 | #MCU = at90usb1287 |
| @@ -68,6 +70,8 @@ RGBLIGHT_ENABLE ?= no # Enable WS2812 RGB underlight. Do not enable this | |||
| 68 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE | 70 | # Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE |
| 69 | SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend | 71 | SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend |
| 70 | 72 | ||
| 73 | CUSTOM_MATRIX = yes | ||
| 74 | |||
| 71 | ifndef QUANTUM_DIR | 75 | ifndef QUANTUM_DIR |
| 72 | include ../../Makefile | 76 | include ../../Makefile |
| 73 | endif \ No newline at end of file | 77 | endif \ No newline at end of file |
diff --git a/keyboards/lets-split/config.h b/keyboards/lets_split/config.h index 5b464147d..e68787e0b 100644 --- a/keyboards/lets-split/config.h +++ b/keyboards/lets_split/config.h | |||
| @@ -29,12 +29,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 29 | #define DESCRIPTION A split keyboard for the cheap makers | 29 | #define DESCRIPTION A split keyboard for the cheap makers |
| 30 | 30 | ||
| 31 | /* key matrix size */ | 31 | /* key matrix size */ |
| 32 | #define MATRIX_ROWS 4 | 32 | #define MATRIX_ROWS 8 |
| 33 | #define MATRIX_COLS 6 | 33 | #define MATRIX_COLS 6 |
| 34 | 34 | ||
| 35 | #define MATRIX_ROW_PINS { B5, B4, E6, D7, } | 35 | // wiring of each half |
| 36 | #define MATRIX_ROW_PINS { B5, B4, E6, D7 } | ||
| 36 | #define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3 } | 37 | #define MATRIX_COL_PINS { F4, F5, F6, F7, B1, B3 } |
| 37 | 38 | ||
| 39 | #define USE_I2C | ||
| 40 | |||
| 41 | // #define I2C_MASTER_LEFT | ||
| 42 | #define I2C_MASTER_RIGHT | ||
| 43 | |||
| 38 | /* COL2ROW or ROW2COL */ | 44 | /* COL2ROW or ROW2COL */ |
| 39 | #define DIODE_DIRECTION COL2ROW | 45 | #define DIODE_DIRECTION COL2ROW |
| 40 | 46 | ||
diff --git a/keyboards/lets_split/i2c.c b/keyboards/lets_split/i2c.c new file mode 100644 index 000000000..c72789403 --- /dev/null +++ b/keyboards/lets_split/i2c.c | |||
| @@ -0,0 +1,159 @@ | |||
| 1 | #include <util/twi.h> | ||
| 2 | #include <avr/io.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <avr/interrupt.h> | ||
| 5 | #include <util/twi.h> | ||
| 6 | #include <stdbool.h> | ||
| 7 | #include "i2c.h" | ||
| 8 | |||
| 9 | // Limits the amount of we wait for any one i2c transaction. | ||
| 10 | // Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is | ||
| 11 | // 9 bits, a single transaction will take around 90μs to complete. | ||
| 12 | // | ||
| 13 | // (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit | ||
| 14 | // poll loop takes at least 8 clock cycles to execute | ||
| 15 | #define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8 | ||
| 16 | |||
| 17 | #define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE) | ||
| 18 | |||
| 19 | volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; | ||
| 20 | |||
| 21 | static volatile uint8_t slave_buffer_pos; | ||
| 22 | static volatile bool slave_has_register_set = false; | ||
| 23 | |||
| 24 | // Wait for an i2c operation to finish | ||
| 25 | inline static | ||
| 26 | void i2c_delay(void) { | ||
| 27 | uint16_t lim = 0; | ||
| 28 | while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT) | ||
| 29 | lim++; | ||
| 30 | |||
| 31 | // easier way, but will wait slightly longer | ||
| 32 | // _delay_us(100); | ||
| 33 | } | ||
| 34 | |||
| 35 | // Setup twi to run at 100kHz | ||
| 36 | void i2c_master_init(void) { | ||
| 37 | // no prescaler | ||
| 38 | TWSR = 0; | ||
| 39 | // Set TWI clock frequency to SCL_CLOCK. Need TWBR>10. | ||
| 40 | // Check datasheets for more info. | ||
| 41 | TWBR = ((F_CPU/SCL_CLOCK)-16)/2; | ||
| 42 | } | ||
| 43 | |||
| 44 | // Start a transaction with the given i2c slave address. The direction of the | ||
| 45 | // transfer is set with I2C_READ and I2C_WRITE. | ||
| 46 | // returns: 0 => success | ||
| 47 | // 1 => error | ||
| 48 | uint8_t i2c_master_start(uint8_t address) { | ||
| 49 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA); | ||
| 50 | |||
| 51 | i2c_delay(); | ||
| 52 | |||
| 53 | // check that we started successfully | ||
| 54 | if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START)) | ||
| 55 | return 1; | ||
| 56 | |||
| 57 | TWDR = address; | ||
| 58 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 59 | |||
| 60 | i2c_delay(); | ||
| 61 | |||
| 62 | if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) ) | ||
| 63 | return 1; // slave did not acknowledge | ||
| 64 | else | ||
| 65 | return 0; // success | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | // Finish the i2c transaction. | ||
| 70 | void i2c_master_stop(void) { | ||
| 71 | TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); | ||
| 72 | |||
| 73 | uint16_t lim = 0; | ||
| 74 | while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT) | ||
| 75 | lim++; | ||
| 76 | } | ||
| 77 | |||
| 78 | // Write one byte to the i2c slave. | ||
| 79 | // returns 0 => slave ACK | ||
| 80 | // 1 => slave NACK | ||
| 81 | uint8_t i2c_master_write(uint8_t data) { | ||
| 82 | TWDR = data; | ||
| 83 | TWCR = (1<<TWINT) | (1<<TWEN); | ||
| 84 | |||
| 85 | i2c_delay(); | ||
| 86 | |||
| 87 | // check if the slave acknowledged us | ||
| 88 | return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1; | ||
| 89 | } | ||
| 90 | |||
| 91 | // Read one byte from the i2c slave. If ack=1 the slave is acknowledged, | ||
| 92 | // if ack=0 the acknowledge bit is not set. | ||
| 93 | // returns: byte read from i2c device | ||
| 94 | uint8_t i2c_master_read(int ack) { | ||
| 95 | TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA); | ||
| 96 | |||
| 97 | i2c_delay(); | ||
| 98 | return TWDR; | ||
| 99 | } | ||
| 100 | |||
| 101 | void i2c_reset_state(void) { | ||
| 102 | TWCR = 0; | ||
| 103 | } | ||
| 104 | |||
| 105 | void i2c_slave_init(uint8_t address) { | ||
| 106 | TWAR = address << 0; // slave i2c address | ||
| 107 | // TWEN - twi enable | ||
| 108 | // TWEA - enable address acknowledgement | ||
| 109 | // TWINT - twi interrupt flag | ||
| 110 | // TWIE - enable the twi interrupt | ||
| 111 | TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN); | ||
| 112 | } | ||
| 113 | |||
| 114 | ISR(TWI_vect); | ||
| 115 | |||
| 116 | ISR(TWI_vect) { | ||
| 117 | uint8_t ack = 1; | ||
| 118 | switch(TW_STATUS) { | ||
| 119 | case TW_SR_SLA_ACK: | ||
| 120 | // this device has been addressed as a slave receiver | ||
| 121 | slave_has_register_set = false; | ||
| 122 | break; | ||
| 123 | |||
| 124 | case TW_SR_DATA_ACK: | ||
| 125 | // this device has received data as a slave receiver | ||
| 126 | // The first byte that we receive in this transaction sets the location | ||
| 127 | // of the read/write location of the slaves memory that it exposes over | ||
| 128 | // i2c. After that, bytes will be written at slave_buffer_pos, incrementing | ||
| 129 | // slave_buffer_pos after each write. | ||
| 130 | if(!slave_has_register_set) { | ||
| 131 | slave_buffer_pos = TWDR; | ||
| 132 | // don't acknowledge the master if this memory loctaion is out of bounds | ||
| 133 | if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) { | ||
| 134 | ack = 0; | ||
| 135 | slave_buffer_pos = 0; | ||
| 136 | } | ||
| 137 | slave_has_register_set = true; | ||
| 138 | } else { | ||
| 139 | i2c_slave_buffer[slave_buffer_pos] = TWDR; | ||
| 140 | BUFFER_POS_INC(); | ||
| 141 | } | ||
| 142 | break; | ||
| 143 | |||
| 144 | case TW_ST_SLA_ACK: | ||
| 145 | case TW_ST_DATA_ACK: | ||
| 146 | // master has addressed this device as a slave transmitter and is | ||
| 147 | // requesting data. | ||
| 148 | TWDR = i2c_slave_buffer[slave_buffer_pos]; | ||
| 149 | BUFFER_POS_INC(); | ||
| 150 | break; | ||
| 151 | |||
| 152 | case TW_BUS_ERROR: // something went wrong, reset twi state | ||
| 153 | TWCR = 0; | ||
| 154 | default: | ||
| 155 | break; | ||
| 156 | } | ||
| 157 | // Reset everything, so we are ready for the next TWI interrupt | ||
| 158 | TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN); | ||
| 159 | } | ||
diff --git a/keyboards/lets_split/i2c.h b/keyboards/lets_split/i2c.h new file mode 100644 index 000000000..08ce4b009 --- /dev/null +++ b/keyboards/lets_split/i2c.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #ifndef I2C_H | ||
| 2 | #define I2C_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #ifndef F_CPU | ||
| 7 | #define F_CPU 16000000UL | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #define I2C_READ 1 | ||
| 11 | #define I2C_WRITE 0 | ||
| 12 | |||
| 13 | #define I2C_ACK 1 | ||
| 14 | #define I2C_NACK 0 | ||
| 15 | |||
| 16 | #define SLAVE_BUFFER_SIZE 0x10 | ||
| 17 | |||
| 18 | // i2c SCL clock frequency | ||
| 19 | #define SCL_CLOCK 100000L | ||
| 20 | |||
| 21 | extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE]; | ||
| 22 | |||
| 23 | void i2c_master_init(void); | ||
| 24 | uint8_t i2c_master_start(uint8_t address); | ||
| 25 | void i2c_master_stop(void); | ||
| 26 | uint8_t i2c_master_write(uint8_t data); | ||
| 27 | uint8_t i2c_master_read(int); | ||
| 28 | void i2c_reset_state(void); | ||
| 29 | void i2c_slave_init(uint8_t address); | ||
| 30 | |||
| 31 | #endif | ||
diff --git a/keyboards/lets-split/keymaps/default/keymap.c b/keyboards/lets_split/keymaps/default/keymap.c index 00602394f..01e3593c2 100644 --- a/keyboards/lets-split/keymaps/default/keymap.c +++ b/keyboards/lets_split/keymaps/default/keymap.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #include "lets-split.h" | 1 | #include "lets_split.h" |
| 2 | #include "action_layer.h" | 2 | #include "action_layer.h" |
| 3 | 3 | ||
| 4 | #define BASE 0 | 4 | #define BASE 0 |
| @@ -14,12 +14,12 @@ enum preonic_keycodes { | |||
| 14 | 14 | ||
| 15 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | 15 | const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { |
| 16 | 16 | ||
| 17 | [BASE] = { | 17 | [BASE] = KEYMAP( |
| 18 | {KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T }, | 18 | KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC, \ |
| 19 | {KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G }, | 19 | KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, \ |
| 20 | {KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B }, | 20 | KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_ENT, \ |
| 21 | {KC_IDK, KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, PM_RESET } | 21 | KC_IDK, KC_LCTL, KC_LALT, KC_LGUI, PM_RESET,KC_SPC, KC_SPC, PM_RESET,KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \ |
| 22 | } | 22 | ) |
| 23 | 23 | ||
| 24 | }; | 24 | }; |
| 25 | 25 | ||
diff --git a/keyboards/lets-split/lets-split.c b/keyboards/lets_split/lets_split.c index ee9872303..1859dc20a 100644 --- a/keyboards/lets-split/lets-split.c +++ b/keyboards/lets_split/lets_split.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | #include "lets-split.h" | 1 | #include "lets_split.h" |
| 2 | 2 | ||
| 3 | #ifdef AUDIO_ENABLE | 3 | #ifdef AUDIO_ENABLE |
| 4 | float tone_startup[][2] = SONG(STARTUP_SOUND); | 4 | float tone_startup[][2] = SONG(STARTUP_SOUND); |
| @@ -12,13 +12,13 @@ void matrix_init_kb(void) { | |||
| 12 | PLAY_NOTE_ARRAY(tone_startup, false, 0); | 12 | PLAY_NOTE_ARRAY(tone_startup, false, 0); |
| 13 | #endif | 13 | #endif |
| 14 | 14 | ||
| 15 | // green led on | 15 | // // green led on |
| 16 | DDRD |= (1<<5); | 16 | // DDRD |= (1<<5); |
| 17 | PORTD &= ~(1<<5); | 17 | // PORTD &= ~(1<<5); |
| 18 | 18 | ||
| 19 | // orange led on | 19 | // // orange led on |
| 20 | DDRB |= (1<<0); | 20 | // DDRB |= (1<<0); |
| 21 | PORTB &= ~(1<<0); | 21 | // PORTB &= ~(1<<0); |
| 22 | 22 | ||
| 23 | matrix_init_user(); | 23 | matrix_init_user(); |
| 24 | }; | 24 | }; |
diff --git a/keyboards/lets_split/lets_split.h b/keyboards/lets_split/lets_split.h new file mode 100644 index 000000000..e59aed592 --- /dev/null +++ b/keyboards/lets_split/lets_split.h | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include "quantum.h" | ||
| 2 | #include <avr/wdt.h> | ||
| 3 | |||
| 4 | void promicro_bootloader_jmp(bool program); | ||
| 5 | |||
| 6 | #define KEYMAP( \ | ||
| 7 | k00, k01, k02, k03, k04, k05, k40, k41, k42, k43, k44, k45, \ | ||
| 8 | k10, k11, k12, k13, k14, k15, k50, k51, k52, k53, k54, k55, \ | ||
| 9 | k20, k21, k22, k23, k24, k25, k60, k61, k62, k63, k64, k65, \ | ||
| 10 | k30, k31, k32, k33, k34, k35, k70, k71, k72, k73, k74, k75 \ | ||
| 11 | ) \ | ||
| 12 | { \ | ||
| 13 | { k00, k01, k02, k03, k04, k05 }, \ | ||
| 14 | { k10, k11, k12, k13, k14, k15 }, \ | ||
| 15 | { k20, k21, k22, k23, k24, k25 }, \ | ||
| 16 | { k30, k31, k32, k33, k34, k35 }, \ | ||
| 17 | { k40, k41, k42, k43, k44, k45 }, \ | ||
| 18 | { k50, k51, k52, k53, k54, k55 }, \ | ||
| 19 | { k60, k61, k62, k63, k64, k65 }, \ | ||
| 20 | { k70, k71, k72, k73, k74, k75 } \ | ||
| 21 | } \ No newline at end of file | ||
diff --git a/keyboards/lets_split/matrix.c b/keyboards/lets_split/matrix.c new file mode 100644 index 000000000..16c2ba0ba --- /dev/null +++ b/keyboards/lets_split/matrix.c | |||
| @@ -0,0 +1,310 @@ | |||
| 1 | /* | ||
| 2 | Copyright 2012 Jun Wako <wakojun@gmail.com> | ||
| 3 | |||
| 4 | This program is free software: you can redistribute it and/or modify | ||
| 5 | it under the terms of the GNU General Public License as published by | ||
| 6 | the Free Software Foundation, either version 2 of the License, or | ||
| 7 | (at your option) any later version. | ||
| 8 | |||
| 9 | This program is distributed in the hope that it will be useful, | ||
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 12 | GNU General Public License for more details. | ||
| 13 | |||
| 14 | You should have received a copy of the GNU General Public License | ||
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* | ||
| 19 | * scan matrix | ||
| 20 | */ | ||
| 21 | #include <stdint.h> | ||
| 22 | #include <stdbool.h> | ||
| 23 | #include <avr/io.h> | ||
| 24 | #include <avr/wdt.h> | ||
| 25 | #include <avr/interrupt.h> | ||
| 26 | #include <util/delay.h> | ||
| 27 | #include "print.h" | ||
| 28 | #include "debug.h" | ||
| 29 | #include "util.h" | ||
| 30 | #include "matrix.h" | ||
| 31 | #include "i2c.h" | ||
| 32 | #include "split_util.h" | ||
| 33 | #include "pro_micro.h" | ||
| 34 | #include "config.h" | ||
| 35 | |||
| 36 | #ifndef DEBOUNCE | ||
| 37 | # define DEBOUNCE 5 | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #define ERROR_DISCONNECT_COUNT 5 | ||
| 41 | |||
| 42 | static uint8_t debouncing = DEBOUNCE; | ||
| 43 | static const int ROWS_PER_HAND = MATRIX_ROWS/2; | ||
| 44 | static uint8_t error_count = 0; | ||
| 45 | |||
| 46 | static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS; | ||
| 47 | static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS; | ||
| 48 | |||
| 49 | /* matrix state(1:on, 0:off) */ | ||
| 50 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 51 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 52 | |||
| 53 | static matrix_row_t read_cols(void); | ||
| 54 | static void init_cols(void); | ||
| 55 | static void unselect_rows(void); | ||
| 56 | static void select_row(uint8_t row); | ||
| 57 | |||
| 58 | __attribute__ ((weak)) | ||
| 59 | void matrix_init_quantum(void) { | ||
| 60 | matrix_init_kb(); | ||
| 61 | } | ||
| 62 | |||
| 63 | __attribute__ ((weak)) | ||
| 64 | void matrix_scan_quantum(void) { | ||
| 65 | matrix_scan_kb(); | ||
| 66 | } | ||
| 67 | |||
| 68 | __attribute__ ((weak)) | ||
| 69 | void matrix_init_kb(void) { | ||
| 70 | matrix_init_user(); | ||
| 71 | } | ||
| 72 | |||
| 73 | __attribute__ ((weak)) | ||
| 74 | void matrix_scan_kb(void) { | ||
| 75 | matrix_scan_user(); | ||
| 76 | } | ||
| 77 | |||
| 78 | __attribute__ ((weak)) | ||
| 79 | void matrix_init_user(void) { | ||
| 80 | } | ||
| 81 | |||
| 82 | __attribute__ ((weak)) | ||
| 83 | void matrix_scan_user(void) { | ||
| 84 | } | ||
| 85 | |||
| 86 | inline | ||
| 87 | uint8_t matrix_rows(void) | ||
| 88 | { | ||
| 89 | return MATRIX_ROWS; | ||
| 90 | } | ||
| 91 | |||
| 92 | inline | ||
| 93 | uint8_t matrix_cols(void) | ||
| 94 | { | ||
| 95 | return MATRIX_COLS; | ||
| 96 | } | ||
| 97 | |||
| 98 | void matrix_init(void) | ||
| 99 | { | ||
| 100 | debug_enable = true; | ||
| 101 | debug_matrix = true; | ||
| 102 | debug_mouse = true; | ||
| 103 | // initialize row and col | ||
| 104 | unselect_rows(); | ||
| 105 | init_cols(); | ||
| 106 | |||
| 107 | TX_RX_LED_INIT; | ||
| 108 | |||
| 109 | // initialize matrix state: all keys off | ||
| 110 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 111 | matrix[i] = 0; | ||
| 112 | matrix_debouncing[i] = 0; | ||
| 113 | } | ||
| 114 | |||
| 115 | matrix_init_quantum(); | ||
| 116 | } | ||
| 117 | |||
| 118 | uint8_t _matrix_scan(void) | ||
| 119 | { | ||
| 120 | // Right hand is stored after the left in the matirx so, we need to offset it | ||
| 121 | int offset = isLeftHand ? 0 : (ROWS_PER_HAND); | ||
| 122 | |||
| 123 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 124 | select_row(i); | ||
| 125 | _delay_us(30); // without this wait read unstable value. | ||
| 126 | matrix_row_t cols = read_cols(); | ||
| 127 | if (matrix_debouncing[i+offset] != cols) { | ||
| 128 | matrix_debouncing[i+offset] = cols; | ||
| 129 | debouncing = DEBOUNCE; | ||
| 130 | } | ||
| 131 | unselect_rows(); | ||
| 132 | } | ||
| 133 | |||
| 134 | if (debouncing) { | ||
| 135 | if (--debouncing) { | ||
| 136 | _delay_ms(1); | ||
| 137 | } else { | ||
| 138 | for (uint8_t i = 0; i < ROWS_PER_HAND; i++) { | ||
| 139 | matrix[i+offset] = matrix_debouncing[i+offset]; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | return 1; | ||
| 145 | } | ||
| 146 | |||
| 147 | // Get rows from other half over i2c | ||
| 148 | int i2c_transaction(void) { | ||
| 149 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 150 | |||
| 151 | int err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_WRITE); | ||
| 152 | if (err) goto i2c_error; | ||
| 153 | |||
| 154 | // start of matrix stored at 0x00 | ||
| 155 | err = i2c_master_write(0x00); | ||
| 156 | if (err) goto i2c_error; | ||
| 157 | |||
| 158 | // Start read | ||
| 159 | err = i2c_master_start(SLAVE_I2C_ADDRESS + I2C_READ); | ||
| 160 | if (err) goto i2c_error; | ||
| 161 | |||
| 162 | if (!err) { | ||
| 163 | int i; | ||
| 164 | for (i = 0; i < ROWS_PER_HAND-1; ++i) { | ||
| 165 | matrix[slaveOffset+i] = i2c_master_read(I2C_ACK); | ||
| 166 | } | ||
| 167 | matrix[slaveOffset+i] = i2c_master_read(I2C_NACK); | ||
| 168 | i2c_master_stop(); | ||
| 169 | } else { | ||
| 170 | i2c_error: // the cable is disconnceted, or something else went wrong | ||
| 171 | i2c_reset_state(); | ||
| 172 | return err; | ||
| 173 | } | ||
| 174 | |||
| 175 | return 0; | ||
| 176 | } | ||
| 177 | |||
| 178 | #ifndef USE_I2C | ||
| 179 | int serial_transaction(void) { | ||
| 180 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 181 | |||
| 182 | if (serial_update_buffers()) { | ||
| 183 | return 1; | ||
| 184 | } | ||
| 185 | |||
| 186 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 187 | matrix[slaveOffset+i] = serial_slave_buffer[i]; | ||
| 188 | } | ||
| 189 | return 0; | ||
| 190 | } | ||
| 191 | #endif | ||
| 192 | |||
| 193 | uint8_t matrix_scan(void) | ||
| 194 | { | ||
| 195 | int ret = _matrix_scan(); | ||
| 196 | |||
| 197 | |||
| 198 | |||
| 199 | #ifdef USE_I2C | ||
| 200 | if( i2c_transaction() ) { | ||
| 201 | #else | ||
| 202 | if( serial_transaction() ) { | ||
| 203 | #endif | ||
| 204 | // turn on the indicator led when halves are disconnected | ||
| 205 | TXLED1; | ||
| 206 | |||
| 207 | error_count++; | ||
| 208 | |||
| 209 | if (error_count > ERROR_DISCONNECT_COUNT) { | ||
| 210 | // reset other half if disconnected | ||
| 211 | int slaveOffset = (isLeftHand) ? (ROWS_PER_HAND) : 0; | ||
| 212 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 213 | matrix[slaveOffset+i] = 0; | ||
| 214 | } | ||
| 215 | } | ||
| 216 | } else { | ||
| 217 | // turn off the indicator led on no error | ||
| 218 | TXLED0; | ||
| 219 | error_count = 0; | ||
| 220 | } | ||
| 221 | |||
| 222 | matrix_scan_quantum(); | ||
| 223 | |||
| 224 | return ret; | ||
| 225 | } | ||
| 226 | |||
| 227 | void matrix_slave_scan(void) { | ||
| 228 | _matrix_scan(); | ||
| 229 | |||
| 230 | int offset = (isLeftHand) ? 0 : (MATRIX_ROWS / 2); | ||
| 231 | |||
| 232 | #ifdef USE_I2C | ||
| 233 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 234 | /* i2c_slave_buffer[i] = matrix[offset+i]; */ | ||
| 235 | i2c_slave_buffer[i] = matrix[offset+i]; | ||
| 236 | } | ||
| 237 | #else | ||
| 238 | for (int i = 0; i < ROWS_PER_HAND; ++i) { | ||
| 239 | serial_slave_buffer[i] = matrix[offset+i]; | ||
| 240 | } | ||
| 241 | #endif | ||
| 242 | } | ||
| 243 | |||
| 244 | bool matrix_is_modified(void) | ||
| 245 | { | ||
| 246 | if (debouncing) return false; | ||
| 247 | return true; | ||
| 248 | } | ||
| 249 | |||
| 250 | inline | ||
| 251 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 252 | { | ||
| 253 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 254 | } | ||
| 255 | |||
| 256 | inline | ||
| 257 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 258 | { | ||
| 259 | return matrix[row]; | ||
| 260 | } | ||
| 261 | |||
| 262 | void matrix_print(void) | ||
| 263 | { | ||
| 264 | print("\nr/c 0123456789ABCDEF\n"); | ||
| 265 | for (uint8_t row = 0; row < MATRIX_ROWS; row++) { | ||
| 266 | phex(row); print(": "); | ||
| 267 | pbin_reverse16(matrix_get_row(row)); | ||
| 268 | print("\n"); | ||
| 269 | } | ||
| 270 | } | ||
| 271 | |||
| 272 | uint8_t matrix_key_count(void) | ||
| 273 | { | ||
| 274 | uint8_t count = 0; | ||
| 275 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 276 | count += bitpop16(matrix[i]); | ||
| 277 | } | ||
| 278 | return count; | ||
| 279 | } | ||
| 280 | |||
| 281 | static void init_cols(void) | ||
| 282 | { | ||
| 283 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 284 | _SFR_IO8((col_pins[x] >> 4) + 1) &= ~_BV(col_pins[x] & 0xF); | ||
| 285 | _SFR_IO8((col_pins[x] >> 4) + 2) |= _BV(col_pins[x] & 0xF); | ||
| 286 | } | ||
| 287 | } | ||
| 288 | |||
| 289 | static matrix_row_t read_cols(void) | ||
| 290 | { | ||
| 291 | matrix_row_t result = 0; | ||
| 292 | for(int x = 0; x < MATRIX_COLS; x++) { | ||
| 293 | result |= (_SFR_IO8(col_pins[x] >> 4) & _BV(col_pins[x] & 0xF)) ? 0 : (1 << x); | ||
| 294 | } | ||
| 295 | return result; | ||
| 296 | } | ||
| 297 | |||
| 298 | static void unselect_rows(void) | ||
| 299 | { | ||
| 300 | for(int x = 0; x < ROWS_PER_HAND; x++) { | ||
| 301 | _SFR_IO8((row_pins[x] >> 4) + 1) &= ~_BV(row_pins[x] & 0xF); | ||
| 302 | _SFR_IO8((row_pins[x] >> 4) + 2) |= _BV(row_pins[x] & 0xF); | ||
| 303 | } | ||
| 304 | } | ||
| 305 | |||
| 306 | static void select_row(uint8_t row) | ||
| 307 | { | ||
| 308 | _SFR_IO8((row_pins[row] >> 4) + 1) |= _BV(row_pins[row] & 0xF); | ||
| 309 | _SFR_IO8((row_pins[row] >> 4) + 2) &= ~_BV(row_pins[row] & 0xF); | ||
| 310 | } | ||
diff --git a/keyboards/lets_split/pro_micro.h b/keyboards/lets_split/pro_micro.h new file mode 100644 index 000000000..09e219b7b --- /dev/null +++ b/keyboards/lets_split/pro_micro.h | |||
| @@ -0,0 +1,362 @@ | |||
| 1 | /* | ||
| 2 | pins_arduino.h - Pin definition functions for Arduino | ||
| 3 | Part of Arduino - http://www.arduino.cc/ | ||
| 4 | |||
| 5 | Copyright (c) 2007 David A. Mellis | ||
| 6 | |||
| 7 | This library is free software; you can redistribute it and/or | ||
| 8 | modify it under the terms of the GNU Lesser General Public | ||
| 9 | License as published by the Free Software Foundation; either | ||
| 10 | version 2.1 of the License, or (at your option) any later version. | ||
| 11 | |||
| 12 | This library is distributed in the hope that it will be useful, | ||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | Lesser General Public License for more details. | ||
| 16 | |||
| 17 | You should have received a copy of the GNU Lesser General | ||
| 18 | Public License along with this library; if not, write to the | ||
| 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, | ||
| 20 | Boston, MA 02111-1307 USA | ||
| 21 | |||
| 22 | $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ | ||
| 23 | */ | ||
| 24 | |||
| 25 | #ifndef Pins_Arduino_h | ||
| 26 | #define Pins_Arduino_h | ||
| 27 | |||
| 28 | #include <avr/pgmspace.h> | ||
| 29 | |||
| 30 | // Workaround for wrong definitions in "iom32u4.h". | ||
| 31 | // This should be fixed in the AVR toolchain. | ||
| 32 | #undef UHCON | ||
| 33 | #undef UHINT | ||
| 34 | #undef UHIEN | ||
| 35 | #undef UHADDR | ||
| 36 | #undef UHFNUM | ||
| 37 | #undef UHFNUML | ||
| 38 | #undef UHFNUMH | ||
| 39 | #undef UHFLEN | ||
| 40 | #undef UPINRQX | ||
| 41 | #undef UPINTX | ||
| 42 | #undef UPNUM | ||
| 43 | #undef UPRST | ||
| 44 | #undef UPCONX | ||
| 45 | #undef UPCFG0X | ||
| 46 | #undef UPCFG1X | ||
| 47 | #undef UPSTAX | ||
| 48 | #undef UPCFG2X | ||
| 49 | #undef UPIENX | ||
| 50 | #undef UPDATX | ||
| 51 | #undef TCCR2A | ||
| 52 | #undef WGM20 | ||
| 53 | #undef WGM21 | ||
| 54 | #undef COM2B0 | ||
| 55 | #undef COM2B1 | ||
| 56 | #undef COM2A0 | ||
| 57 | #undef COM2A1 | ||
| 58 | #undef TCCR2B | ||
| 59 | #undef CS20 | ||
| 60 | #undef CS21 | ||
| 61 | #undef CS22 | ||
| 62 | #undef WGM22 | ||
| 63 | #undef FOC2B | ||
| 64 | #undef FOC2A | ||
| 65 | #undef TCNT2 | ||
| 66 | #undef TCNT2_0 | ||
| 67 | #undef TCNT2_1 | ||
| 68 | #undef TCNT2_2 | ||
| 69 | #undef TCNT2_3 | ||
| 70 | #undef TCNT2_4 | ||
| 71 | #undef TCNT2_5 | ||
| 72 | #undef TCNT2_6 | ||
| 73 | #undef TCNT2_7 | ||
| 74 | #undef OCR2A | ||
| 75 | #undef OCR2_0 | ||
| 76 | #undef OCR2_1 | ||
| 77 | #undef OCR2_2 | ||
| 78 | #undef OCR2_3 | ||
| 79 | #undef OCR2_4 | ||
| 80 | #undef OCR2_5 | ||
| 81 | #undef OCR2_6 | ||
| 82 | #undef OCR2_7 | ||
| 83 | #undef OCR2B | ||
| 84 | #undef OCR2_0 | ||
| 85 | #undef OCR2_1 | ||
| 86 | #undef OCR2_2 | ||
| 87 | #undef OCR2_3 | ||
| 88 | #undef OCR2_4 | ||
| 89 | #undef OCR2_5 | ||
| 90 | #undef OCR2_6 | ||
| 91 | #undef OCR2_7 | ||
| 92 | |||
| 93 | #define NUM_DIGITAL_PINS 30 | ||
| 94 | #define NUM_ANALOG_INPUTS 12 | ||
| 95 | |||
| 96 | #define TX_RX_LED_INIT DDRD |= (1<<5), DDRB |= (1<<0) | ||
| 97 | #define TXLED0 PORTD |= (1<<5) | ||
| 98 | #define TXLED1 PORTD &= ~(1<<5) | ||
| 99 | #define RXLED0 PORTB |= (1<<0) | ||
| 100 | #define RXLED1 PORTB &= ~(1<<0) | ||
| 101 | |||
| 102 | static const uint8_t SDA = 2; | ||
| 103 | static const uint8_t SCL = 3; | ||
| 104 | #define LED_BUILTIN 13 | ||
| 105 | |||
| 106 | // Map SPI port to 'new' pins D14..D17 | ||
| 107 | static const uint8_t SS = 17; | ||
| 108 | static const uint8_t MOSI = 16; | ||
| 109 | static const uint8_t MISO = 14; | ||
| 110 | static const uint8_t SCK = 15; | ||
| 111 | |||
| 112 | // Mapping of analog pins as digital I/O | ||
| 113 | // A6-A11 share with digital pins | ||
| 114 | static const uint8_t A0 = 18; | ||
| 115 | static const uint8_t A1 = 19; | ||
| 116 | static const uint8_t A2 = 20; | ||
| 117 | static const uint8_t A3 = 21; | ||
| 118 | static const uint8_t A4 = 22; | ||
| 119 | static const uint8_t A5 = 23; | ||
| 120 | static const uint8_t A6 = 24; // D4 | ||
| 121 | static const uint8_t A7 = 25; // D6 | ||
| 122 | static const uint8_t A8 = 26; // D8 | ||
| 123 | static const uint8_t A9 = 27; // D9 | ||
| 124 | static const uint8_t A10 = 28; // D10 | ||
| 125 | static const uint8_t A11 = 29; // D12 | ||
| 126 | |||
| 127 | #define digitalPinToPCICR(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCICR) : ((uint8_t *)0)) | ||
| 128 | #define digitalPinToPCICRbit(p) 0 | ||
| 129 | #define digitalPinToPCMSK(p) ((((p) >= 8 && (p) <= 11) || ((p) >= 14 && (p) <= 17) || ((p) >= A8 && (p) <= A10)) ? (&PCMSK0) : ((uint8_t *)0)) | ||
| 130 | #define digitalPinToPCMSKbit(p) ( ((p) >= 8 && (p) <= 11) ? (p) - 4 : ((p) == 14 ? 3 : ((p) == 15 ? 1 : ((p) == 16 ? 2 : ((p) == 17 ? 0 : (p - A8 + 4)))))) | ||
| 131 | |||
| 132 | // __AVR_ATmega32U4__ has an unusual mapping of pins to channels | ||
| 133 | extern const uint8_t PROGMEM analog_pin_to_channel_PGM[]; | ||
| 134 | #define analogPinToChannel(P) ( pgm_read_byte( analog_pin_to_channel_PGM + (P) ) ) | ||
| 135 | |||
| 136 | #define digitalPinToInterrupt(p) ((p) == 0 ? 2 : ((p) == 1 ? 3 : ((p) == 2 ? 1 : ((p) == 3 ? 0 : ((p) == 7 ? 4 : NOT_AN_INTERRUPT))))) | ||
| 137 | |||
| 138 | #ifdef ARDUINO_MAIN | ||
| 139 | |||
| 140 | // On the Arduino board, digital pins are also used | ||
| 141 | // for the analog output (software PWM). Analog input | ||
| 142 | // pins are a separate set. | ||
| 143 | |||
| 144 | // ATMEL ATMEGA32U4 / ARDUINO LEONARDO | ||
| 145 | // | ||
| 146 | // D0 PD2 RXD1/INT2 | ||
| 147 | // D1 PD3 TXD1/INT3 | ||
| 148 | // D2 PD1 SDA SDA/INT1 | ||
| 149 | // D3# PD0 PWM8/SCL OC0B/SCL/INT0 | ||
| 150 | // D4 A6 PD4 ADC8 | ||
| 151 | // D5# PC6 ??? OC3A/#OC4A | ||
| 152 | // D6# A7 PD7 FastPWM #OC4D/ADC10 | ||
| 153 | // D7 PE6 INT6/AIN0 | ||
| 154 | // | ||
| 155 | // D8 A8 PB4 ADC11/PCINT4 | ||
| 156 | // D9# A9 PB5 PWM16 OC1A/#OC4B/ADC12/PCINT5 | ||
| 157 | // D10# A10 PB6 PWM16 OC1B/0c4B/ADC13/PCINT6 | ||
| 158 | // D11# PB7 PWM8/16 0C0A/OC1C/#RTS/PCINT7 | ||
| 159 | // D12 A11 PD6 T1/#OC4D/ADC9 | ||
| 160 | // D13# PC7 PWM10 CLK0/OC4A | ||
| 161 | // | ||
| 162 | // A0 D18 PF7 ADC7 | ||
| 163 | // A1 D19 PF6 ADC6 | ||
| 164 | // A2 D20 PF5 ADC5 | ||
| 165 | // A3 D21 PF4 ADC4 | ||
| 166 | // A4 D22 PF1 ADC1 | ||
| 167 | // A5 D23 PF0 ADC0 | ||
| 168 | // | ||
| 169 | // New pins D14..D17 to map SPI port to digital pins | ||
| 170 | // | ||
| 171 | // MISO D14 PB3 MISO,PCINT3 | ||
| 172 | // SCK D15 PB1 SCK,PCINT1 | ||
| 173 | // MOSI D16 PB2 MOSI,PCINT2 | ||
| 174 | // SS D17 PB0 RXLED,SS/PCINT0 | ||
| 175 | // | ||
| 176 | // Connected LEDs on board for TX and RX | ||
| 177 | // TXLED D24 PD5 XCK1 | ||
| 178 | // RXLED D17 PB0 | ||
| 179 | // HWB PE2 HWB | ||
| 180 | |||
| 181 | // these arrays map port names (e.g. port B) to the | ||
| 182 | // appropriate addresses for various functions (e.g. reading | ||
| 183 | // and writing) | ||
| 184 | const uint16_t PROGMEM port_to_mode_PGM[] = { | ||
| 185 | NOT_A_PORT, | ||
| 186 | NOT_A_PORT, | ||
| 187 | (uint16_t) &DDRB, | ||
| 188 | (uint16_t) &DDRC, | ||
| 189 | (uint16_t) &DDRD, | ||
| 190 | (uint16_t) &DDRE, | ||
| 191 | (uint16_t) &DDRF, | ||
| 192 | }; | ||
| 193 | |||
| 194 | const uint16_t PROGMEM port_to_output_PGM[] = { | ||
| 195 | NOT_A_PORT, | ||
| 196 | NOT_A_PORT, | ||
| 197 | (uint16_t) &PORTB, | ||
| 198 | (uint16_t) &PORTC, | ||
| 199 | (uint16_t) &PORTD, | ||
| 200 | (uint16_t) &PORTE, | ||
| 201 | (uint16_t) &PORTF, | ||
| 202 | }; | ||
| 203 | |||
| 204 | const uint16_t PROGMEM port_to_input_PGM[] = { | ||
| 205 | NOT_A_PORT, | ||
| 206 | NOT_A_PORT, | ||
| 207 | (uint16_t) &PINB, | ||
| 208 | (uint16_t) &PINC, | ||
| 209 | (uint16_t) &PIND, | ||
| 210 | (uint16_t) &PINE, | ||
| 211 | (uint16_t) &PINF, | ||
| 212 | }; | ||
| 213 | |||
| 214 | const uint8_t PROGMEM digital_pin_to_port_PGM[] = { | ||
| 215 | PD, // D0 - PD2 | ||
| 216 | PD, // D1 - PD3 | ||
| 217 | PD, // D2 - PD1 | ||
| 218 | PD, // D3 - PD0 | ||
| 219 | PD, // D4 - PD4 | ||
| 220 | PC, // D5 - PC6 | ||
| 221 | PD, // D6 - PD7 | ||
| 222 | PE, // D7 - PE6 | ||
| 223 | |||
| 224 | PB, // D8 - PB4 | ||
| 225 | PB, // D9 - PB5 | ||
| 226 | PB, // D10 - PB6 | ||
| 227 | PB, // D11 - PB7 | ||
| 228 | PD, // D12 - PD6 | ||
| 229 | PC, // D13 - PC7 | ||
| 230 | |||
| 231 | PB, // D14 - MISO - PB3 | ||
| 232 | PB, // D15 - SCK - PB1 | ||
| 233 | PB, // D16 - MOSI - PB2 | ||
| 234 | PB, // D17 - SS - PB0 | ||
| 235 | |||
| 236 | PF, // D18 - A0 - PF7 | ||
| 237 | PF, // D19 - A1 - PF6 | ||
| 238 | PF, // D20 - A2 - PF5 | ||
| 239 | PF, // D21 - A3 - PF4 | ||
| 240 | PF, // D22 - A4 - PF1 | ||
| 241 | PF, // D23 - A5 - PF0 | ||
| 242 | |||
| 243 | PD, // D24 - PD5 | ||
| 244 | PD, // D25 / D6 - A7 - PD7 | ||
| 245 | PB, // D26 / D8 - A8 - PB4 | ||
| 246 | PB, // D27 / D9 - A9 - PB5 | ||
| 247 | PB, // D28 / D10 - A10 - PB6 | ||
| 248 | PD, // D29 / D12 - A11 - PD6 | ||
| 249 | }; | ||
| 250 | |||
| 251 | const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = { | ||
| 252 | _BV(2), // D0 - PD2 | ||
| 253 | _BV(3), // D1 - PD3 | ||
| 254 | _BV(1), // D2 - PD1 | ||
| 255 | _BV(0), // D3 - PD0 | ||
| 256 | _BV(4), // D4 - PD4 | ||
| 257 | _BV(6), // D5 - PC6 | ||
| 258 | _BV(7), // D6 - PD7 | ||
| 259 | _BV(6), // D7 - PE6 | ||
| 260 | |||
| 261 | _BV(4), // D8 - PB4 | ||
| 262 | _BV(5), // D9 - PB5 | ||
| 263 | _BV(6), // D10 - PB6 | ||
| 264 | _BV(7), // D11 - PB7 | ||
| 265 | _BV(6), // D12 - PD6 | ||
| 266 | _BV(7), // D13 - PC7 | ||
| 267 | |||
| 268 | _BV(3), // D14 - MISO - PB3 | ||
| 269 | _BV(1), // D15 - SCK - PB1 | ||
| 270 | _BV(2), // D16 - MOSI - PB2 | ||
| 271 | _BV(0), // D17 - SS - PB0 | ||
| 272 | |||
| 273 | _BV(7), // D18 - A0 - PF7 | ||
| 274 | _BV(6), // D19 - A1 - PF6 | ||
| 275 | _BV(5), // D20 - A2 - PF5 | ||
| 276 | _BV(4), // D21 - A3 - PF4 | ||
| 277 | _BV(1), // D22 - A4 - PF1 | ||
| 278 | _BV(0), // D23 - A5 - PF0 | ||
| 279 | |||
| 280 | _BV(5), // D24 - PD5 | ||
| 281 | _BV(7), // D25 / D6 - A7 - PD7 | ||
| 282 | _BV(4), // D26 / D8 - A8 - PB4 | ||
| 283 | _BV(5), // D27 / D9 - A9 - PB5 | ||
| 284 | _BV(6), // D28 / D10 - A10 - PB6 | ||
| 285 | _BV(6), // D29 / D12 - A11 - PD6 | ||
| 286 | }; | ||
| 287 | |||
| 288 | const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { | ||
| 289 | NOT_ON_TIMER, | ||
| 290 | NOT_ON_TIMER, | ||
| 291 | NOT_ON_TIMER, | ||
| 292 | TIMER0B, /* 3 */ | ||
| 293 | NOT_ON_TIMER, | ||
| 294 | TIMER3A, /* 5 */ | ||
| 295 | TIMER4D, /* 6 */ | ||
| 296 | NOT_ON_TIMER, | ||
| 297 | |||
| 298 | NOT_ON_TIMER, | ||
| 299 | TIMER1A, /* 9 */ | ||
| 300 | TIMER1B, /* 10 */ | ||
| 301 | TIMER0A, /* 11 */ | ||
| 302 | |||
| 303 | NOT_ON_TIMER, | ||
| 304 | TIMER4A, /* 13 */ | ||
| 305 | |||
| 306 | NOT_ON_TIMER, | ||
| 307 | NOT_ON_TIMER, | ||
| 308 | NOT_ON_TIMER, | ||
| 309 | NOT_ON_TIMER, | ||
| 310 | NOT_ON_TIMER, | ||
| 311 | NOT_ON_TIMER, | ||
| 312 | |||
| 313 | NOT_ON_TIMER, | ||
| 314 | NOT_ON_TIMER, | ||
| 315 | NOT_ON_TIMER, | ||
| 316 | NOT_ON_TIMER, | ||
| 317 | NOT_ON_TIMER, | ||
| 318 | NOT_ON_TIMER, | ||
| 319 | NOT_ON_TIMER, | ||
| 320 | NOT_ON_TIMER, | ||
| 321 | NOT_ON_TIMER, | ||
| 322 | NOT_ON_TIMER, | ||
| 323 | }; | ||
| 324 | |||
| 325 | const uint8_t PROGMEM analog_pin_to_channel_PGM[] = { | ||
| 326 | 7, // A0 PF7 ADC7 | ||
| 327 | 6, // A1 PF6 ADC6 | ||
| 328 | 5, // A2 PF5 ADC5 | ||
| 329 | 4, // A3 PF4 ADC4 | ||
| 330 | 1, // A4 PF1 ADC1 | ||
| 331 | 0, // A5 PF0 ADC0 | ||
| 332 | 8, // A6 D4 PD4 ADC8 | ||
| 333 | 10, // A7 D6 PD7 ADC10 | ||
| 334 | 11, // A8 D8 PB4 ADC11 | ||
| 335 | 12, // A9 D9 PB5 ADC12 | ||
| 336 | 13, // A10 D10 PB6 ADC13 | ||
| 337 | 9 // A11 D12 PD6 ADC9 | ||
| 338 | }; | ||
| 339 | |||
| 340 | #endif /* ARDUINO_MAIN */ | ||
| 341 | |||
| 342 | // These serial port names are intended to allow libraries and architecture-neutral | ||
| 343 | // sketches to automatically default to the correct port name for a particular type | ||
| 344 | // of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN, | ||
| 345 | // the first hardware serial port whose RX/TX pins are not dedicated to another use. | ||
| 346 | // | ||
| 347 | // SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor | ||
| 348 | // | ||
| 349 | // SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial | ||
| 350 | // | ||
| 351 | // SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library | ||
| 352 | // | ||
| 353 | // SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins. | ||
| 354 | // | ||
| 355 | // SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX | ||
| 356 | // pins are NOT connected to anything by default. | ||
| 357 | #define SERIAL_PORT_MONITOR Serial | ||
| 358 | #define SERIAL_PORT_USBVIRTUAL Serial | ||
| 359 | #define SERIAL_PORT_HARDWARE Serial1 | ||
| 360 | #define SERIAL_PORT_HARDWARE_OPEN Serial1 | ||
| 361 | |||
| 362 | #endif /* Pins_Arduino_h */ | ||
diff --git a/keyboards/lets-split/readme.md b/keyboards/lets_split/readme.md index e69de29bb..e69de29bb 100644 --- a/keyboards/lets-split/readme.md +++ b/keyboards/lets_split/readme.md | |||
diff --git a/keyboards/lets_split/split_util.c b/keyboards/lets_split/split_util.c new file mode 100644 index 000000000..c394596e0 --- /dev/null +++ b/keyboards/lets_split/split_util.c | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | #include <avr/io.h> | ||
| 2 | #include <avr/wdt.h> | ||
| 3 | #include <avr/power.h> | ||
| 4 | #include <avr/interrupt.h> | ||
| 5 | #include <util/delay.h> | ||
| 6 | #include <avr/eeprom.h> | ||
| 7 | #include "split_util.h" | ||
| 8 | #include "matrix.h" | ||
| 9 | #include "i2c.h" | ||
| 10 | #include "keyboard.h" | ||
| 11 | #include "config.h" | ||
| 12 | |||
| 13 | volatile bool isLeftHand = true; | ||
| 14 | |||
| 15 | static void setup_handedness(void) { | ||
| 16 | isLeftHand = eeprom_read_byte(EECONFIG_HANDEDNESS); | ||
| 17 | } | ||
| 18 | |||
| 19 | static void keyboard_master_setup(void) { | ||
| 20 | #ifdef USE_I2C | ||
| 21 | i2c_master_init(); | ||
| 22 | #else | ||
| 23 | serial_master_init(); | ||
| 24 | #endif | ||
| 25 | } | ||
| 26 | |||
| 27 | static void keyboard_slave_setup(void) { | ||
| 28 | #ifdef USE_I2C | ||
| 29 | i2c_slave_init(SLAVE_I2C_ADDRESS); | ||
| 30 | #else | ||
| 31 | serial_slave_init(); | ||
| 32 | #endif | ||
| 33 | } | ||
| 34 | |||
| 35 | bool has_usb(void) { | ||
| 36 | USBCON |= (1 << OTGPADE); //enables VBUS pad | ||
| 37 | _delay_us(5); | ||
| 38 | return (USBSTA & (1<<VBUS)); //checks state of VBUS | ||
| 39 | } | ||
| 40 | |||
| 41 | void split_keyboard_setup(void) { | ||
| 42 | setup_handedness(); | ||
| 43 | |||
| 44 | if (has_usb()) { | ||
| 45 | keyboard_master_setup(); | ||
| 46 | } else { | ||
| 47 | keyboard_slave_setup(); | ||
| 48 | } | ||
| 49 | sei(); | ||
| 50 | } | ||
| 51 | |||
| 52 | void keyboard_slave_loop(void) { | ||
| 53 | matrix_init(); | ||
| 54 | |||
| 55 | while (1) { | ||
| 56 | matrix_slave_scan(); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | // this code runs before the usb and keyboard is initialized | ||
| 61 | void matrix_setup(void) { | ||
| 62 | split_keyboard_setup(); | ||
| 63 | |||
| 64 | if (!has_usb()) { | ||
| 65 | keyboard_slave_loop(); | ||
| 66 | } | ||
| 67 | } | ||
diff --git a/keyboards/lets_split/split_util.h b/keyboards/lets_split/split_util.h new file mode 100644 index 000000000..cf6890d37 --- /dev/null +++ b/keyboards/lets_split/split_util.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | #ifndef SPLIT_KEYBOARD_UTIL_H | ||
| 2 | #define SPLIT_KEYBOARD_UTIL_H | ||
| 3 | |||
| 4 | #include <stdbool.h> | ||
| 5 | |||
| 6 | #define EECONFIG_BOOTMAGIC_END (uint8_t *)10 | ||
| 7 | #define EECONFIG_HANDEDNESS EECONFIG_BOOTMAGIC_END | ||
| 8 | |||
| 9 | #define SLAVE_I2C_ADDRESS 0x32 | ||
| 10 | |||
| 11 | extern volatile bool isLeftHand; | ||
| 12 | |||
| 13 | // slave version of matix scan, defined in matrix.c | ||
| 14 | void matrix_slave_scan(void); | ||
| 15 | |||
| 16 | void split_keyboard_setup(void); | ||
| 17 | bool has_usb(void); | ||
| 18 | void keyboard_slave_loop(void); | ||
| 19 | |||
| 20 | #endif | ||
diff --git a/keyboards/lets_split/uno-slave/Makefile b/keyboards/lets_split/uno-slave/Makefile new file mode 100644 index 000000000..84e67de11 --- /dev/null +++ b/keyboards/lets_split/uno-slave/Makefile | |||
| @@ -0,0 +1,226 @@ | |||
| 1 | # Hey Emacs, this is a -*- makefile -*- | ||
| 2 | |||
| 3 | # AVR-GCC Makefile template, derived from the WinAVR template (which | ||
| 4 | # is public domain), believed to be neutral to any flavor of "make" | ||
| 5 | # (GNU make, BSD make, SysV make) | ||
| 6 | |||
| 7 | |||
| 8 | MCU = atmega328p | ||
| 9 | FORMAT = ihex | ||
| 10 | TARGET = keyboard-i2c-slave | ||
| 11 | SRC = \ | ||
| 12 | $(TARGET).c \ | ||
| 13 | uno-matrix.c \ | ||
| 14 | ../serial.c \ | ||
| 15 | ../i2c-slave.c | ||
| 16 | |||
| 17 | ASRC = | ||
| 18 | OPT = s | ||
| 19 | |||
| 20 | # Programming support using avrdude. Settings and variables. | ||
| 21 | |||
| 22 | AVRDUDE_PROGRAMMER = arduino | ||
| 23 | AVRDUDE_PORT = /dev/ttyACM0 | ||
| 24 | |||
| 25 | # Name of this Makefile (used for "make depend"). | ||
| 26 | MAKEFILE = Makefile | ||
| 27 | |||
| 28 | # Debugging format. | ||
| 29 | # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2. | ||
| 30 | # AVR (extended) COFF requires stabs, plus an avr-objcopy run. | ||
| 31 | DEBUG = stabs | ||
| 32 | |||
| 33 | # Compiler flag to set the C Standard level. | ||
| 34 | # c89 - "ANSI" C | ||
| 35 | # gnu89 - c89 plus GCC extensions | ||
| 36 | # c99 - ISO C99 standard (not yet fully implemented) | ||
| 37 | # gnu99 - c99 plus GCC extensions | ||
| 38 | CSTANDARD = -std=gnu99 | ||
| 39 | |||
| 40 | # Place -D or -U options here | ||
| 41 | CDEFS = | ||
| 42 | |||
| 43 | # Place -I options here | ||
| 44 | CINCS = | ||
| 45 | |||
| 46 | |||
| 47 | CDEBUG = -g$(DEBUG) | ||
| 48 | CWARN = -Wall -Wstrict-prototypes | ||
| 49 | CTUNING = -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums | ||
| 50 | #CEXTRA = -Wa,-adhlns=$(<:.c=.lst) | ||
| 51 | CFLAGS = $(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CWARN) $(CSTANDARD) $(CEXTRA) \ | ||
| 52 | -fno-aggressive-loop-optimizations | ||
| 53 | |||
| 54 | #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs | ||
| 55 | |||
| 56 | |||
| 57 | #Additional libraries. | ||
| 58 | |||
| 59 | # Minimalistic printf version | ||
| 60 | PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min | ||
| 61 | |||
| 62 | # Floating point printf version (requires MATH_LIB = -lm below) | ||
| 63 | PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt | ||
| 64 | |||
| 65 | PRINTF_LIB = | ||
| 66 | |||
| 67 | # Minimalistic scanf version | ||
| 68 | SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min | ||
| 69 | |||
| 70 | # Floating point + %[ scanf version (requires MATH_LIB = -lm below) | ||
| 71 | SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt | ||
| 72 | |||
| 73 | SCANF_LIB = | ||
| 74 | |||
| 75 | MATH_LIB = -lm | ||
| 76 | |||
| 77 | # External memory options | ||
| 78 | |||
| 79 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | ||
| 80 | # used for variables (.data/.bss) and heap (malloc()). | ||
| 81 | #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff | ||
| 82 | |||
| 83 | # 64 KB of external RAM, starting after internal RAM (ATmega128!), | ||
| 84 | # only used for heap (malloc()). | ||
| 85 | #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff | ||
| 86 | |||
| 87 | EXTMEMOPTS = | ||
| 88 | |||
| 89 | #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref | ||
| 90 | LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB) | ||
| 91 | |||
| 92 | |||
| 93 | AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex | ||
| 94 | #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep | ||
| 95 | |||
| 96 | |||
| 97 | # Uncomment the following if you want avrdude's erase cycle counter. | ||
| 98 | # Note that this counter needs to be initialized first using -Yn, | ||
| 99 | # see avrdude manual. | ||
| 100 | #AVRDUDE_ERASE_COUNTER = -y | ||
| 101 | |||
| 102 | # Uncomment the following if you do /not/ wish a verification to be | ||
| 103 | # performed after programming the device. | ||
| 104 | #AVRDUDE_NO_VERIFY = -V | ||
| 105 | |||
| 106 | # Increase verbosity level. Please use this when submitting bug | ||
| 107 | # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> | ||
| 108 | # to submit bug reports. | ||
| 109 | #AVRDUDE_VERBOSE = -v -v | ||
| 110 | |||
| 111 | AVRDUDE_BASIC = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) | ||
| 112 | AVRDUDE_FLAGS = $(AVRDUDE_BASIC) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER) | ||
| 113 | |||
| 114 | |||
| 115 | CC = avr-gcc | ||
| 116 | OBJCOPY = avr-objcopy | ||
| 117 | OBJDUMP = avr-objdump | ||
| 118 | SIZE = avr-size | ||
| 119 | NM = avr-nm | ||
| 120 | AVRDUDE = avrdude | ||
| 121 | REMOVE = rm -f | ||
| 122 | MV = mv -f | ||
| 123 | |||
| 124 | # Define all object files. | ||
| 125 | OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) | ||
| 126 | |||
| 127 | # Define all listing files. | ||
| 128 | LST = $(ASRC:.S=.lst) $(SRC:.c=.lst) | ||
| 129 | |||
| 130 | # Combine all necessary flags and optional flags. | ||
| 131 | # Add target processor to flags. | ||
| 132 | ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) | ||
| 133 | ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS) | ||
| 134 | |||
| 135 | |||
| 136 | # Default target. | ||
| 137 | all: build | ||
| 138 | |||
| 139 | build: elf hex eep | ||
| 140 | |||
| 141 | elf: $(TARGET).elf | ||
| 142 | hex: $(TARGET).hex | ||
| 143 | eep: $(TARGET).eep | ||
| 144 | lss: $(TARGET).lss | ||
| 145 | sym: $(TARGET).sym | ||
| 146 | |||
| 147 | |||
| 148 | # Program the device. | ||
| 149 | program: $(TARGET).hex $(TARGET).eep | ||
| 150 | $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM) | ||
| 151 | |||
| 152 | |||
| 153 | # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB. | ||
| 154 | COFFCONVERT=$(OBJCOPY) --debugging \ | ||
| 155 | --change-section-address .data-0x800000 \ | ||
| 156 | --change-section-address .bss-0x800000 \ | ||
| 157 | --change-section-address .noinit-0x800000 \ | ||
| 158 | --change-section-address .eeprom-0x810000 | ||
| 159 | |||
| 160 | |||
| 161 | coff: $(TARGET).elf | ||
| 162 | $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof | ||
| 163 | |||
| 164 | |||
| 165 | extcoff: $(TARGET).elf | ||
| 166 | $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof | ||
| 167 | |||
| 168 | |||
| 169 | .SUFFIXES: .elf .hex .eep .lss .sym | ||
| 170 | |||
| 171 | .elf.hex: | ||
| 172 | $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@ | ||
| 173 | |||
| 174 | .elf.eep: | ||
| 175 | -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \ | ||
| 176 | --change-section-lma .eeprom=0 -O $(FORMAT) $< $@ | ||
| 177 | |||
| 178 | # Create extended listing file from ELF output file. | ||
| 179 | .elf.lss: | ||
| 180 | $(OBJDUMP) -h -S $< > $@ | ||
| 181 | |||
| 182 | # Create a symbol table from ELF output file. | ||
| 183 | .elf.sym: | ||
| 184 | $(NM) -n $< > $@ | ||
| 185 | |||
| 186 | |||
| 187 | |||
| 188 | # Link: create ELF output file from object files. | ||
| 189 | $(TARGET).elf: $(OBJ) | ||
| 190 | $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS) | ||
| 191 | |||
| 192 | |||
| 193 | # Compile: create object files from C source files. | ||
| 194 | .c.o: | ||
| 195 | $(CC) -c $(ALL_CFLAGS) $< -o $@ | ||
| 196 | |||
| 197 | |||
| 198 | # Compile: create assembler files from C source files. | ||
| 199 | .c.s: | ||
| 200 | $(CC) -S $(ALL_CFLAGS) $< -o $@ | ||
| 201 | |||
| 202 | |||
| 203 | # Assemble: create object files from assembler source files. | ||
| 204 | .S.o: | ||
| 205 | $(CC) -c $(ALL_ASFLAGS) $< -o $@ | ||
| 206 | |||
| 207 | |||
| 208 | |||
| 209 | # Target: clean project. | ||
| 210 | clean: | ||
| 211 | $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \ | ||
| 212 | $(TARGET).map $(TARGET).sym $(TARGET).lss \ | ||
| 213 | $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d) | ||
| 214 | |||
| 215 | depend: | ||
| 216 | if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \ | ||
| 217 | then \ | ||
| 218 | sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \ | ||
| 219 | $(MAKEFILE).$$$$ && \ | ||
| 220 | $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \ | ||
| 221 | fi | ||
| 222 | echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \ | ||
| 223 | >> $(MAKEFILE); \ | ||
| 224 | $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE) | ||
| 225 | |||
| 226 | .PHONY: all build elf hex eep lss sym program coff extcoff clean depend | ||
diff --git a/keyboards/lets_split/uno-slave/keyboard-i2c-slave.c b/keyboards/lets_split/uno-slave/keyboard-i2c-slave.c new file mode 100644 index 000000000..2043e7b94 --- /dev/null +++ b/keyboards/lets_split/uno-slave/keyboard-i2c-slave.c | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #include "../i2c-slave.h" | ||
| 2 | #include "../serial.h" | ||
| 3 | #include "uno-matrix.h" | ||
| 4 | |||
| 5 | #include <avr/io.h> | ||
| 6 | #include <avr/interrupt.h> | ||
| 7 | #include <util/delay.h> | ||
| 8 | |||
| 9 | void setup(void) { | ||
| 10 | // give some time for noise to clear | ||
| 11 | _delay_us(1000); | ||
| 12 | |||
| 13 | // turn off arduino uno's led on pin 13 | ||
| 14 | DDRB |= (1 << 5); | ||
| 15 | PORTB &= ~(1 << 5); | ||
| 16 | |||
| 17 | matrix_init(); | ||
| 18 | /* i2c_slave_init(0x32); */ | ||
| 19 | serial_slave_init(); | ||
| 20 | |||
| 21 | /* serial_slave_buffer[0] = 0xa1; */ | ||
| 22 | /* serial_slave_buffer[1] = 0x52; */ | ||
| 23 | /* serial_slave_buffer[2] = 0xa2; */ | ||
| 24 | /* serial_slave_buffer[3] = 0x67; */ | ||
| 25 | |||
| 26 | // need interrupts for i2c slave code to work | ||
| 27 | sei(); | ||
| 28 | } | ||
| 29 | |||
| 30 | void loop(void) { | ||
| 31 | matrix_scan(); | ||
| 32 | for(int i=0; i<MATRIX_ROWS; ++i) { | ||
| 33 | slaveBuffer[i] = matrix_get_row(i); | ||
| 34 | serial_slave_buffer[i] = slaveBuffer[i]; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | int main(int argc, char *argv[]) { | ||
| 39 | setup(); | ||
| 40 | while (1) | ||
| 41 | loop(); | ||
| 42 | } | ||
diff --git a/keyboards/lets_split/uno-slave/readme.md b/keyboards/lets_split/uno-slave/readme.md new file mode 100644 index 000000000..d0f03126c --- /dev/null +++ b/keyboards/lets_split/uno-slave/readme.md | |||
| @@ -0,0 +1 @@ | |||
| Code for Arduino uno (atmega328p) slave used for testing. | |||
diff --git a/keyboards/lets_split/uno-slave/uno-matrix.c b/keyboards/lets_split/uno-slave/uno-matrix.c new file mode 100644 index 000000000..4ac3c33ac --- /dev/null +++ b/keyboards/lets_split/uno-slave/uno-matrix.c | |||
| @@ -0,0 +1,160 @@ | |||
| 1 | #define F_CPU 16000000UL | ||
| 2 | |||
| 3 | #include <util/delay.h> | ||
| 4 | #include <avr/io.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | #include "uno-matrix.h" | ||
| 8 | |||
| 9 | #define debug(X) NULL | ||
| 10 | #define debug_hex(X) NULL | ||
| 11 | |||
| 12 | #ifndef DEBOUNCE | ||
| 13 | # define DEBOUNCE 5 | ||
| 14 | #endif | ||
| 15 | |||
| 16 | static uint8_t debouncing = DEBOUNCE; | ||
| 17 | |||
| 18 | /* matrix state(1:on, 0:off) */ | ||
| 19 | static matrix_row_t matrix[MATRIX_ROWS]; | ||
| 20 | static matrix_row_t matrix_debouncing[MATRIX_ROWS]; | ||
| 21 | |||
| 22 | static matrix_row_t read_cols(void); | ||
| 23 | static void init_cols(void); | ||
| 24 | static void unselect_rows(void); | ||
| 25 | static void select_row(uint8_t row); | ||
| 26 | |||
| 27 | inline | ||
| 28 | uint8_t matrix_rows(void) | ||
| 29 | { | ||
| 30 | return MATRIX_ROWS; | ||
| 31 | } | ||
| 32 | |||
| 33 | inline | ||
| 34 | uint8_t matrix_cols(void) | ||
| 35 | { | ||
| 36 | return MATRIX_COLS; | ||
| 37 | } | ||
| 38 | |||
| 39 | void matrix_init(void) | ||
| 40 | { | ||
| 41 | //debug_enable = true; | ||
| 42 | //debug_matrix = true; | ||
| 43 | //debug_mouse = true; | ||
| 44 | // initialize row and col | ||
| 45 | unselect_rows(); | ||
| 46 | init_cols(); | ||
| 47 | |||
| 48 | // initialize matrix state: all keys off | ||
| 49 | for (uint8_t i=0; i < MATRIX_ROWS; i++) { | ||
| 50 | matrix[i] = 0; | ||
| 51 | matrix_debouncing[i] = 0; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | uint8_t matrix_scan(void) | ||
| 56 | { | ||
| 57 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 58 | select_row(i); | ||
| 59 | _delay_us(30); // without this wait read unstable value. | ||
| 60 | matrix_row_t cols = read_cols(); | ||
| 61 | //Serial.println(cols, BIN); | ||
| 62 | if (matrix_debouncing[i] != cols) { | ||
| 63 | matrix_debouncing[i] = cols; | ||
| 64 | if (debouncing) { | ||
| 65 | debug("bounce!: "); debug_hex(debouncing); debug("\n"); | ||
| 66 | } | ||
| 67 | debouncing = DEBOUNCE; | ||
| 68 | } | ||
| 69 | unselect_rows(); | ||
| 70 | } | ||
| 71 | |||
| 72 | if (debouncing) { | ||
| 73 | if (--debouncing) { | ||
| 74 | _delay_ms(1); | ||
| 75 | } else { | ||
| 76 | for (uint8_t i = 0; i < MATRIX_ROWS; i++) { | ||
| 77 | matrix[i] = matrix_debouncing[i]; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | bool matrix_is_modified(void) | ||
| 86 | { | ||
| 87 | if (debouncing) return false; | ||
| 88 | return true; | ||
| 89 | } | ||
| 90 | |||
| 91 | inline | ||
| 92 | bool matrix_is_on(uint8_t row, uint8_t col) | ||
| 93 | { | ||
| 94 | return (matrix[row] & ((matrix_row_t)1<<col)); | ||
| 95 | } | ||
| 96 | |||
| 97 | inline | ||
| 98 | matrix_row_t matrix_get_row(uint8_t row) | ||
| 99 | { | ||
| 100 | return matrix[row]; | ||
| 101 | } | ||
| 102 | |||
| 103 | // TODO update this comment | ||
| 104 | /* Column pin configuration | ||
| 105 | * col: 0 1 2 3 4 5 | ||
| 106 | * pin: D3 D4 D5 D6 D7 B0 | ||
| 107 | */ | ||
| 108 | static void init_cols(void) | ||
| 109 | { | ||
| 110 | // Input with pull-up(DDR:0, PORT:1) | ||
| 111 | DDRD &= ~(1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7); | ||
| 112 | PORTD |= (1<<3 | 1<<4 | 1<<5 | 1<<6 | 1<<7); | ||
| 113 | |||
| 114 | DDRB &= ~(1<<0); | ||
| 115 | PORTB |= (1<<0); | ||
| 116 | } | ||
| 117 | |||
| 118 | static matrix_row_t read_cols(void) | ||
| 119 | { | ||
| 120 | return (PIND&(1<<3) ? 0 : (1<<0)) | | ||
| 121 | (PIND&(1<<4) ? 0 : (1<<1)) | | ||
| 122 | (PIND&(1<<5) ? 0 : (1<<2)) | | ||
| 123 | (PIND&(1<<6) ? 0 : (1<<3)) | | ||
| 124 | (PIND&(1<<7) ? 0 : (1<<4)) | | ||
| 125 | (PINB&(1<<0) ? 0 : (1<<5)); | ||
| 126 | } | ||
| 127 | |||
| 128 | /* Row pin configuration | ||
| 129 | * row: 0 1 2 3 | ||
| 130 | * pin: C0 C1 C2 C3 | ||
| 131 | */ | ||
| 132 | static void unselect_rows(void) | ||
| 133 | { | ||
| 134 | // Hi-Z(DDR:0, PORT:0) to unselect | ||
| 135 | DDRC &= ~0xF; | ||
| 136 | PORTC &= ~0xF; | ||
| 137 | } | ||
| 138 | |||
| 139 | static void select_row(uint8_t row) | ||
| 140 | { | ||
| 141 | // Output low(DDR:1, PORT:0) to select | ||
| 142 | switch (row) { | ||
| 143 | case 0: | ||
| 144 | DDRC |= (1<<0); | ||
| 145 | PORTC &= ~(1<<0); | ||
| 146 | break; | ||
| 147 | case 1: | ||
| 148 | DDRC |= (1<<1); | ||
| 149 | PORTC &= ~(1<<1); | ||
| 150 | break; | ||
| 151 | case 2: | ||
| 152 | DDRC |= (1<<2); | ||
| 153 | PORTC &= ~(1<<2); | ||
| 154 | break; | ||
| 155 | case 3: | ||
| 156 | DDRC |= (1<<3); | ||
| 157 | PORTC &= ~(1<<3); | ||
| 158 | break; | ||
| 159 | } | ||
| 160 | } | ||
diff --git a/keyboards/lets_split/uno-slave/uno-matrix.h b/keyboards/lets_split/uno-slave/uno-matrix.h new file mode 100644 index 000000000..c0f636f80 --- /dev/null +++ b/keyboards/lets_split/uno-slave/uno-matrix.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | #ifndef UNO_MATRIX | ||
| 2 | #define UNO_MATRIX | ||
| 3 | |||
| 4 | #define MATRIX_ROWS 4 | ||
| 5 | #define MATRIX_COLS 6 | ||
| 6 | |||
| 7 | #include <stdbool.h> | ||
| 8 | |||
| 9 | typedef uint8_t matrix_row_t; | ||
| 10 | |||
| 11 | uint8_t matrix_rows(void); | ||
| 12 | uint8_t matrix_cols(void); | ||
| 13 | void matrix_init(void); | ||
| 14 | uint8_t matrix_scan(void); | ||
| 15 | bool matrix_is_modified(void); | ||
| 16 | bool matrix_is_on(uint8_t row, uint8_t col); | ||
| 17 | matrix_row_t matrix_get_row(uint8_t row); | ||
| 18 | |||
| 19 | #endif | ||
diff --git a/keyboards/lets_split/usbconfig.h b/keyboards/lets_split/usbconfig.h new file mode 100644 index 000000000..d0ca4c717 --- /dev/null +++ b/keyboards/lets_split/usbconfig.h | |||
| @@ -0,0 +1,377 @@ | |||
| 1 | /* Name: usbconfig.h | ||
| 2 | * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers | ||
| 3 | * Author: Christian Starkjohann | ||
| 4 | * Creation Date: 2005-04-01 | ||
| 5 | * Tabsize: 4 | ||
| 6 | * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH | ||
| 7 | * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) | ||
| 8 | * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef __usbconfig_h_included__ | ||
| 12 | #define __usbconfig_h_included__ | ||
| 13 | |||
| 14 | |||
| 15 | /* | ||
| 16 | General Description: | ||
| 17 | This file is an example configuration (with inline documentation) for the USB | ||
| 18 | driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is | ||
| 19 | also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may | ||
| 20 | wire the lines to any other port, as long as D+ is also wired to INT0 (or any | ||
| 21 | other hardware interrupt, as long as it is the highest level interrupt, see | ||
| 22 | section at the end of this file). | ||
| 23 | */ | ||
| 24 | |||
| 25 | /* ---------------------------- Hardware Config ---------------------------- */ | ||
| 26 | |||
| 27 | #define USB_CFG_IOPORTNAME D | ||
| 28 | /* This is the port where the USB bus is connected. When you configure it to | ||
| 29 | * "B", the registers PORTB, PINB and DDRB will be used. | ||
| 30 | */ | ||
| 31 | #define USB_CFG_DMINUS_BIT 3 | ||
| 32 | /* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. | ||
| 33 | * This may be any bit in the port. | ||
| 34 | */ | ||
| 35 | #define USB_CFG_DPLUS_BIT 2 | ||
| 36 | /* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. | ||
| 37 | * This may be any bit in the port. Please note that D+ must also be connected | ||
| 38 | * to interrupt pin INT0! [You can also use other interrupts, see section | ||
| 39 | * "Optional MCU Description" below, or you can connect D- to the interrupt, as | ||
| 40 | * it is required if you use the USB_COUNT_SOF feature. If you use D- for the | ||
| 41 | * interrupt, the USB interrupt will also be triggered at Start-Of-Frame | ||
| 42 | * markers every millisecond.] | ||
| 43 | */ | ||
| 44 | #define USB_CFG_CLOCK_KHZ (F_CPU/1000) | ||
| 45 | /* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, | ||
| 46 | * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code | ||
| 47 | * require no crystal, they tolerate +/- 1% deviation from the nominal | ||
| 48 | * frequency. All other rates require a precision of 2000 ppm and thus a | ||
| 49 | * crystal! | ||
| 50 | * Since F_CPU should be defined to your actual clock rate anyway, you should | ||
| 51 | * not need to modify this setting. | ||
| 52 | */ | ||
| 53 | #define USB_CFG_CHECK_CRC 0 | ||
| 54 | /* Define this to 1 if you want that the driver checks integrity of incoming | ||
| 55 | * data packets (CRC checks). CRC checks cost quite a bit of code size and are | ||
| 56 | * currently only available for 18 MHz crystal clock. You must choose | ||
| 57 | * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. | ||
| 58 | */ | ||
| 59 | |||
| 60 | /* ----------------------- Optional Hardware Config ------------------------ */ | ||
| 61 | |||
| 62 | /* #define USB_CFG_PULLUP_IOPORTNAME D */ | ||
| 63 | /* If you connect the 1.5k pullup resistor from D- to a port pin instead of | ||
| 64 | * V+, you can connect and disconnect the device from firmware by calling | ||
| 65 | * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). | ||
| 66 | * This constant defines the port on which the pullup resistor is connected. | ||
| 67 | */ | ||
| 68 | /* #define USB_CFG_PULLUP_BIT 4 */ | ||
| 69 | /* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined | ||
| 70 | * above) where the 1.5k pullup resistor is connected. See description | ||
| 71 | * above for details. | ||
| 72 | */ | ||
| 73 | |||
| 74 | /* --------------------------- Functional Range ---------------------------- */ | ||
| 75 | |||
| 76 | #define USB_CFG_HAVE_INTRIN_ENDPOINT 1 | ||
| 77 | /* Define this to 1 if you want to compile a version with two endpoints: The | ||
| 78 | * default control endpoint 0 and an interrupt-in endpoint (any other endpoint | ||
| 79 | * number). | ||
| 80 | */ | ||
| 81 | #define USB_CFG_HAVE_INTRIN_ENDPOINT3 1 | ||
| 82 | /* Define this to 1 if you want to compile a version with three endpoints: The | ||
| 83 | * default control endpoint 0, an interrupt-in endpoint 3 (or the number | ||
| 84 | * configured below) and a catch-all default interrupt-in endpoint as above. | ||
| 85 | * You must also define USB_CFG_HAVE_INTRIN_ENDPOINT to 1 for this feature. | ||
| 86 | */ | ||
| 87 | #define USB_CFG_EP3_NUMBER 3 | ||
| 88 | /* If the so-called endpoint 3 is used, it can now be configured to any other | ||
| 89 | * endpoint number (except 0) with this macro. Default if undefined is 3. | ||
| 90 | */ | ||
| 91 | /* #define USB_INITIAL_DATATOKEN USBPID_DATA1 */ | ||
| 92 | /* The above macro defines the startup condition for data toggling on the | ||
| 93 | * interrupt/bulk endpoints 1 and 3. Defaults to USBPID_DATA1. | ||
| 94 | * Since the token is toggled BEFORE sending any data, the first packet is | ||
| 95 | * sent with the oposite value of this configuration! | ||
| 96 | */ | ||
| 97 | #define USB_CFG_IMPLEMENT_HALT 0 | ||
| 98 | /* Define this to 1 if you also want to implement the ENDPOINT_HALT feature | ||
| 99 | * for endpoint 1 (interrupt endpoint). Although you may not need this feature, | ||
| 100 | * it is required by the standard. We have made it a config option because it | ||
| 101 | * bloats the code considerably. | ||
| 102 | */ | ||
| 103 | #define USB_CFG_SUPPRESS_INTR_CODE 0 | ||
| 104 | /* Define this to 1 if you want to declare interrupt-in endpoints, but don't | ||
| 105 | * want to send any data over them. If this macro is defined to 1, functions | ||
| 106 | * usbSetInterrupt() and usbSetInterrupt3() are omitted. This is useful if | ||
| 107 | * you need the interrupt-in endpoints in order to comply to an interface | ||
| 108 | * (e.g. HID), but never want to send any data. This option saves a couple | ||
| 109 | * of bytes in flash memory and the transmit buffers in RAM. | ||
| 110 | */ | ||
| 111 | #define USB_CFG_INTR_POLL_INTERVAL 10 | ||
| 112 | /* If you compile a version with endpoint 1 (interrupt-in), this is the poll | ||
| 113 | * interval. The value is in milliseconds and must not be less than 10 ms for | ||
| 114 | * low speed devices. | ||
| 115 | */ | ||
| 116 | #define USB_CFG_IS_SELF_POWERED 0 | ||
| 117 | /* Define this to 1 if the device has its own power supply. Set it to 0 if the | ||
| 118 | * device is powered from the USB bus. | ||
| 119 | */ | ||
| 120 | #define USB_CFG_MAX_BUS_POWER 100 | ||
| 121 | /* Set this variable to the maximum USB bus power consumption of your device. | ||
| 122 | * The value is in milliamperes. [It will be divided by two since USB | ||
| 123 | * communicates power requirements in units of 2 mA.] | ||
| 124 | */ | ||
| 125 | #define USB_CFG_IMPLEMENT_FN_WRITE 1 | ||
| 126 | /* Set this to 1 if you want usbFunctionWrite() to be called for control-out | ||
| 127 | * transfers. Set it to 0 if you don't need it and want to save a couple of | ||
| 128 | * bytes. | ||
| 129 | */ | ||
| 130 | #define USB_CFG_IMPLEMENT_FN_READ 0 | ||
| 131 | /* Set this to 1 if you need to send control replies which are generated | ||
| 132 | * "on the fly" when usbFunctionRead() is called. If you only want to send | ||
| 133 | * data from a static buffer, set it to 0 and return the data from | ||
| 134 | * usbFunctionSetup(). This saves a couple of bytes. | ||
| 135 | */ | ||
| 136 | #define USB_CFG_IMPLEMENT_FN_WRITEOUT 0 | ||
| 137 | /* Define this to 1 if you want to use interrupt-out (or bulk out) endpoints. | ||
| 138 | * You must implement the function usbFunctionWriteOut() which receives all | ||
| 139 | * interrupt/bulk data sent to any endpoint other than 0. The endpoint number | ||
| 140 | * can be found in 'usbRxToken'. | ||
| 141 | */ | ||
| 142 | #define USB_CFG_HAVE_FLOWCONTROL 0 | ||
| 143 | /* Define this to 1 if you want flowcontrol over USB data. See the definition | ||
| 144 | * of the macros usbDisableAllRequests() and usbEnableAllRequests() in | ||
| 145 | * usbdrv.h. | ||
| 146 | */ | ||
| 147 | #define USB_CFG_DRIVER_FLASH_PAGE 0 | ||
| 148 | /* If the device has more than 64 kBytes of flash, define this to the 64 k page | ||
| 149 | * where the driver's constants (descriptors) are located. Or in other words: | ||
| 150 | * Define this to 1 for boot loaders on the ATMega128. | ||
| 151 | */ | ||
| 152 | #define USB_CFG_LONG_TRANSFERS 0 | ||
| 153 | /* Define this to 1 if you want to send/receive blocks of more than 254 bytes | ||
| 154 | * in a single control-in or control-out transfer. Note that the capability | ||
| 155 | * for long transfers increases the driver size. | ||
| 156 | */ | ||
| 157 | /* #define USB_RX_USER_HOOK(data, len) if(usbRxToken == (uchar)USBPID_SETUP) blinkLED(); */ | ||
| 158 | /* This macro is a hook if you want to do unconventional things. If it is | ||
| 159 | * defined, it's inserted at the beginning of received message processing. | ||
| 160 | * If you eat the received message and don't want default processing to | ||
| 161 | * proceed, do a return after doing your things. One possible application | ||
| 162 | * (besides debugging) is to flash a status LED on each packet. | ||
| 163 | */ | ||
| 164 | /* #define USB_RESET_HOOK(resetStarts) if(!resetStarts){hadUsbReset();} */ | ||
| 165 | /* This macro is a hook if you need to know when an USB RESET occurs. It has | ||
| 166 | * one parameter which distinguishes between the start of RESET state and its | ||
| 167 | * end. | ||
| 168 | */ | ||
| 169 | /* #define USB_SET_ADDRESS_HOOK() hadAddressAssigned(); */ | ||
| 170 | /* This macro (if defined) is executed when a USB SET_ADDRESS request was | ||
| 171 | * received. | ||
| 172 | */ | ||
| 173 | #define USB_COUNT_SOF 0 | ||
| 174 | /* define this macro to 1 if you need the global variable "usbSofCount" which | ||
| 175 | * counts SOF packets. This feature requires that the hardware interrupt is | ||
| 176 | * connected to D- instead of D+. | ||
| 177 | */ | ||
| 178 | /* #ifdef __ASSEMBLER__ | ||
| 179 | * macro myAssemblerMacro | ||
| 180 | * in YL, TCNT0 | ||
| 181 | * sts timer0Snapshot, YL | ||
| 182 | * endm | ||
| 183 | * #endif | ||
| 184 | * #define USB_SOF_HOOK myAssemblerMacro | ||
| 185 | * This macro (if defined) is executed in the assembler module when a | ||
| 186 | * Start Of Frame condition is detected. It is recommended to define it to | ||
| 187 | * the name of an assembler macro which is defined here as well so that more | ||
| 188 | * than one assembler instruction can be used. The macro may use the register | ||
| 189 | * YL and modify SREG. If it lasts longer than a couple of cycles, USB messages | ||
| 190 | * immediately after an SOF pulse may be lost and must be retried by the host. | ||
| 191 | * What can you do with this hook? Since the SOF signal occurs exactly every | ||
| 192 | * 1 ms (unless the host is in sleep mode), you can use it to tune OSCCAL in | ||
| 193 | * designs running on the internal RC oscillator. | ||
| 194 | * Please note that Start Of Frame detection works only if D- is wired to the | ||
| 195 | * interrupt, not D+. THIS IS DIFFERENT THAN MOST EXAMPLES! | ||
| 196 | */ | ||
| 197 | #define USB_CFG_CHECK_DATA_TOGGLING 0 | ||
| 198 | /* define this macro to 1 if you want to filter out duplicate data packets | ||
| 199 | * sent by the host. Duplicates occur only as a consequence of communication | ||
| 200 | * errors, when the host does not receive an ACK. Please note that you need to | ||
| 201 | * implement the filtering yourself in usbFunctionWriteOut() and | ||
| 202 | * usbFunctionWrite(). Use the global usbCurrentDataToken and a static variable | ||
| 203 | * for each control- and out-endpoint to check for duplicate packets. | ||
| 204 | */ | ||
| 205 | #define USB_CFG_HAVE_MEASURE_FRAME_LENGTH 0 | ||
| 206 | /* define this macro to 1 if you want the function usbMeasureFrameLength() | ||
| 207 | * compiled in. This function can be used to calibrate the AVR's RC oscillator. | ||
| 208 | */ | ||
| 209 | #define USB_USE_FAST_CRC 0 | ||
| 210 | /* The assembler module has two implementations for the CRC algorithm. One is | ||
| 211 | * faster, the other is smaller. This CRC routine is only used for transmitted | ||
| 212 | * messages where timing is not critical. The faster routine needs 31 cycles | ||
| 213 | * per byte while the smaller one needs 61 to 69 cycles. The faster routine | ||
| 214 | * may be worth the 32 bytes bigger code size if you transmit lots of data and | ||
| 215 | * run the AVR close to its limit. | ||
| 216 | */ | ||
| 217 | |||
| 218 | /* -------------------------- Device Description --------------------------- */ | ||
| 219 | |||
| 220 | #define USB_CFG_VENDOR_ID (VENDOR_ID & 0xFF), ((VENDOR_ID >> 8) & 0xFF) | ||
| 221 | /* USB vendor ID for the device, low byte first. If you have registered your | ||
| 222 | * own Vendor ID, define it here. Otherwise you may use one of obdev's free | ||
| 223 | * shared VID/PID pairs. Be sure to read USB-IDs-for-free.txt for rules! | ||
| 224 | * *** IMPORTANT NOTE *** | ||
| 225 | * This template uses obdev's shared VID/PID pair for Vendor Class devices | ||
| 226 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand | ||
| 227 | * the implications! | ||
| 228 | */ | ||
| 229 | #define USB_CFG_DEVICE_ID (PRODUCT_ID & 0xFF), ((PRODUCT_ID >> 8) & 0xFF) | ||
| 230 | /* This is the ID of the product, low byte first. It is interpreted in the | ||
| 231 | * scope of the vendor ID. If you have registered your own VID with usb.org | ||
| 232 | * or if you have licensed a PID from somebody else, define it here. Otherwise | ||
| 233 | * you may use one of obdev's free shared VID/PID pairs. See the file | ||
| 234 | * USB-IDs-for-free.txt for details! | ||
| 235 | * *** IMPORTANT NOTE *** | ||
| 236 | * This template uses obdev's shared VID/PID pair for Vendor Class devices | ||
| 237 | * with libusb: 0x16c0/0x5dc. Use this VID/PID pair ONLY if you understand | ||
| 238 | * the implications! | ||
| 239 | */ | ||
| 240 | #define USB_CFG_DEVICE_VERSION 0x00, 0x01 | ||
| 241 | /* Version number of the device: Minor number first, then major number. | ||
| 242 | */ | ||
| 243 | #define USB_CFG_VENDOR_NAME 't', '.', 'm', '.', 'k', '.' | ||
| 244 | #define USB_CFG_VENDOR_NAME_LEN 6 | ||
| 245 | /* These two values define the vendor name returned by the USB device. The name | ||
| 246 | * must be given as a list of characters under single quotes. The characters | ||
| 247 | * are interpreted as Unicode (UTF-16) entities. | ||
| 248 | * If you don't want a vendor name string, undefine these macros. | ||
| 249 | * ALWAYS define a vendor name containing your Internet domain name if you use | ||
| 250 | * obdev's free shared VID/PID pair. See the file USB-IDs-for-free.txt for | ||
| 251 | * details. | ||
| 252 | */ | ||
| 253 | #define USB_CFG_DEVICE_NAME 'P', 'S', '/', '2', ' ', 'k', 'e', 'y', 'b', 'o', 'a', 'r', 'd', ' ', 'c', 'o', 'n', 'v', 'e', 'r', 't', 'e', 'r' | ||
| 254 | #define USB_CFG_DEVICE_NAME_LEN 23 | ||
| 255 | /* Same as above for the device name. If you don't want a device name, undefine | ||
| 256 | * the macros. See the file USB-IDs-for-free.txt before you assign a name if | ||
| 257 | * you use a shared VID/PID. | ||
| 258 | */ | ||
| 259 | /*#define USB_CFG_SERIAL_NUMBER 'N', 'o', 'n', 'e' */ | ||
| 260 | /*#define USB_CFG_SERIAL_NUMBER_LEN 0 */ | ||
| 261 | /* Same as above for the serial number. If you don't want a serial number, | ||
| 262 | * undefine the macros. | ||
| 263 | * It may be useful to provide the serial number through other means than at | ||
| 264 | * compile time. See the section about descriptor properties below for how | ||
| 265 | * to fine tune control over USB descriptors such as the string descriptor | ||
| 266 | * for the serial number. | ||
| 267 | */ | ||
| 268 | #define USB_CFG_DEVICE_CLASS 0 | ||
| 269 | #define USB_CFG_DEVICE_SUBCLASS 0 | ||
| 270 | /* See USB specification if you want to conform to an existing device class. | ||
| 271 | * Class 0xff is "vendor specific". | ||
| 272 | */ | ||
| 273 | #define USB_CFG_INTERFACE_CLASS 3 /* HID */ | ||
| 274 | #define USB_CFG_INTERFACE_SUBCLASS 1 /* Boot */ | ||
| 275 | #define USB_CFG_INTERFACE_PROTOCOL 1 /* Keyboard */ | ||
| 276 | /* See USB specification if you want to conform to an existing device class or | ||
| 277 | * protocol. The following classes must be set at interface level: | ||
| 278 | * HID class is 3, no subclass and protocol required (but may be useful!) | ||
| 279 | * CDC class is 2, use subclass 2 and protocol 1 for ACM | ||
| 280 | */ | ||
| 281 | #define USB_CFG_HID_REPORT_DESCRIPTOR_LENGTH 0 | ||
| 282 | /* Define this to the length of the HID report descriptor, if you implement | ||
| 283 | * an HID device. Otherwise don't define it or define it to 0. | ||
| 284 | * If you use this define, you must add a PROGMEM character array named | ||
| 285 | * "usbHidReportDescriptor" to your code which contains the report descriptor. | ||
| 286 | * Don't forget to keep the array and this define in sync! | ||
| 287 | */ | ||
| 288 | |||
| 289 | /* #define USB_PUBLIC static */ | ||
| 290 | /* Use the define above if you #include usbdrv.c instead of linking against it. | ||
| 291 | * This technique saves a couple of bytes in flash memory. | ||
| 292 | */ | ||
| 293 | |||
| 294 | /* ------------------- Fine Control over USB Descriptors ------------------- */ | ||
| 295 | /* If you don't want to use the driver's default USB descriptors, you can | ||
| 296 | * provide our own. These can be provided as (1) fixed length static data in | ||
| 297 | * flash memory, (2) fixed length static data in RAM or (3) dynamically at | ||
| 298 | * runtime in the function usbFunctionDescriptor(). See usbdrv.h for more | ||
| 299 | * information about this function. | ||
| 300 | * Descriptor handling is configured through the descriptor's properties. If | ||
| 301 | * no properties are defined or if they are 0, the default descriptor is used. | ||
| 302 | * Possible properties are: | ||
| 303 | * + USB_PROP_IS_DYNAMIC: The data for the descriptor should be fetched | ||
| 304 | * at runtime via usbFunctionDescriptor(). If the usbMsgPtr mechanism is | ||
| 305 | * used, the data is in FLASH by default. Add property USB_PROP_IS_RAM if | ||
| 306 | * you want RAM pointers. | ||
| 307 | * + USB_PROP_IS_RAM: The data returned by usbFunctionDescriptor() or found | ||
| 308 | * in static memory is in RAM, not in flash memory. | ||
| 309 | * + USB_PROP_LENGTH(len): If the data is in static memory (RAM or flash), | ||
| 310 | * the driver must know the descriptor's length. The descriptor itself is | ||
| 311 | * found at the address of a well known identifier (see below). | ||
| 312 | * List of static descriptor names (must be declared PROGMEM if in flash): | ||
| 313 | * char usbDescriptorDevice[]; | ||
| 314 | * char usbDescriptorConfiguration[]; | ||
| 315 | * char usbDescriptorHidReport[]; | ||
| 316 | * char usbDescriptorString0[]; | ||
| 317 | * int usbDescriptorStringVendor[]; | ||
| 318 | * int usbDescriptorStringDevice[]; | ||
| 319 | * int usbDescriptorStringSerialNumber[]; | ||
| 320 | * Other descriptors can't be provided statically, they must be provided | ||
| 321 | * dynamically at runtime. | ||
| 322 | * | ||
| 323 | * Descriptor properties are or-ed or added together, e.g.: | ||
| 324 | * #define USB_CFG_DESCR_PROPS_DEVICE (USB_PROP_IS_RAM | USB_PROP_LENGTH(18)) | ||
| 325 | * | ||
| 326 | * The following descriptors are defined: | ||
| 327 | * USB_CFG_DESCR_PROPS_DEVICE | ||
| 328 | * USB_CFG_DESCR_PROPS_CONFIGURATION | ||
| 329 | * USB_CFG_DESCR_PROPS_STRINGS | ||
| 330 | * USB_CFG_DESCR_PROPS_STRING_0 | ||
| 331 | * USB_CFG_DESCR_PROPS_STRING_VENDOR | ||
| 332 | * USB_CFG_DESCR_PROPS_STRING_PRODUCT | ||
| 333 | * USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER | ||
| 334 | * USB_CFG_DESCR_PROPS_HID | ||
| 335 | * USB_CFG_DESCR_PROPS_HID_REPORT | ||
| 336 | * USB_CFG_DESCR_PROPS_UNKNOWN (for all descriptors not handled by the driver) | ||
| 337 | * | ||
| 338 | * Note about string descriptors: String descriptors are not just strings, they | ||
| 339 | * are Unicode strings prefixed with a 2 byte header. Example: | ||
| 340 | * int serialNumberDescriptor[] = { | ||
| 341 | * USB_STRING_DESCRIPTOR_HEADER(6), | ||
| 342 | * 'S', 'e', 'r', 'i', 'a', 'l' | ||
| 343 | * }; | ||
| 344 | */ | ||
| 345 | |||
| 346 | #define USB_CFG_DESCR_PROPS_DEVICE 0 | ||
| 347 | #define USB_CFG_DESCR_PROPS_CONFIGURATION USB_PROP_IS_DYNAMIC | ||
| 348 | //#define USB_CFG_DESCR_PROPS_CONFIGURATION 0 | ||
| 349 | #define USB_CFG_DESCR_PROPS_STRINGS 0 | ||
| 350 | #define USB_CFG_DESCR_PROPS_STRING_0 0 | ||
| 351 | #define USB_CFG_DESCR_PROPS_STRING_VENDOR 0 | ||
| 352 | #define USB_CFG_DESCR_PROPS_STRING_PRODUCT 0 | ||
| 353 | #define USB_CFG_DESCR_PROPS_STRING_SERIAL_NUMBER 0 | ||
| 354 | //#define USB_CFG_DESCR_PROPS_HID USB_PROP_IS_DYNAMIC | ||
| 355 | #define USB_CFG_DESCR_PROPS_HID 0 | ||
| 356 | #define USB_CFG_DESCR_PROPS_HID_REPORT USB_PROP_IS_DYNAMIC | ||
| 357 | //#define USB_CFG_DESCR_PROPS_HID_REPORT 0 | ||
| 358 | #define USB_CFG_DESCR_PROPS_UNKNOWN 0 | ||
| 359 | |||
| 360 | /* ----------------------- Optional MCU Description ------------------------ */ | ||
| 361 | |||
| 362 | /* The following configurations have working defaults in usbdrv.h. You | ||
| 363 | * usually don't need to set them explicitly. Only if you want to run | ||
| 364 | * the driver on a device which is not yet supported or with a compiler | ||
| 365 | * which is not fully supported (such as IAR C) or if you use a differnt | ||
| 366 | * interrupt than INT0, you may have to define some of these. | ||
| 367 | */ | ||
| 368 | /* #define USB_INTR_CFG MCUCR */ | ||
| 369 | /* #define USB_INTR_CFG_SET ((1 << ISC00) | (1 << ISC01)) */ | ||
| 370 | /* #define USB_INTR_CFG_CLR 0 */ | ||
| 371 | /* #define USB_INTR_ENABLE GIMSK */ | ||
| 372 | /* #define USB_INTR_ENABLE_BIT INT0 */ | ||
| 373 | /* #define USB_INTR_PENDING GIFR */ | ||
| 374 | /* #define USB_INTR_PENDING_BIT INTF0 */ | ||
| 375 | /* #define USB_INTR_VECTOR INT0_vect */ | ||
| 376 | |||
| 377 | #endif /* __usbconfig_h_included__ */ | ||
diff --git a/tmk_core/common/matrix.h b/tmk_core/common/matrix.h index 71153a5f5..cee3593ee 100644 --- a/tmk_core/common/matrix.h +++ b/tmk_core/common/matrix.h | |||
| @@ -72,6 +72,11 @@ void matrix_scan_kb(void); | |||
| 72 | void matrix_init_user(void); | 72 | void matrix_init_user(void); |
| 73 | void matrix_scan_user(void); | 73 | void matrix_scan_user(void); |
| 74 | 74 | ||
| 75 | #ifdef I2C_SPLIT | ||
| 76 | void slave_matrix_init(void); | ||
| 77 | uint8_t slave_matrix_scan(void); | ||
| 78 | #endif | ||
| 79 | |||
| 75 | #ifdef __cplusplus | 80 | #ifdef __cplusplus |
| 76 | } | 81 | } |
| 77 | #endif | 82 | #endif |
