1
0
Fork 0

Add support for LFKeyboard products: LFK78, LFK87 and SMK65

This commit is contained in:
Scott Wilson 2017-12-03 10:32:07 -05:00 committed by Jack Humbert
parent 8b1862330a
commit c51dfef958
37 changed files with 3180 additions and 0 deletions

View File

@ -0,0 +1,283 @@
/*
* TWIlib.c
*
* Created: 6/01/2014 10:41:33 PM
* Author: Chris Herring
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include "TWIlib.h"
#include "util/delay.h"
#include "print.h"
void TWIInit()
{
TWIInfo.mode = Ready;
TWIInfo.errorCode = 0xFF;
TWIInfo.repStart = 0;
// Set pre-scalers (no pre-scaling)
TWSR = 0;
// Set bit rate
TWBR = ((F_CPU / TWI_FREQ) - 16) / 2;
// Enable TWI and interrupt
TWCR = (1 << TWIE) | (1 << TWEN);
}
uint8_t isTWIReady()
{
if ( (TWIInfo.mode == Ready) | (TWIInfo.mode == RepeatedStartSent) )
{
return 1;
}
else
{
if(TWIInfo.mode == Initializing){
switch(TWIInfo.errorCode){
case TWI_SUCCESS:
case TWI_NO_RELEVANT_INFO:
break;
case TWI_LOST_ARBIT:
case TWI_MT_DATA_NACK:
// Some kind of I2C error, reset and re-init
xprintf("I2C init error: %d\n", TWIInfo.errorCode);
TWCR = (1 << TWINT)|(1 << TWSTO);
TWIInit();
break;
default:
xprintf("Other i2c init error: %d\n", TWIInfo.errorCode);
}
}
return 0;
}
}
void TWITransmitData(void *const TXdata, uint8_t dataLen, uint8_t repStart, uint8_t blocking)
{
// Wait until ready
while (!isTWIReady()) {_delay_us(1);}
// Reset the I2C stuff
TWCR = (1 << TWINT)|(1 << TWSTO);
TWIInit();
// Set repeated start mode
TWIInfo.repStart = repStart;
// Copy transmit info to global variables
TWITransmitBuffer = (uint8_t *)TXdata;
TXBuffLen = dataLen;
TXBuffIndex = 0;
// If a repeated start has been sent, then devices are already listening for an address
// and another start does not need to be sent.
if (TWIInfo.mode == RepeatedStartSent)
{
TWIInfo.mode = Initializing;
TWDR = TWITransmitBuffer[TXBuffIndex++]; // Load data to transmit buffer
TWISendTransmit(); // Send the data
}
else // Otherwise, just send the normal start signal to begin transmission.
{
TWIInfo.mode = Initializing;
TWISendStart();
}
if(blocking){
// Wait until ready
while (!isTWIReady()){_delay_us(1);}
}
}
// uint8_t TWITransmitData(void *const TXdata, uint8_t dataLen, uint8_t repStart)
// {
// if (dataLen <= TXMAXBUFLEN)
// {
// // Wait until ready
// while (!isTWIReady()) {_delay_us(1);}
// // Set repeated start mode
// TWIInfo.repStart = repStart;
// // Copy data into the transmit buffer
// uint8_t *data = (uint8_t *)TXdata;
// for (int i = 0; i < dataLen; i++)
// {
// TWITransmitBuffer[i] = data[i];
// }
// // Copy transmit info to global variables
// TXBuffLen = dataLen;
// TXBuffIndex = 0;
// // If a repeated start has been sent, then devices are already listening for an address
// // and another start does not need to be sent.
// if (TWIInfo.mode == RepeatedStartSent)
// {
// TWIInfo.mode = Initializing;
// TWDR = TWITransmitBuffer[TXBuffIndex++]; // Load data to transmit buffer
// TWISendTransmit(); // Send the data
// }
// else // Otherwise, just send the normal start signal to begin transmission.
// {
// TWIInfo.mode = Initializing;
// TWISendStart();
// }
// }
// else
// {
// return 1; // return an error if data length is longer than buffer
// }
// return 0;
// }
uint8_t TWIReadData(uint8_t TWIaddr, uint8_t bytesToRead, uint8_t repStart)
{
// Check if number of bytes to read can fit in the RXbuffer
if (bytesToRead < RXMAXBUFLEN)
{
// Reset buffer index and set RXBuffLen to the number of bytes to read
RXBuffIndex = 0;
RXBuffLen = bytesToRead;
// Create the one value array for the address to be transmitted
uint8_t TXdata[1];
// Shift the address and AND a 1 into the read write bit (set to write mode)
TXdata[0] = (TWIaddr << 1) | 0x01;
// Use the TWITransmitData function to initialize the transfer and address the slave
TWITransmitData(TXdata, 1, repStart, 0);
}
else
{
return 0;
}
return 1;
}
ISR (TWI_vect)
{
switch (TWI_STATUS)
{
// ----\/ ---- MASTER TRANSMITTER OR WRITING ADDRESS ----\/ ---- //
case TWI_MT_SLAW_ACK: // SLA+W transmitted and ACK received
// Set mode to Master Transmitter
TWIInfo.mode = MasterTransmitter;
case TWI_START_SENT: // Start condition has been transmitted
case TWI_MT_DATA_ACK: // Data byte has been transmitted, ACK received
if (TXBuffIndex < TXBuffLen) // If there is more data to send
{
TWDR = TWITransmitBuffer[TXBuffIndex++]; // Load data to transmit buffer
TWIInfo.errorCode = TWI_NO_RELEVANT_INFO;
TWISendTransmit(); // Send the data
}
// This transmission is complete however do not release bus yet
else if (TWIInfo.repStart)
{
TWIInfo.errorCode = 0xFF;
TWISendStart();
}
// All transmissions are complete, exit
else
{
TWIInfo.mode = Ready;
TWIInfo.errorCode = 0xFF;
TWISendStop();
}
break;
// ----\/ ---- MASTER RECEIVER ----\/ ---- //
case TWI_MR_SLAR_ACK: // SLA+R has been transmitted, ACK has been received
// Switch to Master Receiver mode
TWIInfo.mode = MasterReceiver;
// If there is more than one byte to be read, receive data byte and return an ACK
if (RXBuffIndex < RXBuffLen-1)
{
TWIInfo.errorCode = TWI_NO_RELEVANT_INFO;
TWISendACK();
}
// Otherwise when a data byte (the only data byte) is received, return NACK
else
{
TWIInfo.errorCode = TWI_NO_RELEVANT_INFO;
TWISendNACK();
}
break;
case TWI_MR_DATA_ACK: // Data has been received, ACK has been transmitted.
/// -- HANDLE DATA BYTE --- ///
TWIReceiveBuffer[RXBuffIndex++] = TWDR;
// If there is more than one byte to be read, receive data byte and return an ACK
if (RXBuffIndex < RXBuffLen-1)
{
TWIInfo.errorCode = TWI_NO_RELEVANT_INFO;
TWISendACK();
}
// Otherwise when a data byte (the only data byte) is received, return NACK
else
{
TWIInfo.errorCode = TWI_NO_RELEVANT_INFO;
TWISendNACK();
}
break;
case TWI_MR_DATA_NACK: // Data byte has been received, NACK has been transmitted. End of transmission.
/// -- HANDLE DATA BYTE --- ///
TWIReceiveBuffer[RXBuffIndex++] = TWDR;
// This transmission is complete however do not release bus yet
if (TWIInfo.repStart)
{
TWIInfo.errorCode = 0xFF;
TWISendStart();
}
// All transmissions are complete, exit
else
{
TWIInfo.mode = Ready;
TWIInfo.errorCode = 0xFF;
TWISendStop();
}
break;
// ----\/ ---- MT and MR common ----\/ ---- //
case TWI_MR_SLAR_NACK: // SLA+R transmitted, NACK received
case TWI_MT_SLAW_NACK: // SLA+W transmitted, NACK received
case TWI_MT_DATA_NACK: // Data byte has been transmitted, NACK received
case TWI_LOST_ARBIT: // Arbitration has been lost
// Return error and send stop and set mode to ready
if (TWIInfo.repStart)
{
TWIInfo.errorCode = TWI_STATUS;
TWISendStart();
}
// All transmissions are complete, exit
else
{
TWIInfo.mode = Ready;
TWIInfo.errorCode = TWI_STATUS;
TWISendStop();
}
break;
case TWI_REP_START_SENT: // Repeated start has been transmitted
// Set the mode but DO NOT clear TWINT as the next data is not yet ready
TWIInfo.mode = RepeatedStartSent;
break;
// ----\/ ---- SLAVE RECEIVER ----\/ ---- //
// TODO IMPLEMENT SLAVE RECEIVER FUNCTIONALITY
// ----\/ ---- SLAVE TRANSMITTER ----\/ ---- //
// TODO IMPLEMENT SLAVE TRANSMITTER FUNCTIONALITY
// ----\/ ---- MISCELLANEOUS STATES ----\/ ---- //
case TWI_NO_RELEVANT_INFO: // It is not really possible to get into this ISR on this condition
// Rather, it is there to be manually set between operations
break;
case TWI_ILLEGAL_START_STOP: // Illegal START/STOP, abort and return error
TWIInfo.errorCode = TWI_ILLEGAL_START_STOP;
TWIInfo.mode = Ready;
TWISendStop();
break;
}
}

View File

@ -0,0 +1,81 @@
/*
* TWIlib.h
*
* Created: 6/01/2014 10:38:42 PM
* Author: Chris Herring
*/
#ifndef TWILIB_H_
#define TWILIB_H_
// TWI bit rate
#define TWI_FREQ 400000
// Get TWI status
#define TWI_STATUS (TWSR & 0xF8)
// Transmit buffer length
#define TXMAXBUFLEN 20
// Receive buffer length
#define RXMAXBUFLEN 20
// Global transmit buffer
volatile uint8_t *TWITransmitBuffer;
// Global receive buffer
volatile uint8_t TWIReceiveBuffer[RXMAXBUFLEN];
// Buffer indexes
volatile int TXBuffIndex; // Index of the transmit buffer. Is volatile, can change at any time.
int RXBuffIndex; // Current index in the receive buffer
// Buffer lengths
int TXBuffLen; // The total length of the transmit buffer
int RXBuffLen; // The total number of bytes to read (should be less than RXMAXBUFFLEN)
typedef enum {
Ready,
Initializing,
RepeatedStartSent,
MasterTransmitter,
MasterReceiver,
SlaceTransmitter,
SlaveReciever
} TWIMode;
typedef struct TWIInfoStruct{
TWIMode mode;
uint8_t errorCode;
uint8_t repStart;
}TWIInfoStruct;
TWIInfoStruct TWIInfo;
// TWI Status Codes
#define TWI_START_SENT 0x08 // Start sent
#define TWI_REP_START_SENT 0x10 // Repeated Start sent
// Master Transmitter Mode
#define TWI_MT_SLAW_ACK 0x18 // SLA+W sent and ACK received
#define TWI_MT_SLAW_NACK 0x20 // SLA+W sent and NACK received
#define TWI_MT_DATA_ACK 0x28 // DATA sent and ACK received
#define TWI_MT_DATA_NACK 0x30 // DATA sent and NACK received
// Master Receiver Mode
#define TWI_MR_SLAR_ACK 0x40 // SLA+R sent, ACK received
#define TWI_MR_SLAR_NACK 0x48 // SLA+R sent, NACK received
#define TWI_MR_DATA_ACK 0x50 // Data received, ACK returned
#define TWI_MR_DATA_NACK 0x58 // Data received, NACK returned
// Miscellaneous States
#define TWI_LOST_ARBIT 0x38 // Arbitration has been lost
#define TWI_NO_RELEVANT_INFO 0xF8 // No relevant information available
#define TWI_ILLEGAL_START_STOP 0x00 // Illegal START or STOP condition has been detected
#define TWI_SUCCESS 0xFF // Successful transfer, this state is impossible from TWSR as bit2 is 0 and read only
#define TWISendStart() (TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN)|(1<<TWIE)) // Send the START signal, enable interrupts and TWI, clear TWINT flag to resume transfer.
#define TWISendStop() (TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN)|(1<<TWIE)) // Send the STOP signal, enable interrupts and TWI, clear TWINT flag.
#define TWISendTransmit() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)) // Used to resume a transfer, clear TWINT and ensure that TWI and interrupts are enabled.
#define TWISendACK() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)|(1<<TWEA)) // FOR MR mode. Resume a transfer, ensure that TWI and interrupts are enabled and respond with an ACK if the device is addressed as a slave or after it receives a byte.
#define TWISendNACK() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)) // FOR MR mode. Resume a transfer, ensure that TWI and interrupts are enabled but DO NOT respond with an ACK if the device is addressed as a slave or after it receives a byte.
// Function declarations
void TWITransmitData(void *const TXdata, uint8_t dataLen, uint8_t repStart, uint8_t blocking);
void TWIInit(void);
uint8_t TWIReadData(uint8_t TWIaddr, uint8_t bytesToRead, uint8_t repStart);
uint8_t isTWIReady(void);
#endif // TWICOMMS_H_

View File

