Ejemplo n.º 1
0
  Spi Gpio::allocateSpi() {
    std::lock_guard<std::mutex> lock(mutex_);

    if (::demo::isVerbose) {
      std::cout << "Allocating SPI pins" << std::endl;
    }

    // The pin number is reduced by 2 as the GPIO pins range from 2 to 27, but the array's indices range from 0 to 25.
    if (ownedPins_.at(5) || ownedPins_.at(6) || ownedPins_.at(7) || ownedPins_.at(8) || ownedPins_.at(9)) {
      throw std::runtime_error("The SPI pins must not already be allocated");
    }

    // The pin number is reduced by 2 as the GPIO pins range from 2 to 27, but the array's indices range from 0 to 25.
    ownedPins_.at(5) = true;
    ownedPins_.at(6) = true;
    ownedPins_.at(7) = true;
    ownedPins_.at(8) = true;
    ownedPins_.at(9) = true;

    return Spi();
  }
Ejemplo n.º 2
0
int main() {
	auto ledStripG = GpioB[5];
	DmaStream dma(2, 3, 3);
	auto ledStripS = Spi(1, &dma);
	//auto ledStripS = Spi(1);
	LedStrip ledStrip(ledStripS);

	ledStripG
		.setPushPull()
		.setDirection(Gpio::OUTPUT)
		.setSpeed(Gpio::SPEED_100MHz);

	ledStripG = false;
	time.msleep(2);
	ledStripG = true;
	time.msleep(2);
	ledStripG = false;
	time.msleep(2);
	ledStripG = true;
	ledStripS.configGpio(ledStripG);
	time.msleep(4);

	int l = 0;
	while(1) {
		for(int i=0; i<71; ++i) {
			if(l==i)
				ledStrip.push(0, 255, 0);
			else
				ledStrip.push(6, 0, 0);
		}
		ledStrip.push(0, 0, 0);

		l++;
		l %= 72;
		ledStrip.reset();
		//time.msleep(200);
	}
}