USB removal/insertion now works for Quiver.

master
Marcio Teixeira 7 years ago
parent c3b05fc2d7
commit febdff2013

@ -269,8 +269,8 @@ void Marlin_LCD_API::initMedia() {
} }
void Marlin_LCD_API::checkMedia() { void Marlin_LCD_API::checkMedia() {
#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT) #if (ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)) || defined(LULZBOT_USE_USB_STICK)
const bool sd_status = IS_SD_INSERTED; const bool sd_status = isMediaInserted();
if (sd_status != lcd_sd_status) { if (sd_status != lcd_sd_status) {
SERIAL_PROTOCOLLNPAIR("SD Status: ", sd_status); SERIAL_PROTOCOLLNPAIR("SD Status: ", sd_status);
@ -309,8 +309,12 @@ bool Marlin_LCD_API::isPrinting() {
} }
bool Marlin_LCD_API::isMediaInserted() { bool Marlin_LCD_API::isMediaInserted() {
#if ENABLED(SDSUPPORT) #if (ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)) || defined(LULZBOT_USE_USB_STICK)
#if defined(LULZBOT_USE_USB_STICK)
return Sd2Card::isInserted();
#else
return IS_SD_INSERTED; return IS_SD_INSERTED;
#endif
#else #else
return false; return false;
#endif #endif

@ -193,7 +193,7 @@
#define LULZBOT_USE_EINSYRAMBO #define LULZBOT_USE_EINSYRAMBO
#define LULZBOT_USE_EINSY_RETRO #define LULZBOT_USE_EINSY_RETRO
#define LULZBOT_USE_TOUCH_UI #define LULZBOT_USE_TOUCH_UI
#define LULZBOT_USE_HIGH_RES //#define LULZBOT_USE_HIGH_RES
#define LULZBOT_USE_PORTRAIT_UI #define LULZBOT_USE_PORTRAIT_UI
#define LULZBOT_TWO_PIECE_BED #define LULZBOT_TWO_PIECE_BED
#define LULZBOT_USE_AUTOLEVELING #define LULZBOT_USE_AUTOLEVELING

@ -67,9 +67,11 @@ uint8_t const SPI_FULL_SPEED = 0, // Set SCK to max rate of F_CPU/2. See
* \brief Raw access to SD and SDHC flash memory cards. * \brief Raw access to SD and SDHC flash memory cards.
*/ */
class Sd2Card { class Sd2Card {
public: private:
static bool usbHostReady();
Sd2Card(); public:
static bool isInserted();
/** /**
* Initialize an SD flash memory card with default clock rate and chip * Initialize an SD flash memory card with default clock rate and chip

@ -21,11 +21,6 @@
*/ */
/******************************************************************************************** /********************************************************************************************
* This program/sketch is used to run a USB Thumb Drive. *
* *
* NOTE - This Arduino Sketch has been modified to initialize a MAX3421E USB Host Interface *
* chip, write 3 test files, print out the directory of the thumb drive and print out the *
* contents of a short .txt file. *
* * * *
* The code is leveraged from the following: * * The code is leveraged from the following: *
* * * *
@ -53,73 +48,61 @@
#include <SPI.h> #include <SPI.h>
//#define _usb_h_
#include "Marlin.h" #include "Marlin.h"
#include "../watchdog.h"
#undef MACROS_H
#define USB_HOST_SERIAL customizedSerial #define USB_HOST_SERIAL customizedSerial
#include "lib/masstorage.h" #if defined(MACROS_H)
#undef MACROS_H // The USB host library wants to redefine this.
#include "lib/masstorage.cpp" #include "lib/masstorage.cpp"
#include "lib/message.cpp" #include "lib/message.cpp"
#include "lib/parsetools.cpp"
#include "lib/Usb.cpp" #include "lib/Usb.cpp"
#else
#include "lib/masstorage.cpp"
#include "lib/message.cpp"
#include "lib/Usb.cpp"
#undef MACROS_H
#endif
#include "Fake_Sd2Card.h" #include "Fake_Sd2Card.h"
#define MAX_USB_RST 7
// USB host objects.v
USB usb; USB usb;
BulkOnly bulk(&usb); BulkOnly bulk(&usb);
#define error(msg) {Serial.print("Error: "); Serial.println(msg);} bool Sd2Card::usbHostReady() {
static enum {
#define TIMEOUT_MILLIS 4000 USB_HOST_UNINITIALIZED,
USB_HOST_FAILED_INIT,
//------------------------------------------------------------------------------ USB_HOST_INITIALIZED
bool initUSB(USB* usb) { } state = USB_HOST_UNINITIALIZED;
uint8_t current_state = 0;
uint32_t m = millis(); if(state == USB_HOST_UNINITIALIZED) {
if(usb.Init(1000) == -1) {
for (uint8_t i = 0; usb->Init(1000) == -1; i++) SERIAL_ECHOLNPGM("USB host failed to initialize");
{ state = USB_HOST_FAILED_INIT;
SERIAL_ECHOLNPGM("No USB HOST Shield?"); } else {
watchdog_reset(); usb.vbusPower(vbus_on);
if (i > 10) { SERIAL_ECHOLNPGM("USB host initialized");
return false; state = USB_HOST_INITIALIZED;
} }
} }
usb->vbusPower(vbus_on); return state == USB_HOST_INITIALIZED;
while ((millis() - m) < TIMEOUT_MILLIS) {
usb->Task();
current_state = usb->getUsbTaskState();
if(current_state == USB_STATE_RUNNING) {
return true;
} }
watchdog_reset();
// Marlin will call this to learn whether an SD card is inserted.
bool Sd2Card::isInserted() {
if(usbHostReady()) {
usb.Task();
return usb.getUsbTaskState() == USB_STATE_RUNNING;
} }
return false;
} }
Sd2Card::Sd2Card() { // Marlin calls this whenever an SD card is detected, so this method
}; // should not be used to initialize the USB host library
bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) { bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
if (!initUSB(&usb)) if(!usbHostReady())
{ return false;
SERIAL_ECHOLNPGM("initUSB failed");
}
else
{
SERIAL_ECHOLNPGM("USB Initialized\n");
}
if(!bulk.LUNIsGood(0)) { if(!bulk.LUNIsGood(0)) {
SERIAL_ECHOLNPGM("LUN zero is not good\n"); SERIAL_ECHOLNPGM("LUN zero is not good\n");
@ -144,4 +127,3 @@ bool Sd2Card::readBlock(uint32_t block, uint8_t* dst) {
bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) { bool Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
return bulk.Write(0, blockNumber, 512, 1, src) == 0; return bulk.Write(0, blockNumber, 512, 1, src) == 0;
} }

@ -222,9 +222,6 @@ public:
return USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS; return USB_ERROR_UNABLE_TO_REGISTER_DEVICE_CLASS;
}; };
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) {
addrPool.ForEachUsbDevice(pfunc);
};
uint8_t getUsbTaskState(void); uint8_t getUsbTaskState(void);
void setUsbTaskState(uint8_t state); void setUsbTaskState(uint8_t state);

@ -87,8 +87,6 @@ public:
virtual void FreeAddress(uint8_t addr) = 0; virtual void FreeAddress(uint8_t addr) = 0;
}; };
typedef void (*UsbDeviceHandleFunc)(UsbDevice *pdev);
#define ADDR_ERROR_INVALID_INDEX 0xFF #define ADDR_ERROR_INVALID_INDEX 0xFF
#define ADDR_ERROR_INVALID_ADDRESS 0xFF #define ADDR_ERROR_INVALID_ADDRESS 0xFF
@ -186,17 +184,6 @@ public:
return (!index) ? NULL : thePool + index; return (!index) ? NULL : thePool + index;
}; };
// Performs an operation specified by pfunc for each addressed device
void ForEachUsbDevice(UsbDeviceHandleFunc pfunc) {
if(!pfunc)
return;
for(uint8_t i = 1; i < MAX_DEVICES_ALLOWED; i++)
if(thePool[i].address.devAddress)
pfunc(thePool + i);
};
// Allocates new address // Allocates new address
virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) { virtual uint8_t AllocAddress(uint8_t parent, bool is_hub = false, uint8_t port = 0) {
@ -260,23 +247,6 @@ public:
uint8_t index = FindAddressIndex(addr); uint8_t index = FindAddressIndex(addr);
FreeAddressByIndex(index); FreeAddressByIndex(index);
}; };
// Returns number of hubs attached
// It can be rather helpfull to find out if there are hubs attached than getting the exact number of hubs.
//uint8_t GetNumHubs()
//{
// return hubCounter;
//};
//uint8_t GetNumDevices()
//{
// uint8_t counter = 0;
// for (uint8_t i=1; i<MAX_DEVICES_ALLOWED; i++)
// if (thePool[i].address != 0);
// counter ++;
// return counter;
//};
}; };
#endif // __ADDRESS_H__ #endif // __ADDRESS_H__

@ -22,8 +22,6 @@ e-mail : support@circuitsathome.com
class UsbConfigXtracter { class UsbConfigXtracter {
public: public:
//virtual void ConfigXtract(const USB_CONFIGURATION_DESCRIPTOR *conf) = 0;
//virtual void InterfaceXtract(uint8_t conf, const USB_INTERFACE_DESCRIPTOR *iface) = 0;
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep) = 0; virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep) = 0;
}; };
@ -55,7 +53,6 @@ class ConfigDescParser : public USBReadParser {
bool UseOr; bool UseOr;
bool ParseDescriptor(uint8_t **pp, uint16_t *pcntdn); bool ParseDescriptor(uint8_t **pp, uint16_t *pcntdn);
void PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc);
public: public:
@ -162,11 +159,6 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
if(theXtractor) if(theXtractor)
theXtractor->EndpointXtract(confValue, ifaceNumber, ifaceAltSet, protoValue, (USB_ENDPOINT_DESCRIPTOR*)varBuffer); theXtractor->EndpointXtract(confValue, ifaceNumber, ifaceAltSet, protoValue, (USB_ENDPOINT_DESCRIPTOR*)varBuffer);
break; break;
//case HID_DESCRIPTOR_HID:
// if (!valParser.Parse(pp, pcntdn))
// return false;
// PrintHidDescriptor((const USB_HID_DESCRIPTOR*)varBuffer);
// break;
default: default:
if(!theSkipper.Skip(pp, pcntdn, dscrLen - 2)) if(!theSkipper.Skip(pp, pcntdn, dscrLen - 2))
return false; return false;
@ -177,41 +169,4 @@ bool ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::ParseDescriptor
return true; return true;
} }
template <const uint8_t CLASS_ID, const uint8_t SUBCLASS_ID, const uint8_t PROTOCOL_ID, const uint8_t MASK>
void ConfigDescParser<CLASS_ID, SUBCLASS_ID, PROTOCOL_ID, MASK>::PrintHidDescriptor(const USB_HID_DESCRIPTOR *pDesc) {
Notify(PSTR("\r\n\r\nHID Descriptor:\r\n"), 0x80);
Notify(PSTR("bDescLength:\t\t"), 0x80);
PrintHex<uint8_t > (pDesc->bLength, 0x80);
Notify(PSTR("\r\nbDescriptorType:\t"), 0x80);
PrintHex<uint8_t > (pDesc->bDescriptorType, 0x80);
Notify(PSTR("\r\nbcdHID:\t\t\t"), 0x80);
PrintHex<uint16_t > (pDesc->bcdHID, 0x80);
Notify(PSTR("\r\nbCountryCode:\t\t"), 0x80);
PrintHex<uint8_t > (pDesc->bCountryCode, 0x80);
Notify(PSTR("\r\nbNumDescriptors:\t"), 0x80);
PrintHex<uint8_t > (pDesc->bNumDescriptors, 0x80);
//Notify(PSTR("\r\nbDescrType:\t\t"));
//PrintHex<uint8_t>(pDesc->bDescrType);
//
//Notify(PSTR("\r\nwDescriptorLength:\t"));
//PrintHex<uint16_t>(pDesc->wDescriptorLength);
for(uint8_t i = 0; i < pDesc->bNumDescriptors; i++) {
HID_CLASS_DESCRIPTOR_LEN_AND_TYPE *pLT = (HID_CLASS_DESCRIPTOR_LEN_AND_TYPE*)&(pDesc->bDescrType);
Notify(PSTR("\r\nbDescrType:\t\t"), 0x80);
PrintHex<uint8_t > (pLT[i].bDescrType, 0x80);
Notify(PSTR("\r\nwDescriptorLength:\t"), 0x80);
PrintHex<uint16_t > (pLT[i].wDescriptorLength, 0x80);
}
Notify(PSTR("\r\n"), 0x80);
}
#endif // __CONFDESCPARSER_H__ #endif // __CONFDESCPARSER_H__

@ -1,67 +0,0 @@
/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
This software may be distributed and modified under the terms of the GNU
General Public License version 2 (GPL2) as published by the Free Software
Foundation and appearing in the file GPL2.TXT included in the packaging of
this file. Please note that GPL2 Section 2[b] requires that all works based
on this software must also be made publicly available under the terms of
the GPL2 ("Copyleft").
Contact information
-------------------
Circuits At Home, LTD
Web : http://www.circuitsathome.com
e-mail : support@circuitsathome.com
*/
#include "Usb.h"
bool MultiByteValueParser::Parse(uint8_t **pp, uint16_t *pcntdn) {
if(!pBuf) {
Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80);
return false;
}
for(; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++)
pBuf[valueSize - countDown] = (**pp);
if(countDown)
return false;
countDown = valueSize;
return true;
}
bool PTPListParser::Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me) {
switch(nStage) {
case 0:
pBuf->valueSize = lenSize;
theParser.Initialize(pBuf);
nStage = 1;
case 1:
if(!theParser.Parse(pp, pcntdn))
return false;
arLen = 0;
arLen = (pBuf->valueSize >= 4) ? *((uint32_t*)pBuf->pValue) : (uint32_t)(*((uint16_t*)pBuf->pValue));
arLenCntdn = arLen;
nStage = 2;
case 2:
pBuf->valueSize = valSize;
theParser.Initialize(pBuf);
nStage = 3;
case 3:
for(; arLenCntdn; arLenCntdn--) {
if(!theParser.Parse(pp, pcntdn))
return false;
if(pf)
pf(pBuf, (arLen - arLenCntdn), me);
}
nStage = 0;
}
return true;
}

@ -44,9 +44,23 @@ public:
countDown = valueSize = pbuf->valueSize; countDown = valueSize = pbuf->valueSize;
}; };
bool Parse(uint8_t **pp, uint16_t *pcntdn); bool Parse(uint8_t **pp, uint16_t *pcntdn) {
if(!pBuf) {
Notify(PSTR("Buffer pointer is NULL!\r\n"), 0x80);
return false;
}
for(; countDown && (*pcntdn); countDown--, (*pcntdn)--, (*pp)++)
pBuf[valueSize - countDown] = (**pp);
if(countDown)
return false;
countDown = valueSize;
return true;
}
}; };
class ByteSkipper { class ByteSkipper {
uint8_t *pBuf; uint8_t *pBuf;
uint8_t nStage; uint8_t nStage;
@ -77,64 +91,4 @@ public:
}; };
}; };
// Pointer to a callback function triggered for each element of PTP array when used with PTPArrayParser
typedef void (*PTP_ARRAY_EL_FUNC)(const MultiValueBuffer * const p, uint32_t count, const void *me);
class PTPListParser {
public:
enum ParseMode {
modeArray, modeRange/*, modeEnum*/
};
private:
uint8_t nStage;
uint8_t enStage;
uint32_t arLen;
uint32_t arLenCntdn;
uint8_t lenSize; // size of the array length field in bytes
uint8_t valSize; // size of the array element in bytes
MultiValueBuffer *pBuf;
// The only parser for both size and array element parsing
MultiByteValueParser theParser;
uint8_t /*ParseMode*/ prsMode;
public:
PTPListParser() :
nStage(0),
enStage(0),
arLen(0),
arLenCntdn(0),
lenSize(0),
valSize(0),
pBuf(NULL),
prsMode(modeArray) {
};
void Initialize(const uint8_t len_size, const uint8_t val_size, MultiValueBuffer * const p, const uint8_t mode = modeArray) {
pBuf = p;
lenSize = len_size;
valSize = val_size;
prsMode = mode;
if(prsMode == modeRange) {
arLenCntdn = arLen = 3;
nStage = 2;
} else {
arLenCntdn = arLen = 0;
nStage = 0;
}
enStage = 0;
theParser.Initialize(p);
};
bool Parse(uint8_t **pp, uint16_t *pcntdn, PTP_ARRAY_EL_FUNC pf, const void *me = NULL);
};
#endif // __PARSETOOLS_H__ #endif // __PARSETOOLS_H__

@ -147,20 +147,4 @@ typedef struct {
uint8_t bInterval; // Polling interval in frames. uint8_t bInterval; // Polling interval in frames.
} __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR; } __attribute__((packed)) USB_ENDPOINT_DESCRIPTOR;
/* HID descriptor */
typedef struct {
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdHID; // HID class specification release
uint8_t bCountryCode;
uint8_t bNumDescriptors; // Number of additional class specific descriptors
uint8_t bDescrType; // Type of class descriptor
uint16_t wDescriptorLength; // Total size of the Report descriptor
} __attribute__((packed)) USB_HID_DESCRIPTOR;
typedef struct {
uint8_t bDescrType; // Type of class descriptor
uint16_t wDescriptorLength; // Total size of the Report descriptor
} __attribute__((packed)) HID_CLASS_DESCRIPTOR_LEN_AND_TYPE;
#endif // _ch9_h_ #endif // _ch9_h_

Loading…
Cancel
Save