aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qa-slave-shield.cpp
blob: fc33a4a5576b547abdc5d1aa9f603340ea2a5fec (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
67
68
69
70
71
72
73
74
75
// Slave mode for QA shield

#include "wirish.h"

#define LED_PIN BOARD_LED_PIN

#if defined(BOARD_maple) || defined(BOARD_maple_RET6)
const uint8 pins_to_skip[] = {LED_PIN};

#elif defined(BOARD_maple_mini)
#define USB_DP 23
#define USB_DM 24
const uint8 pins_to_skip[] = {LED_PIN, USB_DP, USB_DM};

#elif defined(BOARD_maple_native)
const uint8 pins_to_skip[] = {LED_PIN};

#else
#error "Board type has not been selected correctly."
#endif

bool skip_pin_p(uint8 pin);

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

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

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

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

bool skip_pin_p(uint8 pin) {
    for (uint8 i = 0; i < sizeof(pins_to_skip); i++) {
        if (pin == pins_to_skip[i])
            return true;
    }
    return false;
}

// 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;
}