From d9c2f5be3f76d971e2244590749d5879e145516d Mon Sep 17 00:00:00 2001 From: Whywilson Date: Wed, 13 Dec 2023 02:50:40 +0000 Subject: [PATCH 1/2] Finish the BLE protocol under english. --- docs/en/05+1-ble_protocol.md | 184 ++++++++++++++++++++++++++++++++++- 1 file changed, 182 insertions(+), 2 deletions(-) diff --git a/docs/en/05+1-ble_protocol.md b/docs/en/05+1-ble_protocol.md index da5255f8..05200457 100644 --- a/docs/en/05+1-ble_protocol.md +++ b/docs/en/05+1-ble_protocol.md @@ -248,7 +248,7 @@ TODO Supplement the error code in detail. . | cmd | uint8 | 1 | fixed 0x12 | | status | uint8 | 1 | Status code, see status code description | | chunk | uint16 | 2 | 0 | -| file id | uint8 | 1 | File ID, used for subsequent read and write requests | +| file id | uint8 | 1 | file id, used for subsequent read and write requests | ## 0x13: Close file @@ -257,4 +257,184 @@ TODO Supplement the error code in detail. . | Field name | Type | Length (bytes) | Description | | ---- | ----- |---- | ---- | | cmd | uint8 | 1 | 0x13 | -| sta \ No newline at end of file +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | 0 | +| file id | uint8 | 1 | file id | + + +2. Service response + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x13 | +| status | uint8 | 1 | Status code, see status code description | +| chunk | uint16 | 2 | 0 | +| file id | uint8 | 1 | file id, used for subsequent read and write requests | + + +## 0x14: Read file + +1. The client sends a request + +Only support sequential reading. + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x14 | +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | 0 | +| file id | uint8 | 1| file id | + + +2. The server responds to the request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x14 | +| status | uint8 | 1 |Status code, see status code description | +| chunk | uint16 | 2 | Enable chunk transfer | +| data | byte | N | File data | + + +## 0x15 Write to file + +1. The client sends a request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x15 | +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | Enable chunk transfer | +| file id | uint8 | 1 | file id | +| data | byte | N | File data, max length = MTU - 4 | + + + +2. The server responds to the request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x15 | +| status | uint8 | 1 |Status code, see status code description | +| chunk | uint16 | 2 | Same as Request | + + +## 0x16:Read folder + +1. The client sends a request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x16 | +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | 0 | +| path length | uint16 | 2 | Path length under bytes | +| path | byte | N | Path string bytes | + + +2. The server responds to the request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x16 | +| status | uint8 | 1 |Status code, see status code description | +| chunk | uint16 | 2 | Enable chunk transfer | +| file N name length| uint16 | 2 | File name bytes length| +| file N name | byte | N| File name bytes | +| file N size | uint32 | 4 |File size | +| file N type | uint8 | 1 | File Type: 0 => File, 1 => Folder | +| file N meta length | uint8 | 1 | File meta data length, 64 max| +| file N meta | byte | N | File meta data | + +## 0x17 Create folder + +1. The client sends a request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x17 | +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | 0 | +| path length | uint16 | 2 | Path length under bytes | +| path | byte | N | Path string bytes | + + +2. The server responds to the request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x17 | +| status | uint8 | 1 |Status code, see status code description | +| chunk | uint16 | 2 | 0 | + + + +## 0x18 Delete file or folder + +1. The client sends a request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x18 | +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | 0 | +| path length | uint16 | 2 | Path length under bytes | +| path | byte | N | Path string bytes | + + +2. The server responds to the request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x18 | +| status | uint8 | 1 |Status code, see status code description | +| chunk | uint16 | 2 | 0 | + + +## 0x19 Rename file or folder + +1. The client sends a request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x18 | +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | Enable chunk transfer | +| old path length | uint16 | 2 | Path length under bytes | +| old path | byte | N | Path string bytes | +| new path length | uint16 | 2 | Path length under bytes | +| new path | byte | N | Path string bytes | + +If data length is larger than MTU, use chunk transfer. + + +2. The server responds to the request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x18 | +| status | uint8 | 1 |Status code, see status code description | +| chunk | uint16 | 2 | 0 | + + +## 0x1A Update file meta + +1. The client sends a request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x1a | +| status | uint8 | 1 | 0 | +| chunk | uint16 | 2 | 0 | +| path length | uint16 | 2 | Path length under bytes | +| path | byte | N | Path string bytes | +| meta data | byte | N | File Meta Data | + +2. The server responds to the request + +| Field name | Type | Length (bytes) | Description | +| ---- | ----- |---- | ---- | +| cmd | uint8 | 1 | 0x1a | +| status | uint8 | 1 |Status code, see status code description | +| chunk | uint16 | 2 | 0 | + From 4a52f5adb736a958c0e3c37f9e6e320cfa3da82e Mon Sep 17 00:00:00 2001 From: fishybow <149327606+fishybow@users.noreply.github.com> Date: Thu, 28 Dec 2023 11:59:57 -0800 Subject: [PATCH 2/2] Update settings.c: Update settings.c: Default battery mode now depends on whether the screen is OLED. Though OLED doesn't necessarily imply rechargeable battery, it's usually the case, hence the change. --- fw/application/src/mod/settings.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fw/application/src/mod/settings.c b/fw/application/src/mod/settings.c index c180c04c..90dbf07e 100644 --- a/fw/application/src/mod/settings.c +++ b/fw/application/src/mod/settings.c @@ -6,13 +6,20 @@ #define SETTINGS_FILE_NAME "/settings.bin" +#ifdef OLED_SCREEN +// Though OLED doesn't necessarily imply rechargeable battery, it's usually the case. +#define DEFAULT_BAT_MODE 1 +#else // !OLED_SCREEN +#define DEFAULT_BAT_MODE 0 +#endif // OLED_SCREEN + const settings_data_t def_settings_data = {.backlight = 0, .oled_contrast = 40, .auto_gen_amiibo = 0, .auto_gen_amiibolink = 0, .sleep_timeout_sec = 30, .skip_driver_select = 0, - .bat_mode = 0, + .bat_mode = DEFAULT_BAT_MODE, .amiibo_link_ver = BLE_AMIIBOLINK_VER_V1, .language = LANGUAGE_EN_US, .hibernate_enabled = false, @@ -132,4 +139,4 @@ int32_t settings_reset() { memcpy(&m_settings_data, &def_settings_data, sizeof(settings_data_t)); vfs_driver_t *p_driver = vfs_get_default_driver(); return p_driver->remove_file(SETTINGS_FILE_NAME); -} \ No newline at end of file +}