Adding word datatype and cast/construction macros, bitRead(), bitWrite(), bitSet(), bitClear(), bit().

This commit is contained in:
David A. Mellis 2008-10-25 12:52:07 +00:00
parent 5444b25e11
commit da84adb1e9
2 changed files with 17 additions and 16 deletions

View File

@ -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

View File

@ -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);