From aed6f5a14b286ebf94cfa79a112b558eac15cab3 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Sat, 25 Jun 2016 21:30:18 +0200 Subject: [PATCH] pinio.h: support pulldown resistors. These are ARM only, because ATmegas have no such feature. --- pinio.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/pinio.h b/pinio.h index d5d4d96..fa8c0e2 100644 --- a/pinio.h +++ b/pinio.h @@ -51,6 +51,8 @@ /// Enable pullup resistor. #define _PULLUP_ON(IO) _WRITE(IO, 1) + /// No such feature on ATmegas. + #define _PULLDOWN_ON(IO) atmegas_dont_support_pulldown_resistors() /// Disable pullup resistor. #define _PULL_OFF(IO) _WRITE(IO, 0) @@ -89,11 +91,16 @@ IO ## _PORT->DIR |= MASK(IO ## _PIN); \ } while (0) - /// Enable pullup resistor. + /// Enable pullup resistor or switch from pulldown to pullup. #define _PULLUP_ON(IO) \ do { \ LPC_IOCON->IO ## _CMSIS = (IO ## _OUTPUT | IO_MODEMASK_PULLUP); \ } while (0) + /// Enable pulldown resistor or switch from pullup to pulldown. + #define _PULLDOWN_ON(IO) \ + do { \ + LPC_IOCON->IO ## _CMSIS = (IO ## _OUTPUT | IO_MODEMASK_PULLDOWN); \ + } while (0) /// Disable pull resistor. #define _PULL_OFF(IO) \ do { \ @@ -127,8 +134,10 @@ /// Set pin as output wrapper. #define SET_OUTPUT(IO) _SET_OUTPUT(IO) -/// Enable pullup resistor. +/// Enable pullup resistor or switch from pulldown to pullup. #define PULLUP_ON(IO) _PULLUP_ON(IO) +/// Enable pulldown resistor or switch from pullup to pulldown. +#define PULLDOWN_ON(IO) _PULLDOWN_ON(IO) /// Disable pull resistor. #define PULL_OFF(IO) _PULL_OFF(IO)