From 3e26886700a42fa6f66e934d4981b3e285784cd9 Mon Sep 17 00:00:00 2001
From: MechMerlin <30334081+mechmerlin@users.noreply.github.com>
Date: Mon, 8 Apr 2019 10:55:36 -0700
Subject: [PATCH] [Keyboard] Refactor Singa (#5579)
* pragma once it all
* put amnesia's name everywhere
* fixup readme
* remove custom matrix
* remove unneccessary configs
* disable bootmagic
* remove custom i2c in favor of i2c_master
* fix rgb led num
* add in rgb underglow support
---
keyboards/singa/config.h | 9 +-
keyboards/singa/i2c.c | 106 ------------------
keyboards/singa/i2c.h | 27 -----
keyboards/singa/keymaps/amnesia0287/config.h | 2 +-
keyboards/singa/keymaps/amnesia0287/keymap.c | 2 +-
keyboards/singa/keymaps/default/config.h | 2 +-
keyboards/singa/keymaps/default/keymap.c | 2 +-
keyboards/singa/keymaps/test/config.h | 2 +-
keyboards/singa/keymaps/test/keymap.c | 2 +-
keyboards/singa/matrix.c | 112 -------------------
keyboards/singa/readme.md | 8 +-
keyboards/singa/rules.mk | 10 +-
keyboards/singa/singa.c | 71 ++++++++----
keyboards/singa/singa.h | 7 +-
keyboards/singa/usbconfig.h | 5 +-
15 files changed, 67 insertions(+), 300 deletions(-)
delete mode 100644 keyboards/singa/i2c.c
delete mode 100644 keyboards/singa/i2c.h
delete mode 100644 keyboards/singa/matrix.c
diff --git a/keyboards/singa/config.h b/keyboards/singa/config.h
index 54cacee2e9..aca1153d71 100644
--- a/keyboards/singa/config.h
+++ b/keyboards/singa/config.h
@@ -15,8 +15,7 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
-#ifndef CONFIG_H
-#define CONFIG_H
+#pragma once
#include "config_common.h"
@@ -25,7 +24,7 @@ along with this program. If not, see .
#define MANUFACTURER Singa Keyboards
#define PRODUCT Singa
-#define RGBLED_NUM 16
+#define RGBLED_NUM 18
#define MATRIX_ROWS 7
#define MATRIX_COLS 15
@@ -40,7 +39,3 @@ along with this program. If not, see .
#define NO_BACKLIGHT_CLOCK
#define BACKLIGHT_LEVELS 1
#define RGBLIGHT_ANIMATIONS
-
-#define NO_UART 1
-
-#endif
diff --git a/keyboards/singa/i2c.c b/keyboards/singa/i2c.c
deleted file mode 100644
index e8c4455ad1..0000000000
--- a/keyboards/singa/i2c.c
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
-Copyright 2016 Luiz Ribeiro
-
-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 .
-*/
-
-// Please do not modify this file
-
-#include
-#include
-
-#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<
-
-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 .
-*/
-
-// 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
diff --git a/keyboards/singa/keymaps/amnesia0287/config.h b/keyboards/singa/keymaps/amnesia0287/config.h
index 0f75635051..e176ed3479 100644
--- a/keyboards/singa/keymaps/amnesia0287/config.h
+++ b/keyboards/singa/keymaps/amnesia0287/config.h
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
diff --git a/keyboards/singa/keymaps/amnesia0287/keymap.c b/keyboards/singa/keymaps/amnesia0287/keymap.c
index cb0ceac1a8..dc52122db6 100644
--- a/keyboards/singa/keymaps/amnesia0287/keymap.c
+++ b/keyboards/singa/keymaps/amnesia0287/keymap.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
diff --git a/keyboards/singa/keymaps/default/config.h b/keyboards/singa/keymaps/default/config.h
index 4496c59100..93b81b57ba 100644
--- a/keyboards/singa/keymaps/default/config.h
+++ b/keyboards/singa/keymaps/default/config.h
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
diff --git a/keyboards/singa/keymaps/default/keymap.c b/keyboards/singa/keymaps/default/keymap.c
index d201f413b7..7beef8a64d 100644
--- a/keyboards/singa/keymaps/default/keymap.c
+++ b/keyboards/singa/keymaps/default/keymap.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
diff --git a/keyboards/singa/keymaps/test/config.h b/keyboards/singa/keymaps/test/config.h
index 0f75635051..e176ed3479 100644
--- a/keyboards/singa/keymaps/test/config.h
+++ b/keyboards/singa/keymaps/test/config.h
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
diff --git a/keyboards/singa/keymaps/test/keymap.c b/keyboards/singa/keymaps/test/keymap.c
index 30f8de3b3d..a8f31b49c1 100644
--- a/keyboards/singa/keymaps/test/keymap.c
+++ b/keyboards/singa/keymaps/test/keymap.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
diff --git a/keyboards/singa/matrix.c b/keyboards/singa/matrix.c
deleted file mode 100644
index 245813dfd2..0000000000
--- a/keyboards/singa/matrix.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
-Copyright 2017 Luiz Ribeiro
-
-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 .
-*/
-
-#include
-#include
-
-#include "matrix.h"
-
-#ifndef DEBOUNCE
-# define DEBOUNCE 5
-#endif
-
-static uint8_t debouncing = DEBOUNCE;
-
-static matrix_row_t matrix[MATRIX_ROWS];
-static matrix_row_t matrix_debouncing[MATRIX_ROWS];
-
-void matrix_set_row_status(uint8_t row);
-uint8_t bit_reverse(uint8_t x);
-
-void matrix_init(void) {
- // all outputs for rows high
- DDRB = 0xFF;
- PORTB = 0xFF;
- // all inputs for columns
- DDRA = 0x00;
- DDRC &= ~(0x111111<<2);
- DDRD &= ~(1< 7
- (~PINA) & 0xFF
- ) | (
- // cols 8..13, PORTC 7 -> 0
- bit_reverse((~PINC) & 0xFF) << 8
- ) | (
- // col 14, PORTD 7
- ((~PIND) & (1 << PIND7)) << 7
- );
-
- if (matrix_debouncing[row] != cols) {
- matrix_debouncing[row] = cols;
- debouncing = DEBOUNCE;
- }
- }
-
- if (debouncing) {
- if (--debouncing) {
- _delay_ms(1);
- } else {
- for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
- matrix[i] = matrix_debouncing[i];
- }
- }
- }
-
- matrix_scan_quantum();
-
- return 1;
-}
-
-// declarations
-void matrix_set_row_status(uint8_t row) {
- DDRB = (1 << row);
- PORTB = ~(1 << row);
-}
-
-uint8_t bit_reverse(uint8_t x) {
- x = ((x >> 1) & 0x55) | ((x << 1) & 0xaa);
- x = ((x >> 2) & 0x33) | ((x << 2) & 0xcc);
- x = ((x >> 4) & 0x0f) | ((x << 4) & 0xf0);
- return x;
-}
-
-inline matrix_row_t matrix_get_row(uint8_t row) {
- return matrix[row];
-}
-
-void matrix_print(void) {
-}
diff --git a/keyboards/singa/readme.md b/keyboards/singa/readme.md
index bdde361a8e..4400717c80 100644
--- a/keyboards/singa/readme.md
+++ b/keyboards/singa/readme.md
@@ -4,7 +4,7 @@
![Singa](https://i.imgur.com/VVO27Tr.jpg)
-A short description of the keyboard/project
+75% Custom Keyboard.
Keyboard Maintainer: [amnesia0287](https://github.com/amnesia0287)
@@ -38,9 +38,9 @@ macOS:
```
3. Install the following packages:
```
- brew install python
- brew install pyusb
- brew install --HEAD`https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb
+ brew install python3
+ pip3 install pyusb
+ brew install --HEAD https://raw.githubusercontent.com/robertgzr/homebrew-tap/master/bootloadhid.rb
4. Place your keyboard into reset.
5. Flash the board by typing `bootloadHID -r` followed by the path to your `.hex` file.
diff --git a/keyboards/singa/rules.mk b/keyboards/singa/rules.mk
index 68d50aec67..7e46696891 100644
--- a/keyboards/singa/rules.mk
+++ b/keyboards/singa/rules.mk
@@ -31,20 +31,18 @@ F_CPU = 12000000
BOOTLOADER = bootloadHID
# build options
-BOOTMAGIC_ENABLE = yes
+BOOTMAGIC_ENABLE = no
MOUSEKEY_ENABLE = yes
EXTRAKEY_ENABLE = yes
CONSOLE_ENABLE = yes
COMMAND_ENABLE = yes
-BACKLIGHT_ENABLE = no
-RGBLIGHT_ENABLE = no
+BACKLIGHT_ENABLE = yes
+RGBLIGHT_ENABLE = yes
RGBLIGHT_CUSTOM_DRIVER = yes
OPT_DEFS = -DDEBUG_LEVEL=0
-# custom matrix setup
-CUSTOM_MATRIX = yes
-SRC = matrix.c i2c.c
+SRC = i2c_master.c
# programming options
PROGRAM_CMD = ./util/atmega32a_program.py $(TARGET).hex
diff --git a/keyboards/singa/singa.c b/keyboards/singa/singa.c
index 0f5ec471a8..26a7e46375 100644
--- a/keyboards/singa/singa.c
+++ b/keyboards/singa/singa.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
@@ -13,32 +13,57 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-#include QMK_KEYBOARD_H
-
-#include
-#include "action_layer.h"
-#include "i2c.h"
+#include "rgblight.h"
+#include "i2c_master.h"
#include "quantum.h"
+#ifdef RGBLIGHT_ENABLE
+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();
+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_transmit(0xb0, (uint8_t*)led, 3 * RGBLED_NUM, 100);
}
+#endif
-void matrix_scan_kb(void) {
- matrix_scan_user();
- /* Nothing else for now. */
-}
-
-__attribute__((weak)) // overridable
-void matrix_init_user(void) {
-
-}
-
-__attribute__((weak)) // overridable
+__attribute__ ((weak))
void matrix_scan_user(void) {
-
+}
+
+void backlight_init_ports(void) {
+ // initialize pins D0, D1, D4 and D6 as output
+ setPinOutput(D0);
+ setPinOutput(D1);
+ setPinOutput(D4);
+ setPinOutput(D6);
+
+ // turn RGB LEDs on
+ writePinHigh(D0);
+ writePinHigh(D1);
+ writePinHigh(D4);
+ writePinHigh(D6);
+}
+
+void backlight_set(uint8_t level) {
+ if (level == 0) {
+ // turn RGB LEDs off
+ writePinLow(D0);
+ writePinLow(D1);
+ writePinLow(D4);
+ writePinLow(D6);
+ } else {
+ // turn RGB LEDs on
+ writePinHigh(D0);
+ writePinHigh(D1);
+ writePinHigh(D4);
+ writePinHigh(D6);
+ }
}
diff --git a/keyboards/singa/singa.h b/keyboards/singa/singa.h
index 8221176c15..03b6848886 100644
--- a/keyboards/singa/singa.h
+++ b/keyboards/singa/singa.h
@@ -1,4 +1,4 @@
-/* Copyright 2018 REPLACE_WITH_YOUR_NAME
+/* Copyright 2018 amnesia0287
*
* 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
@@ -13,8 +13,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-#ifndef SINGA_H
-#define SINGA_H
+#pragma once
#include "quantum.h"
@@ -139,5 +138,3 @@
{ k74, k81, k75, KC_NO, KC_NO, k76, KC_NO, KC_NO, k77, KC_NO, k82, KC_NO, k78, k79, k80 }, \
{ KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, k15, k30 } \
}
-
-#endif
diff --git a/keyboards/singa/usbconfig.h b/keyboards/singa/usbconfig.h
index d2d848fcdc..54a7d20f14 100644
--- a/keyboards/singa/usbconfig.h
+++ b/keyboards/singa/usbconfig.h
@@ -8,8 +8,7 @@
* This Revision: $Id: usbconfig-prototype.h 785 2010-05-30 17:57:07Z cs $
*/
-#ifndef __usbconfig_h_included__
-#define __usbconfig_h_included__
+#pragma once
#include "config.h"
@@ -392,5 +391,3 @@ section at the end of this file).
/* #define USB_INTR_PENDING EIFR */
#define USB_INTR_PENDING_BIT INTF1
#define USB_INTR_VECTOR INT1_vect
-
-#endif /* __usbconfig_h_included__ */