@ -0,0 +1,244 @@
#ifdef ISSI_ENABLE
#include <stdlib.h>
#include <stdint.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
#include <avr/io.h>
#include <util/twi.h>
#include "issi.h"
#include "print.h"
#include "TWIlib.h"
#define ISSI_ADDR_DEFAULT 0xE8
#define ISSI_REG_CONFIG 0x00
#define ISSI_REG_CONFIG_PICTUREMODE 0x00
#define ISSI_REG_CONFIG_AUTOPLAYMODE 0x08
#define ISSI_CONF_PICTUREMODE 0x00
#define ISSI_CONF_AUTOFRAMEMODE 0x04
#define ISSI_CONF_AUDIOMODE 0x08
#define ISSI_REG_PICTUREFRAME 0x01
#define ISSI_REG_SHUTDOWN 0x0A
#define ISSI_REG_AUDIOSYNC 0x06
#define ISSI_COMMANDREGISTER 0xFD
#define ISSI_BANK_FUNCTIONREG 0x0B // helpfully called 'page nine'
uint8_t control[8][9] = {
{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0},
};
ISSIDeviceStruct *issi_devices[4] = {0, 0, 0, 0};
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
#define I2C_WRITE 0
#define F_SCL 400000UL // SCL frequency
#define Prescaler 1
#define TWBR_val ((((F_CPU / F_SCL) / Prescaler) - 16 ) / 2)
uint8_t i2c_start(uint8_t address)
{
// reset TWI control register
TWCR = 0;
// transmit START condition
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
// wait for end of transmission
while( !(TWCR & (1<<TWINT)) );
// check if the start condition was successfully transmitted
if((TWSR & 0xF8) != TW_START){ return 1; }
// load slave address into data register
TWDR = address;
// start transmission of address
TWCR = (1<<TWINT) | (1<<TWEN);
// wait for end of transmission
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;
}
uint8_t i2c_write(uint8_t data)
{
// load data into data register
TWDR = data;
// start transmission of data
TWCR = (1 << TWINT) | (1 << TWEN);
// wait for end of transmission
while (!(TWCR & (1 << TWINT)))
;
if ((TWSR & 0xF8) != TW_MT_DATA_ACK) {
return 1;
}
return 0;
}
uint8_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length)
{
TWBR = (uint8_t)TWBR_val;
if (i2c_start(address | I2C_WRITE))
return 1;
for (uint16_t i = 0; i < length; i++) {
if (i2c_write(data[i]))
return 1;
}
// transmit STOP condition
TWCR = (1 << TWINT) | (1 << TWEN) | (1 << TWSTO);
return 0;
}
void setFrame(uint8_t device, uint8_t frame)
{
static uint8_t current_frame = -1;
if(current_frame != frame){
uint8_t payload[] = {
ISSI_ADDR_DEFAULT | device << 1,
ISSI_COMMANDREGISTER,
frame
};
TWITransmitData(payload, sizeof(payload), 0, 1);
}
// static uint8_t current_frame = 0xFF;
// if(current_frame == frame){
// // return;
// }
// uint8_t payload[2] = { ISSI_COMMANDREGISTER, frame };
// i2c_transmit(ISSI_ADDR_DEFAULT | device << 1, payload, 2);
// current_frame = frame;
}
void writeRegister8(uint8_t device, uint8_t frame, uint8_t reg, uint8_t data)
{
// Set the frame
setFrame(device, frame);
// Write to the register
uint8_t payload[] = {
ISSI_ADDR_DEFAULT | device << 1,
reg,
data
};
TWITransmitData(payload, sizeof(payload), 0, 1);
}
void activateLED(uint8_t matrix, uint8_t cx, uint8_t cy, uint8_t pwm)
{
uint8_t device_addr = (matrix & 0x06) >> 1;
ISSIDeviceStruct *device = issi_devices[device_addr];
if(device == 0){
return;
}
// xprintf("activeLED: %02X %02X %02X %02X\n", matrix, cy, cx, pwm);
uint8_t x = cx - 1; // funciton takes 1 based counts, but we need 0...
uint8_t y = cy - 1; // creating them once for less confusion
uint8_t control_reg = (y << 1) | (matrix & 0x01);
if(pwm == 0){
cbi(device->led_ctrl[control_reg], x);
cbi(device->led_blink_ctrl[control_reg], x);
}else{
sbi(device->led_ctrl[control_reg], x);
sbi(device->led_blink_ctrl[control_reg], x);
}
uint8_t pwm_reg = 0;
switch(matrix & 0x01){
case 0:
pwm_reg = 0x00;
break;
case 1:
pwm_reg = 0x08;
break;
}
pwm_reg += (y << 4) + x;
device->led_pwm[pwm_reg] = pwm;
device->led_dirty = 1;
}
void update_issi(uint8_t device_addr, uint8_t blocking)
{
// This seems to take about 6ms
ISSIDeviceStruct *device = issi_devices[device_addr];
if(device != 0){
if(device->fn_dirty){
device->fn_dirty = 0;
setFrame(device_addr, ISSI_BANK_FUNCTIONREG);
TWITransmitData(&device->fn_device_addr, sizeof(device->fn_registers) + 2, 0, 1);
}
if(device->led_dirty){
device->led_dirty = 0;
setFrame(device_addr, 0);
TWITransmitData(&device->led_device_addr, 0xB6, 0, blocking);
}
}
}
void issi_init(void)
{
TWIInit();
for(uint8_t device_addr = 0; device_addr < 4; device_addr++){
// If this device has been previously allocated, free it
if(issi_devices[device_addr] != 0){
free(issi_devices[device_addr]);
}
// Try to shutdown the device, if this fails skip this device
writeRegister8(device_addr, ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x00);
while (!isTWIReady()){_delay_us(1);}
if(TWIInfo.errorCode != 0xFF){
xprintf("ISSI init failed %d %02X %02X\n", device_addr, TWIInfo.mode, TWIInfo.errorCode);
continue;
}
// Allocate the device structure - calloc zeros it for us
ISSIDeviceStruct *device = (ISSIDeviceStruct *)calloc(sizeof(ISSIDeviceStruct) * 2, 1);
issi_devices[device_addr] = device;
device->fn_device_addr = ISSI_ADDR_DEFAULT | device_addr << 1;
device->fn_register_addr = 0;
device->led_device_addr = ISSI_ADDR_DEFAULT | device_addr << 1;
device->led_register_addr = 0;
// set dirty bits so that all of the buffered data is written out
device->fn_dirty = 1;
device->led_dirty = 1;
update_issi(device_addr, 1);
// Set the function register to picture mode
// device->fn_reg[ISSI_REG_CONFIG] = ISSI_REG_CONFIG_PICTUREMODE;
writeRegister8(device_addr, ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x01);
}
// Shutdown and set all registers to 0
// writeRegister8(device_addr, ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x00);
// for(uint8_t bank = 0; bank <= 7; bank++){
// for (uint8_t reg = 0x00; reg <= 0xB3; reg++) {
// writeRegister8(device_addr, bank, reg, 0x00);
// }
// }
// for (uint8_t reg = 0; reg <= 0x0C; reg++) {
// writeRegister8(device_addr, ISSI_BANK_FUNCTIONREG, reg, 0x00);
// }
// writeRegister8(device_addr, ISSI_BANK_FUNCTIONREG, ISSI_REG_CONFIG, ISSI_REG_CONFIG_PICTUREMODE);
// writeRegister8(device_addr, ISSI_BANK_FUNCTIONREG, ISSI_REG_SHUTDOWN, 0x01);
// picture mode
// writeRegister8(ISSI_BANK_FUNCTIONREG, 0x01, 0x01);
//Enable blink
// writeRegister8(ISSI_BANK_FUNCTIONREG, 0x05, 0x48B);
//Enable Breath
}
#endif

View File

@ -0,0 +1,40 @@
#ifdef ISSI_ENABLE
#ifndef ISSI_H
#define ISSI_H
typedef struct ISSIDeviceStruct{
uint8_t fn_dirty; // function registers need to be resent
uint8_t fn_device_addr;
uint8_t fn_register_addr;
uint8_t fn_registers[13];
uint8_t led_dirty; // LED data has changed and needs to be resent
uint8_t led_device_addr;
uint8_t led_register_addr;
uint8_t led_ctrl[18];
uint8_t led_blink_ctrl[18];
uint8_t led_pwm[144];
}ISSIDeviceStruct;
extern ISSIDeviceStruct *issi_devices[];
// Low level commands- 'device' is the 2-bit i2c id.
void issi_init(void);
void set_shutdown(uint8_t device, uint8_t shutdown);
void writeRegister8(uint8_t device, uint8_t frame, uint8_t reg, uint8_t data);
// Higher level, no device is given, but it is calculated from 'matrix'
// Each device has 2 blocks, max of 4 devices:
// Device | Block = Matrix
// 0 A 0
// 0 B 1
// 1 A 2
// 1 B 3
// 2 A 4
// 2 B 5
// 3 A 6
// 3 B 7
void activateLED(uint8_t matrix, uint8_t cx, uint8_t cy, uint8_t pwm);
void update_issi(uint8_t device_addr, uint8_t blocking);
#endif
#endif

View File

@ -0,0 +1,172 @@
/*
Copyright 2012 Jun Wako <wakojun@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 CONFIG_H
#define CONFIG_H
#include "config_common.h"
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6060
#define DEVICE_VER 0x0001
#define MANUFACTURER LFKeyboards
#define PRODUCT LFK78
#define DESCRIPTION QMK keyboard firmware for LFK78 LFK_REV_STRING
#ifdef LFK_REV_B
/* RevB Matrix config */
#define DIODE_DIRECTION COL2ROW
#define MATRIX_ROWS 10
#define MATRIX_COLS 8
#define MATRIX_ROW_PINS { B0, B1, B2, B3, B4, F0, F1, F4, F5, F6}
#define MATRIX_COL_PINS { E6, F7, D2, D3, D4, D5, D6, D7 }
#define UNUSED_PINS { C7 }
#define RGBLED_NUM 31 // Number of LEDs
#else
/* RevC/D Matrix config */
#define DIODE_DIRECTION COL2ROW
#define MATRIX_ROWS 5
#define MATRIX_COLS 18
#define MATRIX_ROW_PINS {D2, D3, D4, D5, D6 }
#define MATRIX_COL_PINS {A0, A1, A2, A3, A4, A5, A6, A7, E6, E7,\
F0, F1, F2, F3, C0, C1, C2, C3 }
#define UNUSED_PINS {B0, B1, B2, B3, B4, B4, B5, B6, B7, C4, C5, C6, C7,\
D0, D1, D7, E0, E1, E2, E3, E4, D5, F4, F5, F6, F7,\
E6, E7, F0, F1, F2, F3, C0, C1, C2, C3}
#define RGBLED_NUM 27 // Number of LEDs
#endif
#define AUDIO_VOICES
#define C6_AUDIO
#define BACKLIGHT_LEVELS 8
#define BACKLIGHT_PWM_MAP {8, 16, 40, 55, 70, 128, 200, 255}
#define RGB_DI_PIN C7 // Have to set it to something to get the ws2812 code to compile
#define RGBLIGHT_ANIMATIONS
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_VAL_STEP 17
#define TAPPING_TERM 200
/* 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
/*
* 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)) \
)
/* control how magic key switches layers */
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false
/* override magic key keymap */
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
//#define MAGIC_KEY_HELP1 H
//#define MAGIC_KEY_HELP2 SLASH
//#define MAGIC_KEY_DEBUG D
//#define MAGIC_KEY_DEBUG_MATRIX X
//#define MAGIC_KEY_DEBUG_KBD K
//#define MAGIC_KEY_DEBUG_MOUSE M
//#define MAGIC_KEY_VERSION V
//#define MAGIC_KEY_STATUS S
//#define MAGIC_KEY_CONSOLE C
//#define MAGIC_KEY_LAYER0_ALT1 ESC
//#define MAGIC_KEY_LAYER0_ALT2 GRAVE
//#define MAGIC_KEY_LAYER0 0
//#define MAGIC_KEY_LAYER1 1
//#define MAGIC_KEY_LAYER2 2
//#define MAGIC_KEY_LAYER3 3
//#define MAGIC_KEY_LAYER4 4
//#define MAGIC_KEY_LAYER5 5
//#define MAGIC_KEY_LAYER6 6
//#define MAGIC_KEY_LAYER7 7
//#define MAGIC_KEY_LAYER8 8
//#define MAGIC_KEY_LAYER9 9
//#define MAGIC_KEY_BOOTLOADER PAUSE
//#define MAGIC_KEY_LOCK CAPS
//#define MAGIC_KEY_EEPROM E
//#define MAGIC_KEY_NKRO N
//#define MAGIC_KEY_SLEEP_LED Z
/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/
/* disable debug print */
//#define NO_DEBUG
/* disable print */
//#define NO_PRINT
/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
#endif

View File

@ -0,0 +1,8 @@
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
#include "../../config.h"
// place overrides here
#endif

View File

