Skip to content

Commit

Permalink
Merge pull request #179 from homeodor/master
Browse files Browse the repository at this point in the history
Added setStartStopCallback
  • Loading branch information
hathach authored Jun 30, 2022
2 parents 7264c14 + bce0afa commit ba23152
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/arduino/msc/Adafruit_USBD_MSC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ void Adafruit_USBD_MSC::setReadWriteCallback(uint8_t lun, read_callback_t rd_cb,
_lun_info[lun].fl_cb = fl_cb;
}

void Adafruit_USBD_MSC::setStartStopCallback(uint8_t lun,
start_stop_callback_t cb) {
_lun_info[lun].start_stop_cb = cb;
}

void Adafruit_USBD_MSC::setReadyCallback(uint8_t lun, ready_callback_t cb) {
_lun_info[lun].ready_cb = cb;
}
Expand Down Expand Up @@ -227,6 +232,17 @@ int32_t tud_msc_scsi_cb(uint8_t lun, const uint8_t scsi_cmd[16], void *buffer,
return resplen;
}

// Callback invoked on start/stop
bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start,
bool load_eject) {
if (!(_msc_dev && _msc_dev->_lun_info[lun].start_stop_cb)) {
return true;
}

return _msc_dev->_lun_info[lun].start_stop_cb(power_condition, start,
load_eject);
}

// Callback invoked when received READ10 command.
// Copy disk's data to buffer (up to bufsize) and return number of copied bytes.
int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset,
Expand Down
9 changes: 9 additions & 0 deletions src/arduino/msc/Adafruit_USBD_MSC.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Adafruit_USBD_MSC : public Adafruit_USBD_Interface {
typedef void (*flush_callback_t)(void);
typedef bool (*ready_callback_t)(void);
typedef bool (*writable_callback_t)(void);
typedef bool (*start_stop_callback_t)(uint8_t power_condition, bool start,
bool load_eject);

Adafruit_USBD_MSC(void);

Expand All @@ -53,6 +55,7 @@ class Adafruit_USBD_MSC : public Adafruit_USBD_Interface {
write_callback_t wr_cb, flush_callback_t fl_cb);
void setReadyCallback(uint8_t lun, ready_callback_t cb);
void setWritableCallback(uint8_t lun, writable_callback_t cb);
void setStartStopCallback(uint8_t lun, start_stop_callback_t cb);

//------------- Single LUN API -------------//
void setID(const char *vendor_id, const char *product_id,
Expand All @@ -75,6 +78,9 @@ class Adafruit_USBD_MSC : public Adafruit_USBD_Interface {
void setWritableCallback(writable_callback_t cb) {
setWritableCallback(0, cb);
}
void setStartStopCallback(start_stop_callback_t cb) {
setStartStopCallback(0, cb);
}

// from Adafruit_USBD_Interface
virtual uint16_t getInterfaceDescriptor(uint8_t itfnum, uint8_t *buf,
Expand All @@ -88,6 +94,7 @@ class Adafruit_USBD_MSC : public Adafruit_USBD_Interface {
flush_callback_t fl_cb;
ready_callback_t ready_cb;
writable_callback_t writable_cb;
start_stop_callback_t start_stop_cb;

const char *_inquiry_vid;
const char *_inquiry_pid;
Expand All @@ -114,6 +121,8 @@ class Adafruit_USBD_MSC : public Adafruit_USBD_Interface {
uint8_t *buffer, uint32_t bufsize);
friend void tud_msc_write10_complete_cb(uint8_t lun);
friend bool tud_msc_is_writable_cb(uint8_t lun);
friend bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition,
bool start, bool load_eject);
};

#endif /* ADAFRUIT_USBD_MSC_H_ */

0 comments on commit ba23152

Please sign in to comment.