aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ps2avrGB
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/ps2avrGB')
-rw-r--r--keyboards/ps2avrGB/matrix.c32
-rw-r--r--keyboards/ps2avrGB/ps2avrGB.c49
2 files changed, 60 insertions, 21 deletions
diff --git a/keyboards/ps2avrGB/matrix.c b/keyboards/ps2avrGB/matrix.c
index 57aa36b5f..245813dfd 100644
--- a/keyboards/ps2avrGB/matrix.c
+++ b/keyboards/ps2avrGB/matrix.c
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
21#include "matrix.h" 21#include "matrix.h"
22 22
23#ifndef DEBOUNCE 23#ifndef DEBOUNCE
24#define DEBOUNCE 5 24# define DEBOUNCE 5
25#endif 25#endif
26 26
27static uint8_t debouncing = DEBOUNCE; 27static uint8_t debouncing = DEBOUNCE;
@@ -29,6 +29,9 @@ static uint8_t debouncing = DEBOUNCE;
29static matrix_row_t matrix[MATRIX_ROWS]; 29static matrix_row_t matrix[MATRIX_ROWS];
30static matrix_row_t matrix_debouncing[MATRIX_ROWS]; 30static matrix_row_t matrix_debouncing[MATRIX_ROWS];
31 31
32void matrix_set_row_status(uint8_t row);
33uint8_t bit_reverse(uint8_t x);
34
32void matrix_init(void) { 35void matrix_init(void) {
33 // all outputs for rows high 36 // all outputs for rows high
34 DDRB = 0xFF; 37 DDRB = 0xFF;
@@ -47,18 +50,8 @@ void matrix_init(void) {
47 matrix[row] = 0x00; 50 matrix[row] = 0x00;
48 matrix_debouncing[row] = 0x00; 51 matrix_debouncing[row] = 0x00;
49 } 52 }
50}
51
52void matrix_set_row_status(uint8_t row) {
53 DDRB = (1 << row);
54 PORTB = ~(1 << row);
55}
56 53
57uint8_t bit_reverse(uint8_t x) { 54 matrix_init_quantum();
58 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
59 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
60 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
61 return x;
62} 55}
63 56
64uint8_t matrix_scan(void) { 57uint8_t matrix_scan(void) {
@@ -93,11 +86,24 @@ uint8_t matrix_scan(void) {
93 } 86 }
94 } 87 }
95 88
96 matrix_scan_user(); 89 matrix_scan_quantum();
97 90
98 return 1; 91 return 1;
99} 92}
100 93
94// declarations
95void matrix_set_row_status(uint8_t row) {
96 DDRB = (1 << row);
97 PORTB = ~(1 << row);
98}
99
100uint8_t bit_reverse(uint8_t x) {
101 x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
102 x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
103 x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
104 return x;
105}
106
101inline matrix_row_t matrix_get_row(uint8_t row) { 107inline matrix_row_t matrix_get_row(uint8_t row) {
102 return matrix[row]; 108 return matrix[row];
103} 109}
diff --git a/keyboards/ps2avrGB/ps2avrGB.c b/keyboards/ps2avrGB/ps2avrGB.c
index 701c5847f..45ba37bff 100644
--- a/keyboards/ps2avrGB/ps2avrGB.c
+++ b/keyboards/ps2avrGB/ps2avrGB.c
@@ -24,22 +24,55 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24#include "i2c.h" 24#include "i2c.h"
25#include "quantum.h" 25#include "quantum.h"
26 26
27// for keyboard subdirectory level init functions
28// @Override
29void matrix_init_kb(void) {
30 // call user level keymaps, if any
31 matrix_init_user();
32}
33
34#ifdef RGBLIGHT_ENABLE
27extern rgblight_config_t rgblight_config; 35extern rgblight_config_t rgblight_config;
28 36
37// custom RGB driver
29void rgblight_set(void) { 38void rgblight_set(void) {
30 if (!rgblight_config.enable) { 39 if (!rgblight_config.enable) {
31 for (uint8_t i = 0; i < RGBLED_NUM; i++) { 40 for (uint8_t i=0; i<RGBLED_NUM; i++) {
32 led[i].r = 0; 41 led[i].r = 0;
33 led[i].g = 0; 42 led[i].g = 0;
34 led[i].b = 0; 43 led[i].b = 0;
35 }
36 } 44 }
45 }
46
47 i2c_init();
48 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
49}
50
51bool rgb_init = false;
37 52
53void matrix_scan_kb(void) {
54 // if LEDs were previously on before poweroff, turn them back on
55 if (rgb_init == false && rgblight_config.enable) {
38 i2c_init(); 56 i2c_init();
39 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM); 57 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
58 rgb_init = true;
59 }
60
61 rgblight_task();
62#else
63void matrix_scan_kb(void) {
64#endif
65 matrix_scan_user();
66 /* Nothing else for now. */
40} 67}
41 68
42__attribute__ ((weak)) 69__attribute__((weak)) // overridable
70void matrix_init_user(void) {
71
72}
73
74
75__attribute__((weak)) // overridable
43void matrix_scan_user(void) { 76void matrix_scan_user(void) {
44 rgblight_task(); 77
45} 78}