Browse Source

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
pull/7262/head
fauxpark 4 years ago
committed by Drashna Jaelre
parent
commit
3a215195ed
52 changed files with 138 additions and 2539 deletions
  1. +18
    -35
      keyboards/bfake/bfake.c
  2. +0
    -106
      keyboards/bfake/i2c.c
  3. +0
    -27
      keyboards/bfake/i2c.h
  4. +2
    -17
      keyboards/bfake/rules.mk
  5. +0
    -106
      keyboards/jc65/v32a/i2c.c
  6. +0
    -27
      keyboards/jc65/v32a/i2c.h
  7. +2
    -17
      keyboards/jc65/v32a/rules.mk
  8. +18
    -38
      keyboards/jc65/v32a/v32a.c
  9. +0
    -104
      keyboards/jj50/i2c.c
  10. +0
    -25
      keyboards/jj50/i2c.h
  11. +9
    -58
      keyboards/jj50/jj50.c
  12. +2
    -22
      keyboards/jj50/rules.mk
  13. +0
    -104
      keyboards/mechmini/v1/i2c.c
  14. +0
    -22
      keyboards/mechmini/v1/i2c.h
  15. +2
    -17
      keyboards/mechmini/v1/rules.mk
  16. +6
    -54
      keyboards/mechmini/v1/v1.c
  17. +0
    -106
      keyboards/mehkee96/i2c.c
  18. +0
    -27
      keyboards/mehkee96/i2c.h
  19. +6
    -59
      keyboards/mehkee96/mehkee96.c
  20. +2
    -2
      keyboards/mehkee96/rules.mk
  21. +0
    -104
      keyboards/mt40/i2c.c
  22. +0
    -25
      keyboards/mt40/i2c.h
  23. +1
    -28
      keyboards/mt40/mt40.c
  24. +2
    -2
      keyboards/mt40/rules.mk
  25. +27
    -65
      keyboards/percent/canoe/canoe.c
  26. +0
    -106
      keyboards/percent/canoe/i2c.c
  27. +0
    -27
      keyboards/percent/canoe/i2c.h
  28. +3
    -18
      keyboards/percent/canoe/rules.mk
  29. +0
    -106
      keyboards/percent/skog/i2c.c
  30. +0
    -25
      keyboards/percent/skog/i2c.h
  31. +2
    -17
      keyboards/percent/skog/rules.mk
  32. +8
    -58
      keyboards/percent/skog/skog.c
  33. +1
    -25
      keyboards/winkeyless/bmini/bmini.c
  34. +0
    -106
      keyboards/winkeyless/bmini/i2c.c
  35. +0
    -27
      keyboards/winkeyless/bmini/i2c.h
  36. +2
    -17
      keyboards/winkeyless/bmini/rules.mk
  37. +0
    -61
      keyboards/winkeyless/bminiex/bminiex.c
  38. +0
    -106
      keyboards/winkeyless/bminiex/i2c.c
  39. +0
    -25
      keyboards/winkeyless/bminiex/i2c.h
  40. +2
    -17
      keyboards/winkeyless/bminiex/rules.mk
  41. +0
    -104
      keyboards/ymd75/i2c.c
  42. +0
    -25
      keyboards/ymd75/i2c.h
  43. +2
    -18
      keyboards/ymd75/rules.mk
  44. +9
    -58
      keyboards/ymd75/ymd75.c
  45. +0
    -104
      keyboards/ymd96/i2c.c
  46. +0
    -25
      keyboards/ymd96/i2c.h
  47. +2
    -17
      keyboards/ymd96/rules.mk
  48. +8
    -58
      keyboards/ymd96/ymd96.c
  49. +0
    -104
      keyboards/ymdk_np21/i2c.c
  50. +0
    -25
      keyboards/ymdk_np21/i2c.h
  51. +2
    -18
      keyboards/ymdk_np21/rules.mk
  52. +0
    -45
      keyboards/ymdk_np21/ymdk_np21.c

+ 18
- 35
keyboards/bfake/bfake.c View File

@ -16,51 +16,34 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bfake.h"
#ifdef BACKLIGHT_ENABLE
#include "backlight.h"
#endif
#ifdef RGBLIGHT_ENABLE
#include "rgblight.h"
#endif
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
#endif
__attribute__ ((weak))
void matrix_scan_user(void) {
}
void matrix_scan_user(void) {}
void backlight_init_ports(void) {
DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6);
PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6);
setPinOutput(D0);
setPinOutput(D1);
setPinOutput(D4);
setPinOutput(D6);
writePinLow(D0);
writePinLow(D1);
writePinLow(D4);
writePinLow(D6);
}
void backlight_set(uint8_t level) {
if (level == 0) {
// Turn out the lights
PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6);
writePinLow(D0);
writePinLow(D1);
writePinLow(D4);
writePinLow(D6);
} else {
// Turn on the lights
PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6);
writePinHigh(D0);
writePinHigh(D1);
writePinHigh(D4);
writePinHigh(D6);
}
}

