Home | History | Annotate | Download | only in USB_Host_Shield
      1 /*
      2  * Copyright 2009-2011 Oleg Mazurov, Circuits At Home, http://www.circuitsathome.com
      3  * MAX3421E USB host controller support
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  * 3. Neither the name of the authors nor the names of its contributors
     14  *    may be used to endorse or promote products derived from this software
     15  *    without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  * SUCH DAMAGE.
     28  */
     29 
     30 /* MAX3421E functions */
     31 #ifndef _MAX3421E_H_
     32 #define _MAX3421E_H_
     33 
     34 #include "Arduino.h"
     35 #include "Max3421e_constants.h"
     36 
     37 class MAX3421E /* : public SPI */ {
     38     // byte vbusState;
     39     public:
     40         MAX3421E( void );
     41         byte getVbusState( void );
     42 //        void toggle( byte pin );
     43         static void regWr( byte, byte );
     44         char * bytesWr( byte, byte, char * );
     45         static void gpioWr( byte );
     46         byte regRd( byte );
     47         char * bytesRd( byte, byte, char * );
     48         byte gpioRd( void );
     49         boolean reset();
     50         boolean vbusPwr ( boolean );
     51         void busprobe( void );
     52         void powerOn();
     53         byte IntHandler();
     54         byte GpxHandler();
     55         byte Task();
     56     private:
     57 	static void pinInit(void);
     58 	static void setRST(uint8_t val);
     59 	static uint8_t readINT(void);
     60 	static uint8_t readGPX(void);
     61 
     62       static void spi_init() {
     63         uint8_t tmp;
     64         // initialize SPI pins
     65         pinMode(SCK_PIN, OUTPUT);
     66         pinMode(MOSI_PIN, OUTPUT);
     67         pinMode(MISO_PIN, INPUT);
     68         pinMode(SS_PIN, OUTPUT);
     69         /* mode 00 (CPOL=0, CPHA=0) master, fclk/2. Mode 11 (CPOL=11, CPHA=11) is also supported by MAX3421E */
     70         SPCR = 0x50;
     71         SPSR = 0x01;
     72         /**/
     73         tmp = SPSR;
     74         tmp = SPDR;
     75     }
     76 //        void init();
     77     friend class Max_LCD;
     78 };
     79 
     80 
     81 
     82 
     83 #endif //_MAX3421E_H_
     84