20 #if !defined(_usb_h_) || defined(_USBHOST_H_)
21 #error "Never include usbhost.h directly; include Usb.h instead"
26 #include <spi4teensy3.h>
27 #include <sys/types.h>
31 template<
typename SPI_CLK,
typename SPI_MOSI,
typename SPI_MISO,
typename SPI_SS >
class SPi {
40 SPI_SS::SetDirWrite();
49 SPI_CLK::SetDirWrite();
50 SPI_MOSI::SetDirWrite();
51 SPI_MISO::SetDirRead();
52 SPI_SS::SetDirWrite();
64 #if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
66 #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
68 #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
70 #elif defined(__MK20DX128__) || defined(__MK20DX256__)
73 #error "No SPI entry in usbhost.h"
81 template<
typename SPI_SS,
typename INTR >
class MAX3421e {
82 static uint8_t vbusState;
86 void regWr(uint8_t reg, uint8_t data);
87 uint8_t*
bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p);
89 uint8_t
regRd(uint8_t reg);
90 uint8_t*
bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p);
94 int8_t
Init(
int mseconds);
109 template<
typename SPI_SS,
typename INTR >
113 template<
typename SPI_SS,
typename INTR >
116 #ifdef BOARD_MEGA_ADK
124 template<
typename SPI_SS,
typename INTR >
128 #if USING_SPI4TEENSY3
132 spi4teensy3::send(c, 2);
135 while(!(SPSR & (1 << SPIF)));
137 while(!(SPSR & (1 << SPIF)));
146 template<
typename SPI_SS,
typename INTR >
150 #if USING_SPI4TEENSY3
151 spi4teensy3::send(reg | 0x02);
152 spi4teensy3::send(data_p, nbytes);
157 while(!(SPSR & (1 << SPIF)));
162 while(!(SPSR & (1 << SPIF)));
172 template<
typename SPI_SS,
typename INTR >
181 template<
typename SPI_SS,
typename INTR >
185 #if USING_SPI4TEENSY3
186 spi4teensy3::send(reg);
187 uint8_t rv = spi4teensy3::receive();
191 while(!(SPSR & (1 << SPIF)));
193 while(!(SPSR & (1 << SPIF)));
203 template<
typename SPI_SS,
typename INTR >
207 #if USING_SPI4TEENSY3
208 spi4teensy3::send(reg);
209 spi4teensy3::receive(data_p, nbytes);
213 while(!(SPSR & (1 << SPIF)));
217 while(!(SPSR & (1 << SPIF)));
221 printf(
"%2.2x ", *data_p);
238 template<
typename SPI_SS,
typename INTR >
249 template<
typename SPI_SS,
typename INTR >
263 template<
typename SPI_SS,
typename INTR >
270 SPI_SS::SetDirWrite();
300 template<
typename SPI_SS,
typename INTR >
307 SPI_SS::SetDirWrite();
321 if(mseconds < 1000) mseconds = 1000;
344 template<
typename SPI_SS,
typename INTR >
347 bus_sample = regRd(
rHRSL);
360 if((regRd(
rMODE) & bmLOWSPEED) == 0) {
379 template<
typename SPI_SS,
typename INTR >
385 pinvalue = INTR::IsSet();
388 rcode = IntHandler();
398 template<
typename SPI_SS,
typename INTR >
401 uint8_t HIRQ_sendback = 0x00;
411 regWr(
rHIRQ, HIRQ_sendback);
412 return ( HIRQ_sendback);
uint8_t getVbusState(void)
void gpioWr(uint8_t data)
void vbusPower(VBUS_t state)
uint8_t * bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
#define XMEM_ACQUIRE_SPI()
uint8_t * bytesWr(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
#define XMEM_RELEASE_SPI()
void regWr(uint8_t reg, uint8_t data)
uint8_t regRd(uint8_t reg)