USB device stack, with KL25Z fixes for USB 3.0 hosts and sleep/resume interrupt handling
Dependents: frdm_Slider_Keyboard idd_hw2_figlax_PanType idd_hw2_appachu_finger_chording idd_hw3_AngieWangAntonioDeLimaFernandesDanielLim_BladeSymphony ... more
Fork of USBDevice by
USBMSD Class Reference
USBMSD class: generic class in order to use all kinds of blocks storage chip. More...
#include <USBMSD.h>
Inherits USBDevice.
Public Member Functions | |
USBMSD (uint16_t vendor_id=0x0703, uint16_t product_id=0x0104, uint16_t product_release=0x0001) | |
Constructor. | |
bool | connect (bool blocking=true) |
Connect the USB MSD device. | |
void | disconnect () |
Disconnect the USB MSD device. | |
~USBMSD () | |
Destructor. | |
bool | writeTO (uint8_t endpoint, uint8_t *buffer, uint32_t size, uint32_t maxSize, int timeout_ms) |
Write a certain endpoint. |
Detailed Description
USBMSD class: generic class in order to use all kinds of blocks storage chip.
Introduction
The USBMSD implements the MSD protocol. It permits to access a memory chip (flash, sdcard,...) from a computer over USB. But this class doesn't work standalone, you need to subclass this class and define virtual functions which are called in USBMSD.
How to use this class with your chip ?
You have to inherit and define some pure virtual functions (mandatory step):
- virtual int disk_read(char * data, int block): function to read a block
- virtual int disk_write(const char * data, int block): function to write a block
- virtual int disk_initialize(): function to initialize the memory
- virtual int disk_sectors(): return the number of blocks
- virtual int disk_size(): return the memory size
- virtual int disk_status(): return the status of the storage chip (0: OK, 1: not initialized, 2: no medium in the drive, 4: write protection)
All functions names are compatible with the fat filesystem library. So you can imagine using your own class with USBMSD and the fat filesystem library in the same program. Just be careful because there are two different parts which will access the sd card. You can do a master/slave system using the disk_status method.
Once these functions defined, you can call connect() (at the end of the constructor of your class for instance) of USBMSD to connect your mass storage device. connect() will first call disk_status() to test the status of the disk. If disk_status() returns 1 (disk not initialized), then disk_initialize() is called. After this step, connect() will collect information such as the number of blocks and the memory size.
Definition at line 58 of file USBMSD.h.
Constructor & Destructor Documentation
USBMSD | ( | uint16_t | vendor_id = 0x0703 , |
uint16_t | product_id = 0x0104 , |
||
uint16_t | product_release = 0x0001 |
||
) |
Constructor.
- Parameters:
-
vendor_id Your vendor_id product_id Your product_id product_release Your preoduct_release
Definition at line 66 of file USBMSD.cpp.
~USBMSD | ( | ) |
Destructor.
Definition at line 73 of file USBMSD.cpp.
Member Function Documentation
bool connect | ( | bool | blocking = true ) |
Connect the USB MSD device.
Establish disk initialization before really connect the device.
- Parameters:
-
blocking if not configured
- Returns:
- true if successful
Definition at line 106 of file USBMSD.cpp.
void disconnect | ( | void | ) |
Disconnect the USB MSD device.
Definition at line 137 of file USBMSD.cpp.
bool writeTO | ( | uint8_t | endpoint, |
uint8_t * | buffer, | ||
uint32_t | size, | ||
uint32_t | maxSize, | ||
int | timeout_ms | ||
) | [inherited] |
Write a certain endpoint.
Blocks until the report has been sent successfully, or until the timeout expires, whichever comes first.
- Parameters:
-
endpoint endpoint to write buffer data contained in buffer will be write size the number of bytes to write maxSize the maximum length that can be written on this endpoint timeout_ms timeout in milliseconds
- Returns:
- true if successful, false on error or timeout
Definition at line 928 of file USBDevice.cpp.
Generated on Tue Jul 12 2022 18:05:22 by 1.7.2