Pulldown pin mode support (#9701)

Implemented for LPC1768.
This commit is contained in:
Scott Lahteine
2018-02-18 19:26:23 -06:00
committed by GitHub
parent aef9e036bf
commit ca55f2927a
66 changed files with 1182 additions and 325 deletions

View File

@ -71,7 +71,7 @@ extern "C" void delay(const int msec) {
// IO functions
// As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2)
void pinMode(pin_t pin, uint8_t mode) {
void pinMode(const pin_t pin, const uint8_t mode) {
if (!VALID_PIN(pin)) return;
PINSEL_CFG_Type config = { LPC1768_PIN_PORT(pin),
@ -79,23 +79,24 @@ void pinMode(pin_t pin, uint8_t mode) {
PINSEL_FUNC_0,
PINSEL_PINMODE_TRISTATE,
PINSEL_PINMODE_NORMAL };
switch(mode) {
case INPUT:
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin));
PINSEL_ConfigPin(&config);
break;
case OUTPUT:
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR |= LPC_PIN(LPC1768_PIN_PIN(pin));
PINSEL_ConfigPin(&config);
break;
case INPUT_PULLUP:
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin));
config.Pinmode = PINSEL_PINMODE_PULLUP;
PINSEL_ConfigPin(&config);
break;
default:
break;
switch (mode) {
case INPUT:
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin));
break;
case OUTPUT:
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR |= LPC_PIN(LPC1768_PIN_PIN(pin));
break;
case INPUT_PULLUP:
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin));
config.Pinmode = PINSEL_PINMODE_PULLUP;
break;
case INPUT_PULLDOWN:
LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin));
config.Pinmode = PINSEL_PINMODE_PULLDOWN;
break;
default: return;
}
PINSEL_ConfigPin(&config);
}
void digitalWrite(pin_t pin, uint8_t pin_status) {
@ -108,13 +109,13 @@ void digitalWrite(pin_t pin, uint8_t pin_status) {
pinMode(pin, OUTPUT); // Set pin mode on every write (Arduino version does this)
/**
* Must be done AFTER the output state is set. Doing this before will cause a
* 2uS glitch if writing a "1".
*
* When the Port Direction bit is written to a "1" the output is immediately set
* to the value of the FIOPIN bit which is "0" because of power up defaults.
*/
/**
* Must be done AFTER the output state is set. Doing this before will cause a
* 2uS glitch if writing a "1".
*
* When the Port Direction bit is written to a "1" the output is immediately set
* to the value of the FIOPIN bit which is "0" because of power up defaults.
*/
}
bool digitalRead(pin_t pin) {

View File

@ -85,6 +85,9 @@ bool useable_hardware_PWM(pin_t pin);
/// set pin as input with pullup mode
#define _PULLUP(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLUP : INPUT)))
/// set pin as input with pulldown mode
#define _PULLDOWN(IO, v) (pinMode(IO, (v!=LOW ? INPUT_PULLDOWN : INPUT)))
// hg42: all pins can be input or output (I hope)
// hg42: undefined pins create compile error (IO, is no pin)
// hg42: currently not used, but was used by pinsDebug
@ -119,6 +122,8 @@ bool useable_hardware_PWM(pin_t pin);
#define SET_INPUT(IO) _SET_INPUT(IO)
/// set pin as input with pullup wrapper
#define SET_INPUT_PULLUP(IO) do{ _SET_INPUT(IO); _PULLUP(IO, HIGH); }while(0)
/// set pin as input with pulldown wrapper
#define SET_INPUT_PULLDOWN(IO) do{ _SET_INPUT(IO); _PULLDOWN(IO, HIGH); }while(0)
/// set pin as output wrapper - reads the pin and sets the output to that value
#define SET_OUTPUT(IO) do{ _WRITE(IO, _READ(IO)); _SET_OUTPUT(IO); }while(0)

View File

@ -31,9 +31,10 @@
#define HIGH 0x01
#define LOW 0x00
#define INPUT 0x00
#define OUTPUT 0x01
#define INPUT_PULLUP 0x02
#define INPUT 0x00
#define OUTPUT 0x01
#define INPUT_PULLUP 0x02
#define INPUT_PULLDOWN 0x03
#define LSBFIRST 0
#define MSBFIRST 1
@ -104,7 +105,7 @@ void delayMicroseconds(unsigned long);
uint32_t millis();
//IO functions
void pinMode(pin_t, uint8_t);
void pinMode(const pin_t, const uint8_t);
void digitalWrite(pin_t, uint8_t);
bool digitalRead(pin_t);
void analogWrite(pin_t, int);