Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1e2bf1b

Browse files
authoredJun 13, 2024··
Merge branch 'master' into bugfix/client_read_bytes
2 parents 8c1804d + a31a5fc commit 1e2bf1b

File tree

14 files changed

+270
-108
lines changed

14 files changed

+270
-108
lines changed
 

‎.github/scripts/on-push.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ if [ "$BUILD_PIO" -eq 0 ]; then
108108

109109
if [ "$BUILD_LOG" -eq 1 ]; then
110110
#remove last comma from the last JSON object
111-
sed -i '$ s/.$//' "$sizes_file"
111+
sed -i '$ s/,$//' "$sizes_file"
112112
#echo end of JSON array
113113
echo "]}" >> $sizes_file
114114
fi

‎.github/scripts/set_push_chunks.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
build_all=false
4+
chunks_count=0
5+
6+
if [[ $CORE_CHANGED == 'true' ]] || [[ $IS_PR != 'true' ]]; then
7+
echo "Core files changed or not a PR. Building all."
8+
build_all=true
9+
chunks_count=$MAX_CHUNKS
10+
elif [[ $LIB_CHANGED == 'true' ]]; then
11+
echo "Libraries changed. Building only affected sketches."
12+
if [[ $NETWORKING_CHANGED == 'true' ]]; then
13+
echo "Networking libraries changed. Building networking related sketches."
14+
networking_sketches="$(find libraries/WiFi -name *.ino) "
15+
networking_sketches+="$(find libraries/Ethernet -name *.ino) "
16+
networking_sketches+="$(find libraries/PPP -name *.ino) "
17+
networking_sketches+="$(find libraries/NetworkClientSecure -name *.ino) "
18+
networking_sketches+="$(find libraries/WebServer -name *.ino) "
19+
fi
20+
if [[ $FS_CHANGED == 'true' ]]; then
21+
echo "FS libraries changed. Building FS related sketches."
22+
fs_sketches="$(find libraries/SD -name *.ino) "
23+
fs_sketches+="$(find libraries/SD_MMC -name *.ino) "
24+
fs_sketches+="$(find libraries/SPIFFS -name *.ino) "
25+
fs_sketches+="$(find libraries/LittleFS -name *.ino) "
26+
fs_sketches+="$(find libraries/FFat -name *.ino) "
27+
fi
28+
sketches="$networking_sketches $fs_sketches"
29+
for file in $LIB_FILES; do
30+
if [[ $file == *.ino ]]; then
31+
# If file ends with .ino, add it to the list of sketches
32+
echo "Sketch found: $file"
33+
sketches+="$file "
34+
elif [[ $(basename $(dirname $file)) == "src" ]]; then
35+
# If file is in a src directory, find all sketches in the parent/examples directory
36+
echo "Library src file found: $file"
37+
lib=$(dirname $(dirname $file))
38+
if [[ -d $lib/examples ]]; then
39+
lib_sketches=$(find $lib/examples -name *.ino)
40+
sketches+="$lib_sketches "
41+
echo "Library sketches: $lib_sketches"
42+
fi
43+
else
44+
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
45+
echo "File in example folder found: $file"
46+
sketch=$(find $(dirname $file) -name *.ino)
47+
sketches+="$sketch "
48+
echo "Sketch in example folder: $sketch"
49+
fi
50+
echo ""
51+
done
52+
fi
53+
54+
if [[ -n $sketches ]]; then
55+
# Remove duplicates
56+
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
57+
for sketch in $sketches; do
58+
echo $sketch >> sketches_found.txt
59+
chunks_count=$((chunks_count+1))
60+
done
61+
echo "Number of sketches found: $chunks_count"
62+
echo "Sketches:"
63+
echo "$sketches"
64+
65+
if [[ $chunks_count -gt $MAX_CHUNKS ]]; then
66+
echo "More sketches than the allowed number of chunks found. Limiting to $MAX_CHUNKS chunks."
67+
chunks_count=$MAX_CHUNKS
68+
fi
69+
fi
70+
71+
chunks='["0"'
72+
for i in $(seq 1 $(( $chunks_count - 1 )) ); do
73+
chunks+=",\"$i\""
74+
done
75+
chunks+="]"
76+
77+
echo "build_all=$build_all" >> $GITHUB_OUTPUT
78+
echo "build_libraries=$BUILD_LIBRARIES" >> $GITHUB_OUTPUT
79+
echo "build_static_sketches=$BUILD_STATIC_SKETCHES" >> $GITHUB_OUTPUT
80+
echo "build_idf=$BUILD_IDF" >> $GITHUB_OUTPUT
81+
echo "build_platformio=$BUILD_PLATFORMIO" >> $GITHUB_OUTPUT
82+
echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT
83+
echo "chunks=$chunks" >> $GITHUB_OUTPUT

