aboutsummaryrefslogtreecommitdiff
path: root/keyboards/mehkee96
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/mehkee96
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/mehkee96')
-rw-r--r--keyboards/mehkee96/i2c.c106
-rw-r--r--keyboards/mehkee96/i2c.h27
-rw-r--r--keyboards/mehkee96/mehkee96.c65
-rw-r--r--keyboards/mehkee96/rules.mk4
4 files changed, 8 insertions, 194 deletions
diff --git a/keyboards/mehkee96/i2c.c b/keyboards/mehkee96/i2c.c
deleted file mode 100644
index a4f952135..000000000
--- a/keyboards/mehkee96/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/mehkee96/i2c.h b/keyboards/mehkee96/i2c.h
deleted file mode 100644
index 7ce50cdb5..000000000
--- a/keyboards/mehkee96/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/mehkee96/mehkee96.c b/keyboards/mehkee96/mehkee96.c
index 604fad803..46427ec93 100644
--- a/keyboards/mehkee96/mehkee96.c
+++ b/keyboards/mehkee96/mehkee96.c
@@ -16,66 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include "mehkee96.h" 18#include "mehkee96.h"
19#include "rgblight.h"
20 19
21#include <avr/pgmspace.h> 20void matrix_init_kb(void) { matrix_init_user(); }
22 21
23#include "action_layer.h" 22__attribute__ ((weak))
24#include "i2c.h" 23void matrix_init_user(void) {}
25#include "quantum.h"
26 24
27// for keyboard subdirectory level init functions 25void matrix_scan_kb(void) { matrix_scan_user(); }
28// @Override
29void matrix_init_kb(void) {
30 // call user level keymaps, if any
31 matrix_init_user();
32}
33 26
34#ifdef RGBLIGHT_ENABLE 27__attribute__ ((weak))
35extern rgblight_config_t rgblight_config; 28void matrix_scan_user(void) {}
36
37// custom RGB driver
38void rgblight_set(void) {
39 if (!rgblight_config.enable) {
40 for (uint8_t i=0; i<RGBLED_NUM; i++) {
41 led[i].r = 0;
42 led[i].g = 0;
43 led[i].b = 0;
44 }
45 }
46
47 i2c_init();
48 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
49}
50
51bool rgb_init = false;
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) {
56 i2c_init();
57 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
58 rgb_init = true;
59 }
60
61#ifdef RGBLIGHT_ANIMATION
62 rgblight_task();
63#endif
64
65#else
66void matrix_scan_kb(void) {
67#endif
68 matrix_scan_user();
69 /* Nothing else for now. */
70}
71
72__attribute__((weak)) // overridable
73void matrix_init_user(void) {
74
75}
76
77
78__attribute__((weak)) // overridable
79void matrix_scan_user(void) {
80
81}
diff --git a/keyboards/mehkee96/rules.mk b/keyboards/mehkee96/rules.mk
index 244dd2141..1cbd02948 100644
--- a/keyboards/mehkee96/rules.mk
+++ b/keyboards/mehkee96/rules.mk
@@ -21,10 +21,10 @@ CONSOLE_ENABLE = yes # Console for debug(+400)
21COMMAND_ENABLE = yes # Commands for debug and configuration 21COMMAND_ENABLE = yes # Commands for debug and configuration
22BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality 22BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
23RGBLIGHT_ENABLE = yes 23RGBLIGHT_ENABLE = yes
24RGBLIGHT_CUSTOM_DRIVER = yes 24WS2812_DRIVER = i2c
25 25
26OPT_DEFS = -DDEBUG_LEVEL=0 26OPT_DEFS = -DDEBUG_LEVEL=0
27 27
28# custom matrix setup 28# custom matrix setup
29CUSTOM_MATRIX = yes 29CUSTOM_MATRIX = yes
30SRC = matrix.c i2c.c 30SRC = matrix.c