- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
#ifndef PORT_H_
#define PORT_H_
#define MAKE_PORT(portName, ddrName, pinName, className, ID) \
class className{\
public:\
typedef uint8_t DataT; /* Alias for the type of data port*/\
private:\
static volatile DataT &data()\
{\
return portName;\
}\
static volatile DataT &dir()\
{\
return ddrName;\
}\
static volatile DataT &pin()\
{\
return pinName;\
}\
public:\
static void Write(DataT value) /*Write value to port PORT = value*/\
{\
data() = value;\
}\
static void ClearAndSet(DataT clearMask, DataT value) /*Clear by mask and set PORT = (PORT & ~clearMask) | value */\
{\
data() = (data() & ~clearMask) | value;\
}\
static DataT Read() /*Read the value written to the port*/\
{\
return data();\
}\
static void DirWrite(DataT value)/*Record the value of the direction of the lines I/O */\
{\
dir() = value;\
}\
static DataT DirRead() /*Read the value of the direction of the lines I/O */\
{\
return dir();\
}\
static void Set(DataT value) /*Set bits in the port PORT |= value;*/\
{\
data() |= value;\
}\
static void Clear(DataT value) /*Clear bits in the port PORT &= ~value;*/\
{\
data() &= ~value;\
}\
static void Togle(DataT value) /*Switch bits PORT ^= value;*/\
{\
data() ^= value;\
}\
static void DirSet(DataT value) /*Set direction bits*/\
{\
dir() |= value;\
}\
static void DirClear(DataT value) /*Clear direction bits*/\
{\
dir() &= ~value;\
}\
static void DirTogle(DataT value)\
{\
dir() ^= value;\
}\
static DataT PinRead()\
{\
return pin();\
}\
enum{Id = ID};\
enum{Width=sizeof(DataT)*8};/*Bit depth*/\
};
#ifdef PORTA
MAKE_PORT(PORTA, DDRA, PINA, Porta, 'A');
#endif
#ifdef PORTB
MAKE_PORT(PORTB, DDRB, PINB, Portb, 'B');
#endif
#ifdef PORTC
MAKE_PORT(PORTC, DDRC, PINC, Portc, 'C');
#endif
#ifdef PORTD
MAKE_PORT(PORTD, DDRD, PIND, Portd, 'D');
#endif
#endif /* PORT_H_ */