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 SPI_HAS_TRANSACTION 45 SPI_SS::SetDirWrite();
48 #elif defined(STM32F4) 49 #warning "You need to initialize the SPI interface manually when using the STM32F4 platform" 55 SPI_SS::SetDirWrite();
58 #if defined(__MIPSEL__) 59 SPI.setClockDivider(1);
60 #elif defined(__ARDUINO_X86__) 61 #ifdef SPI_CLOCK_1M // Hack used to check if setClockSpeed is available 62 SPI.setClockSpeed(12000000);
64 SPI.setClockDivider(SPI_CLOCK_DIV2);
66 #elif !defined(RBL_NRF51822) 67 SPI.setClockDivider(4);
73 SPI_CLK::SetDirWrite();
74 SPI_MOSI::SetDirWrite();
75 SPI_MISO::SetDirRead();
76 SPI_SS::SetDirWrite();
88 #if defined(__AVR_ATmega1280__) || (__AVR_ATmega2560__) || defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB1286__) 90 #elif defined(__AVR_ATmega168__) || defined(__AVR_ATmega328P__) 92 #elif defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) 94 #elif (defined(CORE_TEENSY) && (defined(__MK20DX128__) || defined(__MK20DX256__) || defined(__MKL26Z64__))) || defined(__ARDUINO_X86__) || defined(__MIPSEL__) || defined(STM32F4) 96 #elif defined(ARDUINO_SAM_DUE) && defined(__SAM3X8E__) 98 #elif defined(RBL_NRF51822) 101 #error "No SPI entry in usbhost.h" 109 template<
typename SPI_SS,
typename INTR >
class MAX3421e {
110 static uint8_t vbusState;
114 void regWr(uint8_t reg, uint8_t data);
115 uint8_t* bytesWr(uint8_t reg, uint8_t nbytes, uint8_t* data_p);
116 void gpioWr(uint8_t data);
117 uint8_t regRd(uint8_t reg);
118 uint8_t* bytesRd(uint8_t reg, uint8_t nbytes, uint8_t* data_p);
122 int8_t Init(
int mseconds);
132 uint8_t GpxHandler();
133 uint8_t IntHandler();
137 template<
typename SPI_SS,
typename INTR >
141 template<
typename SPI_SS,
typename INTR >
144 #ifdef BOARD_MEGA_ADK 152 template<
typename SPI_SS,
typename INTR >
155 #if SPI_HAS_TRANSACTION 156 SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0));
160 #if USING_SPI4TEENSY3 164 spi4teensy3::send(c, 2);
165 #elif SPI_HAS_TRANSACTION 170 #elif defined(STM32F4) 174 HAL_SPI_Transmit(&SPI_Handle, c, 2, HAL_MAX_DELAY);
176 SPI.transfer(reg | 0x02);
180 while(!(SPSR & (1 << SPIF)));
182 while(!(SPSR & (1 << SPIF)));
186 #if SPI_HAS_TRANSACTION 187 SPI.endTransaction();
195 template<
typename SPI_SS,
typename INTR >
198 #if SPI_HAS_TRANSACTION 199 SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0));
203 #if USING_SPI4TEENSY3 204 spi4teensy3::send(reg | 0x02);
205 spi4teensy3::send(data_p, nbytes);
207 #elif SPI_HAS_TRANSACTION 208 SPI.transfer(reg | 0x02);
209 SPI.transfer(data_p, nbytes);
211 #elif defined(__ARDUINO_X86__) 212 SPI.transfer(reg | 0x02);
213 SPI.transferBuffer(data_p, NULL, nbytes);
215 #elif defined(STM32F4) 216 uint8_t data = reg | 0x02;
217 HAL_SPI_Transmit(&SPI_Handle, &data, 1, HAL_MAX_DELAY);
218 HAL_SPI_Transmit(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
221 SPI.transfer(reg | 0x02);
223 SPI.transfer(*data_p);
230 while(!(SPSR & (1 << SPIF)));
235 while(!(SPSR & (1 << SPIF)));
239 #if SPI_HAS_TRANSACTION 240 SPI.endTransaction();
249 template<
typename SPI_SS,
typename INTR >
258 template<
typename SPI_SS,
typename INTR >
261 #if SPI_HAS_TRANSACTION 262 SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0));
266 #if USING_SPI4TEENSY3 267 spi4teensy3::send(reg);
268 uint8_t rv = spi4teensy3::receive();
270 #elif defined(STM32F4) 271 HAL_SPI_Transmit(&SPI_Handle, ®, 1, HAL_MAX_DELAY);
273 HAL_SPI_Receive(&SPI_Handle, &rv, 1, HAL_MAX_DELAY);
275 #elif !defined(SPDR) || SPI_HAS_TRANSACTION 277 uint8_t rv = SPI.transfer(0);
281 while(!(SPSR & (1 << SPIF)));
283 while(!(SPSR & (1 << SPIF)));
288 #if SPI_HAS_TRANSACTION 289 SPI.endTransaction();
297 template<
typename SPI_SS,
typename INTR >
300 #if SPI_HAS_TRANSACTION 301 SPI.beginTransaction(SPISettings(26000000, MSBFIRST, SPI_MODE0));
305 #if USING_SPI4TEENSY3 306 spi4teensy3::send(reg);
307 spi4teensy3::receive(data_p, nbytes);
309 #elif SPI_HAS_TRANSACTION 311 memset(data_p, 0, nbytes);
312 SPI.transfer(data_p, nbytes);
314 #elif defined(__ARDUINO_X86__) 316 SPI.transferBuffer(NULL, data_p, nbytes);
318 #elif defined(STM32F4) 319 HAL_SPI_Transmit(&SPI_Handle, ®, 1, HAL_MAX_DELAY);
320 memset(data_p, 0, nbytes);
321 HAL_SPI_Receive(&SPI_Handle, data_p, nbytes, HAL_MAX_DELAY);
326 *data_p++ = SPI.transfer(0);
331 while(!(SPSR & (1 << SPIF)));
335 while(!(SPSR & (1 << SPIF)));
339 printf(
"%2.2x ", *data_p);
351 #if SPI_HAS_TRANSACTION 352 SPI.endTransaction();
360 template<
typename SPI_SS,
typename INTR >
371 template<
typename SPI_SS,
typename INTR >
385 template<
typename SPI_SS,
typename INTR >
392 SPI_SS::SetDirWrite();
422 template<
typename SPI_SS,
typename INTR >
429 SPI_SS::SetDirWrite();
443 if(mseconds < 1000) mseconds = 1000;
466 template<
typename SPI_SS,
typename INTR >
469 bus_sample = regRd(
rHRSL);
482 if((regRd(
rMODE) & bmLOWSPEED) == 0) {
501 template<
typename SPI_SS,
typename INTR >
507 pinvalue = INTR::IsSet();
510 rcode = IntHandler();
520 template<
typename SPI_SS,
typename INTR >
523 uint8_t HIRQ_sendback = 0x00;
533 regWr(
rHIRQ, HIRQ_sendback);
534 return ( HIRQ_sendback);
549 #endif // _USBHOST_H_
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)