浏览代码

🎨 Misc. USB flash code cleanup

Scott Lahteine 3 年前
父节点
当前提交
e4a8c693b0
共有 2 个文件被更改,包括 19 次插入18 次删除
  1. 11
    9
      Marlin/src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp
  2. 8
    9
      Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp

+ 11
- 9
Marlin/src/sd/usb_flashdrive/Sd2Card_FlashDrive.cpp 查看文件

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

+ 8
- 9
Marlin/src/sd/usb_flashdrive/lib-uhs2/usbhost.cpp 查看文件

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

正在加载...
取消
保存