You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
861 B
53 lines
861 B
11 years ago
|
#include <string.h>
|
||
|
|
||
10 years ago
|
#include "py/runtime.h"
|
||
11 years ago
|
|
||
10 years ago
|
#include "Arduino.h"
|
||
10 years ago
|
|
||
11 years ago
|
#include "usb.h"
|
||
|
#include "usb_serial.h"
|
||
|
|
||
10 years ago
|
bool usb_vcp_is_connected(void)
|
||
11 years ago
|
{
|
||
|
return usb_configuration && (usb_cdc_line_rtsdtr & (USB_SERIAL_DTR | USB_SERIAL_RTS));
|
||
|
}
|
||
|
|
||
10 years ago
|
bool usb_vcp_is_enabled(void)
|
||
11 years ago
|
{
|
||
10 years ago
|
return true;
|
||
11 years ago
|
}
|
||
|
|
||
11 years ago
|
int usb_vcp_rx_num(void) {
|
||
11 years ago
|
return usb_serial_available();
|
||
|
}
|
||
|
|
||
10 years ago
|
int usb_vcp_recv_byte(uint8_t *ptr)
|
||
11 years ago
|
{
|
||
10 years ago
|
int ch = usb_serial_getchar();
|
||
|
if (ch < 0) {
|
||
|
return 0;
|
||
|
}
|
||
|
*ptr = ch;
|
||
|
return 1;
|
||
11 years ago
|
}
|
||
|
|
||
|
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);
|
||
|
}
|
||
|
}
|