Skip to content

Commit f579bbd

Browse files
committed
reenum adding cdc and msc doesnt reenum til the end
1 parent 8614a6d commit f579bbd

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/components/i2c/controller.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,8 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
692692
if ((strcmp(device_name, "pca9546") == 0) ||
693693
(strcmp(device_name, "pca9548") == 0)) {
694694
WS_DEBUG_PRINT("[i2c] Initializing MUX driver...");
695-
if (!InitMux(device_name, device_descriptor.i2c_device_address, use_alt_bus)) {
695+
if (!InitMux(device_name, device_descriptor.i2c_device_address,
696+
use_alt_bus)) {
696697
// TODO [Online]: Publish back out to IO here!
697698
WsV2.haltErrorV2("[i2c] Failed to initialize MUX driver!",
698699
WS_LED_STATUS_ERROR_RUNTIME, false);
@@ -732,6 +733,13 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
732733
// Get all possible driver candidates for this address
733734
WS_DEBUG_PRINT("[i2c] Obtaining driver candidates @ 0x");
734735
WS_DEBUG_PRINTLN(device_descriptor.i2c_device_address);
736+
if (device_descriptor.i2c_device_address == 0x68 ||
737+
device_descriptor.i2c_device_address == 0x70) {
738+
WS_DEBUG_PRINTLN("[i2c] Device address is shared with rtx/mux, can not "
739+
"auto-init, skipping!");
740+
return true;
741+
}
742+
735743
std::vector<const char *> candidate_drivers =
736744
GetDriversForAddress(device_descriptor.i2c_device_address);
737745

@@ -770,7 +778,8 @@ bool I2cController::Handle_I2cDeviceAddOrReplace(pb_istream_t *stream) {
770778
device_name, bus, device_descriptor.i2c_device_address,
771779
device_descriptor.i2c_mux_channel, device_status);
772780
if (drv == nullptr) {
773-
WS_DEBUG_PRINTLN("[i2c] ERROR: I2C driver type not found or unsupported!");
781+
WS_DEBUG_PRINTLN(
782+
"[i2c] ERROR: I2C driver type not found or unsupported!");
774783
return false;
775784
}
776785

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ws_sdcard::ws_sdcard() {
5050
_sz_cur_log_file = 0;
5151
_sd_cur_log_files = 0;
5252

53-
delay(4000); // TODO: Must enable this delay to debugging the ctor, serial
54-
// won't open otherwise
53+
delay(4000); // TODO: This is for debugging, remove when ready for final
54+
// version!
5555
bool did_init = false;
5656
// Case 1: Try to initialize the SD card with the pin from the config file
5757
if (WsV2.pin_sd_cs != SD_CS_CFG_NOT_FOUND) {

src/provisioning/tinyusb/Wippersnapper_FS.cpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Adafruit_FlashTransport_RP2040 flashTransport_v2;
5858
Adafruit_SPIFlash flash_v2(&flashTransport_v2); ///< SPIFlash object
5959
FatVolume wipperFatFs_v2; ///< File system object from Adafruit SDFat library
6060
Adafruit_USBD_MSC usb_msc_v2; /*!< USB mass storage object */
61+
Adafruit_USBD_CDC usb_cdc; /*!< USB CDC object */
6162
static bool _fs_changed = false;
6263

6364
/**************************************************************************/
@@ -104,10 +105,15 @@ FRESULT format_fs_fat12(void) {
104105
/**************************************************************************/
105106
Wippersnapper_FS::Wippersnapper_FS() {
106107
_fs_changed = false;
107-
// Detach USB device during init.
108-
TinyUSBDevice.detach();
109-
// Wait for detach
110-
delay(500);
108+
109+
usb_cdc.begin(115200);
110+
// If already enumerated, additional class driver begin() e.g msc, hid, midi
111+
// won't take effect until re-enumeration
112+
if (TinyUSBDevice.mounted()) {
113+
TinyUSBDevice.detach();
114+
delay(10);
115+
TinyUSBDevice.attach();
116+
}
111117

112118
// Attempt to initialize the flash chip
113119
if (!flash_v2.begin()) {
@@ -282,22 +288,22 @@ void Wippersnapper_FS::InitUsbMsc() {
282288
usb_msc_v2.setCapacity(flash_v2.pageSize() * flash_v2.numPages() / 512, 512);
283289

284290
// MSC is ready for read/write
285-
usb_msc_v2.setUnitReady(true);
291+
usb_msc_v2.setUnitReady(false);
286292

287293
// Set callback when MSC ready
288294
_fs_changed = false;
289295
usb_msc_v2.setReadyCallback(0, msc_ready_callback);
290296

291297
// init MSC
292-
usb_msc_v2.begin();
298+
// usb_msc_v2.begin();
293299

294-
// If already enumerated, additional class driverr begin() e.g msc, hid, midi
295-
// won't take effect until re-enumeration
296-
// Attach MSC and wait for enumeration
297-
//#ifndef BUILD_OFFLINE_ONLY
300+
// If already enumerated, additional class driverr begin() e.g msc, hid, midi
301+
// won't take effect until re-enumeration
302+
// Attach MSC and wait for enumeration
303+
// #ifndef BUILD_OFFLINE_ONLY
298304
TinyUSBDevice.attach();
299305
delay(500);
300-
//#endif
306+
// #endif
301307
}
302308

303309
/**************************************************************************/
@@ -382,7 +388,7 @@ void Wippersnapper_FS::CreateFileConfig() {
382388
if (file_cfg) {
383389
DeserializationError error = deserializeJson(_doc_cfg, file_cfg);
384390
// if (error)
385-
// HaltFilesystem("Error unable to parse config.json on WIPPER drive!");
391+
// HaltFilesystem("Error unable to parse config.json on WIPPER drive!");
386392
// Remove config from the filesystem
387393
file_cfg.close();
388394
wipperFatFs_v2.remove("/config.json");
@@ -488,8 +494,13 @@ bool Wippersnapper_FS::WriteFileConfig() {
488494
// Re-attach USB-MSC with updated filesystem
489495
// NOTE: This is required to ensure the filesystem is sync'd between host and
490496
// device
491-
// TinyUSBDevice.attach();
492-
delay(2500);
497+
usb_msc_v2.begin();
498+
usb_msc_v2.setUnitReady(true);
499+
if (TinyUSBDevice.mounted()) {
500+
TinyUSBDevice.detach();
501+
delay(10);
502+
TinyUSBDevice.attach();
503+
}
493504
// TODO: This is debug, we can remove it!
494505
WS_DEBUG_PRINT("Bytes written to config.json: ");
495506
WS_DEBUG_PRINTLN(bytes_written);

0 commit comments

Comments
 (0)