@ -0,0 +1,123 @@
#include "lfk78.h"
#include "issi.h"
#include "lighting.h"
#include "action_layer.h"
//Define a shorter 'transparent' key code to make the keymaps more compact
#define KC_TR KC_TRNS
enum keymap_layout {
VANILLA = 0, // matches MF68 layout
FUNC, // 0x02
SETTINGS, // 0x04
};
// Colors of the layer indicator LED
// This list needs to define layer 0xFFFFFFFF, it is the end of the list, and the unknown layer
const Layer_Info layer_info[] = {
// Layer Mask Red Green Blue
{0x00000000, 0xFFFFFFFF, {0x0000, 0x0FFF, 0x0000}}, // base layer - green
{0x00000002, 0xFFFFFFFE, {0x0000, 0x0000, 0x0FFF}}, // function layer - blue
{0x00000004, 0xFFFFFFFC, {0x0FFF, 0x0000, 0x0FFF}}, // settings layer - magenta
{0xFFFFFFFF, 0xFFFFFFFF, {0x0FFF, 0x0FFF, 0x0FFF}}, // unknown layer - REQUIRED - white
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[VANILLA] = KEYMAP(
/* Keymap VANILLA: (Base Layer) Default Layer
* ,---------. ,------------------------------------------------------------. ,---------.
* | F1 | F2 | |Esc~| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0| - | = |Backspa| | Ins|PgUp|
* |---------| |------------------------------------------------------------| |---------|
* | F3 | F4 | |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| | Del|PgDn|
* |---------| |------------------------------------------------------------| `---------'
* | F5 | F6 | |CAPS | A| S| D| F| G| H| J| K| L| ;| '|Return |
* |---------| |------------------------------------------------------------| ,----.
* | F7 | F8 | |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | | Up |
* |---------| |-------------------------------------------------------------------------.
* | F9 | F10| |Ctrl|Win |Alt | Space |Alt |Ctrl|Func | |Lft| Dn |Rig |
* `---------' `------------------------------------------------------' `-------------'
*/
KC_F1, KC_F2, KC_GESC,KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_PGUP,
KC_F3, KC_F4, KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_PGDN,
KC_F5, KC_F6, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT,
KC_F7, KC_F8, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP,
KC_F9, KC_F10, KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RCTL, MO(FUNC), KC_LEFT, KC_DOWN, KC_RGHT),
/* Keymap FUNCTION: Function Layer
* ,---------. ,-------------------------------------------------------------. ,---------.
* | | | | ` |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12|Delete | | Ins|Home|
* |---------| |-------------------------------------------------------------| |---------|
* | | | |Tab |Hom| Up|End|PgU| | | | | | | | | | | Del|End |
* |---------| |-------------------------------------------------------------| `---------'
* | | | |MO(FUNC)|Lft|Dn |Rig|PgD| |Lft|Dwn| Up|Rgt| | | |
* |---------| |-------------------------------------------------------------| ,----.
* | | | |Shift | | | | | | |Mute|V- |V+ | |TG(SETTINGS)| | Up |
* |---------| |--------------------------------------------------------------------------.
* | | | |Ctrl|Win |Alt | Enter |Alt |Func |CTRL | |Lft| Dn |Rig |
* `---------' `------------------------------------------------------' `-------------'
*/
[FUNC] = KEYMAP(
KC_TR, KC_TR, KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, KC_TR, KC_HOME,
KC_TR, KC_TR, KC_NO,KC_HOME, KC_UP, KC_END, KC_PGUP, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_TR, KC_END,
KC_TR, KC_TR, KC_TR, KC_LEFT, KC_DOWN, KC_RGHT, KC_PGDN, KC_NO, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, KC_NO, KC_NO, KC_NO,
KC_TR, KC_TR, KC_TR, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_MUTE, KC_VOLD, KC_VOLU, KC_NO, TG(SETTINGS), KC_TR,
KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_ENT, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR),
/* Keymap SETTINGS: Settings Layer
* ,---------. ,-------------------------------------------------------------. ,-------------.
* | | | |LayClr| | | | | | | | | | |BL-|BL+|BL Togl| |RGB Tog |Val+|
* |---------| |-------------------------------------------------------------| |-------------|
* | | | |MuMode | | | | | | | | | | | | |LEDTst| |RGB Mode|Val-|
* |---------| |-------------------------------------------------------------| `-------------'
* | | | |AudTgl |Hz+|MS+| | | | | | | | | | RST |
* |---------| |-------------------------------------------------------------| ,----.
* | | | |ClickTgl |Hz-|MS-| | | | |MuTgl| | | |Layer Clr | |Hue+|
* |---------| |-------------------------------------------------------------------------.
* | | | | | | | | | | | |Sat-|Hue-|Sat+|
* `---------' `--------------------------------------------------------' `--------------'
*/
[SETTINGS] = KEYMAP(
KC_NO, KC_NO, KC_FN0,KC_NO,KC_NO,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, BL_DEC, BL_INC, BL_TOGG, RGB_TOG, RGB_VAI,
KC_NO, KC_NO, MU_MOD, 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, RGB_MOD, RGB_VAD,
KC_NO, KC_NO, AU_TOG, KC_FN1,KC_FN3, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RESET,
KC_NO, KC_NO, KC_FN5, KC_FN2,KC_FN4, KC_NO, KC_NO, KC_NO, KC_NO, MU_TOG, KC_NO, KC_NO, KC_NO, KC_NO, RGB_HUI,
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RGB_SAD, RGB_HUD, RGB_SAI),
};
const uint16_t PROGMEM fn_actions[] = {
ACTION_FUNCTION(LFK_CLEAR), // FN0 - reset layers
ACTION_FUNCTION(LFK_CLICK_FREQ_HIGHER), // FN1 - Increase Freq of audio click
ACTION_FUNCTION(LFK_CLICK_FREQ_LOWER), // FN2 - Decrease Freq of audio click
ACTION_FUNCTION(LFK_CLICK_TIME_LONGER), // FN3 - Increase length of audio click
ACTION_FUNCTION(LFK_CLICK_TIME_SHORTER), // FN4 - Decrease length of audio click
ACTION_FUNCTION(LFK_CLICK_TOGGLE), // FN5 - Toggle audio click
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
// MACRODOWN only works in this function
switch(id) {
}
return MACRO_NONE;
};
void matrix_init_user(void) {
// This keymap only has a single base layer, so reset the default if needed
if(eeconfig_read_default_layer() > 1){
eeconfig_update_default_layer(1);
default_layer_set(1);
}
}
void matrix_scan_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
void led_set_user(uint8_t usb_led) {
}

View File

@ -0,0 +1 @@
# The default keymap for LFK78

View File

@ -0,0 +1,42 @@
# Build Options
# change to "no" to disable the options, or define them in the Makefile in
# the appropriate keymap folder that will get included automatically
#
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
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = yes # 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. Do not enable this with audio at the same time.
RGBLIGHT_CUSTOM_DRIVER = yes # RGB code is implemented in lefkeyboards, not qmk base
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
TAP_DANCE_ENABLE = no
ISSI_ENABLE = yes # If the I2C pullup resistors aren't install this must be disabled
WATCHDOG_ENABLE = no # Resets keyboard if matrix_scan isn't run every 250ms
ifndef QUANTUM_DIR
include ../../../../Makefile
endif
ifeq ($(strip $(ISSI_ENABLE)), yes)
TMK_COMMON_DEFS += -DISSI_ENABLE
endif
ifeq ($(strip $(WATCHDOG_ENABLE)), yes)
TMK_COMMON_DEFS += -DWATCHDOG_ENABLE
endif
# Override the LFK78 hardware version:
#
# B - first public release, uses atmega32u4, has audio, ISSI matrix split between RGB and backlight
# C-H - at90usb1286, no audio, ISSI device 0 is backlight, 4 is RGB
# J - at90usb646, C6 audio, ISSI device 0 is backlight, 4 is RGB
# LFK_REV = J

View File

@ -0,0 +1,225 @@
#include <avr/sfr_defs.h>
#include <avr/timer_avr.h>
#include <avr/wdt.h>
#include "lfk78.h"
#include "keymap.h"
#include "issi.h"
#include "TWIlib.h"
#include "lighting.h"
#include "debug.h"
#include <audio/audio.h>
uint16_t click_hz = CLICK_HZ;
uint16_t click_time = CLICK_MS;
uint8_t click_toggle = CLICK_ENABLED;
void matrix_init_kb(void)
{
matrix_init_user();
// Configure the Layer LED
// Set up 16 bit PWM: Fast PWM, mode 15, inverted
TCCR1A = 0b11111110;
TCCR1B = 0b00011001;
ICR1 = 0xFFFF;
// PWM values - 0xFFFF = off, 0x0000 = max
OCR1C = 0x0000; // B7 - Blue
OCR1B = 0x0000; // B6 - Green
OCR1A = 0x0FFF; // B5 - Red
// Set as output
DDRB |= 0b11100000;
#ifndef AUDIO_ENABLE
// If we're not using the audio pin, drive it low
sbi(DDRC, 6);
cbi(PORTC, 6);
#endif
#ifdef ISSI_ENABLE
issi_init();
#endif
#ifdef WATCHDOG_ENABLE
// This is done after turning the layer LED red, if we're caught in a loop
// we should get a flashing red light
wdt_enable(WDTO_500MS);
#endif
}
void matrix_scan_kb(void)
{
#ifdef WATCHDOG_ENABLE
wdt_reset();
#endif
#ifdef ISSI_ENABLE
// switch/underglow lighting update
static uint32_t issi_device = 0;
static uint32_t twi_last_ready = 0;
if(twi_last_ready > 1000){
// Its been way too long since the last ISSI update, reset the I2C bus and start again
dprintf("TWI failed to recover, TWI re-init\n");
twi_last_ready = 0;
TWIInit();
force_issi_refresh();
}
if(isTWIReady()){
twi_last_ready = 0;
// If the i2c bus is available, kick off the issi update, alternate between devices
update_issi(issi_device, issi_device);
if(issi_device){
issi_device = 0;
}else{
issi_device = 3;
}
}else{
twi_last_ready++;
}
#endif
// Update layer indicator LED
//
// Not sure how else to reliably do this... TMK has the 'hook_layer_change'
// but can't find QMK equiv
static uint32_t layer_indicator = -1;
if(layer_indicator != layer_state){
for(uint32_t i=0;; i++){
// the layer_info list should end with layer 0xFFFFFFFF
// it will break this out of the loop and define the unknown layer color
if((layer_info[i].layer == (layer_state & layer_info[i].mask)) || (layer_info[i].layer == 0xFFFFFFFF)){
OCR1A = layer_info[i].color.red;
OCR1B = layer_info[i].color.green;
OCR1C = layer_info[i].color.blue;
layer_indicator = layer_state;
break;
}
}
}
matrix_scan_user();
}
void click(uint16_t freq, uint16_t duration){
#ifdef AUDIO_ENABLE
if(freq >= 100 && freq <= 20000 && duration < 100){
play_note(freq, 10);
for (uint16_t i = 0; i < duration; i++){
_delay_ms(1);
}
stop_all_notes();
}
#endif
}
bool process_record_kb(uint16_t keycode, keyrecord_t* record)
{
if (click_toggle && record->event.pressed){
click(click_hz, click_time);
}
if (keycode == RESET) {
reset_keyboard_kb();
} else {
}
return process_record_user(keycode, record);
}
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
{
#ifdef AUDIO_ENABLE
int8_t sign = 1;
#endif
if(id == LFK_ESC_TILDE){
// Send ~ on shift-esc
void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key;
uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
if(layer_state == 0){
method(shifted ? KC_GRAVE : KC_ESCAPE);
}else{
method(shifted ? KC_ESCAPE : KC_GRAVE);
}
send_keyboard_report();
}else if(event->event.pressed){
switch(id){
case LFK_SET_DEFAULT_LAYER:
// set/save the current base layer to eeprom, falls through to LFK_CLEAR
eeconfig_update_default_layer(1UL << opt);
default_layer_set(1UL << opt);
case LFK_CLEAR:
// Go back to default layer
layer_clear();
break;
#ifdef ISSI_ENABLE
case LFK_LED_TEST:
led_test();
break;
#endif
#ifdef AUDIO_ENABLE
case LFK_CLICK_FREQ_LOWER:
sign = -1; // continue to next statement
case LFK_CLICK_FREQ_HIGHER:
click_hz += sign * 100;
click(click_hz, click_time);
break;
case LFK_CLICK_TOGGLE:
if(click_toggle){
click_toggle = 0;
click(4000, 100);
click(1000, 100);
}else{
click_toggle = 1;
click(1000, 100);
click(4000, 100);
}
break;
case LFK_CLICK_TIME_SHORTER:
sign = -1; // continue to next statement
case LFK_CLICK_TIME_LONGER:
click_time += sign;
click(click_hz, click_time);
break;
#endif
case LFK_DEBUG_SETTINGS:
dprintf("Click:\n");
dprintf(" toggle: %d\n", click_toggle);
dprintf(" freq(hz): %d\n", click_hz);
dprintf(" duration(ms): %d\n", click_time);
break;
}
}
}
void reset_keyboard_kb(){
#ifdef WATCHDOG_ENABLE
MCUSR = 0;
wdt_disable();
wdt_reset();
#endif
OCR1A = 0x0000; // B5 - Red
OCR1B = 0x0FFF; // B6 - Green
OCR1C = 0x0FFF; // B7 - Blue
reset_keyboard();
}
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);
}
// LFK lighting info
const uint8_t switch_matrices[] = {0, 1};
const uint8_t rgb_matrices[] = {6, 7};
const uint8_t rgb_sequence[] = {
12, 11, 10, 9, 16, 32, 31, 30, 28, 25, 24, 22, 21,
20, 19, 18, 17, 1, 2, 3, 4, 5, 6, 7, 8, 14, 13
};
// Maps switch LEDs from Row/Col to ISSI matrix.
// Value breakdown:
// Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// / \ ISSI Col | ISSI Row |
// matrix idx
const uint8_t switch_leds[MATRIX_ROWS][MATRIX_COLS] =
KEYMAP(
0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91,
0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0xA9, 0xA8, 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1,
0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0xB9, 0xB8, 0xB7, 0xB6, 0xB5, 0xB3,
0x49, 0x48, 0x47, 0x45, 0x44, 0x43, 0x42, 0x41, 0xC9, 0xC8, 0xC7, 0xC6, 0xC5, 0xC4, 0xC2,
0x59, 0x58, 0x57, 0x56, 0x55, 0x51, 0xD6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1);

View File

