DC01 keyboard addition (#3428)
* DC01 initial commit - Addition of directories - Left readme * Initial commit of left half * Initial files for right half * arrow * i2c adjustments * I2C slave and DC01 refractoring - Cleaned up state machine of I2C slave driver - Modified DC01 left to use already pressent I2C master driver - Modified DC01 matrixes * Fixed tabs to spaces * Addition of Numpad * Add keymaps - Orthopad keymap for numpad module - Numpad keymap for numpad module - ISO, ANSI and HHKB version of keymap for right module * Minor matrix.c fixes * Update Readmes
This commit is contained in:
parent
7e9a7af672
commit
72fd49b146
50 changed files with 3751 additions and 146 deletions
|
@ -15,15 +15,15 @@
|
||||||
void i2c_init(void)
|
void i2c_init(void)
|
||||||
{
|
{
|
||||||
TWSR = 0; /* no prescaler */
|
TWSR = 0; /* no prescaler */
|
||||||
TWBR = (uint8_t)TWBR_val;
|
TWBR = (uint8_t)TWBR_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t i2c_start(uint8_t address, uint16_t timeout)
|
i2c_status_t i2c_start(uint8_t address, uint16_t timeout)
|
||||||
{
|
{
|
||||||
// reset TWI control register
|
// reset TWI control register
|
||||||
TWCR = 0;
|
TWCR = 0;
|
||||||
// transmit START condition
|
// transmit START condition
|
||||||
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
|
TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN);
|
||||||
|
|
||||||
uint16_t timeout_timer = timer_read();
|
uint16_t timeout_timer = timer_read();
|
||||||
while( !(TWCR & (1<<TWINT)) ) {
|
while( !(TWCR & (1<<TWINT)) ) {
|
||||||
|
@ -32,13 +32,13 @@ i2c_status_t i2c_start(uint8_t address, uint16_t timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the start condition was successfully transmitted
|
// check if the start condition was successfully transmitted
|
||||||
if(((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)){ return I2C_STATUS_ERROR; }
|
if(((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)){ return I2C_STATUS_ERROR; }
|
||||||
|
|
||||||
// load slave address into data register
|
// load slave address into data register
|
||||||
TWDR = address;
|
TWDR = address;
|
||||||
// start transmission of address
|
// start transmission of address
|
||||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||||
|
|
||||||
timeout_timer = timer_read();
|
timeout_timer = timer_read();
|
||||||
while( !(TWCR & (1<<TWINT)) ) {
|
while( !(TWCR & (1<<TWINT)) ) {
|
||||||
|
@ -47,19 +47,19 @@ i2c_status_t i2c_start(uint8_t address, uint16_t timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the device has acknowledged the READ / WRITE mode
|
// check if the device has acknowledged the READ / WRITE mode
|
||||||
uint8_t twst = TW_STATUS & 0xF8;
|
uint8_t twst = TW_STATUS & 0xF8;
|
||||||
if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return I2C_STATUS_ERROR;
|
if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return I2C_STATUS_ERROR;
|
||||||
|
|
||||||
return I2C_STATUS_SUCCESS;
|
return I2C_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t i2c_write(uint8_t data, uint16_t timeout)
|
i2c_status_t i2c_write(uint8_t data, uint16_t timeout)
|
||||||
{
|
{
|
||||||
// load data into data register
|
// load data into data register
|
||||||
TWDR = data;
|
TWDR = data;
|
||||||
// start transmission of data
|
// start transmission of data
|
||||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||||
|
|
||||||
uint16_t timeout_timer = timer_read();
|
uint16_t timeout_timer = timer_read();
|
||||||
while( !(TWCR & (1<<TWINT)) ) {
|
while( !(TWCR & (1<<TWINT)) ) {
|
||||||
|
@ -68,16 +68,16 @@ i2c_status_t i2c_write(uint8_t data, uint16_t timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (TW_STATUS & 0xF8) != TW_MT_DATA_ACK ){ return I2C_STATUS_ERROR; }
|
if( (TW_STATUS & 0xF8) != TW_MT_DATA_ACK ){ return I2C_STATUS_ERROR; }
|
||||||
|
|
||||||
return I2C_STATUS_SUCCESS;
|
return I2C_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t i2c_read_ack(uint16_t timeout)
|
int16_t i2c_read_ack(uint16_t timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
// start TWI module and acknowledge data after reception
|
// start TWI module and acknowledge data after reception
|
||||||
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
|
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
|
||||||
|
|
||||||
uint16_t timeout_timer = timer_read();
|
uint16_t timeout_timer = timer_read();
|
||||||
while( !(TWCR & (1<<TWINT)) ) {
|
while( !(TWCR & (1<<TWINT)) ) {
|
||||||
|
@ -86,15 +86,15 @@ int16_t i2c_read_ack(uint16_t timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return received data from TWDR
|
// return received data from TWDR
|
||||||
return TWDR;
|
return TWDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t i2c_read_nack(uint16_t timeout)
|
int16_t i2c_read_nack(uint16_t timeout)
|
||||||
{
|
{
|
||||||
|
|
||||||
// start receiving without acknowledging reception
|
// start receiving without acknowledging reception
|
||||||
TWCR = (1<<TWINT) | (1<<TWEN);
|
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||||
|
|
||||||
uint16_t timeout_timer = timer_read();
|
uint16_t timeout_timer = timer_read();
|
||||||
while( !(TWCR & (1<<TWINT)) ) {
|
while( !(TWCR & (1<<TWINT)) ) {
|
||||||
|
@ -103,39 +103,39 @@ int16_t i2c_read_nack(uint16_t timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return received data from TWDR
|
// return received data from TWDR
|
||||||
return TWDR;
|
return TWDR;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout)
|
i2c_status_t i2c_transmit(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout)
|
||||||
{
|
{
|
||||||
i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
|
i2c_status_t status = i2c_start(address | I2C_WRITE, timeout);
|
||||||
if (status) return status;
|
|
||||||
|
|
||||||
for (uint16_t i = 0; i < length; i++) {
|
|
||||||
status = i2c_write(data[i], timeout);
|
|
||||||
if (status) return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
status = i2c_stop(timeout);
|
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
return I2C_STATUS_SUCCESS;
|
for (uint16_t i = 0; i < length; i++) {
|
||||||
|
status = i2c_write(data[i], timeout);
|
||||||
|
if (status) return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = i2c_stop(timeout);
|
||||||
|
if (status) return status;
|
||||||
|
|
||||||
|
return I2C_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout)
|
i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16_t timeout)
|
||||||
{
|
{
|
||||||
i2c_status_t status = i2c_start(address | I2C_READ, timeout);
|
i2c_status_t status = i2c_start(address | I2C_READ, timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < (length-1); i++) {
|
for (uint16_t i = 0; i < (length-1); i++) {
|
||||||
status = i2c_read_ack(timeout);
|
status = i2c_read_ack(timeout);
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
data[i] = status;
|
data[i] = status;
|
||||||
} else {
|
} else {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = i2c_read_nack(timeout);
|
status = i2c_read_nack(timeout);
|
||||||
if (status >= 0 ) {
|
if (status >= 0 ) {
|
||||||
|
@ -147,47 +147,47 @@ i2c_status_t i2c_receive(uint8_t address, uint8_t* data, uint16_t length, uint16
|
||||||
status = i2c_stop(timeout);
|
status = i2c_stop(timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
return I2C_STATUS_SUCCESS;
|
return I2C_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
|
i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
|
||||||
{
|
{
|
||||||
i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
|
i2c_status_t status = i2c_start(devaddr | 0x00, timeout);
|
||||||
if (status) return status;
|
|
||||||
|
|
||||||
status = i2c_write(regaddr, timeout);
|
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < length; i++) {
|
status = i2c_write(regaddr, timeout);
|
||||||
|
if (status) return status;
|
||||||
|
|
||||||
|
for (uint16_t i = 0; i < length; i++) {
|
||||||
status = i2c_write(data[i], timeout);
|
status = i2c_write(data[i], timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = i2c_stop(timeout);
|
status = i2c_stop(timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
return I2C_STATUS_SUCCESS;
|
return I2C_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
|
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout)
|
||||||
{
|
{
|
||||||
i2c_status_t status = i2c_start(devaddr, timeout);
|
i2c_status_t status = i2c_start(devaddr, timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
status = i2c_write(regaddr, timeout);
|
status = i2c_write(regaddr, timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
status = i2c_start(devaddr | 0x01, timeout);
|
status = i2c_start(devaddr | 0x01, timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
for (uint16_t i = 0; i < (length-1); i++) {
|
for (uint16_t i = 0; i < (length-1); i++) {
|
||||||
status = i2c_read_ack(timeout);
|
status = i2c_read_ack(timeout);
|
||||||
if (status >= 0) {
|
if (status >= 0) {
|
||||||
data[i] = status;
|
data[i] = status;
|
||||||
} else {
|
} else {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
status = i2c_read_nack(timeout);
|
status = i2c_read_nack(timeout);
|
||||||
if (status >= 0 ) {
|
if (status >= 0 ) {
|
||||||
|
@ -199,13 +199,13 @@ i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16
|
||||||
status = i2c_stop(timeout);
|
status = i2c_stop(timeout);
|
||||||
if (status) return status;
|
if (status) return status;
|
||||||
|
|
||||||
return I2C_STATUS_SUCCESS;
|
return I2C_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
i2c_status_t i2c_stop(uint16_t timeout)
|
i2c_status_t i2c_stop(uint16_t timeout)
|
||||||
{
|
{
|
||||||
// transmit STOP condition
|
// transmit STOP condition
|
||||||
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
|
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
|
||||||
|
|
||||||
uint16_t timeout_timer = timer_read();
|
uint16_t timeout_timer = timer_read();
|
||||||
while(TWCR & (1<<TWSTO)) {
|
while(TWCR & (1<<TWSTO)) {
|
||||||
|
@ -215,4 +215,4 @@ i2c_status_t i2c_stop(uint16_t timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
return I2C_STATUS_SUCCESS;
|
return I2C_STATUS_SUCCESS;
|
||||||
}
|
}
|
|
@ -28,4 +28,4 @@ i2c_status_t i2c_writeReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint1
|
||||||
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
|
i2c_status_t i2c_readReg(uint8_t devaddr, uint8_t regaddr, uint8_t* data, uint16_t length, uint16_t timeout);
|
||||||
i2c_status_t i2c_stop(uint16_t timeout);
|
i2c_status_t i2c_stop(uint16_t timeout);
|
||||||
|
|
||||||
#endif // I2C_MASTER_H
|
#endif // I2C_MASTER_H
|
|
@ -5,96 +5,64 @@
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#include <util/twi.h>
|
#include <util/twi.h>
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include "i2c_slave.h"
|
#include "i2c_slave.h"
|
||||||
|
|
||||||
void i2c_init(uint8_t address){
|
void i2c_init(uint8_t address){
|
||||||
// load address into TWI address register
|
// load address into TWI address register
|
||||||
TWAR = (address << 1);
|
TWAR = (address << 1);
|
||||||
// set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt
|
// set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt
|
||||||
TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN);
|
TWCR = (1 << TWIE) | (1 << TWEA) | (1 << TWINT) | (1 << TWEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void i2c_stop(void){
|
void i2c_stop(void){
|
||||||
// clear acknowledge and enable bits
|
// clear acknowledge and enable bits
|
||||||
TWCR &= ~( (1<<TWEA) | (1<<TWEN) );
|
TWCR &= ~((1 << TWEA) | (1 << TWEN));
|
||||||
}
|
}
|
||||||
|
|
||||||
ISR(TWI_vect){
|
ISR(TWI_vect){
|
||||||
|
uint8_t ack = 1;
|
||||||
// temporary stores the received data
|
// temporary stores the received data
|
||||||
uint8_t data;
|
//uint8_t data;
|
||||||
|
|
||||||
// own address has been acknowledged
|
switch(TW_STATUS){
|
||||||
if( (TWSR & 0xF8) == TW_SR_SLA_ACK ){
|
case TW_SR_SLA_ACK:
|
||||||
buffer_address = 0xFF;
|
// The device is now a slave receiver
|
||||||
// clear TWI interrupt flag, prepare to receive next byte and acknowledge
|
slave_has_register_set = false;
|
||||||
TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEA) | (1<<TWEN);
|
break;
|
||||||
}
|
|
||||||
else if( (TWSR & 0xF8) == TW_SR_DATA_ACK ){ // data has been received in slave receiver mode
|
case TW_SR_DATA_ACK:
|
||||||
|
// This device is a slave receiver and has received data
|
||||||
// save the received byte inside data
|
// First byte is the location then the bytes will be writen in buffer with auto-incriment
|
||||||
data = TWDR;
|
if(!slave_has_register_set){
|
||||||
|
buffer_address = TWDR;
|
||||||
// check wether an address has already been transmitted or not
|
|
||||||
if(buffer_address == 0xFF){
|
if (buffer_address >= RX_BUFFER_SIZE){ // address out of bounds dont ack
|
||||||
|
ack = 0;
|
||||||
buffer_address = data;
|
buffer_address = 0;
|
||||||
|
}
|
||||||
// clear TWI interrupt flag, prepare to receive next byte and acknowledge
|
slave_has_register_set = true; // address has been receaved now fill in buffer
|
||||||
TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEA) | (1<<TWEN);
|
} else {
|
||||||
}
|
rxbuffer[buffer_address] = TWDR;
|
||||||
else{ // if a databyte has already been received
|
buffer_address++;
|
||||||
|
}
|
||||||
// store the data at the current address
|
break;
|
||||||
rxbuffer[buffer_address] = data;
|
|
||||||
|
case TW_ST_SLA_ACK:
|
||||||
// increment the buffer address
|
case TW_ST_DATA_ACK:
|
||||||
buffer_address++;
|
// This device is a slave transmitter and master has requested data
|
||||||
|
TWDR = txbuffer[buffer_address];
|
||||||
// if there is still enough space inside the buffer
|
buffer_address++;
|
||||||
if(buffer_address < 0xFF){
|
break;
|
||||||
// clear TWI interrupt flag, prepare to receive next byte and acknowledge
|
|
||||||
TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEA) | (1<<TWEN);
|
case TW_BUS_ERROR:
|
||||||
}
|
// We got an error, reset i2c
|
||||||
else{
|
TWCR = 0;
|
||||||
// Don't acknowledge
|
default:
|
||||||
TWCR &= ~(1<<TWEA);
|
break;
|
||||||
// clear TWI interrupt flag, prepare to receive last byte.
|
}
|
||||||
TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEN);
|
|
||||||
}
|
// Reset i2c state mahcine to be ready for next interrupt
|
||||||
}
|
TWCR |= (1 << TWIE) | (1 << TWINT) | (ack << TWEA) | (1 << TWEN);
|
||||||
}
|
}
|
||||||
else if( (TWSR & 0xF8) == TW_ST_DATA_ACK ){ // device has been addressed to be a transmitter
|
|
||||||
|
|
||||||
// copy data from TWDR to the temporary memory
|
|
||||||
data = TWDR;
|
|
||||||
|
|
||||||
// if no buffer read address has been sent yet
|
|
||||||
if( buffer_address == 0xFF ){
|
|
||||||
buffer_address = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy the specified buffer address into the TWDR register for transmission
|
|
||||||
TWDR = txbuffer[buffer_address];
|
|
||||||
// increment buffer read address
|
|
||||||
buffer_address++;
|
|
||||||
|
|
||||||
// if there is another buffer address that can be sent
|
|
||||||
if(buffer_address < 0xFF){
|
|
||||||
// clear TWI interrupt flag, prepare to send next byte and receive acknowledge
|
|
||||||
TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEA) | (1<<TWEN);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// Don't acknowledge
|
|
||||||
TWCR &= ~(1<<TWEA);
|
|
||||||
// clear TWI interrupt flag, prepare to receive last byte.
|
|
||||||
TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEN);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
// if none of the above apply prepare TWI to be addressed again
|
|
||||||
TWCR |= (1<<TWIE) | (1<<TWEA) | (1<<TWEN);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,12 +8,16 @@
|
||||||
#ifndef I2C_SLAVE_H
|
#ifndef I2C_SLAVE_H
|
||||||
#define I2C_SLAVE_H
|
#define I2C_SLAVE_H
|
||||||
|
|
||||||
|
#define TX_BUFFER_SIZE 30
|
||||||
|
#define RX_BUFFER_SIZE 30
|
||||||
|
|
||||||
volatile uint8_t buffer_address;
|
volatile uint8_t buffer_address;
|
||||||
volatile uint8_t txbuffer[0xFF];
|
static volatile bool slave_has_register_set = false;
|
||||||
volatile uint8_t rxbuffer[0xFF];
|
volatile uint8_t txbuffer[TX_BUFFER_SIZE];
|
||||||
|
volatile uint8_t rxbuffer[RX_BUFFER_SIZE];
|
||||||
|
|
||||||
void i2c_init(uint8_t address);
|
void i2c_init(uint8_t address);
|
||||||
void i2c_stop(void);
|
void i2c_stop(void);
|
||||||
ISR(TWI_vect);
|
ISR(TWI_vect);
|
||||||
|
|
||||||
#endif // I2C_SLAVE_H
|
#endif // I2C_SLAVE_H
|
43
keyboards/dc01/arrow/arrow.c
Normal file
43
keyboards/dc01/arrow/arrow.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "arrow.h"
|
||||||
|
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
// put your keyboard start-up code here
|
||||||
|
// runs once when the firmware starts up
|
||||||
|
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
// put your looping keyboard code here
|
||||||
|
// runs every cycle (a lot)
|
||||||
|
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
// put your per-action keyboard code here
|
||||||
|
// runs for every action, just before processing by the firmware
|
||||||
|
|
||||||
|
return process_record_user(keycode, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_set_kb(uint8_t usb_led) {
|
||||||
|
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||||
|
|
||||||
|
led_set_user(usb_led);
|
||||||
|
}
|
41
keyboards/dc01/arrow/arrow.h
Normal file
41
keyboards/dc01/arrow/arrow.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* 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 ARROW_H
|
||||||
|
#define ARROW_H
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
|
|
||||||
|
#define XXX KC_NO
|
||||||
|
|
||||||
|
// This a shortcut to help you visually see your layout.
|
||||||
|
// The first section contains all of the arguments
|
||||||
|
// The second converts the arguments into a two-dimensional array
|
||||||
|
#define LAYOUT_ALL( \
|
||||||
|
K00, K01, K02, \
|
||||||
|
K10, K11, K12, \
|
||||||
|
\
|
||||||
|
K31, \
|
||||||
|
K40, K41, K42 \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ K00, K01, K02 }, \
|
||||||
|
{ K10, K11, K12 }, \
|
||||||
|
{ XXX, XXX, XXX }, \
|
||||||
|
{ XXX, K31, XXX }, \
|
||||||
|
{ K40, K41, K42 } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
151
keyboards/dc01/arrow/config.h
Normal file
151
keyboards/dc01/arrow/config.h
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 Yiancar
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "config_common.h"
|
||||||
|
|
||||||
|
/* USB Device descriptor parameter */
|
||||||
|
#define VENDOR_ID 0xFEED
|
||||||
|
#define PRODUCT_ID 0x1012
|
||||||
|
#define DEVICE_VER 0x0001
|
||||||
|
#define MANUFACTURER Mechboards
|
||||||
|
#define PRODUCT DC01 Arrow
|
||||||
|
#define DESCRIPTION Arrow cluster of DC01 keyboard
|
||||||
|
|
||||||
|
/* key matrix size */
|
||||||
|
#define MATRIX_ROWS 5
|
||||||
|
#define MATRIX_COLS 3
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keyboard Matrix Assignments
|
||||||
|
*
|
||||||
|
* Change this to how you wired your keyboard
|
||||||
|
* COLS: AVR pins used for columns, left to right
|
||||||
|
* ROWS: AVR pins used for rows, top to bottom
|
||||||
|
* DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
|
||||||
|
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define MATRIX_ROW_PINS { B0, C7, C6, B6, B4 }
|
||||||
|
#define MATRIX_COL_PINS { F0, B7, D2 }
|
||||||
|
#define UNUSED_PINS
|
||||||
|
|
||||||
|
/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
|
||||||
|
#define DIODE_DIRECTION COL2ROW
|
||||||
|
|
||||||
|
// #define BACKLIGHT_PIN B7
|
||||||
|
// #define BACKLIGHT_BREATHING
|
||||||
|
// #define BACKLIGHT_LEVELS 3
|
||||||
|
|
||||||
|
|
||||||
|
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
|
||||||
|
#define DEBOUNCING_DELAY 5
|
||||||
|
|
||||||
|
/* define if matrix has ghost (lacks anti-ghosting diodes) */
|
||||||
|
//#define MATRIX_HAS_GHOST
|
||||||
|
|
||||||
|
/* number of backlight levels */
|
||||||
|
|
||||||
|
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||||
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
|
/* Locking resynchronize hack */
|
||||||
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
|
||||||
|
* This is userful for the Windows task manager shortcut (ctrl+shift+esc).
|
||||||
|
*/
|
||||||
|
// #define GRAVE_ESC_CTRL_OVERRIDE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force NKRO
|
||||||
|
*
|
||||||
|
* Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
|
||||||
|
* state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
|
||||||
|
* makefile for this to work.)
|
||||||
|
*
|
||||||
|
* If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
|
||||||
|
* until the next keyboard reset.
|
||||||
|
*
|
||||||
|
* NKRO may prevent your keystrokes from being detected in the BIOS, but it is
|
||||||
|
* fully operational during normal computer usage.
|
||||||
|
*
|
||||||
|
* For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
|
||||||
|
* or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
|
||||||
|
* bootmagic, NKRO mode will always be enabled until it is toggled again during a
|
||||||
|
* power-up.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//#define FORCE_NKRO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Magic Key Options
|
||||||
|
*
|
||||||
|
* Magic keys are hotkey commands that allow control over firmware functions of
|
||||||
|
* the keyboard. They are best used in combination with the HID Listen program,
|
||||||
|
* found here: https://www.pjrc.com/teensy/hid_listen.html
|
||||||
|
*
|
||||||
|
* The options below allow the magic key functionality to be changed. This is
|
||||||
|
* useful if your keyboard/keypad is missing keys and you want magic key support.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* key combination for magic key command */
|
||||||
|
#define IS_COMMAND() ( \
|
||||||
|
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MIDI options
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Prevent use of disabled MIDI features in the keymap */
|
||||||
|
//#define MIDI_ENABLE_STRICT 1
|
||||||
|
|
||||||
|
/* enable basic MIDI features:
|
||||||
|
- MIDI notes can be sent when in Music mode is on
|
||||||
|
*/
|
||||||
|
//#define MIDI_BASIC
|
||||||
|
|
||||||
|
/* enable advanced MIDI features:
|
||||||
|
- MIDI notes can be added to the keymap
|
||||||
|
- Octave shift and transpose
|
||||||
|
- Virtual sustain, portamento, and modulation wheel
|
||||||
|
- etc.
|
||||||
|
*/
|
||||||
|
//#define MIDI_ADVANCED
|
||||||
|
|
||||||
|
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||||
|
//#define MIDI_TONE_KEYCODE_OCTAVES 1
|
0
keyboards/dc01/arrow/info.json
Normal file
0
keyboards/dc01/arrow/info.json
Normal file
42
keyboards/dc01/arrow/keymaps/default/keymap.c
Normal file
42
keyboards/dc01/arrow/keymaps/default/keymap.c
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/* Copyright 2018 REPLACE_WITH_YOUR_NAME
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_ALL( /* Base */
|
||||||
|
KC_INS, KC_HOME, KC_PGUP, \
|
||||||
|
KC_DEL, KC_END, KC_PGDN, \
|
||||||
|
\
|
||||||
|
KC_UP, \
|
||||||
|
KC_LEFT, KC_DOWN, KC_RIGHT \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
}
|
3
keyboards/dc01/arrow/keymaps/default/readme.md
Normal file
3
keyboards/dc01/arrow/keymaps/default/readme.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# The default ANSI keymap for DC01 Arrow cluster
|
||||||
|
|
||||||
|
When using the arrow module individually, this keymap will take effect. When using the keyboard as a whole please edit the keymap of the left module.
|
404
keyboards/dc01/arrow/matrix.c
Normal file
404
keyboards/dc01/arrow/matrix.c
Normal file
|
@ -0,0 +1,404 @@
|
||||||
|
/*
|
||||||
|
Copyright 2012 Jun Wako
|
||||||
|
Copyright 2014 Jack Humbert
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#if defined(__AVR__)
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#endif
|
||||||
|
#include "wait.h"
|
||||||
|
#include "print.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "timer.h"
|
||||||
|
#include "i2c_slave.h"
|
||||||
|
#include "lufa.h"
|
||||||
|
|
||||||
|
#define SLAVE_I2C_ADDRESS 0x23
|
||||||
|
|
||||||
|
/* Set 0 if debouncing isn't needed */
|
||||||
|
|
||||||
|
#ifndef DEBOUNCING_DELAY
|
||||||
|
# define DEBOUNCING_DELAY 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
static uint16_t debouncing_time;
|
||||||
|
static bool debouncing = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (MATRIX_COLS <= 8)
|
||||||
|
# define print_matrix_header() print("\nr/c 01234567\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint8_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 16)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop16(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint16_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 32)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop32(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint32_t)1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
extern const matrix_row_t matrix_mask[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
|
||||||
|
static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* matrix state(1:on, 0:off) */
|
||||||
|
static matrix_row_t matrix[MATRIX_ROWS];
|
||||||
|
|
||||||
|
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static void init_cols(void);
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
|
||||||
|
static void unselect_rows(void);
|
||||||
|
static void select_row(uint8_t row);
|
||||||
|
static void unselect_row(uint8_t row);
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
static void init_rows(void);
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
|
||||||
|
static void unselect_cols(void);
|
||||||
|
static void unselect_col(uint8_t col);
|
||||||
|
static void select_col(uint8_t col);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_quantum(void) {
|
||||||
|
matrix_init_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_quantum(void) {
|
||||||
|
matrix_scan_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_rows(void) {
|
||||||
|
return MATRIX_ROWS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_cols(void) {
|
||||||
|
return MATRIX_COLS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_init(void) {
|
||||||
|
|
||||||
|
// initialize row and col
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
unselect_rows();
|
||||||
|
init_cols();
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
unselect_cols();
|
||||||
|
init_rows();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// initialize matrix state: all keys off
|
||||||
|
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = 0;
|
||||||
|
matrix_debouncing[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_init_quantum();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_scan(void)
|
||||||
|
{
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
// Set row, read cols
|
||||||
|
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
|
||||||
|
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
|
||||||
|
# else
|
||||||
|
read_cols_on_row(matrix, current_row);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
// Set col, read rows
|
||||||
|
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
read_rows_on_col(matrix, current_col);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = matrix_debouncing[i];
|
||||||
|
}
|
||||||
|
debouncing = false;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured){
|
||||||
|
txbuffer[1] = 0x55;
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++){
|
||||||
|
txbuffer[i+2] = matrix[i]; //send matrix over i2c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_scan_quantum();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool matrix_is_modified(void)
|
||||||
|
{
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing) return false;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||||
|
{
|
||||||
|
return (matrix[row] & ((matrix_row_t)1<col));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
matrix_row_t matrix_get_row(uint8_t row)
|
||||||
|
{
|
||||||
|
// Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
|
||||||
|
// switch blocker installed and the switch is always pressed.
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
return matrix[row] & matrix_mask[row];
|
||||||
|
#else
|
||||||
|
return matrix[row];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_print(void)
|
||||||
|
{
|
||||||
|
print_matrix_header();
|
||||||
|
|
||||||
|
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||||
|
phex(row); print(": ");
|
||||||
|
print_matrix_row(row);
|
||||||
|
print("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_key_count(void)
|
||||||
|
{
|
||||||
|
uint8_t count = 0;
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
count += matrix_bitpop(i);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
static void init_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||||
|
{
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[current_row];
|
||||||
|
|
||||||
|
// Clear data in matrix row
|
||||||
|
current_matrix[current_row] = 0;
|
||||||
|
|
||||||
|
// Select row and wait for row selecton to stabilize
|
||||||
|
select_row(current_row);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each col...
|
||||||
|
for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
|
||||||
|
|
||||||
|
// Select the col pin to read (active low)
|
||||||
|
uint8_t pin = col_pins[col_index];
|
||||||
|
uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
|
||||||
|
|
||||||
|
// Populate the matrix row with the state of the col pin
|
||||||
|
current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect row
|
||||||
|
unselect_row(current_row);
|
||||||
|
|
||||||
|
return (last_row_value != current_matrix[current_row]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
static void init_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
||||||
|
{
|
||||||
|
bool matrix_changed = false;
|
||||||
|
|
||||||
|
// Select col and wait for col selecton to stabilize
|
||||||
|
select_col(current_col);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each row...
|
||||||
|
for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[row_index];
|
||||||
|
|
||||||
|
// Check row pin state
|
||||||
|
if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
|
||||||
|
{
|
||||||
|
// Pin LO, set col bit
|
||||||
|
current_matrix[row_index] |= (ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Pin HI, clear col bit
|
||||||
|
current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if the matrix changed state
|
||||||
|
if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
|
||||||
|
{
|
||||||
|
matrix_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect col
|
||||||
|
unselect_col(current_col);
|
||||||
|
|
||||||
|
return matrix_changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//this replases tmk code
|
||||||
|
void matrix_setup(void){
|
||||||
|
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured){
|
||||||
|
i2c_init(SLAVE_I2C_ADDRESS); //setup address of slave i2c
|
||||||
|
sei(); //enable interupts
|
||||||
|
}
|
||||||
|
}
|
15
keyboards/dc01/arrow/readme.md
Normal file
15
keyboards/dc01/arrow/readme.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# DC01 Arrow Cluster
|
||||||
|
|
||||||
|
![DC01 Arrow Cluster](https://i.imgur.com/PTn0sp8.jpg)
|
||||||
|
|
||||||
|
A hotpluggable four part keyboard which comes together with magnets and pogo pins! This is the arrow cluster
|
||||||
|
|
||||||
|
Keyboard Maintainer: [Yiancar](https://github.com/yiancar)
|
||||||
|
Hardware Supported: Runs on an atmega32u4
|
||||||
|
Hardware Availability: [Mechboards](https://mechboards.co.uk/)
|
||||||
|
|
||||||
|
Make example for this keyboard (after setting up your build environment):
|
||||||
|
|
||||||
|
make dc01/arrow: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.
|
74
keyboards/dc01/arrow/rules.mk
Normal file
74
keyboards/dc01/arrow/rules.mk
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
SRC += matrix.c \
|
||||||
|
../../../drivers/avr/i2c_slave.c
|
||||||
|
|
||||||
|
# MCU name
|
||||||
|
#MCU = at90usb1286
|
||||||
|
MCU = atmega32u4
|
||||||
|
|
||||||
|
# Processor frequency.
|
||||||
|
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||||
|
# processor frequency in Hz. You can then use this symbol in your source code to
|
||||||
|
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||||
|
# automatically to create a 32-bit value in your source code.
|
||||||
|
#
|
||||||
|
# This will be an integer division of F_USB below, as it is sourced by
|
||||||
|
# F_USB after it has run through any CPU prescalers. Note that this value
|
||||||
|
# does not *change* the processor frequency - it should merely be updated to
|
||||||
|
# reflect the processor speed set externally so that the code can use accurate
|
||||||
|
# software delays.
|
||||||
|
F_CPU = 16000000
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# LUFA specific
|
||||||
|
#
|
||||||
|
# Target architecture (see library "Board Types" documentation).
|
||||||
|
ARCH = AVR8
|
||||||
|
|
||||||
|
# Input clock frequency.
|
||||||
|
# This will define a symbol, F_USB, in all source code files equal to the
|
||||||
|
# input clock frequency (before any prescaling is performed) in Hz. This value may
|
||||||
|
# differ from F_CPU if prescaling is used on the latter, and is required as the
|
||||||
|
# raw input clock is fed directly to the PLL sections of the AVR for high speed
|
||||||
|
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
|
||||||
|
# at the end, this will be done automatically to create a 32-bit value in your
|
||||||
|
# source code.
|
||||||
|
#
|
||||||
|
# If no clock division is performed on the input clock inside the AVR (via the
|
||||||
|
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
|
||||||
|
F_USB = $(F_CPU)
|
||||||
|
|
||||||
|
# Interrupt driven control endpoint task(+60)
|
||||||
|
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
|
||||||
|
|
||||||
|
|
||||||
|
# Boot Section Size in *bytes*
|
||||||
|
# Teensy halfKay 512
|
||||||
|
# Teensy++ halfKay 1024
|
||||||
|
# Atmel DFU loader 4096
|
||||||
|
# LUFA bootloader 4096
|
||||||
|
# USBaspLoader 2048
|
||||||
|
OPT_DEFS += -DBOOTLOADER_SIZE=4096
|
||||||
|
|
||||||
|
|
||||||
|
# Build Options
|
||||||
|
# change yes to no to disable
|
||||||
|
#
|
||||||
|
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
|
||||||
|
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
|
||||||
|
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
|
||||||
|
CONSOLE_ENABLE = no # Console for debug(+400)
|
||||||
|
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||||
|
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
|
||||||
|
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
|
||||||
|
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||||
|
NKRO_ENABLE = yes # USB Nkey Rollover
|
||||||
|
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
|
||||||
|
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
|
||||||
|
UNICODE_ENABLE = no # Unicode
|
||||||
|
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||||
|
AUDIO_ENABLE = no # Audio output on port C6
|
||||||
|
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
|
||||||
|
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
|
||||||
|
NO_USB_STARTUP_CHECK = yes # Disable initialization only when usb is plugged in
|
||||||
|
CUSTOM_MATRIX = yes # Use custom matrix
|
152
keyboards/dc01/left/config.h
Normal file
152
keyboards/dc01/left/config.h
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 Yiancar
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "config_common.h"
|
||||||
|
|
||||||
|
/* USB Device descriptor parameter */
|
||||||
|
#define VENDOR_ID 0xFEED
|
||||||
|
#define PRODUCT_ID 0x1010
|
||||||
|
#define DEVICE_VER 0x0001
|
||||||
|
#define MANUFACTURER Mechboards
|
||||||
|
#define PRODUCT DC01 Left
|
||||||
|
#define DESCRIPTION Left half of DC01 keyboard
|
||||||
|
|
||||||
|
/* key matrix size */
|
||||||
|
#define MATRIX_ROWS 5
|
||||||
|
#define MATRIX_COLS 21
|
||||||
|
#define MATRIX_COLS_SCANNED 6
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keyboard Matrix Assignments
|
||||||
|
*
|
||||||
|
* Change this to how you wired your keyboard
|
||||||
|
* COLS: AVR pins used for columns, left to right
|
||||||
|
* ROWS: AVR pins used for rows, top to bottom
|
||||||
|
* DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
|
||||||
|
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define MATRIX_ROW_PINS { B6, B5, B4, D7, D6 }
|
||||||
|
#define MATRIX_COL_PINS { F4, F1, F0, F7, F6, F5 }
|
||||||
|
#define UNUSED_PINS
|
||||||
|
|
||||||
|
/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
|
||||||
|
#define DIODE_DIRECTION COL2ROW
|
||||||
|
|
||||||
|
// #define BACKLIGHT_PIN B7
|
||||||
|
// #define BACKLIGHT_BREATHING
|
||||||
|
// #define BACKLIGHT_LEVELS 3
|
||||||
|
|
||||||
|
|
||||||
|
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
|
||||||
|
#define DEBOUNCING_DELAY 5
|
||||||
|
|
||||||
|
/* define if matrix has ghost (lacks anti-ghosting diodes) */
|
||||||
|
//#define MATRIX_HAS_GHOST
|
||||||
|
|
||||||
|
/* number of backlight levels */
|
||||||
|
|
||||||
|
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||||
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
|
/* Locking resynchronize hack */
|
||||||
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
|
||||||
|
* This is userful for the Windows task manager shortcut (ctrl+shift+esc).
|
||||||
|
*/
|
||||||
|
// #define GRAVE_ESC_CTRL_OVERRIDE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force NKRO
|
||||||
|
*
|
||||||
|
* Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
|
||||||
|
* state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
|
||||||
|
* makefile for this to work.)
|
||||||
|
*
|
||||||
|
* If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
|
||||||
|
* until the next keyboard reset.
|
||||||
|
*
|
||||||
|
* NKRO may prevent your keystrokes from being detected in the BIOS, but it is
|
||||||
|
* fully operational during normal computer usage.
|
||||||
|
*
|
||||||
|
* For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
|
||||||
|
* or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
|
||||||
|
* bootmagic, NKRO mode will always be enabled until it is toggled again during a
|
||||||
|
* power-up.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//#define FORCE_NKRO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Magic Key Options
|
||||||
|
*
|
||||||
|
* Magic keys are hotkey commands that allow control over firmware functions of
|
||||||
|
* the keyboard. They are best used in combination with the HID Listen program,
|
||||||
|
* found here: https://www.pjrc.com/teensy/hid_listen.html
|
||||||
|
*
|
||||||
|
* The options below allow the magic key functionality to be changed. This is
|
||||||
|
* useful if your keyboard/keypad is missing keys and you want magic key support.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* key combination for magic key command */
|
||||||
|
#define IS_COMMAND() ( \
|
||||||
|
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MIDI options
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Prevent use of disabled MIDI features in the keymap */
|
||||||
|
//#define MIDI_ENABLE_STRICT 1
|
||||||
|
|
||||||
|
/* enable basic MIDI features:
|
||||||
|
- MIDI notes can be sent when in Music mode is on
|
||||||
|
*/
|
||||||
|
//#define MIDI_BASIC
|
||||||
|
|
||||||
|
/* enable advanced MIDI features:
|
||||||
|
- MIDI notes can be added to the keymap
|
||||||
|
- Octave shift and transpose
|
||||||
|
- Virtual sustain, portamento, and modulation wheel
|
||||||
|
- etc.
|
||||||
|
*/
|
||||||
|
//#define MIDI_ADVANCED
|
||||||
|
|
||||||
|
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||||
|
//#define MIDI_TONE_KEYCODE_OCTAVES 1
|
159
keyboards/dc01/left/i2c.c
Normal file
159
keyboards/dc01/left/i2c.c
Normal file
|
@ -0,0 +1,159 @@
|
||||||
|
#include <util/twi.h>
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/twi.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include "i2c.h"
|
||||||
|
|
||||||
|
// Limits the amount of we wait for any one i2c transaction.
|
||||||
|
// Since were running SCL line 100kHz (=> 10μs/bit), and each transactions is
|
||||||
|
// 9 bits, a single transaction will take around 90μs to complete.
|
||||||
|
//
|
||||||
|
// (F_CPU/SCL_CLOCK) => # of μC cycles to transfer a bit
|
||||||
|
// poll loop takes at least 8 clock cycles to execute
|
||||||
|
#define I2C_LOOP_TIMEOUT (9+1)*(F_CPU/SCL_CLOCK)/8
|
||||||
|
|
||||||
|
#define BUFFER_POS_INC() (slave_buffer_pos = (slave_buffer_pos+1)%SLAVE_BUFFER_SIZE)
|
||||||
|
|
||||||
|
volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
|
||||||
|
|
||||||
|
static volatile uint8_t slave_buffer_pos;
|
||||||
|
static volatile bool slave_has_register_set = false;
|
||||||
|
|
||||||
|
// Wait for an i2c operation to finish
|
||||||
|
inline static
|
||||||
|
void i2c_delay(void) {
|
||||||
|
uint16_t lim = 0;
|
||||||
|
while(!(TWCR & (1<<TWINT)) && lim < I2C_LOOP_TIMEOUT)
|
||||||
|
lim++;
|
||||||
|
|
||||||
|
// easier way, but will wait slightly longer
|
||||||
|
// _delay_us(100);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Setup twi to run at 100kHz
|
||||||
|
void i2c_master_init(void) {
|
||||||
|
// no prescaler
|
||||||
|
TWSR = 0;
|
||||||
|
// Set TWI clock frequency to SCL_CLOCK. Need TWBR>10.
|
||||||
|
// Check datasheets for more info.
|
||||||
|
TWBR = ((F_CPU/SCL_CLOCK)-16)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start a transaction with the given i2c slave address. The direction of the
|
||||||
|
// transfer is set with I2C_READ and I2C_WRITE.
|
||||||
|
// returns: 0 => success
|
||||||
|
// 1 => error
|
||||||
|
uint8_t i2c_master_start(uint8_t address) {
|
||||||
|
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTA);
|
||||||
|
|
||||||
|
i2c_delay();
|
||||||
|
|
||||||
|
// check that we started successfully
|
||||||
|
if ( (TW_STATUS != TW_START) && (TW_STATUS != TW_REP_START))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
TWDR = address;
|
||||||
|
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||||
|
|
||||||
|
i2c_delay();
|
||||||
|
|
||||||
|
if ( (TW_STATUS != TW_MT_SLA_ACK) && (TW_STATUS != TW_MR_SLA_ACK) )
|
||||||
|
return 1; // slave did not acknowledge
|
||||||
|
else
|
||||||
|
return 0; // success
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Finish the i2c transaction.
|
||||||
|
void i2c_master_stop(void) {
|
||||||
|
TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO);
|
||||||
|
|
||||||
|
uint16_t lim = 0;
|
||||||
|
while(!(TWCR & (1<<TWSTO)) && lim < I2C_LOOP_TIMEOUT)
|
||||||
|
lim++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write one byte to the i2c slave.
|
||||||
|
// returns 0 => slave ACK
|
||||||
|
// 1 => slave NACK
|
||||||
|
uint8_t i2c_master_write(uint8_t data) {
|
||||||
|
TWDR = data;
|
||||||
|
TWCR = (1<<TWINT) | (1<<TWEN);
|
||||||
|
|
||||||
|
i2c_delay();
|
||||||
|
|
||||||
|
// check if the slave acknowledged us
|
||||||
|
return (TW_STATUS == TW_MT_DATA_ACK) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read one byte from the i2c slave. If ack=1 the slave is acknowledged,
|
||||||
|
// if ack=0 the acknowledge bit is not set.
|
||||||
|
// returns: byte read from i2c device
|
||||||
|
uint8_t i2c_master_read(int ack) {
|
||||||
|
TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA);
|
||||||
|
|
||||||
|
i2c_delay();
|
||||||
|
return TWDR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_reset_state(void) {
|
||||||
|
TWCR = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void i2c_slave_init(uint8_t address) {
|
||||||
|
TWAR = address << 0; // slave i2c address
|
||||||
|
// TWEN - twi enable
|
||||||
|
// TWEA - enable address acknowledgement
|
||||||
|
// TWINT - twi interrupt flag
|
||||||
|
// TWIE - enable the twi interrupt
|
||||||
|
TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
ISR(TWI_vect);
|
||||||
|
|
||||||
|
ISR(TWI_vect) {
|
||||||
|
uint8_t ack = 1;
|
||||||
|
switch(TW_STATUS) {
|
||||||
|
case TW_SR_SLA_ACK:
|
||||||
|
// this device has been addressed as a slave receiver
|
||||||
|
slave_has_register_set = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TW_SR_DATA_ACK:
|
||||||
|
// this device has received data as a slave receiver
|
||||||
|
// The first byte that we receive in this transaction sets the location
|
||||||
|
// of the read/write location of the slaves memory that it exposes over
|
||||||
|
// i2c. After that, bytes will be written at slave_buffer_pos, incrementing
|
||||||
|
// slave_buffer_pos after each write.
|
||||||
|
if(!slave_has_register_set) {
|
||||||
|
slave_buffer_pos = TWDR;
|
||||||
|
// don't acknowledge the master if this memory loctaion is out of bounds
|
||||||
|
if ( slave_buffer_pos >= SLAVE_BUFFER_SIZE ) {
|
||||||
|
ack = 0;
|
||||||
|
slave_buffer_pos = 0;
|
||||||
|
}
|
||||||
|
slave_has_register_set = true;
|
||||||
|
} else {
|
||||||
|
i2c_slave_buffer[slave_buffer_pos] = TWDR;
|
||||||
|
BUFFER_POS_INC();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TW_ST_SLA_ACK:
|
||||||
|
case TW_ST_DATA_ACK:
|
||||||
|
// master has addressed this device as a slave transmitter and is
|
||||||
|
// requesting data.
|
||||||
|
TWDR = i2c_slave_buffer[slave_buffer_pos];
|
||||||
|
BUFFER_POS_INC();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case TW_BUS_ERROR: // something went wrong, reset twi state
|
||||||
|
TWCR = 0;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Reset everything, so we are ready for the next TWI interrupt
|
||||||
|
TWCR |= (1<<TWIE) | (1<<TWINT) | (ack<<TWEA) | (1<<TWEN);
|
||||||
|
}
|
31
keyboards/dc01/left/i2c.h
Normal file
31
keyboards/dc01/left/i2c.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#ifndef I2C_H
|
||||||
|
#define I2C_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifndef F_CPU
|
||||||
|
#define F_CPU 16000000UL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define I2C_READ 1
|
||||||
|
#define I2C_WRITE 0
|
||||||
|
|
||||||
|
#define I2C_ACK 1
|
||||||
|
#define I2C_NACK 0
|
||||||
|
|
||||||
|
#define SLAVE_BUFFER_SIZE 0x10
|
||||||
|
|
||||||
|
// i2c SCL clock frequency
|
||||||
|
#define SCL_CLOCK 400000L
|
||||||
|
|
||||||
|
extern volatile uint8_t i2c_slave_buffer[SLAVE_BUFFER_SIZE];
|
||||||
|
|
||||||
|
void i2c_master_init(void);
|
||||||
|
uint8_t i2c_master_start(uint8_t address);
|
||||||
|
void i2c_master_stop(void);
|
||||||
|
uint8_t i2c_master_write(uint8_t data);
|
||||||
|
uint8_t i2c_master_read(int);
|
||||||
|
void i2c_reset_state(void);
|
||||||
|
void i2c_slave_init(uint8_t address);
|
||||||
|
|
||||||
|
#endif
|
0
keyboards/dc01/left/info.json
Normal file
0
keyboards/dc01/left/info.json
Normal file
38
keyboards/dc01/left/keymaps/default/keymap.c
Normal file
38
keyboards/dc01/left/keymaps/default/keymap.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_ANSI( /* Base */
|
||||||
|
KC_ESC, 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_NLCK, KC_PSLS, KC_PAST, KC_PMNS, \
|
||||||
|
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_END, KC_PGDN, KC_P7, KC_P8, KC_P9, KC_PPLS, \
|
||||||
|
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_P4, KC_P5, KC_P6, KC_NO, \
|
||||||
|
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_P1, KC_P2, KC_P3, \
|
||||||
|
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_SPC, KC_SPC, KC_RALT, KC_RGUI, KC_RGUI, KC_RCTL, KC_LEFT, KC_DOWN, KC_RIGHT, KC_P0, KC_NO, KC_PDOT, KC_PENT \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
return true;
|
||||||
|
}
|
9
keyboards/dc01/left/keymaps/default/readme.md
Normal file
9
keyboards/dc01/left/keymaps/default/readme.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# The default ANSI keymap for DC01 Left
|
||||||
|
|
||||||
|
The keymap looks like a full layout keymap.
|
||||||
|
|
||||||
|
This is because the left part of the keyboard acts as the masterm coordinating all four part.
|
||||||
|
|
||||||
|
When using the keyboard to connect the other three parts, this keymap overwrites the individual keymaps of the single modules.
|
||||||
|
|
||||||
|
When using a module individually, the keymap of that module will take effect.
|
43
keyboards/dc01/left/left.c
Normal file
43
keyboards/dc01/left/left.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "left.h"
|
||||||
|
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
// put your keyboard start-up code here
|
||||||
|
// runs once when the firmware starts up
|
||||||
|
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
// put your looping keyboard code here
|
||||||
|
// runs every cycle (a lot)
|
||||||
|
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
// put your per-action keyboard code here
|
||||||
|
// runs for every action, just before processing by the firmware
|
||||||
|
|
||||||
|
return process_record_user(keycode, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_set_kb(uint8_t usb_led) {
|
||||||
|
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||||
|
|
||||||
|
led_set_user(usb_led);
|
||||||
|
}
|
41
keyboards/dc01/left/left.h
Normal file
41
keyboards/dc01/left/left.h
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* 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 LEFT_H
|
||||||
|
#define LEFT_H
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
|
|
||||||
|
#define XXX KC_NO
|
||||||
|
|
||||||
|
// This a shortcut to help you visually see your layout.
|
||||||
|
// The first section contains all of the arguments
|
||||||
|
// The second converts the arguments into a two-dimensional array
|
||||||
|
#define LAYOUT_ANSI( \
|
||||||
|
K00, K01, K02, K03, K04, K05, K45, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, K0H, K0J, K0K, K0L, \
|
||||||
|
K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, K1J, K1K, K1L, \
|
||||||
|
K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, K2D, K2H, K2J, K2K, K2L, \
|
||||||
|
K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, K3D, K3F, K3H, K3J, K3K, \
|
||||||
|
K40, K41, K42, K43, K46, K47, K48, K49, K4A, K4B, K4E, K4F, K4G, K4H, K4J, K4K, K4L \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ K00, K01, K02, K03, K04, K05, XXX, K07, K08, K09, K0A, K0B, K0C, K0D, K0E, K0F, K0G, K0H, K0J, K0K, K0L }, \
|
||||||
|
{ K10, K11, K12, K13, K14, K15, K16, K17, K18, K19, K1A, K1B, K1C, K1D, K1E, K1F, K1G, K1H, K1J, K1K, K1L }, \
|
||||||
|
{ K20, K21, K22, K23, K24, K25, K26, K27, K28, K29, K2A, K2B, XXX, K2D, XXX, XXX, XXX, K2H, K2J, K2K, K2L }, \
|
||||||
|
{ K30, K31, K32, K33, K34, K35, K36, K37, K38, K39, K3A, XXX, XXX, K3D, XXX, K3F, XXX, K3H, K3J, K3K, XXX }, \
|
||||||
|
{ K40, K41, K42, K43, XXX, K45, K46, K47, K48, K49, K4A, K4B, XXX, XXX, K4E, K4F, K4G, K4H, K4J, K4K, K4L } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
479
keyboards/dc01/left/matrix.c
Normal file
479
keyboards/dc01/left/matrix.c
Normal file
|
@ -0,0 +1,479 @@
|
||||||
|
/*
|
||||||
|
Copyright 2012 Jun Wako
|
||||||
|
Copyright 2014 Jack Humbert
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#if defined(__AVR__)
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#endif
|
||||||
|
#include "wait.h"
|
||||||
|
#include "print.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "timer.h"
|
||||||
|
#include "i2c_master.h"
|
||||||
|
|
||||||
|
#define SLAVE_I2C_ADDRESS_RIGHT 0x19
|
||||||
|
#define SLAVE_I2C_ADDRESS_NUMPAD 0x21
|
||||||
|
#define SLAVE_I2C_ADDRESS_ARROW 0x23
|
||||||
|
|
||||||
|
#define ERROR_DISCONNECT_COUNT 5
|
||||||
|
static uint8_t error_count_right = 0;
|
||||||
|
static uint8_t error_count_numpad = 0;
|
||||||
|
static uint8_t error_count_arrow = 0;
|
||||||
|
|
||||||
|
/* Set 0 if debouncing isn't needed */
|
||||||
|
|
||||||
|
#ifndef DEBOUNCING_DELAY
|
||||||
|
# define DEBOUNCING_DELAY 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
static uint16_t debouncing_time;
|
||||||
|
static bool debouncing = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (MATRIX_COLS <= 8)
|
||||||
|
# define print_matrix_header() print("\nr/c 01234567\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint8_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 16)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop16(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint16_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 32)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop32(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint32_t)1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
extern const matrix_row_t matrix_mask[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
|
||||||
|
static const uint8_t col_pins[MATRIX_COLS_SCANNED] = MATRIX_COL_PINS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* matrix state(1:on, 0:off) */
|
||||||
|
static matrix_row_t matrix[MATRIX_ROWS];
|
||||||
|
|
||||||
|
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static void init_cols(void);
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
|
||||||
|
static void unselect_rows(void);
|
||||||
|
static void select_row(uint8_t row);
|
||||||
|
static void unselect_row(uint8_t row);
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
static void init_rows(void);
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
|
||||||
|
static void unselect_cols(void);
|
||||||
|
static void unselect_col(uint8_t col);
|
||||||
|
static void select_col(uint8_t col);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_quantum(void) {
|
||||||
|
matrix_init_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_quantum(void) {
|
||||||
|
matrix_scan_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_rows(void) {
|
||||||
|
return MATRIX_ROWS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_cols(void) {
|
||||||
|
return MATRIX_COLS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
i2c_status_t i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset);
|
||||||
|
//uint8_t i2c_transaction_numpad(void);
|
||||||
|
//uint8_t i2c_transaction_arrow(void);
|
||||||
|
|
||||||
|
//this replases tmk code
|
||||||
|
void matrix_setup(void){
|
||||||
|
i2c_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_init(void) {
|
||||||
|
|
||||||
|
// initialize row and col
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
unselect_rows();
|
||||||
|
init_cols();
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
unselect_cols();
|
||||||
|
init_rows();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// initialize matrix state: all keys off
|
||||||
|
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = 0;
|
||||||
|
matrix_debouncing[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_init_quantum();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_scan(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
// Set row, read cols
|
||||||
|
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
|
||||||
|
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
|
||||||
|
# else
|
||||||
|
read_cols_on_row(matrix, current_row);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
// Set col, read rows
|
||||||
|
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
read_rows_on_col(matrix, current_col);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = matrix_debouncing[i];
|
||||||
|
}
|
||||||
|
debouncing = false;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (i2c_transaction(SLAVE_I2C_ADDRESS_RIGHT, 0x3F, 0)){ //error has occured for main right half
|
||||||
|
error_count_right++;
|
||||||
|
if (error_count_right > ERROR_DISCONNECT_COUNT){ //disconnect half
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS ; i++) {
|
||||||
|
matrix[i] &= 0x3F; //mask bits to keep
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ //no error
|
||||||
|
error_count_right = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i2c_transaction(SLAVE_I2C_ADDRESS_ARROW, 0X3FFF, 8)){ //error has occured for arrow cluster
|
||||||
|
error_count_arrow++;
|
||||||
|
if (error_count_arrow > ERROR_DISCONNECT_COUNT){ //disconnect arrow cluster
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS ; i++) {
|
||||||
|
matrix[i] &= 0x3FFF; //mask bits to keep
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ //no error
|
||||||
|
error_count_arrow = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i2c_transaction(SLAVE_I2C_ADDRESS_NUMPAD, 0x1FFFF, 11)){ //error has occured for numpad
|
||||||
|
error_count_numpad++;
|
||||||
|
if (error_count_numpad > ERROR_DISCONNECT_COUNT){ //disconnect numpad
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS ; i++) {
|
||||||
|
matrix[i] &= 0x1FFFF; //mask bits to keep
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{ //no error
|
||||||
|
error_count_numpad = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_scan_quantum();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool matrix_is_modified(void)
|
||||||
|
{
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing) return false;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||||
|
{
|
||||||
|
return (matrix[row] & ((matrix_row_t)1<col));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
matrix_row_t matrix_get_row(uint8_t row)
|
||||||
|
{
|
||||||
|
// Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
|
||||||
|
// switch blocker installed and the switch is always pressed.
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
return matrix[row] & matrix_mask[row];
|
||||||
|
#else
|
||||||
|
return matrix[row];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_print(void)
|
||||||
|
{
|
||||||
|
print_matrix_header();
|
||||||
|
|
||||||
|
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||||
|
phex(row); print(": ");
|
||||||
|
print_matrix_row(row);
|
||||||
|
print("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_key_count(void)
|
||||||
|
{
|
||||||
|
uint8_t count = 0;
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
count += matrix_bitpop(i);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
static void init_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS_SCANNED; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||||
|
{
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[current_row];
|
||||||
|
|
||||||
|
// Clear data in matrix row
|
||||||
|
current_matrix[current_row] = 0;
|
||||||
|
|
||||||
|
// Select row and wait for row selecton to stabilize
|
||||||
|
select_row(current_row);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each col...
|
||||||
|
for(uint8_t col_index = 0; col_index < MATRIX_COLS_SCANNED; col_index++) {
|
||||||
|
|
||||||
|
// Select the col pin to read (active low)
|
||||||
|
uint8_t pin = col_pins[col_index];
|
||||||
|
uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
|
||||||
|
|
||||||
|
// Populate the matrix row with the state of the col pin
|
||||||
|
current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect row
|
||||||
|
unselect_row(current_row);
|
||||||
|
|
||||||
|
return (last_row_value != current_matrix[current_row]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
static void init_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
||||||
|
{
|
||||||
|
bool matrix_changed = false;
|
||||||
|
|
||||||
|
// Select col and wait for col selecton to stabilize
|
||||||
|
select_col(current_col);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each row...
|
||||||
|
for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[row_index];
|
||||||
|
|
||||||
|
// Check row pin state
|
||||||
|
if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
|
||||||
|
{
|
||||||
|
// Pin LO, set col bit
|
||||||
|
current_matrix[row_index] |= (ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Pin HI, clear col bit
|
||||||
|
current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if the matrix changed state
|
||||||
|
if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
|
||||||
|
{
|
||||||
|
matrix_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect col
|
||||||
|
unselect_col(current_col);
|
||||||
|
|
||||||
|
return matrix_changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS_SCANNED; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Complete rows from other modules over i2c
|
||||||
|
i2c_status_t i2c_transaction(uint8_t address, uint32_t mask, uint8_t col_offset) {
|
||||||
|
i2c_status_t err = i2c_start((address << 1) | I2C_WRITE, 10);
|
||||||
|
if (err) return err;
|
||||||
|
i2c_write(0x01, 10);
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
|
i2c_start((address << 1) | I2C_READ, 10);
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
|
err = i2c_read_ack(10);
|
||||||
|
if (err == 0x55) { //synchronization byte
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS-1 ; i++) { //assemble slave matrix in main matrix
|
||||||
|
matrix[i] &= mask; //mask bits to keep
|
||||||
|
err = i2c_read_ack(10);
|
||||||
|
if (err >= 0) {
|
||||||
|
matrix[i] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end
|
||||||
|
} else {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//last read request must be followed by a NACK
|
||||||
|
matrix[MATRIX_ROWS - 1] &= mask; //mask bits to keep
|
||||||
|
err = i2c_read_nack(10);
|
||||||
|
if (err >= 0) {
|
||||||
|
matrix[MATRIX_ROWS - 1] |= ((uint32_t)err << (MATRIX_COLS_SCANNED + col_offset)); //add new bits at the end
|
||||||
|
} else {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
i2c_stop(10);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
i2c_stop(10);
|
||||||
|
if (err) return err;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
15
keyboards/dc01/left/readme.md
Normal file
15
keyboards/dc01/left/readme.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# DC01 Left Half
|
||||||
|
|
||||||
|
![DC01 Left Half](https://i.imgur.com/PTn0sp8.jpg)
|
||||||
|
|
||||||
|
A hotpluggable four part keyboard which comes together with magnets and pogo pins! This is the left part that also acts as the master.
|
||||||
|
|
||||||
|
Keyboard Maintainer: [Yiancar](https://github.com/yiancar)
|
||||||
|
Hardware Supported: Runs on an atmega32u4
|
||||||
|
Hardware Availability: [Mechboards](https://mechboards.co.uk/)
|
||||||
|
|
||||||
|
Make example for this keyboard (after setting up your build environment):
|
||||||
|
|
||||||
|
make dc01/left: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.
|
73
keyboards/dc01/left/rules.mk
Normal file
73
keyboards/dc01/left/rules.mk
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
SRC += matrix.c \
|
||||||
|
../../../drivers/avr/i2c_master.c
|
||||||
|
|
||||||
|
# MCU name
|
||||||
|
#MCU = at90usb1286
|
||||||
|
MCU = atmega32u4
|
||||||
|
|
||||||
|
# Processor frequency.
|
||||||
|
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||||
|
# processor frequency in Hz. You can then use this symbol in your source code to
|
||||||
|
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||||
|
# automatically to create a 32-bit value in your source code.
|
||||||
|
#
|
||||||
|
# This will be an integer division of F_USB below, as it is sourced by
|
||||||
|
# F_USB after it has run through any CPU prescalers. Note that this value
|
||||||
|
# does not *change* the processor frequency - it should merely be updated to
|
||||||
|
# reflect the processor speed set externally so that the code can use accurate
|
||||||
|
# software delays.
|
||||||
|
F_CPU = 16000000
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# LUFA specific
|
||||||
|
#
|
||||||
|
# Target architecture (see library "Board Types" documentation).
|
||||||
|
ARCH = AVR8
|
||||||
|
|
||||||
|
# Input clock frequency.
|
||||||
|
# This will define a symbol, F_USB, in all source code files equal to the
|
||||||
|
# input clock frequency (before any prescaling is performed) in Hz. This value may
|
||||||
|
# differ from F_CPU if prescaling is used on the latter, and is required as the
|
||||||
|
# raw input clock is fed directly to the PLL sections of the AVR for high speed
|
||||||
|
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
|
||||||
|
# at the end, this will be done automatically to create a 32-bit value in your
|
||||||
|
# source code.
|
||||||
|
#
|
||||||
|
# If no clock division is performed on the input clock inside the AVR (via the
|
||||||
|
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
|
||||||
|
F_USB = $(F_CPU)
|
||||||
|
|
||||||
|
# Interrupt driven control endpoint task(+60)
|
||||||
|
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
|
||||||
|
|
||||||
|
|
||||||
|
# Boot Section Size in *bytes*
|
||||||
|
# Teensy halfKay 512
|
||||||
|
# Teensy++ halfKay 1024
|
||||||
|
# Atmel DFU loader 4096
|
||||||
|
# LUFA bootloader 4096
|
||||||
|
# USBaspLoader 2048
|
||||||
|
OPT_DEFS += -DBOOTLOADER_SIZE=4096
|
||||||
|
|
||||||
|
|
||||||
|
# Build Options
|
||||||
|
# change yes to no to disable
|
||||||
|
#
|
||||||
|
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
|
||||||
|
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
|
||||||
|
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
|
||||||
|
CONSOLE_ENABLE = no # Console for debug(+400)
|
||||||
|
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||||
|
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
|
||||||
|
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
|
||||||
|
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||||
|
NKRO_ENABLE = yes # USB Nkey Rollover
|
||||||
|
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
|
||||||
|
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
|
||||||
|
UNICODE_ENABLE = no # Unicode
|
||||||
|
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||||
|
AUDIO_ENABLE = no # Audio output on port C6
|
||||||
|
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
|
||||||
|
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
|
||||||
|
CUSTOM_MATRIX = yes # Use custom matrix
|
151
keyboards/dc01/numpad/config.h
Normal file
151
keyboards/dc01/numpad/config.h
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 Yiancar
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "config_common.h"
|
||||||
|
|
||||||
|
/* USB Device descriptor parameter */
|
||||||
|
#define VENDOR_ID 0xFEED
|
||||||
|
#define PRODUCT_ID 0x1013
|
||||||
|
#define DEVICE_VER 0x0001
|
||||||
|
#define MANUFACTURER Mechboards
|
||||||
|
#define PRODUCT DC01 Numpad
|
||||||
|
#define DESCRIPTION Numpad of DC01 keyboard
|
||||||
|
|
||||||
|
/* key matrix size */
|
||||||
|
#define MATRIX_ROWS 5
|
||||||
|
#define MATRIX_COLS 4
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keyboard Matrix Assignments
|
||||||
|
*
|
||||||
|
* Change this to how you wired your keyboard
|
||||||
|
* COLS: AVR pins used for columns, left to right
|
||||||
|
* ROWS: AVR pins used for rows, top to bottom
|
||||||
|
* DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
|
||||||
|
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define MATRIX_ROW_PINS { B0, E6, D6, D7, B4 }
|
||||||
|
#define MATRIX_COL_PINS { F0, B7, D2, D3 }
|
||||||
|
#define UNUSED_PINS
|
||||||
|
|
||||||
|
/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
|
||||||
|
#define DIODE_DIRECTION COL2ROW
|
||||||
|
|
||||||
|
// #define BACKLIGHT_PIN B7
|
||||||
|
// #define BACKLIGHT_BREATHING
|
||||||
|
// #define BACKLIGHT_LEVELS 3
|
||||||
|
|
||||||
|
|
||||||
|
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
|
||||||
|
#define DEBOUNCING_DELAY 5
|
||||||
|
|
||||||
|
/* define if matrix has ghost (lacks anti-ghosting diodes) */
|
||||||
|
//#define MATRIX_HAS_GHOST
|
||||||
|
|
||||||
|
/* number of backlight levels */
|
||||||
|
|
||||||
|
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||||
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
|
/* Locking resynchronize hack */
|
||||||
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
|
||||||
|
* This is userful for the Windows task manager shortcut (ctrl+shift+esc).
|
||||||
|
*/
|
||||||
|
// #define GRAVE_ESC_CTRL_OVERRIDE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force NKRO
|
||||||
|
*
|
||||||
|
* Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
|
||||||
|
* state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
|
||||||
|
* makefile for this to work.)
|
||||||
|
*
|
||||||
|
* If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
|
||||||
|
* until the next keyboard reset.
|
||||||
|
*
|
||||||
|
* NKRO may prevent your keystrokes from being detected in the BIOS, but it is
|
||||||
|
* fully operational during normal computer usage.
|
||||||
|
*
|
||||||
|
* For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
|
||||||
|
* or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
|
||||||
|
* bootmagic, NKRO mode will always be enabled until it is toggled again during a
|
||||||
|
* power-up.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//#define FORCE_NKRO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Magic Key Options
|
||||||
|
*
|
||||||
|
* Magic keys are hotkey commands that allow control over firmware functions of
|
||||||
|
* the keyboard. They are best used in combination with the HID Listen program,
|
||||||
|
* found here: https://www.pjrc.com/teensy/hid_listen.html
|
||||||
|
*
|
||||||
|
* The options below allow the magic key functionality to be changed. This is
|
||||||
|
* useful if your keyboard/keypad is missing keys and you want magic key support.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* key combination for magic key command */
|
||||||
|
#define IS_COMMAND() ( \
|
||||||
|
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MIDI options
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Prevent use of disabled MIDI features in the keymap */
|
||||||
|
//#define MIDI_ENABLE_STRICT 1
|
||||||
|
|
||||||
|
/* enable basic MIDI features:
|
||||||
|
- MIDI notes can be sent when in Music mode is on
|
||||||
|
*/
|
||||||
|
//#define MIDI_BASIC
|
||||||
|
|
||||||
|
/* enable advanced MIDI features:
|
||||||
|
- MIDI notes can be added to the keymap
|
||||||
|
- Octave shift and transpose
|
||||||
|
- Virtual sustain, portamento, and modulation wheel
|
||||||
|
- etc.
|
||||||
|
*/
|
||||||
|
//#define MIDI_ADVANCED
|
||||||
|
|
||||||
|
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||||
|
//#define MIDI_TONE_KEYCODE_OCTAVES 1
|
0
keyboards/dc01/numpad/info.json
Normal file
0
keyboards/dc01/numpad/info.json
Normal file
53
keyboards/dc01/numpad/keymaps/default/keymap.c
Normal file
53
keyboards/dc01/numpad/keymaps/default/keymap.c
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
#define _______ KC_TRNS
|
||||||
|
#define XXXXXXX KC_NO
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_numpad_5x4(
|
||||||
|
TG(1), KC_PSLS, KC_PAST, KC_PMNS, \
|
||||||
|
KC_P7, KC_P8, KC_P9, \
|
||||||
|
KC_P4, KC_P5, KC_P6, KC_PPLS, \
|
||||||
|
KC_P1, KC_P2, KC_P3, \
|
||||||
|
KC_P0, KC_PDOT, KC_PENT \
|
||||||
|
),
|
||||||
|
|
||||||
|
[1] = LAYOUT_numpad_5x4(
|
||||||
|
_______, _______, _______, _______, \
|
||||||
|
KC_HOME, KC_UP, KC_PGUP, \
|
||||||
|
KC_LEFT, XXXXXXX, KC_RGHT, _______, \
|
||||||
|
KC_END, KC_DOWN, KC_PGDN, \
|
||||||
|
KC_INS, KC_DEL, _______ \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
|
}
|
3
keyboards/dc01/numpad/keymaps/default/readme.md
Normal file
3
keyboards/dc01/numpad/keymaps/default/readme.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# The default keymap for DC01 Numpad
|
||||||
|
|
||||||
|
When using the numpad module individually, this keymap will take effect. When using the keyboard as a whole please edit the keymap of the left module.
|
65
keyboards/dc01/numpad/keymaps/ortho_5x4/keymap.c
Normal file
65
keyboards/dc01/numpad/keymaps/ortho_5x4/keymap.c
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
#define _______ KC_TRNS
|
||||||
|
#define XXXXXXX KC_NO
|
||||||
|
|
||||||
|
enum custom_keycodes {
|
||||||
|
KC_P00 = SAFE_RANGE
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_ortho_5x4(
|
||||||
|
TG(1), KC_PSLS, KC_PAST, KC_PMNS, \
|
||||||
|
KC_P7, KC_P8, KC_P9, KC_PPLS, \
|
||||||
|
KC_P4, KC_P5, KC_P6, KC_PPLS, \
|
||||||
|
KC_P1, KC_P2, KC_P3, KC_PENT, \
|
||||||
|
KC_P0, KC_P00, KC_PDOT, KC_PENT \
|
||||||
|
),
|
||||||
|
|
||||||
|
[1] = LAYOUT_ortho_5x4(
|
||||||
|
_______, _______, _______, _______, \
|
||||||
|
KC_HOME, KC_UP, KC_PGUP, _______, \
|
||||||
|
KC_LEFT, XXXXXXX, KC_RGHT, _______, \
|
||||||
|
KC_END, KC_DOWN, KC_PGDN, _______, \
|
||||||
|
KC_INS, XXXXXXX, KC_DEL, _______ \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
if (record->event.pressed) {
|
||||||
|
switch(keycode) {
|
||||||
|
case KC_P00:
|
||||||
|
// types Numpad 0 twice
|
||||||
|
SEND_STRING(SS_TAP(X_KP_0) SS_TAP(X_KP_0));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
void led_set_user(uint8_t usb_led) {
|
||||||
|
|
||||||
|
}
|
3
keyboards/dc01/numpad/keymaps/ortho_5x4/readme.md
Normal file
3
keyboards/dc01/numpad/keymaps/ortho_5x4/readme.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# The orthopad keymap for DC01 Numpad
|
||||||
|
|
||||||
|
When using the numpad module individually, this keymap will take effect. When using the keyboard as a whole please edit the keymap of the left module.
|
404
keyboards/dc01/numpad/matrix.c
Normal file
404
keyboards/dc01/numpad/matrix.c
Normal file
|
@ -0,0 +1,404 @@
|
||||||
|
/*
|
||||||
|
Copyright 2012 Jun Wako
|
||||||
|
Copyright 2014 Jack Humbert
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#if defined(__AVR__)
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#endif
|
||||||
|
#include "wait.h"
|
||||||
|
#include "print.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "timer.h"
|
||||||
|
#include "i2c_slave.h"
|
||||||
|
#include "lufa.h"
|
||||||
|
|
||||||
|
#define SLAVE_I2C_ADDRESS 0x21
|
||||||
|
|
||||||
|
/* Set 0 if debouncing isn't needed */
|
||||||
|
|
||||||
|
#ifndef DEBOUNCING_DELAY
|
||||||
|
# define DEBOUNCING_DELAY 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
static uint16_t debouncing_time;
|
||||||
|
static bool debouncing = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (MATRIX_COLS <= 8)
|
||||||
|
# define print_matrix_header() print("\nr/c 01234567\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint8_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 16)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop16(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint16_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 32)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop32(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint32_t)1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
extern const matrix_row_t matrix_mask[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
|
||||||
|
static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* matrix state(1:on, 0:off) */
|
||||||
|
static matrix_row_t matrix[MATRIX_ROWS];
|
||||||
|
|
||||||
|
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static void init_cols(void);
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
|
||||||
|
static void unselect_rows(void);
|
||||||
|
static void select_row(uint8_t row);
|
||||||
|
static void unselect_row(uint8_t row);
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
static void init_rows(void);
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
|
||||||
|
static void unselect_cols(void);
|
||||||
|
static void unselect_col(uint8_t col);
|
||||||
|
static void select_col(uint8_t col);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_quantum(void) {
|
||||||
|
matrix_init_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_quantum(void) {
|
||||||
|
matrix_scan_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_rows(void) {
|
||||||
|
return MATRIX_ROWS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_cols(void) {
|
||||||
|
return MATRIX_COLS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_init(void) {
|
||||||
|
|
||||||
|
// initialize row and col
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
unselect_rows();
|
||||||
|
init_cols();
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
unselect_cols();
|
||||||
|
init_rows();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// initialize matrix state: all keys off
|
||||||
|
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = 0;
|
||||||
|
matrix_debouncing[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_init_quantum();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_scan(void)
|
||||||
|
{
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
// Set row, read cols
|
||||||
|
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
|
||||||
|
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
|
||||||
|
# else
|
||||||
|
read_cols_on_row(matrix, current_row);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
// Set col, read rows
|
||||||
|
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
read_rows_on_col(matrix, current_col);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = matrix_debouncing[i];
|
||||||
|
}
|
||||||
|
debouncing = false;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured){
|
||||||
|
txbuffer[1] = 0x55;
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++){
|
||||||
|
txbuffer[i+2] = matrix[i]; //send matrix over i2c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_scan_quantum();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool matrix_is_modified(void)
|
||||||
|
{
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing) return false;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||||
|
{
|
||||||
|
return (matrix[row] & ((matrix_row_t)1<col));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
matrix_row_t matrix_get_row(uint8_t row)
|
||||||
|
{
|
||||||
|
// Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
|
||||||
|
// switch blocker installed and the switch is always pressed.
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
return matrix[row] & matrix_mask[row];
|
||||||
|
#else
|
||||||
|
return matrix[row];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_print(void)
|
||||||
|
{
|
||||||
|
print_matrix_header();
|
||||||
|
|
||||||
|
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||||
|
phex(row); print(": ");
|
||||||
|
print_matrix_row(row);
|
||||||
|
print("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_key_count(void)
|
||||||
|
{
|
||||||
|
uint8_t count = 0;
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
count += matrix_bitpop(i);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
static void init_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||||
|
{
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[current_row];
|
||||||
|
|
||||||
|
// Clear data in matrix row
|
||||||
|
current_matrix[current_row] = 0;
|
||||||
|
|
||||||
|
// Select row and wait for row selecton to stabilize
|
||||||
|
select_row(current_row);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each col...
|
||||||
|
for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
|
||||||
|
|
||||||
|
// Select the col pin to read (active low)
|
||||||
|
uint8_t pin = col_pins[col_index];
|
||||||
|
uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
|
||||||
|
|
||||||
|
// Populate the matrix row with the state of the col pin
|
||||||
|
current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect row
|
||||||
|
unselect_row(current_row);
|
||||||
|
|
||||||
|
return (last_row_value != current_matrix[current_row]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
static void init_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
||||||
|
{
|
||||||
|
bool matrix_changed = false;
|
||||||
|
|
||||||
|
// Select col and wait for col selecton to stabilize
|
||||||
|
select_col(current_col);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each row...
|
||||||
|
for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[row_index];
|
||||||
|
|
||||||
|
// Check row pin state
|
||||||
|
if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
|
||||||
|
{
|
||||||
|
// Pin LO, set col bit
|
||||||
|
current_matrix[row_index] |= (ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Pin HI, clear col bit
|
||||||
|
current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if the matrix changed state
|
||||||
|
if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
|
||||||
|
{
|
||||||
|
matrix_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect col
|
||||||
|
unselect_col(current_col);
|
||||||
|
|
||||||
|
return matrix_changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//this replases tmk code
|
||||||
|
void matrix_setup(void){
|
||||||
|
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured){
|
||||||
|
i2c_init(SLAVE_I2C_ADDRESS); //setup address of slave i2c
|
||||||
|
sei(); //enable interupts
|
||||||
|
}
|
||||||
|
}
|
43
keyboards/dc01/numpad/numpad.c
Normal file
43
keyboards/dc01/numpad/numpad.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* Copyright 2018 REPLACE_WITH_YOUR_NAME
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "numpad.h"
|
||||||
|
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
// put your keyboard start-up code here
|
||||||
|
// runs once when the firmware starts up
|
||||||
|
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
// put your looping keyboard code here
|
||||||
|
// runs every cycle (a lot)
|
||||||
|
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
// put your per-action keyboard code here
|
||||||
|
// runs for every action, just before processing by the firmware
|
||||||
|
|
||||||
|
return process_record_user(keycode, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_set_kb(uint8_t usb_led) {
|
||||||
|
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||||
|
|
||||||
|
led_set_user(usb_led);
|
||||||
|
}
|
56
keyboards/dc01/numpad/numpad.h
Normal file
56
keyboards/dc01/numpad/numpad.h
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* 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 NUMPAD_H
|
||||||
|
#define NUMPAD_H
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
|
|
||||||
|
#define XXX KC_NO
|
||||||
|
|
||||||
|
// This a shortcut to help you visually see your layout.
|
||||||
|
// The first section contains all of the arguments
|
||||||
|
// The second converts the arguments into a two-dimensional array
|
||||||
|
#define LAYOUT_numpad_5x4( \
|
||||||
|
K00, K01, K02, K03, \
|
||||||
|
K10, K11, K12, K13, \
|
||||||
|
K20, K21, K22, \
|
||||||
|
K30, K31, K32, \
|
||||||
|
K40, K42, K43 \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ K00, K01, K02, K03 }, \
|
||||||
|
{ K10, K11, K12, K13 }, \
|
||||||
|
{ K20, K21, K22, XXX }, \
|
||||||
|
{ K30, K31, K32, XXX }, \
|
||||||
|
{ K40, XXX, K42, K43 } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LAYOUT_ortho_5x4( \
|
||||||
|
K00, K01, K02, K03, \
|
||||||
|
K10, K11, K12, K13, \
|
||||||
|
K20, K21, K22, K23, \
|
||||||
|
K30, K31, K32, K33, \
|
||||||
|
K40, K41, K42, K43 \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ K00, K01, K02, K03 }, \
|
||||||
|
{ K10, K11, K12, K13 }, \
|
||||||
|
{ K20, K21, K22, K23 }, \
|
||||||
|
{ K30, K31, K32, K33 }, \
|
||||||
|
{ K40, K41, K42, K43 } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
15
keyboards/dc01/numpad/readme.md
Normal file
15
keyboards/dc01/numpad/readme.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# DC01 Numpad
|
||||||
|
|
||||||
|
![DC01 Numpad](https://i.imgur.com/PTn0sp8.jpg)
|
||||||
|
|
||||||
|
A hotpluggable four part keyboard which comes together with magnets and pogo pins! This is the numpad
|
||||||
|
|
||||||
|
Keyboard Maintainer: [Yiancar](https://github.com/yiancar)
|
||||||
|
Hardware Supported: Runs on an atmega32u4
|
||||||
|
Hardware Availability: [Mechboards](https://mechboards.co.uk/)
|
||||||
|
|
||||||
|
Make example for this keyboard (after setting up your build environment):
|
||||||
|
|
||||||
|
make dc01/numpad: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.
|
74
keyboards/dc01/numpad/rules.mk
Normal file
74
keyboards/dc01/numpad/rules.mk
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
SRC += matrix.c \
|
||||||
|
../../../drivers/avr/i2c_slave.c
|
||||||
|
|
||||||
|
# MCU name
|
||||||
|
#MCU = at90usb1286
|
||||||
|
MCU = atmega32u4
|
||||||
|
|
||||||
|
# Processor frequency.
|
||||||
|
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||||
|
# processor frequency in Hz. You can then use this symbol in your source code to
|
||||||
|
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||||
|
# automatically to create a 32-bit value in your source code.
|
||||||
|
#
|
||||||
|
# This will be an integer division of F_USB below, as it is sourced by
|
||||||
|
# F_USB after it has run through any CPU prescalers. Note that this value
|
||||||
|
# does not *change* the processor frequency - it should merely be updated to
|
||||||
|
# reflect the processor speed set externally so that the code can use accurate
|
||||||
|
# software delays.
|
||||||
|
F_CPU = 16000000
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# LUFA specific
|
||||||
|
#
|
||||||
|
# Target architecture (see library "Board Types" documentation).
|
||||||
|
ARCH = AVR8
|
||||||
|
|
||||||
|
# Input clock frequency.
|
||||||
|
# This will define a symbol, F_USB, in all source code files equal to the
|
||||||
|
# input clock frequency (before any prescaling is performed) in Hz. This value may
|
||||||
|
# differ from F_CPU if prescaling is used on the latter, and is required as the
|
||||||
|
# raw input clock is fed directly to the PLL sections of the AVR for high speed
|
||||||
|
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
|
||||||
|
# at the end, this will be done automatically to create a 32-bit value in your
|
||||||
|
# source code.
|
||||||
|
#
|
||||||
|
# If no clock division is performed on the input clock inside the AVR (via the
|
||||||
|
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
|
||||||
|
F_USB = $(F_CPU)
|
||||||
|
|
||||||
|
# Interrupt driven control endpoint task(+60)
|
||||||
|
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
|
||||||
|
|
||||||
|
|
||||||
|
# Boot Section Size in *bytes*
|
||||||
|
# Teensy halfKay 512
|
||||||
|
# Teensy++ halfKay 1024
|
||||||
|
# Atmel DFU loader 4096
|
||||||
|
# LUFA bootloader 4096
|
||||||
|
# USBaspLoader 2048
|
||||||
|
OPT_DEFS += -DBOOTLOADER_SIZE=4096
|
||||||
|
|
||||||
|
|
||||||
|
# Build Options
|
||||||
|
# change yes to no to disable
|
||||||
|
#
|
||||||
|
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
|
||||||
|
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
|
||||||
|
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
|
||||||
|
CONSOLE_ENABLE = no # Console for debug(+400)
|
||||||
|
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||||
|
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
|
||||||
|
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
|
||||||
|
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||||
|
NKRO_ENABLE = yes # USB Nkey Rollover
|
||||||
|
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
|
||||||
|
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
|
||||||
|
UNICODE_ENABLE = no # Unicode
|
||||||
|
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||||
|
AUDIO_ENABLE = no # Audio output on port C6
|
||||||
|
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
|
||||||
|
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
|
||||||
|
NO_USB_STARTUP_CHECK = yes # Disable initialization only when usb is plugged in
|
||||||
|
CUSTOM_MATRIX = yes # Use custom matrix
|
151
keyboards/dc01/right/config.h
Normal file
151
keyboards/dc01/right/config.h
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
/*
|
||||||
|
Copyright 2018 Yiancar
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "config_common.h"
|
||||||
|
|
||||||
|
/* USB Device descriptor parameter */
|
||||||
|
#define VENDOR_ID 0xFEED
|
||||||
|
#define PRODUCT_ID 0x1011
|
||||||
|
#define DEVICE_VER 0x0001
|
||||||
|
#define MANUFACTURER Mechboards
|
||||||
|
#define PRODUCT DC01 Right
|
||||||
|
#define DESCRIPTION Right half of DC01 keyboard
|
||||||
|
|
||||||
|
/* key matrix size */
|
||||||
|
#define MATRIX_ROWS 5
|
||||||
|
#define MATRIX_COLS 8
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Keyboard Matrix Assignments
|
||||||
|
*
|
||||||
|
* Change this to how you wired your keyboard
|
||||||
|
* COLS: AVR pins used for columns, left to right
|
||||||
|
* ROWS: AVR pins used for rows, top to bottom
|
||||||
|
* DIODE_DIRECTION: COL2ROW = COL = Anode (+), ROW = Cathode (-, marked on diode)
|
||||||
|
* ROW2COL = ROW = Anode (+), COL = Cathode (-, marked on diode)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#define MATRIX_ROW_PINS { C7, C6, B6, B5, B4 }
|
||||||
|
#define MATRIX_COL_PINS { F1, E6, F6, F5, F4, D4, D6, D7 }
|
||||||
|
#define UNUSED_PINS
|
||||||
|
|
||||||
|
/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */
|
||||||
|
#define DIODE_DIRECTION COL2ROW
|
||||||
|
|
||||||
|
// #define BACKLIGHT_PIN B7
|
||||||
|
// #define BACKLIGHT_BREATHING
|
||||||
|
// #define BACKLIGHT_LEVELS 3
|
||||||
|
|
||||||
|
|
||||||
|
/* Debounce reduces chatter (unintended double-presses) - set 0 if debouncing is not needed */
|
||||||
|
#define DEBOUNCING_DELAY 5
|
||||||
|
|
||||||
|
/* define if matrix has ghost (lacks anti-ghosting diodes) */
|
||||||
|
//#define MATRIX_HAS_GHOST
|
||||||
|
|
||||||
|
/* number of backlight levels */
|
||||||
|
|
||||||
|
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||||
|
#define LOCKING_SUPPORT_ENABLE
|
||||||
|
/* Locking resynchronize hack */
|
||||||
|
#define LOCKING_RESYNC_ENABLE
|
||||||
|
|
||||||
|
/* If defined, GRAVE_ESC will always act as ESC when CTRL is held.
|
||||||
|
* This is userful for the Windows task manager shortcut (ctrl+shift+esc).
|
||||||
|
*/
|
||||||
|
// #define GRAVE_ESC_CTRL_OVERRIDE
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Force NKRO
|
||||||
|
*
|
||||||
|
* Force NKRO (nKey Rollover) to be enabled by default, regardless of the saved
|
||||||
|
* state in the bootmagic EEPROM settings. (Note that NKRO must be enabled in the
|
||||||
|
* makefile for this to work.)
|
||||||
|
*
|
||||||
|
* If forced on, NKRO can be disabled via magic key (default = LShift+RShift+N)
|
||||||
|
* until the next keyboard reset.
|
||||||
|
*
|
||||||
|
* NKRO may prevent your keystrokes from being detected in the BIOS, but it is
|
||||||
|
* fully operational during normal computer usage.
|
||||||
|
*
|
||||||
|
* For a less heavy-handed approach, enable NKRO via magic key (LShift+RShift+N)
|
||||||
|
* or via bootmagic (hold SPACE+N while plugging in the keyboard). Once set by
|
||||||
|
* bootmagic, NKRO mode will always be enabled until it is toggled again during a
|
||||||
|
* power-up.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
//#define FORCE_NKRO
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Magic Key Options
|
||||||
|
*
|
||||||
|
* Magic keys are hotkey commands that allow control over firmware functions of
|
||||||
|
* the keyboard. They are best used in combination with the HID Listen program,
|
||||||
|
* found here: https://www.pjrc.com/teensy/hid_listen.html
|
||||||
|
*
|
||||||
|
* The options below allow the magic key functionality to be changed. This is
|
||||||
|
* useful if your keyboard/keypad is missing keys and you want magic key support.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* key combination for magic key command */
|
||||||
|
#define IS_COMMAND() ( \
|
||||||
|
keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
|
||||||
|
/*
|
||||||
|
* MIDI options
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Prevent use of disabled MIDI features in the keymap */
|
||||||
|
//#define MIDI_ENABLE_STRICT 1
|
||||||
|
|
||||||
|
/* enable basic MIDI features:
|
||||||
|
- MIDI notes can be sent when in Music mode is on
|
||||||
|
*/
|
||||||
|
//#define MIDI_BASIC
|
||||||
|
|
||||||
|
/* enable advanced MIDI features:
|
||||||
|
- MIDI notes can be added to the keymap
|
||||||
|
- Octave shift and transpose
|
||||||
|
- Virtual sustain, portamento, and modulation wheel
|
||||||
|
- etc.
|
||||||
|
*/
|
||||||
|
//#define MIDI_ADVANCED
|
||||||
|
|
||||||
|
/* override number of MIDI tone keycodes (each octave adds 12 keycodes and allocates 12 bytes) */
|
||||||
|
//#define MIDI_TONE_KEYCODE_OCTAVES 1
|
0
keyboards/dc01/right/info.json
Normal file
0
keyboards/dc01/right/info.json
Normal file
38
keyboards/dc01/right/keymaps/default/keymap.c
Normal file
38
keyboards/dc01/right/keymaps/default/keymap.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_ANSI( /* Base */
|
||||||
|
KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \
|
||||||
|
KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC,KC_BSLS, \
|
||||||
|
KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, \
|
||||||
|
KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \
|
||||||
|
KC_SPC, KC_SPC, KC_RALT, KC_RGUI, KC_RGUI, KC_RCTL \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
return true;
|
||||||
|
}
|
3
keyboards/dc01/right/keymaps/default/readme.md
Normal file
3
keyboards/dc01/right/keymaps/default/readme.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# The default ANSI keymap for DC01 Right
|
||||||
|
|
||||||
|
When using the right module individually, this keymap will take effect. When using the keyboard as a whole please edit the keymap of the left module.
|
46
keyboards/dc01/right/keymaps/hhkb_ansi/keymap.c
Normal file
46
keyboards/dc01/right/keymaps/hhkb_ansi/keymap.c
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_HHKB_ANSI( /* Base */
|
||||||
|
KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_GRV, \
|
||||||
|
KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC,KC_BSPC, \
|
||||||
|
KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_ENT, \
|
||||||
|
KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT,MO(1), \
|
||||||
|
KC_SPC, KC_SPC, KC_RALT, KC_RGUI, KC_RGUI, KC_RCTL \
|
||||||
|
),
|
||||||
|
|
||||||
|
[1] = LAYOUT_HHKB_ANSI(
|
||||||
|
KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, \
|
||||||
|
KC_TRNS,KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, KC_TRNS, KC_BSPC, \
|
||||||
|
KC_PAST,KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_PENT, \
|
||||||
|
KC_PPLS,KC_PMNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, \
|
||||||
|
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
return true;
|
||||||
|
}
|
3
keyboards/dc01/right/keymaps/hhkb_ansi/readme.md
Normal file
3
keyboards/dc01/right/keymaps/hhkb_ansi/readme.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# The default HHKB ANSI keymap for DC01 Right
|
||||||
|
|
||||||
|
When using the right module individually, this keymap will take effect. When using the keyboard as a whole please edit the keymap of the left module.
|
46
keyboards/dc01/right/keymaps/hhkb_iso/keymap.c
Normal file
46
keyboards/dc01/right/keymaps/hhkb_iso/keymap.c
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_HHKB_ISO( /* Base */
|
||||||
|
KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSLS, KC_BSPC, \
|
||||||
|
KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, \
|
||||||
|
KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_NUHS,KC_ENT, \
|
||||||
|
KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT,MO(1), \
|
||||||
|
KC_SPC, KC_SPC, KC_RALT, KC_RGUI, KC_RGUI, KC_RCTL \
|
||||||
|
),
|
||||||
|
|
||||||
|
[1] = LAYOUT_HHKB_ISO(
|
||||||
|
KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_INS, KC_DEL, \
|
||||||
|
KC_TRNS,KC_TRNS, KC_PSCR, KC_SLCK, KC_PAUS, KC_UP, KC_TRNS, \
|
||||||
|
KC_PAST,KC_PSLS, KC_HOME, KC_PGUP, KC_LEFT, KC_RGHT, KC_TRNS, KC_PENT, \
|
||||||
|
KC_PPLS,KC_PMNS, KC_END, KC_PGDN, KC_DOWN, KC_TRNS, KC_TRNS, \
|
||||||
|
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
return true;
|
||||||
|
}
|
3
keyboards/dc01/right/keymaps/hhkb_iso/readme.md
Normal file
3
keyboards/dc01/right/keymaps/hhkb_iso/readme.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# The default HHKB ISO keymap for DC01 Right
|
||||||
|
|
||||||
|
When using the right module individually, this keymap will take effect. When using the keyboard as a whole please edit the keymap of the left module.
|
38
keyboards/dc01/right/keymaps/iso/keymap.c
Normal file
38
keyboards/dc01/right/keymaps/iso/keymap.c
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include QMK_KEYBOARD_H
|
||||||
|
|
||||||
|
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
|
||||||
|
[0] = LAYOUT_ISO( /* Base */
|
||||||
|
KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, \
|
||||||
|
KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, \
|
||||||
|
KC_H, KC_J, KC_K, KC_L, KC_SCLN,KC_QUOT, KC_NUHS,KC_ENT, \
|
||||||
|
KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT, \
|
||||||
|
KC_SPC, KC_SPC, KC_RALT, KC_RGUI, KC_RGUI, KC_RCTL \
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
return true;
|
||||||
|
}
|
3
keyboards/dc01/right/keymaps/iso/readme.md
Normal file
3
keyboards/dc01/right/keymaps/iso/readme.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# The default ISO keymap for DC01 Right
|
||||||
|
|
||||||
|
When using the right module individually, this keymap will take effect. When using the keyboard as a whole please edit the keymap of the left module.
|
404
keyboards/dc01/right/matrix.c
Normal file
404
keyboards/dc01/right/matrix.c
Normal file
|
@ -0,0 +1,404 @@
|
||||||
|
/*
|
||||||
|
Copyright 2012 Jun Wako
|
||||||
|
Copyright 2014 Jack Humbert
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#if defined(__AVR__)
|
||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/wdt.h>
|
||||||
|
#include <avr/interrupt.h>
|
||||||
|
#include <util/delay.h>
|
||||||
|
#endif
|
||||||
|
#include "wait.h"
|
||||||
|
#include "print.h"
|
||||||
|
#include "debug.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "matrix.h"
|
||||||
|
#include "timer.h"
|
||||||
|
#include "i2c_slave.h"
|
||||||
|
#include "lufa.h"
|
||||||
|
|
||||||
|
#define SLAVE_I2C_ADDRESS 0x19
|
||||||
|
|
||||||
|
/* Set 0 if debouncing isn't needed */
|
||||||
|
|
||||||
|
#ifndef DEBOUNCING_DELAY
|
||||||
|
# define DEBOUNCING_DELAY 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
static uint16_t debouncing_time;
|
||||||
|
static bool debouncing = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (MATRIX_COLS <= 8)
|
||||||
|
# define print_matrix_header() print("\nr/c 01234567\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse8(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint8_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 16)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse16(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop16(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint16_t)1)
|
||||||
|
#elif (MATRIX_COLS <= 32)
|
||||||
|
# define print_matrix_header() print("\nr/c 0123456789ABCDEF0123456789ABCDEF\n")
|
||||||
|
# define print_matrix_row(row) print_bin_reverse32(matrix_get_row(row))
|
||||||
|
# define matrix_bitpop(i) bitpop32(matrix[i])
|
||||||
|
# define ROW_SHIFTER ((uint32_t)1)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
extern const matrix_row_t matrix_mask[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == ROW2COL) || (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static const uint8_t row_pins[MATRIX_ROWS] = MATRIX_ROW_PINS;
|
||||||
|
static const uint8_t col_pins[MATRIX_COLS] = MATRIX_COL_PINS;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* matrix state(1:on, 0:off) */
|
||||||
|
static matrix_row_t matrix[MATRIX_ROWS];
|
||||||
|
|
||||||
|
static matrix_row_t matrix_debouncing[MATRIX_ROWS];
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
static void init_cols(void);
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row);
|
||||||
|
static void unselect_rows(void);
|
||||||
|
static void select_row(uint8_t row);
|
||||||
|
static void unselect_row(uint8_t row);
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
static void init_rows(void);
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col);
|
||||||
|
static void unselect_cols(void);
|
||||||
|
static void unselect_col(uint8_t col);
|
||||||
|
static void select_col(uint8_t col);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_quantum(void) {
|
||||||
|
matrix_init_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_quantum(void) {
|
||||||
|
matrix_scan_kb();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_init_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
__attribute__ ((weak))
|
||||||
|
void matrix_scan_user(void) {
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_rows(void) {
|
||||||
|
return MATRIX_ROWS;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
uint8_t matrix_cols(void) {
|
||||||
|
return MATRIX_COLS;
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_init(void) {
|
||||||
|
|
||||||
|
// initialize row and col
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
unselect_rows();
|
||||||
|
init_cols();
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
unselect_cols();
|
||||||
|
init_rows();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// initialize matrix state: all keys off
|
||||||
|
for (uint8_t i=0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = 0;
|
||||||
|
matrix_debouncing[i] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_init_quantum();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_scan(void)
|
||||||
|
{
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
// Set row, read cols
|
||||||
|
for (uint8_t current_row = 0; current_row < MATRIX_ROWS; current_row++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_cols_on_row(matrix_debouncing, current_row);
|
||||||
|
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
|
||||||
|
# else
|
||||||
|
read_cols_on_row(matrix, current_row);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
// Set col, read rows
|
||||||
|
for (uint8_t current_col = 0; current_col < MATRIX_COLS; current_col++) {
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
bool matrix_changed = read_rows_on_col(matrix_debouncing, current_col);
|
||||||
|
if (matrix_changed) {
|
||||||
|
debouncing = true;
|
||||||
|
debouncing_time = timer_read();
|
||||||
|
}
|
||||||
|
# else
|
||||||
|
read_rows_on_col(matrix, current_col);
|
||||||
|
# endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
# if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing && (timer_elapsed(debouncing_time) > DEBOUNCING_DELAY)) {
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
matrix[i] = matrix_debouncing[i];
|
||||||
|
}
|
||||||
|
debouncing = false;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured){
|
||||||
|
txbuffer[1] = 0x55;
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++){
|
||||||
|
txbuffer[i+2] = matrix[i]; //send matrix over i2c
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
matrix_scan_quantum();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool matrix_is_modified(void)
|
||||||
|
{
|
||||||
|
#if (DEBOUNCING_DELAY > 0)
|
||||||
|
if (debouncing) return false;
|
||||||
|
#endif
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool matrix_is_on(uint8_t row, uint8_t col)
|
||||||
|
{
|
||||||
|
return (matrix[row] & ((matrix_row_t)1<col));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline
|
||||||
|
matrix_row_t matrix_get_row(uint8_t row)
|
||||||
|
{
|
||||||
|
// Matrix mask lets you disable switches in the returned matrix data. For example, if you have a
|
||||||
|
// switch blocker installed and the switch is always pressed.
|
||||||
|
#ifdef MATRIX_MASKED
|
||||||
|
return matrix[row] & matrix_mask[row];
|
||||||
|
#else
|
||||||
|
return matrix[row];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_print(void)
|
||||||
|
{
|
||||||
|
print_matrix_header();
|
||||||
|
|
||||||
|
for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
|
||||||
|
phex(row); print(": ");
|
||||||
|
print_matrix_row(row);
|
||||||
|
print("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t matrix_key_count(void)
|
||||||
|
{
|
||||||
|
uint8_t count = 0;
|
||||||
|
for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
|
||||||
|
count += matrix_bitpop(i);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if (DIODE_DIRECTION == COL2ROW)
|
||||||
|
|
||||||
|
static void init_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_cols_on_row(matrix_row_t current_matrix[], uint8_t current_row)
|
||||||
|
{
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[current_row];
|
||||||
|
|
||||||
|
// Clear data in matrix row
|
||||||
|
current_matrix[current_row] = 0;
|
||||||
|
|
||||||
|
// Select row and wait for row selecton to stabilize
|
||||||
|
select_row(current_row);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each col...
|
||||||
|
for(uint8_t col_index = 0; col_index < MATRIX_COLS; col_index++) {
|
||||||
|
|
||||||
|
// Select the col pin to read (active low)
|
||||||
|
uint8_t pin = col_pins[col_index];
|
||||||
|
uint8_t pin_state = (_SFR_IO8(pin >> 4) & _BV(pin & 0xF));
|
||||||
|
|
||||||
|
// Populate the matrix row with the state of the col pin
|
||||||
|
current_matrix[current_row] |= pin_state ? 0 : (ROW_SHIFTER << col_index);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect row
|
||||||
|
unselect_row(current_row);
|
||||||
|
|
||||||
|
return (last_row_value != current_matrix[current_row]);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_row(uint8_t row)
|
||||||
|
{
|
||||||
|
uint8_t pin = row_pins[row];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#elif (DIODE_DIRECTION == ROW2COL)
|
||||||
|
|
||||||
|
static void init_rows(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_ROWS; x++) {
|
||||||
|
uint8_t pin = row_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool read_rows_on_col(matrix_row_t current_matrix[], uint8_t current_col)
|
||||||
|
{
|
||||||
|
bool matrix_changed = false;
|
||||||
|
|
||||||
|
// Select col and wait for col selecton to stabilize
|
||||||
|
select_col(current_col);
|
||||||
|
wait_us(30);
|
||||||
|
|
||||||
|
// For each row...
|
||||||
|
for(uint8_t row_index = 0; row_index < MATRIX_ROWS; row_index++)
|
||||||
|
{
|
||||||
|
|
||||||
|
// Store last value of row prior to reading
|
||||||
|
matrix_row_t last_row_value = current_matrix[row_index];
|
||||||
|
|
||||||
|
// Check row pin state
|
||||||
|
if ((_SFR_IO8(row_pins[row_index] >> 4) & _BV(row_pins[row_index] & 0xF)) == 0)
|
||||||
|
{
|
||||||
|
// Pin LO, set col bit
|
||||||
|
current_matrix[row_index] |= (ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Pin HI, clear col bit
|
||||||
|
current_matrix[row_index] &= ~(ROW_SHIFTER << current_col);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if the matrix changed state
|
||||||
|
if ((last_row_value != current_matrix[row_index]) && !(matrix_changed))
|
||||||
|
{
|
||||||
|
matrix_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unselect col
|
||||||
|
unselect_col(current_col);
|
||||||
|
|
||||||
|
return matrix_changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void select_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) |= _BV(pin & 0xF); // OUT
|
||||||
|
_SFR_IO8((pin >> 4) + 2) &= ~_BV(pin & 0xF); // LOW
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_col(uint8_t col)
|
||||||
|
{
|
||||||
|
uint8_t pin = col_pins[col];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
|
||||||
|
static void unselect_cols(void)
|
||||||
|
{
|
||||||
|
for(uint8_t x = 0; x < MATRIX_COLS; x++) {
|
||||||
|
uint8_t pin = col_pins[x];
|
||||||
|
_SFR_IO8((pin >> 4) + 1) &= ~_BV(pin & 0xF); // IN
|
||||||
|
_SFR_IO8((pin >> 4) + 2) |= _BV(pin & 0xF); // HI
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//this replases tmk code
|
||||||
|
void matrix_setup(void){
|
||||||
|
|
||||||
|
if (USB_DeviceState != DEVICE_STATE_Configured){
|
||||||
|
i2c_init(SLAVE_I2C_ADDRESS); //setup address of slave i2c
|
||||||
|
sei(); //enable interupts
|
||||||
|
}
|
||||||
|
}
|
15
keyboards/dc01/right/readme.md
Normal file
15
keyboards/dc01/right/readme.md
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
# DC01 Right Half
|
||||||
|
|
||||||
|
![DC01 Right Half](https://i.imgur.com/PTn0sp8.jpg)
|
||||||
|
|
||||||
|
A hotpluggable four part keyboard which comes together with magnets and pogo pins! This is the right part
|
||||||
|
|
||||||
|
Keyboard Maintainer: [Yiancar](https://github.com/yiancar)
|
||||||
|
Hardware Supported: Runs on an atmega32u4
|
||||||
|
Hardware Availability: [Mechboards](https://mechboards.co.uk/)
|
||||||
|
|
||||||
|
Make example for this keyboard (after setting up your build environment):
|
||||||
|
|
||||||
|
make dc01/right: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.
|
43
keyboards/dc01/right/right.c
Normal file
43
keyboards/dc01/right/right.c
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#include "right.h"
|
||||||
|
|
||||||
|
void matrix_init_kb(void) {
|
||||||
|
// put your keyboard start-up code here
|
||||||
|
// runs once when the firmware starts up
|
||||||
|
|
||||||
|
matrix_init_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
void matrix_scan_kb(void) {
|
||||||
|
// put your looping keyboard code here
|
||||||
|
// runs every cycle (a lot)
|
||||||
|
|
||||||
|
matrix_scan_user();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||||
|
// put your per-action keyboard code here
|
||||||
|
// runs for every action, just before processing by the firmware
|
||||||
|
|
||||||
|
return process_record_user(keycode, record);
|
||||||
|
}
|
||||||
|
|
||||||
|
void led_set_kb(uint8_t usb_led) {
|
||||||
|
// put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
|
||||||
|
|
||||||
|
led_set_user(usb_led);
|
||||||
|
}
|
86
keyboards/dc01/right/right.h
Normal file
86
keyboards/dc01/right/right.h
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
/* Copyright 2018 Yiancar
|
||||||
|
*
|
||||||
|
* 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 RIGHT_H
|
||||||
|
#define RIGHT_H
|
||||||
|
|
||||||
|
#include "quantum.h"
|
||||||
|
|
||||||
|
#define XXX KC_NO
|
||||||
|
|
||||||
|
// This a shortcut to help you visually see your layout.
|
||||||
|
// The first section contains all of the arguments
|
||||||
|
// The second converts the arguments into a two-dimensional array
|
||||||
|
#define LAYOUT_ANSI( \
|
||||||
|
K01, K02, K03, K04, K05, K06, K07, \
|
||||||
|
K10, K11, K12, K13, K14, K15, K16, K17, \
|
||||||
|
K20, K21, K22, K23, K24, K25, K27, \
|
||||||
|
K30, K31, K32, K33, K34, K37, \
|
||||||
|
K40, K41, K42, K43, K44, K45 \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ XXX, K01, K02, K03, K04, K05, K06, K07 }, \
|
||||||
|
{ K10, K11, K12, K13, K14, K15, K16, K17 }, \
|
||||||
|
{ K20, K21, K22, K23, K24, K25, XXX, K27 }, \
|
||||||
|
{ K30, K31, K32, K33, K34, XXX, XXX, K37 }, \
|
||||||
|
{ K40, K41, K42, K43, K44, K45, XXX, XXX } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LAYOUT_ISO( \
|
||||||
|
K01, K02, K03, K04, K05, K06, K07, \
|
||||||
|
K10, K11, K12, K13, K14, K15, K16, \
|
||||||
|
K20, K21, K22, K23, K24, K25, K26, K27, \
|
||||||
|
K30, K31, K32, K33, K34, K37, \
|
||||||
|
K40, K41, K42, K43, K44, K45 \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ XXX, K01, K02, K03, K04, K05, K06, K07 }, \
|
||||||
|
{ K10, K11, K12, K13, K14, K15, K16, XXX }, \
|
||||||
|
{ K20, K21, K22, K23, K24, K25, K26, K27 }, \
|
||||||
|
{ K30, K31, K32, K33, K34, XXX, XXX, K37 }, \
|
||||||
|
{ K40, K41, K42, K43, K44, K45, XXX, XXX } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LAYOUT_HHKB_ANSI( \
|
||||||
|
K01, K02, K03, K04, K05, K06, K07, K00, \
|
||||||
|
K10, K11, K12, K13, K14, K15, K16, K17, \
|
||||||
|
K20, K21, K22, K23, K24, K25, K27, \
|
||||||
|
K30, K31, K32, K33, K34, K36, K37, \
|
||||||
|
K40, K41, K42, K43, K44, K45 \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ K00, K01, K02, K03, K04, K05, K06, K07 }, \
|
||||||
|
{ K10, K11, K12, K13, K14, K15, K16, K17 }, \
|
||||||
|
{ K20, K21, K22, K23, K24, K25, XXX, K27 }, \
|
||||||
|
{ K30, K31, K32, K33, K34, XXX, K36, K37 }, \
|
||||||
|
{ K40, K41, K42, K43, K44, K45, XXX, XXX } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define LAYOUT_HHKB_ISO( \
|
||||||
|
K01, K02, K03, K04, K05, K06, K07, K00, \
|
||||||
|
K10, K11, K12, K13, K14, K15, K16, \
|
||||||
|
K20, K21, K22, K23, K24, K25, K26, K27, \
|
||||||
|
K30, K31, K32, K33, K34, K36, K37, \
|
||||||
|
K40, K41, K42, K43, K44, K45 \
|
||||||
|
) \
|
||||||
|
{ \
|
||||||
|
{ K00, K01, K02, K03, K04, K05, K06, K07 }, \
|
||||||
|
{ K10, K11, K12, K13, K14, K15, K16, XXX }, \
|
||||||
|
{ K20, K21, K22, K23, K24, K25, K26, K27 }, \
|
||||||
|
{ K30, K31, K32, K33, K34, XXX, K36, K37 }, \
|
||||||
|
{ K40, K41, K42, K43, K44, K45, XXX, XXX } \
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
74
keyboards/dc01/right/rules.mk
Normal file
74
keyboards/dc01/right/rules.mk
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
SRC += matrix.c \
|
||||||
|
../../../drivers/avr/i2c_slave.c
|
||||||
|
|
||||||
|
# MCU name
|
||||||
|
#MCU = at90usb1286
|
||||||
|
MCU = atmega32u4
|
||||||
|
|
||||||
|
# Processor frequency.
|
||||||
|
# This will define a symbol, F_CPU, in all source code files equal to the
|
||||||
|
# processor frequency in Hz. You can then use this symbol in your source code to
|
||||||
|
# calculate timings. Do NOT tack on a 'UL' at the end, this will be done
|
||||||
|
# automatically to create a 32-bit value in your source code.
|
||||||
|
#
|
||||||
|
# This will be an integer division of F_USB below, as it is sourced by
|
||||||
|
# F_USB after it has run through any CPU prescalers. Note that this value
|
||||||
|
# does not *change* the processor frequency - it should merely be updated to
|
||||||
|
# reflect the processor speed set externally so that the code can use accurate
|
||||||
|
# software delays.
|
||||||
|
F_CPU = 16000000
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# LUFA specific
|
||||||
|
#
|
||||||
|
# Target architecture (see library "Board Types" documentation).
|
||||||
|
ARCH = AVR8
|
||||||
|
|
||||||
|
# Input clock frequency.
|
||||||
|
# This will define a symbol, F_USB, in all source code files equal to the
|
||||||
|
# input clock frequency (before any prescaling is performed) in Hz. This value may
|
||||||
|
# differ from F_CPU if prescaling is used on the latter, and is required as the
|
||||||
|
# raw input clock is fed directly to the PLL sections of the AVR for high speed
|
||||||
|
# clock generation for the USB and other AVR subsections. Do NOT tack on a 'UL'
|
||||||
|
# at the end, this will be done automatically to create a 32-bit value in your
|
||||||
|
# source code.
|
||||||
|
#
|
||||||
|
# If no clock division is performed on the input clock inside the AVR (via the
|
||||||
|
# CPU clock adjust registers or the clock division fuses), this will be equal to F_CPU.
|
||||||
|
F_USB = $(F_CPU)
|
||||||
|
|
||||||
|
# Interrupt driven control endpoint task(+60)
|
||||||
|
OPT_DEFS += -DINTERRUPT_CONTROL_ENDPOINT
|
||||||
|
|
||||||
|
|
||||||
|
# Boot Section Size in *bytes*
|
||||||
|
# Teensy halfKay 512
|
||||||
|
# Teensy++ halfKay 1024
|
||||||
|
# Atmel DFU loader 4096
|
||||||
|
# LUFA bootloader 4096
|
||||||
|
# USBaspLoader 2048
|
||||||
|
OPT_DEFS += -DBOOTLOADER_SIZE=4096
|
||||||
|
|
||||||
|
|
||||||
|
# Build Options
|
||||||
|
# change yes to no to disable
|
||||||
|
#
|
||||||
|
BOOTMAGIC_ENABLE = no # Virtual DIP switch configuration(+1000)
|
||||||
|
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
|
||||||
|
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
|
||||||
|
CONSOLE_ENABLE = no # Console for debug(+400)
|
||||||
|
COMMAND_ENABLE = no # Commands for debug and configuration
|
||||||
|
# Do not enable SLEEP_LED_ENABLE. it uses the same timer as BACKLIGHT_ENABLE
|
||||||
|
SLEEP_LED_ENABLE = no # Breathing sleep LED during USB suspend
|
||||||
|
# if this doesn't work, see here: https://github.com/tmk/tmk_keyboard/wiki/FAQ#nkro-doesnt-work
|
||||||
|
NKRO_ENABLE = yes # USB Nkey Rollover
|
||||||
|
BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality on B7 by default
|
||||||
|
MIDI_ENABLE = no # MIDI support (+2400 to 4200, depending on config)
|
||||||
|
UNICODE_ENABLE = no # Unicode
|
||||||
|
BLUETOOTH_ENABLE = no # Enable Bluetooth with the Adafruit EZ-Key HID
|
||||||
|
AUDIO_ENABLE = no # Audio output on port C6
|
||||||
|
FAUXCLICKY_ENABLE = no # Use buzzer to emulate clicky switches
|
||||||
|
HD44780_ENABLE = no # Enable support for HD44780 based LCDs (+400)
|
||||||
|
NO_USB_STARTUP_CHECK = yes # Disable initialization only when usb is plugged in
|
||||||
|
CUSTOM_MATRIX = yes # Use custom matrix
|
Loading…
Reference in a new issue