]> git.donarmstrong.com Git - qmk_firmware.git/commitdiff
[Keyboard] Refactor Singa (#5579)
authorMechMerlin <30334081+mechmerlin@users.noreply.github.com>
Mon, 8 Apr 2019 17:55:36 +0000 (10:55 -0700)
committerDrashna Jaelre <drashna@live.com>
Mon, 8 Apr 2019 17:55:36 +0000 (10:55 -0700)
* 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

15 files changed:
keyboards/singa/config.h
keyboards/singa/i2c.c [deleted file]
keyboards/singa/i2c.h [deleted file]
keyboards/singa/keymaps/amnesia0287/config.h
keyboards/singa/keymaps/amnesia0287/keymap.c
keyboards/singa/keymaps/default/config.h
keyboards/singa/keymaps/default/keymap.c
keyboards/singa/keymaps/test/config.h
keyboards/singa/keymaps/test/keymap.c
keyboards/singa/matrix.c [deleted file]
keyboards/singa/readme.md
keyboards/singa/rules.mk
keyboards/singa/singa.c
keyboards/singa/singa.h
keyboards/singa/usbconfig.h

index 54cacee2e90ad9f7d7ededd5f492710b44efb461..aca1153d7146b6adee0aa1830d85125d2c34bbf2 100644 (file)
@@ -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 (file)
index e8c4455..0000000
+++ /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 (file)
index 7ce50cd..0000000
+++ /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
index 0f756350514c248c3f92d5264af4a99344a44bee..e176ed34798ca3ddc0a1f95a2331e4c8910f46d6 100644 (file)
@@ -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
index cb0ceac1a81784c6d6bfe9b55cb15981a3bf1903..dc52122db6b1120b08c8251cd260524c025b2601 100644 (file)
@@ -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
index 4496c59100617fc8c9e820df1515a623273b5d14..93b81b57ba4dd925f27f13f4daf23ac75b1f41f2 100644 (file)
@@ -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
index d201f413b77224c624e68a3a2ce85f625a2e0df6..7beef8a64d8ac86e8e66a06a90aafc8e9885c608 100644 (file)
@@ -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
index 0f756350514c248c3f92d5264af4a99344a44bee..e176ed34798ca3ddc0a1f95a2331e4c8910f46d6 100644 (file)
@@ -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
index 30f8de3b3de588fa97a2d0af28996966889c2249..a8f31b49c198cd7a56874b3b97d6561ba6bf32b4 100644 (file)
@@ -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 (file)
index 245813d..0000000
+++ /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) {
-}
index bdde361a8e7e69bc261a1811596da3882e5766d9..4400717c800e6c30ab6ff2634a4ee51500d9b883 100644 (file)
@@ -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. 
index 68d50aec67a113531b65c01e75ac7969f1d37720..7e46696891c13ae7a7742c4353c927ba1f296b94 100644 (file)
@@ -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
index 0f5ec471a8ee6504d1f8b32642907faba07f20e6..26a7e463751c5c874abdf810dc942376853b4fa2 100644 (file)
@@ -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
  * 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);
+       }
 }
index 8221176c156fe1a16afbaf5b31e1aedadd5e1d88..03b68488860e2586a569ed0bd49487c480414bd6 100644 (file)
@@ -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"
 
   { 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
index d2d848fcdc8fd19f07621d98589d3f152dff5e28..54a7d20f142783843f4bdfb05930a95ef95833f7 100644 (file)
@@ -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__ */