Skip to content

Commit

Permalink
foobar
Browse files Browse the repository at this point in the history
  • Loading branch information
di0ib committed Aug 30, 2017
1 parent 5ef404d commit 51915f9
Show file tree
Hide file tree
Showing 23 changed files with 2,649 additions and 0 deletions.
171 changes: 171 additions & 0 deletions keyboard/foobar/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#----------------------------------------------------------------------------
# On command line:
#
# make all = Make software.
#
# make clean = Clean out built project files.
#
# make coff = Convert ELF to AVR COFF.
#
# make extcoff = Convert ELF to AVR Extended COFF.
#
# make program = Download the hex file to the device.
# Please customize your programmer settings(PROGRAM_CMD)
#
# make teensy = Download the hex file to the device, using teensy_loader_cli.
# (must have teensy_loader_cli installed).
#
# make dfu = Download the hex file to the device, using dfu-programmer (must
# have dfu-programmer installed).
#
# make flip = Download the hex file to the device, using Atmel FLIP (must
# have Atmel FLIP installed).
#
# make dfu-ee = Download the eeprom file to the device, using dfu-programmer
# (must have dfu-programmer installed).
#
# make flip-ee = Download the eeprom file to the device, using Atmel FLIP
# (must have Atmel FLIP installed).
#
# make debug = Start either simulavr or avarice as specified for debugging,
# with avr-gdb or avr-insight as the front end for debugging.
#
# make filename.s = Just compile filename.c into the assembler code only.
#
# make filename.i = Create a preprocessed source file for use in submitting
# bug reports to the GCC project.
#
# To rebuild project do "make clean" then "make all".
#----------------------------------------------------------------------------

# Target file name (without extension).
TARGET = foobar

# Directory common source filess exist
TMK_DIR = ../../tmk_core

# Directory keyboard dependent files exist
TARGET_DIR = .

# project specific files
SRC = matrix.c \
i2c.c \
serial.c \
split-util.c \
led.c

CONFIG_H = config.h

# MCU name
MCU = atmega32u4

COM_PORT=/dev/ttyACM0
PROGRAM_CMD=sleep 3; avrdude -p atmega32u4 -P $(COM_PORT) -c avr109 -U flash:w:$(TARGET).hex

# 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

# Changes some bootmagic settings for when the space is on the left half
OPT_DEFS += -DSPACE_ON_LEFT_HALF

# # Use I2C for communication between the halves of the keyboard
# OPT_DEFS += -DUSE_I2C

# Build Options
# comment out to disable the options.
#
BOOTMAGIC_ENABLE = yes # Virtual DIP switch configuration(+1000)
MOUSEKEY_ENABLE = yes # Mouse keys(+4700)
EXTRAKEY_ENABLE = yes # Audio control and System control(+450)
CONSOLE_ENABLE = yes # Console for debug(+400)
COMMAND_ENABLE = yes # Commands for debug and configuration
SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend
NKRO_ENABLE = yes # USB Nkey Rollover
ACTIONMAP_ENABLE = yes # Use 16bit action codes in keymap instead of 8bit keycodes


ifdef ACTIONMAP_ENABLE
KEYMAP_FILE = actionmap
else
KEYMAP_FILE = keymap
SRC := keymap_common.c $(SRC)
endif
ifdef KEYMAP
SRC := $(KEYMAP_FILE)_$(KEYMAP).c $(SRC)
else
SRC := $(KEYMAP_FILE)_plain.c $(SRC)
endif


#PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support
#PS2_USE_BUSYWAIT = yes # uses primitive reference code
#PS2_USE_INT = yes # uses external interrupt for falling edge of PS/2 clock pin
#PS2_USE_USART = yes # uses hardware USART engine for PS/2 signal receive(recomened)


# Search Path
VPATH += $(TARGET_DIR)
VPATH += $(TMK_DIR)

# Un comment this line if you want to use pjrc protocol
# include $(TMK_DIR)/protocol/pjrc.mk

include $(TMK_DIR)/protocol/lufa.mk
include $(TMK_DIR)/common.mk
include $(TMK_DIR)/rules.mk


debug-on: EXTRAFLAGS += -DDEBUG -DDEBUG_ACTION
debug-on: all

debug-off: EXTRAFLAGS += -DNO_DEBUG -DNO_PRINT
debug-off: OPT_DEFS := $(filter-out -DCONSOLE_ENABLE,$(OPT_DEFS))
debug-off: all

eeprom-left:
sleep 3; avrdude -p atmega32u4 -P $(COM_PORT) -c avr109 -U eeprom:w:eeprom-lefthand.eep

