Merge pull request #5171 from tannewt/unicode_filenames

Turn on unicode for FATFS
This commit is contained in:
Dan Halbert 2021-08-21 16:31:54 -04:00 committed by GitHub
commit 57841dc92b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 209 additions and 23 deletions

View File

@ -1175,6 +1175,7 @@ static DWORD get_fat ( /* 0xFFFFFFFF:Disk error, 1:Internal error, 2..0x7FF
break;
}
}
MP_FALLTHROUGH
/* go to default */
#endif
default:
@ -5518,6 +5519,7 @@ FRESULT f_mkfs (
}
st = 1; /* Do not compress short run */
/* go to next case */
MP_FALLTHROUGH
case 1:
ch = si++; /* Fill the short run */
if (--j == 0) st = 0;

View File

@ -163,8 +163,11 @@
/ memory for the working buffer, memory management functions, ff_memalloc() and
/ ff_memfree() in ffsystem.c, need to be added to the project. */
#ifdef MICROPY_FATFS_LFN_UNICODE
#define FF_LFN_UNICODE (MICROPY_FATFS_LFN_UNICODE)
#else
#define FF_LFN_UNICODE 0
#endif
/* This option switches the character encoding on the API when LFN is enabled.
/
/ 0: ANSI/OEM in current CP (TCHAR = char)

View File

@ -266,7 +266,7 @@ msgstr "l'objet %s ne supporte pas l'assignation d'éléments"
#: py/obj.c
#, c-format
msgid "'%s' object doesn't support item deletion"
msgstr "Lobjet '%s' ne prend pas en charge la suppression déléments"
msgstr "L'objet '%s' ne prend pas en charge la suppression d'éléments"
#: py/runtime.c
msgid "'%s' object has no attribute '%q'"

View File

@ -19,3 +19,11 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// SWD-only
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1

View File

@ -19,3 +19,24 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// Unconnected
// Schematic at: https://jandjstudios.io/assets/pdfs/datum-Distance.pdf
#define IGNORE_PIN_PA03 1
#define IGNORE_PIN_PA02 1
#define IGNORE_PIN_PB08 1
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA15 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PA13 1

View File

@ -19,3 +19,22 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// Unconnected
// Schematic at: https://jandjstudios.io/assets/pdfs/datum-IMU.pdf
#define IGNORE_PIN_PB08 1
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA15 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PA13 1

View File

@ -19,3 +19,24 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// Unconnected
// Schematic at: https://jandjstudios.io/assets/pdfs/datum-Light.pdf
#define IGNORE_PIN_PA03 1
#define IGNORE_PIN_PA02 1
#define IGNORE_PIN_PB08 1
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA15 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PA13 1

View File

@ -19,3 +19,24 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// Unconnected
// Schematic at: https://jandjstudios.io/assets/pdfs/datum-Weather.pdf
#define IGNORE_PIN_PA03 1
#define IGNORE_PIN_PA02 1
#define IGNORE_PIN_PB08 1
#define IGNORE_PIN_PB09 1
#define IGNORE_PIN_PA04 1
#define IGNORE_PIN_PA05 1
#define IGNORE_PIN_PB02 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA15 1
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PA28 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PA13 1

View File

@ -17,3 +17,21 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// Unconnected
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PA09 1
#define IGNORE_PIN_PA13 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA27 1
#define IGNORE_PIN_PA28 1
// SWD-only
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1

View File

@ -17,3 +17,24 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1
// Unconnected
#define IGNORE_PIN_PB03 1
#define IGNORE_PIN_PB22 1
#define IGNORE_PIN_PB23 1
#define IGNORE_PIN_PA06 1
#define IGNORE_PIN_PA08 1
#define IGNORE_PIN_PA09 1
#define IGNORE_PIN_PA13 1
#define IGNORE_PIN_PA14 1
#define IGNORE_PIN_PA21 1
#define IGNORE_PIN_PA27 1
#define IGNORE_PIN_PA28 1
// SWD-only
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1

View File

@ -19,3 +19,5 @@
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
#define MICROPY_FATFS_EXFAT 0

View File

@ -15,6 +15,7 @@ CIRCUITPY_AUDIOMP3 = 0
CIRCUITPY_BLEIO_HCI = 0
CIRCUITPY_DISPLAYIO = 0
CIRCUITPY_FRAMEBUFFERIO = 0
CIRCUITPY_GETPASS = 0
CIRCUITPY_KEYPAD = 0
CIRCUITPY_MSGPACK = 0
CIRCUITPY_PS2IO = 0

View File

@ -18,3 +18,7 @@
// USB is always used internally so skip the pin objects for it.
#define IGNORE_PIN_PA24 1
#define IGNORE_PIN_PA25 1
// Connected to a crystal
#define IGNORE_PIN_PA00 1
#define IGNORE_PIN_PA01 1

View File

@ -59,6 +59,8 @@
X(EISDIR) \
X(EINVAL) \
#define MICROPY_FATFS_EXFAT 0
#endif // SAMD21
////////////////////////////////////////////////////////////////////////////////////////////////////
@ -238,8 +240,13 @@
#include "peripherals/samd/dma.h"
#if CIRCUITPY_AUDIOCORE
#define MICROPY_PORT_ROOT_POINTERS \
CIRCUITPY_COMMON_ROOT_POINTERS \
mp_obj_t playing_audio[AUDIO_DMA_CHANNEL_COUNT];
#else
#define MICROPY_PORT_ROOT_POINTERS \
CIRCUITPY_COMMON_ROOT_POINTERS
#endif
#endif // __INCLUDED_MPCONFIGPORT_H

View File

@ -48,3 +48,5 @@
#define BLEIO_ATTR_TAB_SIZE (BLE_GATTS_ATTR_TAB_SIZE_DEFAULT * 2)
#define SOFTDEVICE_RAM_SIZE (32 * 1024)
#define MICROPY_FATFS_EXFAT 0

View File

@ -57,3 +57,5 @@
#define BLEIO_ATTR_TAB_SIZE (BLE_GATTS_ATTR_TAB_SIZE_DEFAULT * 2)
#define SOFTDEVICE_RAM_SIZE (32 * 1024)
#define MICROPY_FATFS_EXFAT 0

View File

@ -41,3 +41,5 @@
#define BOARD_HAS_LOW_SPEED_CRYSTAL (0)
// #define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
// #define LSE_VALUE ((uint32_t)32768)
#define MICROPY_FATFS_EXFAT 0

View File

@ -47,3 +47,5 @@
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000)
#define AUTORESET_DELAY_MS (500)
#define MICROPY_FATFS_EXFAT 0

View File

@ -50,3 +50,5 @@
#define BOARD_FLASH_SIZE (FLASH_SIZE - 0x2000 - 0xC000)
#define AUTORESET_DELAY_MS (500)
#define MICROPY_FATFS_EXFAT 0

View File

@ -39,3 +39,5 @@
// The schematic has a 32k crystal that isn't fitted. Uncommented the line below if you add it.
// #define BOARD_HAS_LOW_SPEED_CRYSTAL (1)
// #define LSE_VALUE ((uint32_t)32000U)
#define MICROPY_FATFS_EXFAT 0

View File

@ -51,3 +51,5 @@
#define DEFAULT_I2C_BUS_SCL (&pin_PB06)
#define DEFAULT_I2C_BUS_SDA (&pin_PB07)
#define MICROPY_FATFS_EXFAT 0

View File

@ -60,6 +60,7 @@
#define MICROPY_MALLOC_USES_ALLOCATED_SIZE (1)
#define MICROPY_MEM_STATS (1)
#define MICROPY_DEBUG_PRINTERS (1)
#define CIRCUITPY_MICROPYTHON_ADVANCED (1)
// Printing debug to stderr may give tests which
// check stdout a chance to pass, etc.
#define MICROPY_DEBUG_PRINTER (&mp_stderr_print)

View File

@ -132,12 +132,14 @@
//
// 1 = SFN/ANSI 437=LFN/U.S.(OEM)
#define MICROPY_FATFS_ENABLE_LFN (1)
// Code page is ignored because unicode is enabled.
// Don't use parens on the value below because it gets combined with a prefix in
// the preprocessor.
#define MICROPY_FATFS_LFN_CODE_PAGE 437
#define MICROPY_FATFS_USE_LABEL (1)
#define MICROPY_FATFS_RPATH (2)
#define MICROPY_FATFS_MULTI_PARTITION (1)
#define MICROPY_FATFS_LFN_UNICODE 2 // UTF-8
// Only enable this if you really need it. It allocates a byte cache of this size.
// #define MICROPY_FATFS_MAX_SS (4096)
@ -209,6 +211,12 @@ typedef long mp_off_t;
#define MICROPY_PY_URE_MATCH_SPAN_START_END (CIRCUITPY_RE)
#define MICROPY_PY_URE_SUB (CIRCUITPY_RE)
#define CIRCUITPY_MICROPYTHON_ADVANCED (CIRCUITPY_FULL_BUILD)
#ifndef MICROPY_FATFS_EXFAT
#define MICROPY_FATFS_EXFAT (CIRCUITPY_FULL_BUILD)
#endif
// LONGINT_IMPL_xxx are defined in the Makefile.
//
#ifdef LONGINT_IMPL_NONE

View File

@ -37,7 +37,7 @@
// Various builtins specific to MicroPython runtime,
// living in micropython module
#if MICROPY_ENABLE_COMPILER
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_COMPILER
STATIC mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) {
if (n_args == 0) {
return MP_OBJ_NEW_SMALL_INT(MP_STATE_VM(mp_optimise_value));
@ -49,7 +49,7 @@ STATIC mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_opt_level_obj, 0, 1, mp_micropython_opt_level);
#endif
#if MICROPY_PY_MICROPYTHON_MEM_INFO
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_PY_MICROPYTHON_MEM_INFO
#if MICROPY_MEM_STATS
STATIC mp_obj_t mp_micropython_mem_total(void) {
@ -109,21 +109,21 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, m
#endif // MICROPY_PY_MICROPYTHON_MEM_INFO
#if MICROPY_PY_MICROPYTHON_STACK_USE
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_PY_MICROPYTHON_STACK_USE
STATIC mp_obj_t mp_micropython_stack_use(void) {
return MP_OBJ_NEW_SMALL_INT(mp_stack_usage());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_stack_use_obj, mp_micropython_stack_use);
#endif
#if MICROPY_ENABLE_PYSTACK
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_PYSTACK
STATIC mp_obj_t mp_micropython_pystack_use(void) {
return MP_OBJ_NEW_SMALL_INT(mp_pystack_usage());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_pystack_use_obj, mp_micropython_pystack_use);
#endif
#if MICROPY_ENABLE_GC
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_GC
STATIC mp_obj_t mp_micropython_heap_lock(void) {
gc_lock();
return mp_const_none;
@ -144,11 +144,11 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_locked_obj, mp_micropython_
#endif
#endif
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0)
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0)
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_emergency_exception_buf);
#endif
#if MICROPY_KBD_EXCEPTION
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_KBD_EXCEPTION
STATIC mp_obj_t mp_micropython_kbd_intr(mp_obj_t int_chr_in) {
mp_hal_set_interrupt_char(mp_obj_get_int(int_chr_in));
return mp_const_none;
@ -169,10 +169,10 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_micropython_schedule_obj, mp_micropython_sch
STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_micropython) },
{ MP_ROM_QSTR(MP_QSTR_const), MP_ROM_PTR(&mp_identity_obj) },
#if MICROPY_ENABLE_COMPILER
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_COMPILER
{ MP_ROM_QSTR(MP_QSTR_opt_level), MP_ROM_PTR(&mp_micropython_opt_level_obj) },
#endif
#if MICROPY_PY_MICROPYTHON_MEM_INFO
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_PY_MICROPYTHON_MEM_INFO
#if MICROPY_MEM_STATS
{ MP_ROM_QSTR(MP_QSTR_mem_total), MP_ROM_PTR(&mp_micropython_mem_total_obj) },
{ MP_ROM_QSTR(MP_QSTR_mem_current), MP_ROM_PTR(&mp_micropython_mem_current_obj) },
@ -181,23 +181,23 @@ STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_mem_info), MP_ROM_PTR(&mp_micropython_mem_info_obj) },
{ MP_ROM_QSTR(MP_QSTR_qstr_info), MP_ROM_PTR(&mp_micropython_qstr_info_obj) },
#endif
#if MICROPY_PY_MICROPYTHON_STACK_USE
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_PY_MICROPYTHON_STACK_USE
{ MP_ROM_QSTR(MP_QSTR_stack_use), MP_ROM_PTR(&mp_micropython_stack_use_obj) },
#endif
#if MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0)
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0)
{ MP_ROM_QSTR(MP_QSTR_alloc_emergency_exception_buf), MP_ROM_PTR(&mp_alloc_emergency_exception_buf_obj) },
#endif
#if MICROPY_ENABLE_PYSTACK
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_PYSTACK
{ MP_ROM_QSTR(MP_QSTR_pystack_use), MP_ROM_PTR(&mp_micropython_pystack_use_obj) },
#endif
#if MICROPY_ENABLE_GC
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_GC
{ MP_ROM_QSTR(MP_QSTR_heap_lock), MP_ROM_PTR(&mp_micropython_heap_lock_obj) },
{ MP_ROM_QSTR(MP_QSTR_heap_unlock), MP_ROM_PTR(&mp_micropython_heap_unlock_obj) },
#if MICROPY_PY_MICROPYTHON_HEAP_LOCKED
{ MP_ROM_QSTR(MP_QSTR_heap_locked), MP_ROM_PTR(&mp_micropython_heap_locked_obj) },
#endif
#endif
#if MICROPY_KBD_EXCEPTION
#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_KBD_EXCEPTION
{ MP_ROM_QSTR(MP_QSTR_kbd_intr), MP_ROM_PTR(&mp_micropython_kbd_intr_obj) },
#endif
#if MICROPY_ENABLE_SCHEDULER

View File

@ -41,6 +41,13 @@ STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_bu
/******************************************************************************/
/* str */
// These settings approximate CPython's printability. It is not
// exhaustive and may print "unprintable" characters. All ASCII control codes
// are escaped along with variable space widths and paragraph designators.
// Unlike CPython, we do not escape private use codes or reserved characters.
// We assume that the unicode is well formed.
// CPython policy is documented here: https://github.com/python/cpython/blob/bb3e0c240bc60fe08d332ff5955d54197f79751c/Objects/unicodectype.c#L147-L159
STATIC void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint str_len) {
// this escapes characters, but it will be very slow to print (calling print many times)
bool has_single_quote = false;
@ -61,25 +68,26 @@ STATIC void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint
while (s < top) {
unichar ch;
ch = utf8_get_char(s);
const byte *start = s;
s = utf8_next_char(s);
if (ch == quote_char) {
mp_printf(print, "\\%c", quote_char);
} else if (ch == '\\') {
mp_print_str(print, "\\\\");
} else if (32 <= ch && ch <= 126) {
mp_printf(print, "%c", ch);
} else if (ch == '\n') {
mp_print_str(print, "\\n");
} else if (ch == '\r') {
mp_print_str(print, "\\r");
} else if (ch == '\t') {
mp_print_str(print, "\\t");
} else if (ch < 0x100) {
} else if (ch <= 0x1f || (0x7f <= ch && ch <= 0xa0) || ch == 0xad) {
mp_printf(print, "\\x%02x", ch);
} else if (ch < 0x10000) {
} else if ((0x2000 <= ch && ch <= 0x200f) || ch == 0x2028 || ch == 0x2029) {
mp_printf(print, "\\u%04x", ch);
} else {
mp_printf(print, "\\U%08x", ch);
// Print the full character out.
int width = s - start;
mp_print_strn(print, (const char *)start, width, 0, ' ', width);
}
}
mp_printf(print, "%c", quote_char);

View File

@ -19,8 +19,7 @@ print(enc, enc.decode() == s)
# printing of unicode chars using repr
# NOTE: for some characters (eg \u10ff) we differ to CPython
print(repr("a\uffff"))
print(repr("a\U0001ffff"))
print(repr("a\u2000"))
# test invalid escape code
try:

View File

@ -0,0 +1,8 @@
# ¥ is 1 byte wide
# Œ is 2 bytes wide
# 😅 is 4 bytes wide
a = "hello¥Œ😅.txt\n\r\t'\"\\"
print(a)
print(repr(a))