Browse Source

🎨 Misc. USB flash code cleanup

Scott Lahteine 2 years ago
parent
commit
e4a8c693b0

+ 11
- 9
Marlin/src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp View File

@@ -61,10 +61,8 @@
61 61
   #define USB_NO_TEST_UNIT_READY // Required for removable media adapter
62 62
   #define USB_HOST_MANUAL_POLL // Optimization to shut off IRQ automatically
63 63
 
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(); }
68 66
   #define SYSTEM_OR_SPECIAL_YIELD(...) marlin_yield();
69 67
   #define delay(x) safe_delay(x)
70 68
 
@@ -82,6 +80,7 @@
82 80
 
83 81
   #define UHS_START  (usb.Init() == 0)
84 82
   #define UHS_STATE(state) UHS_USB_HOST_STATE_##state
83
+
85 84
 #elif ENABLED(USE_OTG_USB_HOST)
86 85
 
87 86
   #if HAS_SD_HOST_DRIVE
@@ -93,7 +92,9 @@
93 92
   #define UHS_START usb.start()
94 93
   #define rREVISION 0
95 94
   #define UHS_STATE(state) USB_STATE_##state
95
+
96 96
 #else
97
+
97 98
   #include "lib-uhs2/Usb.h"
98 99
   #include "lib-uhs2/masstorage.h"
99 100
 
@@ -102,6 +103,7 @@
102 103
 
103 104
   #define UHS_START usb.start()
104 105
   #define UHS_STATE(state) USB_STATE_##state
106
+
105 107
 #endif
106 108
 
107 109
 #include "Sd2Card_FlashDrive.h"
@@ -271,11 +273,11 @@ bool DiskIODriver_USBFlash::init(const uint8_t, const pin_t) {
271 273
   if (!isInserted()) return false;
272 274
 
273 275
   #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
+    }
279 281
   #endif
280 282
 
281 283
   #if USB_DEBUG >= 3

+ 8
- 9
Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp View File

@@ -27,19 +27,18 @@
27 27
 
28 28
 #if ENABLED(USB_FLASH_DRIVE_SUPPORT) && DISABLED(USE_UHS3_USB)
29 29
 
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
+
30 34
 #include "Usb.h"
31 35
 #include "usbhost.h"
32 36
 
33 37
 uint8_t MAX3421e::vbusState = 0;
34 38
 
35 39
 // 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); }
43 42
 
44 43
 // write single byte into MAX3421 register
45 44
 void MAX3421e::regWr(uint8_t reg, uint8_t data) {
@@ -76,8 +75,8 @@ uint8_t MAX3421e::regRd(uint8_t reg) {
76 75
   ncs();
77 76
   return rv;
78 77
 }
79
-// multiple-byte register read
80 78
 
79
+// multiple-byte register read
81 80
 // return a pointer to a memory position after last read
82 81
 uint8_t* MAX3421e::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p) {
83 82
   cs();
@@ -86,8 +85,8 @@ uint8_t* MAX3421e::bytesRd(uint8_t reg, uint8_t nbytes, uint8_t *data_p) {
86 85
   ncs();
87 86
   return data_p;
88 87
 }
89
-// GPIO read. See gpioWr for explanation
90 88
 
89
+// GPIO read. See gpioWr for explanation
91 90
 // GPIN pins are in high nybbles of IOPINS1, IOPINS2
92 91
 uint8_t MAX3421e::gpioRd() {
93 92
   return (regRd(rIOPINS2) & 0xF0) | // pins 4-7, clean lower nybble

Loading…
Cancel
Save