Updated 4X4 keypad code that works on STM32F407 and Mbed-OS-5. InterruptIn on STM32F4 MCUs seem to float without PullDown/Up, without forced PullDown the original code doesn't work on STM32F407 and most likely other STM32 MCUs as well.
Revision 11:75328ab1acf4, committed 2020-01-27
- Comitter:
- zhiyong
- Date:
- Mon Jan 27 05:15:16 2020 +0000
- Parent:
- 10:da060f8c03e8
- Commit message:
- Added PullDown to InterruptIn initialization so the code can work on STM32F4. Also removed debounce delay in ISR to work on mbed-os-5.; ; Tested working on customized boarded based on Arch_Max/STM32F407VET6.
Changed in this revision
Keypad.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/Keypad.cpp Wed Jan 01 17:45:53 2014 +0000 +++ b/Keypad.cpp Mon Jan 27 05:15:16 2020 +0000 @@ -28,19 +28,19 @@ ) { if (_rows[0]) { - _rows[0]->rise(this, &Keypad::_cbRow0Rise); + _rows[0]->rise(callback(this, &Keypad::_cbRow0Rise)); } if (_rows[1]) { - _rows[1]->rise(this, &Keypad::_cbRow1Rise); + _rows[1]->rise(callback(this, &Keypad::_cbRow1Rise)); } if (_rows[2]) { - _rows[2]->rise(this, &Keypad::_cbRow2Rise); + _rows[2]->rise(callback(this, &Keypad::_cbRow2Rise)); } if (_rows[3]) { - _rows[3]->rise(this, &Keypad::_cbRow3Rise); + _rows[3]->rise(callback(this, &Keypad::_cbRow3Rise)); } } @@ -68,7 +68,9 @@ _nRow = 0; for (int i = 0; i < 4; i++) { if (rPins[i] != NC) { - _rows[i] = new InterruptIn(rPins[i]); + // PullDown required, otherwise won't work on STM32F407, most likely not on other STM32 MCUs as well + // Without PullDown, InterruptIn seems to float + _rows[i] = new InterruptIn(rPins[i], PullDown); _nRow++; } else break; @@ -133,10 +135,12 @@ ,InterruptIn *therow ) { + // Blocking waiting not allowed by mbed-os-5 + // Keypad seems to work fine without debounce #ifdef THREAD_H - Thread::wait(_debounce); + //Thread::wait(_debounce); #else - wait_ms(_debounce); + //wait_ms(_debounce); #endif if (therow->read() == 0)