+ 0
- 106
keyboards/bfake/i2c.c View File

@ -1,106 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 27
keyboards/bfake/i2c.h View File

@ -1,27 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 2
- 17
keyboards/bfake/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = no
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c
SRC = matrix.c

+ 0
- 106
keyboards/jc65/v32a/i2c.c View File

@ -1,106 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 27
keyboards/jc65/v32a/i2c.h View File

@ -1,27 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 2
- 17
keyboards/jc65/v32a/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = yes
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c
SRC = matrix.c

+ 18
- 38
keyboards/jc65/v32a/v32a.c View File

@ -16,56 +16,36 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "v32a.h"
#ifdef BACKLIGHT_ENABLE
#include "backlight.h"
#endif
#ifdef RGBLIGHT_ENABLE
#include "rgblight.h"
#endif
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
#endif
__attribute__ ((weak))
void matrix_scan_user(void) {
#ifdef RGBLIGHT_ENABLE
rgblight_task();
#endif
}
void matrix_scan_user(void) {}
#ifdef BACKLIGHT_ENABLE
void backlight_init_ports(void) {
DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6);
PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6);
setPinOutput(D0);
setPinOutput(D1);
setPinOutput(D4);
setPinOutput(D6);
writePinLow(D0);
writePinLow(D1);
writePinLow(D4);
writePinLow(D6);
}
void backlight_set(uint8_t level) {
if (level == 0) {
// Turn out the lights
PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6);
writePinLow(D0);
writePinLow(D1);
writePinLow(D4);
writePinLow(D6);
} else {
// Turn on the lights
PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6);
writePinHigh(D0);
writePinHigh(D1);
writePinHigh(D4);
writePinHigh(D6);
}
}
#endif

+ 0
- 104
keyboards/jj50/i2c.c View File

@ -1,104 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 25
keyboards/jj50/i2c.h View File

@ -1,25 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 9
- 58
keyboards/jj50/jj50.c View File

@ -17,24 +17,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "jj50.h"
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
#include "backlight.h"
#include "backlight_custom.h"
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
void matrix_init_kb(void) { matrix_init_user(); }
__attribute__ ((weak))
void matrix_init_user(void) {}
void matrix_scan_kb(void) { matrix_scan_user(); }
__attribute__ ((weak))
void matrix_scan_user(void) {}
#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
void backlight_init_ports(void) {
b_led_init_ports();
}
@ -47,48 +43,3 @@ void backlight_set(uint8_t level) {
b_led_set(level);
}
#endif
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}

+ 2
- 22
keyboards/jj50/rules.mk View File

@ -1,19 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
# Modified 2018 Wayne Jones (WarmCatUK) <waynekjones@gmail.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -35,22 +19,18 @@ CONSOLE_ENABLE = no
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = yes
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
NKRO_ENABLE = no
# Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
DISABLE_WS2812 = no
KEY_LOCK_ENABLE = yes
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
#OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c backlight.c
SRC = matrix.c backlight.c
LAYOUTS = ortho_5x12

+ 0
- 104
keyboards/mechmini/v1/i2c.c View File

@ -1,104 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 22
keyboards/mechmini/v1/i2c.h View File

@ -1,22 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 2
- 17
keyboards/mechmini/v1/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c
SRC = matrix.c

+ 6
- 54
keyboards/mechmini/v1/v1.c View File

@ -16,61 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "v1.h"
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
#include "rgblight.h"
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
void matrix_init_kb(void) { matrix_init_user(); }
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
__attribute__ ((weak))
void matrix_init_user(void) {}
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
void matrix_scan_kb(void) { matrix_scan_user(); }
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}
__attribute__ ((weak))
void matrix_scan_user(void) {}

+ 0
- 106
keyboards/mehkee96/i2c.c View File

@ -1,106 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 27
keyboards/mehkee96/i2c.h View File

@ -1,27 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 6
- 59
keyboards/mehkee96/mehkee96.c View File

