still working...

- removed the comment about the RESET pin on the MCP23018: i think these
  chips reset on powerup
- the partitioning of code into files is all wrong at the moment... i
  need to write some more and then fix that
partial-rewrite
Ben Blazak 2012-03-15 01:01:36 -07:00
parent 4bcc0e5dc3
commit 6fb3bf7a57
7 changed files with 179 additions and 39 deletions

View File

@ -1,12 +1,20 @@
## Noob Electronics Stuff
* [Resistor Color Codes (picture)]
* [Resistor Color Codes]
(http://www.ladyada.net/wiki/lib/exe/fetch.php?hash=a2c6a9&w=501&h=785&media=http%3A%2F%2Fwww.ladyada.net%2Fimages%2Fmetertutorial%2Frescolorcode.jpg)
: image
* from [the Multimeter Tutorial]
(http://www.ladyada.net/learn/multimeter/resistance.html)
(on <http://ladyada.net/>)
* [Schematic Symbols]
(http://img.docstoccdn.com/thumb/orig/28066054.png)
: image
* [Vcc, Vdd, Vss, etc.]
(http://encyclobeamia.solarbotics.net/articles/vxx.html)
* [Very Basic Circuits]
(http://www.seattlerobotics.org/encoder/mar97/basics.html)
: column by Kevin Ross for Encoder
@ -23,8 +31,8 @@
-> [powering LEDs]
(http://wolfstone.halloweenhost.com/Lighting/litlpo_PoweringLEDs.html)
* [Vcc, Vdd, Vss, etc.]
(http://encyclobeamia.solarbotics.net/articles/vxx.html)
* [All About Circuits : Reference]
(http://www.allaboutcircuits.com/vol_5/index.html)
## Noob C Stuff

View File

@ -7,8 +7,8 @@
* ------------------------------------------------------------------------- */
#include "keyboard/ergodox.h"
#include "controller/teensy-2-0.h"
#include "hardware/ergodox.h"
#include "lib/twi.h"
#include "lib/print.h"
@ -18,5 +18,9 @@ void main() {
}
void init() {
controller_init(); // must be first
kb_init(); // must be second
// TODO: other stuff?
}

View File

@ -1,11 +1,17 @@
/* ----------------------------------------------------------------------------
* ergoDOX specific stuff
* ergoDOX keyboard specific stuff
* - public things are prefixed by `kb_` or `KB_`
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak
* Released under The MIT License (MIT) (see "license.md") at
* <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
// ----------------------------------------------------------------------------
// documentation
// ----------------------------------------------------------------------------
/* ----------------------------------------------------------------------------
* Matrix [row.column] assignments
* - row and column numbers are in hex
@ -27,12 +33,21 @@
* ------------------------------------------------------------------------- */
#define KB_LAYERS 1
#define KB_ROWS 12 // don't change
#define KB_COLUMNS 7 // don't change
#include "ergodox.h"
uint8_t is_pressed[KB_ROWS][KB_COLUMNS] = {
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// TODO
// ----------------------------------------------------------------------------
// variables
// ----------------------------------------------------------------------------
uint8_t kb_is_pressed[KB_ROWS][KB_COLUMNS] = {
// --- right hand ---
// column 0 1 2 3 4 5 6
0, 0, 0, 0, 0, 0, 0, //row 0x0
@ -41,7 +56,6 @@ uint8_t is_pressed[KB_ROWS][KB_COLUMNS] = {
0, 0, 0, 0, 0, 0, 0, //row 0x3
0, 0, 0, 0, 0, 0, 0, //row 0x4
0, 0, 0, 0, 0, 0, 0, //row 0x5
// --- left hand ---
// column 0 1 2 3 4 5 6
0, 0, 0, 0, 0, 0, 0, //row 0x6
@ -54,7 +68,8 @@ uint8_t is_pressed[KB_ROWS][KB_COLUMNS] = {
// TODO: this belongs in program space
uint8_t kb_maps[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
// --- layer: default ---
// ------- layer: default -------
// --- right hand ---
// column 0 1 2 3 4 5 6
0, 0, 0, 0, 0, 0, 0, //row 0x0
0, 0, 0, 0, 0, 0, 0, //row 0x1
@ -62,6 +77,8 @@ uint8_t kb_maps[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
0, 0, 0, 0, 0, 0, 0, //row 0x3
0, 0, 0, 0, 0, 0, 0, //row 0x4
0, 0, 0, 0, 0, 0, 0, //row 0x5
// --- left hand ---
// column 0 1 2 3 4 5 6
0, 0, 0, 0, 0, 0, 0, //row 0x6
0, 0, 0, 0, 0, 0, 0, //row 0x7
0, 0, 0, 0, 0, 0, 0, //row 0x8
@ -70,3 +87,16 @@ uint8_t kb_maps[KB_LAYERS][KB_ROWS][KB_COLUMNS] = {
0, 0, 0, 0, 0, 0, 0, //row 0xB
}
// ----------------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------------
// TODO
void kb_init() {
}
// TODO
// - cycle through row=HIGH and read each column
void kb_update() {
}

View File

@ -1,11 +1,17 @@
/* ----------------------------------------------------------------------------
* Teensy 2.0 specific stuff
* ergodox controller (Teensy 2.0 and MCP23018) specific stuff
* - public things are prefixed by `controller_` or `CONTROLLER_`
* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak
* Released under The MIT License (MIT) (see "license.md") at
* <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
// ----------------------------------------------------------------------------
// documentation
// ----------------------------------------------------------------------------
/* ----------------------------------------------------------------------------
* Pinouts and Pin assignments
* - '+' indicates pin
@ -51,12 +57,12 @@
* Teensy 2.0 Pin Assignments
* ==========================
* power_negative GND +---.....---+ Vcc power_positive
* column6 PB0 + + PF0 row0
* o + PF1 row1
* o + PF4 row2
* o o o + PF5 row3
* LED3 OC1C + + PF6 row4
* I2C SCL + + PF7 row5
* column6 PB0 + + PF0 row6
* o + PF1 row7
* o + PF4 row8
* o o o + PF5 row9
* LED3 OC1C + + PF6 rowA
* I2C SCL + + PF7 rowB
* I2C SDA + + OC1B LED2
* column3 PD2 + + OC1A LED1
* column4 PD3 + + PB4 column0
@ -68,31 +74,28 @@
* power_negative Vss(GND) +01---.---28o
* o02 27o
* column0 GPB0 +03 26o
* column1 GPB1 +04 25+ GPA5 row5
* column2 GPB2 +05 24+ GPA4 row4
* column3 GPB3 +06 23+ GPA3 row3
* column4 GPB4 +07 22+ GPA2 row2
* column5 GPB5 +08 21+ GPA1 row1
* column6 GPB6 +09 20+ GPA0 row0
* column1 GPB1 +04 25+ GPA5 rowB
* column2 GPB2 +05 24+ GPA4 rowA
* column3 GPB3 +06 23+ GPA3 row9
* column4 GPB4 +07 22+ GPA2 row8
* column5 GPB5 +08 21+ GPA1 row7
* column6 GPB6 +09 20+ GPA0 row6
* o10 19o
* power_positive Vdd(Vcc) +11 18o
* I2C SCL +12 17o
* I2C SDA +13 16+ RESET (see note)
* I2C SDA +13 16o
* o14-------15+ ADDR (see note)
*
* notes:
* - ADDR (pin15): Set to 0b000 via
* Vdd(Vcc) -- R1 -- V2 (on ADDR) -- R2 -- Vss(GND)
* where
* Vdd = +5V
* R1 = ?TODO:\
* V2 = ?TODO: | (see mcp23018 datasheet, pg 11)
* R2 = ?TODO:/
* - RESET (pin16): Not used by software. Might want to have it available
* somewhere physically just in case though?
* - ADDR (pin15): Set slave address to 0b0100000 by connecting to Vss(GND)
* - note: The user-defined bits are the three least significant
* ------------------------------------------------------------------------- */
// ----------------------------------------------------------------------------
// macros
// ----------------------------------------------------------------------------
// processor frequency (from <http://www.pjrc.com/teensy/prescaler.html>)
#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
#define CPU_16MHz 0x00
@ -105,12 +108,89 @@
#define CPU_125kHz 0x07
#define CPU_62kHz 0x08
// pins
// TODO: write some pretty macros
// teensy pins
// TODO
// I2C SCL PD0
// I2C SDA PD1
// LED1 OC1A PB5
// LED2 OC1B PB6
// LED3 OC1C PB7
// COLUMN_0_RH PB4
// COLUMN_1_RH PC6
// COLUMN_2_RH PC7
// COLUMN_3_RH PD2
// COLUMN_4_RH PD3
// COLUMN_5_RH PD7
// COLUMN_6_RH PB0
// ROW_0 PF0
// ROW_1 PF1
// ROW_2 PF4
// ROW_3 PF5
// ROW_4 PF6
// ROW_5 PF7
// TODO:
// - initialize pins
// mcp23018 pins
// TODO
// I2C SCL
// I2C SDA
// COLUMN_0_LH GPB0
// COLUMN_1_LH GPB1
// COLUMN_2_LH GPB2
// COLUMN_3_LH GPB3
// COLUMN_4_LH GPB4
// COLUMN_5_LH GPB5
// COLUMN_6_LH GPB6
// ROW_6 GPA0
// ROW_7 GPA1
// ROW_8 GPA2
// ROW_9 GPA3
// ROW_A GPA4
// ROW_B GPA5
// pins logically common to both
// TODO
// (i don't think we're going to use these this way...)
// COLUMN_0 GPB0
// COLUMN_0 PB4
// COLUMN_1 GPB1
// COLUMN_1 PC6
// COLUMN_2 GPB2
// COLUMN_2 PC7
// COLUMN_3 GPB3
// COLUMN_3 PD2
// COLUMN_4 GPB4
// COLUMN_4 PD3
// COLUMN_5 GPB5
// COLUMN_5 PD7
// COLUMN_6 GPB6
// COLUMN_6 PB0
// ----------------------------------------------------------------------------
// functions
// ----------------------------------------------------------------------------
// TODO
// - set internal brown-out detection circuit?
void controller_init() {
// teensy
// --- processor frequency
CPU_PRESCALE(CPU_16MHz); // speed should match F_CPU in makefile
// --- pins
// --- --- unused: set as input with internal pullup enabled (see
// teensy 2.0 datasheet section 10.2.6)
DDRB &= ~0b00001110; // set B(1,2,3) as input
PORTB |= 0b00001110; // set B(1,2,3) internal pullup enabled
DDRD &= ~0b01110000; // set D(4,5,6) as input
PORTD |= 0b01110000; // set D(4,5,6) internal pullup enabled
DDRE &= ~0b01000000; // set E(6) as input
PORTE |= 0b01000000; // set E(6) internal pullup enabled
// --- --- [used]
// TODO
// mcp32018
// TODO
}

18
src/hardware/ergodox.h Normal file
View File

@ -0,0 +1,18 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2012 Ben Blazak
* Released under The MIT License (MIT) (see "license.md") at
* <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
#define KB_LAYERS 1
#define KB_ROWS 12 // must match real life
#define KB_COLUMNS 7 // must match real life
void controller_init();
void kb_init();
// TODO

View File