aboutsummaryrefslogtreecommitdiff
path: root/keyboards/percent
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/percent')
-rw-r--r--keyboards/percent/canoe/canoe.c92
-rw-r--r--keyboards/percent/canoe/i2c.c106
-rw-r--r--keyboards/percent/canoe/i2c.h27
-rw-r--r--keyboards/percent/canoe/rules.mk21
-rw-r--r--keyboards/percent/skog/i2c.c106
-rw-r--r--keyboards/percent/skog/i2c.h25
-rw-r--r--keyboards/percent/skog/rules.mk19
-rw-r--r--keyboards/percent/skog/skog.c66
8 files changed, 40 insertions, 422 deletions
diff --git a/keyboards/percent/canoe/canoe.c b/keyboards/percent/canoe/canoe.c
index a7427e152..e59b0dd7b 100644
--- a/keyboards/percent/canoe/canoe.c
+++ b/keyboards/percent/canoe/canoe.c
@@ -16,81 +16,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include "canoe.h" 18#include "canoe.h"
19#ifdef BACKLIGHT_ENABLE 19
20#include "backlight.h" 20void matrix_init_kb(void) { matrix_init_user(); }
21#endif 21
22#ifdef RGBLIGHT_ENABLE 22__attribute__ ((weak))
23#include "i2c.h" 23void matrix_init_user(void) {}
24#include "rgblight.h" 24
25#endif 25void matrix_scan_kb(void) { matrix_scan_user(); }
26
27__attribute__ ((weak))
28void matrix_scan_user(void) {}
26 29
27#ifdef BACKLIGHT_ENABLE 30#ifdef BACKLIGHT_ENABLE
28void backlight_set(uint8_t level) { 31void backlight_set(uint8_t level) {
29 if (level == 0) { 32 if (level == 0) {
30 // Turn out the lights 33 // Turn out the lights
31 PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); 34 writePinLow(D0);
35 writePinLow(D1);
36 writePinLow(D4);
37 writePinLow(D6);
32 } else { 38 } else {
33 // Turn on the lights 39 // Turn on the lights
34 PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); 40 writePinHigh(D0);
41 writePinHigh(D1);
42 writePinHigh(D4);
43 writePinHigh(D6);
35 } 44 }
36} 45}
37 46
38void backlight_init_ports(void) { 47void backlight_init_ports(void) {
39 DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); 48 setPinOutput(D0);
40 PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); 49 setPinOutput(D1);
41} 50 setPinOutput(D4);
42 51 setPinOutput(D6);
43#endif 52
44 53 writePinLow(D0);
45// for keyboard subdirectory level init functions 54 writePinLow(D1);
46// @Override 55 writePinLow(D4);
47void matrix_init_kb(void) { 56 writePinLow(D6);
48 // call user level keymaps, if any
49 matrix_init_user();
50}
51
52#ifdef RGBLIGHT_ENABLE
53extern rgblight_config_t rgblight_config;
54
55// custom RGB driver
56void rgblight_set(void) {
57 if (!rgblight_config.enable) {
58 for (uint8_t i=0; i<RGBLED_NUM; i++) {
59 led[i].r = 0;
60 led[i].g = 0;
61 led[i].b = 0;
62 }
63 }
64
65 i2c_init();
66 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
67} 57}
68
69bool rgb_init = false;
70
71void matrix_scan_kb(void) {
72 // if LEDs were previously on before poweroff, turn them back on
73 if (rgb_init == false && rgblight_config.enable) {
74 i2c_init();
75 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
76 rgb_init = true;
77 }
78
79 rgblight_task();
80#else
81void matrix_scan_kb(void) {
82#endif 58#endif
83 matrix_scan_user();
84 /* Nothing else for now. */
85}
86
87__attribute__((weak)) // overridable
88void matrix_init_user(void) {
89
90}
91
92
93__attribute__((weak)) // overridable
94void matrix_scan_user(void) {
95
96}
diff --git a/keyboards/percent/canoe/i2c.c b/keyboards/percent/canoe/i2c.c
deleted file mode 100644
index a4f952135..000000000
--- a/keyboards/percent/canoe/i2c.c
+++ /dev/null
@@ -1,106 +0,0 @@
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// Please do not modify this file
19
20#include <avr/io.h>
21#include <util/twi.h>
22
23#include "i2c.h"
24
25void i2c_set_bitrate(uint16_t bitrate_khz) {
26 uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
27 if (bitrate_div >= 16) {
28 bitrate_div = (bitrate_div - 16) / 2;
29 }
30 TWBR = bitrate_div;
31}
32
33void i2c_init(void) {
34 // set pull-up resistors on I2C bus pins
35 PORTC |= 0b11;
36
37 i2c_set_bitrate(400);
38
39 // enable TWI (two-wire interface)
40 TWCR |= (1 << TWEN);
41
42 // enable TWI interrupt and slave address ACK
43 TWCR |= (1 << TWIE);
44 TWCR |= (1 << TWEA);
45}
46
47uint8_t i2c_start(uint8_t address) {
48 // reset TWI control register
49 TWCR = 0;
50
51 // begin transmission and wait for it to end
52 TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
53 while (!(TWCR & (1<<TWINT)));
54
55 // check if the start condition was successfully transmitted
56 if ((TWSR & 0xF8) != TW_START) {
57 return 1;
58 }
59
60 // transmit address and wait
61 TWDR = address;
62 TWCR = (1<<TWINT) | (1<<TWEN);
63 while (!(TWCR & (1<<TWINT)));
64
65 // check if the device has acknowledged the READ / WRITE mode
66 uint8_t twst = TW_STATUS & 0xF8;
67 if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
68 return 1;
69 }
70
71 return 0;
72}
73
74void i2c_stop(void) {
75 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
76}
77
78uint8_t i2c_write(uint8_t data) {
79 TWDR = data;
80
81 // transmit data and wait
82 TWCR = (1<<TWINT) | (1<<TWEN);
83 while (!(TWCR & (1<<TWINT)));
84
85 if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
86 return 1;
87 }
88
89 return 0;
90}
91
92uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
93 if (i2c_start(address)) {
94 return 1;
95 }
96
97 for (uint16_t i = 0; i < length; i++) {
98 if (i2c_write(data[i])) {
99 return 1;
100 }
101 }
102
103 i2c_stop();
104
105 return 0;
106}
diff --git a/keyboards/percent/canoe/i2c.h b/keyboards/percent/canoe/i2c.h
deleted file mode 100644
index 93a69c94d..000000000
--- a/keyboards/percent/canoe/i2c.h
+++ /dev/null
@@ -1,27 +0,0 @@
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// Please do not modify this file
19
20#ifndef __I2C_H__
21#define __I2C_H__
22
23void i2c_init(void);
24void i2c_set_bitrate(uint16_t bitrate_khz);
25uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
26
27#endif
diff --git a/keyboards/percent/canoe/rules.mk b/keyboards/percent/canoe/rules.mk
index e3269b94d..bb14269a2 100644
--- a/keyboards/percent/canoe/rules.mk
+++ b/keyboards/percent/canoe/rules.mk
@@ -1,18 +1,3 @@
1# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# MCU name 1# MCU name
17MCU = atmega32a 2MCU = atmega32a
18 3
@@ -34,12 +19,12 @@ CONSOLE_ENABLE = yes
34COMMAND_ENABLE = yes 19COMMAND_ENABLE = yes
35BACKLIGHT_ENABLE = no 20BACKLIGHT_ENABLE = no
36RGBLIGHT_ENABLE = yes 21RGBLIGHT_ENABLE = yes
37RGBLIGHT_CUSTOM_DRIVER = yes 22WS2812_DRIVER = i2c
38 23
39OPT_DEFS = -DDEBUG_LEVEL=0 24OPT_DEFS = -DDEBUG_LEVEL=0
40 25
41# custom matrix setup 26# custom matrix setup
42CUSTOM_MATRIX = yes 27CUSTOM_MATRIX = yes
43SRC = matrix.c i2c.c 28SRC = matrix.c
44 29
45LAYOUTS = 65_ansi_blocker \ No newline at end of file 30LAYOUTS = 65_ansi_blocker
diff --git a/keyboards/percent/skog/i2c.c b/keyboards/percent/skog/i2c.c
deleted file mode 100644
index a4f952135..000000000
--- a/keyboards/percent/skog/i2c.c
+++ /dev/null
@@ -1,106 +0,0 @@
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// Please do not modify this file
19
20#include <avr/io.h>
21#include <util/twi.h>
22
23#include "i2c.h"
24
25void i2c_set_bitrate(uint16_t bitrate_khz) {
26 uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
27 if (bitrate_div >= 16) {
28 bitrate_div = (bitrate_div - 16) / 2;
29 }
30 TWBR = bitrate_div;
31}
32
33void i2c_init(void) {
34 // set pull-up resistors on I2C bus pins
35 PORTC |= 0b11;
36
37 i2c_set_bitrate(400);
38
39 // enable TWI (two-wire interface)
40 TWCR |= (1 << TWEN);
41
42 // enable TWI interrupt and slave address ACK
43 TWCR |= (1 << TWIE);
44 TWCR |= (1 << TWEA);
45}
46
47uint8_t i2c_start(uint8_t address) {
48 // reset TWI control register
49 TWCR = 0;
50
51 // begin transmission and wait for it to end
52 TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
53 while (!(TWCR & (1<<TWINT)));
54
55 // check if the start condition was successfully transmitted
56 if ((TWSR & 0xF8) != TW_START) {
57 return 1;
58 }
59
60 // transmit address and wait
61 TWDR = address;
62 TWCR = (1<<TWINT) | (1<<TWEN);
63 while (!(TWCR & (1<<TWINT)));
64
65 // check if the device has acknowledged the READ / WRITE mode
66 uint8_t twst = TW_STATUS & 0xF8;
67 if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
68 return 1;
69 }
70
71 return 0;
72}
73
74void i2c_stop(void) {
75 TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
76}
77
78uint8_t i2c_write(uint8_t data) {
79 TWDR = data;
80
81 // transmit data and wait
82 TWCR = (1<<TWINT) | (1<<TWEN);
83 while (!(TWCR & (1<<TWINT)));
84
85 if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
86 return 1;
87 }
88
89 return 0;
90}
91
92uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
93 if (i2c_start(address)) {
94 return 1;
95 }
96
97 for (uint16_t i = 0; i < length; i++) {
98 if (i2c_write(data[i])) {
99 return 1;
100 }
101 }
102
103 i2c_stop();
104
105 return 0;
106}
diff --git a/keyboards/percent/skog/i2c.h b/keyboards/percent/skog/i2c.h
deleted file mode 100644
index ada8cc7bf..000000000
--- a/keyboards/percent/skog/i2c.h
+++ /dev/null
@@ -1,25 +0,0 @@
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// Please do not modify this file
19
20#pragma once
21
22void i2c_init(void);
23void i2c_set_bitrate(uint16_t bitrate_khz);
24uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
25
diff --git a/keyboards/percent/skog/rules.mk b/keyboards/percent/skog/rules.mk
index b8439906b..2b0c1154d 100644
--- a/keyboards/percent/skog/rules.mk
+++ b/keyboards/percent/skog/rules.mk
@@ -1,18 +1,3 @@
1# Copyright 2018 Jumail Mundekkat / MxBlue
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 2 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# MCU name 1# MCU name
17MCU = atmega32a 2MCU = atmega32a
18 3
@@ -34,9 +19,9 @@ CONSOLE_ENABLE = yes
34COMMAND_ENABLE = yes 19COMMAND_ENABLE = yes
35BACKLIGHT_ENABLE = yes 20BACKLIGHT_ENABLE = yes
36RGBLIGHT_ENABLE = yes 21RGBLIGHT_ENABLE = yes
22WS2812_DRIVER = i2c
37 23
38BACKLIGHT_CUSTOM_DRIVER = yes 24BACKLIGHT_CUSTOM_DRIVER = yes
39RGBLIGHT_CUSTOM_DRIVER = yes
40 25
41OPT_DEFS = -DDEBUG_LEVEL=0 26OPT_DEFS = -DDEBUG_LEVEL=0
42 27
@@ -45,4 +30,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
45 30
46# custom matrix setup 31# custom matrix setup
47CUSTOM_MATRIX = yes 32CUSTOM_MATRIX = yes
48SRC = matrix.c i2c.c backlight.c 33SRC = matrix.c backlight.c
diff --git a/keyboards/percent/skog/skog.c b/keyboards/percent/skog/skog.c
index 3d1eb0e1a..8678d483a 100644
--- a/keyboards/percent/skog/skog.c
+++ b/keyboards/percent/skog/skog.c
@@ -19,23 +19,18 @@ ps2avrGB support code by Kenneth A. (bminiex/.[ch])
19 19
20#include "skog.h" 20#include "skog.h"
21 21
22#include "rgblight.h" 22#include "backlight.h"
23#include "backlight_custom.h"
23 24
24#include <avr/pgmspace.h> 25void matrix_init_kb(void) { matrix_init_user(); }
25 26
26#include "action_layer.h" 27__attribute__ ((weak))
27#include "i2c.h" 28void matrix_init_user(void) {}
28#include "quantum.h"
29 29
30#include "backlight.h" 30void matrix_scan_kb(void) { matrix_scan_user(); }
31#include "backlight_custom.h"
32 31
33// for keyboard subdirectory level init functions 32__attribute__ ((weak))
34// @Override 33void matrix_scan_user(void) {}
35void matrix_init_kb(void) {
36 // call user level keymaps, if any
37 matrix_init_user();
38}
39 34
40#ifdef BACKLIGHT_ENABLE 35#ifdef BACKLIGHT_ENABLE
41/// Overrides functions in `quantum.c` 36/// Overrides functions in `quantum.c`
@@ -51,48 +46,3 @@ void backlight_set(uint8_t level) {
51 b_led_set(level); 46 b_led_set(level);
52} 47}
53#endif 48#endif
54
55#ifdef RGBLIGHT_ENABLE
56extern rgblight_config_t rgblight_config;
57
58// custom RGB driver
59void rgblight_set(void) {
60 if (!rgblight_config.enable) {
61 for (uint8_t i=0; i<RGBLED_NUM; i++) {
62 led[i].r = 0;
63 led[i].g = 0;
64 led[i].b = 0;
65 }
66 }
67
68 i2c_init();
69 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
70}
71
72bool rgb_init = false;
73
74void matrix_scan_kb(void) {
75 // if LEDs were previously on before poweroff, turn them back on
76 if (rgb_init == false && rgblight_config.enable) {
77 i2c_init();
78 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
79 rgb_init = true;
80 }
81
82 rgblight_task();
83#else
84void matrix_scan_kb(void) {
85#endif
86 matrix_scan_user();
87 /* Nothing else for now. */
88}
89
90__attribute__((weak)) // overridable
91void matrix_init_user(void) {
92
93}
94
95__attribute__((weak)) // overridable
96void matrix_scan_user(void) {
97
98}