Arduino/include/bits.h

21 lines
608 B
C

//
// Created by servostar on 27.10.23.
//
#ifndef ARDUINO_BITS_H
#define ARDUINO_BITS_H
#define SET_BIT(field, idx) ((field) |= (1 << (idx)))
#define CLR_BIT(field, idx) ((field) &= ~(1 << (idx)))
#define TOG_BIT(field, idx) ((field) ^= (1 << (idx)))
#define GET_BIT(field, idx) (((field) >> idx) & 0x1)
#define SET_OUTPUT(port, pin) SET_BIT(port, pin)
#define SET_INPUT(port, pin) CLR_BIT(port, pin)
// makes pin 4 of port B a pull up resistor
// example: PULL_UP_RESISTOR(DDRB, PORTB, DDB4)
#define PULL_UP_RESISTOR(port, output, pin) CLR_BIT(port, pin); SET_BIT(output, pin)
#endif //ARDUINO_BITS_H