Browse Source

rename #define SAMPLE_COUNT_MACRO to const SAMPLE_COUNT

tags/v0.6.6
wolfv6 7 years ago
parent
commit
04f395f499

+ 2
- 2
doc/PLANNED_FEATURES.md View File

@@ -3,11 +3,11 @@ planned_features is a view of where the keybrd project is headed.
Top priority
------------
* Add matrix-to-layout mapping (to decouple key matrix from layout)
* Add breadboard keyboard schematics to tutorials
Medium priority
---------------
* Getting user feedback
* Add breadboard keyboard schematics to tutorials
Low priority
------------
* Getting user feedback

+ 0
- 1
doc/keybrd_library_developer_guide.md View File

@@ -171,7 +171,6 @@ Following the style guide makes it easier for the next programmer to understand
* Member names use camelCase starting with lowercase letter.
* Use constants rather than macros, except for header guards.
* Global const names and static const names use ALL_CAPS_WITH_UNDERSCORE.
* Macros use ALL_CAPS_WITH_UNDERSCORE and have _MACRO suffix e.g. SAMPLE_COUNT_MACRO
* Header guards have _H suffix e.g. #ifndef FILE_NAME_H
* Pointer names are prefixed with "ptr" e.g. ptrRow = &row;
* Arrays names use the plural of the element name e.g. Row* const = ptrsRows { &row0, &row1 };

+ 1
- 1
library.properties View File

@@ -1,5 +1,5 @@
name=keybrd
version=0.6.3
version=0.6.5
author=Wolfram Volpi
maintainer=Wolfram Volpi
sentence=A library for creating custom-keyboard firmware.

+ 9
- 10
src/Debouncer_Samples.cpp View File

@@ -12,22 +12,21 @@ This class was tested on split keyboard with a 3-meter long telephone wire to I/
Dr. Marty's debounce algorithm:
Periodically read samples and update the state when a number consecutive sample bits are equal.

Output from keybrd/examples/debounce_unit_test.cpp with SAMPLE_COUNT_MACRO 4:
Output from keybrd/examples/debounce_unit_test.cpp with SAMPLE_COUNT 4:
button pressed: 100000001111111110000
bouncy signal: 100001001111011110000
debounced signal: 000000000001111111110
isFallingEdge: 000000000000000000001
isRisingEdge: 000000000001000000000
There is a latency equal to SAMPLE_COUNT_MACRO, between button press and debounced signal.
There is a latency equal to SAMPLE_COUNT, between button press and debounced signal.

samples[SAMPLE_COUNT_MACRO] is a ring buffer. samplesIndex is it's current write index.
SAMPLE_COUNT_MACRO is the number of consecutive equal samples needed to debounce.
SAMPLE_COUNT_MACRO is a macro because it defines samples[SAMPLE_COUNT_MACRO] array size at compile time.
SAMPLE_COUNT_MACRO is defined in config_keybrd.h and should be at lease 1.
samples[SAMPLE_COUNT] is a ring buffer. samplesIndex is it's current write index.
SAMPLE_COUNT is the number of consecutive equal samples needed to debounce.
SAMPLE_COUNT is defined in config_keybrd.h and should be at lease 1.

SAMPLE_COUNT_MACRO = 4 is very reliable for a keyboard.
SAMPLE_COUNT = 4 is very reliable for a keyboard.
Split keyboards with a long connecting wire or in environment with
strong electromagnetic interference (EMI) may need a larger SAMPLE_COUNT_MACRO for reliability.
strong electromagnetic interference (EMI) may need a larger SAMPLE_COUNT for reliability.
*/
#include "Debouncer_Samples.h"

