RAMA M6-B and IS31FL3218 driver (#4021)

* Initial RAMA M6-B commit.

* Moved IS31FL3218 driver, minor cleanups

* Refactor, added dynamic keymap.

* Added dynamic keymaps to RAMA M6-A

* Refactor M6-A and M6-B to use common code.

* Formatting

* Cleanup

* Cleanup

* Changes from review
master
Wilba6582 2018-10-01 01:35:10 +10:00 committed by Jack Humbert
parent 6734cd9c5c
commit 66ef1e3d67
18 changed files with 885 additions and 378 deletions

View File

@ -0,0 +1,102 @@
/* Copyright 2018 Jason Williams (Wilba)
*
* 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 "is31fl3218.h"
#include "i2c_master.h"
// This is the full 8-bit address
#define ISSI_ADDRESS 0b10101000
// These are the register addresses
#define ISSI_REG_SHUTDOWN 0x00
#define ISSI_REG_PWM 0x01
#define ISSI_REG_CONTROL 0x13
#define ISSI_REG_UPDATE 0x16
#define ISSI_REG_RESET 0x17
// Default timeout if no I2C response
#define ISSI_TIMEOUT 100
// Reusable buffer for transfers
uint8_t g_twi_transfer_buffer[20];
// IS31FL3218 has 18 PWM outputs and a fixed I2C address, so no chaining.
// If used as RGB LED driver, LEDs are assigned RGB,RGB,RGB,RGB,RGB,RGB
uint8_t g_pwm_buffer[18];
bool g_pwm_buffer_update_required = false;
void IS31FL3218_write_register( uint8_t reg, uint8_t data )
{
g_twi_transfer_buffer[0] = reg;
g_twi_transfer_buffer[1] = data;
i2c_transmit( ISSI_ADDRESS, g_twi_transfer_buffer, 2, ISSI_TIMEOUT);
}
void IS31FL3218_write_pwm_buffer( uint8_t *pwm_buffer )
{
g_twi_transfer_buffer[0] = ISSI_REG_PWM;
for ( int i=0; i<18; i++ ) {
g_twi_transfer_buffer[1+i] = pwm_buffer[i];
}
i2c_transmit( ISSI_ADDRESS, g_twi_transfer_buffer, 19, ISSI_TIMEOUT);
}
void IS31FL3218_init(void)
{
// In case we ever want to reinitialize (?)
IS31FL3218_write_register( ISSI_REG_RESET, 0x00 );
// Turn off software shutdown
IS31FL3218_write_register( ISSI_REG_SHUTDOWN, 0x01 );
// Set all PWM values to zero
for ( uint8_t i = 0; i < 18; i++ ) {
IS31FL3218_write_register( ISSI_REG_PWM+i, 0x00 );
}
// Enable all channels
for ( uint8_t i = 0; i < 3; i++ ) {
IS31FL3218_write_register( ISSI_REG_CONTROL+i, 0b00111111 );
}
// Load PWM registers and LED Control register data
IS31FL3218_write_register( ISSI_REG_UPDATE, 0x01 );
}
void IS31FL3218_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
{
g_pwm_buffer[index * 3 + 0] = red;
g_pwm_buffer[index * 3 + 1] = green;
g_pwm_buffer[index * 3 + 2] = blue;
g_pwm_buffer_update_required = true;
}
void IS31FL3218_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
{
for ( int i = 0; i < 6; i++ ) {
IS31FL3218_set_color( i, red, green, blue );
}
}
void IS31FL3218_update_pwm_buffers(void)
{
if ( g_pwm_buffer_update_required ) {
IS31FL3218_write_pwm_buffer( g_pwm_buffer );
// Load PWM registers and LED Control register data
IS31FL3218_write_register( ISSI_REG_UPDATE, 0x01 );
}
g_pwm_buffer_update_required = false;
}

View File

@ -1,4 +1,4 @@
/* Copyright 2018 Wilba
/* Copyright 2018 Jason Williams (Wilba)
*
* 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,12 +13,12 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
#include <stdint.h>
#include <stdbool.h>
#include "../../config.h"
// place overrides here
#endif
void IS31FL3218_init(void);
void IS31FL3218_set_color( int index, uint8_t red, uint8_t green, uint8_t blue );
void IS31FL3218_set_color_all( uint8_t red, uint8_t green, uint8_t blue );
void IS31FL3218_update_pwm_buffers(void);

View 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"
@ -187,4 +186,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
//#define MIDI_TONE_KEYCODE_OCTAVES 1
#endif
#define RGB_BACKLIGHT_ENABLED 0
#define DYNAMIC_KEYMAP_LAYER_COUNT 4
// EEPROM usage
// TODO: refactor with new user EEPROM code (coming soon)
#define EEPROM_MAGIC 0x451F
#define EEPROM_MAGIC_ADDR 32
// Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07
#define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72

View File

@ -3,322 +3,14 @@
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LAYOUT(
TO(1), KC_A, KC_B, KC_C, KC_D, KC_E),
KC_1, KC_2, KC_3, KC_4, KC_5, KC_6),
LAYOUT(
TO(2), KC_F, KC_G, KC_H, KC_I, KC_J),
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO),
LAYOUT(
TO(3), KC_K, KC_L, KC_M, KC_N, KC_O),
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO),
LAYOUT(
TO(4), KC_P, KC_Q, KC_R, KC_S, KC_T),
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO) };
LAYOUT(
TO(5), KC_U, KC_V, KC_W, KC_X, KC_Y),
LAYOUT(
TO(0), KC_Z, KC_1, KC_2, KC_3, KC_4)};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
//keyevent_t event = record->event;
switch (id)
{
case 0:
if (record->event.pressed)
{
return MACRO(T(T), T(G), T(L), T(H), T(F), T(ENT), END);
}
break;
case 1:
if (record->event.pressed)
{
return MACRO(T(T), T(G), T(G), T(ENT), END);
}
break;
case 2:
if (record->event.pressed)
{
return MACRO(D(NO), T(L), U(NO), END);
}
break;
case 3:
if (record->event.pressed)
{
return MACRO(D(LCTL), T(Z), U(LCTL), END);
}
break;
case 4:
if (record->event.pressed)
{
return MACRO(D(LCTL), D(LSFT), T(Z), U(LSFT), U(LCTL), END);
}
break;
case 5:
if (record->event.pressed)
{
return MACRO(D(LCTL), T(X), U(LCTL), END);
}
break;
case 6:
if (record->event.pressed)
{
return MACRO(D(LCTL), T(C), U(LCTL), END);
}
break;
case 7:
if (record->event.pressed)
{
return MACRO(D(LCTL), T(V), U(LCTL), END);
}
break;
}
return MACRO_NONE;
}
// M6-A LEDs are connected to D6, B6, F5, B4, C7, F7
// This is 1-based because I copied it from Knops code.
void set_switch_led(int ledId, bool state)
{
if (state)
{
switch (ledId)
{
case 1:
PORTD |= (1 << 6);
break;
case 2:
PORTB |= (1 << 6);
break;
case 3:
PORTF |= (1 << 5);
break;
case 4:
PORTB |= (1 << 4);
break;
case 5:
PORTC |= (1 << 7);
break;
case 6:
PORTF |= (1 << 7);
break;
}
}
else
{
switch (ledId)
{
case 1:
PORTD &= ~(1 << 6);
break;
case 2:
PORTB &= ~(1 << 6);
break;
case 3:
PORTF &= ~(1 << 5);
break;
case 4:
PORTB &= ~(1 << 4);
break;
case 5:
PORTC &= ~(1 << 7);
break;
case 6:
PORTF &= ~(1 << 7);
break;
}
}
}
void set_layer_led(int layerId)
{
// UNUSED
}
void led_set_layer(int layer);
void matrix_init_user(void)
{
led_init_ports();
led_set_layer(0);
}
void matrix_scan_user(void)
{
}
// M6-A LEDs are connected to D6, B6, F5, B4, C7, F7
void led_init_ports()
{
// Switch #1
DDRD |= (1 << 6);
PORTD &= ~(1 << 6);
// Switch #2
DDRB |= (1 << 6);
PORTB &= ~(1 << 6);
// Switch #3
DDRF |= (1 << 5);
PORTF &= ~(1 << 5);
// Switch #4
DDRB |= (1 << 4);
PORTB &= ~(1 << 4);
// Switch #5
DDRC |= (1 << 7);
PORTC &= ~(1 << 7);
// Switch #6
DDRF |= (1 << 7);
PORTF &= ~(1 << 7);
}
void led_set_user(uint8_t usb_led)
{
if (usb_led & (1 << USB_LED_NUM_LOCK))
{
}
else
{
}
if (usb_led & (1 << USB_LED_CAPS_LOCK))
{
}
else
{
}
if (usb_led & (1 << USB_LED_SCROLL_LOCK))
{
}
else
{
}
if (usb_led & (1 << USB_LED_COMPOSE))
{
}
else
{
}
if (usb_led & (1 << USB_LED_KANA))
{
}
else
{
}
}
void led_set_layer(int layer)
{
switch (layer)
{
case 0:
set_switch_led(1, true);
set_switch_led(2, false);
set_switch_led(3, false);
set_switch_led(4, false);
set_switch_led(5, false);
set_switch_led(6, false);
break;
case 1:
set_switch_led(1, false);
set_switch_led(2, true);
set_switch_led(3, false);
set_switch_led(4, false);
set_switch_led(5, false);
set_switch_led(6, false);
break;
case 2:
set_switch_led(1, false);
set_switch_led(2, false);
set_switch_led(3, true);
set_switch_led(4, false);
set_switch_led(5, false);
set_switch_led(6, false);
break;
case 3:
set_switch_led(1, false);
set_switch_led(2, false);
set_switch_led(3, false);
set_switch_led(4, true);
set_switch_led(5, false);
set_switch_led(6, false);
break;
case 4:
set_switch_led(1, false);
set_switch_led(2, false);
set_switch_led(3, false);
set_switch_led(4, false);
set_switch_led(5, true);
set_switch_led(6, false);
break;
case 5:
set_switch_led(1, false);
set_switch_led(2, false);
set_switch_led(3, false);
set_switch_led(4, false);
set_switch_led(5, false);
set_switch_led(6, true);
break;
default:
set_switch_led(1, true);
set_switch_led(2, true);
set_switch_led(3, true);
set_switch_led(4, true);
set_switch_led(5, true);
set_switch_led(6, true);
break;
}
}
bool process_record_user(uint16_t keycode, keyrecord_t *record)
{
switch (keycode)
{
case TO(0):
if (record->event.pressed)
{
led_set_layer(0);
}
break;
case TO(1):
if (record->event.pressed)
{
led_set_layer(1);
}
break;
case TO(2):
if (record->event.pressed)
{
led_set_layer(2);
}
break;
case TO(3):
if (record->event.pressed)
{
led_set_layer(3);
}
break;
case TO(4):
if (record->event.pressed)
{
led_set_layer(4);
}
break;
case TO(5):
if (record->event.pressed)
{
led_set_layer(5);
}
break;
}
return true;
}

View File

@ -1,4 +1,4 @@
/* Copyright 2018 Wilba
/* Copyright 2018 Jason Williams (Wilba)
*
* 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,3 @@
* 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 "m6_a.h"
/*
void matrix_init_kb(void) {
// put your keyboard start-up code here
// runs once when the firmware starts up
matrix_init_user();
}
void matrix_scan_kb(void) {
// put your looping keyboard code here
// runs every cycle (a lot)
matrix_scan_user();
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
// put your per-action keyboard code here
// runs for every action, just before processing by the firmware
return process_record_user(keycode, record);
}
void led_set_kb(uint8_t usb_led) {
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
led_set_user(usb_led);
}
*/

View File

@ -12,4 +12,4 @@ Make example for this keyboard (after setting up your build environment):
make rama/m6_a:default
See [build environment setup](https://docs.qmk.fm/build_environment_setup.html) then the [make instructions](https://docs.qmk.fm/make_instructions.html) for more information.
See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).

View File

@ -1,5 +1,7 @@
# project specific files
SRC = keyboards/rama/m6_b/m6_b.c
# MCU name
#MCU = at90usb1286
MCU = atmega32u4
# Processor frequency.
@ -38,31 +40,27 @@ F_USB = $(F_CPU)
# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# Boot Section Size in *bytes*
# Teensy halfKay 512
# Teensy++ halfKay 1024
# Atmel DFU loader 4096
# LUFA bootloader 4096
# USBaspLoader 2048
OPT_DEFS += -DBOOTLOADER_SIZE=4096
# Boot Section
BOOTLOADER = atmel-dfu
# Build Options
# change yes to no to disable
#
BOOTMAGIC_ENABLE ?= no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE ?= yes # Mouse keys(+4700)
EXTRAKEY_ENABLE ?= yes # Audio control and System control(+450)
CONSOLE_ENABLE ?= yes # Console for debug(+400)
COMMAND_ENABLE ?= yes # Commands for debug and configuration
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400)
COMMAND_ENABLE = no # Commands for debug and configuration
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE ?= no # Breathing sleep LED during USB suspend
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
NKRO_ENABLE ?= no # USB Nkey Rollover
BACKLIGHT_ENABLE ?= no # Enable keyboard backlight functionality on B7 by default
MIDI_ENABLE ?= no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE ?= no # Unicode
BLUETOOTH_ENABLE ?= no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE ?= no # Audio output on port C6
FAUXCLICKY_ENABLE ?= no # Use buzzer to emulate clicky switches
NKRO_ENABLE = yes # USB Nkey Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
RAW_ENABLE = yes
DYNAMIC_KEYMAP_ENABLE = yes