@ -0,0 +1,155 @@
#ifndef LFK78_H
#define LFK78_H
/* if the kb.h file exists (because we're running from qmkbuilder) include it */
#if __has_include("kb.h")
#include "kb.h"
#endif
#include "quantum.h"
#include "matrix.h"
#include <avr/sfr_defs.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
typedef struct RGB_Color {
uint16_t red;
uint16_t green;
uint16_t blue;
} RGB_Color;
typedef struct Layer_Info {
uint32_t layer;
uint32_t mask;
RGB_Color color;
} Layer_Info;
extern const uint32_t layer_count;
extern const Layer_Info layer_info[];
enum action_functions {
LFK_CLEAR = 0, // Resets all layers
LFK_ESC_TILDE, // esc+lshift = ~
LFK_SET_DEFAULT_LAYER, // changes and saves current base layer to eeprom
LFK_CLICK_TOGGLE, // Adjusts click duration
LFK_CLICK_FREQ_HIGHER, // Adjusts click frequency
LFK_CLICK_FREQ_LOWER, // Adjusts click frequency
LFK_CLICK_TIME_LONGER, // Adjusts click duration
LFK_CLICK_TIME_SHORTER, // Adjusts click duration
LFK_DEBUG_SETTINGS, // prints LED and click settings to HID
LFK_LED_TEST // cycles through switch and RGB LEDs
};
#define CLICK_HZ 500
#define CLICK_MS 2
#define CLICK_ENABLED 0
void reset_keyboard_kb(void);
void click(uint16_t freq, uint16_t duration);
#ifdef LFK_REV_B
/* RevB Keymap */
// This a shortcut to help you visually see your layout.
/*
* ,---------. ,-----------------------------------------------------------------------. ,---------.
* | 0 | 1 | | 2 | 3 | 4 | 5 | 6 | 7 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | | 94 | 95 |
* |---------| |-----------------------------------------------------------------------| |---------|
* | 10 | 11 | | 12 | 13 | 14 | 15 | 16 | 17 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | | 96 | 97 |
* |---------| |-----------------------------------------------------------------------| `---------'
* | 20 | 21 | | 22 | 23 | 24 | 25 | 26 | 27 | 70 | 71 | 72 | 73 | 74 | 75 | 76 |
* |---------| |-----------------------------------------------------------------------| ,----.
* | 30 | 31 | | 32 | 33 | 34 | 35 | 36 | 37 | 80 | 81 | 82 | 83 | 84 | 85 | | 86 |
* |---------| |-------------------------------------------------------------------------------------.
* | 40 | 41 | | 42 | 43 | 44 | 45 | 46 | 47 | 90 | | 91 | 92 | 93 |
* `---------' `--------------------------------------------------------------------' `--------------'
*/
// The first section contains all of the arguements
// The second converts the arguments into a two-dimensional array
#define KEYMAP( \
k00, k01, k02, k03, k04, k05, k06, k07, k50, k51, k52, k53, k54, k55, k56, k57, k94, k95, \
k10, k11, k12, k13, k14, k15, k16, k17, k60, k61, k62, k63, k64, k65, k66, k67, k96, k97, \
k20, k21, k22, k23, k24, k25, k26, k27, k70, k71, k72, k73, k74, k75, k76, \
k30, k31, k32, k33, k34, k35, k36, k37, k80, k81, k82, k83, k84, k85, k86, \
k40, k41, k42, k43, k44, k45, k46, k47, k90, k91, k92, k93 \
) { \
{ k00, k01, k02, k03, k04, k05, k06, k07, }, \
{ k10, k11, k12, k13, k14, k15, k16, k17, }, \
{ k20, k21, k22, k23, k24, k25, k26, k27, }, \
{ k30, k31, k32, k33, k34, k35, k36, k37, }, \
{ k40, k41, k42, k43, k44, k45, k46, k47, }, \
{ k50, k51, k52, k53, k54, k55, k56, k57, }, \
{ k60, k61, k62, k63, k64, k65, k66, k67, }, \
{ k70, k71, k72, k73, k74, k75, k76, KC_NO,}, \
{ k80, k81, k82, k83, k84, k85, k86, KC_NO,}, \
{ k90, k91, k92, k93, k94, k95, k96, k97, }, \
}
#else
/* RevC/D Keymap */
// This a shortcut to help you visually see your layout.
/*
* ,---------. ,-----------------------------------------------------------------------. ,---------.
* | 11 | 12 | | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B | 1C | 1D | 1E | 1F | 1G | | 1H | 1I |
* |---------| |-----------------------------------------------------------------------| |---------|
* | 21 | 22 | | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 2A | 2B | 2C | 2D | 2E | 2F | 2G | | 2H | 2I |
* |---------| |-----------------------------------------------------------------------| `---------'
* | 31 | 32 | | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 3A | 3B | 3C | 3D | 3E | 3F |
* |---------| |-----------------------------------------------------------------------| ,----.
* | 41 | 42 | | 43 | 45 | 46 | 47 | 48 | 49 | 4A | 4B | 4C | 4D | 4E | 4F | | 4H |
* |---------| |-------------------------------------------------------------------------------------.
* | 51 | 52 | | 53 | 54 | 55 | 59 | 5D | 5E | 5F | | 5G | 5H | 5I |
* `---------' `--------------------------------------------------------------------' `--------------'
*/
// The first section contains all of the arguements
// The second converts the arguments into a two-dimensional array
#define KEYMAP( \
k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, k1E, k1F, k1G, k1H, k1I, \
k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, k2E, k2F, k2G, k2H, k2I, \
k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, k3D, k3E, k3F, \
k41, k42, k43, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4E, k4F, k4H, \
k51, k52, k53, k54, k55, k59, k5D, k5E, k5F, k5G, k5H, k5I \
) { \
{k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, k1E, k1F, k1G, k1H, k1I}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, k2E, k2F, k2G, k2H, k2I}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, k3D, k3E, k3F, KC_NO, KC_NO, KC_NO}, \
{k41, k42, k43, KC_NO, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4E, k4F, KC_NO, k4H, KC_NO}, \
{k51, k52, k53, k54, k55, KC_NO, KC_NO, KC_NO, k59, KC_NO, KC_NO, KC_NO, k5D, k5E, k5F, k5G, k5H, k5I} \
}
#define SPLIT_SHIFT_KEYMAP( \
k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, k1E, k1F, k1G, k1H, k1I, \
k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, k2E, k2F, k2G, k2H, k2I, \
k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, k3D, k3E, k3F, \
k41, k42, k43, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4E, k4F, k4G, k4H, \
k51, k52, k53, k54, k55, k59, k5D, k5E, k5F, k5G, k5H, k5I \
) { \
{k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, k1E, k1F, k1G, k1H, k1I}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, k2E, k2F, k2G, k2H, k2I}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, k3D, k3E, k3F, KC_NO, KC_NO, KC_NO}, \
{k41, k42, k43, KC_NO, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4E, k4F, k4G, k4H, KC_NO}, \
{k51, k52, k53, k54, k55, KC_NO, KC_NO, KC_NO, k59, KC_NO, KC_NO, KC_NO, k5D, k5E, k5F, k5G, k5H, k5I} \
}
#define ISO_KEYMAP( \
k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, k1E, k1F, k1G, k1H, k1I, \
k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, k2E, k2F, k2G, k2H, k2I, \
k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, k3D, k3E, k3F, \
k41, k42, k43, k44, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4E, k4F, k4H, \
k51, k52, k53, k54, k55, k59, k5D, k5E, k5F, k5G, k5H, k5I \
) { \
{k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, k1E, k1F, k1G, k1H, k1I}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, k2E, k2F, k2G, k2H, k2I}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, k3D, k3E, k3F, KC_NO, KC_NO, KC_NO}, \
{k41, k42, k43, k44, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4E, k4F, KC_NO, k4H, KC_NO}, \
{k51, k52, k53, k54, k55, KC_NO, KC_NO, KC_NO, k59, KC_NO, KC_NO, KC_NO, k5D, k5E, k5F, k5G, k5H, k5I} \
}
#endif //LFK_REV_B
#endif //LFK78_H

View File

@ -0,0 +1,14 @@
LFK78/68
===
A 65% keyboard similar to the MagicForce68 or VA68M. Optional fuction key block on left side.
Keyboard Maintainer: [LFKeyboards](https://github.com/lfkeyboards)
Hardware Supported: LFK78/68 RevB - RevJ, SMK78/68
Hardware Availability: [LFKeyboards.com](https://www.lfkeyboards.com/)
Make example for this keyboard (after setting up your build environment):
make lfkeyboards/lfk78: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.

View File

@ -0,0 +1,34 @@
# Set the LFK78 hardware version.
#
# B - first public release, uses atmega32u4, has audio, ISSI matrix split between RGB and backlight
# C-H - at90usb1286, no audio, ISSI device 0 is backlight, 4 is RGB
# J - at90usb646, C6 audio, ISSI device 0 is backlight, 4 is RGB
LFK_REV = J
ifeq ($(LFK_REV), B)
MCU = atmega32u4
OPT_DEFS += -DBOOTLOADER_SIZE=4096
else ifeq ($(LFK_REV), J)
MCU = at90usb646
OPT_DEFS += -DBOOTLOADER_SIZE=4096
else
MCU = at90usb1286
OPT_DEFS += -DBOOTLOADER_SIZE=8192
endif
OPT_DEFS += -DLFK_REV_$(LFK_REV)
OPT_DEFS += -DLFK_REV_STRING=\"Rev$(LFK_REV)\"
# Extra source files for IS3731 lighting
SRC = TWIlib.c issi.c lighting.c
# Processor frequency.
F_CPU = 16000000
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Input clock frequency.
F_USB = $(F_CPU)
# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT

View File

@ -0,0 +1,173 @@
/*
Copyright 2012 Jun Wako <wakojun@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 CONFIG_H
#define CONFIG_H
#include "config_common.h"
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6060
#define DEVICE_VER 0x0001
#define MANUFACTURER LFKeyboards
#define PRODUCT LFK87
#define DESCRIPTION QMK keyboard firmware for LFK87
#define DIODE_DIRECTION COL2ROW
#ifdef LFK_TKL_REV_A
/* RevB Matrix config */
#define MATRIX_ROWS 6
#define MATRIX_COLS 17
#define MATRIX_ROW_PINS {D2, D3, D4, D5, D6, D7 }
#define MATRIX_COL_PINS {A0, A1, A2, A3, A4, A5, A6, A7, E6, E7,\
F0, F1, F2, F3, C0, C1, C2 }
#define UNUSED_PINS {B0, B1, B2, B3, B4, B4, B5, B6, B7, C4, C5, C6, C7,\
D0, D1, E0, E1, E2, E3, E4, F4, F5, F6, F7}
#define RGBLED_NUM 25 // Number of LEDs
#else
/* RevC/D Matrix config */
#define MATRIX_ROWS 7
#define MATRIX_COLS 16
#define MATRIX_ROW_PINS {F2, D7, D6, D5, D4, D3, F3}
#define MATRIX_COL_PINS {A0, A1, A2, A3, A4, A5, A6, A7, C7, C1, C0, E1, E0, C2, C3, C4}
#define UNUSED_PINS {B0, B1, B2, B3, B4, B4, B5, B6, B7, C5, C6, D2, E3, E4, E5, E6, E7, \
F0, F1, F4, F5, F6, F7}
#define RGBLED_NUM 24 // Number of LEDs
#endif
#define AUDIO_VOICES
#define C6_AUDIO
#define BACKLIGHT_LEVELS 10
#define BACKLIGHT_PWM_MAP {2, 4, 8, 16, 40, 55, 70, 128, 200, 255}
#define RGB_DI_PIN F4 // Have to set it to something to get the ws2812 code to compile
#define RGBLIGHT_ANIMATIONS
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_VAL_STEP 17
#define TAPPING_TERM 200
/* 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
/*
* 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)) \
)
/* control how magic key switches layers */
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false
/* override magic key keymap */
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
//#define MAGIC_KEY_HELP1 H
//#define MAGIC_KEY_HELP2 SLASH
//#define MAGIC_KEY_DEBUG D
//#define MAGIC_KEY_DEBUG_MATRIX X
//#define MAGIC_KEY_DEBUG_KBD K
//#define MAGIC_KEY_DEBUG_MOUSE M
//#define MAGIC_KEY_VERSION V
//#define MAGIC_KEY_STATUS S
//#define MAGIC_KEY_CONSOLE C
//#define MAGIC_KEY_LAYER0_ALT1 ESC
//#define MAGIC_KEY_LAYER0_ALT2 GRAVE
//#define MAGIC_KEY_LAYER0 0
//#define MAGIC_KEY_LAYER1 1
//#define MAGIC_KEY_LAYER2 2
//#define MAGIC_KEY_LAYER3 3
//#define MAGIC_KEY_LAYER4 4
//#define MAGIC_KEY_LAYER5 5
//#define MAGIC_KEY_LAYER6 6
//#define MAGIC_KEY_LAYER7 7
//#define MAGIC_KEY_LAYER8 8
//#define MAGIC_KEY_LAYER9 9
//#define MAGIC_KEY_BOOTLOADER PAUSE
//#define MAGIC_KEY_LOCK CAPS
//#define MAGIC_KEY_EEPROM E
//#define MAGIC_KEY_NKRO N
//#define MAGIC_KEY_SLEEP_LED Z
/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/
/* disable debug print */
//#define NO_DEBUG
/* disable print */
//#define NO_PRINT
/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
#endif

View File

@ -0,0 +1,8 @@
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
#include "../../config.h"
// place overrides here
#endif

View File

