diff options
author | David A. Mellis <d.mellis@arduino.cc> | 2008-10-25 12:52:07 +0000 |
---|---|---|
committer | David A. Mellis <d.mellis@arduino.cc> | 2008-10-25 12:52:07 +0000 |
commit | da84adb1e9d09b069137dd90f2e99c43a4db42ad (patch) | |
tree | 1adee6ae83c6159a9a952183d5feed51a2fbf779 /cores/arduino | |
parent | 5444b25e11bce6139a58c8a641dccd266f90a0f1 (diff) |
Adding word datatype and cast/construction macros, bitRead(), bitWrite(), bitSet(), bitClear(), bit().
Diffstat (limited to 'cores/arduino')
-rwxr-xr-x | cores/arduino/WProgram.h | 5 | ||||
-rwxr-xr-x | cores/arduino/wiring.h | 28 |
2 files changed, 17 insertions, 16 deletions
diff --git a/cores/arduino/WProgram.h b/cores/arduino/WProgram.h index 20650df..e20cab5 100755 --- a/cores/arduino/WProgram.h +++ b/cores/arduino/WProgram.h @@ -12,6 +12,11 @@ #ifdef __cplusplus #include "HardwareSerial.h" +uint16_t makeWord(uint16_t w) { return w; } +uint16_t makeWord(byte h, byte l) { return (h << 8) | l; } + +#define word(...) makeWord(__VA_ARGS__) + unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); // WMath prototypes diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h index 3701f6d..46d5334 100755 --- a/cores/arduino/wiring.h +++ b/cores/arduino/wiring.h @@ -66,13 +66,6 @@ extern "C"{ #undef abs #endif -//#define int(x) ((int)(x)) -//#define char(x) ((char)(x)) -//#define long(x) ((long)(x)) -//#define byte(x) ((uint8_t)(x)) -//#define float(x) ((float)(x)) -//#define boolean(x) ((uint8_t)((x)==0?0:1)) - #define min(a,b) ((a)<(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b)) #define abs(x) ((x)>0?(x):-(x)) @@ -89,6 +82,18 @@ extern "C"{ #define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() ) #define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() ) +#define lowByte(w) ((w) & 0xff) +#define highByte(w) ((w) >> 8) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + +typedef unsigned int word; + +#define bit(b) (1 << (b)) + typedef uint8_t boolean; typedef uint8_t byte; @@ -106,15 +111,6 @@ void serialWrite(unsigned char); int serialAvailable(void); int serialRead(void); void serialFlush(void); -void printMode(int); -void printByte(unsigned char c); -void printNewline(void); -void printString(const char *s); -void printInteger(long n); -void printHex(unsigned long n); -void printOctal(unsigned long n); -void printBinary(unsigned long n); -void printIntegerInBase(unsigned long n, unsigned long base); unsigned long millis(void); void delay(unsigned long); |