View File

@ -0,0 +1,129 @@
/* Copyright 2018 Jason Williams (Wilba)
*
* 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/>.
*/
#pragma once
#include "config_common.h"
/* USB Device descriptor parameter */
#define VENDOR_ID 0x5241 // "RW"
#define PRODUCT_ID 0x006B // 6-B
#define DEVICE_VER 0x0001
#define MANUFACTURER RAMA.WORKS
#define PRODUCT RAMA M6-B
#define DESCRIPTION RAMA M6-B Macropad
/* key matrix size */
#define MATRIX_ROWS 1
#define MATRIX_COLS 6
/*
* Keyboard Matrix Assignments
*
* Change this to how you wired your keyboard
* COLS: AVR pins used for columns, left to right
* ROWS: AVR pins used for rows, top to bottom
* DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
*
*/
#define MATRIX_ROW_PINS { E6 }
#define MATRIX_COL_PINS { D4, B5, F4, D7, C6, F6 }
#define UNUSED_PINS
/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
#define DIODE_DIRECTION COL2ROW
// #define BACKLIGHT_PIN B7
// #define BACKLIGHT_BREATHING
// #define BACKLIGHT_LEVELS 3
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
#define DEBOUNCING_DELAY 5
/* define if matrix has ghost (lacks anti-ghosting diodes) */
//#define MATRIX_HAS_GHOST
/* number of backlight levels */
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
#define LOCKING_SUPPORT_ENABLE
/* Locking resynchronize hack */
#define LOCKING_RESYNC_ENABLE
/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
* This is userful for the Windows task manager shortcut (ctrl+shift+esc).
*/
// #define GRAVE_ESC_CTRL_OVERRIDE
/*
* Force NKRO
*
* Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
* state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
* makefile for this to work.)
*
* If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
* until the next keyboard reset.
*
* NKRO may prevent your keystrokes from being detected in the BIOS, but it is
* fully operational during normal computer usage.
*
* For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
* or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
* bootmagic, NKRO mode will always be enabled until it is toggled again during a
* power-up.
*
*/
//#define FORCE_NKRO
/*
* Magic Key Options
*
* Magic keys are hotkey commands that allow control over firmware functions of
* the keyboard. They are best used in combination with the HID Listen program,
* found here: https://www.pjrc.com/teensy/hid_listen.html
*
* The options below allow the magic key functionality to be changed. This is
* useful if your keyboard/keypad is missing keys and you want magic key support.
*
*/
/* key combination for magic key command */
#define IS_COMMAND() ( \
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
)
#define RGB_BACKLIGHT_ENABLED 1
#define DYNAMIC_KEYMAP_LAYER_COUNT 4
// EEPROM usage
// TODO: refactor with new user EEPROM code (coming soon)
#define EEPROM_MAGIC 0x451F
#define EEPROM_MAGIC_ADDR 32
// Bump this every time we change what we store
// This will automatically reset the EEPROM with defaults
// and avoid loading invalid data from the EEPROM
#define EEPROM_VERSION 0x07
#define EEPROM_VERSION_ADDR 34
// Backlight config starts after EEPROM version
#define RGB_BACKLIGHT_CONFIG_EEPROM_ADDR 35
// Dynamic keymap starts after backlight config (35+37)
#define DYNAMIC_KEYMAP_EEPROM_ADDR 72

