summaryrefslogtreecommitdiff
path: root/tmk_core/tool/mbed/mbed-sdk/libraries/tests/mbed/serial_interrupt_2/main.cpp
blob: 8833c36da7ce5aa9b9744cdd3e0b350b87016b99 (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
#include "mbed.h"

Serial pc(USBTX, USBRX);

#if defined(TARGET_LPC4088)
Serial uart(P4_22, P4_23);
#elif defined(TARGET_MAXWSNENV)
Serial uart(P0_1, P0_0);
#else
Serial uart(p9, p10);
#endif

DigitalOut led1(LED1);
DigitalOut led2(LED2);

// This function is called when a character goes into the RX buffer.
void rxCallback(void) {
    led1 = !led1;
    pc.putc(uart.getc());
}


int main() {
    // Use a deliberatly slow baud to fill up the TX buffer
    uart.baud(1200);
    uart.attach(&rxCallback, Serial::RxIrq);

    printf("Starting test loop:\n");
    wait(1);

    int c = 'A';
    for (int loop = 0; loop < 512; loop++) {
        uart.printf("%c", c);
        c++;
        if (c > 'Z') c = 'A';
    }

    while (true) {
        led2 = !led2;
        wait(1);
    }
}