(intermediate checkin)

partial-rewrite
Ben Blazak 2013-01-29 21:34:46 -08:00
parent 94e18d611d
commit 1db6d4dd37
20 changed files with 468 additions and 64 deletions

View File

@ -514,6 +514,8 @@
### Other Random Stuff
#### Software
* [Tutorial: Metacompilers Part 1]
(http://www.bayfronttechnologies.com/mc_tutorial.html)
Probably doesn't have anything to do with microprocessors *or* web
@ -544,6 +546,21 @@
And the documentation's fairly incomplete (which is sad, it looks like a
really cool language :) ).
#### Hardware
* [Working with Acrylic]
(http://www.bcae1.com/plexi.htm)
* mentioned in [this post]
(http://geekhack.org/index.php?topic=22780.msg782192#msg782192)
by [sordna] (http://geekhack.org/index.php?action=profile;u=9426)
(on <http://geekhack.org/>)
* also see [this post]
(http://geekhack.org/index.php?topic=22780.msg782080#msg782080)
by [kurplop] (http://geekhack.org/index.php?action=profile;u=17045)
(on <http://geekhack.org/>)
-------------------------------------------------------------------------------

View File

@ -26,6 +26,28 @@
|| !( OPT__MCP23018__DRIVE_ROWS || OPT__MCP23018__DRIVE_COLUMNS )
#error "MCP23018 pin drive direction incorrectly set"
#endif
/** macros/(group) pin drive direction
* Select which set of pins (rows or columns) will drive (alternate between
* hi-Z and drive low), and which will be inputs (hi-Z)
*
* Members:
* - `OPT__MCP23018__DRIVE_ROWS`
* - `OPT__MCP23018__DRIVE_COLUMNS`
*
*
* Notes:
*
* - You must set exactly one of these variables to `1`, and the other to `0`
*
* - If you are using internal diodes (inside the key switches), set
* `OPT__MCP23018__DRIVE_ROWS` to `1`
*
* - If the diode cathode is towards the square solder pad, set
* `OPT__MCP23018__DRIVE_COLUMNS` to `1`
*
* - If the diode cathode is towards the circular solder pad, set
* `OPT__MCP23018__DRIVE_ROWS` to `1`
*/
// ----------------------------------------------------------------------------

View File

@ -1,5 +1,3 @@
# Documentation : MCP23018
## Pinout and Pin assignments
* `+` indicates connected pin

View File

@ -31,6 +31,28 @@
|| !( OPT__TEENSY__DRIVE_ROWS || OPT__TEENSY__DRIVE_COLUMNS )
#error "Teensy pin drive direction incorrectly set"
#endif
/** macros/(group) pin drive direction
* Select which set of pins (rows or columns) will drive (alternate between
* hi-Z and drive low), and which will be inputs (hi-Z)
*
* Members:
* - `OPT__TEENSY__DRIVE_ROWS`
* - `OPT__TEENSY__DRIVE_COLUMNS`
*
*
* Notes:
*
* - You must set exactly one of these variables to `1`, and the other to `0`
*
* - If you are using internal diodes (inside the key switches), set
* `OPT__TEENSY__DRIVE_COLUMNS` to `1`
*
* - If the diode cathode is towards the square solder pad, set
* `OPT__TEENSY__DRIVE_COLUMNS` to `1`
*
* - If the diode cathode is towards the circular solder pad, set
* `OPT__TEENSY__DRIVE_ROWS` to `1`
*/
// ----------------------------------------------------------------------------

View File

@ -1,5 +1,3 @@
# Documentation : Teensy 2.0
## Pinout and Pin assignments
* `+` indicates connected pin

View File

@ -16,6 +16,16 @@
// ----------------------------------------------------------------------------
#ifndef OPT__LED_BRIGHTNESS
#error "OPT__LED_BRIGHTNESS not defined"
#endif
/** macros/OPT__LED_BRIGHTNESS/description
* A percentage of maximum brightness, with '1' being greatest and '0' being
* not quite off
*/
// ----------------------------------------------------------------------------
void kb__led__on(uint8_t led) {
switch(led) {
case 1: (DDRB |= (1<<5)); break; // topmost

View File

@ -7,7 +7,7 @@
/** description
* A central place for all ErgoDox source-level options
*
* Prefixes: `OPT__`
* Prefix: `OPT__`
*
* This file is meant to be globally included on the command line.
*/
@ -18,53 +18,30 @@
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// firmware/main
// ----------------------------------------------------------------------------
#define OPT__DEBOUNCE_TIME 5
/** macros/OPT__DEBOUNCE_TIME/description
* in milliseconds; 5ms should be good for cherry mx switches (per the
* keyswitch spec)
*/
// ----------------------------------------------------------------------------
// firmware/keyboard/controller
// ----------------------------------------------------------------------------
// --- if the diode cathode is towards the square solder pad
#define OPT__TEENSY__DRIVE_ROWS 0
#define OPT__TEENSY__DRIVE_COLUMNS 1
#define OPT__MCP23018__DRIVE_ROWS 0
#define OPT__MCP23018__DRIVE_COLUMNS 1
/** macros/(group) pin drive direction/description
* Select which set of pins will drive (alternate between hi-Z and drive low)
* and which will be inputs (hi-Z)
*
* Members:
* - `OPT__TEENSY__DRIVE_ROWS`
* - `OPT__TEENSY__DRIVE_COLUMNS`
* - `OPT__MCP23018__DRIVE_ROWS`
* - `OPT__MCP23018__DRIVE_COLUMNS`
*
*
* Notes:
*
* - You must set exactly one of each 'TEENSY' variable, and one of each
* 'MCP23018' variable, to '1', and the other must be set to '0'
*
* - If you are using internal diodes (inside the key switches), set
* OPT__TEENSY__DRIVE_COLUMNS := 1
* OPT__MCP23018__DRIVE_ROWS := 1
*
* - If the diode cathode is towards the square solder pad, set
* OPT__TEENSY__DRIVE_COLUMNS := 1
* OPT__MCP23018__DRIVE_COLUMNS := 1
*
* - If the diode cathode is towards the circular solder pad, set
* OPT__TEENSY__DRIVE_ROWS := 1
* OPT__MCP23018__DRIVE_ROWS := 1
*/
// ............................................................................
// --- if the diode cathode is towards the circular solder pad
// #define OPT__TEENSY__DRIVE_ROWS 1
// #define OPT__TEENSY__DRIVE_COLUMNS 0
// #define OPT__MCP23018__DRIVE_ROWS 1
// #define OPT__MCP23018__DRIVE_COLUMNS 0
// ............................................................................
// --- if you are using internal diodes (inside the key switches)
// #define OPT__TEENSY__DRIVE_ROWS 0
// #define OPT__TEENSY__DRIVE_COLUMNS 1
// #define OPT__MCP23018__DRIVE_ROWS 1
// #define OPT__MCP23018__DRIVE_COLUMNS 0
// ............................................................................
// ............................................................................
// pin drive direction
// ----------------------------------------------------------------------------
@ -72,19 +49,26 @@
// ----------------------------------------------------------------------------
#define OPT__LED_BRIGHTNESS 0.5
/** macros/MAKE__LED_BRIGHTNESS/description
* a multiplier, with 1 being the max
*/
// a multiplier, with '1' being max
// ----------------------------------------------------------------------------
// firmware/main
// ----------------------------------------------------------------------------
#define OPT__DEBOUNCE_TIME 5
// in milliseconds
#include "../../../firmware/main/options.h"
// ----------------------------------------------------------------------------
// firmware/lib/twi
// ----------------------------------------------------------------------------
#define OPT__TWI_FREQENCY 400000
/** macros/OPT__TWI__FREQENCY/description
* in Hz; max value is 400000 (400kHz) (Teensy datasheet sec 20.1)
*/
#define OPT__TWI__FREQENCY 400000
#include "../../../firmware/lib/twi/options.h"
// ----------------------------------------------------------------------------
@ -95,15 +79,8 @@
#define OPT__USB__STR_PRODUCT L"ErgoDox ergonomic keyboard"
#define OPT__USB__VENDOR_ID 0x1d50 // Openmoko, Inc.
#define OPT__USB__PRODUCT_ID 0x6028 // ErgoDox ergonomic keyboard
/** macros/(group) USB/description
* USB identifier information
*
* Members:
* - `OPT__USB__STR_MANUFACTURER`
* - `OPT__USB__STR_PRODUCT`
* - `OPT__USB__VENDOR_ID`
* - `OPT__USB__PRODUCT_ID`
*/
#include "../../../firmware/lib/usb/keyboard/options.h"
// ----------------------------------------------------------------------------

View File

@ -9,12 +9,21 @@
#
# TODO: include the other 'options.mk' files that we need to
BINARY_FORMAT := ihex
# the binary format to generate
MCU := atmega32u4
# processor type (for the teensy 2.0)
F_CPU := 16000000
# processor speed, in Hz; max value is 16000000 (16MHz)
KEYBOARD_LAYOUT := qwerty-kinesis-mod
# default layout for this keyboard
KEYBOARD_LAYOUTS := \
colemak-symbol-mod \
dvorak-kinesis-mod \
@ -27,3 +36,5 @@ SCR += $(wildcard *.c)
SRC += $(wildcard controller/*.c)
SRC += $(wildcard layout/$(KEYBOARD_LAYOUT)*.c)
CFLAGS += -include $(wildcard options.h)

37
firmware/lib/twi.h Normal file
View File

@ -0,0 +1,37 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2012, 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* The TWI (aka I&sup2;C) interface
*
* Prefix: `twi__`
*
* Functions are named after the basic TWI actions; see general documentation
* on TWI for more information.
*/
#ifndef ERGODOX_FIRMWARE__FIRMWARE__LIB__TWI__H
#define ERGODOX_FIRMWARE__FIRMWARE__LIB__TWI__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#include <stdint.h>
// ----------------------------------------------------------------------------
void twi__init (void);
uint8_t twi__start (void);
void twi__stop (void);
uint8_t twi__send (uint8_t data);
uint8_t twi__read (uint8_t * data);
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__LIB__TWI__H

View File

@ -0,0 +1,104 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2012, 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Very simple implementation for the Teensy 2.0 (ATmega32U4)
*
* - This is mostly straight from the datasheet, section 20.6.6, figure 20-11
* (the code example in C), and section 20.8.1, figure 20-12
* - Also see the documentation for `<util/twi.h>` at
* <http://www.nongnu.org/avr-libc/user-manual/group__util__twi.html#ga8d3aca0acc182f459a51797321728168>
*
* Some other (more complete) TWI libraries for the Teensy 2.0 (and other Atmel
* processors):
* - [i2cmaster] (http://homepage.hispeed.ch/peterfleury/i2cmaster.zip)
* - written by [peter-fleury] (http://homepage.hispeed.ch/peterfleury/)
* - [the arduino twi library]
* (https://github.com/arduino/Arduino/tree/master/libraries/Wire/utility)
* - look for an older version if you need one that doesn't depend on all
* the other Arduino stuff
*/
#include <util/twi.h>
// ----------------------------------------------------------------------------
#ifndef OPT__TWI__FREQUENCY
#error "OPT__TWI__FREQUENCY not defined"
#endif
/** macros/OPT__TWI__FREQUENCY/description
* The TWI Frequency, in Hz.
*
* Notes:
* - The max speed for the ATmega32U4 is 400kHz (datasheet sec. 20.1)
* - The max speed for the MCP23017 is 1.7MHz (datasheet pg. 1)
* - The max speed for the MCP23018 is 3.4MHz (datasheet pg. 1)
*/
// ----------------------------------------------------------------------------
void twi_init(void) {
// set the prescaler value to 0
TWSR &= ~( (1<<TWPS1)|(1<<TWPS0) );
// set the bit rate
// - TWBR should be 10 or higher (datasheet section 20.5.2)
TWBR = ((F_CPU / OPT__TWI__FREQUENCY) - 16) / 2;
}
uint8_t twi_start(void) {
// send start
TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTA);
// wait for transmission to complete
while (!(TWCR & (1<<TWINT)));
// if it didn't work, return the status code (else return 0)
if ( (TW_STATUS != TW_START) &&
(TW_STATUS != TW_REP_START) )
return TW_STATUS; // error
return 0; // success
}
void twi_stop(void) {
// send stop
TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWSTO);
// wait for transmission to complete
while (TWCR & (1<<TWSTO));
}
uint8_t twi_send(uint8_t data) {
// load data into the data register
TWDR = data;
// send data
TWCR = (1<<TWINT)|(1<<TWEN);
// wait for transmission to complete
while (!(TWCR & (1<<TWINT)));
// if it didn't work, return the status code (else return 0)
if ( (TW_STATUS != TW_MT_SLA_ACK) &&
(TW_STATUS != TW_MT_DATA_ACK) &&
(TW_STATUS != TW_MR_SLA_ACK) )
return TW_STATUS; // error
return 0; // success
}
uint8_t twi_read(uint8_t * data) {
// read 1 byte to TWDR, send ACK
TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);
// wait for transmission to complete
while (!(TWCR & (1<<TWINT)));
// set data variable
*data = TWDR;
// if it didn't work, return the status code (else return 0)
if (TW_STATUS != TW_MR_DATA_ACK)
return TW_STATUS; // error
return 0; // success
}
// ----------------------------------------------------------------------------
#endif
// ----------------------------------------------------------------------------

View File

@ -0,0 +1,28 @@
## I&sup2;C Status Codes (for Master modes)
### Master Transmitter (datasheet section 20.8.1, table 20-3)
* `0x08` A START condition has been transmitted
* `0x10` A repeated START condition has been transmitted
* `0x18` SLA+W has been transmitted; ACK has been received
* `0x20` SLA+W has been transmitted; NOT ACK has been received
* `0x28` Data byte has been transmitted; ACK has been received
* `0x30` Data byte has been transmitted; NOT ACK has been received
* `0x38` Arbitration lost in SLA+W or data bytes
### Master Receiver (datasheet section 20.8.2, table 20-4)
* `0x08` A START condition has been transmitted
* `0x10` A repeated START condition has been transmitted
* `0x38` Arbitration lost in SLA+R or NOT ACK bit
* `0x40` SLA+R has been transmitted; ACK has been received
* `0x48` SLA+R has been transmitted; NOT ACK has been received
* `0x50` Data byte has been received; ACK has been returned
* `0x58` Data byte has been received; NOT ACK has been returned
-------------------------------------------------------------------------------
Copyright &copy; 2012 Ben Blazak <benblazak.dev@gmail.com>
Released under The MIT License (MIT) (see "license.md")
Project located at <https://github.com/benblazak/ergodox-firmware>

View File

@ -0,0 +1,30 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* TWI options
*
* Prefix: `OPT__`
*
* This file is meant to be included by the using '.../options.h'
*/
#ifndef ERGODOX_FIRMWARE__FIRMWARE__LIB__TWI__OPTIONS__H
#define ERGODOX_FIRMWARE__FIRMWARE__LIB__TWI__OPTIONS__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#ifndef OPT__TWI__FREQUENCY
#error "OPT__TWI__FREQUENCY not defined"
#endif
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__LIB__TWI__OPTIONS__H

View File

@ -0,0 +1,15 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
# Released under The MIT License (see "doc/license.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------
## description
# TWI options
#
# This file is meant to be included by the using '.../options.mk'
#
SRC += $(wildcard $(MCU).c

View File

@ -22,6 +22,10 @@
* THE SOFTWARE.
* ------------------------------------------------------------------------- */
// Version 1.0: Initial Release
// Version 1.1: Add support for Teensy 2.0
/** description
* Implements the USB interface
*
@ -32,8 +36,32 @@
*/
// Version 1.0: Initial Release
// Version 1.1: Add support for Teensy 2.0
// ----------------------------------------------------------------------------
#ifndef OPT__USB__STR_MANUFACTURER
#error "OPT__USB__STR_MANUFACTURER not defined"
#endif
#ifndef OPT__USB__STR_PRODUCT
#error "OPT__USB__STR_PRODUCT not defined"
#endif
#ifndef OPT__USB__VENDOR_ID
#error "OPT__USB__VENDOR_ID not defined"
#endif
#ifndef OPT__USB__PRODUCT_ID
#error "OPT__USB__PRODUCT_ID not defined"
#endif
/** macros/(group) USB/description
* USB identifier information
*
* Members:
* - `OPT__USB__STR_MANUFACTURER`
* - `OPT__USB__STR_PRODUCT`
* - `OPT__USB__VENDOR_ID`
* - `OPT__USB__PRODUCT_ID`
*/
// ----------------------------------------------------------------------------
#define USB_SERIAL_PRIVATE_INCLUDE
#include "usb_keyboard.h"

View File

@ -3,7 +3,7 @@
* ------------------------------------------------------------------------- */
/** description
* The USB interface
* The PJRC USB interface
*
* Prefix: `usb__`
*

View File

@ -0,0 +1,39 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* USB keyboard options
*
* Prefix: `OPT__`
*
* This file is meant to be included by the using '.../options.h'
*/
#ifndef ERGODOX_FIRMWARE__FIRMWARE__LIB__USB__KEYBOARD__OPTIONS__H
#define ERGODOX_FIRMWARE__FIRMWARE__LIB__USB__KEYBOARD__OPTIONS__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#ifndef OPT__USB__STR_MANUFACTURER
#error "OPT__USB__STR_MANUFACTURER not defined"
#endif
#ifndef OPT__USB__STR_PRODUCT
#error "OPT__USB__STR_PRODUCT not defined"
#endif
#ifndef OPT__USB__VENDOR_ID
#error "OPT__USB__VENDOR_ID not defined"
#endif
#ifndef OPT__USB__PRODUCT_ID
#error "OPT__USB__PRODUCT_ID not defined"
#endif
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__LIB__USB__KEYBOARD__OPTIONS__H

View File

@ -0,0 +1,15 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
# Released under The MIT License (see "doc/license.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------
## description
# USB keyboard options
#
# This file is meant to be included by the using '.../options.mk'
#
SRC += $(wildcard from-pjrc/*.c)

View File

@ -270,7 +270,7 @@
#define KEY__RightAlt 0xE6 // √ √ √ 101/104
#define KEY__RightGUI 0xE7 // √ √ √ 104
// (Reserved) 0xE8..0xFFFF // - - - -
// (Reserved) 0xE8..0xFFFF // - - - -
// ----------------------------------------------------------------------------

37
firmware/main/options.h Normal file
View File

@ -0,0 +1,37 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/license.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* `main()` options
*
* Prefix: `OPT__`
*
* This file is meant to be included by the using '.../options.h'
*/
#ifndef ERGODOX_FIRMWARE__FIRMWARE__MAIN__OPTIONS__H
#define ERGODOX_FIRMWARE__FIRMWARE__MAIN__OPTIONS__H
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#ifndef OPT__DEBOUNCE_TIME
#error "OPT__DEBOUNCE_TIME not defined"
#endif
/** macros/OPT__DEBOUNCE_TIME/description
* The minimum amount of time to wait between two scans of a key, in
* milliseconds
*
* Notes:
* - Cherry MX bounce time <= 5ms (at 16 in/sec actuation speed) (spec)
*/
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
#endif // ERGODOX_FIRMWARE__FIRMWARE__MAIN__OPTIONS__H

16
firmware/main/options.mk Normal file
View File

@ -0,0 +1,16 @@
# -----------------------------------------------------------------------------
# Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
# Released under The MIT License (see "doc/license.md")
# Project located at <https://github.com/benblazak/ergodox-firmware>
# -----------------------------------------------------------------------------
## description
# `main()` options
#
# This file is meant to be included by the using '.../options.mk'
#
SRC += $(wildcard ../main.c)
SRC += $(wildcard main/*.c)