mirror of
https://github.com/im-tomu/foboot.git
synced 2024-09-20 02:40:09 +00:00
sw: get usb working with eptri
This commit is the final commit necessary to get foboot working with the new eptri api. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
1ee442d407
commit
d4b1a64dca
@ -20,7 +20,7 @@ void usb_setup(const struct usb_setup_request *setup);
|
||||
void usb_send(uint8_t epno, const void *data, int total_count);
|
||||
void usb_ack(uint8_t ep);
|
||||
void usb_err(uint8_t ep);
|
||||
int usb_recv(void *buffer, unsigned int buffer_len);
|
||||
int usb_recv(void *buffer, int buffer_len);
|
||||
void usb_poll(void);
|
||||
void usb_wait_for_send_done(void);
|
||||
void usb_set_address(uint8_t new_address);
|
||||
|
@ -14,7 +14,7 @@ static uint32_t rx_buffer[USB_MAX_PACKET_SIZE/4];
|
||||
|
||||
void usb_setup(const struct usb_setup_request *setup)
|
||||
{
|
||||
uint8_t ep_dir = ((const uint8_t *)setup)[0] >> 7;
|
||||
uint8_t ep_dir = setup->bmRequestType >> 7;
|
||||
const uint8_t *data = NULL;
|
||||
uint32_t datalen = 0;
|
||||
const usb_descriptor_list_t *list;
|
||||
@ -142,9 +142,6 @@ void usb_setup(const struct usb_setup_request *setup)
|
||||
return;
|
||||
}
|
||||
|
||||
// ACK the setup packet
|
||||
usb_ack(1);
|
||||
|
||||
int bytes_remaining = setup->wLength;
|
||||
int ep0_rx_offset = 0;
|
||||
// Fill the buffer, or if there is enough space transfer the whole packet.
|
||||
@ -158,8 +155,9 @@ void usb_setup(const struct usb_setup_request *setup)
|
||||
|
||||
// Receive DATA packets (which are automatically ACKed)
|
||||
len = usb_recv((void *)rx_buffer, len);
|
||||
if (len == -1)
|
||||
if (len == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Append the data to the download buffer.
|
||||
dfu_download(blockNum, blockLength, ep0_rx_offset, len, (void *)rx_buffer);
|
||||
@ -200,10 +198,7 @@ void usb_setup(const struct usb_setup_request *setup)
|
||||
// once the host acknowledges the packet.
|
||||
if (reply_buffer[4] == 8) {
|
||||
usb_send(0, data, datalen);
|
||||
usb_wait_for_send_done();
|
||||
int i;
|
||||
for (i = 0; i < 10000; i++)
|
||||
asm("nop");
|
||||
usb_recv((void *)rx_buffer, sizeof(rx_buffer));
|
||||
reboot();
|
||||
}
|
||||
break;
|
||||
|
@ -222,7 +222,7 @@ void usb_err(uint8_t epdir) {
|
||||
usb_ep_0_in_respond_write(EPF_STALL);
|
||||
}
|
||||
|
||||
int usb_recv(void *buffer, unsigned int buffer_len) {
|
||||
int usb_recv(void *buffer, int buffer_len) {
|
||||
|
||||
// Set the OUT response to ACK, since we are in a position to receive data now.
|
||||
usb_ep_0_out_respond_write(EPF_ACK);
|
||||
|
@ -233,10 +233,10 @@ void usb_isr(void) {
|
||||
if (!(usb_setup_status_read() & (1 << CSR_USB_SETUP_STATUS_HAVE_OFFSET)))
|
||||
rgb_mode_error();
|
||||
previous_setup_length = setup_length;
|
||||
memcpy(previous_setup_packet, setup_packet, sizeof(setup_packet));
|
||||
memcpy((void *)previous_setup_packet, (void *)setup_packet, sizeof(setup_packet));
|
||||
|
||||
setup_length = 0;
|
||||
memset(setup_packet, 0, sizeof(setup_packet));
|
||||
memset((void *)setup_packet, 0, sizeof(setup_packet));
|
||||
while (usb_setup_status_read() & (1 << CSR_USB_SETUP_STATUS_HAVE_OFFSET)) {
|
||||
setup_packet[setup_length++] = usb_setup_data_read();
|
||||
}
|
||||
@ -297,16 +297,16 @@ void usb_err(uint8_t ep) {
|
||||
usb_out_ctrl_write(1 << CSR_USB_OUT_CTRL_STALL_OFFSET);
|
||||
}
|
||||
|
||||
int usb_recv(void *buffer, unsigned int buffer_len) {
|
||||
int usb_recv(void *buffer, int buffer_len) {
|
||||
// Set the OUT response to ACK, since we are in a position to receive data now.
|
||||
if (out_have) {
|
||||
usb_ack(0);
|
||||
}
|
||||
while (1) {
|
||||
if (out_buffer_length) {
|
||||
if (out_have) {
|
||||
if (buffer_len > out_buffer_length)
|
||||
buffer_len = out_buffer_length;
|
||||
memcpy(buffer, out_buffer, buffer_len);
|
||||
memcpy(buffer, (void *)out_buffer, buffer_len);
|
||||
usb_ack(0);
|
||||
return buffer_len;
|
||||
}
|
||||
@ -321,7 +321,7 @@ void usb_poll(void) {
|
||||
// If some data was received, then process it.
|
||||
if (setup_length) {
|
||||
setup_length = 0;
|
||||
usb_setup(setup_packet);
|
||||
usb_setup((const struct usb_setup_request *)setup_packet);
|
||||
}
|
||||
|
||||
// process_tx();
|
||||
|
Loading…
Reference in New Issue
Block a user