Created
November 20, 2020 13:34
-
-
Save sago35/b86af767e3849aa20552eaeda20606ca to your computer and use it in GitHub Desktop.
Wio Terminal RTL8720D UART Transport Passthrough
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <wiring_private.h> | |
#define PIN_BLE_SERIAL_X_RX (84ul) | |
#define PIN_BLE_SERIAL_X_TX (85ul) | |
#define PAD_BLE_SERIAL_X_RX (SERCOM_RX_PAD_2) | |
#define PAD_BLE_SERIAL_X_TX (UART_TX_PAD_0) | |
#define SERCOM_BLE_SERIAL_X sercom0 | |
static Uart rtl_uart(&SERCOM_BLE_SERIAL_X, PIN_BLE_SERIAL_X_RX, PIN_BLE_SERIAL_X_TX, PAD_BLE_SERIAL_X_RX, PAD_BLE_SERIAL_X_TX); | |
extern "C" { | |
void SERCOM0_0_Handler() | |
{ | |
rtl_uart.IrqHandler(); | |
} | |
void SERCOM0_1_Handler() | |
{ | |
rtl_uart.IrqHandler(); | |
} | |
void SERCOM0_2_Handler() | |
{ | |
rtl_uart.IrqHandler(); | |
} | |
void SERCOM0_3_Handler() | |
{ | |
rtl_uart.IrqHandler(); | |
} | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
while(!Serial); | |
rtl_uart.begin(1843200); | |
//rtl_uart.begin(115200); | |
rtl_uart.setTimeout(10 * 1000); | |
pinMode(RTL8720D_CHIP_PU, OUTPUT); | |
digitalWrite(RTL8720D_CHIP_PU, LOW); | |
delay(100); | |
digitalWrite(RTL8720D_CHIP_PU, HIGH); | |
delay(100); | |
digitalWrite(RTL8720D_CHIP_PU, LOW); | |
delay(100); | |
digitalWrite(RTL8720D_CHIP_PU, HIGH); | |
delay(100); | |
} | |
char buf4[4]; | |
char buf[0x0400]; | |
int idx; | |
void loop() | |
{ | |
if (Serial.available() > 0) | |
{ | |
char c = Serial.read(); | |
rtl_uart.write(c); | |
} | |
if (idx == 0) { | |
if (rtl_uart.available() > 0) | |
{ | |
rtl_uart.readBytes(buf4, 4); | |
idx = buf4[0] + (buf4[1]<<8); | |
for (int i = 0; i < 4; i++) { | |
Serial.write(buf4[i]); | |
} | |
} | |
} else { | |
if (rtl_uart.available() > 0) { | |
rtl_uart.readBytes(buf, idx); | |
for (int i = 0; i < idx; i++) { | |
Serial.write(buf[i]); | |
} | |
idx = 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
以下をベースに作成。
元コードだと、 read の速度が足りてないのか欠落してしまっている感じ。
https://gist.github.com/ciniml/5521e556cc1740b973858a5249a88da7