/* * spreadspace avr utils * * * Copyright (C) 2013-2015 Christian Pointner * * This file is part of spreadspace avr utils. * * spreadspace avr utils is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * spreadspace avr utils is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with spreadspace avr utils. If not, see . */ #include #include "dualusbio.h" /* LUFA Library Copyright (C) Dean Camera, 2012. dean [at] fourwalledcubicle [dot] com www.lufa-lib.org */ #include #include "lufa-descriptor-usbdualserial.h" USB_ClassInfo_CDC_Device_t VirtualSerial1_CDC_Interface = { .Config = { .ControlInterfaceNumber = 0, .DataINEndpointNumber = CDC1_TX_EPNUM, .DataINEndpointSize = CDC_TXRX_EPSIZE, .DataINEndpointDoubleBank = false, .DataOUTEndpointNumber = CDC1_RX_EPNUM, .DataOUTEndpointSize = CDC_TXRX_EPSIZE, .DataOUTEndpointDoubleBank = false, .NotificationEndpointNumber = CDC1_NOTIFICATION_EPNUM, .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, .NotificationEndpointDoubleBank = false, }, }; USB_ClassInfo_CDC_Device_t VirtualSerial2_CDC_Interface = { .Config = { .ControlInterfaceNumber = 2, .DataINEndpointNumber = CDC2_TX_EPNUM, .DataINEndpointSize = CDC_TXRX_EPSIZE, .DataINEndpointDoubleBank = false, .DataOUTEndpointNumber = CDC2_RX_EPNUM, .DataOUTEndpointSize = CDC_TXRX_EPSIZE, .DataOUTEndpointDoubleBank = false, .NotificationEndpointNumber = CDC2_NOTIFICATION_EPNUM, .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, .NotificationEndpointDoubleBank = false, }, }; void EVENT_USB_Device_ConfigurationChanged(void) { CDC_Device_ConfigureEndpoints(&VirtualSerial1_CDC_Interface); CDC_Device_ConfigureEndpoints(&VirtualSerial2_CDC_Interface); } void EVENT_USB_Device_ControlRequest(void) { CDC_Device_ProcessControlRequest(&VirtualSerial1_CDC_Interface); CDC_Device_ProcessControlRequest(&VirtualSerial2_CDC_Interface); } FILE usbio_port1; FILE usbio_port2; void dualusbio_init(void) { USB_Init(); CDC_Device_CreateStream(&VirtualSerial1_CDC_Interface, &usbio_port1); CDC_Device_CreateStream(&VirtualSerial2_CDC_Interface, &usbio_port2); } void dualusbio_task(void) { #if defined(USB_SERIES_4_AVR) || defined(USB_SERIES_6_AVR) || defined(USB_SERIES_7_AVR) if(USB_DeviceState == DEVICE_STATE_Unattached && USB_VBUS_GetStatus()) { USB_Disable(); USB_Init(); } #endif CDC_Device_USBTask(&VirtualSerial1_CDC_Interface); CDC_Device_USBTask(&VirtualSerial2_CDC_Interface); USB_USBTask(); } void dualusbio_make_stdio(uint8_t port) { switch(port) { case 1: stdin = stdout = stderr = &usbio_port1; break; case 2: stdin = stdout = stderr = &usbio_port2; break; } } int16_t dualusbio_bytes_received(uint8_t port) { switch(port) { case 1: return CDC_Device_BytesReceived(&VirtualSerial1_CDC_Interface); case 2: return CDC_Device_BytesReceived(&VirtualSerial2_CDC_Interface); } return 0; }