diff options
Diffstat (limited to 'quantum')
20 files changed, 858 insertions, 24 deletions
diff --git a/quantum/rgb_matrix.c b/quantum/rgb_matrix.c index 558e28dece..992ce99de9 100644 --- a/quantum/rgb_matrix.c +++ b/quantum/rgb_matrix.c @@ -18,7 +18,7 @@ #include "rgb_matrix.h" #include <avr/io.h> -#include "TWIlib.h" +#include "i2c_master.h" #include <util/delay.h> #include <avr/interrupt.h> #include "progmem.h" @@ -324,8 +324,8 @@ void rgb_matrix_raindrops(bool initialize) { HSV hsv; RGB rgb; - // Change one LED every tick - uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % DRIVER_LED_TOTAL : 255; + // Change one LED every tick, make sure speed is not 0 + uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255; for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) { @@ -432,7 +432,7 @@ void rgb_matrix_rainbow_beacon(void) { rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { led = g_rgb_leds[i]; - hsv.h = 1.5 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 1.5 * (led.point.x - 112.0) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; + hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.y - 32.0)* cos(g_tick * PI / 128) + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.x - 112.0) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; rgb = hsv_to_rgb( hsv ); rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); } @@ -444,7 +444,7 @@ void rgb_matrix_rainbow_pinwheels(void) { rgb_led led; for (uint8_t i = 0; i < DRIVER_LED_TOTAL; i++) { led = g_rgb_leds[i]; - hsv.h = 2 * (led.point.y - 32.0)* cos(g_tick * PI / 128) + 2 * (66 - abs(led.point.x - 112.0)) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; + hsv.h = (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.y - 32.0)* cos(g_tick * PI / 128) + (2 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (66 - abs(led.point.x - 112.0)) * sin(g_tick * PI / 128) + rgb_matrix_config.hue; rgb = hsv_to_rgb( hsv ); rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); } @@ -458,7 +458,7 @@ void rgb_matrix_rainbow_moving_chevron(void) { led = g_rgb_leds[i]; // uint8_t r = g_tick; uint8_t r = 32; - hsv.h = 1.5 * abs(led.point.y - 32.0)* sin(r * PI / 128) + 1.5 * (led.point.x - (g_tick / 256.0 * 224)) * cos(r * PI / 128) + rgb_matrix_config.hue; + hsv.h = (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * abs(led.point.y - 32.0)* sin(r * PI / 128) + (1.5 * (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed)) * (led.point.x - (g_tick / 256.0 * 224)) * cos(r * PI / 128) + rgb_matrix_config.hue; rgb = hsv_to_rgb( hsv ); rgb_matrix_set_color( i, rgb.r, rgb.g, rgb.b ); } @@ -469,8 +469,8 @@ void rgb_matrix_jellybean_raindrops( bool initialize ) { HSV hsv; RGB rgb; - // Change one LED every tick - uint8_t led_to_change = ( g_tick & 0x000 ) == 0 ? rand() % DRIVER_LED_TOTAL : 255; + // Change one LED every tick, make sure speed is not 0 + uint8_t led_to_change = ( g_tick & ( 0x0A / (rgb_matrix_config.speed == 0 ? 1 : rgb_matrix_config.speed) ) ) == 0 ? rand() % (DRIVER_LED_TOTAL) : 255; for ( int i=0; i<DRIVER_LED_TOTAL; i++ ) { @@ -577,8 +577,10 @@ void rgb_matrix_custom(void) { } void rgb_matrix_task(void) { + static uint8_t toggle_enable_last = 255; if (!rgb_matrix_config.enable) { rgb_matrix_all_off(); + toggle_enable_last = rgb_matrix_config.enable; return; } // delay 1 second before driving LEDs or doing anything else @@ -618,8 +620,9 @@ void rgb_matrix_task(void) { // detect change in effect, so each effect can // have an optional initialization. static uint8_t effect_last = 255; - bool initialize = effect != effect_last; + bool initialize = (effect != effect_last) || (rgb_matrix_config.enable != toggle_enable_last); effect_last = effect; + toggle_enable_last = rgb_matrix_config.enable; // this gets ticked at 20 Hz. // each effect can opt to do calculations @@ -628,9 +631,6 @@ void rgb_matrix_task(void) { case RGB_MATRIX_SOLID_COLOR: rgb_matrix_solid_color(); break; - case RGB_MATRIX_SOLID_REACTIVE: - rgb_matrix_solid_reactive(); - break; case RGB_MATRIX_ALPHAS_MODS: rgb_matrix_alphas_mods(); break; @@ -665,6 +665,9 @@ void rgb_matrix_task(void) { rgb_matrix_jellybean_raindrops( initialize ); break; #ifdef RGB_MATRIX_KEYPRESSES + case RGB_MATRIX_SOLID_REACTIVE: + rgb_matrix_solid_reactive(); + break; case RGB_MATRIX_SPLASH: rgb_matrix_splash(); break; @@ -719,10 +722,8 @@ void rgb_matrix_indicators_user(void) {} // } void rgb_matrix_init_drivers(void) { - //sei(); - // Initialize TWI - TWIInit(); + i2c_init(); IS31FL3731_init( DRIVER_ADDR_1 ); IS31FL3731_init( DRIVER_ADDR_2 ); @@ -830,8 +831,8 @@ void rgblight_step(void) { void rgblight_step_reverse(void) { rgb_matrix_config.mode--; - if (rgb_matrix_config.mode <= 1) - rgb_matrix_config.mode = (RGB_MATRIX_EFFECT_MAX - 1); + if (rgb_matrix_config.mode < 1) + rgb_matrix_config.mode = RGB_MATRIX_EFFECT_MAX - 1; eeconfig_update_rgb_matrix(rgb_matrix_config.raw); } diff --git a/quantum/rgb_matrix.h b/quantum/rgb_matrix.h index 1552d59103..aaa85d5f51 100644 --- a/quantum/rgb_matrix.h +++ b/quantum/rgb_matrix.h @@ -64,7 +64,6 @@ typedef union { enum rgb_matrix_effects { RGB_MATRIX_SOLID_COLOR = 1, - RGB_MATRIX_SOLID_REACTIVE, RGB_MATRIX_ALPHAS_MODS, RGB_MATRIX_DUAL_BEACON, RGB_MATRIX_GRADIENT_UP_DOWN, @@ -77,6 +76,7 @@ enum rgb_matrix_effects { RGB_MATRIX_RAINBOW_MOVING_CHEVRON, RGB_MATRIX_JELLYBEAN_RAINDROPS, #ifdef RGB_MATRIX_KEYPRESSES + RGB_MATRIX_SOLID_REACTIVE, RGB_MATRIX_SPLASH, RGB_MATRIX_MULTISPLASH, RGB_MATRIX_SOLID_SPLASH, diff --git a/quantum/rgblight_list.h b/quantum/rgblight_list.h index 5dd480b617..29b2802263 100644 --- a/quantum/rgblight_list.h +++ b/quantum/rgblight_list.h @@ -36,6 +36,26 @@ #define rgblight_setrgb_magenta() rgblight_setrgb (0xFF, 0x00, 0xFF) #define rgblight_setrgb_pink() rgblight_setrgb (0xFF, 0x80, 0xBF) +/* SET RGB List */ +#define rgblight_setrgb_white_at(at) rgblight_setrgb_at (0xFF, 0xFF, 0xFF, at) +#define rgblight_setrgb_red_at(at) rgblight_setrgb_at (0xFF, 0x00, 0x00, at) +#define rgblight_setrgb_coral_at(at) rgblight_setrgb_at (0xFF, 0x7C, 0x4D, at) +#define rgblight_setrgb_orange_at(at) rgblight_setrgb_at (0xFF, 0x80, 0x00, at) +#define rgblight_setrgb_goldenrod_at(at) rgblight_setrgb_at (0xD9, 0xA5, 0x21, at) +#define rgblight_setrgb_gold_at(at) rgblight_setrgb_at (0xFF, 0xD9, 0x00, at) +#define rgblight_setrgb_yellow_at(at) rgblight_setrgb_at (0xFF, 0xFF, 0x00, at) +#define rgblight_setrgb_chartreuse_at(at) rgblight_setrgb_at (0x80, 0xFF, 0x00, at) +#define rgblight_setrgb_green_at(at) rgblight_setrgb_at (0x00, 0xFF, 0x00, at) +#define rgblight_setrgb_springgreen_at(at) rgblight_setrgb_at (0x00, 0xFF, 0x80, at) +#define rgblight_setrgb_turquoise_at(at) rgblight_setrgb_at (0x47, 0x6E, 0x6A, at) +#define rgblight_setrgb_teal_at(at) rgblight_setrgb_at (0x00, 0x80, 0x80, at) +#define rgblight_setrgb_cyan_at(at) rgblight_setrgb_at (0x00, 0xFF, 0xFF, at) +#define rgblight_setrgb_azure_at(at) rgblight_setrgb_at (0x99, 0xf5, 0xFF, at) +#define rgblight_setrgb_blue_at(at) rgblight_setrgb_at (0x00, 0x00, 0xFF, at) +#define rgblight_setrgb_purple_at(at) rgblight_setrgb_at (0x7A, 0x00, 0xFF, at) +#define rgblight_setrgb_magenta_at(at) rgblight_setrgb_at (0xFF, 0x00, 0xFF, at) +#define rgblight_setrgb_pink_at(at) rgblight_setrgb_at (0xFF, 0x80, 0xBF, at) + /* SET HSV List */ #define rgblight_sethsv_white() rgblight_sethsv ( 0, 0, 255) #define rgblight_sethsv_red() rgblight_sethsv ( 0, 255, 255) @@ -56,4 +76,24 @@ #define rgblight_sethsv_magenta() rgblight_sethsv (300, 255, 255) #define rgblight_sethsv_pink() rgblight_sethsv (330, 128, 255) +/* SET HSV List */ +#define rgblight_sethsv_white_at(at) rgblight_sethsv_at ( 0, 0, 255, at) +#define rgblight_sethsv_red_at(at) rgblight_sethsv_at ( 0, 255, 255, at) +#define rgblight_sethsv_coral_at(at) rgblight_sethsv_at ( 16, 176, 255, at) +#define rgblight_sethsv_orange_at(at) rgblight_sethsv_at ( 39, 255, 255, at) +#define rgblight_sethsv_goldenrod_at(at) rgblight_sethsv_at ( 43, 218, 218, at) +#define rgblight_sethsv_gold_at(at) rgblight_sethsv_at ( 51, 255, 255, at) +#define rgblight_sethsv_yellow_at(at) rgblight_sethsv_at ( 60, 255, 255, at) +#define rgblight_sethsv_chartreuse_at(at) rgblight_sethsv_at ( 90, 255, 255, at) +#define rgblight_sethsv_green_at(at) rgblight_sethsv_at (120, 255, 255, at) +#define rgblight_sethsv_springgreen_at(at) rgblight_sethsv_at (150, 255, 255, at) +#define rgblight_sethsv_turquoise_at(at) rgblight_sethsv_at (174, 90, 112, at) +#define rgblight_sethsv_teal_at(at) rgblight_sethsv_at (180, 255, 128, at) +#define rgblight_sethsv_cyan_at(at) rgblight_sethsv_at (180, 255, 255, at) +#define rgblight_sethsv_azure_at(at) rgblight_sethsv_at (186, 102, 255, at) +#define rgblight_sethsv_blue_at(at) rgblight_sethsv_at (240, 255, 255, at) +#define rgblight_sethsv_purple_at(at) rgblight_sethsv_at (270, 255, 255, at) +#define rgblight_sethsv_magenta_at(at) rgblight_sethsv_at (300, 255, 255, at) +#define rgblight_sethsv_pink_at(at) rgblight_sethsv_at (330, 128, 255, at) + #endif diff --git a/quantum/template/config.h b/quantum/template/avr/config.h index 6d0b3c4d58..e739c93c97 100644 --- a/quantum/template/config.h +++ b/quantum/template/avr/config.h @@ -1,5 +1,5 @@ /* -Copyright 2017 REPLACE_WITH_YOUR_NAME +Copyright 2018 REPLACE_WITH_YOUR_NAME This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -48,7 +48,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. /* COL2ROW, ROW2COL, or CUSTOM_MATRIX */ #define DIODE_DIRECTION COL2ROW - + // #define BACKLIGHT_PIN B7 // #define BACKLIGHT_BREATHING // #define BACKLIGHT_LEVELS 3 diff --git a/quantum/template/rules.mk b/quantum/template/avr/rules.mk index 45eb6ee376..45eb6ee376 100644 --- a/quantum/template/rules.mk +++ b/quantum/template/avr/rules.mk diff --git a/quantum/template/template.c b/quantum/template/avr/template.c index 97f788654b..b6366fd9a3 100644 --- a/quantum/template/template.c +++ b/quantum/template/avr/template.c @@ -1,4 +1,4 @@ -/* Copyright 2017 REPLACE_WITH_YOUR_NAME +/* Copyright 2018 REPLACE_WITH_YOUR_NAME * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/quantum/template/template.h b/quantum/template/avr/template.h index c24bb1650f..c3924ee71f 100644 --- a/quantum/template/template.h +++ b/quantum/template/avr/template.h @@ -1,4 +1,4 @@ -/* Copyright 2017 REPLACE_WITH_YOUR_NAME +/* Copyright 2018 REPLACE_WITH_YOUR_NAME * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/quantum/template/base/info.json b/quantum/template/base/info.json new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/quantum/template/base/info.json diff --git a/quantum/template/keymaps/default/config.h b/quantum/template/base/keymaps/default/config.h index 0aa9e9e81b..0f75635051 100644 --- a/quantum/template/keymaps/default/config.h +++ b/quantum/template/base/keymaps/default/config.h @@ -1,4 +1,4 @@ -/* Copyright 2017 REPLACE_WITH_YOUR_NAME +/* Copyright 2018 REPLACE_WITH_YOUR_NAME * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/quantum/template/keymaps/default/keymap.c b/quantum/template/base/keymaps/default/keymap.c index d4bda895c7..14a8bc0f28 100644 --- a/quantum/template/keymaps/default/keymap.c +++ b/quantum/template/base/keymaps/default/keymap.c @@ -1,4 +1,4 @@ -/* Copyright 2017 REPLACE_WITH_YOUR_NAME +/* Copyright 2018 REPLACE_WITH_YOUR_NAME * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/quantum/template/keymaps/default/readme.md b/quantum/template/base/keymaps/default/readme.md index 21aa663d55..21aa663d55 100644 --- a/quantum/template/keymaps/default/readme.md +++ b/quantum/template/base/keymaps/default/readme.md diff --git a/quantum/template/readme.md b/quantum/template/base/readme.md index d9349811d0..d9349811d0 100644 --- a/quantum/template/readme.md +++ b/quantum/template/base/readme.md diff --git a/quantum/template/ps2avrgb/config.h b/quantum/template/ps2avrgb/config.h new file mode 100644 index 0000000000..b957465952 --- /dev/null +++ b/quantum/template/ps2avrgb/config.h @@ -0,0 +1,49 @@ +/* +Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +#include "config_common.h" + +#define VENDOR_ID 0x20A0 +#define PRODUCT_ID 0x422D +#define MANUFACTURER You +#define PRODUCT %KEYBOARD% + +#define RGBLED_NUM 16 + +#define MATRIX_ROWS 2 +#define MATRIX_COLS 3 + +#define MATRIX_ROW_PINS { D0, D5 } +#define MATRIX_COL_PINS { F1, F0, B0 } +#define UNUSED_PINS + +#define DIODE_DIRECTION COL2ROW +#define DEBOUNCING_DELAY 5 + +#define NO_BACKLIGHT_CLOCK +#define BACKLIGHT_LEVELS 1 +#define RGBLIGHT_ANIMATIONS + +#define NO_UART 1 + +/* key combination for command */ +#define IS_COMMAND() (keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) + +#endif diff --git a/quantum/template/ps2avrgb/i2c.c b/quantum/template/ps2avrgb/i2c.c new file mode 100644 index 0000000000..e8c4455ad1 --- /dev/null +++ b/quantum/template/ps2avrgb/i2c.c @@ -0,0 +1,106 @@ +/* +Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +// Please do not modify this file + +#include <avr/io.h> +#include <util/twi.h> + +#include "i2c.h" + +void i2c_set_bitrate(uint16_t bitrate_khz) { + uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz); + if (bitrate_div >= 16) { + bitrate_div = (bitrate_div - 16) / 2; + } + TWBR = bitrate_div; +} + +void i2c_init(void) { + // set pull-up resistors on I2C bus pins + PORTC |= 0b11; + + i2c_set_bitrate(400); + + // enable TWI (two-wire interface) + TWCR |= (1 << TWEN); + + // enable TWI interrupt and slave address ACK + TWCR |= (1 << TWIE); + TWCR |= (1 << TWEA); +} + +uint8_t i2c_start(uint8_t address) { + // reset TWI control register + TWCR = 0; + + // begin transmission and wait for it to end + TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); + while (!(TWCR & (1<<TWINT))); + + // check if the start condition was successfully transmitted + if ((TWSR & 0xF8) != TW_START) { + return 1; + } + + // transmit address and wait + TWDR = address; + TWCR = (1<<TWINT) | (1<<TWEN); + while (!(TWCR & (1<<TWINT))); + + // check if the device has acknowledged the READ / WRITE mode + uint8_t twst = TW_STATUS & 0xF8; + if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) { + return 1; + } + + return 0; +} + +void i2c_stop(void) { + TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); +} + +uint8_t i2c_write(uint8_t data) { + TWDR = data; + + // transmit data and wait + TWCR = (1<<TWINT) | (1<<TWEN); + while (!(TWCR & (1<<TWINT))); + + if ((TWSR & 0xF8) != TW_MT_DATA_ACK) { + return 1; + } + + return 0; +} + +uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) { + if (i2c_start(address)) { + return 1; + } + + for (uint16_t i = 0; i < length; i++) { + if (i2c_write(data[i])) { + return 1; + } + } + + i2c_stop(); + + return 0; +} diff --git a/quantum/template/ps2avrgb/i2c.h b/quantum/template/ps2avrgb/i2c.h new file mode 100644 index 0000000000..7ce50cdb57 --- /dev/null +++ b/quantum/template/ps2avrgb/i2c.h @@ -0,0 +1,27 @@ +/* +Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +// Please do not modify this file + +#ifndef __I2C_H__ +#define __I2C_H__ + +void i2c_init(void); +void i2c_set_bitrate(uint16_t bitrate_khz); +uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length); + +#endif diff --git a/quantum/template/ps2avrgb/matrix.c b/quantum/template/ps2avrgb/matrix.c new file mode 100644 index 0000000000..57aa36b5ff --- /dev/null +++ b/quantum/template/ps2avrgb/matrix.c @@ -0,0 +1,106 @@ +/* +Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#include <avr/io.h> +#include <util/delay.h> + +#include "matrix.h" + +#ifndef DEBOUNCE +#define DEBOUNCE 5 +#endif + +static uint8_t debouncing = DEBOUNCE; + +static matrix_row_t matrix[MATRIX_ROWS]; +static matrix_row_t matrix_debouncing[MATRIX_ROWS]; + +void matrix_init(void) { + // all outputs for rows high + DDRB = 0xFF; + PORTB = 0xFF; + // all inputs for columns + DDRA = 0x00; + DDRC &= ~(0x111111<<2); + DDRD &= ~(1<<PIND7); + // all columns are pulled-up + PORTA = 0xFF; + PORTC |= (0b111111<<2); + PORTD |= (1<<PIND7); + + // initialize matrix state: all keys off + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + matrix[row] = 0x00; + matrix_debouncing[row] = 0x00; + } +} + +void matrix_set_row_status(uint8_t row) { + DDRB = (1 << row); + PORTB = ~(1 << row); +} + +uint8_t bit_reverse(uint8_t x) { + x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa); + x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc); + x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0); + return x; +} + +uint8_t matrix_scan(void) { + for (uint8_t row = 0; row < MATRIX_ROWS; row++) { + matrix_set_row_status(row); + _delay_us(5); + + matrix_row_t cols = ( + // cols 0..7, PORTA 0 -> 7 + (~PINA) & 0xFF + ) | ( + // cols 8..13, PORTC 7 -> 0 + bit_reverse((~PINC) & 0xFF) << 8 + ) | ( + // col 14, PORTD 7 + ((~PIND) & (1 << PIND7)) << 7 + ); + + if (matrix_debouncing[row] != cols) { + matrix_debouncing[row] = cols; + debouncing = DEBOUNCE; + } + } + + if (debouncing) { + if (--debouncing) { + _delay_ms(1); + } else { + for (uint8_t i = 0; i < MATRIX_ROWS; i++) { + matrix[i] = matrix_debouncing[i]; + } + } + } + + matrix_scan_user(); + + return 1; +} + +inline matrix_row_t matrix_get_row(uint8_t row) { + return matrix[row]; +} + +void matrix_print(void) { +} diff --git a/quantum/template/ps2avrgb/rules.mk b/quantum/template/ps2avrgb/rules.mk new file mode 100644 index 0000000000..68d50aec67 --- /dev/null +++ b/quantum/template/ps2avrgb/rules.mk @@ -0,0 +1,50 @@ +# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# MCU name +MCU = atmega32a +PROTOCOL = VUSB + +# unsupported features for now +NO_UART = yes +NO_SUSPEND_POWER_DOWN = yes + +# processor frequency +F_CPU = 12000000 + +# Bootloader +# This definition is optional, and if your keyboard supports multiple bootloaders of +# different sizes, comment this out, and the correct address will be loaded +# automatically (+60). See bootloader.mk for all options. +BOOTLOADER = bootloadHID + +# build options +BOOTMAGIC_ENABLE = yes +MOUSEKEY_ENABLE = yes +EXTRAKEY_ENABLE = yes +CONSOLE_ENABLE = yes +COMMAND_ENABLE = yes +BACKLIGHT_ENABLE = no +RGBLIGHT_ENABLE = no +RGBLIGHT_CUSTOM_DRIVER = yes + +OPT_DEFS = -DDEBUG_LEVEL=0 + +# custom matrix setup +CUSTOM_MATRIX = yes +SRC = matrix.c i2c.c + +# programming options +PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex diff --git a/quantum/template/ps2avrgb/template.c b/quantum/template/ps2avrgb/template.c new file mode 100644 index 0000000000..8bbf9ebda5 --- /dev/null +++ b/quantum/template/ps2avrgb/template.c @@ -0,0 +1,25 @@ +/* Copyright 2018 REPLACE_WITH_YOUR_NAME + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#include "%KEYBOARD%.h" + +#include <avr/pgmspace.h> +#include "action_layer.h" +#include "i2c.h" +#include "quantum.h" + +__attribute__ ((weak)) +void matrix_scan_user(void) { +} diff --git a/quantum/template/ps2avrgb/template.h b/quantum/template/ps2avrgb/template.h new file mode 100644 index 0000000000..c3924ee71f --- /dev/null +++ b/quantum/template/ps2avrgb/template.h @@ -0,0 +1,34 @@ +/* Copyright 2018 REPLACE_WITH_YOUR_NAME + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ +#ifndef %KEYBOARD_UPPERCASE%_H +#define %KEYBOARD_UPPERCASE%_H + +#include "quantum.h" + +// This a shortcut to help you visually see your layout. +// The following is an example using the Planck MIT layout +// The first section contains all of the arguments +// The second converts the arguments into a two-dimensional array +#define LAYOUT( \ + k00, k01, k02, \ + k10, k11 \ +) \ +{ \ + { k00, k01, k02 }, \ + { k10, KC_NO, k11 }, \ +} + +#endif diff --git a/quantum/template/ps2avrgb/usbconfig.h b/quantum/template/ps2avrgb/usbconfig.h new file mode 100644 index 0000000000..d2d848fcdc --- /dev/null +++ b/quantum/template/ps2avrgb/usbconfig.h @@ -0,0 +1,396 @@ +/* Name: usbconfig.h + * Project: V-USB, virtual USB port for Atmel's(r) AVR(r) microcontrollers + * Author: Christian Starkjohann + * Creation Date: 2005-04-01 + * Tabsize: 4 + * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH + * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt) + * This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $ + */ + +#ifndef __usbconfig_h_included__ +#define __usbconfig_h_included__ + +#include "config.h" + +/* +General Description: +This file is an example configuration (with inline documentation) for the USB +driver. It configures V-USB for USB D+ connected to Port D bit 2 (which is +also hardware interrupt 0 on many devices) and USB D- to Port D bit 4. You may +wire the lines to any other port, as long as D+ is also wired to INT0 (or any +other hardware interrupt, as long as it is the highest level interrupt, see +section at the end of this file). +*/ + +/* ---------------------------- Hardware Config ---------------------------- */ + +#define USB_CFG_IOPORTNAME D +/* This is the port where the USB bus is connected. When you configure it to + * "B", the registers PORTB, PINB and DDRB will be used. + */ +#define USB_CFG_DMINUS_BIT 3 +/* This is the bit number in USB_CFG_IOPORT where the USB D- line is connected. + * This may be any bit in the port. + */ +#define USB_CFG_DPLUS_BIT 2 +/* This is the bit number in USB_CFG_IOPORT where the USB D+ line is connected. + * This may be any bit in the port. Please note that D+ must also be connected + * to interrupt pin INT0! [You can also use other interrupts, see section + * "Optional MCU Description" below, or you can connect D- to the interrupt, as + * it is required if you use the USB_COUNT_SOF feature. If you use D- for the + * interrupt, the USB interrupt will also be triggered at Start-Of-Frame + * markers every millisecond.] + */ +#define USB_CFG_CLOCK_KHZ (F_CPU/1000) +/* Clock rate of the AVR in kHz. Legal values are 12000, 12800, 15000, 16000, + * 16500, 18000 and 20000. The 12.8 MHz and 16.5 MHz versions of the code + * require no crystal, they tolerate +/- 1% deviation from the nominal + * frequency. All other rates require a precision of 2000 ppm and thus a + * crystal! + * Since F_CPU should be defined to your actual clock rate anyway, you should + * not need to modify this setting. + */ +#define USB_CFG_CHECK_CRC 0 +/* Define this to 1 if you want that the driver checks integrity of incoming + * data packets (CRC checks). CRC checks cost quite a bit of code size and are + * currently only available for 18 MHz crystal clock. You must choose + * USB_CFG_CLOCK_KHZ = 18000 if you enable this option. + */ + +/* ----------------------- Optional Hardware Config ------------------------ */ + +/* #define USB_CFG_PULLUP_IOPORTNAME D */ +/* If you connect the 1.5k pullup resistor from D- to a port pin instead of + * V+, you can connect and disconnect the device from firmware by calling + * the macros usbDeviceConnect() and usbDeviceDisconnect() (see usbdrv.h). + * This constant defines the port on which the pullup resistor is connected. + */ +/* #define USB_CFG_PULLUP_BIT 4 */ +/* This constant defines the bit number in USB_CFG_PULLUP_IOPORT (defined + * above) where the 1.5k pullup resistor is connected. See description + * above for details. + */ + +/* --------------------------- Functional Range ---------------------------- */ + +#de |