pinio.h: implement PULLUP_ON() and PULLUP_OFF().

On ARM enabling the pullup on an input pin isn't done by writing
a 1 to the pin, but by setting the corresponding register.
Accordingly we need a distinct function for this.
This commit is contained in:
Markus Hitter 2015-07-24 13:36:19 +02:00
parent 45bcef395e
commit facd1ee606
1 changed files with 23 additions and 0 deletions

23
pinio.h
View File

@ -49,6 +49,11 @@
/// Set pin as output.
#define _SET_OUTPUT(IO) do { IO ## _DDR |= MASK(IO ## _PIN); } while (0)
/// Enable pullup resistor.
#define _PULLUP_ON(IO) _WRITE(IO, 1)
/// Disable pullup resistor.
#define _PULLUP_OFF(IO) _WRITE(IO, 0)
#elif defined __ARMEL__
/**
@ -84,6 +89,17 @@
IO ## _PORT->DIR |= MASK(IO ## _PIN); \
} while (0)
/// Enable pullup resistor.
#define _PULLUP_ON(IO) \
do { \
LPC_IOCON->IO ## _CMSIS = (IO ## _OUTPUT | IO_MODEMASK_PULLUP); \
} while (0)
/// Disable pullup resistor.
#define _PULLUP_OFF(IO) \
do { \
LPC_IOCON->IO ## _CMSIS = (IO ## _OUTPUT | IO_MODEMASK_INACTIVE); \
} while (0)
#elif defined SIMULATOR
#include "simulator.h"
@ -92,6 +108,8 @@
void _WRITE(pin_t pin, bool on);
void _SET_OUTPUT(pin_t pin);
void _SET_INPUT(pin_t pin);
#define _PULLUP_ON(IO) _WRITE(IO, 1)
#define _PULLUP_OFF(IO) _WRITE(IO, 0)
#endif /* __AVR__, __ARMEL__, SIMULATOR */
@ -109,6 +127,11 @@
/// Set pin as output wrapper.
#define SET_OUTPUT(IO) _SET_OUTPUT(IO)
/// Enable pullup resistor.
#define PULLUP_ON(IO) _PULLUP_ON(IO)
/// Disable pullup resistor.
#define PULLUP_OFF(IO) _PULLUP_OFF(IO)
/*
Power
*/