Skip to content

Commit

Permalink
Make USB play better with subprojects, and allow much larger custom c…
Browse files Browse the repository at this point in the history
…ontrol messages.
  • Loading branch information
cnlohr committed Oct 8, 2016
1 parent a6de842 commit 0e28e0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
5 changes: 3 additions & 2 deletions user/usb.c
Expand Up @@ -12,14 +12,16 @@ 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 <usb_config.h>

//Received a setup for a specific endpoint.
void usb_pid_handle_setup( uint32_t this_token, struct usb_internal_state_struct * ist )
{
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;

Expand Down Expand Up @@ -246,6 +248,5 @@ void ICACHE_FLASH_ATTR usb_init()
gp[GPIO_OFFSET_DIR_IN/4] = _BV(DPLUS) | _BV(DMINUS);

ETS_GPIO_INTR_ENABLE();

}

14 changes: 7 additions & 7 deletions user/usb.h
@@ -1,7 +1,7 @@
#ifndef _USB_H
#define _USB_H

#include "usb_config.h"
#include <usb_config.h>

#define USB_LOW_SPEED

Expand All @@ -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
Expand All @@ -44,14 +44,14 @@ 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];

//Things past here are addressable by C.

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)));
Expand Down

0 comments on commit 0e28e0e

Please sign in to comment.