aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ymd96
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/ymd96
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/ymd96')
-rw-r--r--keyboards/ymd96/i2c.c104
-rw-r--r--keyboards/ymd96/i2c.h25
-rw-r--r--keyboards/ymd96/rules.mk19
-rw-r--r--keyboards/ymd96/ymd96.c66
4 files changed, 10 insertions, 204 deletions
diff --git a/keyboards/ymd96/i2c.c b/keyboards/ymd96/i2c.c
deleted file mode 100644
index c27f3e3d1..000000000
--- a/keyboards/ymd96/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/ymd96/i2c.h b/keyboards/ymd96/i2c.h
deleted file mode 100644
index 27c9d3d05..000000000
--- a/keyboards/ymd96/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/ymd96/rules.mk b/keyboards/ymd96/rules.mk
index 96441e1b3..19d9fd81a 100644
--- a/keyboards/ymd96/rules.mk
+++ b/keyboards/ymd96/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
@@ -37,7 +22,7 @@ BACKLIGHT_ENABLE = yes
37BACKLIGHT_CUSTOM_DRIVER = yes 22BACKLIGHT_CUSTOM_DRIVER = yes
38 23
39RGBLIGHT_ENABLE = yes 24RGBLIGHT_ENABLE = yes
40RGBLIGHT_CUSTOM_DRIVER = yes 25WS2812_DRIVER = i2c
41 26
42KEY_LOCK_ENABLE = yes 27KEY_LOCK_ENABLE = yes
43 28
@@ -48,4 +33,4 @@ OPT_DEFS = -DDEBUG_LEVEL=0
48 33
49# custom matrix setup 34# custom matrix setup
50CUSTOM_MATRIX = yes 35CUSTOM_MATRIX = yes
51SRC = matrix.c i2c.c backlight.c 36SRC = matrix.c backlight.c
diff --git a/keyboards/ymd96/ymd96.c b/keyboards/ymd96/ymd96.c
index b0bf6128f..546a4c6e3 100644
--- a/keyboards/ymd96/ymd96.c
+++ b/keyboards/ymd96/ymd96.c
@@ -18,22 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19#include "ymd96.h" 19#include "ymd96.h"
20 20
21#include <avr/pgmspace.h> 21#include "backlight.h"
22#include "backlight_custom.h"
22 23
23#include "action_layer.h" 24void matrix_init_kb(void) { matrix_init_user(); }
24#include "quantum.h"
25 25
26#include "i2c.h" 26__attribute__ ((weak))
27void matrix_init_user(void) {}
27 28
28#include "backlight.h" 29void matrix_scan_kb(void) { matrix_scan_user(); }
29#include "backlight_custom.h"
30 30
31// for keyboard subdirectory level init functions 31__attribute__ ((weak))
32// @Override 32void matrix_scan_user(void) {}
33void matrix_init_kb(void) {
34 // call user level keymaps, if any
35 matrix_init_user();
36}
37 33
38#ifdef BACKLIGHT_ENABLE 34#ifdef BACKLIGHT_ENABLE
39/// Overrides functions in `quantum.c` 35/// Overrides functions in `quantum.c`
@@ -49,49 +45,3 @@ void backlight_set(uint8_t level) {
49 b_led_set(level); 45 b_led_set(level);
50} 46}
51#endif 47#endif
52
53#ifdef RGBLIGHT_ENABLE
54extern rgblight_config_t rgblight_config;
55
56// custom RGB driver
57void rgblight_set(void) {
58 if (!rgblight_config.enable) {
59 for (uint8_t i=0; i<RGBLED_NUM; i++) {
60 led[i].r = 0;
61 led[i].g = 0;
62 led[i].b = 0;
63 }
64 }
65
66 i2c_init();
67 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
68}
69
70bool rgb_init = false;
71
72void matrix_scan_kb(void) {
73 // if LEDs were previously on before poweroff, turn them back on
74 if (rgb_init == false && rgblight_config.enable) {
75 i2c_init();
76 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
77 rgb_init = true;
78 }
79
80 rgblight_task();
81#else
82void matrix_scan_kb(void) {
83#endif
84 matrix_scan_user();
85 /* Nothing else for now. */
86}
87
88__attribute__((weak)) // overridable
89void matrix_init_user(void) {
90
91}
92
93
94__attribute__((weak)) // overridable
95void matrix_scan_user(void) {
96
97}