aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2017-09-15 21:44:39 -0400
committerJack Humbert <jack.humb@gmail.com>2017-09-15 21:44:39 -0400
commit5ad5c230d6cf9f90a8337ec54dee8b14e332d3c6 (patch)
treeac6e6b0417e3c6550e6c8e07f615fabdc74b1ef1
parentafcf3a2878d5b5de0f9daba201ab44d779a8b2b1 (diff)
parentdc7d0c7b7442b87600352e083e3da4a08cb2d069 (diff)
downloadqmk_firmware-5ad5c230d6cf9f90a8337ec54dee8b14e332d3c6.tar.gz
qmk_firmware-5ad5c230d6cf9f90a8337ec54dee8b14e332d3c6.zip
Merge branch 'luizribeiro-ps2avrGB'
-rw-r--r--common_features.mk7
-rw-r--r--drivers/avr/ws2812.h18
-rw-r--r--keyboards/ps2avrGB/config.h3
-rw-r--r--keyboards/ps2avrGB/i2c.c104
-rw-r--r--keyboards/ps2avrGB/i2c.h25
-rw-r--r--keyboards/ps2avrGB/keymaps/default/keymap.c27
-rw-r--r--keyboards/ps2avrGB/matrix.c2
-rw-r--r--keyboards/ps2avrGB/ps2avrGB.c45
-rw-r--r--keyboards/ps2avrGB/ps2avrGB.h1
-rw-r--r--keyboards/ps2avrGB/rules.mk6
-rw-r--r--quantum/rgblight.c3
-rw-r--r--quantum/rgblight.h3
-rw-r--r--quantum/rgblight_types.h45
13 files changed, 259 insertions, 30 deletions
diff --git a/common_features.mk b/common_features.mk
index d499d1f0b..6f29c97c9 100644
--- a/common_features.mk
+++ b/common_features.mk
@@ -93,10 +93,13 @@ endif
93 93
94ifeq ($(strip $(RGBLIGHT_ENABLE)), yes) 94ifeq ($(strip $(RGBLIGHT_ENABLE)), yes)
95 OPT_DEFS += -DRGBLIGHT_ENABLE 95 OPT_DEFS += -DRGBLIGHT_ENABLE
96 SRC += ws2812.c
97 SRC += $(QUANTUM_DIR)/rgblight.c
98 CIE1931_CURVE = yes 96 CIE1931_CURVE = yes
99 LED_BREATHING_TABLE = yes 97 LED_BREATHING_TABLE = yes
98 ifeq ($(strip $(RGBLIGHT_CUSTOM_DRIVER)), yes)
99 OPT_DEFS += -DRGBLIGHT_CUSTOM_DRIVER
100 else
101 SRC += ws2812.c
102 endif
100endif 103endif
101 104
102ifeq ($(strip $(TAP_DANCE_ENABLE)), yes) 105ifeq ($(strip $(TAP_DANCE_ENABLE)), yes)
diff --git a/drivers/avr/ws2812.h b/drivers/avr/ws2812.h
index 60924a0fb..f7e0c3144 100644
--- a/drivers/avr/ws2812.h
+++ b/drivers/avr/ws2812.h
@@ -28,23 +28,7 @@
28//#include "ws2812_config.h" 28//#include "ws2812_config.h"
29//#include "i2cmaster.h" 29//#include "i2cmaster.h"
30 30
31#ifdef RGBW 31#include "rgblight_types.h"
32 #define LED_TYPE struct cRGBW
33#else
34 #define LED_TYPE struct cRGB
35#endif
36
37
38/*
39 * Structure of the LED array
40 *
41 * cRGB: RGB for WS2812S/B/C/D, SK6812, SK6812Mini, SK6812WWA, APA104, APA106
42 * cRGBW: RGBW for SK6812RGBW
43 */
44
45struct cRGB { uint8_t g; uint8_t r; uint8_t b; };
46struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;};
47
48 32
49 33
50/* User Interface 34/* User Interface
diff --git a/keyboards/ps2avrGB/config.h b/keyboards/ps2avrGB/config.h
index b5c696f3f..fc17b5d5e 100644
--- a/keyboards/ps2avrGB/config.h
+++ b/keyboards/ps2avrGB/config.h
@@ -29,6 +29,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
29#define MATRIX_ROWS 8 29#define MATRIX_ROWS 8
30#define MATRIX_COLS 15 30#define MATRIX_COLS 15
31 31
32#define RGBLED_NUM 16
33#define RGBLIGHT_ANIMATIONS
34
32#define NO_UART 1 35#define NO_UART 1
33#define BOOTLOADHID_BOOTLOADER 1 36#define BOOTLOADHID_BOOTLOADER 1
34 37
diff --git a/keyboards/ps2avrGB/i2c.c b/keyboards/ps2avrGB/i2c.c
new file mode 100644
index 000000000..c27f3e3d1
--- /dev/null
+++ b/keyboards/ps2avrGB/i2c.c
@@ -0,0 +1,104 @@
1/*
2Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include <avr/io.h>
19#include <util/twi.h>
20
21#include "i2c.h"
22
23void i2c_set_bitrate(uint16_t bitrate_khz) {
24 uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
25 if (bitrate_div >= 16) {
26 bitrate_div = (bitrate_div - 16) / 2;
27 }
28 TWBR = bitrate_div;
29}
30
31void i2c_init(void) {
32 // set pull-up resistors on I2C bus pins
33 PORTC |= 0b11;
34
35 i2c_set_bitrate(400);
36
37 // enable TWI (two-wire interface)
38 TWCR |= (1 << TWEN);
39
40 // enable TWI interrupt and slave address ACK
41 TWCR |= (1 << TWIE);
42 TWCR |= (1 << TWEA);
43}
44
45uint8_t i2c_start(uint8_t address) {
46 // reset TWI control register
47 TWCR = 0;
48
49 // begin transmission and wait for it to end
50 TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
51 while (!(TWCR & (1<<TWINT)));
52
53 // check if the start condition was successfully transmitted
54 if ((TWSR & 0xF8) != TW_START) {
55 return 1;
56 }
57
58 // transmit address and wait
59 TWDR = address;
60 TWCR = (1<<TWINT) | (1<<TWEN);
61 while (!(TWCR & (1<<TWINT)));
62
63 // check if the device has acknowledged the READ / WRITE mode
64 uint8_t twst = TW_STATUS & 0xF8;
65 if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
66 return 1;
67 }
68
69 return 0;
70}
71
72void i2c_stop(void) {
73 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
74}
75
76uint8_t i2c_write(uint8_t data) {
77 TWDR = data;
78
79 // transmit data and wait
80 TWCR = (1<<TWINT) | (1<<TWEN);
81 while (!(TWCR & (1<<TWINT)));
82
83 if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
84 return 1;
85 }
86
87 return 0;
88}
89
90uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
91 if (i2c_start(address)) {
92 return 1;
93 }
94
95 for (uint16_t i = 0; i < length; i++) {
96 if (i2c_write(data[i])) {
97 return 1;
98 }
99 }
100
101 i2c_stop();
102
103 return 0;
104}
diff --git a/keyboards/ps2avrGB/i2c.h b/keyboards/ps2avrGB/i2c.h
new file mode 100644
index 000000000..27c9d3d05
--- /dev/null
+++ b/keyboards/ps2avrGB/i2c.h
@@ -0,0 +1,25 @@
1/*
2Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#ifndef __I2C_H__
19#define __I2C_H__
20
21void i2c_init(void);
22void i2c_set_bitrate(uint16_t bitrate_khz);
23uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
24
25#endif
diff --git a/keyboards/ps2avrGB/keymaps/default/keymap.c b/keyboards/ps2avrGB/keymaps/default/keymap.c
index 3e4cebc81..4650ff633 100644
--- a/keyboards/ps2avrGB/keymaps/default/keymap.c
+++ b/keyboards/ps2avrGB/keymaps/default/keymap.c
@@ -16,17 +16,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include "ps2avrGB.h" 18#include "ps2avrGB.h"
19#include "action_layer.h"
20#include "rgblight.h"
19 21
20const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { 22const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
21 KC_KEYMAP( 23 [0] = KEYMAP(
22 ESC, F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, PSCR,HOME,END, 24 KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR,KC_HOME,KC_END,
23 GRV, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, MINS,EQL, BSPC, DEL, 25 KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS,KC_EQL, KC_BSPC, KC_DEL,
24 TAB, Q, W, E, R, T, Y, U, I, O, P, LBRC,RBRC,BSLS, INS, 26 KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC,KC_RBRC,KC_BSLS, KC_INS,
25 CAPS,A, S, D, F, G, H, J, K, L, SCLN,QUOT,ENT, PGUP, 27 KC_FN0, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT,KC_ENT, KC_PGUP,
26 LSFT,Z, X, C, V, B, N, M, COMM,DOT, SLSH,RSFT, UP, PGDN, 28 KC_LSFT,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH,KC_RSFT, KC_UP, KC_PGDN,
27 LCTL,LALT,LGUI, SPC, RGUI,RALT,RCTL,LEFT,DOWN,RGHT 29 KC_LCTL,KC_LALT,KC_LGUI, KC_SPC, KC_RGUI,KC_RALT,KC_RCTL,KC_LEFT,KC_DOWN,KC_RGHT
28 ) 30 ),
31 [1] = KEYMAP(
32 KC_TRNS,RGB_TOG,RGB_MOD,RGB_HUI,RGB_SAI,RGB_VAI,RGB_HUD,RGB_SAD,RGB_VAD,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_END,
33 KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS, KC_DEL,
34 KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS, KC_INS,
35 KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS, KC_TRNS,
36 KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS, KC_TRNS,KC_TRNS,
37 KC_TRNS,KC_TRNS,KC_TRNS, KC_TRNS, KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_TRNS,KC_RGHT
38 ),
29}; 39};
30 40
31const uint16_t PROGMEM fn_actions[] = { 41const uint16_t PROGMEM fn_actions[] = {
42 [0] = ACTION_LAYER_MOMENTARY(1),
32}; 43};
diff --git a/keyboards/ps2avrGB/matrix.c b/keyboards/ps2avrGB/matrix.c
index beaa54c40..140026013 100644
--- a/keyboards/ps2avrGB/matrix.c
+++ b/keyboards/ps2avrGB/matrix.c
@@ -93,6 +93,8 @@ uint8_t matrix_scan(void) {
93 } 93 }
94 } 94 }
95 95
96 matrix_scan_user();
97
96 return 1; 98 return 1;
97} 99}
98 100
diff --git a/keyboards/ps2avrGB/ps2avrGB.c b/keyboards/ps2avrGB/ps2avrGB.c
index e69de29bb..701c5847f 100644
--- a/keyboards/ps2avrGB/ps2avrGB.c
+++ b/keyboards/ps2avrGB/ps2avrGB.c
@@ -0,0 +1,45 @@
1/*
2Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
3
4This program is free software: you can redistribute it and/or modify
5it under the terms of the GNU General Public License as published by
6the Free Software Foundation, either version 2 of the License, or
7(at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12GNU General Public License for more details.
13
14You should have received a copy of the GNU General Public License
15along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/
17
18#include "ps2avrGB.h"
19#include "rgblight.h"
20
21#include <avr/pgmspace.h>
22
23#include "action_layer.h"
24#include "i2c.h"
25#include "quantum.h"
26
27extern rgblight_config_t rgblight_config;
28
29void rgblight_set(void) {
30 if (!rgblight_config.enable) {
31 for (uint8_t i = 0; i < RGBLED_NUM; i++) {
32 led[i].r = 0;
33 led[i].g = 0;
34 led[i].b = 0;
35 }
36 }
37
38 i2c_init();
39 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
40}
41
42__attribute__ ((weak))
43void matrix_scan_user(void) {
44 rgblight_task();
45}
diff --git a/keyboards/ps2avrGB/ps2avrGB.h b/keyboards/ps2avrGB/ps2avrGB.h
index 813f31f80..35902cff4 100644
--- a/keyboards/ps2avrGB/ps2avrGB.h
+++ b/keyboards/ps2avrGB/ps2avrGB.h
@@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18#ifndef KEYMAP_COMMON_H 18#ifndef KEYMAP_COMMON_H
19#define KEYMAP_COMMON_H 19#define KEYMAP_COMMON_H
20 20
21#include "quantum_keycodes.h"
21#include "keycode.h" 22#include "keycode.h"
22#include "action.h" 23#include "action.h"
23 24
diff --git a/keyboards/ps2avrGB/rules.mk b/keyboards/ps2avrGB/rules.mk
index e2b5922ea..9e76993c4 100644
--- a/keyboards/ps2avrGB/rules.mk
+++ b/keyboards/ps2avrGB/rules.mk
@@ -20,7 +20,6 @@ PROTOCOL = VUSB
20# unsupported features for now 20# unsupported features for now
21NO_UART = yes 21NO_UART = yes
22NO_SUSPEND_POWER_DOWN = yes 22NO_SUSPEND_POWER_DOWN = yes
23BACKLIGHT_ENABLE = no
24 23
25# processor frequency 24# processor frequency
26F_CPU = 12000000 25F_CPU = 12000000
@@ -31,13 +30,16 @@ MOUSEKEY_ENABLE = yes
31EXTRAKEY_ENABLE = yes 30EXTRAKEY_ENABLE = yes
32CONSOLE_ENABLE = yes 31CONSOLE_ENABLE = yes
33COMMAND_ENABLE = yes 32COMMAND_ENABLE = yes
33BACKLIGHT_ENABLE = no
34RGBLIGHT_ENABLE = yes
35RGBLIGHT_CUSTOM_DRIVER = yes
34 36
35OPT_DEFS = -DDEBUG_LEVEL=0 37OPT_DEFS = -DDEBUG_LEVEL=0
36OPT_DEFS += -DBOOTLOADER_SIZE=2048 38OPT_DEFS += -DBOOTLOADER_SIZE=2048
37 39
38# custom matrix setup 40# custom matrix setup
39CUSTOM_MATRIX = yes 41CUSTOM_MATRIX = yes
40SRC = matrix.c 42SRC = matrix.c i2c.c
41 43
42# programming options 44# programming options
43PROGRAM_CMD = ./keyboards/ps2avrGB/program $(TARGET).hex 45PROGRAM_CMD = ./keyboards/ps2avrGB/program $(TARGET).hex
diff --git a/quantum/rgblight.c b/quantum/rgblight.c
index 5ae6e69d6..9ac1893d2 100644
--- a/quantum/rgblight.c
+++ b/quantum/rgblight.c
@@ -373,7 +373,7 @@ void rgblight_setrgb(uint8_t r, uint8_t g, uint8_t b) {
373 rgblight_set(); 373 rgblight_set();
374} 374}
375 375
376__attribute__ ((weak)) 376#ifndef RGBLIGHT_CUSTOM_DRIVER
377void rgblight_set(void) { 377void rgblight_set(void) {
378 if (rgblight_config.enable) { 378 if (rgblight_config.enable) {
379 #ifdef RGBW 379 #ifdef RGBW
@@ -394,6 +394,7 @@ void rgblight_set(void) {
394 #endif 394 #endif
395 } 395 }
396} 396}
397#endif
397 398
398#ifdef RGBLIGHT_ANIMATIONS 399#ifdef RGBLIGHT_ANIMATIONS
399 400
diff --git a/quantum/rgblight.h b/quantum/rgblight.h
index 7acd5a257..c1b3378b3 100644
--- a/quantum/rgblight.h
+++ b/quantum/rgblight.h
@@ -62,7 +62,10 @@
62#include <stdint.h> 62#include <stdint.h>
63#include <stdbool.h> 63#include <stdbool.h>
64#include "eeconfig.h" 64#include "eeconfig.h"
65#ifndef RGBLIGHT_CUSTOM_DRIVER
65#include "ws2812.h" 66#include "ws2812.h"
67#endif
68#include "rgblight_types.h"
66 69
67extern LED_TYPE led[RGBLED_NUM]; 70extern LED_TYPE led[RGBLED_NUM];
68 71
diff --git a/quantum/rgblight_types.h b/quantum/rgblight_types.h
new file mode 100644
index 000000000..b1aa7026c
--- /dev/null
+++ b/quantum/rgblight_types.h
@@ -0,0 +1,45 @@
1/*
2 * light weight WS2812 lib include
3 *
4 * Version 2.3 - Nev 29th 2015
5 * Author: Tim (cpldcpu@gmail.com)
6 *
7 * Please do not change this file! All configuration is handled in "ws2812_config.h"
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef RGBLIGHT_TYPES
24#define RGBLIGHT_TYPES
25
26#include <avr/io.h>
27
28#ifdef RGBW
29 #define LED_TYPE struct cRGBW
30#else
31 #define LED_TYPE struct cRGB
32#endif
33
34
35/*
36 * Structure of the LED array
37 *
38 * cRGB: RGB for WS2812S/B/C/D, SK6812, SK6812Mini, SK6812WWA, APA104, APA106
39 * cRGBW: RGBW for SK6812RGBW
40 */
41
42struct cRGB { uint8_t g; uint8_t r; uint8_t b; };
43struct cRGBW { uint8_t g; uint8_t r; uint8_t b; uint8_t w;};
44
45#endif