aboutsummaryrefslogtreecommitdiffstats
path: root/keyboards
diff options
context:
space:
mode:
authorMechMerlin <30334081+mechmerlin@users.noreply.github.com>2019-04-08 10:55:36 -0700
committerDrashna Jaelre <drashna@live.com>2019-04-08 10:55:36 -0700
commit3e26886700a42fa6f66e934d4981b3e285784cd9 (patch)
tree1c084bb10f45a29106233fc7105363980178fecb /keyboards
parent0456bd668de37f118e717aabf00a132756ea619c (diff)
downloadfirmware-3e26886700a42fa6f66e934d4981b3e285784cd9.tar.gz
firmware-3e26886700a42fa6f66e934d4981b3e285784cd9.tar.bz2
firmware-3e26886700a42fa6f66e934d4981b3e285784cd9.zip
[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
Diffstat (limited to 'keyboards')
-rw-r--r--keyboards/singa/config.h9
-rw-r--r--keyboards/singa/i2c.c106
-rw-r--r--keyboards/singa/i2c.h27
-rw-r--r--keyboards/singa/keymaps/amnesia0287/config.h2
-rw-r--r--keyboards/singa/keymaps/amnesia0287/keymap.c2
-rw-r--r--keyboards/singa/keymaps/default/config.h2
-rw-r--r--keyboards/singa/keymaps/default/keymap.c2
-rw-r--r--keyboards/singa/keymaps/test/config.h2
-rw-r--r--keyboards/singa/keymaps/test/keymap.c2
-rw-r--r--keyboards/singa/matrix.c112
-rw-r--r--keyboards/singa/readme.md8
-rw-r--r--keyboards/singa/rules.mk10
-rw-r--r--keyboards/singa/singa.c63
-rw-r--r--keyboards/singa/singa.h7
-rw-r--r--keyboards/singa/usbconfig.h5
15 files changed, 63 insertions, 296 deletions
diff --git a/keyboards/singa/config.h b/keyboards/singa/config.h
index 54cacee2e..aca1153d7 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 <http://www.gnu.org/licenses/>.
*/
-#ifndef CONFIG_H
-#define CONFIG_H
+#pragma once
#include "config_common.h"
@@ -25,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#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 <http://www.gnu.org/licenses/>.
#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 e8c4455ad..000000000
--- a/keyboards/singa/i2c.c
+++ /dev/null
@@ -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;
-}
diff --git a/keyboards/singa/i2c.h b/keyboards/singa/i2c.h
deleted file mode 100644
index 7ce50cdb5..000000000
--- a/keyboards/singa/i2c.h
+++ /dev/null
@@ -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
diff --git a/keyboards/singa/keymaps/amnesia0287/config.h b/keyboards/singa/keymaps/amnesia0287/config.h
index 0f7563505..e176ed347 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 cb0ceac1a..dc52122db 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 4496c5910..93b81b57b 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 d201f413b..7beef8a64 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 0f7563505..e176ed347 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 30f8de3b3..a8f31b49c 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 245813dfd..000000000
--- a/keyboards/singa/matrix.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
-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/>.
-*/
-
-#include <avr/io.h>
-#include <util/delay.h>
-
-#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<<PIND7);
- // all columns are pulled-up
- PORTA = 0xFF;
- PORTC |= (0b111111<<2);
- PORTD |= (1<<PIND7);
-
- // initialize matrix state: all keys off
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- matrix[row] = 0x00;
- matrix_debouncing[row] = 0x00;
- }
-
- matrix_init_quantum();
-}
-
-uint8_t matrix_scan(void) {
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- matrix_set_row_status(row);
- _delay_us(5);
-
- matrix_row_t cols = (
- // cols 0..7, PORTA 0 -> 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 bdde361a8..4400717c8 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 68d50aec6..7e4669689 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 0f5ec471a..26a7e4637 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 <http://www.gnu.org/licenses/>.
*/
-#include QMK_KEYBOARD_H
-
-#include <avr/pgmspace.h>
-#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;
+
+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;
+ }
+ }
-// for keyboard subdirectory level init functions
-// @Override
-void matrix_init_kb(void) {
- // call user level keymaps, if any
- matrix_init_user();
+ 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))
+void matrix_scan_user(void) {
}
-__attribute__((weak)) // overridable
-void matrix_init_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);
}
-__attribute__((weak)) // overridable
-void matrix_scan_user(void) {
-
+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 8221176c1..03b684888 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 <http://www.gnu.org/licenses/>.
*/
-#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 d2d848fcd..54a7d20f1 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__ */