eeprom-right:
sleep 3; avrdude -p atmega32u4 -P $(COM_PORT) -c avr109 -U eeprom:w:eeprom-righthand.eep
99 changes: 99 additions & 0 deletions keyboard/foobar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
This is a modification of the TMK firmware by ahtn found here https://github.com/ahtn/tmk_keyboard/tree/master/keyboard/split_keyboard

Custom split keyboard firmware
======

Split keyboard firmware for Arduino Pro Micro or other ATmega32u4
based boards.


Features
--------

Some features supported by the firmware:

* Either half can connect to the computer via USB, or both halves can be used
independently.
* You only need 3 wires to connect the two halves. Two for VCC and GND and one
for serial communication.
* Optional support for I2C connection between the two halves if for some
reason you require a faster connection between the two halves. Note this
requires an extra wire between halves and pull-up resistors on the data lines.

Required Hardware
-----------------

Apart from diodes and key switches for the keyboard matrix in each half, you
will need:

* 2 Arduino Pro Micro's. You can find theses on aliexpress for ≈3.50USD each.
* 2 TRS sockets
* 1 TRS cable.

Alternatively, you can use any sort of cable and socket that has at least 3
wires. If you want to use I2C to communicate between halves, you will need a
cable with at least 4 wires and 2x 4.7kΩ pull-up resistors


Wiring
------

The 3 wires of the TRS cable need to connect GND, VCC, and digital pin 3 (i.e.
`PD0` on the ATmega32u4) between the two Pro Micros.

Then wire your key matrix to any of the remaining 17 IO pins of the pro micro
and modify the `MATRIX_COL_PINS` and `MATRIX_ROW_PINS` in `config.h` accordingly.

The wiring for serial:

![serial wiring](imgs/split-keyboard-serial-schematic.png)

The wiring for i2c:

![i2c wiring](imgs/split-keyboard-i2c-schematic.png)

The pull-up resistors may be placed on either half. It is also possible
to use 4 resistors and have the pull-ups in both halves, but this is
unnecessary in simple use cases.

Notes on Software Configuration
-------------------------------

Configuring the firmware is similar to any other TMK project. One thing
to note is that `MATIX_ROWS` in `config.h` is the total number of rows between
the two halves, i.e. if your split keyboard has 4 rows in each half, then
`MATRIX_ROWS=8`.

Also the current implementation assumes a maximum of 8 columns, but it would
not be very difficult to adapt it to support more if required.


Flashing
--------

Before you go to flash the program memory for the first time, you will need to
EEPROM for the left and right halves. The EEPROM is used to store whether the
half is left handed or right handed. This makes it so that the same firmware
file will run on both hands instead of having to flash left and right handed
versions of the firmware to each half. To flash the EEPROM file for the left
half run:
```
make eeprom-left
```
and similarly for right half
```
make eeprom-right
```

After you have flashed the EEPROM for the first time, you then need to program
the flash memory:
```
make program
```
Note that you need to program both halves, but you have the option of using
different keymaps for each half. You could program the left half with a QWERTY
layout and the right half with a Colemak layout. Then if you connect the left
half to a computer by USB the keyboard will use QWERTY and Colemak when the
right half is connected.


22 changes: 22 additions & 0 deletions keyboard/foobar/actionmap_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef ACTIONMAP_COMMON_H
#define ACTIONMAP_COMMON_H

