aboutsummaryrefslogtreecommitdiffstats
path: root/wirish
diff options
context:
space:
mode:
authorMarti Bolivar <mbolivar@leaflabs.com>2012-06-05 18:11:29 -0400
committerMarti Bolivar <mbolivar@leaflabs.com>2012-06-07 03:38:30 -0400
commit66167fcf43fabbf33a1ea357954a433cee4a76ff (patch)
treebde30708cc8f20f5e90054a5d6095599434a37b9 /wirish
parentab6814b687a670475fcf9be2be2af30f72904320 (diff)
downloadlibrambutan-66167fcf43fabbf33a1ea357954a433cee4a76ff.tar.gz
librambutan-66167fcf43fabbf33a1ea357954a433cee4a76ff.zip
<wirish/boards.h>: Add BOARD_BUTTON_PRESSED_LEVEL.
This allows boards to override the logic level of a pressed button. All Maple boards have a pressed button read HIGH, but if the opposite convention is used, isButtonPressed() will infinite loop. Make isButtonPressed() respect this setting. Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'wirish')
-rw-r--r--wirish/include/wirish/boards.h10
-rw-r--r--wirish/wirish_digital.cpp4
2 files changed, 11 insertions, 3 deletions
diff --git a/wirish/include/wirish/boards.h b/wirish/include/wirish/boards.h
index 73d5509..6676a02 100644
--- a/wirish/include/wirish/boards.h
+++ b/wirish/include/wirish/boards.h
@@ -110,13 +110,21 @@ extern void boardInit(void);
*/
bool boardUsesPin(uint8 pin);
-/* Set derived definitions */
+/*
+ * Derived and default board definitions
+ */
+
#define CLOCK_SPEED_MHZ CYCLES_PER_MICROSECOND
#define CLOCK_SPEED_HZ (CLOCK_SPEED_MHZ * 1000000UL)
+
#ifndef SYSTICK_RELOAD_VAL
#define SYSTICK_RELOAD_VAL (1000 * CYCLES_PER_MICROSECOND - 1)
#endif
+#ifndef BOARD_BUTTON_PRESSED_LEVEL
+#define BOARD_BUTTON_PRESSED_LEVEL HIGH
+#endif
+
/**
* @brief Does the board break out a USART/UART's RX and TX pins?
*
diff --git a/wirish/wirish_digital.cpp b/wirish/wirish_digital.cpp
index a7f10cd..05ce756 100644
--- a/wirish/wirish_digital.cpp
+++ b/wirish/wirish_digital.cpp
@@ -65,9 +65,9 @@ void togglePin(uint8 pin) {
#define BUTTON_DEBOUNCE_DELAY 1
uint8 isButtonPressed() {
- if (digitalRead(BOARD_BUTTON_PIN)) {
+ if (digitalRead(BOARD_BUTTON_PIN) == BOARD_BUTTON_PRESSED_LEVEL) {
delay(BUTTON_DEBOUNCE_DELAY);
- while (digitalRead(BOARD_BUTTON_PIN))
+ while (digitalRead(BOARD_BUTTON_PIN) == BOARD_BUTTON_PRESSED_LEVEL)
;
return true;
}