2017-03-08 12:43:24 +00:00
|
|
|
#include "py/mphal.h"
|
2017-03-30 14:06:01 +00:00
|
|
|
#include "usb.h"
|
2017-05-09 14:10:27 +00:00
|
|
|
#include "common.h"
|
2017-03-08 12:43:24 +00:00
|
|
|
|
2017-05-09 14:10:27 +00:00
|
|
|
static int vcp_iface_num = -1;
|
2017-03-08 12:43:24 +00:00
|
|
|
|
|
|
|
int mp_hal_stdin_rx_chr(void) {
|
2017-10-26 21:51:39 +00:00
|
|
|
ensure(sectrue * (vcp_iface_num >= 0), "vcp stdio is not configured");
|
2017-10-11 22:32:46 +00:00
|
|
|
uint8_t c = 0;
|
2017-12-16 17:42:06 +00:00
|
|
|
ensure(usb_vcp_read_blocking(vcp_iface_num, &c, 1, -1), NULL);
|
2017-10-11 22:32:46 +00:00
|
|
|
return c;
|
2017-03-08 12:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
2017-10-11 22:32:46 +00:00
|
|
|
if (vcp_iface_num >= 0) {
|
2017-12-16 17:42:06 +00:00
|
|
|
ensure(usb_vcp_write_blocking(vcp_iface_num, (const uint8_t *)str, len, 0), NULL);
|
2017-05-09 14:10:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mp_hal_set_vcp_iface(int iface_num) {
|
|
|
|
vcp_iface_num = iface_num;
|
2017-03-08 12:43:24 +00:00
|
|
|
}
|