teensy_hal.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include "py/runtime.h"
  4. #include "py/mphal.h"
  5. #include "usb.h"
  6. #include "uart.h"
  7. #include "Arduino.h"
  8. mp_uint_t mp_hal_ticks_ms(void) {
  9. return millis();
  10. }
  11. void mp_hal_delay_ms(mp_uint_t ms) {
  12. delay(ms);
  13. }
  14. void mp_hal_set_interrupt_char(int c) {
  15. // The teensy 3.1 usb stack doesn't currently have the notion of generating
  16. // an exception when a certain character is received. That just means that
  17. // you can't press Control-C and get your python script to stop.
  18. }
  19. int mp_hal_stdin_rx_chr(void) {
  20. for (;;) {
  21. byte c;
  22. if (usb_vcp_recv_byte(&c) != 0) {
  23. return c;
  24. } else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
  25. return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
  26. }
  27. __WFI();
  28. }
  29. }
  30. void mp_hal_stdout_tx_str(const char *str) {
  31. mp_hal_stdout_tx_strn(str, strlen(str));
  32. }
  33. void mp_hal_stdout_tx_strn(const char *str, size_t len) {
  34. if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
  35. uart_tx_strn(MP_STATE_PORT(pyb_stdio_uart), str, len);
  36. }
  37. if (usb_vcp_is_enabled()) {
  38. usb_vcp_send_strn(str, len);
  39. }
  40. }
  41. void mp_hal_stdout_tx_strn_cooked(const char *str, size_t len) {
  42. // send stdout to UART and USB CDC VCP
  43. if (MP_STATE_PORT(pyb_stdio_uart) != NULL) {
  44. void uart_tx_strn_cooked(pyb_uart_obj_t *uart_obj, const char *str, uint len);
  45. uart_tx_strn_cooked(MP_STATE_PORT(pyb_stdio_uart), str, len);
  46. }
  47. if (usb_vcp_is_enabled()) {
  48. usb_vcp_send_strn_cooked(str, len);
  49. }
  50. }
  51. void mp_hal_gpio_clock_enable(GPIO_TypeDef *gpio) {
  52. }
  53. void extint_register_pin(const void *pin, uint32_t mode, int hard_irq, mp_obj_t callback_obj) {
  54. mp_raise_NotImplementedError(NULL);
  55. }