Refactored I2C interface definitions, added capabilities flags for run time discovery.

This commit is contained in:
Terje Io
2025-02-28 23:38:55 +01:00
parent 68aa11923a
commit 2d54e34339
9 changed files with 143 additions and 44 deletions
+2 -2
View File
@@ -1,6 +1,6 @@
## grblHAL ##
Latest build date is 20250225, see the [changelog](changelog.md) for details.
Latest build date is 20250228, see the [changelog](changelog.md) for details.
> [!NOTE]
> A settings reset will be performed on an update of builds prior to 20241208. Backup and restore of settings is recommended.
@@ -89,4 +89,4 @@ G/M-codes not supported by [legacy Grbl](https://github.com/gnea/grbl/wiki) are
Some [plugins](https://github.com/grblHAL/plugins) implements additional M-codes.
---
20250225
20250228
+26
View File
@@ -1,5 +1,31 @@
## grblHAL changelog
<a name="20250228">Build 20250228
Core:
* Refactored I2C interface definitions, added capabilities flags for run time discovery.
Drivers:
* All: updated for refactored I2C interface. Some updated from a non-compliant implementation of the previous version..
* RP2040, STM32F7xx: added driver support for max limit switches. Ref. issue [#116](https://github.com/grblHAL/RP2040/issues/116).
* STM32F4xx: aded support for I2C DMA writes.
Plugins:
* EEPROM, Keypad: updated for refactored I2C interface.
* SD card: removed unused variable, only add chmod() support for FatFs if available.
* Networking: added code guard to prevent compiler error in some configurations.
* WebUI: fixed regression affecting WebUI v2.
---
<a name="20250225">Build 20250225
Core \(for developers\):
+11 -10
View File
@@ -137,11 +137,8 @@
#endif
#endif
#if DISPLAY_ENABLE == 2
#ifdef I2C_ENABLE
#undef I2C_ENABLE
#endif
#define I2C_ENABLE 1
#ifndef DISPLAY_ENABLE
#define DISPLAY_ENABLE 0
#endif
#ifndef EEPROM_ENABLE
@@ -151,16 +148,20 @@
#define EEPROM_IS_FRAM 0
#endif
#ifndef I2C_ENABLE
#if EEPROM_ENABLE || KEYPAD_ENABLE == 1 || DISPLAY_ENABLE == 1 || DISPLAY_ENABLE == 2 || I2C_STROBE_ENABLE || (TRINAMIC_ENABLE && TRINAMIC_I2C)
#define I2C_ENABLE 1
#if EEPROM_ENABLE || KEYPAD_ENABLE == 1 || I2C_STROBE_ENABLE || (DISPLAY_ENABLE & DISPLAY_I2C) || (TRINAMIC_ENABLE && TRINAMIC_I2C)
#if defined(I2C_ENABLE) && I2C_ENABLE == 0
#undef I2C_ENABLE
#else
#define I2C_ENABLE 0
#define I2C_ENABLE 1
#endif
#endif
#ifndef I2C_ENABLE
#define I2C_ENABLE 0
#endif
#ifndef SPINDLE_SYNC_ENABLE
#define SPINDLE_SYNC_ENABLE 0
#define SPINDLE_SYNC_ENABLE 0
#endif
#ifndef SPINDLE_ENCODER_ENABLE
+1 -1
View File
@@ -42,7 +42,7 @@
#else
#define GRBL_VERSION "1.1f"
#endif
#define GRBL_BUILD 20250225
#define GRBL_BUILD 20250228
#define GRBL_URL "https://github.com/grblHAL"
+42 -4
View File
@@ -1236,6 +1236,44 @@
#define Z_LIMIT_BIT_MAX 0
#endif
#endif
#ifndef A_LIMIT_BIT_MAX
#ifdef A_LIMIT_PIN_MAX
#define A_LIMIT_BIT_MAX (1<<A_LIMIT_PIN_MAX)
#else
#define A_LIMIT_BIT_MAX 0
#endif
#endif
#ifndef B_LIMIT_BIT_MAX
#ifdef B_LIMIT_PIN_MAX
#define B_LIMIT_BIT_MAX (1<<B_LIMIT_PIN_MAX)
#else
#define B_LIMIT_BIT_MAX 0
#endif
#endif
#ifndef C_LIMIT_BIT_MAX
#ifdef C_LIMIT_PIN_MAX
#define C_LIMIT_BIT_MAX (1<<C_LIMIT_PIN_MAX)
#else
#define C_LIMIT_BIT_MAX 0
#endif
#endif
#ifndef U_LIMIT_BIT_MAX
#ifdef U_LIMIT_PIN_MAX
#define U_LIMIT_BIT_MAX (1<<U_LIMIT_PIN_MAX)
#else
#define U_LIMIT_BIT_MAX 0
#endif
#endif
#ifndef V_LIMIT_BIT_MAX
#ifdef V_LIMIT_PIN_MAX
#define V_LIMIT_BIT_MAX (1<<V_LIMIT_PIN_MAX)
#else
#define V_LIMIT_BIT_MAX 0
#endif
#endif
#define LIMIT_MAX_MASK (X_LIMIT_BIT_MAX|Y_LIMIT_BIT_MAX|Z_LIMIT_BIT_MAX|A_LIMIT_BIT_MAX|B_LIMIT_BIT_MAX|C_LIMIT_BIT_MAX|U_LIMIT_BIT_MAX|V_LIMIT_BIT_MAX)
#define LIMIT_MAX_SUM (X_LIMIT_BIT_MAX+Y_LIMIT_BIT_MAX+Z_LIMIT_BIT_MAX+A_LIMIT_BIT_MAX+B_LIMIT_BIT_MAX+C_LIMIT_BIT_MAX+U_LIMIT_BIT_MAX+V_LIMIT_BIT_MAX)
#if !defined(X_ENABLE_BIT) && defined(X_ENABLE_PIN)
#define X_ENABLE_BIT (1<<X_ENABLE_PIN)
@@ -1383,11 +1421,11 @@
#endif
#ifdef Z_LIMIT_POLL
#define LIMIT_MASK_BASE (X_LIMIT_BIT|Y_LIMIT_BIT|LIMIT2_MASK)
#define LIMIT_MASK_BASE_SUM (X_LIMIT_BIT+Y_LIMIT_BIT+LIMIT2_MASK_SUM)
#define LIMIT_MASK_BASE (X_LIMIT_BIT|Y_LIMIT_BIT|LIMIT2_MASK|LIMIT_MAX_MASK)
#define LIMIT_MASK_BASE_SUM (X_LIMIT_BIT+Y_LIMIT_BIT+LIMIT2_MASK_SUM+LIMIT_MAX_SUM)
#else
#define LIMIT_MASK_BASE (X_LIMIT_BIT|Y_LIMIT_BIT|Z_LIMIT_BIT|X_LIMIT_BIT_MAX|Y_LIMIT_BIT_MAX|Z_LIMIT_BIT_MAX|LIMIT2_MASK)
#define LIMIT_MASK_BASE_SUM (X_LIMIT_BIT+Y_LIMIT_BIT+Z_LIMIT_BIT+X_LIMIT_BIT_MAX+Y_LIMIT_BIT_MAX+Z_LIMIT_BIT_MAX+LIMIT2_MASK_SUM)
#define LIMIT_MASK_BASE (X_LIMIT_BIT|Y_LIMIT_BIT|Z_LIMIT_BIT|LIMIT2_MASK|LIMIT_MAX_MASK)
#define LIMIT_MASK_BASE_SUM (X_LIMIT_BIT+Y_LIMIT_BIT+Z_LIMIT_BIT+LIMIT2_MASK_SUM+LIMIT_MAX_SUM)
#endif
#if N_AXIS == 3
+3 -9
View File
@@ -3,7 +3,7 @@
Part of grblHAL
Copyright (c) 2017-2023 Terje Io
Copyright (c) 2017-2025 Terje Io
Copyright (c) 2009-2011 Simen Svale Skogsrud
grblHAL is free software: you can redistribute it and/or modify
@@ -92,12 +92,6 @@ typedef struct {
uint16_t size; //!< Actual size of driver area in bytes.
} nvs_driver_area_t;
typedef enum {
NVS_TransferResult_Failed = 0, //!< 0
NVS_TransferResult_Busy, //!< 1
NVS_TransferResult_OK, //!< 2
} nvs_transfer_result_t;
/*! \brief Pointer to function for getting a byte from NVS storage.
\param addr index base address into the area.
\returns byte read.
@@ -117,7 +111,7 @@ typedef void (*put_byte_ptr)(uint32_t addr, uint8_t new_value);
\param with_checksum \a true calculate and verify checksum at the end of the data block, \a false do not calculate and verify checksum.
\returns #nvs_transfer_result_t enum.
*/
typedef nvs_transfer_result_t (*memcpy_from_nvs_ptr)(uint8_t *dest, uint32_t source, uint32_t size, bool with_checksum);
typedef bool (*memcpy_from_nvs_ptr)(uint8_t *dest, uint32_t source, uint32_t size, bool with_checksum);
/*! \brief Pointer to function for writing a block of data to NVS storage
\param dest index based address into the storage area.
@@ -126,7 +120,7 @@ typedef nvs_transfer_result_t (*memcpy_from_nvs_ptr)(uint8_t *dest, uint32_t sou
\param with_checksum \a true calculate and add a checksum at the end of the data block, \a false do not add checksum.
\returns #nvs_transfer_result_t enum.
*/
typedef nvs_transfer_result_t (*memcpy_to_nvs_ptr)(uint32_t dest, uint8_t *source, uint32_t size, bool with_checksum);
typedef bool (*memcpy_to_nvs_ptr)(uint32_t dest, uint8_t *source, uint32_t size, bool with_checksum);
/*! \brief Pointer to function for reading a block of data from flash based NVS storage.
\param dest pointer to destination of data.
+2 -2
View File
@@ -214,9 +214,9 @@ static nvs_transfer_result_t memcpy_from_ram (uint8_t *destination, uint32_t sou
*(destination++) = ram_get_byte(source++);
#if NVS_CRC_BYTES == 1
return with_checksum ? (checksum == ram_get_byte(source) ? NVS_TransferResult_OK : NVS_TransferResult_Failed) : NVS_TransferResult_OK;
return !with_checksum || checksum == ram_get_byte(source);
#else
return with_checksum ? (checksum == (ram_get_byte(source) | (ram_get_byte(source + 1) << 8)) ? NVS_TransferResult_OK : NVS_TransferResult_Failed) : NVS_TransferResult_OK;
return !with_checksum || checksum == (ram_get_byte(source) | (ram_get_byte(source + 1) << 8));
#endif
}
+53 -13
View File
@@ -221,26 +221,66 @@ typedef struct {
encoder_settings_t *settings;
} encoder_t;
// EEPROM/FRAM interface
// I2C interface
typedef uint_fast16_t i2c_address_t;
typedef struct {
uint8_t address;
uint8_t word_addr_bytes;
uint16_t word_addr;
volatile uint_fast16_t count;
bool add_checksum;
uint8_t checksum;
i2c_address_t address;
union {
struct {
uint8_t cmd_bytes;
uint16_t cmd;
};
struct {
uint8_t word_addr_bytes;
uint16_t word_addr;
};
};
uint_fast16_t count;
bool no_block;
uint8_t *data;
} nvs_transfer_t;
} i2c_transfer_t;
extern nvs_transfer_result_t i2c_nvs_transfer (nvs_transfer_t *i2c, bool read);
typedef union {
uint8_t ok;
struct {
uint8_t started :1,
tx_non_blocking :1,
tx_dma :1,
unassigned :5;
};
} i2c_cap_t;
// I2C interface
// DISPLAYS:
// Interfaces
#define DISPLAY_I2C (1<<0) //!< 1
#define DISPLAY_SPI (1<<1) //!< 2
#define DISPLAY_UART (1<<2) //!< 4
// Plugins
#define DISPLAY_I2C_INTERFACE ((1<<3)|DISPLAY_I2C) //!< 9
#define DISPLAY_I2C_LEDS ((1<<4)|DISPLAY_I2C) //!< 17
#define DISPLAY_I2C_LUC ((1<<5)|DISPLAY_I2C) //!< 33
// EEPROM/FRAM:
typedef i2c_transfer_t nvs_transfer_t;
#define i2c_nvs_transfer(i2c, rd) i2c_transfer(i2c, rd)
typedef bool nvs_transfer_result_t;
#define NVS_TransferResult_OK true
// I2C interface:
typedef void (*keycode_callback_ptr)(const char c);
extern bool i2c_probe (uint_fast16_t i2c_address);
extern bool i2c_send (uint_fast16_t i2c_address, uint8_t *data, size_t size, bool block);
extern void i2c_get_keycode (uint_fast16_t i2c_address, keycode_callback_ptr callback);
extern i2c_cap_t i2c_start (void);
extern bool i2c_probe (i2c_address_t i2c_address);
extern bool i2c_send (i2c_address_t i2c_address, uint8_t *data, size_t size, bool block);
extern bool i2c_receive (i2c_address_t i2cAddr, uint8_t *buf, size_t size, bool block);
extern bool i2c_get_keycode (i2c_address_t i2c_address, keycode_callback_ptr callback);
extern bool i2c_transfer (i2c_transfer_t *i2c, bool read);
#endif
+3 -3
View File
@@ -576,6 +576,8 @@ bool vfs_mount (const char *path, const vfs_t *fs, vfs_st_mode_t mode)
root.mode = mode;
} else if((mount = (vfs_mount_t *)calloc(sizeof(vfs_mount_t), 1))) {
struct tm tm;
strcpy(mount->path, path);
if(mount->path[strlen(path) - 1] != '/')
strcat(mount->path, "/");
@@ -583,9 +585,7 @@ bool vfs_mount (const char *path, const vfs_t *fs, vfs_st_mode_t mode)
mount->vfs = fs;
mount->mode = mode;
mount->next = NULL;
if(hal.rtc.get_datetime) {
struct tm tm;
hal.rtc.get_datetime(&tm);
if(hal.rtc.get_datetime && hal.rtc.get_datetime(&tm)) {
#ifdef ESP_PLATFORM
mount->st_mtim = mktime(&tm);
#else