‎.github/scripts/sketch_utils.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
192192

193193
exit_status=$?
194194
if [ $exit_status -ne 0 ]; then
195-
echo ""ERROR: Compilation failed with error code $exit_status""
195+
echo "ERROR: Compilation failed with error code $exit_status"
196196
exit $exit_status
197197
fi
198198

@@ -236,7 +236,7 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
236236

237237
exit_status=$?
238238
if [ $exit_status -ne 0 ]; then
239-
echo ""ERROR: Compilation failed with error code $exit_status""
239+
echo "ERROR: Compilation failed with error code $exit_status"
240240
exit $exit_status
241241
fi
242242
# $ide_path/arduino-builder -compile -logger=human -core-api-version=10810 \
@@ -398,6 +398,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
398398
else
399399
start_index=$(( $chunk_index * $chunk_size ))
400400
if [ "$sketchcount" -le "$start_index" ]; then
401+
echo "No sketches to build for $target in this chunk"
401402
return 0
402403
fi
403404

@@ -437,7 +438,7 @@ function build_sketches(){ # build_sketches <ide_path> <user_path> <target> <pat
437438
continue
438439
fi
439440
echo ""
440-
echo "Building Sketch Index $(($sketchnum - 1)) - $sketchdirname"
441+
echo "Building Sketch Index $sketchnum - $sketchdirname"
441442
build_sketch $args -s $sketchdir $xtra_opts
442443
local result=$?
443444
if [ $result -ne 0 ]; then

‎.github/scripts/tests_run.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ function run_test() {
9595
printf "\033[95mpytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args\033[0m\n"
9696
bash -c "set +e; pytest tests --build-dir $build_dir -k test_$sketchname --junit-xml=$report_file $extra_args; exit \$?" || result=$?
9797
printf "\n"
98-
result=$?
9998
if [ $result -ne 0 ]; then
99+
printf "\033[91mFailed test: $sketchname -- Config: $i\033[0m\n\n"
100100
error=$result
101101
fi
102102
fi
103103
done
104-
printf "Test return code: $error\n"
105104
return $error
106105
}
107106

@@ -250,7 +249,6 @@ else
250249

251250
exit_code=0
252251
run_test $target $sketch $options $erase || exit_code=$?
253-
echo "Sketch $sketch exit code: $exit_code"
254252
if [ $exit_code -ne 0 ]; then
255253
error=$exit_code
256254
fi

‎.github/workflows/hw.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,16 @@ jobs:
7777
run: |
7878
pip install -U pip
7979
pip install -r tests/requirements.txt --extra-index-url https://dl.espressif.com/pypi
80+
apt update
81+
apt install -y jq
8082
8183
- name: Get binaries
82-
id: cache-build-binaries
83-
uses: actions/cache/restore@v4
8484
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
85+
uses: actions/download-artifact@v4
8586
with:
86-
fail-on-cache-miss: true
87-
key: tests-${{ env.id }}-bin
87+
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
8888
path: |
89-
~/.arduino/tests/**/build*.tmp/*.bin
90-
~/.arduino/tests/**/build*.tmp/*.elf
91-
~/.arduino/tests/**/build*.tmp/*.json
89+
~/.arduino/tests
9290
9391
- name: Run Tests
9492
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

‎.github/workflows/lib.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ jobs:
120120

121121
- name: Push to github repo
122122
run: |
123-
git config user.name github-actions
124-
git config user.email github-actions@github.com
123+
git config user.name "github-actions[bot]"
124+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
125125
git add ${{ env.RESULT_LIBRARY_TEST_FILE }}
126126
git commit -m "Generated External Libraries Test Results"
127127
git push origin HEAD:gh-pages

‎.github/workflows/publishsizes-2.x.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ jobs:
3232
run: |
3333
mv master_cli_compile/*.json artifacts/sizes-report/pr/
3434
mv v2.x_cli_compile/*.json artifacts/sizes-report/master/
35-
35+
3636
- name: Report results
3737
uses: P-R-O-C-H-Y/report-size-deltas@sizes_v2
3838
with:
3939
sketches-reports-source: ${{ env.SKETCHES_REPORTS_PATH }}
4040
github-token: ${{ env.GITHUB_TOKEN }}
4141
destination-file: ${{ env.RESULT_SIZES_TEST_FILE }}
42-
42+
4343
- name: Append file with action URL
4444
run:
4545
echo "/ [GitHub Action Link](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}})" >> ${{ env.RESULT_SIZES_TEST_FILE }}
4646

4747
- name: Push to github repo
4848
run: |
49-
git config user.name github-actions
50-
git config user.email github-actions@github.com
49+
git config user.name "github-actions[bot]"
50+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
5151
git add ${{ env.RESULT_SIZES_TEST_FILE }}
5252
git commit -m "Generated Sizes Results (master-v2.x)"
5353
git push origin HEAD:gh-pages

‎.github/workflows/push.yml

Lines changed: 18 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ jobs:
7777
libraries:
7878
- 'libraries/**/examples/**'
7979
- 'libraries/**/src/**'
80+
networking:
81+
- 'libraries/Network/src/**'
82+
fs:
83+
- 'libraries/FS/src/**'
8084
static_sketeches:
8185
- 'libraries/NetworkClientSecure/examples/WiFiClientSecure/WiFiClientSecure.ino'
8286
- 'libraries/BLE/examples/Server/Server.ino'
@@ -97,78 +101,18 @@ jobs:
97101
id: set-chunks
98102
env:
99103
LIB_FILES: ${{ steps.changed-files.outputs.libraries_all_changed_files }}
104+
IS_PR: ${{ github.event_name == 'pull_request' }}
105+
MAX_CHUNKS: ${{ env.MAX_CHUNKS }}
106+
BUILD_PLATFORMIO: ${{ steps.changed-files.outputs.platformio_any_changed == 'true' }}
107+
BUILD_IDF: ${{ steps.changed-files.outputs.idf_any_changed == 'true' }}
108+
BUILD_LIBRARIES: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
109+
BUILD_STATIC_SKETCHES: ${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }}
110+
FS_CHANGED: ${{ steps.changed-files.outputs.fs_any_changed == 'true' }}
111+
NETWORKING_CHANGED: ${{ steps.changed-files.outputs.networking_any_changed == 'true' }}
112+
CORE_CHANGED: ${{ steps.changed-files.outputs.core_any_changed == 'true' }}
113+
LIB_CHANGED: ${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
100114
run: |
101-
build_all=false
102-
chunks_count=0
103-
is_pr=${{ github.event_name == 'pull_request' }}
104-
105-
build_platformio=${{ steps.changed-files.outputs.platformio_any_changed == 'true' }}
106-
build_idf=${{ steps.changed-files.outputs.idf_any_changed == 'true' }}
107-
build_libraries=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
108-
build_static_sketches=${{ steps.changed-files.outputs.static_sketeches_any_changed == 'true' }}
109-
110-
core_changed=${{ steps.changed-files.outputs.core_any_changed == 'true' }}
111-
lib_changed=${{ steps.changed-files.outputs.libraries_any_changed == 'true' }}
112-
113-
if [[ $core_changed == 'true' ]] || [[ $is_pr != 'true' ]]; then
114-
echo "Core files changed or not a PR. Building all."
115-
build_all=true
116-
chunks_count=${{ env.MAX_CHUNKS }}
117-
elif [[ $lib_changed == 'true' ]]; then
118-
echo "Libraries changed. Building only affected sketches."
119-
sketches=""
120-
for file in $LIB_FILES; do
121-
if [[ $file == *.ino ]]; then
122-
# If file ends with .ino, add it to the list of sketches
123-
echo "Sketch found: $file"
124-
sketches+="$file "
125-
elif [[ $(basename $(dirname $file)) == "src" ]]; then
126-
# If file is in a src directory, find all sketches in the parent/examples directory
127-
echo "Library src file found: $file"
128-
lib=$(dirname $(dirname $file))
129-
lib_sketches=$(find $lib/examples -name *.ino)
130-
sketches+="$lib_sketches "
131-
echo "Library sketches: $lib_sketches"
132-
else
133-
# If file is in a example folder but it is not a sketch, find all sketches in the current directory
134-
echo "File in example folder found: $file"
135-
sketch=$(find $(dirname $file) -name *.ino)
136-
sketches+="$sketch "
137-
echo "Sketch in example folder: $sketch"
138-
fi
139-
echo ""
140-
done
141-
fi
142-
143-
if [[ -n $sketches ]]; then
144-
# Remove duplicates
145-
sketches=$(echo $sketches | tr ' ' '\n' | sort | uniq)
146-
for sketch in $sketches; do
147-
echo $sketch >> sketches_found.txt
148-
chunks_count=$((chunks_count+1))
149-
done
150-
echo "Number of sketches found: $chunks_count"
151-
echo "Sketches: $sketches"
152-
153-
if [[ $chunks_count -gt ${{ env.MAX_CHUNKS }} ]]; then
154-
echo "More sketches than the allowed number of chunks found. Limiting to ${{ env.MAX_CHUNKS }} chunks."
155-
chunks_count=${{ env.MAX_CHUNKS }}
156-
fi
157-
fi
158-
159-
chunks='["0"'
160-
for i in $(seq 1 $(( $chunks_count - 1 )) ); do
161-
chunks+=",\"$i\""
162-
done
163-
chunks+="]"
164-
165-
echo "build_all=$build_all" >> $GITHUB_OUTPUT
166-
echo "build_libraries=$build_libraries" >> $GITHUB_OUTPUT
167-
echo "build_static_sketches=$build_static_sketches" >> $GITHUB_OUTPUT
168-
echo "build_idf=$build_idf" >> $GITHUB_OUTPUT
169-
echo "build_platformio=$build_platformio" >> $GITHUB_OUTPUT
170-
echo "chunk_count=$chunks_count" >> $GITHUB_OUTPUT
171-
echo "chunks=$chunks" >> $GITHUB_OUTPUT
115+
bash ./.github/scripts/set_push_chunks.sh
172116
173117
- name: Upload sketches found
174118
if: ${{ steps.set-chunks.outputs.build_all == 'false' && steps.set-chunks.outputs.build_libraries == 'true' }}
@@ -336,9 +280,10 @@ jobs:
336280

337281
- name: Commit json files to gh-pages if on master
338282
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
283+
continue-on-error: true
339284
run: |
340-
git config user.name github-actions
341-
git config user.email github-actions@github.com
285+
git config user.name "github-actions[bot]"
286+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
342287
git add --all
343288
git commit -m "Updated cli compile json files"
344289
git push origin HEAD:gh-pages

‎.github/workflows/qemu.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,11 @@ jobs:
113113
114114
- name: Get binaries
115115
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
116-
id: cache-build-binaries
117-
uses: actions/cache/restore@v4
116+
uses: actions/download-artifact@v4
118117
with:
119-
fail-on-cache-miss: true
120-
key: tests-${{ env.id }}-bin
118+
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
121119
path: |
122-
~/.arduino/tests/**/build*.tmp/*.bin
123-
~/.arduino/tests/**/build*.tmp/*.elf
124-
~/.arduino/tests/**/build*.tmp/*.json
120+
~/.arduino/tests
125121
126122
- name: Run Tests
127123
if: ${{ steps.check-tests.outputs.enabled == 'true' }}

‎.github/workflows/wokwi.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,11 @@ jobs:
9191

9292
- name: Get binaries
9393
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
94-
id: cache-build-binaries
95-
uses: actions/cache/restore@v4
94+
uses: actions/download-artifact@v4
9695
with:
97-
fail-on-cache-miss: true
98-
key: tests-${{ env.id }}-bin
96+
name: tests-bin-${{ inputs.chip }}-${{ inputs.type }}
9997
path: |
100-
~/.arduino/tests/**/build*.tmp/*.bin
101-
~/.arduino/tests/**/build*.tmp/*.elf
102-
~/.arduino/tests/**/build*.tmp/*.json
98+
~/.arduino/tests
10399
104100
- name: Run Tests
105101
if: ${{ steps.check-tests.outputs.enabled == 'true' }}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#if !SOC_USB_OTG_SUPPORTED || ARDUINO_USB_MODE
2+
#error Device does not support USB_OTG or native USB CDC/JTAG is selected
3+
#endif
4+
5+
#include <USB.h>
6+
#include <USBMSC.h>
7+
#include <SD_MMC.h>
8+
9+
// USB Mass Storage Class (MSC) object
10+
USBMSC msc;
11+
12+
int clk = 36;
13+
int cmd = 35;
14+
int d0 = 37;
15+
int d1 = 38;
16+
int d2 = 33;
17+
int d3 = 34;
18+
bool onebit = true; // set to false for 4-bit. 1-bit will ignore the d1-d3 pins (but d3 must be pulled high)
19+
20+
static int32_t onWrite(uint32_t lba, uint32_t offset, uint8_t *buffer, uint32_t bufsize) {
21+
uint32_t secSize = SD_MMC.sectorSize();
22+
if (!secSize) {
23+
return false; // disk error
24+
}
25+
log_v("Write lba: %ld\toffset: %ld\tbufsize: %ld", lba, offset, bufsize);
26+
for (int x = 0; x < bufsize / secSize; x++) {
27+
uint8_t blkbuffer[secSize];
28+
memcpy(blkbuffer, (uint8_t *)buffer + secSize * x, secSize);
29+
if (!SD_MMC.writeRAW(blkbuffer, lba + x)) {
30+
return false;
31+
}
32+
}
33+
return bufsize;
34+
}
35+
36+
static int32_t onRead(uint32_t lba, uint32_t offset, void *buffer, uint32_t bufsize) {
37+
uint32_t secSize = SD_MMC.sectorSize();
38+
if (!secSize) {
39+
return false; // disk error
40+
}
41+
log_v("Read lba: %ld\toffset: %ld\tbufsize: %ld\tsector: %lu", lba, offset, bufsize, secSize);
42+
for (int x = 0; x < bufsize / secSize; x++) {
43+
if (!SD_MMC.readRAW((uint8_t *)buffer + (x * secSize), lba + x)) {
44+
return false; // outside of volume boundary
45+
}
46+
}
47+
return bufsize;
48+
}
49+
50+
static bool onStartStop(uint8_t power_condition, bool start, bool load_eject) {
51+
log_i("Start/Stop power: %u\tstart: %d\teject: %d", power_condition, start, load_eject);
52+
return true;
53+
}
54+
55+
static void usbEventCallback(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) {
56+
if (event_base == ARDUINO_USB_EVENTS) {
57+
arduino_usb_event_data_t *data = (arduino_usb_event_data_t *)event_data;
58+
switch (event_id) {
59+
case ARDUINO_USB_STARTED_EVENT: Serial.println("USB PLUGGED"); break;
60+
case ARDUINO_USB_STOPPED_EVENT: Serial.println("USB UNPLUGGED"); break;
61+
case ARDUINO_USB_SUSPEND_EVENT: Serial.printf("USB SUSPENDED: remote_wakeup_en: %u\n", data->suspend.remote_wakeup_en); break;
62+
case ARDUINO_USB_RESUME_EVENT: Serial.println("USB RESUMED"); break;
63+
64+
default: break;
65+
}
66+
}
67+
}
68+
69+
void setup() {
70+
Serial.begin(115200);
71+
Serial.println("Starting Serial");
72+
73+
Serial.println("Mounting SDcard");
74+
SD_MMC.setPins(clk, cmd, d0, d1, d2, d3);
75+
if (!SD_MMC.begin("/sdcard", onebit)) {
76+
Serial.println("Mount Failed");
77+
return;
78+
}
79+
80+
Serial.println("Initializing MSC");
81+
// Initialize USB metadata and callbacks for MSC (Mass Storage Class)
82+
msc.vendorID("ESP32");
83+
msc.productID("USB_MSC");
84+
msc.productRevision("1.0");
85+
msc.onRead(onRead);
86+
msc.onWrite(onWrite);
87+
msc.onStartStop(onStartStop);
88+
msc.mediaPresent(true);
89+
msc.begin(SD_MMC.numSectors(), SD_MMC.sectorSize());
90+
91+
Serial.println("Initializing USB");
92+
93+
USB.begin();
94+
USB.onEvent(usbEventCallback);
95+
96+
Serial.printf("Card Size: %lluMB\n", SD_MMC.totalBytes() / 1024 / 1024);
97+
Serial.printf("Sector: %d\tCount: %d\n", SD_MMC.sectorSize(), SD_MMC.numSectors());
98+
}
99+
100+
void loop() {
101+
delay(-1);
102+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"targets": {
3+
"esp32": false,
4+
"esp32s2": false,
5+
"esp32c3": false,
6+
"esp32c6": false,
7+
"esp32h2": false
8+
}
9+
}

‎libraries/SD_MMC/src/SD_MMC.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#include "driver/sdmmc_host.h"
2727
#include "driver/sdmmc_defs.h"
2828
#include "sdmmc_cmd.h"
29+
#include "diskio_sdmmc.h"
30+
#include "diskio.h"
2931
#include "soc/sdmmc_pins.h"
3032
#include "ff.h"
3133
#include "esp32-hal-periman.h"
@@ -191,6 +193,7 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_
191193
return false;
192194
}
193195
_impl->mountpoint(mountpoint);
196+
_pdrv = ff_diskio_get_pdrv_card(_card);
194197

195198
if (!perimanSetPinBus(_pin_cmd, ESP32_BUS_TYPE_SDMMC_CMD, (void *)(this), -1, -1)) {
196199
goto err;
@@ -280,5 +283,27 @@ uint64_t SDMMCFS::usedBytes() {
280283
return size;
281284
}
282285

286+
int SDMMCFS::sectorSize() {
287+
if (!_card) {
288+
return 0;
289+
}
290+
return _card->csd.sector_size;
291+
}
292+
293+
int SDMMCFS::numSectors() {
294+
if (!_card) {
295+
return 0;
296+
}
297+
return (totalBytes() / _card->csd.sector_size);
298+
}
299+
300+
bool SDMMCFS::readRAW(uint8_t *buffer, uint32_t sector) {
301+
return (disk_read(_pdrv, buffer, sector, 1) == 0);
302+
}
303+
304+
bool SDMMCFS::writeRAW(uint8_t *buffer, uint32_t sector) {
305+
return (disk_write(_pdrv, buffer, sector, 1) == 0);
306+
}
307+
283308
SDMMCFS SD_MMC = SDMMCFS(FSImplPtr(new VFSImpl()));
284309
#endif /* SOC_SDMMC_HOST_SUPPORTED */

‎libraries/SD_MMC/src/SD_MMC.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
#include "sdkconfig.h"
1818
#include "soc/soc_caps.h"
19-
#ifdef SOC_SDMMC_HOST_SUPPORTED
19+
#ifndef SOC_SDMMC_HOST_SUPPORTED
20+
#ifdef ARDUINO
21+
#warning The SDMMC library requires a device with an SDIO Host
22+
#endif
23+
#else
2024

2125
#include "FS.h"
2226
#include "driver/sdmmc_types.h"
@@ -40,6 +44,7 @@ class SDMMCFS : public FS {
4044
int8_t _pin_d1 = -1;
4145
int8_t _pin_d2 = -1;
4246
int8_t _pin_d3 = -1;
47+
uint8_t _pdrv = 0xFF;
4348
bool _mode1bit = false;
4449

4550
public:
@@ -55,6 +60,10 @@ class SDMMCFS : public FS {
5560
uint64_t cardSize();
5661
uint64_t totalBytes();
5762
uint64_t usedBytes();
63+
int sectorSize();
64+
int numSectors();
65+
bool readRAW(uint8_t *buffer, uint32_t sector);
66+
bool writeRAW(uint8_t *buffer, uint32_t sector);
5867

5968
private:
6069
static bool sdmmcDetachBus(void *bus_pointer);

0 commit comments

Comments
 (0)
Please sign in to comment.