@ -0,0 +1,133 @@
#include "lfk87.h"
#include "issi.h"
#include "lighting.h"
#include "action_layer.h"
//Define a shorter 'transparent' key code to make the keymaps more compact
#define KC_TR KC_TRNS
enum keymap_layout {
VANILLA = 0, // matches MF68 layout
FUNC, // 0x08
SETTINGS, // 0x10
};
// Colors of the layer indicator LED
// This list needs to define layer 0xFFFFFFFF, it is the end of the list, and the unknown layer
const Layer_Info layer_info[] = {
// Layer Mask Red Green Blue
{0x00000000, 0xFFFFFFFF, {0x00, 0xFF, 0x00}}, // base layers - green
{0x00000002, 0xFFFFFFFE, {0x00, 0x00, 0xFF}}, // function layer - blue
{0x00000004, 0xFFFFFFFC, {0xFF, 0x00, 0xFF}}, // settings layer - magenta
{0xFFFFFFFF, 0xFFFFFFFF, {0xFF, 0xFF, 0xFF}}, // unknown layer - REQUIRED - white
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[VANILLA] = KEYMAP(
/* Keymap VANILLA: (Base Layer) Default Layer
* ,-----------------------------------------------------------------------------.
* |Esc |f1| f2| f3| f4| | f5| f6| f7| f8| | f9|f10|f11|f12| |Prnt|ScLk|Paus|
* |-----------------------------------------------------------| |--------------|
* | ~ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0| - | = |Backsp | | Ins|Home|PgUp|
* |-----------------------------------------------------------| |--------------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| | Del| End|PgDn|
* |-----------------------------------------------------------| `--------------'
* |CAPS | A| S| D| F| G| H| J| K| L| ;| '|Return |
* |-----------------------------------------------------------| ,----.
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift | | Up |
* |-----------------------------------------------------------| ,-------------.
* |Ctrl|Gui |Alt | Space |ALT |GUI |Func|CTRL | |Lft| Dn |Rig |
* `-----------------------------------------------------------' `-------------'
*/
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_SLCK, KC_PAUS, \
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, \
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DELETE, KC_END, KC_PGDN, \
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, \
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, \
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI, MO(FUNC), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT),
/* Keymap FUNCTION: Function Layer
* ,-------------------------------------------------------------. ,--------------.
* |Esc |f1| f2| f3| f4| | f5| f6| f7| f8| | f9|f10|f11|f12 | |Prnt|ScLk|Paus|
* |-------------------------------------------------------------| |--------------|
* | ` |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12|Delete | | | | |
* |-------------------------------------------------------------| |--------------|
* |Tab | |PgU| | | | | | Up| | | | | | | | | |
* |-------------------------------------------------------------| `--------------'
* |Control|Hme|PgD|End| | | |Lft|Dwn|Rgt| | | |
* |-------------------------------------------------------------| ,----.
* |Shift | |Del| | | | |Mute|V- |V+ | |TG(SETTINGS)| | Up |
* |-------------------------------------------------------------' ,-------------.
* |Func|Win |Alt | PgD |Alt |Ctrl |Func | |Lft| Dn |Rig |
* `------------------------------------------------------' `-------------'
*/
[FUNC] = KEYMAP(
KC_ESC, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_PSCR, KC_SLCK, KC_PAUS, \
KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_DEL, KC_TR, KC_TR, KC_TR, \
KC_NO,KC_NO, KC_PGUP, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_UP, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_TR, KC_TR, KC_TR, \
KC_TR, KC_HOME, KC_PGDN, KC_END, KC_NO, KC_NO, KC_NO, KC_LEFT, KC_DOWN, KC_RGHT, KC_NO, KC_NO, KC_NO, \
KC_TR, KC_NO, KC_DEL, KC_NO, KC_NO, KC_NO, KC_NO, KC_MUTE, KC_VOLD, KC_VOLU, KC_NO, TG(SETTINGS), KC_TR, \
KC_TR, KC_TR, KC_TR, KC_PGDN, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR),
/* Keymap SETTINGS: Settings Layer
* ,-----------------------------------------------------------. ,-------------.
* |Esc |f1| f2| f3| f4| | f5| f6| f7| f8| | f9|f10|f11|f12 | |Prnt|ScLk|Paus|
* |-------------------------------------------------------------| |--------------|
* |FN0 | | | | | | | | | | |BL-|BL+|BL Togl| |RGB Tog |Val+|
* |-----------------------------------------------------------| |-------------|
* |MuMode| | | | | | | | | | | | |LEDTst| |RGB Mode|Val-|
* |-----------------------------------------------------------| `-------------'
* |AudTgl |Hz+|MS+| | | | | | | | | | RST |
* |-----------------------------------------------------------| ,----.
* |ClickTgl|Hz-|MS-| | | | | | | | |Layer Clr | |Hue+|
* |--------------------------------------------------------------------------.
* | | | | | | | | | |Sat-|Hue-|Sat+|
* `----------------------------------------------------------------------------'
*/
[SETTINGS] = KEYMAP(
KC_FN0, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, BL_DEC, KC_NO, KC_NO, KC_NO,
KC_FN0,KC_NO,KC_NO,KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, BL_DEC, BL_INC, BL_TOGG, RGB_TOG, RGB_VAI, KC_NO,
MU_MOD, 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_FN2, RGB_MOD, RGB_VAD, KC_NO,
AU_TOG, KC_F1,KC_FN3, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RESET,
KC_FN5, KC_FN2,KC_FN4, KC_NO, KC_NO, KC_NO, KC_NO, MU_TOG, KC_NO, KC_NO, KC_NO, KC_NO, RGB_HUI,
KC_NO, KC_NO, KC_NO, KC_FN12, KC_NO, KC_NO, KC_NO, KC_TR, RGB_SAD, RGB_HUD, RGB_SAI),
};
const uint16_t PROGMEM fn_actions[] = {
ACTION_FUNCTION(LFK_CLEAR), // FN0 - reset layers
ACTION_FUNCTION(LFK_CLICK_FREQ_HIGHER), // FN1 - Increase Freq of audio click
ACTION_FUNCTION(LFK_CLICK_FREQ_LOWER), // FN2 - Decrease Freq of audio click
ACTION_FUNCTION(LFK_CLICK_TIME_LONGER), // FN3 - Increase length of audio click
ACTION_FUNCTION(LFK_CLICK_TIME_SHORTER), // FN4 - Decrease length of audio click
ACTION_FUNCTION(LFK_CLICK_TOGGLE), // FN5 - Toggle audio click
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
// MACRODOWN only works in this function
switch(id) {
}
return MACRO_NONE;
};
void matrix_init_user(void) {
// This keymap only has a single base layer, so reset the default if needed
if(eeconfig_read_default_layer() > 1){
eeconfig_update_default_layer(1);
default_layer_set(1);
}
}
void matrix_scan_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
void led_set_user(uint8_t usb_led) {
}

View File

@ -0,0 +1,54 @@
# Build Options
# change to "no" to disable the options, or define them in the Makefile in
# the appropriate keymap folder that will get included automatically
#
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
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = yes # Audio output on port C6
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = yes # Enable RGB underlight
RGBLIGHT_CUSTOM_DRIVER = yes # RGB code is implemented in lefkeyboards, not WS2812
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
TAP_DANCE_ENABLE = no
ISSI_ENABLE = yes # If the I2C pullup resistors aren't install this must be disabled
WATCHDOG_ENABLE = no # Resets keyboard if matrix_scan isn't run every 250ms
ifndef QUANTUM_DIR
include ../../../../Makefile
endif
ifeq ($(strip $(ISSI_ENABLE)), yes)
TMK_COMMON_DEFS += -DISSI_ENABLE
endif
ifeq ($(strip $(WATCHDOG_ENABLE)), yes)
TMK_COMMON_DEFS += -DWATCHDOG_ENABLE
endif
# Override the LFK87 hardware version.
#
# A - Green PCB. at90usb1286 Only 3 exist
# B - We don't talk about RevB
# C-D - Black PCB. at90usb646 First public release
#
# LFK_REV = C
# ifeq ($(LFK_REV), A)
# MCU = at90usb1286
# OPT_DEFS += -DBOOTLOADER_SIZE=8192
# else
# MCU = at90usb646
# OPT_DEFS += -DBOOTLOADER_SIZE=4096
# endif
# OPT_DEFS += -DLFK_TKL_REV_$(LFK_REV)

View File

@ -0,0 +1,8 @@
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
#include "../../config.h"
// place overrides here
#endif

View File

@ -0,0 +1,137 @@
#include "lfk87.h"
#include "issi.h"
#include "lighting.h"
#include "action_layer.h"
//Define a shorter 'transparent' key code to make the keymaps more compact
#define KC_TR KC_TRNS
enum keymap_layout {
VANILLA = 0,
FUNC, // 0x02
SETTINGS, // 0x04
};
// Colors of the layer indicator LED
// This list needs to define layer 0xFFFFFFFF, it is the end of the list, and the unknown layer
const Layer_Info layer_info[] = {
// Layer Mask Red Green Blue
{0x00000000, 0xFFFFFFFF, {0x00, 0x00, 0x00}}, // base layer - off
{0x00000002, 0xFFFFFFFE, {0x00, 0x00, 0x7F}}, // function layer - blue
{0x00000004, 0xFFFFFFFC, {0x7F, 0x00, 0x00}}, // settings layer - red
{0xFFFFFFFF, 0xFFFFFFFF, {0x0F, 0x0F, 0x0F}}, // unknown layer - REQUIRED - white
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[VANILLA] = ISO_KEYMAP(
/* Keymap VANILLA: (Base Layer) Default Layer
* ,-----------------------------------------------------------------------------.
* |Esc |f1| f2| f3| f4| | f5| f6| f7| f8| | f9|f10|f11|f12| |Prnt|ScLk|Paus|
* |-----------------------------------------------------------| |--------------|
* | ~ | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0| - | = |Backsp | | Ins|Home|PgUp|
* |-----------------------------------------------------------| |--------------|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| Ret| | Del| End|PgDn|
* |--------------------------------------------------------. | `--------------'
* |CAPS | A| S| D| F| G| H| J| K| L| ;| '| # | |
* |-----------------------------------------------------------| ,----.
* |Shft| \ | Z| X| C| V| B| N| M| ,| .| /|Shift | | Up |
* |-----------------------------------------------------------| ,-------------.
* |Ctrl|Gui |Alt | Space |ALT |GUI | Func|CTRL| |Lft| Dn |Rig |
* `-----------------------------------------------------------' `-------------'
*/
KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PSCR, KC_LSCR, KC_PAUS, \
KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, \
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_ENT, KC_DELETE, KC_END, KC_PGDN, \
KC_LCAP, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_NUHS, \
KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, \
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RGUI, MO(FUNC), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT),
/* Keymap FUNCTION: Function Layer
* ,-------------------------------------------------------------. ,--------------.
* | |f1| f2| f3| f4| | f5| f6| f7| f8| | f9|f10|f11|f12 | |Prnt|ScLk|Paus|
* |-------------------------------------------------------------| |--------------|
* | |F1 |F2 |F3 |F4 |F5 |F6 |F7 |F8 |F9 |F10|F11|F12|Delete | | | | |
* |-------------------------------------------------------------| |--------------|
* |Tab | |PgU| | | | | | Up| | | | | | | | | | |
* |---------------------------------------------------------. | `--------------'
* |Control|Hme|PgD|End| | | |Lft|Dwn|Rgt| | | | |
* |-------------------------------------------------------------| ,----.
* |Shift| | |Del| | | | |Mute|V- |V+ | |TG(SETTINGS)| | Up |
* |-------------------------------------------------------------' ,-------------.
* |Func|Win |Alt | PgD |ALT |GUI | Func|CTRL| |Lft| Dn |Rig |
* `-------------------------------------------------------------' `-------------'
*/
[FUNC] = ISO_KEYMAP(
KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_PSCR, KC_SLCK, KC_PAUS, \
KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_DEL, KC_TR, KC_TR, KC_TR, \
KC_NO,KC_NO, KC_PGUP, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_UP, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_TR, KC_TR, KC_TR, \
KC_TR, KC_HOME, KC_PGDN, KC_END, KC_NO, KC_NO, KC_NO, KC_LEFT, KC_DOWN, KC_RGHT, KC_NO, KC_NO, KC_NO, \
KC_TR,KC_NO, KC_NO, KC_DEL, KC_NO, KC_NO, KC_NO, KC_NO, KC_MUTE, KC_VOLD, KC_VOLU, KC_NO, TG(SETTINGS), KC_TR, \
KC_TR, KC_TR, KC_TR, KC_PGDN, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR),
/* Keymap SETTINGS: Settings Layer
* ,-----------------------------------------------------------. ,-------------.
* |Esc |f1| f2| f3| f4| | f5| f6| f7| f8| | f9|f10|f11|f12 | |Prnt|ScLk|Paus|
* |-------------------------------------------------------------| |--------------|
* |FN3 |BL0|BL1|BL2|BL3| | | | | | |BL-|BL+|BL Togl| |RGB Tog |Val+|
* |-----------------------------------------------------------| |-------------|
* |Debug| | | | | | | | | | | | | RST | |RGB Mode|Val-|
* |--------------------------------------------------------. | `-------------'
* |LayrClr|Hz+|MS+| | | | | | | | | | | |
* |-----------------------------------------------------------| ,----.
* |ClickTgl|Hz-|MS-| | | | | | | | |Layer Clr | |Hue+|
* |------------------------------------------------------------------------.
* | | | | | | | | |Sat-|Hue-|Sat+|
* `------------------------------------------------------' `--------------'
*/
[SETTINGS] = ISO_KEYMAP(
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, BL_DEC, KC_NO, KC_NO, KC_NO,
KC_FN0,KC_FN3,KC_FN4,KC_FN5, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, BL_DEC, BL_INC, BL_TOGG, RGB_TOG, RGB_VAI, KC_NO,
MU_MOD, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, RESET, RGB_MOD, RGB_VAD, KC_NO,
AU_TOG, KC_FN3,KC_FN5, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO,
KC_FN7, KC_NO, KC_FN4, KC_FN6, KC_NO, KC_NO, KC_NO, KC_NO, MU_TOG, KC_NO, KC_NO, KC_NO, KC_FN0, RGB_HUI,
KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_NO, KC_FN0, RGB_SAD, RGB_HUD, RGB_SAI),
};
const uint16_t PROGMEM fn_actions[] = {
ACTION_FUNCTION(LFK_CLEAR), // FN0 - reset layers
ACTION_FUNCTION(LFK_ESC_TILDE), // FN1 - esc+shift = ~, else escape
ACTION_FUNCTION(LFK_LED_TEST), // FN2 - cycle through LEDs for testing
ACTION_FUNCTION(LFK_CLICK_FREQ_HIGHER), // FN3 - Increase Freq of audio click
ACTION_FUNCTION(LFK_CLICK_FREQ_LOWER), // FN4 - Decrease Freq of audio click
ACTION_FUNCTION(LFK_CLICK_TIME_LONGER), // FN5 - Increase length of audio click
ACTION_FUNCTION(LFK_CLICK_TIME_SHORTER), // FN6 - Decrease length of audio click
ACTION_FUNCTION(LFK_CLICK_TOGGLE), // FN7 - Toggle audio click
ACTION_FUNCTION(LFK_LED_TEST), // FN8 - cycle through LEDs for testing
ACTION_FUNCTION(LFK_DEBUG_SETTINGS), // FN9 - prints LED and click settings to HID
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
// MACRODOWN only works in this function
switch(id) {
}
return MACRO_NONE;
};
void matrix_init_user(void) {
// This keymap only has a single base layer, so reset the default if needed
if(eeconfig_read_default_layer() > 1){
eeconfig_update_default_layer(1);
default_layer_set(1);
}
}
void matrix_scan_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
void led_set_user(uint8_t usb_led) {
}