View File

@ -0,0 +1,19 @@
{
"keyboard_name": "m6-b",
"url": "",
"maintainer": "qmk",
"width": 3,
"height": 2,
"layouts": {
"LAYOUT": {
"layout": [
{ "x": 0, "y": 0 },
{ "x": 1, "y": 0 },
{ "x": 2, "y": 0 },
{ "x": 0, "y": 1 },
{ "x": 1, "y": 1 },
{ "x": 2, "y": 1 }
]
}
}
}

View File

@ -0,0 +1,16 @@
#include QMK_KEYBOARD_H
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
LAYOUT(
KC_1, KC_2, KC_3, KC_4, KC_5, KC_6),
LAYOUT(
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO),
LAYOUT(
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO),
LAYOUT(
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO) };

View File

@ -0,0 +1,230 @@
/* Copyright 2018 Jason Williams (Wilba)
*
* 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 "m6_b.h"
#include "m6_b_api.h"
// Check that no backlight functions are called
#if RGB_BACKLIGHT_ENABLED
#include "rgb_backlight.h"
#endif // RGB_BACKLIGHT_ENABLED
#include "raw_hid.h"
#include "dynamic_keymap.h"
#include "timer.h"
#include "tmk_core/common/eeprom.h"
bool eeprom_is_valid(void)
{
return (eeprom_read_word(((void*)EEPROM_MAGIC_ADDR)) == EEPROM_MAGIC &&
eeprom_read_byte(((void*)EEPROM_VERSION_ADDR)) == EEPROM_VERSION);
}
void eeprom_set_valid(bool valid)
{
eeprom_update_word(((void*)EEPROM_MAGIC_ADDR), valid ? EEPROM_MAGIC : 0xFFFF);
eeprom_update_byte(((void*)EEPROM_VERSION_ADDR), valid ? EEPROM_VERSION : 0xFF);
}
void eeprom_reset(void)
{
// Set the keyboard-specific EEPROM state as invalid.
eeprom_set_valid(false);
// Set the TMK/QMK EEPROM state as invalid.
eeconfig_disable();
}
#ifdef RAW_ENABLE
void raw_hid_receive( uint8_t *data, uint8_t length )
{
uint8_t *command_id = &(data[0]);
uint8_t *command_data = &(data[1]);
switch ( *command_id )
{
case id_get_protocol_version:
{
command_data[0] = PROTOCOL_VERSION >> 8;
command_data[1] = PROTOCOL_VERSION & 0xFF;
break;
}
case id_get_keyboard_value:
{
if ( command_data[0] == id_uptime )
{
uint32_t value = timer_read32();
command_data[1] = (value >> 24 ) & 0xFF;
command_data[2] = (value >> 16 ) & 0xFF;
command_data[3] = (value >> 8 ) & 0xFF;
command_data[4] = value & 0xFF;
}
else
{
*command_id = id_unhandled;
}
break;
}
#ifdef DYNAMIC_KEYMAP_ENABLE
case id_dynamic_keymap_get_keycode:
{
uint16_t keycode = dynamic_keymap_get_keycode( command_data[0], command_data[1], command_data[2] );
command_data[3] = keycode >> 8;
command_data[4] = keycode & 0xFF;
break;
}
case id_dynamic_keymap_set_keycode:
{
dynamic_keymap_set_keycode( command_data[0], command_data[1], command_data[2], ( command_data[3] << 8 ) | command_data[4] );
break;
}
case id_dynamic_keymap_reset:
{
dynamic_keymap_reset();
break;
}
#endif // DYNAMIC_KEYMAP_ENABLE
#if RGB_BACKLIGHT_ENABLED
case id_backlight_config_set_value:
{
//backlight_config_set_value(command_data);
break;
}
case id_backlight_config_get_value:
{
//backlight_config_get_value(command_data);
break;
}
case id_backlight_config_save:
{
//backlight_config_save();
break;
}
#endif // RGB_BACKLIGHT_ENABLED
case id_eeprom_reset:
{
eeprom_reset();
break;
}
case id_bootloader_jump:
{
// Need to send data back before the jump
// Informs host that the command is handled
raw_hid_send( data, length );
// Give host time to read it
wait_ms(100);
bootloader_jump();
break;
}
default:
{
// Unhandled message.
*command_id = id_unhandled;
break;
}
}
// Return same buffer with values changed
raw_hid_send( data, length );
}
#endif
void main_init(void)
{
// If the EEPROM has the magic, the data is good.
// OK to load from EEPROM.
if (eeprom_is_valid()) {
#if RGB_BACKLIGHT_ENABLED
//backlight_config_load();
#endif // RGB_BACKLIGHT_ENABLED
} else {
#if RGB_BACKLIGHT_ENABLED
// If the EEPROM has not been saved before, or is out of date,
// save the default values to the EEPROM. Default values
// come from construction of the zeal_backlight_config instance.
//backlight_config_save();
#endif // RGB_BACKLIGHT_ENABLED
#ifdef DYNAMIC_KEYMAP_ENABLE
// This resets the keymaps in EEPROM to what is in flash.
dynamic_keymap_reset();
#endif
// Save the magic number last, in case saving was interrupted
eeprom_set_valid(true);
}
#if RGB_BACKLIGHT_ENABLED
// Initialize LED drivers for backlight.
backlight_init_drivers();
backlight_timer_init();
backlight_timer_enable();
#endif // RGB_BACKLIGHT_ENABLED
}
void bootmagic_lite(void)
{
// The lite version of TMK's bootmagic.
// 100% less potential for accidentally making the
// keyboard do stupid things.
// We need multiple scans because debouncing can't be turned off.
matrix_scan();
wait_ms(DEBOUNCING_DELAY);
wait_ms(DEBOUNCING_DELAY);
matrix_scan();
// If the Esc (matrix 0,0) is held down on power up,
// reset the EEPROM valid state and jump to bootloader.
if ( matrix_get_row(0) & (1<<0) ) {
eeprom_reset();
bootloader_jump();
}
}
void matrix_init_kb(void) {
bootmagic_lite();
main_init();
matrix_init_user();
}
void matrix_scan_kb(void) {
#if RGB_BACKLIGHT_ENABLED
// This only updates the LED driver buffers if something has changed.
backlight_update_pwm_buffers();
#endif // BACKLIGHT_ENABLED
matrix_scan_user();
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
return process_record_user(keycode, record);
}
void led_set_kb(uint8_t usb_led) {
led_set_user(usb_led);
}
void suspend_power_down_kb(void)
{
#if RGB_BACKLIGHT_ENABLED
//backlight_set_suspend_state(true);
#endif // BACKLIGHT_ENABLED
}
void suspend_wakeup_init_kb(void)
{
#if RGB_BACKLIGHT_ENABLED
//backlight_set_suspend_state(false);
#endif // BACKLIGHT_ENABLED
}

View File

@ -0,0 +1,28 @@
/* Copyright 2018 Jason Williams (Wilba)
*
* 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/>.
*/
#pragma once
#include "quantum.h"
// This a shortcut to help you visually see your layout.
// The first section contains all of the arguments
// The second converts the arguments into a two-dimensional array
#define LAYOUT( \
K00, K01, K02, K03, K04, K05) \
{ \
{K00, K01, K02, K03, K04, K05}, \
}

