summaryrefslogtreecommitdiff
path: root/tool/mbed/mbed-sdk/libraries/tests/mbed/serial_interrupt/main.cpp
blob: 50b55e6e3b42b62ec6d82db0c4058f7624b349e5 (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
#include "mbed.h"

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

Serial computer(USBTX, USBRX);

// This function is called when a character goes into the TX buffer.
void txCallback() {
    led1 = !led1;
}

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

int main() {
    printf("start test\n");
    computer.attach(&txCallback, Serial::TxIrq);
    computer.attach(&rxCallback, Serial::RxIrq);
    while (true) {
        wait(1);
    }
}