aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qa-slave-shield.cpp
blob: 178b7801e0a853423a1085f1f9d56a26b29bff1d (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
// Slave mode for QA shield

#include "wirish.h"

// FIXME generalize for Maple Native, Maple Mini (NUM_GPIO, Mini USB
// breakout pins, etc.)

#define LED_PIN BOARD_LED_PIN
#define NUM_GPIO 38 // Ignore JTAG pins.

void setup() {
    /* Set up the LED to blink  */
    pinMode(LED_PIN, OUTPUT);
    digitalWrite(LED_PIN, HIGH);

    for(int i = 0; i < NUM_GPIO; i++) {
        if (i == BOARD_LED_PIN) {
            continue;
        }
        pinMode(i, OUTPUT);
        digitalWrite(i, LOW);
    }
    SerialUSB.println("OK, starting...");
}

void loop() {
    toggleLED();
    delay(100);
    toggleLED();

    for(int i = 0; i < NUM_GPIO; i++) {
        if (i == BOARD_LED_PIN) {
            continue;
        }
        togglePin(i);
        delay(5);
        togglePin(i);
        delay(5);
    }
}

// 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 (1) {
        loop();
    }
    return 0;
}