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 {
39 SPI_SS::SetDirWrite();
42 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
44 SPI_SS::SetDirWrite();
47 SPI.setClockDivider(4);
52 SPI_CLK::SetDirWrite();
53 SPI_MOSI::SetDirWrite();
54 SPI_MISO::SetDirRead();
55 SPI_SS::SetDirWrite();
67 #if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__)
69 #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__)
71 #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)
73 #elif defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__))
75 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
78 #error "No SPI entry in usbhost.h"
86 template<
typename SPI_SS,
typename INTR >
class MAX3421e {
87 static uint8_t vbusState;
91 void regWr(uint8_t reg, uint8_t data);
92 uint8_t*
bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p);
94 uint8_t
regRd(uint8_t reg);
95 uint8_t*
bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p);
99 int8_t
Init(
int mseconds);
114 template<
typename SPI_SS,
typename INTR >
118 template<
typename SPI_SS,
typename INTR >
121 #ifdef BOARD_MEGA_ADK
129 template<
typename SPI_SS,
typename INTR >
133 #if USING_SPI4TEENSY3
137 spi4teensy3::send(c, 2);
138 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
139 SPI.transfer(reg | 0x02);
143 while(!(SPSR & (1 << SPIF)));
145 while(!(SPSR & (1 << SPIF)));
154 template<
typename SPI_SS,
typename INTR >
158 #if USING_SPI4TEENSY3
159 spi4teensy3::send(reg | 0x02);
160 spi4teensy3::send(data_p, nbytes);
162 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
163 SPI.transfer(reg | 0x02);
165 SPI.transfer(*data_p);
172 while(!(SPSR & (1 << SPIF)));
177 while(!(SPSR & (1 << SPIF)));
187 template<
typename SPI_SS,
typename INTR >
196 template<
typename SPI_SS,
typename INTR >
200 #if USING_SPI4TEENSY3
201 spi4teensy3::send(reg);
202 uint8_t rv = spi4teensy3::receive();
204 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
206 uint8_t rv = SPI.transfer(0);
210 while(!(SPSR & (1 << SPIF)));
212 while(!(SPSR & (1 << SPIF)));
222 template<
typename SPI_SS,
typename INTR >
226 #if USING_SPI4TEENSY3
227 spi4teensy3::send(reg);
228 spi4teensy3::receive(data_p, nbytes);
230 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__)
233 *data_p++ = SPI.transfer(0);
238 while(!(SPSR & (1 << SPIF)));
242 while(!(SPSR & (1 << SPIF)));
246 printf(
"%2.2x ", *data_p);
263 template<
typename SPI_SS,
typename INTR >
274 template<
typename SPI_SS,
typename INTR >
288 template<
typename SPI_SS,
typename INTR >
295 SPI_SS::SetDirWrite();
325 template<
typename SPI_SS,
typename INTR >
332 SPI_SS::SetDirWrite();
346 if(mseconds < 1000) mseconds = 1000;
369 template<
typename SPI_SS,
typename INTR >
372 bus_sample = regRd(
rHRSL);
385 if((regRd(
rMODE) & bmLOWSPEED) == 0) {
404 template<
typename SPI_SS,
typename INTR >
410 pinvalue = INTR::IsSet();
413 rcode = IntHandler();
423 template<
typename SPI_SS,
typename INTR >
426 uint8_t HIRQ_sendback = 0x00;
436 regWr(
rHIRQ, HIRQ_sendback);
437 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)