@ -16,66 +16,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mehkee96.h"
#include "rgblight.h"
#include <avr/pgmspace.h>
void matrix_init_kb(void) { matrix_init_user(); }
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
__attribute__ ((weak))
void matrix_init_user(void) {}
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
void matrix_scan_kb(void) { matrix_scan_user(); }
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
#ifdef RGBLIGHT_ANIMATION
rgblight_task();
#endif
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}
__attribute__ ((weak))
void matrix_scan_user(void) {}

+ 2
- 2
keyboards/mehkee96/rules.mk View File

@ -21,10 +21,10 @@ CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c
SRC = matrix.c

+ 0
- 104
keyboards/mt40/i2c.c View File

@ -1,104 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 25
keyboards/mt40/i2c.h View File

@ -1,25 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 1
- 28
keyboards/mt40/mt40.c View File

@ -13,32 +13,5 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mt40.h"
#include "rgblight.h"
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
extern rgblight_config_t rgblight_config;
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
__attribute__ ((weak))
void matrix_scan_kb(void) {
rgblight_task();
matrix_init_user();
}
#include "mt40.h"

+ 2
- 2
keyboards/mt40/rules.mk View File

@ -24,14 +24,14 @@ AUDIO_ENABLE ?= no # Audio output on port C6
UNICODE_ENABLE ?= no # Unicode
BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE ?= yes # Enable WS2812 RGB underlight.
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
TAP_DANCE_ENABLE = no
OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c
SRC = matrix.c
LAYOUTS = planck_mit
LAYOUTS_HAS_RGB = no

+ 27
- 65
keyboards/percent/canoe/canoe.c View File

@ -16,81 +16,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "canoe.h"
#ifdef BACKLIGHT_ENABLE
#include "backlight.h"
#endif
#ifdef RGBLIGHT_ENABLE
#include "i2c.h"
#include "rgblight.h"
#endif
void matrix_init_kb(void) { matrix_init_user(); }
__attribute__ ((weak))
void matrix_init_user(void) {}
void matrix_scan_kb(void) { matrix_scan_user(); }
__attribute__ ((weak))
void matrix_scan_user(void) {}
#ifdef BACKLIGHT_ENABLE
void backlight_set(uint8_t level) {
if (level == 0) {
// Turn out the lights
PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6);
writePinLow(D0);
writePinLow(D1);
writePinLow(D4);
writePinLow(D6);
} else {
// Turn on the lights
PORTD |= (1<<0 | 1<<1 | 1<<4 | 1<<6);
writePinHigh(D0);
writePinHigh(D1);
writePinHigh(D4);
writePinHigh(D6);
}
}
void backlight_init_ports(void) {
DDRD |= (1<<0 | 1<<1 | 1<<4 | 1<<6);
PORTD &= ~(1<<0 | 1<<1 | 1<<4 | 1<<6);
}
#endif
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
setPinOutput(D0);
setPinOutput(D1);
setPinOutput(D4);
setPinOutput(D6);
writePinLow(D0);
writePinLow(D1);
writePinLow(D4);
writePinLow(D6);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}

+ 0
- 106
keyboards/percent/canoe/i2c.c View File

@ -1,106 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 27
keyboards/percent/canoe/i2c.h View File

@ -1,27 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 3
- 18
keyboards/percent/canoe/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -34,12 +19,12 @@ CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c
SRC = matrix.c
LAYOUTS = 65_ansi_blocker
LAYOUTS = 65_ansi_blocker

+ 0
- 106
keyboards/percent/skog/i2c.c View File

@ -1,106 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 25
keyboards/percent/skog/i2c.h View File

@ -1,25 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#pragma once
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);

+ 2
- 17
keyboards/percent/skog/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2018 Jumail Mundekkat / MxBlue
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -34,9 +19,9 @@ CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = yes
RGBLIGHT_ENABLE = yes
WS2812_DRIVER = i2c
BACKLIGHT_CUSTOM_DRIVER = yes
RGBLIGHT_CUSTOM_DRIVER = yes
OPT_DEFS = -DDEBUG_LEVEL=0
@ -45,4 +30,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c backlight.c
SRC = matrix.c backlight.c

+ 8
- 58
keyboards/percent/skog/skog.c View File

@ -19,23 +19,18 @@ ps2avrGB support code by Kenneth A. (bminiex/.[ch])
#include "skog.h"
#include "rgblight.h"
#include "backlight.h"
#include "backlight_custom.h"
#include <avr/pgmspace.h>
void matrix_init_kb(void) { matrix_init_user(); }
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
__attribute__ ((weak))
void matrix_init_user(void) {}
#include "backlight.h"
#include "backlight_custom.h"
void matrix_scan_kb(void) { matrix_scan_user(); }
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
__attribute__ ((weak))
void matrix_scan_user(void) {}
#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
@ -51,48 +46,3 @@ void backlight_set(uint8_t level) {
b_led_set(level);
}
#endif
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}