@@ -44,12 +43,12 @@ read_pins_t Debouncer_Samples::debounce(const read_pins_t rawSignal, read_pins_t

samples[samplesIndex] = rawSignal; //insert rawSignal into samples[] ring buffer

if (++samplesIndex >= SAMPLE_COUNT_MACRO) //if end of ring buffer
if (++samplesIndex >= SAMPLE_COUNT) //if end of ring buffer
{
samplesIndex = 0; //wrap samplesIndex to beginning of ring buffer
}

for (uint8_t j = 0; j < SAMPLE_COUNT_MACRO; j++) //traverse the sample[] ring buffer
for (uint8_t j = 0; j < SAMPLE_COUNT; j++) //traverse the sample[] ring buffer
{
all_1 &= samples[j]; //1 if all samples are 1
all_0 |= samples[j]; //0 if all samples are 0

+ 2
- 2
src/Debouncer_Samples.h View File

@@ -7,12 +7,12 @@
#include <DebouncerInterface.h>

/* Debouncer_Samples
Configuration: #define SAMPLE_COUNT_MACRO in config_keybrd.h
Configuration: SAMPLE_COUNT is defined in config_keybrd.h
*/
class Debouncer_Samples : public DebouncerInterface
{
private:
read_pins_t samples[SAMPLE_COUNT_MACRO]; //bits, one bit per key, most recent readings
read_pins_t samples[SAMPLE_COUNT]; //bits, one bit per key, most recent readings
uint8_t samplesIndex; //samples[] current write index
public:
Debouncer_Samples(): samplesIndex(0) {}

+ 2
- 2
src/ScanDelay.h View File

@@ -8,14 +8,14 @@
DELAY_MICROSECONDS explained
----------------------------
A keyboard with a faster scan rate responds faster.
Follow these step to tune DELAY_MICROSECONDS for maximum scan rate for a given SAMPLE_COUNT_MACRO:
Follow these step to tune DELAY_MICROSECONDS for maximum scan rate for a given SAMPLE_COUNT:
Intantiate DELAY_MICROSECONDS in your sketch:
ScanDelay scanDelay(1000);
Add this to the sketch's loop() function:
debug.printMicrosecondsPerScan();
Compile and load the sketch into the microcontroller; microseconds_per_scan is printed every second.
Adjust the value of DELAY_MICROSECONDS and repeat until:
debug.printMicrosecondsPerScan() <= DEBOUNCE_TIME / SAMPLE_COUNT_MACRO
debug.printMicrosecondsPerScan() <= DEBOUNCE_TIME / SAMPLE_COUNT

DEBOUNCE_TIME can be obtained from the switch's datasheet. Some switch bounce times are:
Cherry MX specifies 5msec bounce time http://www.cherrycorp.com/english/switches/key/mx.htm

+ 13
- 7
src/config_keybrd.h View File

@@ -2,7 +2,12 @@
#define CONFIG_KEYBRD_H
#include <inttypes.h>

/* The maximum number of pins scanned by RowScanner depends on size of read_pins_t.
/* This config_keybrd.h file is included by several keybrd library files.
If you change any values in this file, copy the entire library into your sketch folder,
and use double quotes to include the files in your sketch.
That way libary updates don't overwrite your changes.
The maximum number of pins scanned by RowScanner depends on size of read_pins_t.
By default, read_pins_t is set to uint32_t.
If your 8-bit AVR (Teensy 2) is running low on memory, using a smaller type saves SRAM.
Using smaller types on a 32-bit uC (Teensy LC) would accomplish nothing.
@@ -10,25 +15,26 @@ Using smaller types on a 32-bit uC (Teensy LC) would accomplish nothing.
read_pins_t is used in:
Row bit patterns
ScannerInterface::scan()
Scanner_ShiftRegsPISO::scan()
Scanner_ShiftRegsRead::scan()
Scanner_ShiftRegsReadStrobed::scan()
Scanner_uC::scan()
DebouncerInterface::debounce()
Debouncer_Samples::debounce()

Use a read_pins_t size that covers all read pins of all Scanner objects i.e.
For Scanner_uC: read_pins_t bits >= Scanner_uC::readPinCount
For Scanner_ShiftRegsPISO: read_pins_t bits >= Scanner_ShiftRegsPISO::byte_count * 8
For Scanner_ShiftRegsRead: read_pins_t bits >= Scanner_ShiftRegsRead::byte_count * 8
(For Scanner_IOE: I/O expanders are assumed to have 8 bits per port or less)
*/
//typedef uint8_t read_pins_t;
//typedef uint16_t read_pins_t;
typedef uint32_t read_pins_t;

/* SAMPLE_COUNT_MACRO is used in Debouncer_Samples.h
SAMPLE_COUNT_MACRO = 4 is very reliable for a keyboard.
/* SAMPLE_COUNT is used in Debouncer_Samples.h
SAMPLE_COUNT = 4 is very reliable for a keyboard.
Split keyboards with a long connecting wire or in environment with
strong electromagnetic interference (EMI) may need a larger SAMPLE_COUNT_MACRO for reliability.
strong electromagnetic interference (EMI) may need a larger SAMPLE_COUNT for reliability.
*/
#define SAMPLE_COUNT_MACRO 4 //number of consecutive equal bits needed to change a debounced bit
const uint8_t SAMPLE_COUNT = 4; //number of consecutive equal bits needed to change a debounced bit

#endif