/* * mjo-pin.h * * Experimental macros for I/O port manipulation * * usage: * SINGLE_PIN(foo, C, 3); * * foo_set_low(); * foo_init_read(); * ... * * Copyright 2014, Martin Oldfield * * See http://mjoldfield.com/atelier/2014/05/pin-macros.html * * Permission to use, copy, modify, and/or distribute this software for * any purpose with or without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS * SOFTWARE. */ #ifndef _MJOPIN_H_ #define _MJOPIN_H_ #define SINGLE_PIN(NAME,BANK,BIT) \ static inline void NAME ## _set_low (void) __attribute__((always_inline)); \ static inline void NAME ## _set_low (void) { PORT ## BANK &= ~(_BV(PORT ## BANK ## BIT)); } \ static inline void NAME ## _set_high (void) __attribute__((always_inline)); \ static inline void NAME ## _set_high (void) { PORT ## BANK |= (_BV(PORT ## BANK ## BIT)); } \ static inline void NAME ## _set(uint8_t) __attribute__((always_inline)); \ static inline void NAME ## _set(uint8_t x) { if (x) { NAME ## _set_high(); } else { NAME ## _set_low(); } } \ static inline void NAME ## _init_liwrite (void) __attribute__((always_inline)); \ static inline void NAME ## _init_write (void) { DDR ## BANK |= (_BV(PORT ## BANK ## BIT)); } \ static inline uint8_t NAME ## _get (void) __attribute__((always_inline)); \ static inline uint8_t NAME ## _get (void) { return PIN ## BANK & (_BV(PORT ## BANK ## BIT)); } \ static inline void NAME ## _init_read (void) __attribute__((always_inline)); \ static inline void NAME ## _init_read (void) { DDR ## BANK &= ~(_BV(PORT ## BANK ## BIT)); } #endif