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