From f9a3c0888542b951de58ae92929f38b7f55eed49 Mon Sep 17 00:00:00 2001 From: David Refoua Date: Mon, 5 Jun 2023 21:02:39 +0330 Subject: [PATCH] add `packToInt`, `packToLong`, `bitIsSet` and `bitIsClear` --- cores/arduino/Arduino.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 91eeb16bc..fd361254e 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -73,7 +73,7 @@ void yield(void); #define INTERNAL INTERNAL1V1 #define INTERNAL2V56 9 #define INTERNAL2V56_EXTCAP 13 -#else +#else #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__) || defined(__AVR_ATmega644__) || defined(__AVR_ATmega644A__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) #define INTERNAL1V1 2 #define INTERNAL2V56 3 @@ -108,11 +108,16 @@ void yield(void); #define lowByte(w) ((uint8_t) ((w) & 0xff)) #define highByte(w) ((uint8_t) ((w) >> 8)) +#define packToInt(h,l) ((uint16_t)h)<<8 | (uint16_t)l) +#define packToLong(i3,i2,i1,i0) (((uint32_t)i3<<24) | ((uint32_t)i2<<16) | ((uint32_t)i1<<8) | (uint32_t)i0) + #define bitRead(value, bit) (((value) >> (bit)) & 0x01) #define bitSet(value, bit) ((value) |= (1UL << (bit))) #define bitClear(value, bit) ((value) &= ~(1UL << (bit))) #define bitToggle(value, bit) ((value) ^= (1UL << (bit))) #define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit)) +#define bitIsSet(value, bit) ((value) & (1UL << (bit))) +#define bitIsClear(value, bit) (!((value) & (1UL << (bit)))) // avr-libc defines _NOP() since 1.6.2 #ifndef _NOP @@ -172,7 +177,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[]; // Get the bit location within the hardware port of the given virtual pin. // This comes from the pins_*.c file for the active board configuration. -// +// // These perform slightly better as macros compared to inline functions // #define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )