Dongha Shin / Mbed OS lab07-pc-esp-115200

main.cpp

Committer:
dshin
Date:
2022-05-22
Revision:
0:0d96af962118

File content as of revision 0:0d96af962118:

// ======================================================================

#include "mbed.h"

RawSerial PC(USBTX, USBRX);         // PC = (USBTX=TX, USBRX=RX)
RawSerial ESP(D1, D0);              // ESP = (D1=TX, D0=RX)

/// ======================================================================
// ISR for redirecting PC RX to ESP TX

void ISR_PC_to_ESP()
{
    while(PC.readable()) {
        ESP.putc(PC.getc());
    }
}

// ======================================================================
// ISR for redirecting ESP RX to PC TX

void ISR_ESP_to_PC()
{
    while(ESP.readable()) {
        PC.putc(ESP.getc());
    }
}

// ======================================================================
// Main thread

int main()
{
    PC.baud(115200);
    ESP.baud(115200);

    PC.attach(&ISR_PC_to_ESP, Serial::RxIrq);
    ESP.attach(&ISR_ESP_to_PC, Serial::RxIrq);

    while(1) {
        sleep();
    }
}

// ======================================================================