X-Git-Url: http://git.rot13.org//?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fusb%2Fmaxusb.c;fp=firmware%2Fapps%2Fusb%2Fmaxusb.c;h=dbe554a538f3510fcbb1a1059d3b3bd4ca988f10;hp=0000000000000000000000000000000000000000;hb=f3480afd0970eb232b17070d8596e5d09aef2c7e;hpb=2e3af17125cdd3e5b4c7725dfadd15f4c8145484 diff --git a/firmware/apps/usb/maxusb.c b/firmware/apps/usb/maxusb.c new file mode 100644 index 0000000..dbe554a --- /dev/null +++ b/firmware/apps/usb/maxusb.c @@ -0,0 +1,99 @@ +/*! \file max3421.c + \author Travis Goodspeed + \brief SPI Driver for MAX342x USB Controllers +*/ + + +#include "command.h" + +#ifdef __MSPGCC__ +#include +#else +#include +#include +#include +#endif + +#include "maxusb.h" + +#define MAXUSBAPPLICATION + +#include "platform.h" + + +// define the spi app's app_t +app_t const maxusb_app = { + + /* app number */ + MAXUSB, + + /* handle fn */ + maxusb_handle_fn, + + /* name */ + "MAXUSB", + + /* desc */ + "\tThis allows you to write USB Host or USB Device drivers for\n" + "\t the MAX3421 and MAX3420 chips.\n" +}; + +//! Set up the pins for SPI mode. +void maxusb_setup(){ + SETSS; + SPIDIR|=MOSI+SCK+BIT0; //BIT0 might be SS + SPIDIR&=~MISO; + P4DIR&=~TST; //TST line becomes interrupt input. + P2DIR|=RST; + DIRSS; + + + //Setup the configuration pins. + //This might need some delays. + CLRRST; //Put the chip into RESET. + debugstr("MAXUSB is off."); + SETSS; //Deselect the chip, end any existing transation. + SETRST; //Bring the chip out of RESET. + debugstr("MAXUSB is on."); +} + + + +//! Handles a MAXUSB monitor command. +void maxusb_handle_fn( uint8_t const app, + uint8_t const verb, + uint32_t const len){ + unsigned long i; + + //Raise !SS to end transaction, just in case we forgot. + SETSS; + + switch(verb){ + case READ: + case WRITE: + CLRSS; //Drop !SS to begin transaction. + for(i=0;i