131 lines
2.5 KiB
C
131 lines
2.5 KiB
C
#ifndef _ARDUINO_H
|
|
#define _ARDUINO_H
|
|
|
|
#include <avr/io.h>
|
|
|
|
/*
|
|
utility functions
|
|
*/
|
|
|
|
#ifndef MASK
|
|
#define MASK(PIN) (1 << PIN)
|
|
#endif
|
|
|
|
#define _READ(IO) (RPORT_ ## IO & MASK(PIN_ ## IO))
|
|
#define _WRITE(IO, v) if (v) { WPORT_ ## IO |= MASK(PIN_ ## IO); } else { WPORT_ ## IO &= ~MASK(PIN_ ## IO); }
|
|
|
|
#define _SET_INPUT(IO) (DDR_ ## IO |= MASK(PIN_ ## IO))
|
|
#define _SET_OUTPUT(IO) (DDR_ ## IO &= ~MASK(PIN_ ## IO))
|
|
|
|
// why double up on macros? see http://gcc.gnu.org/onlinedocs/cpp/Stringification.html
|
|
|
|
#define READ(IO) _READ(IO)
|
|
#define WRITE(IO, v) _WRITE(IO, v)
|
|
#define SET_INPUT(IO) _SET_INPUT(IO)
|
|
#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
|
|
|
|
/*
|
|
pins
|
|
*/
|
|
|
|
#define PIN_DIO0 PD0
|
|
#define RPORT_DIO0 PIND
|
|
#define WPORT_DIO0 PORTD
|
|
#define DDR_DIO0 DDRD
|
|
|
|
#define PIN_DIO1 PD1
|
|
#define RPORT_DIO1 PIND
|
|
#define WPORT_DIO1 PORTD
|
|
#define DDR_DIO1 DDRD
|
|
|
|
#define PIN_DIO2 PD2
|
|
#define RPORT_DIO2 PIND
|
|
#define WPORT_DIO2 PORTD
|
|
#define DDR_DIO2 DDRD
|
|
|
|
#define PIN_DIO3 PD3
|
|
#define RPORT_DIO3 PIND
|
|
#define WPORT_DIO3 PORTD
|
|
#define DDR_DIO3 DDRD
|
|
|
|
#define PIN_DIO4 PD4
|
|
#define RPORT_DIO4 PIND
|
|
#define WPORT_DIO4 PORTD
|
|
#define DDR_DIO4 DDRD
|
|
|
|
#define PIN_DIO5 PD5
|
|
#define RPORT_DIO5 PIND
|
|
#define WPORT_DIO5 PORTD
|
|
#define DDR_DIO5 DDRD
|
|
|
|
#define PIN_DIO6 PD6
|
|
#define RPORT_DIO6 PIND
|
|
#define WPORT_DIO6 PORTD
|
|
#define DDR_DIO6 DDRD
|
|
|
|
#define PIN_DIO7 PD7
|
|
#define RPORT_DIO7 PIND
|
|
#define WPORT_DIO7 PORTD
|
|
#define DDR_DIO7 DDRD
|
|
|
|
#define PIN_DIO8 PB0
|
|
#define RPORT_DIO8 PINB
|
|
#define WPORT_DIO8 PORTB
|
|
#define DDR_DIO8 DDRB
|
|
|
|
#define PIN_DIO9 PB1
|
|
#define RPORT_DIO9 PINB
|
|
#define WPORT_DIO9 PORTB
|
|
#define DDR_DIO9 DDRB
|
|
|
|
#define PIN_DIO10 PB2
|
|
#define RPORT_DIO10 PINB
|
|
#define WPORT_DIO10 PORTB
|
|
#define DDR_DIO10 DDRB
|
|
|
|
#define PIN_DIO11 PB3
|
|
#define RPORT_DIO11 PINB
|
|
#define WPORT_DIO11 PORTB
|
|
#define DDR_DIO11 DDRB
|
|
|
|
#define PIN_DIO12 PB4
|
|
#define RPORT_DIO12 PINB
|
|
#define WPORT_DIO12 PORTB
|
|
#define DDR_DIO12 DDRB
|
|
|
|
#define PIN_DIO13 PB5
|
|
#define RPORT_DIO13 PINB
|
|
#define WPORT_DIO13 PORTB
|
|
#define DDR_DIO13 DDRB
|
|
|
|
#define PIN_AIO0 PC0
|
|
#define RPORT_AIO0 PINC
|
|
#define WPORT_AIO0 PORTC
|
|
#define DDR_AIO0 DDRC
|
|
|
|
#define PIN_AIO1 PC1
|
|
#define RPORT_AIO1 PINC
|
|
#define WPORT_AIO1 PORTC
|
|
#define DDR_AIO1 DDRC
|
|
|
|
#define PIN_AIO2 PC2
|
|
#define RPORT_AIO2 PINC
|
|
#define WPORT_AIO2 PORTC
|
|
#define DDR_AIO2 DDRC
|
|
|
|
#define PIN_AIO3 PC3
|
|
#define RPORT_AIO3 PINC
|
|
#define WPORT_AIO3 PORTC
|
|
#define DDR_AIO3 DDRC
|
|
|
|
#define PIN_AIO4 PC4
|
|
#define RPORT_AIO4 PINC
|
|
#define WPORT_AIO4 PORTC
|
|
#define DDR_AIO4 DDRC
|
|
|
|
#define PIN_AIO5 PC5
|
|
#define RPORT_AIO5 PINC
|
|
#define WPORT_AIO5 PORTC
|
|
#define DDR_AIO5 DDRC
|
|
|
|
#endif /* _ARDUINO_H */ |