+ 1
- 25
keyboards/winkeyless/bmini/bmini.c View File

@ -16,30 +16,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bmini.h"
#include "rgblight.h"
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
extern rgblight_config_t rgblight_config;
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i = 0; i < RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
__attribute__ ((weak))
void matrix_scan_user(void) {
rgblight_task();
}
void matrix_scan_user(void) {}

+ 0
- 106
keyboards/winkeyless/bmini/i2c.c View File

@ -1,106 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 27
keyboards/winkeyless/bmini/i2c.h View File

@ -1,27 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 2
- 17
keyboards/winkeyless/bmini/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -34,10 +19,10 @@ CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = no
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c
SRC = matrix.c

+ 0
- 61
keyboards/winkeyless/bminiex/bminiex.c View File

@ -16,24 +16,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bminiex.h"
#include "rgblight.h"
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
#include "backlight.h"
#include "backlight_custom.h"
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
void backlight_init_ports(void) {
@ -48,50 +34,3 @@ void backlight_set(uint8_t level) {
b_led_set(level);
}
#endif
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}

+ 0
- 106
keyboards/winkeyless/bminiex/i2c.c View File

@ -1,106 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 25
keyboards/winkeyless/bminiex/i2c.h View File

@ -1,25 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Please do not modify this file
#pragma once
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);

+ 2
- 17
keyboards/winkeyless/bminiex/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -36,7 +21,7 @@ COMMAND_ENABLE = no
BACKLIGHT_ENABLE = yes
BACKLIGHT_CUSTOM_DRIVER = yes
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
TAP_DANCE_ENABLE = no
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
@ -46,4 +31,4 @@ OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c backlight.c
SRC = matrix.c backlight.c

+ 0
- 104
keyboards/ymd75/i2c.c View File

@ -1,104 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 25
keyboards/ymd75/i2c.h View File

@ -1,25 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 2
- 18
keyboards/ymd75/rules.mk View File

@ -1,19 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
# Modified 2018 Wayne Jones (WarmCatUK) <waynekjones@gmail.com>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -35,7 +19,7 @@ CONSOLE_ENABLE = no
COMMAND_ENABLE = yes
BACKLIGHT_ENABLE = yes
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
NKRO_ENABLE = no
# Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
@ -51,4 +35,4 @@ SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c backlight.c
SRC = matrix.c backlight.c

+ 9
- 58
keyboards/ymd75/ymd75.c View File

@ -16,23 +16,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ymd75.h"
//#include "rgblight.h"
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "i2c.h"
#include "quantum.h"
#include "backlight.h"
#include "backlight_custom.h"
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
void matrix_init_kb(void) { matrix_init_user(); }
__attribute__ ((weak))
void matrix_init_user(void) {}
void matrix_scan_kb(void) { matrix_scan_user(); }
__attribute__ ((weak))
void matrix_scan_user(void) {}
#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
@ -48,48 +44,3 @@ void backlight_set(uint8_t level) {
b_led_set(level);
}
#endif
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}

+ 0
- 104
keyboards/ymd96/i2c.c View File

@ -1,104 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 25
keyboards/ymd96/i2c.h View File

@ -1,25 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 2
- 17
keyboards/ymd96/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -37,7 +22,7 @@ BACKLIGHT_ENABLE = yes
BACKLIGHT_CUSTOM_DRIVER = yes
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
WS2812_DRIVER = i2c
KEY_LOCK_ENABLE = yes
@ -48,4 +33,4 @@ OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c backlight.c
SRC = matrix.c backlight.c

+ 8
- 58
keyboards/ymd96/ymd96.c View File

@ -18,22 +18,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ymd96.h"
#include <avr/pgmspace.h>
#include "backlight.h"
#include "backlight_custom.h"
#include "action_layer.h"
#include "quantum.h"
void matrix_init_kb(void) { matrix_init_user(); }
#include "i2c.h"
__attribute__ ((weak))
void matrix_init_user(void) {}
#include "backlight.h"
#include "backlight_custom.h"
void matrix_scan_kb(void) { matrix_scan_user(); }
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
__attribute__ ((weak))
void matrix_scan_user(void) {}
#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
@ -49,49 +45,3 @@ void backlight_set(uint8_t level) {
b_led_set(level);
}
#endif
#ifdef RGBLIGHT_ENABLE
extern rgblight_config_t rgblight_config;
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
#else
void matrix_scan_kb(void) {
#endif
matrix_scan_user();
/* Nothing else for now. */
}
__attribute__((weak)) // overridable
void matrix_init_user(void) {
}
__attribute__((weak)) // overridable
void matrix_scan_user(void) {
}