View File

@ -0,0 +1,53 @@
# Build Options
# change to "no" to disable the options, or define them in the Makefile in
# the appropriate keymap folder that will get included automatically
#
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
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = yes # Audio output on port C6
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = yes # Enable RGB underlight
RGBLIGHT_CUSTOM_DRIVER = yes # RGB code is implemented in lefkeyboards, not WS2812
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
TAP_DANCE_ENABLE = no
ISSI_ENABLE = yes # If the I2C pullup resistors aren't install this must be disabled
WATCHDOG_ENABLE = no # Resets keyboard if matrix_scan isn't run every 250ms
ifndef QUANTUM_DIR
include ../../../../Makefile
endif
ifeq ($(strip $(ISSI_ENABLE)), yes)
TMK_COMMON_DEFS += -DISSI_ENABLE
endif
ifeq ($(strip $(WATCHDOG_ENABLE)), yes)
TMK_COMMON_DEFS += -DWATCHDOG_ENABLE
endif
# # Set the LFK78 hardware version. This is defined in rules.mk, but can be overidden here if desired
# #
# # RevB - first public release, uses atmega32u4, has audio, ISSI matrix split between RGB and backlight
# # RevC/D - at90usb1286, no audio, ISSI device 0 is backlight, 4 is RGB
# #
# # Set to B, C or D
# LFK_REV = D
# ifeq ($(LFK_REV), B)
# MCU = atmega32u4
# else
# MCU = at90usb1286
# endif
# OPT_DEFS += -DLFK_REV_$(LFK_REV)
# OPT_DEFS += -DUSB_PRODUCT=\"LFK_Rev$(LFK_REV)\"

View File

@ -0,0 +1,215 @@
#include <avr/sfr_defs.h>
#include <avr/timer_avr.h>
#include <avr/wdt.h>
#include "lfk87.h"
#include "keymap.h"
#include "issi.h"
#include "TWIlib.h"
#include "lighting.h"
#include "debug.h"
#include "quantum.h"
uint16_t click_hz = CLICK_HZ;
uint16_t click_time = CLICK_MS;
uint8_t click_toggle = CLICK_ENABLED;
void matrix_init_kb(void)
{
// put your keyboard start-up code here
// runs once when the firmware starts up
matrix_init_user();
set_rgb(31, 0x00, 0x00, 0x00); // Caps lock
set_rgb(32, 0xFF, 0x00, 0x00); // Layer indicator, start red
#ifndef AUDIO_ENABLE
// If we're not using the audio pin, drive it low
sbi(DDRC, 6);
cbi(PORTC, 6);
#endif
#ifdef ISSI_ENABLE
issi_init();
#endif
#ifdef WATCHDOG_ENABLE
// This is done after turning the layer LED red, if we're caught in a loop
// we should get a flashing red light
wdt_enable(WDTO_500MS);
#endif
}
void matrix_scan_kb(void)
{
#ifdef WATCHDOG_ENABLE
wdt_reset();
#endif
#ifdef ISSI_ENABLE
// switch/underglow lighting update
static uint32_t issi_device = 0;
static uint32_t twi_last_ready = 0;
if(twi_last_ready > 1000){
// Its been way too long since the last ISSI update, reset the I2C bus and start again
twi_last_ready = 0;
TWIInit();
force_issi_refresh();
}
if(isTWIReady()){
twi_last_ready = 0;
// If the i2c bus is available, kick off the issi update, alternate between devices
update_issi(issi_device, issi_device);
if(issi_device){
issi_device = 0;
}else{
issi_device = 3;
}
}else{
twi_last_ready++;
}
#endif
// Update layer indicator LED
//
// Not sure how else to reliably do this... TMK has the 'hook_layer_change'
// but can't find QMK equiv
static uint32_t layer_indicator = -1;
if(layer_indicator != layer_state){
for(uint32_t i=0;; i++){
// the layer_info list should end with layer 0xFFFF
// it will break this out of the loop and define the unknown layer color
if((layer_info[i].layer == (layer_state & layer_info[i].mask)) || (layer_info[i].layer == 0xFFFFFFFF)){
set_rgb(32, layer_info[i].color.red, layer_info[i].color.green, layer_info[i].color.blue);
layer_indicator = layer_state;
break;
}
}
}
matrix_scan_user();
}
void click(uint16_t freq, uint16_t duration){
#ifdef AUDIO_ENABLE
if(freq >= 100 && freq <= 20000 && duration < 100){
play_note(freq, 10);
for (uint16_t i = 0; i < duration; i++){
_delay_ms(1);
}
stop_all_notes();
}
#endif
}
bool process_record_kb(uint16_t keycode, keyrecord_t* record)
{
if (click_toggle && record->event.pressed){
click(click_hz, click_time);
}
if (keycode == RESET) {
reset_keyboard_kb();
} else {
}
return process_record_user(keycode, record);
}
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
{
#ifdef AUDIO_ENABLE
int8_t sign = 1;
#endif
if(id == LFK_ESC_TILDE){
// Send ~ on shift-esc
void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key;
uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
method(shifted ? KC_GRAVE : KC_ESCAPE);
send_keyboard_report();
}else if(event->event.pressed){
switch(id){
case LFK_SET_DEFAULT_LAYER:
// set/save the current base layer to eeprom, falls through to LFK_CLEAR
eeconfig_update_default_layer(1UL << opt);
default_layer_set(1UL << opt);
case LFK_CLEAR:
// Go back to default layer
layer_clear();
break;
#ifdef ISSI_ENABLE
case LFK_LED_TEST:
led_test();
break;
#endif
#ifdef AUDIO_ENABLE
case LFK_CLICK_FREQ_LOWER:
sign = -1; // continue to next statement
case LFK_CLICK_FREQ_HIGHER:
click_hz += sign * 100;
click(click_hz, click_time);
break;
case LFK_CLICK_TOGGLE:
if(click_toggle){
click_toggle = 0;
click(4000, 100);
click(1000, 100);
}else{
click_toggle = 1;
click(1000, 100);
click(4000, 100);
}
break;
case LFK_CLICK_TIME_SHORTER:
sign = -1; // continue to next statement
case LFK_CLICK_TIME_LONGER:
click_time += sign;
click(click_hz, click_time);
break;
#endif
}
}
}
void reset_keyboard_kb(){
#ifdef WATCHDOG_ENABLE
MCUSR = 0;
wdt_disable();
wdt_reset();
#endif
set_rgb(31, 0x00, 0xFF, 0xFF);
set_rgb(32, 0x00, 0xFF, 0xFF);
force_issi_refresh();
reset_keyboard();
}
void led_set_kb(uint8_t usb_led)
{
// Set capslock LED to Blue
if (usb_led & (1 << USB_LED_CAPS_LOCK)) {
set_rgb(31, 0x00, 0x00, 0x7F);
}else{
set_rgb(31, 0x00, 0x00, 0x00);
}
led_set_user(usb_led);
}
// Lighting info, see lighting.h for details
const uint8_t switch_matrices[] = {0, 1};
const uint8_t rgb_matrices[] = {6, 7};
// RGB Map:
// 27 29 10 9 8 7 6
// 26 5
// 25 4
// 24 3
// 23 22 21 20 14 15 11 1 2
const uint8_t rgb_sequence[] = {
27, 29, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 11, 15, 14, 20, 21, 22, 23, 24, 25, 26
};
// Maps switch LEDs from Row/Col to ISSI matrix.
// Value breakdown:
// Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// | | ISSI Col | ISSI Row |
// / |
// Device
const uint8_t switch_leds[MATRIX_ROWS][MATRIX_COLS] =
KEYMAP(
0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91,
0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0xA9, 0xA8, 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1,
0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0xB9, 0xB8, 0xB7, 0xB6, 0xB5, 0xB3,
0x49, 0x48, 0x47, 0x45, 0x44, 0x43, 0x42, 0x41, 0xC9, 0xC8, 0xC7, 0xC6, 0xC5, 0xC4, 0xC2,
0x59, 0x58, 0x57, 0x56, 0x55, 0x51, 0xD6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);

View File

@ -0,0 +1,139 @@
#ifndef LFK87_H
#define LFK87_H
/* if the kb.h file exists (because we're running from qmkbuilder) include it */
#if __has_include("kb.h")
#include "kb.h"
#endif
#include "quantum.h"
#include "matrix.h"
#include <avr/sfr_defs.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
typedef struct RGB_Color {
uint16_t red;
uint16_t green;
uint16_t blue;
} RGB_Color;
typedef struct Layer_Info {
uint32_t layer;
uint32_t mask;
RGB_Color color;
} Layer_Info;
extern const uint32_t layer_count;
extern const Layer_Info layer_info[];
enum action_functions {
LFK_CLEAR = 0, // Resets all layers
LFK_ESC_TILDE, // esc+lshift = ~
LFK_SET_DEFAULT_LAYER, // changes and saves current base layer to eeprom
LFK_CLICK_TOGGLE, // Adjusts click duration
LFK_CLICK_FREQ_HIGHER, // Adjusts click frequency
LFK_CLICK_FREQ_LOWER, // Adjusts click frequency
LFK_CLICK_TIME_LONGER, // Adjusts click duration
LFK_CLICK_TIME_SHORTER, // Adjusts click duration
LFK_DEBUG_SETTINGS, // prints LED and click settings to HID
LFK_LED_TEST, // cycles through switch and RGB LEDs
LFK_PLAY_ONEUP
};
#define CLICK_HZ 500
#define CLICK_MS 2
#define CLICK_ENABLED 0
void reset_keyboard_kb(void);
void click(uint16_t freq, uint16_t duration);
#define k00 KC_NO
#ifdef LFK_TKL_REV_A
#ifndef KEYMAP
#define KEYMAP( \
k11, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1d, k1e, k1f, k1g, k1h, \
k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2d, k2e, k2f, k2g, k2h, \
k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g, k3h, \
k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, k4d, \
k51, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k5d, k5g, \
k61, k62, k63, k67, k6b, k6c, k6d, k6e, k6f, k6g, k6h \
) \
{ \
{k11, k00, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1d, k1e, k1f, k1g, k1h}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2d, k2e, k2f, k2g, k2h}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g, k3h}, \
{k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, k4d, k00, k00, k00, k00}, \
{k51, k00, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k5d, k00, k00, k5g, k00}, \
{k61, k62, k63, k00, k00, k00, k67, k00, k00, k00, k6b, k6c, k6d, k6e, k6f, k6g, k6h}, \
}
#endif //!KEYMAP#endif
#ifndef ISO_KEYMAP
#define ISO_KEYMAP( \
k11, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1d, k1e, k1f, k1g, k1h, \
k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2d, k2e, k2f, k2g, k2h, \
k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g, k3h, \
k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, k4d, \
k51, k52, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k5d, k5g, \
k61, k62, k63, k67, k6b, k6c, k6d, k6e, k6f, k6g, k6h \
) \
{ \
{k11, k00, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1d, k1e, k1f, k1g, k1h}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2d, k2e, k2f, k2g, k2h}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g, k3h}, \
{k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, k4d, k00, k00, k00, k00}, \
{k51, k52, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k5d, k00, k00, k5g, k00}, \
{k61, k62, k63, k00, k00, k00, k67, k00, k00, k00, k6b, k6c, k6d, k6e, k6f, k6g, k6h}, \
}
#endif //!ISO_KEYMAP
#else // RevC+ keymaps
#ifndef KEYMAP
#define KEYMAP( \
k71, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1e, k1f, k1g, \
k72, k73, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2e, k2f, k2g, \
k74, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g, \
k61, k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, \
k62, k52, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k5f, \
k63, k64, k65, k67, k6a, k6b, k6c, k6d, k6e, k6f, k6g \
) \
{ \
{k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k00, k1e, k1f, k1g}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k00, k2e, k2f, k2g}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g}, \
{k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, k00, k00, k00, k00}, \
{k00, k52, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k00, k00, k5f, k00}, \
{k61, k62, k63, k64, k65, k00, k67, k00, k00, k6a, k6b, k6c, k6d, k6e, k6f, k6g}, \
{k71, k72, k73, k74, k00, k00, k00, k00, k00, k00, k00, k00, k00, k00, k00, k00}, \
}
#endif //!KEYMAP#endif
#ifndef ISO_KEYMAP
#define ISO_KEYMAP( \
k71, k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k1e, k1f, k1g, \
k72, k73, k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k2e, k2f, k2g, \
k74, k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g, \
k61, k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, \
k62, k51, k52, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k5f, \
k63, k64, k65, k67, k6a, k6b, k6c, k6d, k6e, k6f, k6g \
) \
{ \
{k11, k12, k13, k14, k15, k16, k17, k18, k19, k1a, k1b, k1c, k00, k1e, k1f, k1g}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2a, k2b, k2c, k00, k2e, k2f, k2g}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3a, k3b, k3c, k3d, k3e, k3f, k3g}, \
{k41, k42, k43, k44, k45, k46, k47, k48, k49, k4a, k4b, k4c, k00, k00, k00, k00}, \
{k51, k52, k53, k54, k55, k56, k57, k58, k59, k5a, k5b, k5c, k00, k00, k5f, k00}, \
{k61, k62, k63, k64, k65, k00, k67, k00, k00, k6a, k6b, k6c, k6d, k6e, k6f, k6g}, \
{k71, k72, k73, k74, k00, k00, k00, k00, k00, k00, k00, k00, k00, k00, k00, k00}, \
}
#endif //!ISO_KEYMAP
#endif //Rev
#endif //LFK87_H

