Removed string descriptor buffer
This commit is contained in:
parent
d43800a156
commit
f809f06f2f
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
/*- Includes ----------------------------------------------------------------*/
|
/*- Includes ----------------------------------------------------------------*/
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdalign.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "udc.h"
|
#include "udc.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
@ -115,18 +116,21 @@ void usb_handle_standard_request(usb_request_t *request)
|
|||||||
{
|
{
|
||||||
const char *str = usb_strings[index];
|
const char *str = usb_strings[index];
|
||||||
int len = strlen(str);
|
int len = strlen(str);
|
||||||
|
int size = len*2 + 2;
|
||||||
|
alignas(4) uint8_t buf[size];
|
||||||
|
|
||||||
memset(usb_string_descriptor_buffer, 0, sizeof(usb_string_descriptor_buffer));
|
buf[0] = size;
|
||||||
|
buf[1] = USB_STRING_DESCRIPTOR;
|
||||||
usb_string_descriptor_buffer[0] = len*2 + 2;
|
|
||||||
usb_string_descriptor_buffer[1] = USB_STRING_DESCRIPTOR;
|
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
usb_string_descriptor_buffer[2 + i*2] = str[i];
|
{
|
||||||
|
buf[2 + i*2] = str[i];
|
||||||
|
buf[3 + i*2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
length = LIMIT(length, usb_string_descriptor_buffer[0]);
|
length = LIMIT(length, size);
|
||||||
|
|
||||||
udc_control_send(usb_string_descriptor_buffer, length);
|
udc_control_send(buf, length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -134,7 +138,9 @@ void usb_handle_standard_request(usb_request_t *request)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
udc_control_stall();
|
udc_control_stall();
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case USB_CMD(OUT, DEVICE, STANDARD, SET_ADDRESS):
|
case USB_CMD(OUT, DEVICE, STANDARD, SET_ADDRESS):
|
||||||
|
|||||||
@ -148,5 +148,3 @@ const char *const usb_strings[] =
|
|||||||
[USB_STR_INTERFACE] = "Main Interface",
|
[USB_STR_INTERFACE] = "Main Interface",
|
||||||
};
|
};
|
||||||
|
|
||||||
alignas(4) uint8_t usb_string_descriptor_buffer[64];
|
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,6 @@ extern const usb_configuration_hierarchy_t usb_configuration_hierarchy;
|
|||||||
extern const uint8_t usb_hid_report_descriptor[33];
|
extern const uint8_t usb_hid_report_descriptor[33];
|
||||||
extern const usb_string_descriptor_zero_t usb_string_descriptor_zero;
|
extern const usb_string_descriptor_zero_t usb_string_descriptor_zero;
|
||||||
extern const char *const usb_strings[];
|
extern const char *const usb_strings[];
|
||||||
extern uint8_t usb_string_descriptor_buffer[64];
|
|
||||||
|
|
||||||
#endif // _USB_DESCRIPTORS_H_
|
#endif // _USB_DESCRIPTORS_H_
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdalign.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "samd21.h"
|
#include "samd21.h"
|
||||||
#include "hal_gpio.h"
|
#include "hal_gpio.h"
|
||||||
@ -43,8 +44,8 @@
|
|||||||
#define APP_EP_RECV 2
|
#define APP_EP_RECV 2
|
||||||
|
|
||||||
/*- Variables ---------------------------------------------------------------*/
|
/*- Variables ---------------------------------------------------------------*/
|
||||||
ALIGNED(4) uint8_t app_request_buffer[DAP_CONFIG_PACKET_SIZE];
|
alignas(4) uint8_t app_request_buffer[DAP_CONFIG_PACKET_SIZE];
|
||||||
ALIGNED(4) uint8_t app_response_buffer[DAP_CONFIG_PACKET_SIZE];
|
alignas(4) uint8_t app_response_buffer[DAP_CONFIG_PACKET_SIZE];
|
||||||
|
|
||||||
/*- Implementations ---------------------------------------------------------*/
|
/*- Implementations ---------------------------------------------------------*/
|
||||||
|
|
||||||
|
|||||||
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
/*- Includes ----------------------------------------------------------------*/
|
/*- Includes ----------------------------------------------------------------*/
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdalign.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "udc.h"
|
#include "udc.h"
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
@ -115,18 +116,21 @@ void usb_handle_standard_request(usb_request_t *request)
|
|||||||
{
|
{
|
||||||
const char *str = usb_strings[index];
|
const char *str = usb_strings[index];
|
||||||
int len = strlen(str);
|
int len = strlen(str);
|
||||||
|
int size = len*2 + 2;
|
||||||
|
alignas(4) uint8_t buf[size];
|
||||||
|
|
||||||
memset(usb_string_descriptor_buffer, 0, sizeof(usb_string_descriptor_buffer));
|
buf[0] = size;
|
||||||
|
buf[1] = USB_STRING_DESCRIPTOR;
|
||||||
usb_string_descriptor_buffer[0] = len*2 + 2;
|
|
||||||
usb_string_descriptor_buffer[1] = USB_STRING_DESCRIPTOR;
|
|
||||||
|
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
usb_string_descriptor_buffer[2 + i*2] = str[i];
|
{
|
||||||
|
buf[2 + i*2] = str[i];
|
||||||
|
buf[3 + i*2] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
length = LIMIT(length, usb_string_descriptor_buffer[0]);
|
length = LIMIT(length, size);
|
||||||
|
|
||||||
udc_control_send(usb_string_descriptor_buffer, length);
|
udc_control_send(buf, length);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,11 +28,12 @@
|
|||||||
|
|
||||||
|
|
||||||
/*- Includes ----------------------------------------------------------------*/
|
/*- Includes ----------------------------------------------------------------*/
|
||||||
|
#include <stdalign.h>
|
||||||
#include "usb.h"
|
#include "usb.h"
|
||||||
#include "usb_descriptors.h"
|
#include "usb_descriptors.h"
|
||||||
|
|
||||||
/*- Variables ---------------------------------------------------------------*/
|
/*- Variables ---------------------------------------------------------------*/
|
||||||
ALIGNED(4) const usb_device_descriptor_t usb_device_descriptor =
|
const alignas(4) usb_device_descriptor_t usb_device_descriptor =
|
||||||
{
|
{
|
||||||
.bLength = sizeof(usb_device_descriptor_t),
|
.bLength = sizeof(usb_device_descriptor_t),
|
||||||
.bDescriptorType = USB_DEVICE_DESCRIPTOR,
|
.bDescriptorType = USB_DEVICE_DESCRIPTOR,
|
||||||
@ -50,7 +51,7 @@ ALIGNED(4) const usb_device_descriptor_t usb_device_descriptor =
|
|||||||
.bNumConfigurations = 1,
|
.bNumConfigurations = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
ALIGNED(4) const usb_configuration_hierarchy_t usb_configuration_hierarchy =
|
const alignas(4) usb_configuration_hierarchy_t usb_configuration_hierarchy =
|
||||||
{
|
{
|
||||||
.configuration =
|
.configuration =
|
||||||
{
|
{
|
||||||
@ -109,7 +110,7 @@ ALIGNED(4) const usb_configuration_hierarchy_t usb_configuration_hierarchy =
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
ALIGNED(4) const uint8_t usb_hid_report_descriptor[33] =
|
const alignas(4) uint8_t usb_hid_report_descriptor[33] =
|
||||||
{
|
{
|
||||||
0x06, 0x00, 0xff, // Usage Page (Vendor Defined 0xFF00)
|
0x06, 0x00, 0xff, // Usage Page (Vendor Defined 0xFF00)
|
||||||
0x09, 0x01, // Usage (0x01)
|
0x09, 0x01, // Usage (0x01)
|
||||||
@ -129,7 +130,7 @@ ALIGNED(4) const uint8_t usb_hid_report_descriptor[33] =
|
|||||||
0xc0, // End Collection
|
0xc0, // End Collection
|
||||||
};
|
};
|
||||||
|
|
||||||
ALIGNED(4) const usb_string_descriptor_zero_t usb_string_descriptor_zero =
|
const alignas(4) usb_string_descriptor_zero_t usb_string_descriptor_zero =
|
||||||
{
|
{
|
||||||
.bLength = sizeof(usb_string_descriptor_zero_t),
|
.bLength = sizeof(usb_string_descriptor_zero_t),
|
||||||
.bDescriptorType = USB_STRING_DESCRIPTOR,
|
.bDescriptorType = USB_STRING_DESCRIPTOR,
|
||||||
@ -145,5 +146,3 @@ const char *const usb_strings[] =
|
|||||||
[USB_STR_INTERFACE] = "Main Interface",
|
[USB_STR_INTERFACE] = "Main Interface",
|
||||||
};
|
};
|
||||||
|
|
||||||
ALIGNED(4) uint8_t usb_string_descriptor_buffer[64];
|
|
||||||
|
|
||||||
|
|||||||
@ -79,7 +79,6 @@ extern const usb_configuration_hierarchy_t usb_configuration_hierarchy;
|
|||||||
extern const uint8_t usb_hid_report_descriptor[33];
|
extern const uint8_t usb_hid_report_descriptor[33];
|
||||||
extern const usb_string_descriptor_zero_t usb_string_descriptor_zero;
|
extern const usb_string_descriptor_zero_t usb_string_descriptor_zero;
|
||||||
extern const char *const usb_strings[];
|
extern const char *const usb_strings[];
|
||||||
extern uint8_t usb_string_descriptor_buffer[64];
|
|
||||||
|
|
||||||
#endif // _USB_DESCRIPTORS_H_
|
#endif // _USB_DESCRIPTORS_H_
|
||||||
|
|
||||||
|
|||||||
@ -30,8 +30,6 @@
|
|||||||
#define _UTILS_H_
|
#define _UTILS_H_
|
||||||
|
|
||||||
/*- Definitions -------------------------------------------------------------*/
|
/*- Definitions -------------------------------------------------------------*/
|
||||||
#define ALIGNED(a) __attribute__((__aligned__(a)))
|
|
||||||
|
|
||||||
#define PACK __attribute__((packed))
|
#define PACK __attribute__((packed))
|
||||||
|
|
||||||
#define INLINE static inline __attribute__((always_inline))
|
#define INLINE static inline __attribute__((always_inline))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user