+ 0
- 104
keyboards/ymdk_np21/i2c.c View File

@ -1,104 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <avr/io.h>
#include <util/twi.h>
#include "i2c.h"
void i2c_set_bitrate(uint16_t bitrate_khz) {
uint8_t bitrate_div = ((F_CPU / 1000l) / bitrate_khz);
if (bitrate_div >= 16) {
bitrate_div = (bitrate_div - 16) / 2;
}
TWBR = bitrate_div;
}
void i2c_init(void) {
// set pull-up resistors on I2C bus pins
PORTC |= 0b11;
i2c_set_bitrate(400);
// enable TWI (two-wire interface)
TWCR |= (1 << TWEN);
// enable TWI interrupt and slave address ACK
TWCR |= (1 << TWIE);
TWCR |= (1 << TWEA);
}
uint8_t i2c_start(uint8_t address) {
// reset TWI control register
TWCR = 0;
// begin transmission and wait for it to end
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the start condition was successfully transmitted
if ((TWSR & 0xF8) != TW_START) {
return 1;
}
// transmit address and wait
TWDR = address;
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
// check if the device has acknowledged the READ / WRITE mode
uint8_t twst = TW_STATUS & 0xF8;
if ((twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK)) {
return 1;
}
return 0;
}
void i2c_stop(void) {
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
}
uint8_t i2c_write(uint8_t data) {
TWDR = data;
// transmit data and wait
TWCR = (1<<TWINT) | (1<<TWEN);
while (!(TWCR & (1<<TWINT)));
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length) {
if (i2c_start(address)) {
return 1;
}
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i])) {
return 1;
}
}
i2c_stop();
return 0;
}

+ 0
- 25
keyboards/ymdk_np21/i2c.h View File

@ -1,25 +0,0 @@
/*
Copyright 2016 Luiz Ribeiro <luizribeiro@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __I2C_H__
#define __I2C_H__
void i2c_init(void);
void i2c_set_bitrate(uint16_t bitrate_khz);
uint8_t i2c_send(uint8_t address, uint8_t *data, uint16_t length);
#endif

+ 2
- 18
keyboards/ymdk_np21/rules.mk View File

@ -1,18 +1,3 @@
# Copyright 2017 Luiz Ribeiro <luizribeiro@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# MCU name
MCU = atmega32a
@ -37,8 +22,7 @@ BACKLIGHT_ENABLE = yes
BACKLIGHT_CUSTOM_DRIVER = yes
RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
# DISABLE_WS2812 = no
WS2812_DRIVER = i2c
KEY_LOCK_ENABLE = yes
@ -49,4 +33,4 @@ OPT_DEFS = -DDEBUG_LEVEL=0
# custom matrix setup
CUSTOM_MATRIX = yes
SRC = matrix.c i2c.c backlight.c
SRC = matrix.c backlight.c

+ 0
- 45
keyboards/ymdk_np21/ymdk_np21.c View File

@ -18,25 +18,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "ymdk_np21.h"
#include <avr/pgmspace.h>
#include "action_layer.h"
#include "quantum.h"
#include "i2c.h"
#include "backlight.h"
#include "backlight_custom.h"
extern rgblight_config_t rgblight_config;
// for keyboard subdirectory level init functions
// @Override
void matrix_init_kb(void) {
// call user level keymaps, if any
matrix_init_user();
}
#ifdef BACKLIGHT_ENABLE
/// Overrides functions in `quantum.c`
void backlight_init_ports(void) {
@ -51,32 +35,3 @@ void backlight_set(uint8_t level) {
b_led_set(level);
}
#endif
// custom RGB driver
void rgblight_set(void) {
if (!rgblight_config.enable) {
for (uint8_t i=0; i<RGBLED_NUM; i++) {
led[i].r = 0;
led[i].g = 0;
led[i].b = 0;
}
}
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
}
bool rgb_init = false;
void matrix_scan_kb(void) {
// if LEDs were previously on before poweroff, turn them back on
if (rgb_init == false && rgblight_config.enable) {
i2c_init();
i2c_send(0xb0, (uint8_t*)led, 3 * RGBLED_NUM);
rgb_init = true;
}
rgblight_task();
/* Nothing else for now. */
matrix_scan_user();
}

Loading…
Cancel
Save