Skip to content

Commit

Permalink
rp2: Enable VfsFat class for FAT filesystem support.
Browse files Browse the repository at this point in the history
Allows interfacing with SD cards, for example.
  • Loading branch information
StereoRocker authored and dpgeorge committed Mar 11, 2021
1 parent 23ce25a commit 8610bab
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions ports/rp2/CMakeLists.txt
Expand Up @@ -51,6 +51,7 @@ set(SOURCE_DRIVERS
)

set(SOURCE_PORT
fatfs_port.c
machine_adc.c
machine_i2c.c
machine_pin.c
Expand Down
34 changes: 34 additions & 0 deletions ports/rp2/fatfs_port.c
@@ -0,0 +1,34 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2013, 2014 Damien P. George
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "lib/oofatfs/ff.h"
#include "hardware/rtc.h"

MP_WEAK DWORD get_fattime(void) {
datetime_t t;
rtc_get_datetime(&t);
return ((2000 + t.year - 1980) << 25) | ((t.month) << 21) | ((t.day) << 16) | ((t.hour) << 11) | ((t.min) << 5) | (t.sec / 2);
}
6 changes: 6 additions & 0 deletions ports/rp2/mpconfigport.h
Expand Up @@ -118,6 +118,12 @@
#define MICROPY_PY_FRAMEBUF (1)
#define MICROPY_VFS (1)
#define MICROPY_VFS_LFS2 (1)
#define MICROPY_VFS_FAT (1)

// fatfs configuration
#define MICROPY_FATFS_ENABLE_LFN (1)
#define MICROPY_FATFS_LFN_CODE_PAGE 437 /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
#define MICROPY_FATFS_RPATH (2)

// Use VfsLfs2's types for fileio/textio
#define mp_type_fileio mp_type_vfs_lfs2_fileio
Expand Down

0 comments on commit 8610bab

Please sign in to comment.