summaryrefslogtreecommitdiffstatshomepage
path: root/teensy/usb.c
blob: ab4731f27b139128463eb960ef40f38e2c523828 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Arduino.h"

#include "usb.h"
#include "usb_serial.h"

int usb_vcp_is_connected(void)
{
  return usb_configuration && (usb_cdc_line_rtsdtr & (USB_SERIAL_DTR | USB_SERIAL_RTS));
}

int usb_vcp_is_enabled(void)
{
  return 1;
}

void usb_vcp_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.
}

int usb_vcp_rx_num(void) {
  return usb_serial_available();
}

char usb_vcp_rx_get(void)
{
  return usb_serial_getchar();
}

void usb_vcp_send_str(const char* str)
{
  usb_vcp_send_strn(str, strlen(str));
}

void usb_vcp_send_strn(const char* str, int len)
{
  usb_serial_write(str, len);
}

void usb_vcp_send_strn_cooked(const char *str, int len)
{
  for (const char *top = str + len; str < top; str++) {
    if (*str == '\n') {
      usb_serial_putchar('\r');
    }
    usb_serial_putchar(*str);
  }
}