void PCF8574::pinMode(uint8_t pin, uint8_t mode) { /* Switch according mode */ switch (mode) { case INPUT: _DDR &= ~(1 << pin); _PORT &= ~(1 << pin); break; case INPUT_PULLUP: _DDR &= ~(1 << pin); _PORT |= (1 << pin); break; case OUTPUT: _DDR |= (1 << pin); _PORT &= ~(1 << pin); break; default: break; } /* Update GPIO values */ updateGPIO(); }
void PCF8574::write(uint8_t value) { /* Store pins values and apply */ _PORT = value; /* Update GPIO values */ updateGPIO(); }
void PCF8574::toggle(uint8_t pin) { /* Toggle pin state */ _PORT ^= (1 << pin); /* Update GPIO values */ updateGPIO(); }
void I2C_4DI4RO::begin(uint8_t address) { _address = address + 0x20; Wire.begin(); readGPIO(); _DDR = 0b11110000; _PORT = 0b11111111; updateGPIO(); lastCommandOK = false; }
void KEYS::digitalWrite(uint32_t pin, uint8_t value) { if(value) bitSet(_PORT, pin); else bitClear(_PORT, pin); updateGPIO(); }
void PCF8574::digitalWrite(uint8_t pin, uint8_t value) { /* Set PORT bit value */ if (value) _PORT |= (1 << pin); else _PORT &= ~(1 << pin); /* Update GPIO values */ updateGPIO(); }
void I2C_4DI4RO::relayWrite(uint8_t pin, uint8_t value) { pin += 3; /* Set PORT bit value */ if (value) _PORT &= ~(1 << pin); else _PORT |= (1 << pin); /* Update GPIO values */ lastCommandOK = false; updateGPIO(); if(dinRead(pin+3) == value) lastCommandOK = true; }
void KEYS::pinMode(uint32_t pin, uint8_t mode) { uint32_t pullUp, dbc; readGPIO(); switch(mode) { case INPUT: bitClear(_PORT, pin); bitClear(_DDR, pin); bitClear(_PKG, pin); bitSet(_PUR, pin); break; case INPUT_PULLUP: bitClear(_PORT, pin); bitClear(_DDR, pin); bitClear(_PKG, pin); bitClear(_PUR, pin); break; case OUTPUT: bitClear(_PORT, pin); bitSet(_DDR, pin); bitClear(_PKG, pin); bitSet(_PUR, pin); break; case KEYPAD: bitClear(_PORT, pin); bitClear(_DDR, pin); bitSet(_PKG, pin); bitClear(_PUR, pin); break; case DEBOUNCE: read3Bytes((uint32_t *)&dbc, REG_DEBOUNCE_DIS1); bitClear(dbc, pin); write3Bytes((uint32_t)dbc, REG_DEBOUNCE_DIS1); break; case NODEBOUNCE: read3Bytes((uint32_t *)&dbc, REG_DEBOUNCE_DIS1); bitSet(dbc, pin); write3Bytes((uint32_t)dbc, REG_DEBOUNCE_DIS1); break; default: break; } updateGPIO(); }
/**************************************************************************//** * @brief Main function *****************************************************************************/ int main(void) { CHIP_Init(); // initializations initGPIO(); /* Enable LCD without voltage boost */ SegmentLCD_Init(false); setupSWOForPrint(); updateLCD(getCapsenseCurrent()); while (1) { updateGPIO(); if (getCapsensePrevious() != getCapsenseCurrent()) { updateLCD(getCapsenseCurrent()); updateSWO(); } } }
void KEYS::toggle(uint32_t pin) { _PORT ^= (bit(pin)); updateGPIO(); }
void KEYS::write(uint32_t value) { _PORT = value; updateGPIO(); }