@@ -160,12 +160,14 @@ Following the style guide makes it easier for the next programmer to understand | |||
<!-- http://stackoverflow.com/questions/2198241/best-practice-for-c-function-commenting --> | |||
## Trace of keybrd scan | |||
Arduino does not have a debugger; so here is a list of functions in the order that they are called. | |||
Arduino does not have a debugger. | |||
So here is the next best thing; a list of functions in the order that they are called. | |||
Refer to it like a table of contents while reading the keybrd library. | |||
``` | |||
Matrix::scan() for each row | |||
Row::process() | |||
Row::wait() | |||
Row::scan() | |||
RowPort_*::setActivePin*() strobe row on | |||
for each col port | |||
@@ -177,6 +179,9 @@ Refer to it like a table of contents while reading the keybrd library. | |||
set rowState bit | |||
Row::debounce() debounce | |||
Row::pressRelease() for each key in row | |||
if falling edge | |||
Key_*::release() scanCode->release() | |||
Code_*::release() Keyboard.release(scancode) | |||
if rising edge | |||
Key_*::press() scanCode->press() | |||
Code_*::press() Keyboard.press(scancode) |
@@ -7,5 +7,7 @@ uint8_t ColPort::getColPins() | |||
uint8_t ColPort::getPortState() | |||
{ | |||
//todo Keyboard.print(" portState="); | |||
//Keyboard.print(portState); | |||
return portState; | |||
} |
@@ -20,6 +20,7 @@ extern unsigned int __heap_start; | |||
extern void *__brkval; | |||
//measure and return amount of free SRAM | |||
/* | |||
uint16_t getFreeSRAM() | |||
{ | |||
uint8_t newVariable; | |||
@@ -34,3 +35,19 @@ uint16_t getFreeSRAM() | |||
return (((uint16_t)&newVariable) - ((uint16_t)__brkval)); | |||
} | |||
}; | |||
*/ | |||
// uint32_t for Teensy LC | |||
uint32_t getFreeSRAM() | |||
{ | |||
uint8_t newVariable; | |||
// if heap is empty, use bss as start memory address | |||
if ((uint32_t)__brkval == 0) | |||
{ | |||
return (((uint32_t)&newVariable) - ((uint32_t)&__bss_end)); | |||
} | |||
// else use heap end as the start of the memory address | |||
else | |||
{ | |||
return (((uint32_t)&newVariable) - ((uint32_t)__brkval)); | |||
} | |||
}; |
@@ -24,7 +24,6 @@ keybrd runs at the end of this sketch, under the "MAIN" heading. | |||
// ################## GLOBAL ################### | |||
// ================= INCLUDES ================== | |||
/* | |||
The compiler copies #included files into the sketch. | |||
All the includes in this sketch are to keybrd library classes. | |||
*/ | |||
//Ports |
@@ -49,17 +49,24 @@ Switch-diode pairs connect rows to columns. | |||
The green rectangle on the right is the Teensy 2.0 microcontroller. | |||
The matrix rows and columns connect to the microcontroller via jumper wires. | |||
Tutorials 4,5,9 will add more components to the breadboard. | |||
Positioning components as shown on the picture will provide space for those components, with room for up to 9 cols. | |||
Breadboard terminal strips are indexed 1 to 63 for accurate positioning of components. | |||
[pic of IOE, LEDs, active high on one bb] | |||
Breadboard keyboard assembly instructions: | |||
1. Cut leads to length. | |||
* tactile-switch-lead length 6 to 8 mm | |||
* diodes 22 to 24 mm total end-to-end length, and save the cut offs for steps 2 and 3 | |||
2. Insert parts into the breadboard as shown in the picture. | |||
* Teensy LC on the terminal strip labeled 1 | |||
* switch leads oriented so that they will connect diodes to columns | |||
* diode cut offs connect terminal strips into columns | |||
* diodes are orient with cathode (banded end) towards the row (power strip) | |||
* switches connect diode to columns | |||
3. Insert jumper wires connecting Teensy2 to the matrix rows and columns. | |||
* follow pin connections table (below) and consult pinout diagram in | |||
[close-up pic shows switch way half out, to show lead orientation] | |||
[Teensy2_pinout.txt](../doc/Teensy2_pinout.txt) | |||
todo add a schematic |
@@ -1,12 +1,13 @@ | |||
Tutorial 2 - single-layer keyboard | |||
======================================= | |||
[keybrd_2_single-layer_annotated.ino](keybrd_2_single-layer_annotated/keybrd_2_single-layer_annotated.ino) explains how a keybrd sketch works. | |||
You can view the class definitions in the [keybrd library](../src/). | |||
The easiest way to learn the keyboard library is to read some simple sketches. | |||
[keybrd_2_single-layer_annotated.ino](keybrd_2_single-layer_annotated/keybrd_2_single-layer_annotated.ino) is a simple sketch with annotations that explain how a keybrd sketch works. | |||
After reading the sketch you will be able to modify it to suite your own single-layer keyboard design. | |||
You can view the class definitions in the [keybrd library](../src/). | |||
## Exercises | |||
1) Add a third column to the breadboard and sketch. | |||
1) Add a third column to the breadboard keyboard and sketch. | |||
| Layout | **0** | **1** | **2** | | |||
|:------:|-------|-------|-------| |