From: travisutk Date: Sun, 26 Feb 2012 01:11:36 +0000 (+0000) Subject: Code for talking to the MAX3420 USB Device Controller. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=f3480afd0970eb232b17070d8596e5d09aef2c7e;hp=2e3af17125cdd3e5b4c7725dfadd15f4c8145484 Code for talking to the MAX3420 USB Device Controller. I might make a monitor for this later, but FTDI is cheaper. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@1099 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/firmware/Makefile b/firmware/Makefile index 4df4028..30695a5 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -141,6 +141,14 @@ ifeq ($(filter jtag, $(config)), jtag) endif endif +# include MAX342x USB drivers. +ifeq ($(filter maxusb, $(config)), maxusb) + ifneq ($(filter apps/usb/maxusb.o, $(apps)), apps/usb/maxusb.o) + apps+= apps/usb/maxusb.o + hdrs+= maxusb.h + endif +endif + # include the sbw defs if they specified it ifeq ($(filter sbw, $(config)), sbw) # if they only specify sbw, include jtag 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