aboutsummaryrefslogtreecommitdiff
path: root/keyboards/ymd75
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/ymd75
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/ymd75')
-rw-r--r--keyboards/ymd75/i2c.c104
-rw-r--r--keyboards/ymd75/i2c.h25
-rw-r--r--keyboards/ymd75/rules.mk20
-rw-r--r--keyboards/ymd75/ymd75.c67
4 files changed, 11 insertions, 205 deletions
diff --git a/keyboards/ymd75/i2c.c b/keyboards/ymd75/i2c.c
deleted file mode 100644
index c27f3e3d1..000000000
--- a/keyboards/ymd75/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/ymd75/i2c.h b/keyboards/ymd75/i2c.h
deleted file mode 100644
index 27c9d3d05..000000000
--- a/keyboards/ymd75/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/ymd75/rules.mk b/keyboards/ymd75/rules.mk
index 7bee20173..0c1c9110c 100644
--- a/keyboards/ymd75/rules.mk
+++ b/keyboards/ymd75/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,7 +19,7 @@ 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
@@ -51,4 +35,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
51 35
52# custom matrix setup 36# custom matrix setup
53CUSTOM_MATRIX = yes 37CUSTOM_MATRIX = yes
54SRC = matrix.c i2c.c backlight.c 38SRC = matrix.c backlight.c
diff --git a/keyboards/ymd75/ymd75.c b/keyboards/ymd75/ymd75.c
index 2259dfa5f..74f7c6a49 100644
--- a/keyboards/ymd75/ymd75.c
+++ b/keyboards/ymd75/ymd75.c
@@ -16,23 +16,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include "ymd75.h" 18#include "ymd75.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 19
27#include "backlight.h" 20#include "backlight.h"
28#include "backlight_custom.h" 21#include "backlight_custom.h"
29 22
30// for keyboard subdirectory level init functions 23void matrix_init_kb(void) { matrix_init_user(); }
31// @Override 24
32void matrix_init_kb(void) { 25__attribute__ ((weak))
33 // call user level keymaps, if any 26void matrix_init_user(void) {}
34 matrix_init_user(); 27
35} 28void matrix_scan_kb(void) { matrix_scan_user(); }
29
30__attribute__ ((weak))
31void matrix_scan_user(void) {}
36 32
37#ifdef BACKLIGHT_ENABLE 33#ifdef BACKLIGHT_ENABLE
38/// Overrides functions in `quantum.c` 34/// Overrides functions in `quantum.c`
@@ -48,48 +44,3 @@ void backlight_set(uint8_t level) {
48 b_led_set(level); 44 b_led_set(level);
49} 45}
50#endif 46#endif
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}
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
81 void matrix_scan_kb(void) {
82#endif
83 matrix_scan_user();
84 /* Nothing else for now. */
85 }
86
87 __attribute__((weak)) // overridable
88 void matrix_init_user(void) {
89
90 }
91
92 __attribute__((weak)) // overridable
93 void matrix_scan_user(void) {
94
95 }