View File

@ -0,0 +1,14 @@
LFK87
===
A standard TKL with RGB underglow, in switch backlighting and audio support.
Keyboard Maintainer: [LFKeyboards](https://github.com/lfkeyboards)
Hardware Supported: LFK87, SMK87
Hardware Availability: [LFKeyboards.com](https://www.lfkeyboards.com/)
Make example for this keyboard (after setting up your build environment):
make lfkeyboards/lfk87: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.

View File

@ -0,0 +1,31 @@
# Set the LFK87 hardware version.
#
# A - Green PCB. at90usb1286 Only 3 exist
# B - We don't talk about RevB
# C-D - Black PCB. at90usb646 First public release
#
LFK_REV = C
ifeq ($(LFK_REV), A)
MCU = at90usb1286
OPT_DEFS += -DBOOTLOADER_SIZE=8192
else
MCU = at90usb646
OPT_DEFS += -DBOOTLOADER_SIZE=4096
endif
OPT_DEFS += -DLFK_TKL_REV_$(LFK_REV)
# Extra source files for IS3731 lighting
SRC = TWIlib.c issi.c lighting.c
# Processor frequency.
F_CPU = 16000000
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Input clock frequency.
F_USB = $(F_CPU)
# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT

View File

View File

View File

@ -0,0 +1,157 @@
#ifdef ISSI_ENABLE
#include <avr/sfr_defs.h>
#include <avr/timer_avr.h>
#include <avr/wdt.h>
#include "quantum.h"
// #include "lfk87.h"
#include "issi.h"
#include "TWIlib.h"
#include "lighting.h"
#include "debug.h"
#include "rgblight.h"
#include "audio/audio.h"
extern rgblight_config_t rgblight_config; // Declared in rgblight.c
const uint8_t backlight_pwm_map[BACKLIGHT_LEVELS] = BACKLIGHT_PWM_MAP;
// RGB# to ISSI matrix, this is the same across all revisions
const uint8_t rgb_leds[][3][2] = {
{{0, 0}, {0, 0}, {0, 0}},
{{1, 1}, {2, 3}, {2, 4}}, // RGB1/RGB17
{{2, 1}, {2, 2}, {3, 4}}, // RGB2/RGB18
{{3, 1}, {3, 2}, {3, 3}}, // RGB3/RGB19
{{4, 1}, {4, 2}, {4, 3}}, // RGB4/RGB20
{{5, 1}, {5, 2}, {5, 3}}, // RGB5/RGB21
{{6, 1}, {6, 2}, {6, 3}}, // RGB6/RGB22
{{7, 1}, {7, 2}, {7, 3}}, // RGB6/RGB23
{{8, 1}, {8, 2}, {8, 3}}, // RGB8/RGB24
{{1, 9}, {1, 8}, {1, 7}}, // RGB9/RGB25
{{2, 9}, {2, 8}, {2, 7}}, // RGB10/RGB26
{{3, 9}, {3, 8}, {3, 7}}, // RGB11/RGB27
{{4, 9}, {4, 8}, {4, 7}}, // RGB12/RGB28
{{5, 9}, {5, 8}, {5, 7}}, // RGB13/RGB29
{{6, 9}, {6, 8}, {6, 7}}, // RGB14/RGB30
{{7, 9}, {7, 8}, {6, 6}}, // RGB15/RGB31
{{8, 9}, {7, 7}, {7, 6}} // RGB16/RGB32
};
void set_rgb(uint8_t rgb_led, uint8_t red, uint8_t green, uint8_t blue){
#ifdef RGBLIGHT_ENABLE
uint8_t matrix = rgb_matrices[0];
if(rgb_led >= 17){
matrix = rgb_matrices[1];
rgb_led -= 16;
}
if(rgb_leds[rgb_led][0][1] != 0){
activateLED(matrix, rgb_leds[rgb_led][0][0], rgb_leds[rgb_led][0][1], red);
}
if(rgb_leds[rgb_led][1][1] != 0){
activateLED(matrix, rgb_leds[rgb_led][1][0], rgb_leds[rgb_led][1][1], green);
}
if(rgb_leds[rgb_led][2][1] != 0){
activateLED(matrix, rgb_leds[rgb_led][2][0], rgb_leds[rgb_led][2][1], blue);
}
#endif
}
void backlight_set(uint8_t level){
#ifdef BACKLIGHT_ENABLE
uint8_t pwm_value = 0;
if(level >= BACKLIGHT_LEVELS){
level = BACKLIGHT_LEVELS;
}
if(level > 0){
pwm_value = backlight_pwm_map[level-1];
}
for(int x = 1; x <= 9; x++){
for(int y = 1; y <= 9; y++){
activateLED(switch_matrices[0], x, y, pwm_value);
activateLED(switch_matrices[1], x, y, pwm_value);
}
}
#endif
}
void set_underglow(uint8_t red, uint8_t green, uint8_t blue){
#ifdef RGBLIGHT_ENABLE
for(uint8_t x = 1; x <= 32; x++){
set_rgb(x, red, green, blue);
}
#endif
}
void rgblight_set(void) {
#ifdef RGBLIGHT_ENABLE
for(uint8_t i = 0; (i < sizeof(rgb_sequence)) && (i < RGBLED_NUM); i++){
if(rgblight_config.enable){
set_rgb(rgb_sequence[i], led[i].r, led[i].g, led[i].b);
}else{
set_rgb(rgb_sequence[i], 0, 0, 0);
}
}
#endif
}
void set_backlight_by_keymap(uint8_t col, uint8_t row){
#ifdef RGBLIGHT_ENABLE
uint8_t lookup_value = switch_leds[row][col];
uint8_t matrix = switch_matrices[0];
if(lookup_value & 0x80){
matrix = switch_matrices[1];
}
issi_devices[0]->led_dirty = 1;
uint8_t led_col = (lookup_value & 0x70) >> 4;
uint8_t led_row = lookup_value & 0x0F;
activateLED(matrix, led_col, led_row, 255);
#endif
}
void force_issi_refresh(){
#ifdef ISSI_ENABLE
issi_devices[0]->led_dirty = true;
update_issi(0, true);
issi_devices[3]->led_dirty = true;
update_issi(3, true);
#endif
}
void led_test(){
#ifdef ISSI_ENABLE
#ifdef WATCHDOG_ENABLE
// This test take a long time to run, disable the WTD until its complete
wdt_disable();
#endif
backlight_set(0);
set_underglow(0, 0, 0);
force_issi_refresh();
set_underglow(0, 0, 0);
for(uint8_t x = 0; x < sizeof(rgb_sequence); x++){
set_rgb(rgb_sequence[x], 255, 0, 0);
force_issi_refresh();
_delay_ms(250);
set_rgb(rgb_sequence[x], 0, 255, 0);
force_issi_refresh();
_delay_ms(250);
set_rgb(rgb_sequence[x], 0, 0, 255);
force_issi_refresh();
_delay_ms(250);
set_rgb(rgb_sequence[x], 0, 0, 0);
force_issi_refresh();
}
#ifdef WATCHDOG_ENABLE
wdt_enable(WDTO_250MS);
#endif
#endif
}
void backlight_init_ports(void){
issi_init();
}
#endif

View File

@ -0,0 +1,53 @@
#ifndef LIGHTING_H
#define LIGHTING_H
// rgb_sequence[RGBLED_NUM]
//
// Array used for sequential lighting effects.
//
// Example LFK78 RevC+ RGB Map:
// 27 29 10 9 8 7 6
// 26 5
// 25 4
// 24 3
// 23 22 21 20 14 15 11 1 2
//
// const uint8_t rgb_sequence[] = {
// 27, 29, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,
// 11, 15, 14, 20, 21, 22, 23, 24, 25, 26
// };
extern const uint8_t rgb_sequence[RGBLED_NUM];
// switch_matrices[]
//
// The ISSI matrices for switch backlighting
//
// Example LFK78 RevC+ - ISSI Device 0, banks 0 and 1:
// switch_matrices[] = {0, 1};
extern const uint8_t switch_matrices[];
// rgb_matrices[]
// The ISSI matrices for RGB Underglow
//
// Example LFK78 RevC+ - ISSI Device 3, banks 0 and 1:
// rgb_matrices[] = {6, 7};
extern const uint8_t rgb_matrices[];
// switch_leds[MATRIX_ROWS][MATRIX_COLS]
// Maps switch LEDs from Row/Col to ISSI matrix.
// Value breakdown:
// Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// | | ISSI Col | ISSI Row |
// | |
// Device
extern const uint8_t switch_leds[MATRIX_ROWS][MATRIX_COLS];
void led_test(void);
void force_issi_refresh(void);
void set_backlight(uint8_t level);
void set_underglow(uint8_t red, uint8_t green, uint8_t blue);
void set_rgb(uint8_t rgb_led, uint8_t red, uint8_t green, uint8_t blue);
void set_backlight_by_keymap(uint8_t col, uint8_t row);
#endif

View File

@ -0,0 +1 @@
SRC = TWIlib.c issi.c lighting.c

View File

@ -0,0 +1,168 @@
/*
Copyright 2012 Jun Wako <wakojun@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 CONFIG_H
#define CONFIG_H
#include "config_common.h"
#define VENDOR_ID 0xFEED
#define PRODUCT_ID 0x6062
#define DEVICE_VER 0x0001
#define MANUFACTURER LFKeyboards
#define PRODUCT SMK65v2
#define DESCRIPTION QMK keyboard firmware for SMK65
// RevA
// #define DIODE_DIRECTION COL2ROW
// #define MATRIX_ROWS 5
// #define MATRIX_COLS 16
// #define MATRIX_ROW_PINS {B7, F7, F6, F5, F4}
// #define MATRIX_COL_PINS {F0, F1, D2, D3, D5, D4, D6, D7, B4, B5, B6, C7, B3, B2, B1, B0}
// #define UNUSED_PINS {}
// RevB
#define DIODE_DIRECTION COL2ROW
#define MATRIX_ROWS 5
#define MATRIX_COLS 16
#define MATRIX_ROW_PINS {D6, D7, E0, C3, C4}
#define MATRIX_COL_PINS {F2, C5, E5, E4, B7, B6, B5, B4, B3, B2, B1, B0, E1, C0, C1, C2}
#define UNUSED_PINS {}
#define RGBLED_NUM 20 // Number of LEDs
//RevB only:
#define AUDIO_VOICES
#define C6_AUDIO
// #define B5_AUDIO
#define BACKLIGHT_LEVELS 8
#define BACKLIGHT_PWM_MAP {8, 16, 40, 55, 70, 128, 200, 255}
#define RGB_DI_PIN C7 // Have to set it to something to get the ws2812 code to compile
#define RGBLED_NUM 20 // Number of LEDs
#define RGBLIGHT_ANIMATIONS
#define RGBLIGHT_HUE_STEP 10
#define RGBLIGHT_SAT_STEP 17
#define RGBLIGHT_VAL_STEP 17
/* 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
/*
* 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)) \
)
/* control how magic key switches layers */
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS true
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS true
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM false
/* override magic key keymap */
//#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS
//#define MAGIC_KEY_SWITCH_LAYER_WITH_CUSTOM
//#define MAGIC_KEY_HELP1 H
//#define MAGIC_KEY_HELP2 SLASH
//#define MAGIC_KEY_DEBUG D
//#define MAGIC_KEY_DEBUG_MATRIX X
//#define MAGIC_KEY_DEBUG_KBD K
//#define MAGIC_KEY_DEBUG_MOUSE M
//#define MAGIC_KEY_VERSION V
//#define MAGIC_KEY_STATUS S
//#define MAGIC_KEY_CONSOLE C
//#define MAGIC_KEY_LAYER0_ALT1 ESC
//#define MAGIC_KEY_LAYER0_ALT2 GRAVE
//#define MAGIC_KEY_LAYER0 0
//#define MAGIC_KEY_LAYER1 1
//#define MAGIC_KEY_LAYER2 2
//#define MAGIC_KEY_LAYER3 3
//#define MAGIC_KEY_LAYER4 4
//#define MAGIC_KEY_LAYER5 5
//#define MAGIC_KEY_LAYER6 6
//#define MAGIC_KEY_LAYER7 7
//#define MAGIC_KEY_LAYER8 8
//#define MAGIC_KEY_LAYER9 9
//#define MAGIC_KEY_BOOTLOADER PAUSE
//#define MAGIC_KEY_LOCK CAPS
//#define MAGIC_KEY_EEPROM E
//#define MAGIC_KEY_NKRO N
//#define MAGIC_KEY_SLEEP_LED Z
/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/
/* disable debug print */
//#define NO_DEBUG
/* disable print */
//#define NO_PRINT
/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
#endif

View File

@ -0,0 +1,8 @@
#ifndef CONFIG_USER_H
#define CONFIG_USER_H
#include "../../config.h"
// place overrides here
#endif

View File

@ -0,0 +1,85 @@
#include "smk65.h"
#include "action_layer.h"
//Define a shorter 'transparent' key code to make the keymaps more compact
#define KC_TR KC_TRNS
enum keymap_layout {
VANILLA = 0,
FUNC,
SETTINGS,
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[VANILLA] = KEYMAP(
/* Keymap VANILLA: (Base Layer) Default Layer
* ,------------------------------------------------------------.----.
* |Esc~| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0| - | = |Backspa| Ins|
* |------------------------------------------------------------|----|
* |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| Del|
* |------------------------------------------------------------|----|
* |CAPS | A| S| D| F| G| H| J| K| L| ;| '|Return |PgUp|
* |------------------------------------------------------------|----|
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Up |PgDn|
* |-----------------------------------------------------------------|
* |Ctrl|Win |Alt | Space |Alt |Ctrl|Func|Lft| Dn |Rig |
* `-----------------------------------------------------------------'
*/
KC_GESC,KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL,
KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_PGUP,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_PGDN,
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, KC_RCTL, MO(FUNC), KC_LEFT, KC_DOWN, KC_RGHT),
[FUNC] = KEYMAP(
/* Keymap VANILLA: Function Layer
* ,------------------------------------------------------------.----.
* |Esc~| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0| - | = |Backspa| Ins|
* |------------------------------------------------------------|----|
* |AudTgl| Q| W| E| R| T| Y| U| I| O| P| [| ]| \| Del|
* |------------------------------------------------------------|----|
* |CAPS | A| S| D| F| G| H| J| K| L| ;| '|Return |PgUp|
* |------------------------------------------------------------|----|
* |Shift | Z| X| C| V| B| N| M| ,| .| /|Shift |Up |PgDn|
* |-----------------------------------------------------------------|
* |Ctrl|Win |Alt | Space |Alt |Ctrl|Func|Lft| Dn |Rig |
* `-----------------------------------------------------------------'
*/
KC_GRV,KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_F13, KC_F14,
AU_TOG, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR,
KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR,
KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR,
KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR, KC_TR),
};
const uint16_t PROGMEM fn_actions[] = {
ACTION_FUNCTION(LFK_CLEAR), // FN0 - reset layers
ACTION_FUNCTION(LFK_ESC_TILDE), // FN1 - esc+shift = ~, else escape
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
{
// MACRODOWN only works in this function
switch(id) {
}
return MACRO_NONE;
};
void matrix_init_user(void) {
}
void matrix_scan_user(void) {
}
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
return true;
}
void led_set_user(uint8_t usb_led) {
}

View File

@ -0,0 +1,36 @@
# Build Options
# change to "no" to disable the options, or define them in the Makefile in
# the appropriate keymap folder that will get included automatically
#
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
NKRO_ENABLE = yes # Nkey Rollover - if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
BACKLIGHT_ENABLE = no # Disable keyboard backlight functionality
MIDI_ENABLE = no # MIDI controls
AUDIO_ENABLE = yes # Audio output on port C6
UNICODE_ENABLE = no # Unicode
BLUETOOTH_ENABLE = no # Disable Bluetooth with the Adafruit EZ-Key HID
RGBLIGHT_ENABLE = yes # Disable RGB underlight
RGBLIGHT_CUSTOM_DRIVER = yes # RGB code is implemented in lefkeyboards, not WS2812
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
TAP_DANCE_ENABLE = no
ISSI_ENABLE = yes # If the I2C pullup resistors aren't install this must be disabled
WATCHDOG_ENABLE = no # Resets keyboard if matrix_scan isn't run every 250ms
ifndef QUANTUM_DIR
include ../../../../Makefile
endif
ifeq ($(strip $(ISSI_ENABLE)), yes)
TMK_COMMON_DEFS += -DISSI_ENABLE
endif
ifeq ($(strip $(WATCHDOG_ENABLE)), yes)
TMK_COMMON_DEFS += -DWATCHDOG_ENABLE
endif

View File

@ -0,0 +1,14 @@
SMK65
===
65% layout based on Mat3o's Whitefox, but with support for SMK switches.
Keyboard Maintainer: [LFKeyboards](https://github.com/lfkeyboards)
Hardware Supported: SMK65
Hardware Availability: [LFKeyboards.com](https://www.lfkeyboards.com/)
Make example for this keyboard (after setting up your build environment):
make lfkeyboards/smk65: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.

View File

@ -0,0 +1,17 @@
MCU = at90usb646
OPT_DEFS += -DBOOTLOADER_SIZE=4096
# Extra source files for IS3731 lighting
SRC = TWIlib.c issi.c lighting.c
# Processor frequency.
F_CPU = 16000000
# Target architecture (see library "Board Types" documentation).
ARCH = AVR8
# Input clock frequency.
F_USB = $(F_CPU)
# Interrupt driven control endpoint task(+60)
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT

View File

@ -0,0 +1,164 @@
#include <avr/sfr_defs.h>
#include <avr/timer_avr.h>
#include <avr/wdt.h>
#include "smk65.h"
#include "keymap.h"
#include "debug.h"
#include "issi.h"
#include "TWIlib.h"
#include "lighting.h"
uint16_t click_hz = CLICK_HZ;
uint16_t click_time = CLICK_MS;
uint8_t click_toggle = CLICK_ENABLED;
void matrix_init_kb(void)
{
matrix_init_user();
#ifdef AUDIO_ENABLE
// audio_init() sets PB5 to output and drives it low, which breaks our matrix
// so reset PB5 to input
cbi(DDRB, 5);
sbi(PORTB, 5);
#else
// If we're not using the audio pin, drive it low
sbi(DDRC, 6);
cbi(PORTC, 6);
#endif
#ifdef ISSI_ENABLE
issi_init();
#endif
}
void matrix_scan_kb(void)
{
#ifdef WATCHDOG_ENABLE
wdt_reset();
#endif
matrix_scan_user();
}
void click(uint16_t freq, uint16_t duration){
#ifdef AUDIO_ENABLE
if(freq >= 100 && freq <= 20000 && duration < 100){
play_note(freq, 10);
for (uint16_t i = 0; i < duration; i++){
_delay_ms(1);
}
stop_all_notes();
}
#endif
}
bool process_record_kb(uint16_t keycode, keyrecord_t* record)
{
// Test code that turns on the switch led for the key that is pressed
// set_backlight_by_keymap(record->event.key.col, record->event.key.row);
if (click_toggle && record->event.pressed){
click(click_hz, click_time);
}
if (keycode == RESET) {
reset_keyboard_kb();
} else {
}
return process_record_user(keycode, record);
}
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt)
{
#ifdef AUDIO_ENABLE
int8_t sign = 1;
#endif
if(id == LFK_ESC_TILDE){
// Send ~ on shift-esc
void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key;
uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT));
method(shifted ? KC_GRAVE : KC_ESCAPE);
send_keyboard_report();
}else if(event->event.pressed){
switch(id){
case LFK_SET_DEFAULT_LAYER:
// set/save the current base layer to eeprom, falls through to LFK_CLEAR
eeconfig_update_default_layer(1UL << opt);
default_layer_set(1UL << opt);
case LFK_CLEAR:
// Go back to default layer
layer_clear();
break;
#ifdef AUDIO_ENABLE
case LFK_CLICK_FREQ_LOWER:
sign = -1; // continue to next statement
case LFK_CLICK_FREQ_HIGHER:
click_hz += sign * 100;
click(click_hz, click_time);
break;
case LFK_CLICK_TOGGLE:
if(click_toggle){
click_toggle = 0;
click(4000, 100);
click(1000, 100);
}else{
click_toggle = 1;
click(1000, 100);
click(4000, 100);
}
break;
case LFK_CLICK_TIME_SHORTER:
sign = -1; // continue to next statement
case LFK_CLICK_TIME_LONGER:
click_time += sign;
click(click_hz, click_time);
break;
#endif
case LFK_DEBUG_SETTINGS:
dprintf("Click:\n");
dprintf(" toggle: %d\n", click_toggle);
dprintf(" freq(hz): %d\n", click_hz);
dprintf(" duration(ms): %d\n", click_time);
break;
}
}
}
void reset_keyboard_kb(){
#ifdef WATCHDOG_ENABLE
MCUSR = 0;
wdt_disable();
wdt_reset();
#endif
reset_keyboard();
}
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);
}
// LFK lighting info
const uint8_t switch_matrices[] = {0, 1};
const uint8_t rgb_matrices[] = {6, 7};
// const uint8_t rgb_sequence[] = {
// 14, 24, 23, 22, 21, 20, 19, 18, 26, 25, 28, 29,
// 30, 31, 32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
// };
const uint8_t rgb_sequence[] = {
25, 28, 29,
30, 31, 32, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14
};
// Maps switch LEDs from Row/Col to ISSI matrix.
// Value breakdown:
// Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
// / \ ISSI Col | ISSI Row |
// matrix idx
// const uint8_t switch_leds[MATRIX_ROWS][MATRIX_COLS] =
// KEYMAP(
// 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x99, 0x98, 0x97, 0x96, 0x95, 0x94, 0x93, 0x92, 0x91,
// 0x29, 0x28, 0x27, 0x26, 0x25, 0x24, 0x23, 0x22, 0x21, 0xA9, 0xA8, 0xA7, 0xA6, 0xA5, 0xA4, 0xA3, 0xA2, 0xA1,
// 0x39, 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31, 0xB9, 0xB8, 0xB7, 0xB6, 0xB5, 0xB3,
// 0x49, 0x48, 0x47, 0x45, 0x44, 0x43, 0x42, 0x41, 0xC9, 0xC8, 0xC7, 0xC6, 0xC5, 0xC4, 0xC2,
// 0x59, 0x58, 0x57, 0x56, 0x55, 0x51, 0xD6, 0xE5, 0xE4, 0xE3, 0xE2, 0xE1);