#define ACTIONMAP( \
K00, K01, K02, K03, K04, \
K10, K11, K12, K13, K14, \
K20, K21, K22, K23, K24, \
\
K30, K31, K32, K33, K34, \
K40, K41, K42, K43, K44, \
K50, K51, K52, K53, K54 \
) { \
{ AC_##K00, AC_##K01, AC_##K02, AC_##K03, AC_##K04 }, \
{ AC_##K10, AC_##K11, AC_##K12, AC_##K13, AC_##K14 }, \
{ AC_##K20, AC_##K21, AC_##K22, AC_##K23, AC_##K24 }, \
\
{ AC_##K34, AC_##K33, AC_##K32, AC_##K31, AC_##K30 }, \
{ AC_##K44, AC_##K43, AC_##K42, AC_##K41, AC_##K40 }, \
{ AC_##K54, AC_##K53, AC_##K52, AC_##K51, AC_##K50 } \
}

#endif
97 changes: 97 additions & 0 deletions keyboard/foobar/actionmap_plain.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#include "actionmap.h"
#include "action_code.h"
#include "actionmap_common.h"


/*
* Actions
*/
#define AC_BLD ACTION_BACKLIGHT_DECREASE()
#define AC_BLI ACTION_BACKLIGHT_INCREASE()
#define AC_TL1 ACTION_LAYER_TAP_KEY(1, KC_SPACE)
#define AC_TL2 ACTION_LAYER_TAP_KEY(2, KC_BSPACE)
#define AC_TL3 ACTION_LAYER_TAP_KEY(3, KC_C)
#define AC_TL4 ACTION_LAYER_TAP_KEY(4, KC_V)
#define AC_TL5 ACTION_LAYER_TAP_KEY(5, KC_B)
#define AC_TM1 ACTION_MODS_TAP_KEY(MOD_RSFT, KC_ENT)
#define AC_TM2 ACTION_MODS_TAP_KEY(MOD_LCTL, KC_Z)
#define AC_TM3 ACTION_MODS_TAP_KEY(MOD_LALT, KC_X)
#define AC_TM4 ACTION_MODS_TAP_KEY(MOD_RALT, KC_N)
#define AC_TM5 ACTION_MODS_TAP_KEY(MOD_RCTL, KC_M)
#define AC_S01 ACTION_MODS_KEY(MOD_LSFT, KC_1)
#define AC_S02 ACTION_MODS_KEY(MOD_LSFT, KC_2)
#define AC_S03 ACTION_MODS_KEY(MOD_LSFT, KC_3)
#define AC_S04 ACTION_MODS_KEY(MOD_LSFT, KC_4)
#define AC_S05 ACTION_MODS_KEY(MOD_LSFT, KC_5)
#define AC_S06 ACTION_MODS_KEY(MOD_LSFT, KC_6)
#define AC_S07 ACTION_MODS_KEY(MOD_LSFT, KC_7)
#define AC_S08 ACTION_MODS_KEY(MOD_LSFT, KC_8)
#define AC_S09 ACTION_MODS_KEY(MOD_LSFT, KC_9)
#define AC_S10 ACTION_MODS_KEY(MOD_LSFT, KC_0)
#define AC_S11 ACTION_MODS_KEY(MOD_LSFT, KC_MINS)
#define AC_S12 ACTION_MODS_KEY(MOD_LSFT, KC_EQL)
#define AC_S13 ACTION_MODS_KEY(MOD_LSFT, KC_LBRC)
#define AC_S14 ACTION_MODS_KEY(MOD_LSFT, KC_RBRC)
#define AC_S15 ACTION_MODS_KEY(MOD_LSFT, KC_BSLS)
#define AC_S16 ACTION_MODS_KEY(MOD_LSFT, KC_COMM)
#define AC_S17 ACTION_MODS_KEY(MOD_LSFT, KC_DOT)
#define AC_S18 ACTION_MODS_KEY(MOD_LSFT, KC_SLSH)
#define AC_S19 ACTION_MODS_KEY(MOD_LSFT, KC_SCLN)
#define AC_S20 ACTION_MODS_KEY(MOD_LSFT, KC_QUOT)

const action_t PROGMEM actionmaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = ACTIONMAP(
Q, W, E, R, T,
A, S, D, F, G,
TM2, TM3, TL3, TL4, TL2,

Y, U, I, O, P,
H, J, K, L, ESC,
TL1, TL5, TM4, TM5, TM1),

[1] = ACTIONMAP(
1, 2, 3, 4, 5,
F1, F2, F3, F4, F5,
TRNS, TRNS, TRNS, TRNS, DEL,

6, 7, 8, 9, 0,
F6, F7, F8, F9, F10,
TRNS, TRNS, TRNS, TRNS, TRNS),

[2] = ACTIONMAP(
S01, S02, S03, S04, S05,
F11, F12, TRNS, TRNS, TRNS,
TRNS, TRNS, TRNS, TRNS, TRNS,

S06, S07, S08, S09, S10,
TRNS, TRNS, TRNS, TRNS, GRV,
TRNS, TRNS, TRNS, TRNS, TRNS),

[3] = ACTIONMAP(
TRNS, TRNS, TRNS, TRNS, TRNS,
TAB, TRNS, TRNS, TRNS, TRNS,
TRNS, TRNS, TRNS, TRNS, TRNS,

MINS, EQL, LBRC, RBRC, BSLS,
COMM, DOT, SLSH, SCLN, QUOT,
TRNS, LEFT, DOWN, UP, RGHT),

[4] = ACTIONMAP(
TRNS, TRNS, TRNS, TRNS, TRNS,
TAB, TRNS, TRNS, TRNS, TRNS,
TRNS, TRNS, TRNS, TRNS, TRNS,

S11, S12, S13, S14, S15,
S16, S17, S18, S19, S20,
TRNS, HOME, PGDN, PGUP, END),

[5] = ACTIONMAP(
CALC, WHOM, MAIL, MYCM, TRNS,
TRNS, TRNS, TRNS, TRNS, TRNS,
TRNS, TRNS, TRNS, TRNS, BTLD,

TRNS, TRNS, TRNS, TRNS, PSCR,
TRNS, TRNS, TRNS, BLD, BLI,
TRNS, TRNS, TRNS, TRNS, TRNS),
};

Loading

0 comments on commit 51915f9

Please sign in to comment.