Browse Source

replace ACTIVE_HIGH and activeHigh with STROBE_ON, STROBE_OFF

tags/v0.5.0
wolfv6 7 years ago
parent
commit
f5448b200a

+ 5
- 1
examples/keybrd_shift_register/keybrd_shift_register.ino View File

@@ -30,7 +30,11 @@ Layout

// =============== CONFIGURATION ===============
ScanDelay scanDelay(9000);
const bool RowScanner_PinsArray::ACTIVE_HIGH = 0; //left matrix is active low

//active state of left matrix
const bool RowScanner_PinsArray::STROBE_ON = LOW;
const bool RowScanner_PinsArray::STROBE_OFF = HIGH;

const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;

Debug debug;

+ 6
- 22
src/RowScanner_PinsArray.cpp View File

@@ -11,13 +11,13 @@ RowScanner_PinsArray::RowScanner_PinsArray(const uint8_t STROBE_PIN,
//configure row
pinMode(STROBE_PIN, OUTPUT);

if (ACTIVE_HIGH)
if (STROBE_ON == LOW) //if active low
{
mode = INPUT; //requires external pull-down resistor
mode = INPUT_PULLUP; //uses internal pull-up resistor
}
else
{
mode = INPUT_PULLUP; //uses internal pull-up resistor
mode = INPUT; //requires external pull-down resistor
}

//configure cols
@@ -41,36 +41,20 @@ read_pins_t RowScanner_PinsArray::scan(uint8_t& keyCount)
read_pins_t rowState = 0; //bitwise, one col per bit, 1 means key is pressed
read_pins_t rowMask = 1; //bitwise, one col per bit, active col bit is 1

//strobe row on
if (ACTIVE_HIGH)
{
digitalWrite(STROBE_PIN, HIGH);
}
else //activeLow
{
digitalWrite(STROBE_PIN, LOW);
}
digitalWrite(STROBE_PIN, STROBE_ON);
delayMicroseconds(3); //time to stablize voltage

//read all the column pins
for (uint8_t i=0; i < READ_PIN_COUNT; i++)
{
if ( digitalRead(READ_PINS[i]) == ACTIVE_HIGH )
if ( digitalRead(READ_PINS[i]) == STROBE_ON )
{
rowState |= rowMask;
}
rowMask <<= 1;
}

//strobe row off
if (ACTIVE_HIGH)
{
digitalWrite(STROBE_PIN, LOW);
}
else //activeLow
{
digitalWrite(STROBE_PIN, HIGH);
}
digitalWrite(STROBE_PIN, STROBE_OFF);

keyCount = READ_PIN_COUNT;
return rowState;

+ 2
- 1
src/RowScanner_PinsArray.h View File

@@ -12,7 +12,8 @@ Constructor is in RowScanner_PinsArray.cpp
class RowScanner_PinsArray
{
private:
static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh
static const bool STROBE_ON; //logic level of strobe on, HIGH or LOW
static const bool STROBE_OFF; //logic level of strobe off, HIGH or LOW
const uint8_t STROBE_PIN; //Arduino pin number connected to this row
const uint8_t* const READ_PINS; //array of read pin numbers
const uint8_t READ_PIN_COUNT; //number of read pins

+ 6
- 6
src/RowScanner_PinsBitwise.cpp View File

@@ -5,13 +5,13 @@ Strobes the row and reads the columns.
ColPort* const RowScanner_PinsBitwise::scan()
{
//strobe row on
if (activeHigh)
if (STROBE_ON == LOW)
{
refRowPort.setActivePinHigh(strobePin);
refRowPort.setActivePinLow(strobePin);
}
else //activeLow
{
refRowPort.setActivePinLow(strobePin);
refRowPort.setActivePinHigh(strobePin);
}
delayMicroseconds(3); //time to stablize voltage

@@ -19,13 +19,13 @@ ColPort* const RowScanner_PinsBitwise::scan()
refColPort.read();

//strobe row off
if (activeHigh)
if (STROBE_ON == LOW)
{
refRowPort.setActivePinLow(strobePin);
refRowPort.setActivePinHigh(strobePin);
}
else //activeLow
{
refRowPort.setActivePinHigh(strobePin);
refRowPort.setActivePinLow(strobePin);
}
return &refColPort;

+ 1
- 1
src/RowScanner_PinsBitwise.h View File

@@ -19,7 +19,7 @@ class RowScanner_PinsBitwise
ColPort& refColPort)
: refRowPort(refRowPort), strobePin(strobePin),
refColPort(refColPort) {}
static const bool activeHigh; //logic level of strobe pin: 0=activeLow, 1=activeHigh
static const bool STROBE_ON; //logic level of strobe on, active state, HIGH or LOW
virtual ColPort* const scan();
};
#endif

+ 2
- 2
src/Row_uC.h View File

@@ -10,11 +10,11 @@
Instantiation
-------------
Definition of DELAY_MICROSECONDS is explained in RowBase.cpp.
todo Definition of activeHigh is explained in RowScanner_Interface.h
Example instantiation of a row:

const unsigned int RowBase::DELAY_MICROSECONDS = 1000;
const bool RowScanner_PinsArray::activeHigh = 0;
const bool RowScanner_PinsArray::STROBE_ON = LOW; //logic level of strobe on
const bool RowScanner_PinsArray::STROBE_OFF = HIGH; //logic level of strobe off

const uint8_t colPins[] = {0,1,2,3,7,8};
const uint8_t COL_PIN_COUNT = sizeof(colPins)/sizeof(*colPins);

+ 1
- 1
src/config_keybrd.h View File

@@ -8,7 +8,7 @@ If your 8-bit AVR is running low on memory, using a smaller type saves SRAM.
Using smaller types on a 32-bit uC (Teensy LC) would accomplish nothing.
*/

/* Uncomment a typedef read_pins_t that covers all col pins of the RowScanner object with the most col pins i.e.
/* Uncomment a typedef read_pins_t size that covers all col pins of all RowScanner objects i.e.
For RowScanner_PinsArray, RowScanner_PinsArray::READ_PIN_COUNT
For RowScanner_SPIShiftRegisters, RowScanner_SPIShiftRegisters::KEY_COUNT
For RowScanner_PinsBitwise, cover the last 1 bit in RowScanner_PinsBitwise::strobePin