From 0e28e0eb8d04b9f48452bd6ab333d3738797dbc8 Mon Sep 17 00:00:00 2001 From: Charles Lohr Date: Fri, 7 Oct 2016 22:41:28 -0400 Subject: [PATCH] Make USB play better with subprojects, and allow much larger custom control messages. --- esp82xx | 2 +- user/usb.c | 5 +++-- user/usb.h | 14 +++++++------- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/esp82xx b/esp82xx index 986fb57..153309d 160000 --- a/esp82xx +++ b/esp82xx @@ -1 +1 @@ -Subproject commit 986fb577d02c0e1864ed382191c045f4fa48502d +Subproject commit 153309d8dae0ad377ebddde445dbfae82e6475be diff --git a/user/usb.c b/user/usb.c index d2f95ae..38a74cf 100644 --- a/user/usb.c +++ b/user/usb.c @@ -12,7 +12,7 @@ struct usb_internal_state_struct usb_internal_state __attribute__((aligned(4))); #define ENDPOINT0_SIZE 8 //Fixed for USB 1.1, Low Speed. #define INSTANCE_DESCRIPTORS -#include "usb_config.h" +#include //Received a setup for a specific endpoint. void usb_pid_handle_setup( uint32_t this_token, struct usb_internal_state_struct * ist ) @@ -20,6 +20,8 @@ void usb_pid_handle_setup( uint32_t this_token, struct usb_internal_state_struct uint8_t addr = (this_token>>8) & 0x7f; uint8_t endp = (this_token>>15) & 0xf; + ist->there_is_a_host = 1; + if( endp >= ENDPOINTS ) goto end; if( addr != 0 && addr != ist->my_address ) goto end; @@ -246,6 +248,5 @@ void ICACHE_FLASH_ATTR usb_init() gp[GPIO_OFFSET_DIR_IN/4] = _BV(DPLUS) | _BV(DMINUS); ETS_GPIO_INTR_ENABLE(); - } diff --git a/user/usb.h b/user/usb.h index 31fd450..348656e 100644 --- a/user/usb.h +++ b/user/usb.h @@ -1,7 +1,7 @@ #ifndef _USB_H #define _USB_H -#include "usb_config.h" +#include #define USB_LOW_SPEED @@ -21,17 +21,17 @@ struct usb_endpoint { const uint8_t * ptr_in; // Pointer to "IN" data (US->PC) - uint8_t size_in; // Total size of the structure pointed to by ptr_in - uint8_t advance_in; // How much data was sent this packet? (How much to advance in ack) - uint8_t place_in; // Where in the ptr_in we are currently pointing. + uint16_t size_in; // Total size of the structure pointed to by ptr_in + uint16_t advance_in; // How much data was sent this packet? (How much to advance in ack) + uint16_t place_in; // Where in the ptr_in we are currently pointing. uint8_t toggle_in; // DATA0 or DATA1? uint8_t send; // Sets back to 0 when done sending. uint8_t * ptr_out; int * transfer_done_ptr; //Written to # of bytes received when a datagram is done. - uint8_t max_size_out; + uint16_t max_size_out; + uint16_t got_size_out; uint8_t toggle_out; //Out PC->US - uint8_t got_size_out; }; struct usb_internal_state_struct @@ -44,7 +44,6 @@ struct usb_internal_state_struct uint32_t last_token; uint32_t debug; - struct usb_endpoint * ce; //Current endpoint (set by IN/OUT PIDs) struct usb_endpoint eps[ENDPOINTS]; @@ -52,6 +51,7 @@ struct usb_internal_state_struct uint32_t my_address; //For the current address set up by the setup portion of USB. uint32_t setup_request; //1 if needing setup packet. + uint32_t there_is_a_host; //1 if there is a host at all, i.e. enumeration attempts have begun. }; extern struct usb_internal_state_struct usb_internal_state __attribute__((aligned(4)));