Skip to content

Commit cf1509c

Browse files
committed
esp32/fatfs_port: Implement get_fattime so FAT files have a timestamp.
Fixes issue adafruit#3859.
1 parent d11fb09 commit cf1509c

1 file changed

Lines changed: 4 additions & 9 deletions

File tree

ports/esp32/fatfs_port.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,15 @@
2626
* THE SOFTWARE.
2727
*/
2828

29-
#include "py/obj.h"
29+
#include <sys/time.h>
3030
#include "lib/oofatfs/ff.h"
3131
#include "timeutils.h"
32-
//#include "modmachine.h"
3332

3433
DWORD get_fattime(void) {
35-
36-
// TODO: Optimize division (there's no HW division support on ESP8266,
37-
// so it's expensive).
38-
//uint32_t secs = (uint32_t)(pyb_rtc_get_us_since_2000() / 1000000);
39-
uint32_t secs = 0;
40-
34+
struct timeval tv;
35+
gettimeofday(&tv, NULL);
4136
timeutils_struct_time_t tm;
42-
timeutils_seconds_since_2000_to_struct_time(secs, &tm);
37+
timeutils_seconds_since_2000_to_struct_time(tv.tv_sec, &tm);
4338

4439
return (((DWORD)(tm.tm_year - 1980) << 25) | ((DWORD)tm.tm_mon << 21) | ((DWORD)tm.tm_mday << 16) |
4540
((DWORD)tm.tm_hour << 11) | ((DWORD)tm.tm_min << 5) | ((DWORD)tm.tm_sec >> 1));

0 commit comments

Comments
 (0)