2014-06-16 12:38:24 -04:00
|
|
|
#include <string.h>
|
2014-08-03 12:55:24 -04:00
|
|
|
#include <stdint.h>
|
2014-06-16 12:38:24 -04:00
|
|
|
|
2014-01-06 03:20:11 -05:00
|
|
|
#include "Arduino.h"
|
|
|
|
|
2014-08-03 12:55:24 -04:00
|
|
|
#include "mpconfig.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "qstr.h"
|
|
|
|
#include "obj.h"
|
|
|
|
#include "runtime.h"
|
|
|
|
|
2014-01-06 03:20:11 -05:00
|
|
|
#include "usb.h"
|
|
|
|
#include "usb_serial.h"
|
|
|
|
|
2014-08-03 12:55:24 -04:00
|
|
|
bool usb_vcp_is_connected(void)
|
2014-01-06 03:20:11 -05:00
|
|
|
{
|
|
|
|
return usb_configuration && (usb_cdc_line_rtsdtr & (USB_SERIAL_DTR | USB_SERIAL_RTS));
|
|
|
|
}
|
|
|
|
|
2014-08-03 12:55:24 -04:00
|
|
|
bool usb_vcp_is_enabled(void)
|
2014-01-06 03:20:11 -05:00
|
|
|
{
|
2014-08-03 12:55:24 -04:00
|
|
|
return true;
|
2014-01-06 03:20:11 -05:00
|
|
|
}
|
|
|
|
|
2014-06-16 01:33:14 -04:00
|
|
|
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) {
|
2014-01-06 03:20:11 -05:00
|
|
|
return usb_serial_available();
|
|
|
|
}
|
|
|
|
|
2014-08-03 12:55:24 -04:00
|
|
|
int usb_vcp_recv_byte(uint8_t *ptr)
|
2014-01-06 03:20:11 -05:00
|
|
|
{
|
2014-08-03 12:55:24 -04:00
|
|
|
int ch = usb_serial_getchar();
|
|
|
|
if (ch < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
*ptr = ch;
|
|
|
|
return 1;
|
2014-01-06 03:20:11 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|