Skip to content

Commit ba2f32e

Browse files
authored
Merge pull request #5578 from jepler/disable-mkfs-fat32
oofatfs: Allow fat32 mkfs to be compiled out. optimize rainbowio & enable everywhere
2 parents 894adc7 + edac675 commit ba2f32e

File tree

15 files changed

+93
-30
lines changed

15 files changed

+93
-30
lines changed

lib/oofatfs/ff.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5392,7 +5392,9 @@ FRESULT f_mkfs (
53925392
const UINT n_fats = 1; /* Number of FATs for FAT/FAT32 volume (1 or 2) */
53935393
const UINT n_rootdir = 512; /* Number of root directory entries for FAT volume */
53945394
static const WORD cst[] = {1, 4, 16, 64, 256, 512, 0}; /* Cluster size boundary for FAT volume (4Ks unit) */
5395+
#if FF_MKFS_FAT32
53955396
static const WORD cst32[] = {1, 2, 4, 8, 16, 32, 0}; /* Cluster size boundary for FAT32 volume (128Ks unit) */
5397+
#endif
53965398
BYTE fmt, sys, *buf, *pte, part; void *pdrv;
53975399
WORD ss; /* Sector size */
53985400
DWORD szb_buf, sz_buf, sz_blk, n_clst, pau, sect, nsect, n;
@@ -5464,7 +5466,7 @@ FRESULT f_mkfs (
54645466
}
54655467
}
54665468
if (au > 128) LEAVE_MKFS(FR_INVALID_PARAMETER); /* Too large au for FAT/FAT32 */
5467-
if (opt & FM_FAT32) { /* FAT32 possible? */
5469+
if (FF_MKFS_FAT32 && (opt & FM_FAT32)) { /* FAT32 possible? */
54685470
if ((opt & FM_ANY) == FM_FAT32 || !(opt & FM_FAT)) { /* FAT32 only or no-FAT? */
54695471
fmt = FS_FAT32; break;
54705472
}
@@ -5641,6 +5643,7 @@ FRESULT f_mkfs (
56415643
do {
56425644
pau = au;
56435645
/* Pre-determine number of clusters and FAT sub-type */
5646+
#if FF_MKFS_FAT32
56445647
if (fmt == FS_FAT32) { /* FAT32 volume */
56455648
if (pau == 0) { /* au auto-selection */
56465649
n = sz_vol / 0x20000; /* Volume size in unit of 128KS */
@@ -5651,7 +5654,9 @@ FRESULT f_mkfs (
56515654
sz_rsv = 32; /* Number of reserved sectors */
56525655
sz_dir = 0; /* No static directory */
56535656
if (n_clst <= MAX_FAT16 || n_clst > MAX_FAT32) LEAVE_MKFS(FR_MKFS_ABORTED);
5654-
} else { /* FAT volume */
5657+
} else
5658+
#endif
5659+
{ /* FAT volume */
56555660
if (pau == 0) { /* au auto-selection */
56565661
n = sz_vol / 0x1000; /* Volume size in unit of 4KS */
56575662
for (i = 0, pau = 1; cst[i] && cst[i] <= n; i++, pau <<= 1) ; /* Get from table */
@@ -5681,12 +5686,14 @@ FRESULT f_mkfs (
56815686
/* Determine number of clusters and final check of validity of the FAT sub-type */
56825687
if (sz_vol < b_data + pau * 16 - b_vol) LEAVE_MKFS(FR_MKFS_ABORTED); /* Too small volume */
56835688
n_clst = (sz_vol - sz_rsv - sz_fat * n_fats - sz_dir) / pau;
5689+
#if FF_MKFS_FAT32
56845690
if (fmt == FS_FAT32) {
56855691
if (n_clst <= MAX_FAT16) { /* Too few clusters for FAT32 */
56865692
if (au == 0 && (au = pau / 2) != 0) continue; /* Adjust cluster size and retry */
56875693
LEAVE_MKFS(FR_MKFS_ABORTED);
56885694
}
56895695
}
5696+
#endif
56905697
if (fmt == FS_FAT16) {
56915698
if (n_clst > MAX_FAT16) { /* Too many clusters for FAT16 */
56925699
if (au == 0 && (pau * 2) <= 64) {
@@ -5720,7 +5727,11 @@ FRESULT f_mkfs (
57205727
buf[BPB_SecPerClus] = (BYTE)pau; /* Cluster size [sector] */
57215728
st_word(buf + BPB_RsvdSecCnt, (WORD)sz_rsv); /* Size of reserved area */
57225729
buf[BPB_NumFATs] = (BYTE)n_fats; /* Number of FATs */
5730+
#if FF_MKFS_FAT32
57235731
st_word(buf + BPB_RootEntCnt, (WORD)((fmt == FS_FAT32) ? 0 : n_rootdir)); /* Number of root directory entries */
5732+
#else
5733+
st_word(buf + BPB_RootEntCnt, (WORD) n_rootdir); /* Number of root directory entries */
5734+
#endif
57245735
if (sz_vol < 0x10000) {
57255736
st_word(buf + BPB_TotSec16, (WORD)sz_vol); /* Volume size in 16-bit LBA */
57265737
} else {
@@ -5730,6 +5741,7 @@ FRESULT f_mkfs (
57305741
st_word(buf + BPB_SecPerTrk, 63); /* Number of sectors per track (for int13) */
57315742
st_word(buf + BPB_NumHeads, 255); /* Number of heads (for int13) */
57325743
st_dword(buf + BPB_HiddSec, b_vol); /* Volume offset in the physical drive [sector] */
5744+
#if FF_MKFS_FAT32
57335745
if (fmt == FS_FAT32) {
57345746
st_dword(buf + BS_VolID32, GET_FATTIME()); /* VSN */
57355747
st_dword(buf + BPB_FATSz32, sz_fat); /* FAT size [sector] */
@@ -5739,7 +5751,9 @@ FRESULT f_mkfs (
57395751
buf[BS_DrvNum32] = 0x80; /* Drive number (for int13) */
57405752
buf[BS_BootSig32] = 0x29; /* Extended boot signature */
57415753
mem_cpy(buf + BS_VolLab32, "NO NAME " "FAT32 ", 19); /* Volume label, FAT signature */
5742-
} else {
5754+
} else
5755+
#endif
5756+
{
57435757
st_dword(buf + BS_VolID, GET_FATTIME()); /* VSN */
57445758
st_word(buf + BPB_FATSz16, (WORD)sz_fat); /* FAT size [sector] */
57455759
buf[BS_DrvNum] = 0x80; /* Drive number (for int13) */
@@ -5750,6 +5764,7 @@ FRESULT f_mkfs (
57505764
if (disk_write(pdrv, buf, b_vol, 1) != RES_OK) LEAVE_MKFS(FR_DISK_ERR); /* Write it to the VBR sector */
57515765

57525766
/* Create FSINFO record if needed */
5767+
#if FF_MKFS_FAT32
57535768
if (fmt == FS_FAT32) {
57545769
disk_write(pdrv, buf, b_vol + 6, 1); /* Write backup VBR (VBR + 6) */
57555770
mem_set(buf, 0, ss);
@@ -5761,16 +5776,20 @@ FRESULT f_mkfs (
57615776
disk_write(pdrv, buf, b_vol + 7, 1); /* Write backup FSINFO (VBR + 7) */
57625777
disk_write(pdrv, buf, b_vol + 1, 1); /* Write original FSINFO (VBR + 1) */
57635778
}
5779+
#endif
57645780

57655781
/* Initialize FAT area */
57665782
mem_set(buf, 0, (UINT)szb_buf);
57675783
sect = b_fat; /* FAT start sector */
57685784
for (i = 0; i < n_fats; i++) { /* Initialize FATs each */
5785+
#if FF_MKFS_FAT32
57695786
if (fmt == FS_FAT32) {
57705787
st_dword(buf + 0, 0xFFFFFFF8); /* Entry 0 */
57715788
st_dword(buf + 4, 0xFFFFFFFF); /* Entry 1 */
57725789
st_dword(buf + 8, 0x0FFFFFFF); /* Entry 2 (root directory) */
5773-
} else {
5790+
} else
5791+
#endif
5792+
{
57745793
st_dword(buf + 0, (fmt == FS_FAT12) ? 0xFFFFF8 : 0xFFFFFFF8); /* Entry 0 and 1 */
57755794
}
57765795
nsect = sz_fat; /* Number of FAT sectors */
@@ -5783,7 +5802,11 @@ FRESULT f_mkfs (
57835802
}
57845803

57855804
/* Initialize root directory (fill with zero) */
5805+
#if FF_MKFS_FAT32
57865806
nsect = (fmt == FS_FAT32) ? pau : sz_dir; /* Number of root directory sectors */
5807+
#else
5808+
nsect = sz_dir; /* Number of root directory sectors */
5809+
#endif
57875810
do {
57885811
n = (nsect > sz_buf) ? sz_buf : nsect;
57895812
if (disk_write(pdrv, buf, sect, (UINT)n) != RES_OK) LEAVE_MKFS(FR_DISK_ERR);
@@ -5795,7 +5818,7 @@ FRESULT f_mkfs (
57955818
if (FF_FS_EXFAT && fmt == FS_EXFAT) {
57965819
sys = 0x07; /* HPFS/NTFS/exFAT */
57975820
} else {
5798-
if (fmt == FS_FAT32) {
5821+
if (FF_MKFS_FAT32 && fmt == FS_FAT32) {
57995822
sys = 0x0C; /* FAT32X */
58005823
} else {
58015824
if (sz_vol >= 0x10000) {

lib/oofatfs/ffconf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@
7272
#define FF_USE_MKFS 1
7373
/* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
7474

75+
#ifdef MICROPY_FF_MKFS_FAT32
76+
#define FF_MKFS_FAT32 MICROPY_FF_MKFS_FAT32
77+
#else
78+
#define FF_MKFS_FAT32 0
79+
#endif
80+
/* This option switches off FAT32 support in f_mkfs() */
7581

7682
#define FF_USE_FASTSEEK 1
7783
/* This option switches fast seek function. (0:Disable or 1:Enable) */

ports/atmel-samd/boards/arduino_mkr1300/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ CHIP_FAMILY = samd21
99
INTERNAL_FLASH_FILESYSTEM = 1
1010
LONGINT_IMPL = NONE
1111
CIRCUITPY_FULL_BUILD = 0
12-
13-
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/arduino_nano_33_iot/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ LONGINT_IMPL = NONE
1111
CIRCUITPY_FULL_BUILD = 0
1212

1313
CIRCUITPY_ONEWIREIO = 0
14-
CIRCUITPY_RAINBOWIO = 0

ports/atmel-samd/boards/arduino_zero/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ CHIP_FAMILY = samd21
99
INTERNAL_FLASH_FILESYSTEM = 1
1010
LONGINT_IMPL = NONE
1111
CIRCUITPY_FULL_BUILD = 0
12-
13-
CIRCUITPY_RAINBOWIO = 0

ports/unix/variants/coverage/mpconfigvariant.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#define MICROPY_PY_URE_SUB (1)
6060
#define MICROPY_VFS_POSIX (1)
6161
#define MICROPY_FATFS_USE_LABEL (1)
62+
#define MICROPY_FF_MKFS_FAT32 (1)
6263
#define MICROPY_PY_FRAMEBUF (1)
6364
#define MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT (1)
6465
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT (1)

ports/unix/variants/coverage/mpconfigvariant.mk

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ SRC_BITMAP := \
3131
$(patsubst ../../%,%,$(wildcard ../../shared-bindings/gifio/*.c ../../shared-module/gifio/*.c)) \
3232
shared/runtime/context_manager_helpers.c \
3333
displayio_min.c \
34+
shared-bindings/bitmaptools/__init__.c \
3435
shared-bindings/displayio/Bitmap.c \
36+
shared-bindings/rainbowio/__init__.c \
37+
shared-bindings/util.c \
38+
shared-module/bitmaptools/__init__.c \
3539
shared-module/displayio/area.c \
3640
shared-module/displayio/Bitmap.c \
3741
shared-module/displayio/ColorConverter.c \
38-
shared-bindings/bitmaptools/__init__.c \
39-
shared-module/bitmaptools/__init__.c \
40-
shared-bindings/util.c \
42+
shared-module/displayio/ColorConverter.c \
43+
shared-module/rainbowio/__init__.c \
4144

4245
$(info $(SRC_BITMAP))
4346
SRC_C += $(SRC_BITMAP)
4447

45-
CFLAGS += -DCIRCUITPY_GIFIO=1 -DCIRCUITPY_DISPLAYIO_UNIX=1 -DCIRCUITPY_BITMAPTOOLS=1
48+
CFLAGS += -DCIRCUITPY_GIFIO=1 -DCIRCUITPY_DISPLAYIO_UNIX=1 -DCIRCUITPY_BITMAPTOOLS=1 -DCIRCUITPY_RAINBOWIO=1
4649

4750
SRC_C += coverage.c
4851
SRC_CXX += coveragecpp.cpp

shared-bindings/rainbowio/__init__.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
//| ...
3838
//|
3939
STATIC mp_obj_t rainbowio_colorwheel(mp_obj_t n) {
40-
return MP_OBJ_NEW_SMALL_INT(colorwheel(mp_obj_is_small_int(n) ? MP_OBJ_SMALL_INT_VALUE(n) : mp_obj_get_float(n)));
40+
mp_float_t f = mp_obj_get_float(n);
41+
return MP_OBJ_NEW_SMALL_INT(colorwheel(f));
4142
}
4243
STATIC MP_DEFINE_CONST_FUN_OBJ_1(rainbowio_colorwheel_obj, rainbowio_colorwheel);
4344

shared-bindings/rainbowio/__init__.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
#ifndef CP_SHARED_BINDINGS_RAINBOWIO_INIT_H
2828
#define CP_SHARED_BINDINGS_RAINBOWIO_INIT_H
2929
#include <stdint.h>
30+
#include "py/misc.h"
3031

31-
const int32_t colorwheel(float pos);
32+
int32_t colorwheel(mp_float_t pos);
3233

3334
#endif // CP_SHARED_BINDINGS_RAINBOWIO_INIT_H

shared-module/rainbowio/__init__.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@
2626

2727
#include "shared-bindings/rainbowio/__init__.h"
2828

29-
const int32_t colorwheel(float pos) {
30-
if (pos > 255) {
31-
pos = pos - ((uint32_t)(pos / 256) * 256);
32-
}
29+
int32_t colorwheel(mp_float_t pos) {
30+
pos = pos - ((uint32_t)(pos / 256) * 256);
31+
int shift1, shift2;
3332
if (pos < 85) {
34-
return (uint8_t)(255 - (pos * 3)) << 16 | (uint8_t)(pos * 3) << 8;
33+
shift1 = 8;
34+
shift2 = 16;
3535
} else if (pos < 170) {
3636
pos -= 85;
37-
return (uint8_t)(255 - (pos * 3)) << 8 | (uint8_t)(pos * 3);
37+
shift1 = 0;
38+
shift2 = 8;
3839
} else {
3940
pos -= 170;
40-
return (uint8_t)(pos * 3) << 16 | (uint8_t)(255 - (pos * 3));
41+
shift1 = 16;
42+
shift2 = 0;
4143
}
44+
int p = (int)(pos * 3);
45+
return (p << shift1) | ((255 - p) << shift2);
4246
}

tests/circuitpython/blinky.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

tests/circuitpython/rainbows.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import rainbowio
2+
3+
for i in range(0, 256, 15):
4+
print("{:3} {:06x} {:06x}".format(i, rainbowio.colorwheel(i), rainbowio.colorwheel(float(i))))
5+
for i in range(256, 1024, 128):
6+
print("{:3} {:06x}".format(i, rainbowio.colorwheel(i)))

tests/circuitpython/rainbows.py.exp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
0 ff0000 ff0000
2+
15 d22d00 d22d00
3+
30 a55a00 a55a00
4+
45 788700 788700
5+
60 4bb400 4bb400
6+
75 1ee100 1ee100
7+
90 00f00f 00f00f
8+
105 00c33c 00c33c
9+
120 009669 009669
10+
135 006996 006996
11+
150 003cc3 003cc3
12+
165 000ff0 000ff0
13+
180 1e00e1 1e00e1
14+
195 4b00b4 4b00b4
15+
210 780087 780087
16+
225 a5005a a5005a
17+
240 d2002d d2002d
18+
255 ff0000 ff0000
19+
256 ff0000
20+
384 007e81
21+
512 ff0000
22+
640 007e81
23+
768 ff0000
24+
896 007e81

tests/run-tests.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ def main():
819819
if args.test_dirs is None:
820820
test_dirs = (
821821
"basics",
822+
"circuitpython",
822823
"micropython",
823824
"misc",
824825
"extmod",

tests/unix/extra_coverage.py.exp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ binascii bitmaptools btree cexample
3434
cmath collections cppexample displayio
3535
errno ffi framebuf gc
3636
gifio hashlib json math
37-
qrio re sys termios
38-
ubinascii uctypes uerrno uheapq
39-
uio ujson ulab uos
40-
urandom ure uselect ustruct
41-
utime utimeq uzlib
37+
qrio rainbowio re sys
38+
termios ubinascii uctypes uerrno
39+
uheapq uio ujson ulab
40+
uos urandom ure uselect
41+
ustruct utime utimeq uzlib
4242
ime
4343

4444
utime utimeq

0 commit comments

Comments
 (0)