18 #define DDR_HIGH (*_DDR |= _offset) 19 #define DDR_TOGGLE (*_DDR ^= _offset) 20 #define DDR_LOW (*_DDR &= _ioffset) 22 #define PORT_HIGH (*_PORT |= _offset) 23 #define PORT_TOGGLE (*_PORT ^= _offset) 24 #define PORT_LOW (*_PORT &= _ioffset) 26 #define DDR_ON (*_DDR & _offset) 27 #define DDR_OFF (*_DDR | _ioffset) 29 #define PORT_ON (*_PORT & _offset) 30 #define PORT_OFF (*_PORT | _ioffset) 32 #define PIN_ON (*_PIN & _offset) 33 #define PIN_OFF (*_PIN | _ioffset) 47 _offset = digitalPinToBitMask(_number);
49 _timer = digitalPinToTimer(_number);
50 _PIN = portInputRegister(digitalPinToPort(_number));
51 _PORT = portOutputRegister(digitalPinToPort(_number));
52 _DDR = portModeRegister(digitalPinToPort(_number));
62 _offset = digitalPinToBitMask(_number);
64 _timer = digitalPinToTimer(_number);
65 _PIN = portInputRegister(digitalPinToPort(_number));
66 _PORT = portOutputRegister(digitalPinToPort(_number));
67 _DDR = portModeRegister(digitalPinToPort(_number));
82 Pin(uint8_t number, uint8_t offset, uint8_t timer,
volatile uint8_t* PIN,
volatile uint8_t* PORT,
volatile uint8_t* DDR) {
97 operator bool()
const {
107 uint8_t oldSREG = SREG;
227 return analogRead(_number);
236 void set(uint8_t mode, uint8_t state) {
237 uint8_t oldSREG = SREG;
258 uint8_t oldSREG = SREG;
274 uint8_t oldSREG = SREG;
288 uint8_t oldSREG = SREG;
298 uint8_t oldSREG = SREG;
308 uint8_t oldSREG = SREG;
318 uint8_t oldSREG = SREG;
329 uint8_t oldSREG = SREG;
340 uint8_t oldSREG = SREG;
350 uint8_t oldSREG = SREG;
360 uint8_t oldSREG = SREG;
370 uint8_t oldSREG = SREG;
381 uint8_t oldSREG = SREG;
394 analogWrite(_number,value);
401 uint8_t oldSREG = SREG;
411 uint8_t oldSREG = SREG;
424 volatile unsigned int rcTimer(
volatile unsigned int count) {
438 "in %[status], __SREG__ \n\t" 442 "ld __tmp_reg__, %a[_DDR] \n\t" 443 "and __tmp_reg__, %[_ioffset] \n\t" 444 "st %a[_DDR], __tmp_reg__ \n\t" 448 "ld __tmp_reg__,%a[_PIN] \n\t" 449 "and __tmp_reg__, %[_offset] \n\t" 457 "ld __tmp_reg__, %a[_DDR] \n\t" 458 "or __tmp_reg__, %[_offset] \n\t" 459 "st %a[_DDR], __tmp_reg__ \n\t" 462 "out __SREG__, %[status] \n\t" 466 [count]
"+r" (count),
467 [status]
"=&r" (status)
473 [_offset]
"r" (_offset),
474 [_ioffset]
"r" (_ioffset)
485 volatile uint8_t* _PIN;
486 volatile uint8_t* _PORT;
487 volatile uint8_t* _DDR;
void setInputPullupOff()
Set the pin mode to input and the pin pullup resistor to off.
uint8_t getState()
Get the state of the pin from the PORT register.
uint8_t getNumber()
Get the pin number.
#define DDR_ON
Get the DDR register for the pin (HIGH, LOW)
void setHigh()
Set the pin output to HIGH.
uint8_t getInverseOffset()
Get the inverse pin offset.
Class for fast operations on Arduino I/O pins.
void setDutyCycle(int value)
Set the PWM duty cycle.
#define PIN_ON
Get the PIN register for the pin (HIGH, LOW)
volatile uint8_t * getPIN()
Get a pointer to the PIN register.
#define DDR_LOW
Set the DDR register to LOW for the pin.
uint16_t getAnalogValue()
Get the analog value of the pin.
#define PORT_ON
Get the PORT register for the pin (HIGH, LOW)
void setPullupOff()
Set the pin pullup resistor to off.
void setInputPullupOn()
Set the pin mode to input and the pin pullup resistor to on.
Pin & operator=(uint8_t state)
Set the pin state.
#define PORT_TOGGLE
Set the PORT register to the inverse for the pin.
void setOutput()
Set the pin mode to output.
void setOutputHigh()
Set the pin mode to output and the pin output to HIGH.
void setMode(uint8_t mode)
Set the pin mode.
volatile uint8_t * getPORT()
Get a pointer to the PORT register.
void setLow()
Set the pin output to LOW.
#define DDR_HIGH
Set the DDR register to HIGH for the pin.
#define PORT_HIGH
Set the PORT register to HIGH for the pin.
void setPullupOn()
Set the pin pullup resistor to on.
void setOutputLow()
Set the pin mode to output and the pin output to LOW.
uint8_t getValue()
Get the value of the pin from the PIN register.
void toggleMode()
Toggle the pin mode (OUTPUT -> INPUT, INPUT -> OUTPUT)
void toggleState()
Toggle the pin state (HIGH -> LOW, LOW -> HIGH)
uint8_t getOffset()
Get the pin offset.
Pin()
Default constructor.
#define PORT_LOW
Set the PORT register to LOW for the pin.
volatile uint8_t * getDDR()
Get a pointer to the DDR register.
void setInput()
Set the pin mode to input.
Pin(uint8_t number)
Arduino supported board constructor.
Pin(uint8_t number, uint8_t offset, uint8_t timer, volatile uint8_t *PIN, volatile uint8_t *PORT, volatile uint8_t *DDR)
Custom board constructor.
uint8_t getMode()
Get the mode of the pin from the DDR register.
void setState(uint8_t state)
Set the pin state.
uint8_t getTimer()
Get the pin timer.
#define DDR_TOGGLE
Set the DDR register to the inverse for the pin.
volatile unsigned int rcTimer(volatile unsigned int count)
Set the pin mode to input and decrement a counter until the pin goes HIGH or the counter reaches 0 th...