Skip to content

Commit f9a3c08

Browse files
authored
add packToInt, packToLong, bitIsSet and bitIsClear
1 parent eabd762 commit f9a3c08

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Diff for: cores/arduino/Arduino.h

+7-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ void yield(void);
7373
#define INTERNAL INTERNAL1V1
7474
#define INTERNAL2V56 9
7575
#define INTERNAL2V56_EXTCAP 13
76-
#else
76+
#else
7777
#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__)
7878
#define INTERNAL1V1 2
7979
#define INTERNAL2V56 3
@@ -108,11 +108,16 @@ void yield(void);
108108
#define lowByte(w) ((uint8_t) ((w) & 0xff))
109109
#define highByte(w) ((uint8_t) ((w) >> 8))
110110

111+
#define packToInt(h,l) ((uint16_t)h)<<8 | (uint16_t)l)
112+
#define packToLong(i3,i2,i1,i0) (((uint32_t)i3<<24) | ((uint32_t)i2<<16) | ((uint32_t)i1<<8) | (uint32_t)i0)
113+
111114
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
112115
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
113116
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
114117
#define bitToggle(value, bit) ((value) ^= (1UL << (bit)))
115118
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet(value, bit) : bitClear(value, bit))
119+
#define bitIsSet(value, bit) ((value) & (1UL << (bit)))
120+
#define bitIsClear(value, bit) (!((value) & (1UL << (bit))))
116121

117122
// avr-libc defines _NOP() since 1.6.2
118123
#ifndef _NOP
@@ -172,7 +177,7 @@ extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
172177

173178
// Get the bit location within the hardware port of the given virtual pin.
174179
// This comes from the pins_*.c file for the active board configuration.
175-
//
180+
//
176181
// These perform slightly better as macros compared to inline functions
177182
//
178183
#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )

0 commit comments

Comments
 (0)