diff --git a/IODevice.cpp b/IODevice.cpp index 63a6d8b..b61ecf8 100644 --- a/IODevice.cpp +++ b/IODevice.cpp @@ -305,18 +305,16 @@ bool IODevice::owns(VPIN id) { // Minimal implementations of public HAL interface, to support Arduino pin I/O and nothing more. void IODevice::begin() { DIAG(F("NO HAL CONFIGURED!")); } -bool IODevice::configure(VPIN pin, ConfigTypeEnum, int, int p[]) { +bool IODevice::configure(VPIN pin, ConfigTypeEnum configType, int nParams, int p[]) { + if (configType!=CONFIGURE_INPUT || nParams!=1 || pin >= NUM_DIGITAL_PINS) return false; #ifdef DIAG_IO DIAG(F("Arduino _configurePullup Pin:%d Val:%d"), pin, p[0]); #endif - if (p[0]) { - pinMode(pin, INPUT_PULLUP); - } else { - pinMode(pin, INPUT); - } + pinMode(pin, p[0] ? INPUT_PULLUP : INPUT); return true; } void IODevice::write(VPIN vpin, int value) { + if (vpin >= NUM_DIGITAL_PINS) return; digitalWrite(vpin, value); pinMode(vpin, OUTPUT); } @@ -324,6 +322,7 @@ void IODevice::writeAnalogue(VPIN, int, uint8_t, uint16_t) {} bool IODevice::isBusy(VPIN) { return false; } bool IODevice::hasCallback(VPIN) { return false; } int IODevice::read(VPIN vpin) { + if (vpin >= NUM_DIGITAL_PINS) return 0; return !digitalRead(vpin); // Return inverted state (5v=0, 0v=1) } int IODevice::readAnalogue(VPIN vpin) {