mirror of https://github.com/ARMmbed/mbed-os.git
Update USBMSD to be more consistent with others
Add second constructor and reorder constructor parameters to match other USB classes. Also remove the ready() function since there are no calls that can only mbe made from a ready state.pull/9768/head
parent
79376c6f00
commit
3657dab5db
|
@ -17,6 +17,7 @@
|
|||
#include "stdint.h"
|
||||
#include "USBMSD.h"
|
||||
#include "EndpointResolver.h"
|
||||
#include "usb_phy_api.h"
|
||||
|
||||
#define DISK_OK 0x00
|
||||
#define NO_INIT 0x01
|
||||
|
@ -61,11 +62,28 @@ enum Status {
|
|||
CSW_ERROR,
|
||||
};
|
||||
|
||||
USBMSD::USBMSD(BlockDevice *bd, USBPhy *phy, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
|
||||
: USBDevice(phy, vendor_id, product_id, product_release),
|
||||
_init(false), _in_task(&_queue), _out_task(&_queue), _reset_task(&_queue), _control_task(&_queue), _configure_task(&_queue)
|
||||
USBMSD::USBMSD(BlockDevice *bd, bool connect_blocking, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
|
||||
: USBDevice(get_usb_phy(), vendor_id, product_id, product_release),
|
||||
_initialized(false), _in_task(&_queue), _out_task(&_queue), _reset_task(&_queue), _control_task(&_queue), _configure_task(&_queue), _bd(bd)
|
||||
{
|
||||
_init();
|
||||
if (connect_blocking) {
|
||||
connect();
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
USBMSD::USBMSD(USBPhy *phy, BlockDevice *bd, uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
|
||||
: USBDevice(phy, vendor_id, product_id, product_release),
|
||||
_initialized(false), _in_task(&_queue), _out_task(&_queue), _reset_task(&_queue), _control_task(&_queue), _configure_task(&_queue), _bd(bd)
|
||||
{
|
||||
_init();
|
||||
}
|
||||
|
||||
|
||||
void USBMSD::_init()
|
||||
{
|
||||
_bd = bd;
|
||||
_bd->init();
|
||||
|
||||
_in_task = callback(this, &USBMSD::_in);
|
||||
|
@ -100,7 +118,7 @@ bool USBMSD::connect()
|
|||
_mutex.lock();
|
||||
|
||||
// already initialized
|
||||
if (_init) {
|
||||
if (_initialized) {
|
||||
_mutex.unlock();
|
||||
_mutex_init.unlock();
|
||||
return false;
|
||||
|
@ -140,7 +158,7 @@ bool USBMSD::connect()
|
|||
|
||||
//connect the device
|
||||
USBDevice::connect();
|
||||
_init = true;
|
||||
_initialized = true;
|
||||
_mutex.unlock();
|
||||
_mutex_init.unlock();
|
||||
return true;
|
||||
|
@ -152,7 +170,7 @@ void USBMSD::disconnect()
|
|||
_mutex.lock();
|
||||
|
||||
USBDevice::disconnect();
|
||||
_init = false;
|
||||
_initialized = false;
|
||||
|
||||
_in_task.cancel();
|
||||
_out_task.cancel();
|
||||
|
@ -179,11 +197,6 @@ void USBMSD::disconnect()
|
|||
_mutex_init.unlock();
|
||||
}
|
||||
|
||||
bool USBMSD::ready()
|
||||
{
|
||||
return configured();
|
||||
}
|
||||
|
||||
void USBMSD::process()
|
||||
{
|
||||
_queue.dispatch();
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "events/Task.h"
|
||||
#include "BlockDevice.h"
|
||||
#include "Mutex.h"
|
||||
#include "usb_phy_api.h"
|
||||
|
||||
#include "USBDevice.h"
|
||||
|
||||
|
@ -46,7 +45,6 @@
|
|||
* USBMSD usb(&sd);
|
||||
*
|
||||
* int main() {
|
||||
* usb.connect();
|
||||
*
|
||||
* while(true) {
|
||||
* usb.process();
|
||||
|
@ -66,12 +64,31 @@ public:
|
|||
* for the block device to connect.
|
||||
*
|
||||
* @param bd BlockDevice to mount as a USB drive
|
||||
* @param phy USB phy to use
|
||||
* @param connect_blocking true to perform a blocking connect, false to start in a disconnected state
|
||||
* @param vendor_id Your vendor_id
|
||||
* @param product_id Your product_id
|
||||
* @param product_release Your preoduct_release
|
||||
*/
|
||||
USBMSD(BlockDevice *bd, USBPhy *phy=get_usb_phy(), uint16_t vendor_id = 0x0703, uint16_t product_id = 0x0104, uint16_t product_release = 0x0001);
|
||||
USBMSD(BlockDevice *bd, bool connect_blocking = true, uint16_t vendor_id = 0x0703, uint16_t product_id = 0x0104, uint16_t product_release = 0x0001);
|
||||
|
||||
/**
|
||||
* Fully featured constructor
|
||||
*
|
||||
* Construct this object with the supplied USBPhy and parameters. The user
|
||||
* this object is responsible for calling connect() or init().
|
||||
*
|
||||
* @note Derived classes must use this constructor and call init() or
|
||||
* connect() themselves. Derived classes should also call deinit() in
|
||||
* their destructor. This ensures that no interrupts can occur when the
|
||||
* object is partially constructed or destroyed.
|
||||
*
|
||||
* @param phy USB phy to use
|
||||
* @param bd BlockDevice to mount as a USB drive
|
||||
* @param vendor_id Your vendor_id
|
||||
* @param product_id Your product_id
|
||||
* @param product_release Your preoduct_release
|
||||
*/
|
||||
USBMSD(USBPhy *phy, BlockDevice *bd, uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
|
||||
|
||||
/**
|
||||
* Destroy this object
|
||||
|
@ -82,7 +99,7 @@ public:
|
|||
virtual ~USBMSD();
|
||||
|
||||
/**
|
||||
* Connect the USB MSD device. Establish disk initialization before really connect the device.
|
||||
* Connect the USB MSD device.
|
||||
*
|
||||
* @returns true if successful
|
||||
*/
|
||||
|
@ -93,13 +110,6 @@ public:
|
|||
*/
|
||||
void disconnect();
|
||||
|
||||
/**
|
||||
* Check if USB is connected
|
||||
*
|
||||
* @return true if a USB is connected, false otherwise
|
||||
*/
|
||||
bool ready();
|
||||
|
||||
/**
|
||||
* Perform USB processing
|
||||
*/
|
||||
|
@ -190,7 +200,7 @@ private:
|
|||
} CSW;
|
||||
|
||||
// If this class has been initialized
|
||||
bool _init;
|
||||
bool _initialized;
|
||||
|
||||
//state of the bulk-only state machine
|
||||
Stage _stage;
|
||||
|
@ -259,6 +269,7 @@ private:
|
|||
void _control(const setup_packet_t *request);
|
||||
void _configure();
|
||||
|
||||
void _init();
|
||||
void _process();
|
||||
void _write_next(uint8_t *data, uint32_t size);
|
||||
void _read_next();
|
||||
|
|
Loading…
Reference in New Issue