turn ftdi driver into echo server
[goodfet] / firmware / apps / usb / maxusb.c
1 /*! \file max3421.c
2   \author Travis Goodspeed
3   \brief SPI Driver for MAX342x USB Controllers
4 */
5
6
7 #include "command.h"
8
9 #ifdef __MSPGCC__
10 #include <msp430.h>
11 #else
12 #include <signal.h>
13 #include <msp430.h>
14 #include <iomacros.h>
15 #endif
16
17 #include "maxusb.h"
18
19 #define MAXUSBAPPLICATION
20
21 #include "platform.h"
22
23
24 // define for the app list.
25 app_t const maxusb_app = {
26         /* app number */
27         MAXUSB,
28
29         /* handle fn */
30         maxusb_handle_fn,
31
32         /* name */
33         "MAXUSB",
34
35         /* desc */
36         "\tThis allows you to write USB Host or USB Device drivers for\n"
37         "\t the MAX3421 and MAX3420 chips.\n"
38 };
39
40 //! Set up the pins for SPI mode.
41 void maxusb_setup(){
42   SETSS;
43   SPIDIR|=MOSI+SCK+BIT0; //BIT0 might be SS
44   SPIDIR&=~MISO;
45   P4DIR&=~TST; //TST line becomes interrupt input.
46   P4DIR&=~BIT7; //GPX pin.
47   P2DIR|=RST;
48   DIRSS;
49   
50   
51   //Setup the configuration pins.
52   //This might need some delays.
53   CLRRST; //Put the chip into RESET.
54   SETSS;  //Deselect the chip, end any existing transation.
55   SETRST; //Bring the chip out of RESET.
56 }
57
58
59
60 //! Handles a MAXUSB monitor command.
61 void maxusb_handle_fn( uint8_t const app,
62                        uint8_t const verb,
63                        uint32_t const len){
64   unsigned long i;
65
66   //Raise !SS to end transaction, just in case we forgot.
67   SETSS;
68
69   switch(verb){
70   case READ:
71   case WRITE:
72     CLRSS; //Drop !SS to begin transaction.
73     for(i=0;i<len;i++)
74       cmddata[i]=spitrans8(cmddata[i]);
75     SETSS;  //Raise !SS to end transaction.
76     txdata(app,verb,len);
77     break;
78
79   case PEEK://TODO peek a register.
80     debugstr("PEEK isn't implemented in MAXUSB");
81     txdata(app,verb,0);
82     break;
83
84   case POKE://TODO poke a register.
85     debugstr("POKE isn't implemented in MAXUSB");
86     txdata(app,verb,0);
87     break;
88     
89   case SETUP:
90     maxusb_setup();
91     txdata(app,verb,0);
92     break;
93   }
94         
95   //Raise !SS to end transaction, in case we forgot.
96   SETSS;
97 }