blob: 2da1c04d4987e17cbb0d7710614e8d6e7af946d1 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 | // Slave mode for Quality Assurance test
#include "wirish.h"
#define INTER_TOGGLE_DELAY_NORMAL 5
#define INTER_TOGGLE_DELAY_SLOW   80
void interToggleDelay(void);
void setup() {
    pinMode(BOARD_LED_PIN, OUTPUT);
    pinMode(BOARD_BUTTON_PIN, INPUT);
    // All unused pins start out low.
    for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
        if (boardUsesPin(i))
            continue;
        pinMode(i, OUTPUT);
        digitalWrite(i, LOW);
    }
    SerialUSB.println("OK, starting...");
}
void loop() {
    toggleLED();
    delay(100);
    toggleLED();
    for (int i = 0; i < BOARD_NR_GPIO_PINS; i++) {
        if (boardUsesPin(i))
            continue;
        // Bring just this pin high.
        digitalWrite(i, HIGH);
        // Give the master time to detect if any other pins also went high.
        interToggleDelay();
        // Bring this pin back low again; all pins should now be low.
        digitalWrite(i, LOW);
        // Give the master time to detect if any pins are still high.
        interToggleDelay();
    }
}
void interToggleDelay(void) {
    if (digitalRead(BOARD_BUTTON_PIN)) { // don't pay the debouncing time
        delay(INTER_TOGGLE_DELAY_SLOW);
    } else {
        delay(INTER_TOGGLE_DELAY_NORMAL);
    }
 }
// Force init to be called *first*, i.e. before static object allocation.
// Otherwise, statically allocated objects that need libmaple may fail.
__attribute__((constructor)) void premain() {
    init();
}
int main(void) {
    setup();
    while (true) {
        loop();
    }
    return 0;
}
 |