Skip to content

Commit dc93cb8

Browse files
thinkyheadLCh-77
authored andcommitted
🎨 Misc. USB flash code cleanup
1 parent 0db0c8e commit dc93cb8

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

Marlin/src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,8 @@
6161
#define USB_NO_TEST_UNIT_READY // Required for removable media adapter
6262
#define USB_HOST_MANUAL_POLL // Optimization to shut off IRQ automatically
6363

64-
// Workarounds for keeping Marlin's watchdog timer from barking...
65-
void marlin_yield() {
66-
thermalManager.manage_heater();
67-
}
64+
// Workarounds to keep Marlin's watchdog timer from barking...
65+
void marlin_yield() { thermalManager.manage_heater(); }
6866
#define SYSTEM_OR_SPECIAL_YIELD(...) marlin_yield();
6967
#define delay(x) safe_delay(x)
7068

@@ -82,6 +80,7 @@
8280

8381
#define UHS_START (usb.Init() == 0)
8482
#define UHS_STATE(state) UHS_USB_HOST_STATE_##state
83+
8584
#elif ENABLED(USE_OTG_USB_HOST)
8685

8786
#if HAS_SD_HOST_DRIVE
@@ -93,7 +92,9 @@
9392
#define UHS_START usb.start()
9493
#define rREVISION 0
9594
#define UHS_STATE(state) USB_STATE_##state
95+
9696
#else
97+
9798
#include "lib-uhs2/Usb.h"
9899
#include "lib-uhs2/masstorage.h"
99100

@@ -102,6 +103,7 @@
102103

103104
#define UHS_START usb.start()
104105
#define UHS_STATE(state) USB_STATE_##state
106+
105107
#endif
106108

107109
#include "Sd2Card_FlashDrive.h"
@@ -271,11 +273,11 @@ bool DiskIODriver_USBFlash::init(const uint8_t, const pin_t) {
271273
if (!isInserted()) return false;
272274

273275
#if USB_DEBUG >= 1
274-
const uint32_t sectorSize = bulk.GetSectorSize(0);
275-
if (sectorSize != 512) {
276-
SERIAL_ECHOLNPGM("Expecting sector size of 512. Got: ", sectorSize);
277-
return false;
278-
}
276+
const uint32_t sectorSize = bulk.GetSectorSize(0);
277+
if (sectorSize != 512) {
278+
SERIAL_ECHOLNPGM("Expecting sector size of 512. Got: ", sectorSize);
279+
return false;
280+
}
279281
#endif
280282

281283
#if USB_DEBUG >= 3

Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp

+8-9
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@
2727

2828
#if ENABLED(USB_FLASH_DRIVE_SUPPORT) && DISABLED(USE_UHS3_USB)
2929

30+
#if !PINS_EXIST(USB_CS, USB_INTR)
31+
#error "USB_FLASH_DRIVE_SUPPORT requires USB_CS_PIN and USB_INTR_PIN to be defined."
32+
#endif
33+
3034
#include "Usb.h"
3135
#include "usbhost.h"
3236

3337
uint8_t MAX3421e::vbusState = 0;
3438

3539
// constructor
36-
void MAX3421e::cs() {
37-
WRITE(USB_CS_PIN,0);
38-
}
39-
40-
void MAX3421e::ncs() {
41-
WRITE(USB_CS_PIN,1);
42-
}
40+
void MAX3421e::cs() { WRITE(USB_CS_PIN, LOW); }
41+
void MAX3421e::ncs() { WRITE(USB_CS_PIN, HIGH); }
4342

4443
// write single byte into MAX3421 register
4544
void MAX3421e::regWr(uint8_t reg, uint8_t data) {
@@ -76,8 +75,8 @@ uint8_t MAX3421e::regRd(uint8_t reg) {
7675
ncs();
7776
return rv;
7877
}
79-
// multiple-byte register read
8078

79+
// multiple-byte register read
8180
// return a pointer to a memory position after last read
8281
uint8_t* MAX3421e::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p) {
8382
cs();
@@ -86,8 +85,8 @@ uint8_t* MAX3421e::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p) {
8685
ncs();
8786
return data_p;
8887
}
89-
// GPIO read. See gpioWr for explanation
9088

89+
// GPIO read. See gpioWr for explanation
9190
// GPIN pins are in high nybbles of IOPINS1, IOPINS2
9291
uint8_t MAX3421e::gpioRd() {
9392
return (regRd(rIOPINS2) & 0xF0) | // pins 4-7, clean lower nybble

0 commit comments

Comments
 (0)