View File

@ -0,0 +1,39 @@
/* Copyright 2017 Jason Williams (Wilba)
*
* 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/>.
*/
#pragma once
#define PROTOCOL_VERSION 0x0001
enum m6_b_command_id
{
id_get_protocol_version = 0x01, // always 0x01
id_get_keyboard_value,
id_set_keyboard_value,
id_dynamic_keymap_get_keycode,
id_dynamic_keymap_set_keycode,
id_dynamic_keymap_reset,
id_backlight_config_set_value,
id_backlight_config_get_value,
id_backlight_config_save,
id_eeprom_reset,
id_bootloader_jump,
id_unhandled = 0xFF,
};
enum m6_b_keyboard_value_id
{
id_uptime = 0x01
};

View File

@ -0,0 +1,15 @@
# RAMA M6-B
![RAMA M6-B](https://static1.squarespace.com/static/563c788ae4b099120ae219e2/t/59fc7b1053450adf5bf9a852/1515932239307/RAMA-RAMA-M6-DSA-XO-CAPS.73-3_1.jpg?format=1500w)
A 6-key companion keyboard. [More info at RAMA WORKS](https://rama.works/m6a)
Keyboard Maintainer: [Wilba6582](https://github.com/Wilba6582)
Hardware Supported: RAMA M6-B PCB
Hardware Availability: [RAMA WORKS Store](https://ramaworks.store/)
Make example for this keyboard (after setting up your build environment):
make rama/m6_b:default
See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs).

View File

@ -0,0 +1,139 @@
/* Copyright 2018 Jason Williams (Wilba)
*
* 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/>.
*/
#if RGB_BACKLIGHT_ENABLED
#include "rgb_backlight.h"
//#include "rgb_backlight_api.h"
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "progmem.h"
#include "quantum/color.h"
#include "drivers/avr/i2c_master.h"
#include "drivers/issi/is31fl3218.h"
bool g_suspend_state = false;
// Global tick at 20 Hz
uint32_t g_tick = 0;
uint8_t g_config_effect_speed = 0;
uint8_t g_config_brightness = 255;
void backlight_update_pwm_buffers(void)
{
IS31FL3218_update_pwm_buffers();
}
void backlight_set_color( int index, uint8_t red, uint8_t green, uint8_t blue )
{
IS31FL3218_set_color( index, red, green, blue );
}
void backlight_set_color_all( uint8_t red, uint8_t green, uint8_t blue )
{
IS31FL3218_set_color_all( red, green, blue );
}
// This is (F_CPU/1024) / 20 Hz
// = 15625 Hz / 20 Hz
// = 781
#define TIMER3_TOP 260
void backlight_timer_init(void)
{
static uint8_t backlight_timer_is_init = 0;
if ( backlight_timer_is_init )
{
return;
}
backlight_timer_is_init = 1;
// Timer 3 setup
TCCR3B = _BV(WGM32) | // CTC mode OCR3A as TOP
_BV(CS32) | _BV(CS30); // prescale by /1024
// Set TOP value
uint8_t sreg = SREG;
cli();
OCR3AH = (TIMER3_TOP >> 8) & 0xff;
OCR3AL = TIMER3_TOP & 0xff;
SREG = sreg;
}
void backlight_timer_enable(void)
{
TIMSK3 |= _BV(OCIE3A);
}
void backlight_timer_disable(void)
{
TIMSK3 &= ~_BV(OCIE3A);
}
void backlight_set_suspend_state(bool state)
{
g_suspend_state = state;
}
void backlight_effect_cycle_all(void)
{
uint8_t hueOffset = ( g_tick << g_config_effect_speed ) & 0xFF;
uint8_t satOffset = 127;
// Relies on hue being 8-bit and wrapping
for ( int i=0; i<6; i++ )
{
HSV hsv = { .h = hueOffset, .s = satOffset, .v = g_config_brightness };
RGB rgb = hsv_to_rgb( hsv );
backlight_set_color( i, rgb.r, rgb.g, rgb.b );
}
}
ISR(TIMER3_COMPA_vect)
{
// delay 1 second before driving LEDs or doing anything else
static uint8_t startup_tick = 0;
if ( startup_tick < 20 )
{
startup_tick++;
return;
}
g_tick++;
if ( g_suspend_state )
{
backlight_set_color_all( 0, 0, 0 );
}
else
{
//HSV hsv = { .h = 240, .s = 255, .v = g_config_brightness };
//RGB rgb = hsv_to_rgb( hsv );
//backlight_set_color_all( rgb.r, rgb.g, rgb.b );
backlight_effect_cycle_all();
}
}
void backlight_init_drivers(void)
{
// Initialize I2C
i2c_init();
IS31FL3218_init();
}
#endif // RGB_BACKLIGHT_ENABLED

View File

@ -0,0 +1,34 @@
/* Copyright 2018 Jason Williams (Wilba)
*
* 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/>.
*/
#pragma once
#if RGB_BACKLIGHT_ENABLED
#else
#error rgb_backlight.h included when RGB_BACKLIGHT_ENABLED == 0
#endif // RGB_BACKLIGHT_ENABLED
#include <stdint.h>
#include <stdbool.h>
#include "quantum/color.h"
void backlight_init_drivers(void);
void backlight_update_pwm_buffers(void);
void backlight_timer_init(void);
void backlight_timer_enable(void);
void backlight_timer_disable(void);
void backlight_set_suspend_state(bool state);

View File

@ -0,0 +1,77 @@
# project specific files
SRC = rgb_backlight.c \
quantum/color.c \
drivers/issi/is31fl3218.c \
drivers/avr/i2c_master.c
# MCU name
MCU = atmega32u4
# Processor frequency.
# This will define a symbol, F_CPU, in all source code files equal to the
# processor frequency in Hz. You can then use this symbol in your source code to
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
# automatically to create a 32-bit value in your source code.
#
# This will be an integer division of F_USB below, as it is sourced by
# F_USB after it has run through any CPU prescalers. Note that this value
# does not *change* the processor frequency - it should merely be updated to
# reflect the processor speed set externally so that the code can use accurate
# software delays.
F_CPU = 16000000
#
# LUFA specific
#
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Input clock frequency.
# This will define a symbol, F_USB, in all source code files equal to the
# input clock frequency (before any prescaling is performed) in Hz. This value may
# differ from F_CPU if prescaling is used on the latter, and is required as the
# raw input clock is fed directly to the PLL sections of the AVR for high speed
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
# at the end, this will be done automatically to create a 32-bit value in your
# source code.
#
# If no clock division is performed on the input clock inside the AVR (via the
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
F_USB = $(F_CPU)
# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
# Boot Section
BOOTLOADER = atmel-dfu
# Do not put the microcontroller into power saving mode
# when we get USB suspend event. We want it to keep updating
# backlight effects.
OPT_DEFS += -DNO_SUSPEND_POWER_DOWN
# Build Options
# change yes to no to disable
#
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = no # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = no # Console for debug(+400)
COMMAND_ENABLE = no # Commands for debug and configuration
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
NKRO_ENABLE = yes # USB Nkey Rollover
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
AUDIO_ENABLE = no # Audio output on port C6
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
RAW_ENABLE = yes
DYNAMIC_KEYMAP_ENABLE = yes
CIE1931_CURVE = yes