2 atmega168_timer_64led.h
4 Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
6 This file is part of simavr.
8 simavr is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 simavr is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with simavr. If not, see <http://www.gnu.org/licenses/>.
25 #include <util/delay.h>
30 static inline void delay_ms(uint16_t millis)
37 #include <avr/pgmspace.h>
39 #define printf(format, ...) printf_P(PSTR(format), ## __VA_ARGS__)
40 #define sprintf(wh, format, ...) sprintf_P(wh, PSTR(format), ## __VA_ARGS__)
44 given a pin name, port, bit number and mask (how many bits it takes) this macro
45 defines a set of inline accessors to set/clear/read the pin
47 #define PIN_DEFINE(__name, __port, __pin, __mask) \
48 enum { __name##_PIN = (__pin), __name##_MASK = (__mask << __pin) }; \
49 /* toggle pin in PORT */static inline void TOG_##__name() { PIN##__port ^= __mask << __pin; } \
50 /* Clear Pin */ static inline void CLR_##__name() { PORT##__port &= ~(__mask << __pin); } \
51 /* Set pin to 1 */ static inline void SET_##__name() { PORT##__port |= (__mask << __pin); } \
52 /* Set pin to 0/1 */ static inline void SET_##__name##_V(uint8_t __val) { PORT##__port = (PORT##__port & ~(__mask << __pin)) | (__val << __pin); } \
53 /* Get pin value */ static inline uint8_t GET##__name() { return (PIN##__port >> __pin) & __mask; } \
54 /* Set pin direction */ static inline void DDR_##__name(uint8_t __val) { DDR##__port = (DDR##__port & ~(__mask << __pin)) | (__val << __pin); }
62 #endif // __COMMON_H__