Erik Gilling | 8a71565 | 2011-03-22 14:00:56 -0700 | [diff] [blame^] | 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 |
|
Erik Gilling | 51f1751 | 2011-02-17 20:39:36 -0800 | [diff] [blame] | 30 | /* MAX3421E functions */
|
| 31 | #ifndef _MAX3421E_H_
|
| 32 | #define _MAX3421E_H_
|
| 33 |
|
| 34 |
|
| 35 | //#include <Spi.h>
|
| 36 | //#include <WProgram.h>
|
| 37 | #include "WProgram.h"
|
| 38 | #include "Max3421e_constants.h"
|
| 39 |
|
| 40 | class MAX3421E /* : public SPI */ {
|
| 41 | // byte vbusState;
|
| 42 | public:
|
| 43 | MAX3421E( void );
|
| 44 | byte getVbusState( void );
|
| 45 | // void toggle( byte pin );
|
| 46 | static void regWr( byte, byte );
|
| 47 | char * bytesWr( byte, byte, char * );
|
| 48 | static void gpioWr( byte );
|
| 49 | byte regRd( byte );
|
| 50 | char * bytesRd( byte, byte, char * );
|
| 51 | byte gpioRd( void );
|
| 52 | boolean reset();
|
| 53 | boolean vbusPwr ( boolean );
|
| 54 | void busprobe( void );
|
| 55 | void powerOn();
|
| 56 | byte IntHandler();
|
| 57 | byte GpxHandler();
|
| 58 | byte Task();
|
| 59 | private:
|
Erik Gilling | bb9ab4b | 2011-02-17 20:41:12 -0800 | [diff] [blame] | 60 | static void pinInit(void);
|
| 61 | static void setRST(uint8_t val);
|
| 62 | static uint8_t readINT(void);
|
| 63 | static uint8_t readGPX(void);
|
| 64 |
|
Erik Gilling | 51f1751 | 2011-02-17 20:39:36 -0800 | [diff] [blame] | 65 | static void spi_init() {
|
| 66 | uint8_t tmp;
|
| 67 | // initialize SPI pins
|
| 68 | pinMode(SCK_PIN, OUTPUT);
|
| 69 | pinMode(MOSI_PIN, OUTPUT);
|
| 70 | pinMode(MISO_PIN, INPUT);
|
| 71 | pinMode(SS_PIN, OUTPUT);
|
Erik Gilling | 51f1751 | 2011-02-17 20:39:36 -0800 | [diff] [blame] | 72 | /* mode 00 (CPOL=0, CPHA=0) master, fclk/2. Mode 11 (CPOL=11, CPHA=11) is also supported by MAX3421E */
|
| 73 | SPCR = 0x50;
|
| 74 | SPSR = 0x01;
|
| 75 | /**/
|
| 76 | tmp = SPSR;
|
| 77 | tmp = SPDR;
|
| 78 | }
|
| 79 | // void init();
|
| 80 | friend class Max_LCD;
|
| 81 | };
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 | #endif //_MAX3421E_H_
|