diff options
author | yiancar <yiangosyiangou@cytanet.com.cy> | 2018-07-18 19:55:57 +0300 |
---|---|---|
committer | Jack Humbert <jack.humb@gmail.com> | 2018-07-18 12:55:57 -0400 |
commit | 72fd49b1468d6bbfa59e1c6334866d7aa34f31c1 (patch) | |
tree | d9d5d7a66eebd37765e2ff103e09ed57d787eae9 | |
parent | 7e9a7af672ab226cc57f05f362d6b1e965ac56e6 (diff) |
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
50 files changed, 3747 insertions, 142 deletions
diff --git a/drivers/avr/i2c_master.c b/drivers/avr/i2c_master.c index 4e76e2e7c6..47c6f8e6c6 100755 --- a/drivers/avr/i2c_master.c +++ b/drivers/avr/i2c_master.c @@ -15,15 +15,15 @@ void i2c_init(void) { 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) { - // reset TWI control register - TWCR = 0; - // transmit START condition - TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); + // reset TWI control register + TWCR = 0; + // transmit START condition + TWCR = (1<<TWINT) | (1<<TWSTA) | (1<<TWEN); uint16_t timeout_timer = timer_read(); 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 - if(((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)){ return I2C_STATUS_ERROR; } + // check if the start condition was successfully transmitted + if(((TW_STATUS & 0xF8) != TW_START) && ((TW_STATUS & 0xF8) != TW_REP_START)){ return I2C_STATUS_ERROR; } - // load slave address into data register - TWDR = address; - // start transmission of address - TWCR = (1<<TWINT) | (1<<TWEN); + // load slave address into data register + TWDR = address; + // start transmission of address + TWCR = (1<<TWINT) | (1<<TWEN); timeout_timer = timer_read(); 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 - uint8_t twst = TW_STATUS & 0xF8; - if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return I2C_STATUS_ERROR; + // check if the device has acknowledged the READ / WRITE mode + uint8_t twst = TW_STATUS & 0xF8; + if ( (twst != TW_MT_SLA_ACK) && (twst != TW_MR_SLA_ACK) ) return I2C_STATUS_ERROR; - return I2C_STATUS_SUCCESS; + return I2C_STATUS_SUCCESS; } i2c_status_t i2c_write(uint8_t data, uint16_t timeout) { - // load data into data register - TWDR = data; - // start transmission of data - TWCR = (1<<TWINT) | (1<<TWEN); + // load data into data register + TWDR = data; + // start transmission of data + TWCR = (1<<TWINT) | (1<<TWEN); uint16_t timeout_timer = timer_read(); 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) { - // start TWI module and acknowledge data after reception - TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA); + // start TWI module and acknowledge data after reception + TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA); uint16_t timeout_timer = timer_read(); while( !(TWCR & (1<<TWINT)) ) { @@ -86,15 +86,15 @@ int16_t i2c_read_ack(uint16_t timeout) } } - // return received data from TWDR - return TWDR; + // return received data from TWDR + return TWDR; } int16_t i2c_read_nack(uint16_t timeout) { - // start receiving without acknowledging reception - TWCR = (1<<TWINT) | (1<<TWEN); + // start receiving without acknowledging reception + TWCR = (1<<TWINT) | (1<<TWEN); uint16_t timeout_timer = timer_read(); while( !(TWCR & (1<<TWINT)) ) { @@ -103,39 +103,39 @@ int16_t i2c_read_nack(uint16_t timeout) } } - // return received data from TWDR - return TWDR; + // return received data from TWDR + return TWDR; } 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); - if (status) return status; + if (status) return status; - for (uint16_t i = 0; i < length; i++) { - status = i2c_write(data[i], timeout); + for (uint16_t i = 0; i < length; i++) { + status = i2c_write(data[i], timeout); if (status) return status; - } + } - status = i2c_stop(timeout); + status = i2c_stop(timeout); if (status) return status; - return I2C_STATUS_SUCCESS; + return I2C_STATUS_SUCCESS; } 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); - 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); if (status >= 0) { data[i] = status; } else { return status; } - } + } status = i2c_read_nack(timeout); 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); 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 status = i2c_start(devaddr | 0x00, timeout); - if (status) return status; + if (status) return status; - status = i2c_write(regaddr, timeout); + status = i2c_write(regaddr, timeout); if (status) return status; - for (uint16_t i = 0; i < length; i++) { + for (uint16_t i = 0; i < length; i++) { 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; - 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 status = i2c_start(devaddr, timeout); - if (status) return status; + if (status) return status; status = i2c_write(regaddr, timeout); if (status) return status; status = i2c_start(devaddr | 0x01, timeout); - if (status) return status; + if (status) return status; - for (uint16_t i = 0; i < (length-1); i++) { - status = i2c_read_ack(timeout); + for (uint16_t i = 0; i < (length-1); i++) { + status = i2c_read_ack(timeout); if (status >= 0) { data[i] = status; } else { return status; } - } + } status = i2c_read_nack(timeout); 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); if (status) return status; - return I2C_STATUS_SUCCESS; + return I2C_STATUS_SUCCESS; } i2c_status_t i2c_stop(uint16_t timeout) { - // transmit STOP condition - TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); + // transmit STOP condition + TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWSTO); uint16_t timeout_timer = timer_read(); while(TWCR & (1<<TWSTO)) { @@ -215,4 +215,4 @@ i2c_status_t i2c_stop(uint16_t timeout) } return I2C_STATUS_SUCCESS; -} +}
\ No newline at end of file diff --git a/drivers/avr/i2c_master.h b/drivers/avr/i2c_master.h index cf93680be4..89c64599c5 100755 --- a/drivers/avr/i2c_master.h +++ b/drivers/avr/i2c_master.h @@ -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_stop(uint16_t timeout); -#endif // I2C_MASTER_H +#endif // I2C_MASTER_H
\ No newline at end of file diff --git a/drivers/avr/i2c_slave.c b/drivers/avr/i2c_slave.c index 3edf85b12b..27696ca01a 100755 --- a/drivers/avr/i2c_slave.c +++ b/drivers/avr/i2c_slave.c @@ -5,96 +5,64 @@ #include <avr/io.h> #include <util/twi.h> #include <avr/interrupt.h> +#include <stdbool.h> #include "i2c_slave.h" void i2c_init(uint8_t address){ - // load address into TWI address register - TWAR = (address << 1); - // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt - TWCR = (1<<TWIE) | (1<<TWEA) | (1<<TWINT) | (1<<TWEN); + // load address into TWI address register + TWAR = (address << 1); + // set the TWCR to enable address matching and enable TWI, clear TWINT, enable TWI interrupt + TWCR = (1 << TWIE) | (1 << TWEA) | (1 << TWINT) | (1 << TWEN); } void i2c_stop(void){ - // clear acknowledge and enable bits - TWCR &= ~( (1<<TWEA) | (1<<TWEN) ); + // clear acknowledge and enable bits + TWCR &= ~((1 << TWEA) | (1 << TWEN)); } ISR(TWI_vect){ - - // temporary stores the received data - uint8_t data; - - // own address has been acknowledged - if( (TWSR & 0xF8) == TW_SR_SLA_ACK ){ - buffer_address = 0xFF; - // clear TWI interrupt flag, prepare to receive next byte and acknowledge - TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEA) | (1<<TWEN); - } - else if( (TWSR & 0xF8) == TW_SR_DATA_ACK ){ // data has been received in slave receiver mode - - // save the received byte inside data - data = TWDR; - - // check wether an address has already been transmitted or not - if(buffer_address == 0xFF){ - - buffer_address = data; - - // clear TWI interrupt flag, prepare to receive next byte and acknowledge - TWCR |= (1<<TWIE) | (1<<TWINT) | (1<<TWEA) | (1<<TWEN); - } - else{ // if a databyte has already been received - - // store the data at the current address - rxbuffer[buffer_address] = data; - - // increment the buffer address - buffer_address++; - - // if there is still enough space inside the buffer - if(buffer_address < 0xFF){ - // clear TWI interrupt flag, prepare to receive next byte and 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( (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); - } -} + uint8_t ack = 1; + // temporary stores the received data + //uint8_t data; + + switch(TW_STATUS){ + case TW_SR_SLA_ACK: + // The device is now a slave receiver + slave_has_register_set = false; + break; + + case TW_SR_DATA_ACK: + // This device is a slave receiver and has received data + // First byte is the location then the bytes will be writen in buffer with auto-incriment + if(!slave_has_register_set){ + buffer_address = TWDR; + + if (buffer_address >= RX_BUFFER_SIZE){ // address out of bounds dont ack + ack = 0; + buffer_address = 0; + } + slave_has_register_set = true; // address has been receaved now fill in buffer + } else { + rxbuffer[buffer_address] = TWDR; + buffer_address++; + } + break; + + case TW_ST_SLA_ACK: + case TW_ST_DATA_ACK: + // This device is a slave transmitter and master has requested data + TWDR = txbuffer[buffer_address]; + buffer_address++; + break; + + case TW_BUS_ERROR: + // We got an error, reset i2c + TWCR = 0; + default: + break; + } + + // Reset i2c state mahcine to be ready for next interrupt + TWCR |= (1 << TWIE) | (1 << TWINT) | (ack << TWEA) | (1 << TWEN); +}
\ No newline at end of file diff --git a/drivers/avr/i2c_slave.h b/drivers/avr/i2c_slave.h index 3fda7f8c09..1c3b9ecc00 100755 --- a/drivers/avr/i2c_slave.h +++ b/drivers/avr/i2c_slave.h @@ -8,12 +8,16 @@ #ifndef 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 txbuffer[0xFF]; -volatile uint8_t rxbuffer[0xFF]; +static volatile bool slave_has_register_set = false; +volatile uint8_t txbuffer[TX_BUFFER_SIZE]; +volatile uint8_t rxbuffer[RX_BUFFER_SIZE]; void i2c_init(uint8_t address); void i2c_stop(void); ISR(TWI_vect); -#endif // I2C_SLAVE_H +#endif // I2C_SLAVE_H
\ No newline at end of file diff --git a/keyboards/dc01/arrow/arrow.c b/keyboards/dc01/arrow/arrow.c new file mode 100644 index 0000000000..07988b8099 --- /dev/null +++ b/keyboards/dc01/arrow/arrow.c @@ -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); +} diff --git a/keyboards/dc01/arrow/arrow.h b/keyboards/dc01/arrow/arrow.h new file mode 100644 index 0000000000..b7fec9ee84 --- /dev/null +++ b/keyboards/dc01/arrow/arrow.h @@ -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 diff --git a/keyboards/dc01/arrow/config.h b/keyboards/dc01/arrow/config.h new file mode 100644 index 0000000000..75c674f631 --- /dev/null +++ b/keyboards/dc01/arrow/config.h @@ -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 + |