Explorar el Código

feat: do code cleanup

Alex4386 hace 1 año
padre
commit
a7c997f0f2
Se han modificado 5 ficheros con 56 adiciones y 39 borrados
  1. 35 25
      README.md
  2. 11 4
      src/scenes/mtp/mtp.c
  3. 2 2
      src/scenes/mtp/mtp.h
  4. 1 1
      src/scenes/mtp/usb.h
  5. 7 7
      src/scenes/mtp/usb_desc.h

+ 35 - 25
README.md

@@ -9,18 +9,18 @@ See this in action on YouTube!<br>
 - **Latest Release**: [Download](https://github.com/Alex4386/f0-mtp/releases/latest)
 - **Latest Nightly**: [Download](https://github.com/Alex4386/f0-mtp/actions/workflows/nightly.yml) _(GitHub Login Required)_
 
-|                                           Nightly Build                                           |                                           Release Build                                           |
-| :-----------------------------------------------------------------------------------------------: | :-----------------------------------------------------------------------------------------------: |
+|                                        Nightly Build                                         |                                        Release Build                                         |
+| :------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------: |
 | ![Nightly Build](https://github.com/Alex4386/f0-mtp/actions/workflows/nightly.yml/badge.svg) | ![Release Build](https://github.com/Alex4386/f0-mtp/actions/workflows/release.yml/badge.svg) |
 
 ## What is this?
 
 `f0-mtp` is a application that implements [`MTP (Media Transfer Protocol)` defined by `USB-IF`](https://www.usb.org/document-library/media-transfer-protocol-v11-spec-and-mtp-v11-adopters-agreement) on Flipper Zero.  
-This allows you to access the Flipper Zero's internal and SD card storages from your computer without the need of any additional drivers like [`HID-File-Transfer`](https://github.com/Kavakuo/HID-File-Transfer).  
-  
-If your computer can handle Android devices, it should be able to handle Flipper Zero as well with this application.  
+This allows you to access the Flipper Zero's internal and SD card storages from your computer without the need of any additional drivers like [`HID-File-Transfer`](https://github.com/Kavakuo/HID-File-Transfer).
 
-Due to limitation of the Flipper Zero's hardware, The MTP connection utilizes `Full Speed` USB, which is USB 1.1 (12Mbps). which may be slow&trade;.  
+If your computer can handle Android devices, it should be able to handle Flipper Zero as well with this application.
+
+Due to limitation of the Flipper Zero's hardware, The MTP connection utilizes `Full Speed` USB, which is USB 1.1 (12Mbps). which may be slow&trade;.
 
 > [!NOTE]
 > Flipper Zero utilizes `SPI` for SD card, which speed is limited to around 1MB/s.  
@@ -28,53 +28,63 @@ Due to limitation of the Flipper Zero's hardware, The MTP connection utilizes `F
 > <b>So, If you need quick copy, Use a proper SD Card Reader.</b>
 
 ### Before using...
+
 Here are some things you should know before using this application:
 
-> [!WARNING]
-> **DO NOT transfer files over 64K** in one go.  
+> [!WARNING] > **DO NOT transfer files over 64K** in one go.  
 > This will:
+>
 > - **Crash the Flipper** if the file is too big.
-> 
-> And _might_ :  
+>
+> And _might_ :
+>
 > - **Corrupt the SD Card filesystem** due to current implementation's limitation.
 >   (If you know how to fix this issue, feel free to give me a PR!, quick `chkdsk` will fix the corruption though)
->
 
-> [!WARNING]
-> **DO NOT** use `UNICODE` characters in the file/directory names.  
+> [!WARNING] > **DO NOT** use `UNICODE` characters in the file/directory names.  
 > Flipper Zero's filesystem isn't designed to handle `UNICODE` characters. such as:
+>
 > - `한글.txt`
 > - `日本語.txt`
 > - `中文.txt`
 
 ### Features
-* Access Internal and SD card storages
-* List files and directories
-   - Navigate directories
-* Opening Files (Downloading Flipper files into Computer)
+
+- Access Internal and SD card storages
+- List files and directories
+  - Navigate directories
+- Opening Files (Downloading Flipper files into Computer)
   - Large file transfer now **WORKS**!
     - It didn't work since the header did not have proper `size` defined, ignoring the further packets.
     - Now utilizing even less memory via `streaming` support!
-* Move Files into Flipper
+- Move Files into Flipper
   - **NEW!** Now you can upload files to Flipper Zero!
   - **Note:** Flipper Zero has limited memory, please refrain from moving files bigger than 64K on one go. (for me 80K was a hard limit)
-* Deleting Files/Directories
+- Deleting Files/Directories
+- Move Files/Directories
+- Create Directories (Renaming not supported)
+- Actual **Serial Number**, **Model Name**, **Firmware Version** is now shown in the MTP client.
+
+### Known Issuesß
 
-### Known Issues
-* Renaming directories, files are not supported yet.
-* Fix "memory leaks"  
+- Renaming directories, files are not supported yet.
+- Fix "memory leaks"
   - I'm currently busy working on code cleanup. So, I can't afford to do this right now.
 
 ## How to build
-See [HOW_TO_BUILD.md](HOW_TO_BUILD.md) for more information.  
+
+See [HOW_TO_BUILD.md](HOW_TO_BUILD.md) for more information.
 
 ## Special Thanks
+
 - [viveris/uMTP-Responder](https://github.com/viveris/uMTP-Responder)
 - [yoonghm/MTP](https://github.com/yoonghm/MTP)
 
-**and Special NOT Thanks to**:  
-- [Microsoft](https://microsoft.com) for making the [MTP Spec](https://www.usb.org/document-library/media-transfer-protocol-v11-spec-and-mtp-v11-adopters-agreement) so hard to understand. `>:(`  
+**and Special NOT Thanks to**:
+
+- [Microsoft](https://microsoft.com) for making the [MTP Spec](https://www.usb.org/document-library/media-transfer-protocol-v11-spec-and-mtp-v11-adopters-agreement) so hard to understand. `>:(`
 - [Microsoft](https://microsoft.com) for reserving place for programmers to live in `WideChar` and `MultiByte` hellscape. `>:(`
 
 ## License
+
 This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

+ 11 - 4
src/scenes/mtp/mtp.c

@@ -914,10 +914,16 @@ int GetDevicePropValue(uint32_t prop_code, uint8_t* buffer) {
     uint16_t length;
 
     switch(prop_code) {
-    case 0xd402:
-        WriteMTPString(ptr, "Flipper Zero", &length);
+    case 0xd402: {
+        const char* deviceName = furi_hal_version_get_name_ptr();
+        if(deviceName == NULL) {
+            deviceName = "Flipper Zero";
+        }
+
+        WriteMTPString(ptr, deviceName, &length);
         ptr += length;
         break;
+    }
     case 0x5001: {
         // Battery level
         Power* power = furi_record_open(RECORD_POWER);
@@ -1227,7 +1233,8 @@ int BuildDeviceInfo(uint8_t* buffer) {
     ptr += length;
 
     // Device version
-    WriteMTPString(ptr, MTP_DEVICE_VERSION, &length);
+    const Version* ver = furi_hal_version_get_firmware_version();
+    WriteMTPString(ptr, version_get_version(ver), &length);
     ptr += length;
 
     // Serial number
@@ -1520,7 +1527,7 @@ int GetObjectPropValueInternal(AppMTP* mtp, const char* path, uint32_t prop_code
         *(uint32_t*)ptr = 0xffff;
         ptr += sizeof(uint32_t);
 
-        *(uint8_t*)ptr = 0x00;
+        *(uint8_t*)ptr = 0x01;
         ptr += sizeof(uint8_t);
 
         char* file_name = strrchr(path, '/');

+ 2 - 2
src/scenes/mtp/mtp.h

@@ -1,8 +1,8 @@
 #pragma once
 
 // MTP Device Serial
-#define MTP_DEVICE_FALLBACK_SERIAL "HakureiReimu"
-#define MTP_DEVICE_VERSION         "1.0"
+#define MTP_DEVICE_FALLBACK_SERIAL \
+    "HakureiReimu" // If you found this, Thank you for checking my (shitty) code!
 
 #define MTP_STANDARD_VERSION         100
 #define MTP_VENDOR_EXTENSION_ID      0x6

+ 1 - 1
src/scenes/mtp/usb.h

@@ -18,4 +18,4 @@ enum UsbDevDescStr {
 void usb_mtp_init(usbd_device* dev, FuriHalUsbInterface* intf, void* ctx);
 void usb_mtp_deinit(usbd_device* dev);
 void usb_mtp_wakeup(usbd_device* dev);
-void usb_mtp_suspend(usbd_device* dev);
+void usb_mtp_suspend(usbd_device* dev);

+ 7 - 7
src/scenes/mtp/usb_desc.h

@@ -4,21 +4,21 @@
 #include <furi_hal_usb.h>
 
 #define USB_MANUFACTURER_STRING "Flipper Devices Inc."
-#define USB_PRODUCT_STRING "Flipper Zero Virtual MTP Device"
-#define USB_DEVICE_MODEL "Flipper Zero"
+#define USB_PRODUCT_STRING      "Flipper Zero Virtual MTP Device"
+#define USB_DEVICE_MODEL        "Flipper Zero"
 
 #define USB_SUBCLASS_MTP 0x01
-#define USB_PROTO_MTP 0x01
+#define USB_PROTO_MTP    0x01
 #define USB_CONF_VAL_MTP 1
 
 // Endpoint Addresses
-#define MTP_EP_IN_ADDR 0x81
-#define MTP_EP_OUT_ADDR 0x02
+#define MTP_EP_IN_ADDR     0x81
+#define MTP_EP_OUT_ADDR    0x02
 #define MTP_EP_INT_IN_ADDR 0x03
 
-#define MTP_MAX_PACKET_SIZE 64
+#define MTP_MAX_PACKET_SIZE    64
 #define USB_MAX_INTERRUPT_SIZE 28
-#define BCD_VERSION VERSION_BCD(1, 0, 0)
+#define BCD_VERSION            VERSION_BCD(1, 0, 0)
 
 struct MtpDescriptor {
     struct usb_config_descriptor config;