From e009f47116db4d21f94d2bd1a1b5e682c35ff493 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Sun, 4 Sep 2022 20:56:33 +0200 Subject: [PATCH] Added optional RTC (Real Time Clock) support to the HAL. VFS improvements. --- README.md | 4 ++-- changelog.md | 22 ++++++++++++++++++++++ grbl.h | 2 +- hal.h | 25 +++++++++++++++++++++++++ vfs.c | 11 +++++++++++ vfs.h | 6 +++++- 6 files changed, 66 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 7451423..a726af0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ It has been written to complement grblHAL and has features such as proper keyboa --- -Latest build date is 20220903, see the [changelog](changelog.md) for details. +Latest build date is 20220904, see the [changelog](changelog.md) for details. __NOTE:__ A settings reset will be performed on an update for versions earlier than 20211122. Backup and restore of settings is recommended. __IMPORTANT!__ A new setting has been introduced for ganged axes motors in version 20211121. I have only bench tested this for a couple of drivers, correct function should be verified after updating by those who have more than three motors configured. @@ -84,4 +84,4 @@ List of Supported G-Codes: Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes. --- -2022-09-03 +2022-09-04 diff --git a/changelog.md b/changelog.md index f38ed1a..0ccf718 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,27 @@ ## grblHAL changelog +20220904: + +Core: + +* Added optional RTC (Real Time Clock) support to the HAL. VFS improvements. + +Plugins: + +* Networking: improved websocket protocol handling. + +* WebUI: separated command handlers for v2 and v3 and improved detection of v3 clients. Now sets RTC from ESP800 if HAL allows. + +Drivers: + +* RP2040: Added RTC support++. + +* iMXRT1062: updated uSDFS patch - needed for VFS changes. + +* STM32F7xx: updated FatFs options file for better VFS integration. + +--- + 20220903: Core: diff --git a/grbl.h b/grbl.h index 6f26044..cebad7c 100644 --- a/grbl.h +++ b/grbl.h @@ -34,7 +34,7 @@ #else #define GRBL_VERSION "1.1f" #endif -#define GRBL_BUILD 20220903 +#define GRBL_BUILD 20220904 // The following symbols are set here if not already set by the compiler or in config.h // Do NOT change here! diff --git a/hal.h b/hal.h index e276928..53c5aa8 100644 --- a/hal.h +++ b/hal.h @@ -26,6 +26,8 @@ #ifndef _HAL_H_ #define _HAL_H_ +#include + #include "grbl.h" #include "core_handlers.h" #include "gcode.h" @@ -470,6 +472,28 @@ typedef struct { */ typedef bool (*irq_claim_ptr)(irq_type_t irq, uint_fast8_t id, irq_callback_ptr callback); + +/************************** + * RTC (Real Time Clock * + **************************/ + +/*! \brief Pointer to function for setting the current datetime. +\param datetime pointer to a \a tm struct. +\returns true if successful. +*/ +typedef bool (*rtc_get_datetime_ptr)(struct tm *datetime); + +/*! \brief Pointer to function for setting the current datetime. +\param datetime pointer to a \a tm struct. +\returns true if successful. +*/ +typedef bool (*rtc_set_datetime_ptr)(struct tm *datetime); + +typedef struct { + rtc_get_datetime_ptr get_datetime; //!< Optional handler getting the current datetime. + rtc_set_datetime_ptr set_datetime; //!< Optional handler setting the current datetime. +} rtc_ptrs_t; + /*! \brief HAL structure used for the driver interface. This structure contains properties and function pointers (to handlers) that the core uses to communicate with the driver. @@ -549,6 +573,7 @@ typedef struct { settings_changed_ptr settings_changed; //!< Callback handler to be called on settings loaded or settings changed events. probe_ptrs_t probe; //!< Optional handlers for probe input(s). tool_ptrs_t tool; //!< Optional handlers for tool changes. + rtc_ptrs_t rtc; //!< Optional handlers for real time clock (RTC). io_port_t port; //!< Optional handlers for axuillary I/O (adds support for M62-M66). periph_port_t periph_port; //!< Optional handlers for peripheral pin registration. driver_reset_ptr driver_reset; //!< Optional handler, called on soft resets. Set to a dummy handler by the core at startup. diff --git a/vfs.c b/vfs.c index 0d0d4f9..47fc5a0 100644 --- a/vfs.c +++ b/vfs.c @@ -24,6 +24,8 @@ #include #include +#ifndef ARDUINO_SAM_DUE + #include "hal.h" #include "vfs.h" //#include @@ -340,6 +342,13 @@ int vfs_stat (const char *filename, vfs_stat_t *st) return mount ? mount->vfs->fstat(get_filename(mount, filename), st) : -1; } +int vfs_utime (const char *filename, struct tm *modified) +{ + vfs_mount_t *mount = get_mount(filename); + + return mount && mount->vfs->futime ? mount->vfs->futime(get_filename(mount, filename), modified) : -1; +} + vfs_free_t *vfs_fgetfree (const char *path) { static vfs_free_t free; @@ -403,6 +412,8 @@ bool vfs_unmount (const char *path) return true; } +#endif + /* struct tm *gmtime (const time_t *c_t) { diff --git a/vfs.h b/vfs.h index 7634b5f..f6671a7 100644 --- a/vfs.h +++ b/vfs.h @@ -35,7 +35,7 @@ #define vfs_load_plugin(x) #define bcopy(src, dest, len) memmove(dest, src, len) -#ifndef __time_t_defined +#if !(defined(__time_t_defined) || defined(__MSP432P401R__) || defined(PART_TM4C123GH6PM)) typedef struct { short date; short time; @@ -120,11 +120,13 @@ typedef vfs_dir_t *(*vfs_opendir_ptr)(const char *path); typedef char *(*vfs_readdir_ptr)(vfs_dir_t *dir, vfs_dirent_t *dirent); typedef void (*vfs_closedir_ptr)(vfs_dir_t *dir); typedef int (*vfs_stat_ptr)(const char *filename, vfs_stat_t *st); +typedef int (*vfs_utime_ptr)(const char *filename, struct tm *modified); typedef bool (*vfs_getfree_ptr)(vfs_free_t *free); typedef struct { + const char *fs_name; vfs_st_mode_t mode; vfs_open_ptr fopen; vfs_close_ptr fclose; @@ -142,6 +144,7 @@ typedef struct vfs_readdir_ptr readdir; vfs_closedir_ptr fclosedir; vfs_stat_ptr fstat; + vfs_utime_ptr futime; vfs_getcwd_ptr fgetcwd; vfs_getfree_ptr fgetfree; } vfs_t; @@ -177,6 +180,7 @@ vfs_dirent_t *vfs_readdir (vfs_dir_t *dir); void vfs_closedir (vfs_dir_t *dir); char *vfs_getcwd (char *buf, size_t len); int vfs_stat (const char *filename, vfs_stat_t *st); +int vfs_utime (const char *filename, struct tm *modified); vfs_free_t *vfs_fgetfree (const char *path); #endif