// 2.1 - sets the state of the SDI-12 object. void SDI12::setState(uint8_t state){ if(state == HOLDING){ pinMode(_dataPin,OUTPUT); digitalWrite(_dataPin,LOW); *digitalPinToPCMSK(_dataPin) &= ~(1<<digitalPinToPCMSKbit(_dataPin)); return; } if(state == TRANSMITTING){ pinMode(_dataPin,OUTPUT); noInterrupts(); // supplied by Arduino.h, same as cli() return; } if(state == LISTENING) { digitalWrite(_dataPin,LOW); pinMode(_dataPin,INPUT); interrupts(); // supplied by Arduino.h, same as sei() *digitalPinToPCICR(_dataPin) |= (1<<digitalPinToPCICRbit(_dataPin)); *digitalPinToPCMSK(_dataPin) |= (1<<digitalPinToPCMSKbit(_dataPin)); } else { // implies state==DISABLED digitalWrite(_dataPin,LOW); pinMode(_dataPin,INPUT); *digitalPinToPCMSK(_dataPin) &= ~(1<<digitalPinToPCMSKbit(_dataPin)); if(!*digitalPinToPCMSK(_dataPin)){ *digitalPinToPCICR(_dataPin) &= ~(1<<digitalPinToPCICRbit(_dataPin)); } } }
void TinyPinChange_EnablePin(uint8_t Pin) { if(digitalPinToPCICR(Pin)) { *digitalPinToPCICR(Pin) |= _BV(digitalPinToPCICRbit(Pin)); *digitalPinToPCMSK(Pin) |= _BV(digitalPinToPCMSKbit(Pin)); } }
void ExpanduinoSubdeviceGpioLinuxInputArduino::begin() { for (int i=0; i<numComponents; i++) { components[i].value = 0; switch (components[i].type.type) { case EV_KEY: case EV_SW: { pinMode(components[i].pin, INPUT_PULLUP); if (digitalPinToPCICR(components[i].pin)) { PcInt::attachInterrupt(components[i].pin, pinChanged, this, CHANGE, true); } break; } case EV_ABS: { pinMode(components[i].pin, INPUT); break; } case EV_LED: case EV_SND: { pinMode(components[i].pin, OUTPUT); digitalWrite(components[i].pin, LOW); break; } } setValue(i, 0); } }
void TinyPinChange_DisablePin(uint8_t Pin) { if(digitalPinToPCICR(Pin)) { *digitalPinToPCMSK(Pin) &= (_BV(digitalPinToPCMSKbit(Pin)) ^ 0xFF); } }
// initialization void IRrecv::enableIRIn() { cli(); if (digitalPinToPCICR(irparams.recvpin)) { *digitalPinToPCICR(irparams.recvpin) |= _BV(digitalPinToPCICRbit(irparams.recvpin)); *digitalPinToPCMSK(irparams.recvpin) |= _BV(digitalPinToPCMSKbit(irparams.recvpin)); } // initialize state machine variables irparams.rcvstate = STATE_IDLE; irparams.rawlen = 0; irparams.startTime = micros(); sei(); // enable interrupts // set pin modes pinMode(irparams.recvpin, INPUT); }
// ------------------------------------------------------------------------------ // Enable soft serial RX. // ------------------------------------------------------------------------------ void gSoftSerial::listen() { rxState = 0xFF; // no start bit detected yet rxHead = rxTail = 0; // no characters in buffer uint8_t prevSREG = SREG; cli(); *digitalPinToPCMSK(rxPin) |= _BV(digitalPinToPCMSKbit(rxPin)); *digitalPinToPCICR(rxPin) |= _BV(digitalPinToPCICRbit(rxPin)); SREG = prevSREG; }
void ExpanduinoSubdeviceGpioLinuxInputArduino::end() { for (int i=0; i<numComponents; i++) { components[i].value = 0; switch (components[i].type.type) { case EV_KEY: case EV_SW: case EV_LED: if (digitalPinToPCICR(components[i].pin)) { PcInt::detachInterrupt(components[i].pin); } case EV_SND: case EV_ABS: { pinMode(components[i].pin, INPUT); break; } } setValue(i, 0); } }