2021-08-08 21:03:25 +03:00
|
|
|
#include <furi-hal-spi-config.h>
|
|
|
|
#include <furi-hal-resources.h>
|
2021-05-18 12:23:14 +03:00
|
|
|
|
|
|
|
extern SPI_HandleTypeDef SPI_R;
|
|
|
|
extern SPI_HandleTypeDef SPI_D;
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
const SPI_InitTypeDef furi_hal_spi_config_nfc = {
|
2021-05-18 12:23:14 +03:00
|
|
|
.Mode = SPI_MODE_MASTER,
|
|
|
|
.Direction = SPI_DIRECTION_2LINES,
|
|
|
|
.DataSize = SPI_DATASIZE_8BIT,
|
|
|
|
.CLKPolarity = SPI_POLARITY_LOW,
|
|
|
|
.CLKPhase = SPI_PHASE_2EDGE,
|
|
|
|
.NSS = SPI_NSS_SOFT,
|
|
|
|
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8,
|
|
|
|
.FirstBit = SPI_FIRSTBIT_MSB,
|
|
|
|
.TIMode = SPI_TIMODE_DISABLE,
|
|
|
|
.CRCCalculation = SPI_CRCCALCULATION_DISABLE,
|
|
|
|
.CRCPolynomial = 7,
|
|
|
|
.CRCLength = SPI_CRC_LENGTH_DATASIZE,
|
|
|
|
.NSSPMode = SPI_NSS_PULSE_DISABLE,
|
|
|
|
};
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
const SPI_InitTypeDef furi_hal_spi_config_subghz = {
|
2021-05-18 12:23:14 +03:00
|
|
|
.Mode = SPI_MODE_MASTER,
|
|
|
|
.Direction = SPI_DIRECTION_2LINES,
|
|
|
|
.DataSize = SPI_DATASIZE_8BIT,
|
|
|
|
.CLKPolarity = SPI_POLARITY_LOW,
|
|
|
|
.CLKPhase = SPI_PHASE_1EDGE,
|
|
|
|
.NSS = SPI_NSS_SOFT,
|
|
|
|
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8,
|
|
|
|
.FirstBit = SPI_FIRSTBIT_MSB,
|
|
|
|
.TIMode = SPI_TIMODE_DISABLE,
|
|
|
|
.CRCCalculation = SPI_CRCCALCULATION_DISABLE,
|
|
|
|
.CRCPolynomial = 7,
|
|
|
|
.CRCLength = SPI_CRC_LENGTH_DATASIZE,
|
|
|
|
.NSSPMode = SPI_NSS_PULSE_DISABLE,
|
|
|
|
};
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
const SPI_InitTypeDef furi_hal_spi_config_display = {
|
2021-05-18 12:23:14 +03:00
|
|
|
.Mode = SPI_MODE_MASTER,
|
|
|
|
.Direction = SPI_DIRECTION_2LINES,
|
|
|
|
.DataSize = SPI_DATASIZE_8BIT,
|
|
|
|
.CLKPolarity = SPI_POLARITY_LOW,
|
|
|
|
.CLKPhase = SPI_PHASE_1EDGE,
|
|
|
|
.NSS = SPI_NSS_SOFT,
|
|
|
|
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16,
|
|
|
|
.FirstBit = SPI_FIRSTBIT_MSB,
|
|
|
|
.TIMode = SPI_TIMODE_DISABLE,
|
|
|
|
.CRCCalculation = SPI_CRCCALCULATION_DISABLE,
|
|
|
|
.CRCPolynomial = 7,
|
|
|
|
.CRCLength = SPI_CRC_LENGTH_DATASIZE,
|
|
|
|
.NSSPMode = SPI_NSS_PULSE_ENABLE,
|
|
|
|
};
|
|
|
|
|
2021-05-26 18:42:12 +03:00
|
|
|
/**
|
|
|
|
* SD Card in fast mode (after init)
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
const SPI_InitTypeDef furi_hal_spi_config_sd_fast = {
|
2021-05-26 18:42:12 +03:00
|
|
|
.Mode = SPI_MODE_MASTER,
|
|
|
|
.Direction = SPI_DIRECTION_2LINES,
|
|
|
|
.DataSize = SPI_DATASIZE_8BIT,
|
|
|
|
.CLKPolarity = SPI_POLARITY_LOW,
|
|
|
|
.CLKPhase = SPI_PHASE_1EDGE,
|
|
|
|
.NSS = SPI_NSS_SOFT,
|
|
|
|
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2,
|
|
|
|
.FirstBit = SPI_FIRSTBIT_MSB,
|
|
|
|
.TIMode = SPI_TIMODE_DISABLE,
|
|
|
|
.CRCCalculation = SPI_CRCCALCULATION_DISABLE,
|
|
|
|
.CRCPolynomial = 7,
|
|
|
|
.CRCLength = SPI_CRC_LENGTH_DATASIZE,
|
|
|
|
.NSSPMode = SPI_NSS_PULSE_ENABLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* SD Card in slow mode (before init)
|
|
|
|
*/
|
2021-08-08 21:03:25 +03:00
|
|
|
const SPI_InitTypeDef furi_hal_spi_config_sd_slow = {
|
2021-05-26 18:42:12 +03:00
|
|
|
.Mode = SPI_MODE_MASTER,
|
|
|
|
.Direction = SPI_DIRECTION_2LINES,
|
|
|
|
.DataSize = SPI_DATASIZE_8BIT,
|
|
|
|
.CLKPolarity = SPI_POLARITY_LOW,
|
|
|
|
.CLKPhase = SPI_PHASE_1EDGE,
|
|
|
|
.NSS = SPI_NSS_SOFT,
|
|
|
|
.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32,
|
|
|
|
.FirstBit = SPI_FIRSTBIT_MSB,
|
|
|
|
.TIMode = SPI_TIMODE_DISABLE,
|
|
|
|
.CRCCalculation = SPI_CRCCALCULATION_DISABLE,
|
|
|
|
.CRCPolynomial = 7,
|
|
|
|
.CRCLength = SPI_CRC_LENGTH_DATASIZE,
|
|
|
|
.NSSPMode = SPI_NSS_PULSE_ENABLE,
|
|
|
|
};
|
|
|
|
|
2021-05-18 12:23:14 +03:00
|
|
|
osMutexId_t spi_mutex_d = NULL;
|
|
|
|
osMutexId_t spi_mutex_r = NULL;
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
const FuriHalSpiBus spi_r = {
|
2021-05-18 12:23:14 +03:00
|
|
|
.spi=&SPI_R,
|
|
|
|
.mutex=&spi_mutex_r,
|
|
|
|
.miso=&gpio_spi_r_miso,
|
|
|
|
.mosi=&gpio_spi_r_mosi,
|
|
|
|
.clk=&gpio_spi_r_sck,
|
|
|
|
};
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
const FuriHalSpiBus spi_d = {
|
2021-05-18 12:23:14 +03:00
|
|
|
.spi=&SPI_D,
|
|
|
|
.mutex=&spi_mutex_d,
|
|
|
|
.miso=&gpio_spi_d_miso,
|
|
|
|
.mosi=&gpio_spi_d_mosi,
|
|
|
|
.clk=&gpio_spi_d_sck,
|
|
|
|
};
|
|
|
|
|
2021-08-08 21:03:25 +03:00
|
|
|
const FuriHalSpiDevice furi_hal_spi_devices[FuriHalSpiDeviceIdMax] = {
|
|
|
|
{ .bus=&spi_r, .config=&furi_hal_spi_config_subghz, .chip_select=&gpio_subghz_cs, },
|
|
|
|
{ .bus=&spi_d, .config=&furi_hal_spi_config_display, .chip_select=&gpio_display_cs, },
|
|
|
|
{ .bus=&spi_d, .config=&furi_hal_spi_config_sd_fast, .chip_select=&gpio_sdcard_cs, },
|
|
|
|
{ .bus=&spi_d, .config=&furi_hal_spi_config_sd_slow, .chip_select=&gpio_sdcard_cs, },
|
|
|
|
{ .bus=&spi_r, .config=&furi_hal_spi_config_nfc, .chip_select=&gpio_nfc_cs },
|
2021-05-18 12:23:14 +03:00
|
|
|
};
|