View File

@ -0,0 +1,90 @@
#ifndef SMK65_H
#define SMK65_H
/* if the kb.h file exists (because we're running from qmkbuilder) include it */
#ifdef __has_include
#if __has_include("kb.h")
#include "kb.h"
#endif
#endif
#include "quantum.h"
#include "matrix.h"
#include <avr/sfr_defs.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
typedef struct RGB_Color {
uint16_t red;
uint16_t green;
uint16_t blue;
} RGB_Color;
typedef struct Layer_Info {
uint32_t layer;
uint32_t mask;
RGB_Color color;
} Layer_Info;
extern const uint32_t layer_count;
extern const Layer_Info layer_info[];
enum action_functions {
LFK_CLEAR = 0, // Resets all layers
LFK_ESC_TILDE, // esc+lshift = ~
LFK_SET_DEFAULT_LAYER, // changes and saves current base layer to eeprom
LFK_CLICK_TOGGLE, // Adjusts click duration
LFK_CLICK_FREQ_HIGHER, // Adjusts click frequency
LFK_CLICK_FREQ_LOWER, // Adjusts click frequency
LFK_CLICK_TIME_LONGER, // Adjusts click duration
LFK_CLICK_TIME_SHORTER, // Adjusts click duration
LFK_DEBUG_SETTINGS, // prints LED and click settings to HID
LFK_LED_TEST // cycles through switch and RGB LEDs
};
#define CLICK_HZ 500
#define CLICK_MS 2
#define CLICK_ENABLED 0
void reset_keyboard_kb(void);
void click(uint16_t freq, uint16_t duration);
/* Vanilla Keymap */
// This a shortcut to help you visually see your layout.
/*
* ,-------------------------------------------------------------------------------.
* | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 1A | 1B | 1C | 1D | 1E | 1G |
* |-------------------------------------------------------------------------------|
* | 21 | 22 |23 | 24 | 25 | 26 | 27 | 28 | 29 | 2A | 2B | 2C | 2D | 2F | 2G |
* |-------------------------------------------------------------------------------|
* | 31 | 32 |33 | 34 | 35 | 36 | 37 | 38 | 39 | 3A | 3B | 3C | 3F | 3G |
* |-------------------------------------------------------------------------------|
* | 41 | 42 |43 | 45 | 46 | 47 | 48 | 49 | 4A | 4B | 4C | 4D | 4F | 4G |
* |-------------------------------------------------------------------------------|
* | 51 | 52 | 53 | 57 | 5A | 5B | 5C | 5D | 5E | 3E | 4E |
* `-------------------------------------------------------------------------------'
*/
// The first section contains all of the arguements
// The second converts the arguments into a two-dimensional array
#define KEYMAP( \
k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, k1F, k1G, \
k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, k2F, k2G, \
k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, k3F, k3G, \
k41, k43, k44, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4F, k4G, \
k51, k52, k53, k57, k5B, k5C, k5D, k5E, k3E, k4E \
) { \
{k11, k12, k13, k14, k15, k16, k17, k18, k19, k1A, k1B, k1C, k1D, KC_NO, k1F, k1G}, \
{k21, k22, k23, k24, k25, k26, k27, k28, k29, k2A, k2B, k2C, k2D, KC_NO, k2F, k2G}, \
{k31, k32, k33, k34, k35, k36, k37, k38, k39, k3A, k3B, k3C, KC_NO, k3E, k3F, k3G}, \
{k41, KC_NO, k43, k44, k45, k46, k47, k48, k49, k4A, k4B, k4C, k4D, k4E, k4F, k4G}, \
{k51, k52, k53, KC_NO, KC_NO, KC_NO, k57, KC_NO, KC_NO, KC_NO, k5B, k5C, k5D, k5E, KC_NO, KC_NO}, \
}
#endif //SMK65_H