Exemplo n.º 1
0
/*
 * Apply device specific configuration of SPI controller
 */
static void ad_spi_bus_apply_config(spi_device_config *device)
{
        const HW_SPI_ID id = ad_spi_get_hw_spi_id(device);

        current_config[id == HW_SPI1 ? 0 : 1] = device;
        device->bus_data->current_device = device;

        hw_spi_init(id, &device->hw_init);
}
Exemplo n.º 2
0
// Constructor for hardware SPI -- must connect to MOSI, SCK pins
Adafruit_DotStar::Adafruit_DotStar(uint16_t n, uint8_t o) :
 numLEDs(n), dataPin(USE_HW_SPI), brightness(0), pixels(NULL),
 rOffset(o & 3), gOffset((o >> 2) & 3), bOffset((o >> 4) & 3)
{
  updateLength(n);
}

// Constructor for 'soft' (bitbang) SPI -- any two pins can be used
Adafruit_DotStar::Adafruit_DotStar(uint16_t n, uint8_t data, uint8_t clock,
  uint8_t o) :
 dataPin(data), clockPin(clock), brightness(0), pixels(NULL),
 rOffset(o & 3), gOffset((o >> 2) & 3), bOffset((o >> 4) & 3)
{
  updateLength(n);
}

Adafruit_DotStar::~Adafruit_DotStar(void) { // Destructor
  if(pixels)                free(pixels);
  if(dataPin == USE_HW_SPI) hw_spi_end();
  else                      sw_spi_end();
}

void Adafruit_DotStar::begin(void) { // Initialize SPI
  if(dataPin == USE_HW_SPI) hw_spi_init();
  else                      sw_spi_init();
}

// Pins may be reassigned post-begin(), so a sketch can store hardware
// config in flash, SD card, etc. rather than hardcoded.  Also permits
// "recycling" LED ram across multiple strips: set pins to first strip,
// render & write all data, reassign pins to next strip, render & write,
// etc.  They won't update simultaneously, but usually unnoticeable.

// Change to hardware SPI -- must connect to MOSI, SCK pins
void Adafruit_DotStar::updatePins(void) {
  sw_spi_end();
  dataPin = USE_HW_SPI;
  hw_spi_init();
}
Exemplo n.º 3
0
void hw_init(void)
{
    gpio_rs_fd = sysfs_gpio_open("out", GPIO_RS_PIN);
    if(gpio_rs_fd < 0) {
	fprintf(stderr, "Error: hw_gpio_init(GPIO_RS_PIN)\n");
	exit(1);
    }

    spi_fd = hw_spi_init();
    if(spi_fd < 0) {
	fprintf(stderr, "Error: hw_spi_init()\n");
	exit(1);
    }
}
Exemplo n.º 4
0
static void bus_spi_open(void)
{
    hw_spi_init();
}