Fix formatting and 🐑

pull/115/head
Alex Voinea 2021-09-20 16:07:15 +02:00
parent 895671aeb2
commit 9611db9f53
2 changed files with 151 additions and 181 deletions

View File

@ -37,17 +37,15 @@
#include "Descriptors.h" #include "Descriptors.h"
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall /** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
* device characteristics, including the supported USB version, control endpoint size and the * device characteristics, including the supported USB version, control endpoint size and the
* number of device configurations. The descriptor is read out by the USB host when the enumeration * number of device configurations. The descriptor is read out by the USB host when the enumeration
* process begins. * process begins.
*/ */
const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
{ .Header = { .Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device },
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
.USBSpecification = VERSION_BCD(1,1,0), .USBSpecification = VERSION_BCD(1, 1, 0),
.Class = CDC_CSCP_CDCClass, .Class = CDC_CSCP_CDCClass,
.SubClass = CDC_CSCP_NoSpecificSubclass, .SubClass = CDC_CSCP_NoSpecificSubclass,
.Protocol = CDC_CSCP_NoSpecificProtocol, .Protocol = CDC_CSCP_NoSpecificProtocol,
@ -56,7 +54,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
.VendorID = 0x2C99, .VendorID = 0x2C99,
.ProductID = 0x0004, .ProductID = 0x0004,
.ReleaseNumber = VERSION_BCD(0,0,1), .ReleaseNumber = VERSION_BCD(0, 0, 1),
.ManufacturerStrIndex = STRING_ID_Manufacturer, .ManufacturerStrIndex = STRING_ID_Manufacturer,
.ProductStrIndex = STRING_ID_Product, .ProductStrIndex = STRING_ID_Product,
@ -70,11 +68,9 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
* and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting * and endpoints. The descriptor is read out by the USB host during the enumeration process when selecting
* a configuration so that the host may correctly communicate with the USB device. * a configuration so that the host may correctly communicate with the USB device.
*/ */
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
{ .Config = {
.Config = .Header = { .Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration },
{
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t), .TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
.TotalInterfaces = 2, .TotalInterfaces = 2,
@ -84,12 +80,9 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED), .ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100) .MaxPowerConsumption = USB_CONFIG_POWER_MA(100) },
},
.CDC_CCI_Interface = .CDC_CCI_Interface = { .Header = { .Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface },
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = INTERFACE_ID_CDC_CCI, .InterfaceNumber = INTERFACE_ID_CDC_CCI,
.AlternateSetting = 0, .AlternateSetting = 0,
@ -100,47 +93,38 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.SubClass = CDC_CSCP_ACMSubclass, .SubClass = CDC_CSCP_ACMSubclass,
.Protocol = CDC_CSCP_ATCommandProtocol, .Protocol = CDC_CSCP_ATCommandProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR .InterfaceStrIndex = NO_DESCRIPTOR },
},
.CDC_Functional_Header = .CDC_Functional_Header = {
{ .Header = { .Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = CDC_DTYPE_CSInterface },
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = CDC_DTYPE_CSInterface},
.Subtype = CDC_DSUBTYPE_CSInterface_Header, .Subtype = CDC_DSUBTYPE_CSInterface_Header,
.CDCSpecification = VERSION_BCD(1,1,0), .CDCSpecification = VERSION_BCD(1, 1, 0),
}, },
.CDC_Functional_ACM = .CDC_Functional_ACM = {
{ .Header = { .Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = CDC_DTYPE_CSInterface },
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = CDC_DTYPE_CSInterface},
.Subtype = CDC_DSUBTYPE_CSInterface_ACM, .Subtype = CDC_DSUBTYPE_CSInterface_ACM,
.Capabilities = 0x06, .Capabilities = 0x06,
}, },
.CDC_Functional_Union = .CDC_Functional_Union = {
{ .Header = { .Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = CDC_DTYPE_CSInterface },
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = CDC_DTYPE_CSInterface},
.Subtype = CDC_DSUBTYPE_CSInterface_Union, .Subtype = CDC_DSUBTYPE_CSInterface_Union,
.MasterInterfaceNumber = INTERFACE_ID_CDC_CCI, .MasterInterfaceNumber = INTERFACE_ID_CDC_CCI,
.SlaveInterfaceNumber = INTERFACE_ID_CDC_DCI, .SlaveInterfaceNumber = INTERFACE_ID_CDC_DCI,
}, },
.CDC_NotificationEndpoint = .CDC_NotificationEndpoint = { .Header = { .Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint },
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = CDC_NOTIFICATION_EPADDR, .EndpointAddress = CDC_NOTIFICATION_EPADDR,
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_NOTIFICATION_EPSIZE, .EndpointSize = CDC_NOTIFICATION_EPSIZE,
.PollingIntervalMS = 0xFF .PollingIntervalMS = 0xFF },
},
.CDC_DCI_Interface = .CDC_DCI_Interface = { .Header = { .Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface },
{
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
.InterfaceNumber = INTERFACE_ID_CDC_DCI, .InterfaceNumber = INTERFACE_ID_CDC_DCI,
.AlternateSetting = 0, .AlternateSetting = 0,
@ -151,28 +135,21 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
.SubClass = CDC_CSCP_NoDataSubclass, .SubClass = CDC_CSCP_NoDataSubclass,
.Protocol = CDC_CSCP_NoDataProtocol, .Protocol = CDC_CSCP_NoDataProtocol,
.InterfaceStrIndex = NO_DESCRIPTOR .InterfaceStrIndex = NO_DESCRIPTOR },
},
.CDC_DataOutEndpoint = .CDC_DataOutEndpoint = { .Header = { .Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint },
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = CDC_RX_EPADDR, .EndpointAddress = CDC_RX_EPADDR,
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE, .EndpointSize = CDC_TXRX_EPSIZE,
.PollingIntervalMS = 0x05 .PollingIntervalMS = 0x05 },
},
.CDC_DataInEndpoint = .CDC_DataInEndpoint = { .Header = { .Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint },
{
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
.EndpointAddress = CDC_TX_EPADDR, .EndpointAddress = CDC_TX_EPADDR,
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA), .Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
.EndpointSize = CDC_TXRX_EPSIZE, .EndpointSize = CDC_TXRX_EPSIZE,
.PollingIntervalMS = 0x05 .PollingIntervalMS = 0x05 }
}
}; };
/** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests /** Language descriptor structure. This descriptor, located in FLASH memory, is returned when the host requests
@ -191,7 +168,7 @@ const USB_Descriptor_String_t PROGMEM ManufacturerString = USB_STRING_DESCRIPTOR
* and is read out upon request by the host when the appropriate string ID is requested, listed in the Device * and is read out upon request by the host when the appropriate string ID is requested, listed in the Device
* Descriptor. * Descriptor.
*/ */
const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"Original Prusa i3 MK3 Multi Material 2.0 upgrade"); const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"Original Prusa i3 MK3 Multi Material 2.0 upgrade 🐑");
/** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors" /** This function is called by the library when in device mode, and must be overridden (see library "USB Descriptors"
* documentation) by the application code so that the address and size of a requested descriptor can be given * documentation) by the application code so that the address and size of a requested descriptor can be given
@ -201,16 +178,14 @@ const USB_Descriptor_String_t PROGMEM ProductString = USB_STRING_DESCRIPTOR(L"Or
*/ */
uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue, uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
const uint16_t wIndex, const uint16_t wIndex,
const void** const DescriptorAddress) const void **const DescriptorAddress) {
{
const uint8_t DescriptorType = (wValue >> 8); const uint8_t DescriptorType = (wValue >> 8);
const uint8_t DescriptorNumber = (wValue & 0xFF); const uint8_t DescriptorNumber = (wValue & 0xFF);
const void* Address = NULL; const void *Address = NULL;
uint16_t Size = NO_DESCRIPTOR; uint16_t Size = NO_DESCRIPTOR;
switch (DescriptorType) switch (DescriptorType) {
{
case DTYPE_Device: case DTYPE_Device:
Address = &DeviceDescriptor; Address = &DeviceDescriptor;
Size = sizeof(USB_Descriptor_Device_t); Size = sizeof(USB_Descriptor_Device_t);
@ -220,8 +195,7 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
Size = sizeof(USB_Descriptor_Configuration_t); Size = sizeof(USB_Descriptor_Configuration_t);
break; break;
case DTYPE_String: case DTYPE_String:
switch (DescriptorNumber) switch (DescriptorNumber) {
{
case STRING_ID_Language: case STRING_ID_Language:
Address = &LanguageString; Address = &LanguageString;
Size = pgm_read_byte(&LanguageString.Header.Size); Size = pgm_read_byte(&LanguageString.Header.Size);
@ -242,4 +216,3 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
*DescriptorAddress = Address; *DescriptorAddress = Address;
return Size; return Size;
} }

View File

@ -47,34 +47,29 @@ extern "C" {
* passed to all CDC Class driver functions, so that multiple instances of the same class * passed to all CDC Class driver functions, so that multiple instances of the same class
* within a device can be differentiated from one another. * within a device can be differentiated from one another.
*/ */
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = {
{ .Config = {
.Config =
{
.ControlInterfaceNumber = INTERFACE_ID_CDC_CCI, .ControlInterfaceNumber = INTERFACE_ID_CDC_CCI,
.DataINEndpoint = .DataINEndpoint = {
{
.Address = CDC_TX_EPADDR, .Address = CDC_TX_EPADDR,
.Size = CDC_TXRX_EPSIZE, .Size = CDC_TXRX_EPSIZE,
.Type = EP_TYPE_BULK, .Type = EP_TYPE_BULK,
.Banks = 1, .Banks = 1,
}, },
.DataOUTEndpoint = .DataOUTEndpoint = {
{
.Address = CDC_RX_EPADDR, .Address = CDC_RX_EPADDR,
.Size = CDC_TXRX_EPSIZE, .Size = CDC_TXRX_EPSIZE,
.Type = EP_TYPE_BULK, .Type = EP_TYPE_BULK,
.Banks = 1, .Banks = 1,
}, },
.NotificationEndpoint = .NotificationEndpoint = {
{
.Address = CDC_NOTIFICATION_EPADDR, .Address = CDC_NOTIFICATION_EPADDR,
.Size = CDC_NOTIFICATION_EPSIZE, .Size = CDC_NOTIFICATION_EPSIZE,
.Type = EP_TYPE_INTERRUPT, .Type = EP_TYPE_INTERRUPT,
.Banks = 1, .Banks = 1,
}, },
}, },
}; };
// void testFunc1(uint8_t i) { // void testFunc1(uint8_t i) {
// char str[30]; // char str[30];
@ -89,20 +84,17 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
// } // }
/** Event handler for the library USB Connection event. */ /** Event handler for the library USB Connection event. */
void EVENT_USB_Device_Connect(void) void EVENT_USB_Device_Connect(void) {
{
hal::usart::usart1.puts("EVENT_USB_Device_Connect\n"); hal::usart::usart1.puts("EVENT_USB_Device_Connect\n");
} }
/** Event handler for the library USB Disconnection event. */ /** Event handler for the library USB Disconnection event. */
void EVENT_USB_Device_Disconnect(void) void EVENT_USB_Device_Disconnect(void) {
{
hal::usart::usart1.puts("EVENT_USB_Device_Disconnect\n"); hal::usart::usart1.puts("EVENT_USB_Device_Disconnect\n");
} }
/** Event handler for the library USB Configuration Changed event. */ /** Event handler for the library USB Configuration Changed event. */
void EVENT_USB_Device_ConfigurationChanged(void) void EVENT_USB_Device_ConfigurationChanged(void) {
{
bool ConfigSuccess = true; bool ConfigSuccess = true;
ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface); ConfigSuccess &= CDC_Device_ConfigureEndpoints(&VirtualSerial_CDC_Interface);
@ -115,8 +107,7 @@ void EVENT_USB_Device_ConfigurationChanged(void)
} }
/** Event handler for the library USB Control Request reception event. */ /** Event handler for the library USB Control Request reception event. */
void EVENT_USB_Device_ControlRequest(void) void EVENT_USB_Device_ControlRequest(void) {
{
hal::usart::usart1.puts("EVENT_USB_Device_ControlRequest\n"); hal::usart::usart1.puts("EVENT_USB_Device_ControlRequest\n");
CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface); CDC_Device_ProcessControlRequest(&VirtualSerial_CDC_Interface);
} }
@ -126,8 +117,8 @@ void EVENT_USB_Device_ControlRequest(void)
* *
* \param[in] CDCInterfaceInfo Pointer to the CDC class interface configuration structure being referenced * \param[in] CDCInterfaceInfo Pointer to the CDC class interface configuration structure being referenced
*/ */
void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t *const CDCInterfaceInfo) void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t *const CDCInterfaceInfo) {
{ hal::usart::usart1.puts("EVENT_CDC_Device_ControLineStateChanged\n");
/* You can get changes to the virtual CDC lines in this callback; a common /* You can get changes to the virtual CDC lines in this callback; a common
use-case is to use the Data Terminal Ready (DTR) flag to enable and use-case is to use the Data Terminal Ready (DTR) flag to enable and
disable CDC communications in your application when set to avoid the disable CDC communications in your application when set to avoid the
@ -135,10 +126,16 @@ void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t *const C
in the pending data from the USB endpoints. in the pending data from the USB endpoints.
*/ */
bool HostReady = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR) != 0; bool HostReady = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR) != 0;
char str[50];
(void)HostReady; sprintf_P(str, PSTR("DTR:%hu\n"), HostReady);
hal::usart::usart1.puts(str);
} }
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t *const CDCInterfaceInfo) {
char str[50];
sprintf_P(str, PSTR("baud:%lu\n"), CDCInterfaceInfo->State.LineEncoding.BaudRateBPS);
hal::usart::usart1.puts(str);
}
} }
/// Global instance of the protocol codec /// Global instance of the protocol codec