aboutsummaryrefslogtreecommitdiff
path: root/keyboards/jc65
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/jc65
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/jc65')
-rw-r--r--keyboards/jc65/v32a/i2c.c106
-rw-r--r--keyboards/jc65/v32a/i2c.h27
-rw-r--r--keyboards/jc65/v32a/rules.mk19
-rw-r--r--keyboards/jc65/v32a/v32a.c56
4 files changed, 20 insertions, 188 deletions
diff --git a/keyboards/jc65/v32a/i2c.c b/keyboards/jc65/v32a/i2c.c
deleted file mode 100644
index a4f952135..000000000
--- a/keyboards/jc65/v32a/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/jc65/v32a/i2c.h b/keyboards/jc65/v32a/i2c.h
deleted file mode 100644
index 93a69c94d..000000000
--- a/keyboards/jc65/v32a/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/jc65/v32a/rules.mk b/keyboards/jc65/v32a/rules.mk
index ee6efb3fa..18e7f1de9 100644
--- a/keyboards/jc65/v32a/rules.mk
+++ b/keyboards/jc65/v32a/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,10 +19,10 @@ CONSOLE_ENABLE = yes
34COMMAND_ENABLE = yes 19COMMAND_ENABLE = yes
35BACKLIGHT_ENABLE = yes 20BACKLIGHT_ENABLE = yes
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
diff --git a/keyboards/jc65/v32a/v32a.c b/keyboards/jc65/v32a/v32a.c
index 8176ade0a..9b1e07274 100644
--- a/keyboards/jc65/v32a/v32a.c
+++ b/keyboards/jc65/v32a/v32a.c
@@ -16,56 +16,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
16*/ 16*/
17 17
18#include "v32a.h" 18#include "v32a.h"
19#ifdef BACKLIGHT_ENABLE
20#include "backlight.h"
21#endif
22#ifdef RGBLIGHT_ENABLE
23#include "rgblight.h"
24#endif
25
26#include <avr/pgmspace.h>
27
28#include "action_layer.h"
29#include "i2c.h"
30#include "quantum.h"
31
32#ifdef RGBLIGHT_ENABLE
33extern rgblight_config_t rgblight_config;
34
35void rgblight_set(void) {
36 if (!rgblight_config.enable) {
37 for (uint8_t i = 0; i < RGBLED_NUM; i++) {
38 led[i].r = 0;
39 led[i].g = 0;
40 led[i].b = 0;
41 }
42 }
43
44 i2c_init();
45 i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
46}
47#endif
48 19
49__attribute__ ((weak)) 20__attribute__ ((weak))
50void matrix_scan_user(void) { 21void matrix_scan_user(void) {}
51#ifdef RGBLIGHT_ENABLE
52 rgblight_task();
53#endif
54}
55 22
56#ifdef BACKLIGHT_ENABLE 23#ifdef BACKLIGHT_ENABLE
57void backlight_init_ports(void) { 24void backlight_init_ports(void) {
58 DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); 25 setPinOutput(D0);
59 PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); 26 setPinOutput(D1);
27 setPinOutput(D4);
28 setPinOutput(D6);
29
30 writePinLow(D0);
31 writePinLow(D1);
32 writePinLow(D4);
33 writePinLow(D6);
60} 34}
61 35
62void backlight_set(uint8_t level) { 36void backlight_set(uint8_t level) {
63 if (level == 0) { 37 if (level == 0) {
64 // Turn out the lights 38 // Turn out the lights
65 PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6); 39 writePinLow(D0);
40 writePinLow(D1);
41 writePinLow(D4);
42 writePinLow(D6);
66 } else { 43 } else {
67 // Turn on the lights 44 // Turn on the lights
68 PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6); 45 writePinHigh(D0);
46 writePinHigh(D1);
47 writePinHigh(D4);
48 writePinHigh(D6);
69 } 49 }
70} 50}
71#endif 51#endif