Newer
Older
Tardis / src / MyUSBMSD.cpp
/*
SPDX-License-Identifier: MIT
Copyright (c) 2024 Casey Reeves and the LuminaSensum contributors
*/

#include "MyUSBMSD.h"
#include "ButtonThread.h"
#include "mbed.h"

#include "mbed-trace/mbed_trace.h"
#define TRACE_GROUP "USBM"

// create a custom usb mass storage subclass to override
// the product description

MyUSBMSD::MyUSBMSD(mbed::BlockDevice *bd, bool connect_blocking,
	uint16_t vendor_id, uint16_t product_id, uint16_t product_release)
    : USBMSD(bd, connect_blocking, vendor_id, product_id, product_release) {}

const uint8_t *MyUSBMSD::string_iproduct_desc() {
	static const uint8_t string_iproduct_descriptor[] = {
		0x28, // bLength
		STRING_DESCRIPTOR, // bDescriptorType
		'L', 0, 'u', 0, 'm', 0, 'i', 0, 'n', 0, 'a', 0, 'S', 0, 'e', 0,
		'n', 0, 's', 0, 'u', 0, 'm', 0, ' ', 0, 'T', 0, 'a', 0, 'r', 0,
		'd', 0, 'i', 0, 's', 0 // bString iProduct - usb mass storage
	};
	return string_iproduct_descriptor;
}

void doUSBMSD(mbed::BlockDevice &bd) {
	tr_info("Switching to the usb mass storage mode...");
	MyUSBMSD usb(&bd, true, 0x1209, 0x10);

	while (true) {
		int presses = waitForPresses(0s);
		usb.process();
		if (presses == 1) {
			tr_info("Disconnecting the usb mass storage device...");
			usb.disconnect();
			tr_info("Switched usb mass storage mode off.");
			break;
		}
	}
}