diff --git a/core/include/common_macros.h b/core/include/common_macros.h index 669203a..b0c7a08 100644 --- a/core/include/common_macros.h +++ b/core/include/common_macros.h @@ -20,12 +20,21 @@ * and shift) constants. Used primarily with ESP8266 register access. */ -#define VAL2FIELD(fieldname, value) (((value) & fieldname##_M) << fieldname##_S) +#define VAL2FIELD(fieldname, value) ((value) << fieldname##_S) #define FIELD2VAL(fieldname, regbits) (((regbits) >> fieldname##_S) & fieldname##_M) #define FIELD_MASK(fieldname) (fieldname##_M << fieldname##_S) #define SET_FIELD(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD(fieldname, value)) +/* VAL2FIELD/SET_FIELD do not normally check to make sure that the passed value + * will fit in the specified field (without clobbering other bits). This makes + * them faster and is usually fine. If you do need to make sure that the value + * will not overflow the field, use VAL2FIELD_M or SET_FIELD_M (which will + * first mask the supplied value to only the allowed number of bits) instead. + */ +#define VAL2FIELD_M(fieldname, value) (((value) & fieldname##_M) << fieldname##_S) +#define SET_FIELD_M(regbits, fieldname, value) (((regbits) & ~FIELD_MASK(fieldname)) | VAL2FIELD_M(fieldname, value)) + /* Use this macro to store constant values in IROM flash instead of having them loaded into rodata (which resides in DRAM)