X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fspi%2Fspi.c;h=c880e8c701c47c134c64412b3faac563f05a6cff;hp=12eaf60c1d995f612e2a57f91ac69adae755e3e9;hb=69539bb167246135b1bde3c55dca7d19bc3c7aee;hpb=d96bdf017938c586c4eff9e9dd981005f1af7dbe diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index 12eaf60..c880e8c 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -5,7 +5,7 @@ //Higher level left to client application. -#include "platform.h" + #include "command.h" #include @@ -14,6 +14,32 @@ #include "spi.h" +#define SPIAPPLICATION + +#include "platform.h" + +//! Handles a monitor command. +void spi_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len); + +// define the spi app's app_t +app_t const spi_app = { + + /* app number */ + SPI, + + /* handle fn */ + spi_handle_fn, + + /* name */ + "SPI", + + /* desc */ + "\tThe SPI app handles the SPI bus protocol, turning\n" + "\tyour GoodFET into a USB-to-SPI adapter.\n" +}; + //This could be more accurate. //Does it ever need to be? #define SPISPEED 0 @@ -23,15 +49,14 @@ //! Set up the pins for SPI mode. void spisetup(){ SETSS; - P5DIR|=MOSI+SCK+BIT0; //BIT0 might be SS - P5DIR&=~MISO; + SPIDIR|=MOSI+SCK+BIT0; //BIT0 might be SS + SPIDIR&=~MISO; DIRSS; //Begin a new transaction. CLRSS; SETSS; - } @@ -49,9 +74,9 @@ unsigned char spitrans8(unsigned char byte){ CLRMOSI; byte <<= 1; - SPIDELAY(100); + //SPIDELAY(100); SETCLK; - SPIDELAY(100); + //SPIDELAY(100); /* read MISO on trailing edge */ byte |= READMISO; @@ -238,13 +263,12 @@ void em260_wake(){ } //! Handle an EM260 exchange. void spi_rw_em260(u8 app, u8 verb, u32 len){ - static int state=0; unsigned long i; u8 lastin; P4DIR=0; //TODO ASAP remove P4 references. P4OUT=0xFF; - P4REN=0xFF; + //P4REN=0xFF; //See GoodFETEM260.py for details. //The EM260 requires that the host wait for the client. @@ -254,11 +278,8 @@ void spi_rw_em260(u8 app, u8 verb, u32 len){ debugstr("Detected HOST_INT."); */ - //if(!state++) - //if(state++&1) em260_wake(); - em260woken: SETMOSI; //Autodetected SPI mode. CLRSS; //Drop !SS to begin transaction. @@ -266,8 +287,9 @@ void spi_rw_em260(u8 app, u8 verb, u32 len){ for(i=0;i