2014-06-16 01:33:14 -04:00
|
|
|
#include <stdio.h>
|
2015-02-13 10:04:53 -05:00
|
|
|
#include <string.h>
|
2014-06-16 01:33:14 -04:00
|
|
|
|
2015-02-13 10:04:53 -05:00
|
|
|
#include "py/mpstate.h"
|
|
|
|
#include "usb.h"
|
|
|
|
#include "uart.h"
|
2014-06-16 01:33:14 -04:00
|
|
|
#include "Arduino.h"
|
2014-07-02 08:42:37 -04:00
|
|
|
#include MICROPY_HAL_H
|
2014-06-16 01:33:14 -04:00
|
|
|
|
|
|
|
uint32_t HAL_GetTick(void) {
|
2014-09-28 14:21:13 -04:00
|
|
|
return millis();
|
2014-06-16 01:33:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void HAL_Delay(uint32_t Delay) {
|
|
|
|
delay(Delay);
|
|
|
|
}
|
2014-11-27 11:58:31 -05:00
|
|
|
|
|
|
|
void mp_hal_set_interrupt_char(int c) {
|
|
|
|
// The teensy 3.1 usb stack doesn't currently have the notion of generating
|
|
|
|
// an exception when a certain character is received. That just means that
|
|
|
|
// you can't press Control-C and get your python script to stop.
|
|
|
|
}
|
2015-02-13 10:04:53 -05:00
|
|
|
|
|
|
|
int mp_hal_stdin_rx_chr(void) {
|
|
|
|
for (;;) {
|
|
|
|
byte c;
|
|
|
|
if (usb_vcp_recv_byte(&c) != 0) {
|
|
|
|
return c;
|
|
|
|
} else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
|
|
|
|
return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
|
|
|
|
}
|
|
|
|
__WFI();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mp_hal_stdout_tx_str(const char *str) {
|
|
|
|
mp_hal_stdout_tx_strn(str, strlen(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
void mp_hal_stdout_tx_strn(const char *str, uint32_t len) {
|
|
|
|
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
|
|
|
|
uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
|
|
|
|
}
|
|
|
|
if (usb_vcp_is_enabled()) {
|
|
|
|
usb_vcp_send_strn(str, len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mp_hal_stdout_tx_strn_cooked(const char *str, uint32_t len) {
|
|
|
|
// send stdout to UART and USB CDC VCP
|
|
|
|
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
|
|
|
|
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
|
|
|
|
}
|
|
|
|
if (usb_vcp_is_enabled()) {
|
|
|
|
usb_vcp_send_strn_cooked(str, len);
|
|
|
|
}
|
|
|
|
}
|