diff options
| author | Jason Green <jason@jasg.org> | 2016-08-01 05:02:52 +0000 |
|---|---|---|
| committer | Jason Green <jason@jasg.org> | 2016-08-23 04:16:35 +0000 |
| commit | 80d10bef073e3d32149aa4a137d8016ac999dffc (patch) | |
| tree | 763014f6f4484073e1c9c139f3ff9feb8189204e /tmk_core/protocol/lufa/lufa.c | |
| parent | d8c5041f0a3849c96d7e0bfcf7b22e1aba98ac04 (diff) | |
| download | qmk_firmware-80d10bef073e3d32149aa4a137d8016ac999dffc.tar.gz qmk_firmware-80d10bef073e3d32149aa4a137d8016ac999dffc.zip | |
Added USB Virtual Serial support
Diffstat (limited to 'tmk_core/protocol/lufa/lufa.c')
| -rw-r--r-- | tmk_core/protocol/lufa/lufa.c | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c index 9ca55dbc9..af73f34d7 100644 --- a/tmk_core/protocol/lufa/lufa.c +++ b/tmk_core/protocol/lufa/lufa.c | |||
| @@ -60,6 +60,10 @@ | |||
| 60 | #include "bluetooth.h" | 60 | #include "bluetooth.h" |
| 61 | #endif | 61 | #endif |
| 62 | 62 | ||
| 63 | #ifdef VIRTSER_ENABLE | ||
| 64 | #include "virtser.h" | ||
| 65 | #endif | ||
| 66 | |||
| 63 | uint8_t keyboard_idle = 0; | 67 | uint8_t keyboard_idle = 0; |
| 64 | /* 0: Boot Protocol, 1: Report Protocol(default) */ | 68 | /* 0: Boot Protocol, 1: Report Protocol(default) */ |
| 65 | uint8_t keyboard_protocol = 1; | 69 | uint8_t keyboard_protocol = 1; |
| @@ -127,6 +131,34 @@ USB_ClassInfo_MIDI_Device_t USB_MIDI_Interface = | |||
| 127 | #define SYS_COMMON_3 0x30 | 131 | #define SYS_COMMON_3 0x30 |
| 128 | #endif | 132 | #endif |
| 129 | 133 | ||
| 134 | #ifdef VIRTSER_ENABLE | ||
| 135 | USB_ClassInfo_CDC_Device_t cdc_device = | ||
| 136 | { | ||
| 137 | .Config = | ||
| 138 | { | ||
| 139 | .ControlInterfaceNumber = CCI_INTERFACE, | ||
| 140 | .DataINEndpoint = | ||
| 141 | { | ||
| 142 | .Address = CDC_IN_EPADDR, | ||
| 143 | .Size = CDC_EPSIZE, | ||
| 144 | .Banks = 1, | ||
| 145 | }, | ||
| 146 | .DataOUTEndpoint = | ||
| 147 | { | ||
| 148 | .Address = CDC_OUT_EPADDR, | ||
| 149 | .Size = CDC_EPSIZE, | ||
| 150 | .Banks = 1, | ||
| 151 | }, | ||
| 152 | .NotificationEndpoint = | ||
| 153 | { | ||
| 154 | .Address = CDC_NOTIFICATION_EPADDR, | ||
| 155 | .Size = CDC_NOTIFICATION_EPSIZE, | ||
| 156 | .Banks = 1, | ||
| 157 | }, | ||
| 158 | }, | ||
| 159 | }; | ||
| 160 | #endif | ||
| 161 | |||
| 130 | 162 | ||
| 131 | /******************************************************************************* | 163 | /******************************************************************************* |
| 132 | * Console | 164 | * Console |
| @@ -311,6 +343,12 @@ void EVENT_USB_Device_ConfigurationChanged(void) | |||
| 311 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); | 343 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_IN_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 312 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); | 344 | ConfigSuccess &= Endpoint_ConfigureEndpoint(MIDI_STREAM_OUT_EPADDR, EP_TYPE_BULK, MIDI_STREAM_EPSIZE, ENDPOINT_BANK_SINGLE); |
| 313 | #endif | 345 | #endif |
| 346 | |||
| 347 | #ifdef VIRTSER_ENABLE | ||
| 348 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
| 349 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_OUT_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
| 350 | ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_IN_EPADDR, EP_TYPE_BULK, CDC_EPSIZE, ENDPOINT_BANK_SINGLE); | ||
| 351 | #endif | ||
| 314 | } | 352 | } |
| 315 | 353 | ||
| 316 | /* | 354 | /* |
| @@ -432,10 +470,15 @@ void EVENT_USB_Device_ControlRequest(void) | |||
| 432 | 470 | ||
| 433 | break; | 471 | break; |
| 434 | } | 472 | } |
| 473 | |||
| 474 | #ifdef VIRTSER_ENABLE | ||
| 475 | CDC_Device_ProcessControlRequest(&cdc_device); | ||
| 476 | #endif | ||
| 435 | } | 477 | } |
| 436 | 478 | ||
| 437 | /******************************************************************************* | 479 | /******************************************************************************* |
| 438 | * Host driver | 480 | * Host driver |
| 481 | p | ||
| 439 | ******************************************************************************/ | 482 | ******************************************************************************/ |
| 440 | static uint8_t keyboard_leds(void) | 483 | static uint8_t keyboard_leds(void) |
| 441 | { | 484 | { |
| @@ -827,6 +870,61 @@ void MIDI_Task(void) | |||
| 827 | 870 | ||
| 828 | #endif | 871 | #endif |
| 829 | 872 | ||
| 873 | /******************************************************************************* | ||
| 874 | * VIRTUAL SERIAL | ||
| 875 | ******************************************************************************/ | ||
| 876 | |||
| 877 | #ifdef VIRTSER_ENABLE | ||
| 878 | void virtser_init(void) | ||
| 879 | { | ||
| 880 | cdc_device.State.ControlLineStates.DeviceToHost = CDC_CONTROL_LINE_IN_DSR ; | ||
| 881 | CDC_Device_SendControlLineStateChange(&cdc_device); | ||
| 882 | } | ||
| 883 | |||
| 884 | __attribute__ ((weak)) | ||
| 885 | void virtser_recv(uint8_t c) | ||
| 886 | { | ||
| 887 | // Ignore by default | ||
| 888 | } | ||
| 889 | |||
| 890 | void virtser_task(void) | ||
| 891 | { | ||
| 892 | uint16_t count = CDC_Device_BytesReceived(&cdc_device); | ||
| 893 | uint8_t ch; | ||
| 894 | if (count) | ||
| 895 | { | ||
| 896 | ch = CDC_Device_ReceiveByte(&cdc_device); | ||
| 897 | virtser_recv(ch); | ||
| 898 | } | ||
| 899 | } | ||
| 900 | void virtser_send(const uint8_t byte) | ||
| 901 | { | ||
| 902 | uint8_t timeout = 255; | ||
| 903 | uint8_t ep = Endpoint_GetCurrentEndpoint(); | ||
| 904 | |||
| 905 | if (cdc_device.State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR) | ||
| 906 | { | ||
| 907 | /* IN packet */ | ||
| 908 | Endpoint_SelectEndpoint(cdc_device.Config.DataINEndpoint.Address); | ||
| 909 | |||
| 910 | if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) { | ||
| 911 | Endpoint_SelectEndpoint(ep); | ||
| 912 | return; | ||
| 913 | } | ||
| 914 | |||
| 915 | while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40); | ||
| 916 | |||
| 917 | Endpoint_Write_8(byte); | ||
| 918 | CDC_Device_Flush(&cdc_device); | ||
| 919 | |||
| 920 | if (Endpoint_IsINReady()) { | ||
| 921 | Endpoint_ClearIN(); | ||
| 922 | } | ||
| 923 | |||
| 924 | Endpoint_SelectEndpoint(ep); | ||
| 925 | } | ||
| 926 | } | ||
| 927 | #endif | ||
| 830 | 928 | ||
| 831 | /******************************************************************************* | 929 | /******************************************************************************* |
| 832 | * main | 930 | * main |
| @@ -918,6 +1016,10 @@ int main(void) | |||
| 918 | sleep_led_init(); | 1016 | sleep_led_init(); |
| 919 | #endif | 1017 | #endif |
| 920 | 1018 | ||
| 1019 | #ifdef VIRTSER_ENABLE | ||
| 1020 | virtser_init(); | ||
| 1021 | #endif | ||
| 1022 | |||
| 921 | print("Keyboard start.\n"); | 1023 | print("Keyboard start.\n"); |
| 922 | while (1) { | 1024 | while (1) { |
| 923 | #ifndef BLUETOOTH_ENABLE | 1025 | #ifndef BLUETOOTH_ENABLE |
| @@ -936,6 +1038,11 @@ int main(void) | |||
| 936 | #endif | 1038 | #endif |
| 937 | keyboard_task(); | 1039 | keyboard_task(); |
| 938 | 1040 | ||
| 1041 | #ifdef VIRTSER_ENABLE | ||
| 1042 | virtser_task(); | ||
| 1043 | CDC_Device_USBTask(&cdc_device); | ||
| 1044 | #endif | ||
| 1045 | |||
| 939 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) | 1046 | #if !defined(INTERRUPT_CONTROL_ENDPOINT) |
| 940 | USB_USBTask(); | 1047 | USB_USBTask(); |
| 941 | #endif | 1048 | #endif |
