aboutsummaryrefslogtreecommitdiffstats
path: root/wirish/wirish_digital.c
diff options
context:
space:
mode:
Diffstat (limited to 'wirish/wirish_digital.c')
-rw-r--r--wirish/wirish_digital.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/wirish/wirish_digital.c b/wirish/wirish_digital.c
index aa22196..cdd04bf 100644
--- a/wirish/wirish_digital.c
+++ b/wirish/wirish_digital.c
@@ -103,3 +103,35 @@ void digitalWrite(uint8 pin, uint8 val) {
gpio_write_bit(PIN_MAP[pin].port, PIN_MAP[pin].pin, val);
}
+
+void togglePin(uint8 pin) {
+ gpio_toggle_pin(PIN_MAP[pin].port, PIN_MAP[pin].pin);
+}
+
+uint8 isButtonPressed() {
+ if (digitalRead(BOARD_BUTTON_PIN)) {
+ while (digitalRead(BOARD_BUTTON_PIN))
+ ;
+ return true;
+ }
+ return false;
+}
+
+uint8 waitForButtonPress(uint32 timeout) {
+ uint32 start = millis();
+ uint32 time;
+ if (timeout == 0) {
+ while (!isButtonPressed())
+ ;
+ return true;
+ }
+ do {
+ time = millis();
+ /* properly handle wrap-around */
+ if ((start > time && time + (0xffffffffU - start) > timeout) ||
+ time - start > timeout) {
+ return false;
+ }
+ } while (!isButtonPressed());
+ return true;
+}