Fix formatting and 🐑
parent
895671aeb2
commit
9611db9f53
|
|
@ -37,17 +37,15 @@
|
|||
|
||||
#include "Descriptors.h"
|
||||
|
||||
|
||||
/** Device descriptor structure. This descriptor, located in FLASH memory, describes the overall
|
||||
* 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
|
||||
* process begins.
|
||||
*/
|
||||
const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Device_t), .Type = DTYPE_Device},
|
||||
const USB_Descriptor_Device_t PROGMEM DeviceDescriptor = {
|
||||
.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,
|
||||
.SubClass = CDC_CSCP_NoSpecificSubclass,
|
||||
.Protocol = CDC_CSCP_NoSpecificProtocol,
|
||||
|
|
@ -56,7 +54,7 @@ const USB_Descriptor_Device_t PROGMEM DeviceDescriptor =
|
|||
|
||||
.VendorID = 0x2C99,
|
||||
.ProductID = 0x0004,
|
||||
.ReleaseNumber = VERSION_BCD(0,0,1),
|
||||
.ReleaseNumber = VERSION_BCD(0, 0, 1),
|
||||
|
||||
.ManufacturerStrIndex = STRING_ID_Manufacturer,
|
||||
.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
|
||||
* a configuration so that the host may correctly communicate with the USB device.
|
||||
*/
|
||||
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration},
|
||||
const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor = {
|
||||
.Config = {
|
||||
.Header = { .Size = sizeof(USB_Descriptor_Configuration_Header_t), .Type = DTYPE_Configuration },
|
||||
|
||||
.TotalConfigurationSize = sizeof(USB_Descriptor_Configuration_t),
|
||||
.TotalInterfaces = 2,
|
||||
|
|
@ -84,12 +80,9 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||
|
||||
.ConfigAttributes = (USB_CONFIG_ATTR_RESERVED | USB_CONFIG_ATTR_SELFPOWERED),
|
||||
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100)
|
||||
},
|
||||
.MaxPowerConsumption = USB_CONFIG_POWER_MA(100) },
|
||||
|
||||
.CDC_CCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
.CDC_CCI_Interface = { .Header = { .Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface },
|
||||
|
||||
.InterfaceNumber = INTERFACE_ID_CDC_CCI,
|
||||
.AlternateSetting = 0,
|
||||
|
|
@ -100,47 +93,38 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||
.SubClass = CDC_CSCP_ACMSubclass,
|
||||
.Protocol = CDC_CSCP_ATCommandProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR },
|
||||
|
||||
.CDC_Functional_Header =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = CDC_DTYPE_CSInterface},
|
||||
.CDC_Functional_Header = {
|
||||
.Header = { .Size = sizeof(USB_CDC_Descriptor_FunctionalHeader_t), .Type = CDC_DTYPE_CSInterface },
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Header,
|
||||
|
||||
.CDCSpecification = VERSION_BCD(1,1,0),
|
||||
.CDCSpecification = VERSION_BCD(1, 1, 0),
|
||||
},
|
||||
|
||||
.CDC_Functional_ACM =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = CDC_DTYPE_CSInterface},
|
||||
.CDC_Functional_ACM = {
|
||||
.Header = { .Size = sizeof(USB_CDC_Descriptor_FunctionalACM_t), .Type = CDC_DTYPE_CSInterface },
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_ACM,
|
||||
|
||||
.Capabilities = 0x06,
|
||||
},
|
||||
|
||||
.CDC_Functional_Union =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = CDC_DTYPE_CSInterface},
|
||||
.CDC_Functional_Union = {
|
||||
.Header = { .Size = sizeof(USB_CDC_Descriptor_FunctionalUnion_t), .Type = CDC_DTYPE_CSInterface },
|
||||
.Subtype = CDC_DSUBTYPE_CSInterface_Union,
|
||||
|
||||
.MasterInterfaceNumber = INTERFACE_ID_CDC_CCI,
|
||||
.SlaveInterfaceNumber = INTERFACE_ID_CDC_DCI,
|
||||
},
|
||||
|
||||
.CDC_NotificationEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
.CDC_NotificationEndpoint = { .Header = { .Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint },
|
||||
|
||||
.EndpointAddress = CDC_NOTIFICATION_EPADDR,
|
||||
.Attributes = (EP_TYPE_INTERRUPT | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_NOTIFICATION_EPSIZE,
|
||||
.PollingIntervalMS = 0xFF
|
||||
},
|
||||
.PollingIntervalMS = 0xFF },
|
||||
|
||||
.CDC_DCI_Interface =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface},
|
||||
.CDC_DCI_Interface = { .Header = { .Size = sizeof(USB_Descriptor_Interface_t), .Type = DTYPE_Interface },
|
||||
|
||||
.InterfaceNumber = INTERFACE_ID_CDC_DCI,
|
||||
.AlternateSetting = 0,
|
||||
|
|
@ -151,28 +135,21 @@ const USB_Descriptor_Configuration_t PROGMEM ConfigurationDescriptor =
|
|||
.SubClass = CDC_CSCP_NoDataSubclass,
|
||||
.Protocol = CDC_CSCP_NoDataProtocol,
|
||||
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR
|
||||
},
|
||||
.InterfaceStrIndex = NO_DESCRIPTOR },
|
||||
|
||||
.CDC_DataOutEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
.CDC_DataOutEndpoint = { .Header = { .Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint },
|
||||
|
||||
.EndpointAddress = CDC_RX_EPADDR,
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_TXRX_EPSIZE,
|
||||
.PollingIntervalMS = 0x05
|
||||
},
|
||||
.PollingIntervalMS = 0x05 },
|
||||
|
||||
.CDC_DataInEndpoint =
|
||||
{
|
||||
.Header = {.Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint},
|
||||
.CDC_DataInEndpoint = { .Header = { .Size = sizeof(USB_Descriptor_Endpoint_t), .Type = DTYPE_Endpoint },
|
||||
|
||||
.EndpointAddress = CDC_TX_EPADDR,
|
||||
.Attributes = (EP_TYPE_BULK | ENDPOINT_ATTR_NO_SYNC | ENDPOINT_USAGE_DATA),
|
||||
.EndpointSize = CDC_TXRX_EPSIZE,
|
||||
.PollingIntervalMS = 0x05
|
||||
}
|
||||
.PollingIntervalMS = 0x05 }
|
||||
};
|
||||
|
||||
/** 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
|
||||
* 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"
|
||||
* 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,
|
||||
const uint16_t wIndex,
|
||||
const void** const DescriptorAddress)
|
||||
{
|
||||
const void **const DescriptorAddress) {
|
||||
const uint8_t DescriptorType = (wValue >> 8);
|
||||
const uint8_t DescriptorNumber = (wValue & 0xFF);
|
||||
|
||||
const void* Address = NULL;
|
||||
const void *Address = NULL;
|
||||
uint16_t Size = NO_DESCRIPTOR;
|
||||
|
||||
switch (DescriptorType)
|
||||
{
|
||||
switch (DescriptorType) {
|
||||
case DTYPE_Device:
|
||||
Address = &DeviceDescriptor;
|
||||
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);
|
||||
break;
|
||||
case DTYPE_String:
|
||||
switch (DescriptorNumber)
|
||||
{
|
||||
switch (DescriptorNumber) {
|
||||
case STRING_ID_Language:
|
||||
Address = &LanguageString;
|
||||
Size = pgm_read_byte(&LanguageString.Header.Size);
|
||||
|
|
@ -242,4 +216,3 @@ uint16_t CALLBACK_USB_GetDescriptor(const uint16_t wValue,
|
|||
*DescriptorAddress = Address;
|
||||
return Size;
|
||||
}
|
||||
|
||||
|
|
|
|||
43
src/main.cpp
43
src/main.cpp
|
|
@ -47,34 +47,29 @@ extern "C" {
|
|||
* passed to all CDC Class driver functions, so that multiple instances of the same class
|
||||
* within a device can be differentiated from one another.
|
||||
*/
|
||||
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
|
||||
{
|
||||
.Config =
|
||||
{
|
||||
USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = {
|
||||
.Config = {
|
||||
.ControlInterfaceNumber = INTERFACE_ID_CDC_CCI,
|
||||
.DataINEndpoint =
|
||||
{
|
||||
.DataINEndpoint = {
|
||||
.Address = CDC_TX_EPADDR,
|
||||
.Size = CDC_TXRX_EPSIZE,
|
||||
.Type = EP_TYPE_BULK,
|
||||
.Banks = 1,
|
||||
},
|
||||
.DataOUTEndpoint =
|
||||
{
|
||||
.DataOUTEndpoint = {
|
||||
.Address = CDC_RX_EPADDR,
|
||||
.Size = CDC_TXRX_EPSIZE,
|
||||
.Type = EP_TYPE_BULK,
|
||||
.Banks = 1,
|
||||
},
|
||||
.NotificationEndpoint =
|
||||
{
|
||||
.NotificationEndpoint = {
|
||||
.Address = CDC_NOTIFICATION_EPADDR,
|
||||
.Size = CDC_NOTIFICATION_EPSIZE,
|
||||
.Type = EP_TYPE_INTERRUPT,
|
||||
.Banks = 1,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// void testFunc1(uint8_t i) {
|
||||
// char str[30];
|
||||
|
|
@ -89,20 +84,17 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
|
|||
// }
|
||||
|
||||
/** 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");
|
||||
}
|
||||
|
||||
/** 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");
|
||||
}
|
||||
|
||||
/** Event handler for the library USB Configuration Changed event. */
|
||||
void EVENT_USB_Device_ConfigurationChanged(void)
|
||||
{
|
||||
void EVENT_USB_Device_ConfigurationChanged(void) {
|
||||
bool ConfigSuccess = true;
|
||||
|
||||
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. */
|
||||
void EVENT_USB_Device_ControlRequest(void)
|
||||
{
|
||||
void EVENT_USB_Device_ControlRequest(void) {
|
||||
hal::usart::usart1.puts("EVENT_USB_Device_ControlRequest\n");
|
||||
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
|
||||
*/
|
||||
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
|
||||
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
|
||||
|
|
@ -135,10 +126,16 @@ void EVENT_CDC_Device_ControLineStateChanged(USB_ClassInfo_CDC_Device_t *const C
|
|||
in the pending data from the USB endpoints.
|
||||
*/
|
||||
bool HostReady = (CDCInterfaceInfo->State.ControlLineStates.HostToDevice & CDC_CONTROL_LINE_OUT_DTR) != 0;
|
||||
|
||||
(void)HostReady;
|
||||
char str[50];
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue