aboutsummaryrefslogtreecommitdiff
path: root/keyboards/jj50
diff options
context:
space:
mode:
authorfauxpark <fauxpark@gmail.com>2019-11-04 09:43:13 +1100
committerDrashna Jaelre <drashna@live.com>2019-11-03 14:43:13 -0800
commit3a215195ed3a12464df7169e7b68bfe0763e95b1 (patch)
tree914eb8dadc62958633a862a8f25870b7a98fd4cc /keyboards/jj50
parenta4d138645fdb5043cd76bc135eea48453cc50dff (diff)
downloadqmk_firmware-3a215195ed3a12464df7169e7b68bfe0763e95b1.tar.gz
qmk_firmware-3a215195ed3a12464df7169e7b68bfe0763e95b1.zip
Convert remaining PS2AVRGB boards to I2C WS2812 driver (#7245)
* Convert remaining PS2AVRGB boards to I2C WS2812 driver * Add back functions to make the custom matrices happy
Diffstat (limited to 'keyboards/jj50')
-rw-r--r--keyboards/jj50/i2c.c104
-rw-r--r--keyboards/jj50/i2c.h25
-rw-r--r--keyboards/jj50/jj50.c67
-rw-r--r--keyboards/jj50/rules.mk24
4 files changed, 11 insertions, 209 deletions
diff --git a/keyboards/jj50/i2c.c b/keyboards/jj50/i2c.c
deleted file mode 100644
index c27f3e3d1..000000000
--- a/keyboards/jj50/i2c.c
+++ /dev/null
@@ -1,104 +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#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/jj50/i2c.h b/keyboards/jj50/i2c.h
deleted file mode 100644
index 27c9d3d05..000000000
--- a/keyboards/jj50/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#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/jj50/jj50.c b/keyboards/jj50/jj50.c
index d4a70f68d..7c3cee95d 100644
--- a/keyboards/jj50/jj50.c
+++ b/keyboards/jj50/jj50.c
@@ -17,24 +17,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18#include "jj50.h" 18#include "jj50.h"
19 19
20#include <avr/pgmspace.h>
21
22#include "action_layer.h"
23#include "i2c.h"
24#include "quantum.h"
25
26#include "backlight.h" 20#include "backlight.h"
27#include "backlight_custom.h" 21#include "backlight_custom.h"
28 22
29// for keyboard subdirectory level init functions 23void matrix_init_kb(void) { matrix_init_user(); }
30// @Override 24
31void matrix_init_kb(void) { 25__attribute__ ((weak))
32 // call user level keymaps, if any 26void matrix_init_user(void) {}
33 matrix_init_user(); 27
34} 28void matrix_scan_kb(void) { matrix_scan_user(); }
29
30__attribute__ ((weak))
31void matrix_scan_user(void) {}
35 32
36#ifdef BACKLIGHT_ENABLE 33#ifdef BACKLIGHT_ENABLE
37/// Overrides functions in `quantum.c`
38void backlight_init_ports(void) { 34void backlight_init_ports(void) {
39 b_led_init_ports(); 35 b_led_init_ports();
40} 36}
@@ -47,48 +43,3 @@ void backlight_set(uint8_t level) {
47 b_led_set(level); 43 b_led_set(level);
48} 44}
49#endif 45#endif
50
51#ifdef RGBLIGHT_ENABLE
52extern rgblight_config_t rgblight_config;
53
54// custom RGB driver
55void rgblight_set(void) {
56 if (!rgblight_config.enable) {
57 for (uint8_t i=0; i<RGBLED_NUM; i++) {
58 led[i].r = 0;
59 led[i].g = 0;
60 led[i].b = 0;
61 }
62 }
63
64 i2c_init();
65 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
66}
67
68bool rgb_init = false;
69
70void matrix_scan_kb(void) {
71 // if LEDs were previously on before poweroff, turn them back on
72 if (rgb_init == false && rgblight_config.enable) {
73 i2c_init();
74 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
75 rgb_init = true;
76 }
77
78 rgblight_task();
79#else
80 void matrix_scan_kb(void) {
81#endif
82 matrix_scan_user();
83 /* Nothing else for now. */
84 }
85
86 __attribute__((weak)) // overridable
87 void matrix_init_user(void) {
88
89 }
90
91 __attribute__((weak)) // overridable
92 void matrix_scan_user(void) {
93
94 }
diff --git a/keyboards/jj50/rules.mk b/keyboards/jj50/rules.mk
index b23b4becd..40473e6ec 100644
--- a/keyboards/jj50/rules.mk
+++ b/keyboards/jj50/rules.mk
@@ -1,19 +1,3 @@
1# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
2# Modified 2018 Wayne Jones (WarmCatUK) <waynekjones@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# MCU name 1# MCU name
18MCU = atmega32a 2MCU = atmega32a
19 3
@@ -35,22 +19,18 @@ CONSOLE_ENABLE = no
35COMMAND_ENABLE = yes 19COMMAND_ENABLE = yes
36BACKLIGHT_ENABLE = yes 20BACKLIGHT_ENABLE = yes
37RGBLIGHT_ENABLE = yes 21RGBLIGHT_ENABLE = yes
38RGBLIGHT_CUSTOM_DRIVER = yes 22WS2812_DRIVER = i2c
39NKRO_ENABLE = no 23NKRO_ENABLE = no
40# Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work 24# Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
41 25
42
43DISABLE_WS2812 = no
44
45KEY_LOCK_ENABLE = yes 26KEY_LOCK_ENABLE = yes
46# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE 27# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
47SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend 28SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
48 29
49
50#OPT_DEFS = -DDEBUG_LEVEL=0 30#OPT_DEFS = -DDEBUG_LEVEL=0
51 31
52# custom matrix setup 32# custom matrix setup
53CUSTOM_MATRIX = yes 33CUSTOM_MATRIX = yes
54SRC = matrix.c i2c.c backlight.c 34SRC = matrix.c backlight.c
55 35
56LAYOUTS = ortho_5x12 36LAYOUTS = ortho_5x12