furi-hal-spi-config.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #include <furi-hal-spi-config.h>
  2. #include <furi-hal-resources.h>
  3. #define SPI_R SPI1
  4. #define SPI_D SPI2
  5. const LL_SPI_InitTypeDef furi_hal_spi_config_nfc = {
  6. .Mode = LL_SPI_MODE_MASTER,
  7. .TransferDirection = LL_SPI_FULL_DUPLEX,
  8. .DataWidth = LL_SPI_DATAWIDTH_8BIT,
  9. .ClockPolarity = LL_SPI_POLARITY_LOW,
  10. .ClockPhase = LL_SPI_PHASE_2EDGE,
  11. .NSS = LL_SPI_NSS_SOFT,
  12. .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8,
  13. .BitOrder = LL_SPI_MSB_FIRST,
  14. .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE,
  15. .CRCPoly = 7,
  16. };
  17. const LL_SPI_InitTypeDef furi_hal_spi_config_subghz = {
  18. .Mode = LL_SPI_MODE_MASTER,
  19. .TransferDirection = LL_SPI_FULL_DUPLEX,
  20. .DataWidth = LL_SPI_DATAWIDTH_8BIT,
  21. .ClockPolarity = LL_SPI_POLARITY_LOW,
  22. .ClockPhase = LL_SPI_PHASE_1EDGE,
  23. .NSS = LL_SPI_NSS_SOFT,
  24. .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV8,
  25. .BitOrder = LL_SPI_MSB_FIRST,
  26. .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE,
  27. .CRCPoly = 7,
  28. };
  29. const LL_SPI_InitTypeDef furi_hal_spi_config_display = {
  30. .Mode = LL_SPI_MODE_MASTER,
  31. .TransferDirection = LL_SPI_FULL_DUPLEX,
  32. .DataWidth = LL_SPI_DATAWIDTH_8BIT,
  33. .ClockPolarity = LL_SPI_POLARITY_LOW,
  34. .ClockPhase = LL_SPI_PHASE_1EDGE,
  35. .NSS = LL_SPI_NSS_SOFT,
  36. .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV16,
  37. .BitOrder = LL_SPI_MSB_FIRST,
  38. .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE,
  39. .CRCPoly = 7,
  40. };
  41. /**
  42. * SD Card in fast mode (after init)
  43. */
  44. const LL_SPI_InitTypeDef furi_hal_spi_config_sd_fast = {
  45. .Mode = LL_SPI_MODE_MASTER,
  46. .TransferDirection = LL_SPI_FULL_DUPLEX,
  47. .DataWidth = LL_SPI_DATAWIDTH_8BIT,
  48. .ClockPolarity = LL_SPI_POLARITY_LOW,
  49. .ClockPhase = LL_SPI_PHASE_1EDGE,
  50. .NSS = LL_SPI_NSS_SOFT,
  51. .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2,
  52. .BitOrder = LL_SPI_MSB_FIRST,
  53. .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE,
  54. .CRCPoly = 7,
  55. };
  56. /**
  57. * SD Card in slow mode (before init)
  58. */
  59. const LL_SPI_InitTypeDef furi_hal_spi_config_sd_slow = {
  60. .Mode = LL_SPI_MODE_MASTER,
  61. .TransferDirection = LL_SPI_FULL_DUPLEX,
  62. .DataWidth = LL_SPI_DATAWIDTH_8BIT,
  63. .ClockPolarity = LL_SPI_POLARITY_LOW,
  64. .ClockPhase = LL_SPI_PHASE_1EDGE,
  65. .NSS = LL_SPI_NSS_SOFT,
  66. .BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV32,
  67. .BitOrder = LL_SPI_MSB_FIRST,
  68. .CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE,
  69. .CRCPoly = 7,
  70. };
  71. osMutexId_t spi_mutex_d = NULL;
  72. osMutexId_t spi_mutex_r = NULL;
  73. const FuriHalSpiBus spi_r = {
  74. .spi=SPI_R,
  75. .mutex=&spi_mutex_r,
  76. .miso=&gpio_spi_r_miso,
  77. .mosi=&gpio_spi_r_mosi,
  78. .clk=&gpio_spi_r_sck,
  79. };
  80. const FuriHalSpiBus spi_d = {
  81. .spi=SPI_D,
  82. .mutex=&spi_mutex_d,
  83. .miso=&gpio_spi_d_miso,
  84. .mosi=&gpio_spi_d_mosi,
  85. .clk=&gpio_spi_d_sck,
  86. };
  87. const FuriHalSpiDevice furi_hal_spi_devices[FuriHalSpiDeviceIdMax] = {
  88. { .bus=&spi_r, .config=&furi_hal_spi_config_subghz, .chip_select=&gpio_subghz_cs, },
  89. { .bus=&spi_d, .config=&furi_hal_spi_config_display, .chip_select=&gpio_display_cs, },
  90. { .bus=&spi_d, .config=&furi_hal_spi_config_sd_fast, .chip_select=&gpio_sdcard_cs, },
  91. { .bus=&spi_d, .config=&furi_hal_spi_config_sd_slow, .chip_select=&gpio_sdcard_cs, },
  92. { .bus=&spi_r, .config=&furi_hal_spi_config_nfc, .chip_select=&gpio_nfc_cs },
  93. };