2018-02-26 13:06:10 +00:00
|
|
|
/*
|
2019-06-17 18:27:55 +00:00
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
2018-02-26 13:06:10 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) SatoshiLabs
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
#include "common.h"
|
2017-03-08 12:43:24 +00:00
|
|
|
#include "py/mphal.h"
|
2020-12-07 03:45:29 +00:00
|
|
|
#include "string.h"
|
2020-12-11 15:45:10 +00:00
|
|
|
#include "usb.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) {
|
2019-03-29 15:26:02 +00:00
|
|
|
ensure(sectrue * (vcp_iface_num >= 0), "vcp stdio is not configured");
|
|
|
|
uint8_t c = 0;
|
|
|
|
int r = usb_vcp_read_blocking(vcp_iface_num, &c, 1, -1);
|
|
|
|
(void)r;
|
|
|
|
return c;
|
2017-03-08 12:43:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
2019-03-29 15:26:02 +00:00
|
|
|
if (vcp_iface_num >= 0) {
|
2020-07-15 14:49:54 +00:00
|
|
|
// The write timeout is set to 0, because otherwise when the VCP receive
|
|
|
|
// buffer on the host gets full, the timeout will block device operation.
|
|
|
|
int r = usb_vcp_write_blocking(vcp_iface_num, (const uint8_t *)str, len, 0);
|
2019-03-29 15:26:02 +00:00
|
|
|
(void)r;
|
|
|
|
}
|
2017-05-09 14:10:27 +00:00
|
|
|
}
|
|
|
|
|
2019-03-29 15:26:02 +00:00
|
|
|
void mp_hal_set_vcp_iface(int iface_num) { vcp_iface_num = iface_num; }
|