Arduino/include/bits.h

21 lines
608 B
C
Raw Normal View History

2023-10-27 15:52:40 +00:00
//
// 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)
2023-12-09 10:22:31 +00:00
// 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)
2023-10-27 15:52:40 +00:00
#endif //ARDUINO_BITS_H