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
|
|
|
|
2017-06-15 03:42:18 -04:00
|
|
|
#include "py/runtime.h"
|
2019-06-19 00:02:38 -04:00
|
|
|
#include "py/stream.h"
|
2015-10-30 19:03:58 -04:00
|
|
|
#include "py/mphal.h"
|
2015-02-13 10:04:53 -05:00
|
|
|
#include "usb.h"
|
|
|
|
#include "uart.h"
|
2014-06-16 01:33:14 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2015-10-30 19:03:58 -04:00
|
|
|
mp_uint_t mp_hal_ticks_ms(void) {
|
2014-09-28 14:21:13 -04:00
|
|
|
return millis();
|
2014-06-16 01:33:14 -04:00
|
|
|
}
|
|
|
|
|
2015-10-30 19:03:58 -04:00
|
|
|
void mp_hal_delay_ms(mp_uint_t ms) {
|
2015-10-29 13:12:13 -04:00
|
|
|
delay(ms);
|
2014-06-16 01:33:14 -04:00
|
|
|
}
|
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
|
|
|
|
2019-06-19 00:02:38 -04:00
|
|
|
uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags) {
|
|
|
|
uintptr_t ret = 0;
|
|
|
|
if (poll_flags & MP_STREAM_POLL_RD) {
|
|
|
|
if (usb_vcp_rx_num()) {
|
|
|
|
ret |= MP_STREAM_POLL_RD;
|
|
|
|
}
|
|
|
|
if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
|
|
|
|
ret |= MP_STREAM_POLL_RD;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:03:58 -04:00
|
|
|
void mp_hal_stdout_tx_strn(const char *str, size_t len) {
|
2015-02-13 10:04:53 -05:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-30 19:03:58 -04:00
|
|
|
void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
|
2015-02-13 10:04:53 -05:00
|
|
|
// send stdout to UART and USB CDC VCP
|
|
|
|
if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
|
2017-10-31 20:00:30 -04:00
|
|
|
void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
|
2015-02-13 10:04:53 -05:00
|
|
|
uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
|
|
|
|
}
|
|
|
|
if (usb_vcp_is_enabled()) {
|
|
|
|
usb_vcp_send_strn_cooked(str, len);
|
|
|
|
}
|
|
|
|
}
|
2015-08-02 19:05:16 -04:00
|
|
|
|
|
|
|
void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio) {
|
|
|
|
}
|
2017-06-15 03:42:18 -04:00
|
|
|
|
|
|
|
void extint_register_pin(const void *pin, uint32_t mode, int hard_irq, mp_obj_t callback_obj) {
|
2017-08-09 00:40:45 -04:00
|
|
|
mp_raise_NotImplementedError(NULL);
|
2017-06-15 03:42:18 -04:00
|
|
|
}
|
2022-07-01 16:51:12 -04:00
|
|
|
|
|
|
|
MP_REGISTER_ROOT_POINTER(struct _pyb_uart_obj_t *pyb_stdio_uart);
|