bool spi_init(struct spi_bus *bus) { #ifdef DEBUG_LED /* Grab a debug LED for testing. */ pin_enable(DEBUG_LED); pin_reset(DEBUG_LED); pin_set_mode(DEBUG_LED, PIN_MODE_OUTPUT); pin_set_otype(DEBUG_LED, PIN_TYPE_PUSHPULL); pin_set_ospeed(DEBUG_LED, PIN_SPEED_2MHZ); #endif #ifdef ERROR_LED pin_enable(ERROR_LED); pin_reset(ERROR_LED); pin_set_mode(ERROR_LED, PIN_MODE_OUTPUT); pin_set_otype(ERROR_LED, PIN_TYPE_PUSHPULL); pin_set_ospeed(ERROR_LED, PIN_SPEED_2MHZ); #endif rcc_enable(bus->rcc_dev); /* Configure GPIO pins for SPI operation. */ pin_enable(bus->miso_pin); pin_set_af(bus->miso_pin, bus->af); pin_set_mode(bus->miso_pin, PIN_MODE_AF); pin_set_pupd(bus->miso_pin, PIN_PUPD_NONE); pin_enable(bus->mosi_pin); pin_set_af(bus->mosi_pin, bus->af); pin_set_mode(bus->mosi_pin, PIN_MODE_AF); pin_set_otype(bus->mosi_pin, PIN_TYPE_PUSHPULL); pin_enable(bus->sck_pin); pin_set_af(bus->sck_pin, bus->af); pin_set_mode(bus->sck_pin, PIN_MODE_AF); pin_set_otype(bus->sck_pin, PIN_TYPE_PUSHPULL); bus->lock = xSemaphoreCreateMutex(); if (bus->lock == NULL) goto fail; vSemaphoreCreateBinary(bus->complete); if (bus->complete == NULL) goto fail; /* Take the semaphore initially so we will block next time. */ xSemaphoreTake(bus->complete, portMAX_DELAY); interrupt_set_priority(bus->irq, INTERRUPT_PRIORITY_FREERTOS_SAFE); return true; fail: if (bus->lock != NULL) vSemaphoreDelete(bus->lock); if (bus->complete != NULL) vSemaphoreDelete(bus->complete); return false; }
static void led_pin_setup(struct pin *pin) { pin_enable(pin); pin_set_mode(pin, PIN_MODE_OUTPUT); pin_set_otype(pin, PIN_TYPE_PUSHPULL); pin_set_ospeed(pin, PIN_SPEED_2MHZ); pin_set_pupd(pin, PIN_PUPD_NONE); pin_reset(pin); }
void spi_device_init(struct spi_device *device) { pin_enable(device->chip_select); spi_device_deselect(device); pin_set_mode(device->chip_select, PIN_MODE_OUTPUT); pin_set_otype(device->chip_select, PIN_TYPE_PUSHPULL); pin_set_ospeed(device->chip_select, PIN_SPEED_2MHZ); }