/** * pinModeIRQ * * pin - arduino pin * mode - one of the modes defined for arudino IRQs LOW , CHANGE, RISING, FALLING, HIGH */ int pinModeIRQ(uint8_t pin, int8_t mode) { int ret = 0; uint32_t gpio = 0; ret = variantPinModeIRQ(pin, mode); if (ret) { trace_error("%s: variantPinMode failed\n", __func__); return ret; } gpio = pin2gpio(pin); if (gpio == PIN_EINVAL){ trace_error("%s: pin %d out of range (gpio%d)", __func__, pin, gpio); return gpio; } ret = muxSelectDigitalPin(pin); if (ret) { trace_error("%s: can't set mux for pin%d\n", __func__, pin); return ret; } trace_debug("%s: pin=%d, gpio=%d, mode=%d", __func__, pin, gpio, mode); // Now set the mode for IRQ granularity switch (mode) { case NONE: case CHANGE: case RISING: case FALLING: ret = sysfsGpioEdgeConfig(gpio, mode); break; case LOW: case HIGH: // Implies edge config none ret = sysfsGpioEdgeConfig(gpio, NONE); if ( ret < 0 ) break; // Set to active high or active low ret = sysfsGpioLevelConfig(gpio, mode); break; default: ret = PIN_EINVAL; break; } return ret; }
void SPIClass::begin() { /* Set the pin mux, for the SCK, MOSI and MISO pins ONLY * * Leave the SS pin in GPIO mode (the application will control it) * but set it's direction to output and initially high */ muxSelectDigitalPin(SPI_SS_GPIO_PIN); pinMode(SPI_SS_GPIO_PIN, OUTPUT); digitalWrite(SPI_SS_GPIO_PIN, HIGH); muxSelectSpi(1); this->fd = open(LINUX_SPIDEV, O_RDWR); if (this->fd < 0) { trace_error("Failed to open SPI device\n"); return; } /* Load default/last configuration */ this->setBitOrder(this->bitOrder); this->setClockDivider(this->clkDiv); this->setDataMode(this->mode); }