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 CLK,
typename MOSI,
typename MISO,
typename SPI_SS >
class SPi {
40 SPI_SS::SetDirWrite();
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__)
73 #error "No SPI entry in usbhost.h"
81 template<
typename 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 SS,
typename INTR >
113 template<
typename SS,
typename INTR >
116 #ifdef BOARD_MEGA_ADK
124 template<
typename 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 SS,
typename INTR >
150 #if USING_SPI4TEENSY3
151 spi4teensy3::send(reg | 0x02);
152 spi4teensy3::send(data_p, nbytes);
157 while(!(SPSR & (1 << SPIF)));
161 while(!(SPSR & (1 << SPIF)));
171 template<
typename SS,
typename INTR >
180 template<
typename SS,
typename INTR >
184 #if USING_SPI4TEENSY3
185 spi4teensy3::send(reg);
186 uint8_t rv = spi4teensy3::receive();
190 while(!(SPSR & (1 << SPIF)));
192 while(!(SPSR & (1 << SPIF)));
202 template<
typename SS,
typename INTR >
206 #if USING_SPI4TEENSY3
207 spi4teensy3::send(reg);
208 spi4teensy3::receive(data_p, nbytes);
212 while(!(SPSR & (1 << SPIF)));
216 while(!(SPSR & (1 << SPIF)));
220 printf(
"%2.2x ", *data_p);
237 template<
typename SS,
typename INTR >
248 template<
typename SS,
typename INTR >
262 template<
typename SS,
typename INTR >
299 template<
typename SS,
typename INTR >
320 if(mseconds < 1000) mseconds = 1000;
343 template<
typename SS,
typename INTR >
346 bus_sample = regRd(
rHRSL);
359 if((regRd(
rMODE) & bmLOWSPEED) == 0) {
378 template<
typename SS,
typename INTR >
384 pinvalue = INTR::IsSet();
387 rcode = IntHandler();
397 template<
typename SS,
typename INTR >
400 uint8_t HIRQ_sendback = 0x00;
410 regWr(
rHIRQ, HIRQ_sendback);
411 return( HIRQ_sendback);
void regWr(uint8_t reg, uint8_t data)
void gpioWr(uint8_t data)
#define XMEM_ACQUIRE_SPI()
void vbusPower(VBUS_t state)
uint8_t * bytesWr(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
#define XMEM_RELEASE_SPI()
uint8_t * bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p)
uint8_t getVbusState(void)
uint8_t regRd(uint8_t reg)