USB driver update
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
|||||||
|
2015-07-27 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* src/usb_stm32f103.c (usb_lld_answer_control): New.
|
||||||
|
(usb_lld_set_data_to_send): Remove.
|
||||||
|
(usb_lld_set_data_to_recv): Not a macro but a function.
|
||||||
|
(std_get_status): Don't use statically allocated memory.
|
||||||
|
(std_get_configuration): Use usb_lld_answer_control.
|
||||||
|
(handle_setup0): Follow the change.
|
||||||
|
* src/usb_ctrl.c (vcom_port_data_setup, usb_cb_setup)
|
||||||
|
(usb_cb_interface): Use usb_lld_answer_control.
|
||||||
|
* src/usb_desc.c (usb_cb_get_descriptor): Likewise.
|
||||||
|
|
||||||
2015-07-24 Niibe Yutaka <gniibe@fsij.org>
|
2015-07-24 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* tool/gnuk_put_binary.py: Remove.
|
* tool/gnuk_put_binary.py: Remove.
|
||||||
|
|||||||
@@ -63,10 +63,7 @@ vcom_port_data_setup (uint8_t req, uint8_t req_no, uint16_t value)
|
|||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_CDC_REQ_GET_LINE_CODING)
|
if (req_no == USB_CDC_REQ_GET_LINE_CODING)
|
||||||
{
|
return usb_lld_answer_control (&line_coding, sizeof(line_coding));
|
||||||
usb_lld_set_data_to_send (&line_coding, sizeof(line_coding));
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else /* USB_SETUP_SET (req) */
|
else /* USB_SETUP_SET (req) */
|
||||||
{
|
{
|
||||||
@@ -272,10 +269,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no,
|
|||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_FSIJ_GNUK_MEMINFO)
|
if (req_no == USB_FSIJ_GNUK_MEMINFO)
|
||||||
{
|
return usb_lld_answer_control (mem_info, sizeof (mem_info));
|
||||||
usb_lld_set_data_to_send (mem_info, sizeof (mem_info));
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else /* SETUP_SET */
|
else /* SETUP_SET */
|
||||||
{
|
{
|
||||||
@@ -322,16 +316,10 @@ usb_cb_setup (uint8_t req, uint8_t req_no,
|
|||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == USB_CCID_REQ_GET_CLOCK_FREQUENCIES)
|
if (req_no == USB_CCID_REQ_GET_CLOCK_FREQUENCIES)
|
||||||
{
|
return usb_lld_answer_control (freq_table, sizeof (freq_table));
|
||||||
usb_lld_set_data_to_send (freq_table, sizeof (freq_table));
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
else if (req_no == USB_CCID_REQ_GET_DATA_RATES)
|
else if (req_no == USB_CCID_REQ_GET_DATA_RATES)
|
||||||
{
|
return usb_lld_answer_control (data_rate_table,
|
||||||
usb_lld_set_data_to_send (data_rate_table,
|
sizeof (data_rate_table));
|
||||||
sizeof (data_rate_table));
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -347,16 +335,14 @@ usb_cb_setup (uint8_t req, uint8_t req_no,
|
|||||||
switch (req_no)
|
switch (req_no)
|
||||||
{
|
{
|
||||||
case USB_HID_REQ_GET_IDLE:
|
case USB_HID_REQ_GET_IDLE:
|
||||||
usb_lld_set_data_to_send (&hid_idle_rate, 1);
|
return usb_lld_answer_control (&hid_idle_rate, 1);
|
||||||
return USB_SUCCESS;
|
|
||||||
case USB_HID_REQ_SET_IDLE:
|
case USB_HID_REQ_SET_IDLE:
|
||||||
usb_lld_set_data_to_recv (&hid_idle_rate, 1);
|
usb_lld_set_data_to_recv (&hid_idle_rate, 1);
|
||||||
return USB_SUCCESS;
|
return USB_SUCCESS;
|
||||||
|
|
||||||
case USB_HID_REQ_GET_REPORT:
|
case USB_HID_REQ_GET_REPORT:
|
||||||
/* Request of LED status and key press */
|
/* Request of LED status and key press */
|
||||||
usb_lld_set_data_to_send (&hid_report, 2);
|
return usb_lld_answer_control (&hid_report, 2);
|
||||||
return USB_SUCCESS;
|
|
||||||
|
|
||||||
case USB_HID_REQ_SET_REPORT:
|
case USB_HID_REQ_SET_REPORT:
|
||||||
/* Received LED set request */
|
/* Received LED set request */
|
||||||
@@ -384,10 +370,7 @@ usb_cb_setup (uint8_t req, uint8_t req_no,
|
|||||||
if (USB_SETUP_GET (req))
|
if (USB_SETUP_GET (req))
|
||||||
{
|
{
|
||||||
if (req_no == MSC_GET_MAX_LUN_COMMAND)
|
if (req_no == MSC_GET_MAX_LUN_COMMAND)
|
||||||
{
|
return usb_lld_answer_control (lun_table, sizeof (lun_table));
|
||||||
usb_lld_set_data_to_send (lun_table, sizeof (lun_table));
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (req_no == MSC_MASS_STORAGE_RESET_COMMAND)
|
if (req_no == MSC_MASS_STORAGE_RESET_COMMAND)
|
||||||
@@ -495,9 +478,7 @@ int usb_cb_interface (uint8_t cmd, uint16_t interface, uint16_t alt)
|
|||||||
}
|
}
|
||||||
|
|
||||||
case USB_GET_INTERFACE:
|
case USB_GET_INTERFACE:
|
||||||
usb_lld_write (ENDP0, &zero, 1);
|
return usb_lld_answer_control (&zero, 1);
|
||||||
usb_lld_set_data_to_send (NULL, 1);
|
|
||||||
return USB_SUCCESS;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
case USB_QUERY_INTERFACE:
|
case USB_QUERY_INTERFACE:
|
||||||
|
|||||||
@@ -351,25 +351,16 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
{
|
||||||
if (desc_type == DEVICE_DESCRIPTOR)
|
if (desc_type == DEVICE_DESCRIPTOR)
|
||||||
{
|
return usb_lld_answer_control (gnukDeviceDescriptor,
|
||||||
usb_lld_set_data_to_send (gnukDeviceDescriptor,
|
sizeof (gnukDeviceDescriptor));
|
||||||
sizeof (gnukDeviceDescriptor));
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
else if (desc_type == CONFIG_DESCRIPTOR)
|
else if (desc_type == CONFIG_DESCRIPTOR)
|
||||||
{
|
return usb_lld_answer_control (gnukConfigDescriptor,
|
||||||
usb_lld_set_data_to_send (gnukConfigDescriptor,
|
sizeof (gnukConfigDescriptor));
|
||||||
sizeof (gnukConfigDescriptor));
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
else if (desc_type == STRING_DESCRIPTOR)
|
else if (desc_type == STRING_DESCRIPTOR)
|
||||||
{
|
{
|
||||||
if (desc_index < NUM_STRING_DESC)
|
if (desc_index < NUM_STRING_DESC)
|
||||||
{
|
return usb_lld_answer_control (string_descriptors[desc_index].desc,
|
||||||
usb_lld_set_data_to_send (string_descriptors[desc_index].desc,
|
string_descriptors[desc_index].size);
|
||||||
string_descriptors[desc_index].size);
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
else if (desc_index == NUM_STRING_DESC)
|
else if (desc_index == NUM_STRING_DESC)
|
||||||
{
|
{
|
||||||
uint8_t usbbuf[64];
|
uint8_t usbbuf[64];
|
||||||
@@ -388,9 +379,7 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
usbbuf[1] = USB_STRING_DESCRIPTOR_TYPE;
|
usbbuf[1] = USB_STRING_DESCRIPTOR_TYPE;
|
||||||
if (len > length)
|
if (len > length)
|
||||||
len = length;
|
len = length;
|
||||||
usb_lld_write (ENDP0, usbbuf, len);
|
return usb_lld_answer_control (usbbuf, len);
|
||||||
usb_lld_set_data_to_send (NULL, len);
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,16 +389,9 @@ usb_cb_get_descriptor (uint8_t rcp, uint8_t desc_type, uint8_t desc_index,
|
|||||||
if (index == 1)
|
if (index == 1)
|
||||||
{
|
{
|
||||||
if (desc_type == USB_DT_HID)
|
if (desc_type == USB_DT_HID)
|
||||||
{
|
return usb_lld_answer_control (gnukConfigDescriptor+ICC_TOTAL_LENGTH+9, 9);
|
||||||
usb_lld_set_data_to_send (gnukConfigDescriptor+ICC_TOTAL_LENGTH+9,
|
|
||||||
9);
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
else if (desc_type == USB_DT_REPORT)
|
else if (desc_type == USB_DT_REPORT)
|
||||||
{
|
return usb_lld_answer_control (hid_report_desc, HID_REPORT_DESC_SIZE);
|
||||||
usb_lld_set_data_to_send (hid_report_desc, HID_REPORT_DESC_SIZE);
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ int usb_lld_tx_data_len (int ep_num);
|
|||||||
void usb_lld_txcpy (const void *src, int ep_num, int offset, size_t len);
|
void usb_lld_txcpy (const void *src, int ep_num, int offset, size_t len);
|
||||||
void usb_lld_tx_enable (int ep_num, size_t len);
|
void usb_lld_tx_enable (int ep_num, size_t len);
|
||||||
void usb_lld_write (uint8_t ep_num, const void *buf, size_t len);
|
void usb_lld_write (uint8_t ep_num, const void *buf, size_t len);
|
||||||
|
int usb_lld_answer_control (const void *buf, size_t buflen);
|
||||||
void usb_lld_rx_enable (int ep_num);
|
void usb_lld_rx_enable (int ep_num);
|
||||||
int usb_lld_rx_data_len (int ep_num);
|
int usb_lld_rx_data_len (int ep_num);
|
||||||
void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len);
|
void usb_lld_rxcpy (uint8_t *dst, int ep_num, int offset, size_t len);
|
||||||
@@ -109,12 +110,7 @@ void usb_lld_setup_endpoint (int ep_num, int ep_type, int ep_kind,
|
|||||||
void usb_lld_set_configuration (uint8_t config);
|
void usb_lld_set_configuration (uint8_t config);
|
||||||
uint8_t usb_lld_current_configuration (void);
|
uint8_t usb_lld_current_configuration (void);
|
||||||
void usb_lld_set_feature (uint8_t feature);
|
void usb_lld_set_feature (uint8_t feature);
|
||||||
void usb_lld_set_data_to_send (const void *p, size_t len);
|
void usb_lld_set_data_to_recv (const void *p, size_t len);
|
||||||
|
|
||||||
extern inline void usb_lld_set_data_to_recv (void *p, size_t len)
|
|
||||||
{
|
|
||||||
usb_lld_set_data_to_send ((const void *)p, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
void usb_lld_prepare_shutdown (void);
|
void usb_lld_prepare_shutdown (void);
|
||||||
void usb_lld_shutdown (void);
|
void usb_lld_shutdown (void);
|
||||||
|
|||||||
@@ -488,11 +488,8 @@ static int std_none (uint8_t req,
|
|||||||
static int std_get_status (uint8_t req,
|
static int std_get_status (uint8_t req,
|
||||||
uint16_t value, uint16_t index, uint16_t length)
|
uint16_t value, uint16_t index, uint16_t length)
|
||||||
{
|
{
|
||||||
static uint16_t status_info;
|
|
||||||
uint8_t rcp = req & RECIPIENT;
|
uint8_t rcp = req & RECIPIENT;
|
||||||
|
uint16_t status_info = 0;
|
||||||
status_info = 0; /* Reset Status Information */
|
|
||||||
data_p->addr = (uint8_t *)&status_info;
|
|
||||||
|
|
||||||
if (value != 0 || length != 2 || (index >> 8) != 0
|
if (value != 0 || length != 2 || (index >> 8) != 0
|
||||||
|| (req & REQUEST_DIR) == 0)
|
|| (req & REQUEST_DIR) == 0)
|
||||||
@@ -517,8 +514,7 @@ static int std_get_status (uint8_t req,
|
|||||||
else /* Self-powered */
|
else /* Self-powered */
|
||||||
status_info &= ~1;
|
status_info &= ~1;
|
||||||
|
|
||||||
data_p->len = 2;
|
return usb_lld_answer_control (&status_info, 2);
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (rcp == INTERFACE_RECIPIENT)
|
else if (rcp == INTERFACE_RECIPIENT)
|
||||||
@@ -532,8 +528,7 @@ static int std_get_status (uint8_t req,
|
|||||||
if (r != USB_SUCCESS)
|
if (r != USB_SUCCESS)
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
|
|
||||||
data_p->len = 2;
|
return usb_lld_answer_control (&status_info, 2);
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
}
|
||||||
else if (rcp == ENDPOINT_RECIPIENT)
|
else if (rcp == ENDPOINT_RECIPIENT)
|
||||||
{
|
{
|
||||||
@@ -560,8 +555,7 @@ static int std_get_status (uint8_t req,
|
|||||||
status_info |= 1; /* OUT Endpoint stalled */
|
status_info |= 1; /* OUT Endpoint stalled */
|
||||||
}
|
}
|
||||||
|
|
||||||
data_p->len = 2;
|
return usb_lld_answer_control (&status_info, 2);
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
@@ -712,11 +706,7 @@ static int std_get_configuration (uint8_t req, uint16_t value,
|
|||||||
|
|
||||||
(void)value; (void)index; (void)length;
|
(void)value; (void)index; (void)length;
|
||||||
if (rcp == DEVICE_RECIPIENT)
|
if (rcp == DEVICE_RECIPIENT)
|
||||||
{
|
return usb_lld_answer_control (&dev_p->current_configuration, 1);
|
||||||
data_p->addr = &dev_p->current_configuration;
|
|
||||||
data_p->len = 1;
|
|
||||||
return USB_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
return USB_UNSUPPORT;
|
return USB_UNSUPPORT;
|
||||||
}
|
}
|
||||||
@@ -845,30 +835,7 @@ static void handle_setup0 (void)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (USB_SETUP_GET (ctrl_p->bmRequestType))
|
if (USB_SETUP_GET (ctrl_p->bmRequestType))
|
||||||
{
|
;
|
||||||
uint32_t len = ctrl_p->wLength;
|
|
||||||
|
|
||||||
/* Restrict the data length to be the one host asks for */
|
|
||||||
if (data_p->len > len)
|
|
||||||
data_p->len = len;
|
|
||||||
|
|
||||||
if (data_p->len != 0 && (data_p->len % USB_MAX_PACKET_SIZE) == 0)
|
|
||||||
data_p->require_zlp = TRUE;
|
|
||||||
else
|
|
||||||
data_p->require_zlp = FALSE;
|
|
||||||
|
|
||||||
if (data_p->addr == NULL)
|
|
||||||
{
|
|
||||||
/* usb_lld_wite was called already by the setup callback. */
|
|
||||||
dev_p->state = LAST_IN_DATA;
|
|
||||||
data_p->len = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dev_p->state = IN_DATA;
|
|
||||||
handle_datastage_in ();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (ctrl_p->wLength == 0)
|
else if (ctrl_p->wLength == 0)
|
||||||
{
|
{
|
||||||
dev_p->state = WAIT_STATUS_IN;
|
dev_p->state = WAIT_STATUS_IN;
|
||||||
@@ -1121,7 +1088,7 @@ void usb_lld_set_feature (uint8_t feature)
|
|||||||
dev_p->current_feature = feature;
|
dev_p->current_feature = feature;
|
||||||
}
|
}
|
||||||
|
|
||||||
void usb_lld_set_data_to_send (const void *p, size_t len)
|
void usb_lld_set_data_to_recv (const void *p, size_t len)
|
||||||
{
|
{
|
||||||
data_p->addr = (uint8_t *)p;
|
data_p->addr = (uint8_t *)p;
|
||||||
data_p->len = len;
|
data_p->len = len;
|
||||||
@@ -1199,3 +1166,51 @@ void usb_lld_from_pmabuf (void *dst, uint16_t addr, size_t n)
|
|||||||
*d = (w & 0xff);
|
*d = (w & 0xff);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* BUF: Pointer to data memory. Data memory should not be allocated
|
||||||
|
* on stack when BUFLEN > USB_MAX_PACKET_SIZE.
|
||||||
|
*
|
||||||
|
* BUFLEN: size of the data.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
usb_lld_answer_control (const void *buf, size_t buflen)
|
||||||
|
{
|
||||||
|
uint32_t len_asked = ctrl_p->wLength;
|
||||||
|
uint32_t len;
|
||||||
|
|
||||||
|
data_p->addr = (void *)buf;
|
||||||
|
data_p->len = buflen;
|
||||||
|
|
||||||
|
/* Restrict the data length to be the one host asks for */
|
||||||
|
if (data_p->len > len_asked)
|
||||||
|
data_p->len = len_asked;
|
||||||
|
|
||||||
|
if (data_p->len != 0 && (data_p->len % USB_MAX_PACKET_SIZE) == 0)
|
||||||
|
data_p->require_zlp = TRUE;
|
||||||
|
else
|
||||||
|
data_p->require_zlp = FALSE;
|
||||||
|
|
||||||
|
if (data_p->len < USB_MAX_PACKET_SIZE)
|
||||||
|
{
|
||||||
|
len = data_p->len;
|
||||||
|
dev_p->state = LAST_IN_DATA;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
len = USB_MAX_PACKET_SIZE;
|
||||||
|
dev_p->state = IN_DATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len)
|
||||||
|
{
|
||||||
|
usb_lld_to_pmabuf (data_p->addr, st103_get_tx_addr (ENDP0), len);
|
||||||
|
data_p->len -= len;
|
||||||
|
data_p->offset += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
st103_set_tx_count (ENDP0, len);
|
||||||
|
st103_ep_set_tx_status (ENDP0, EP_TX_VALID);
|
||||||
|
return USB_SUCCESS;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user