furi-hal-spi-config.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. const FuriHalSpiBus spi_r = {
  72. .spi = SPI_R,
  73. .miso = &gpio_spi_r_miso,
  74. .mosi = &gpio_spi_r_mosi,
  75. .clk = &gpio_spi_r_sck,
  76. };
  77. const FuriHalSpiBus spi_d = {
  78. .spi = SPI_D,
  79. .miso = &gpio_spi_d_miso,
  80. .mosi = &gpio_spi_d_mosi,
  81. .clk = &gpio_spi_d_sck,
  82. };
  83. const FuriHalSpiDevice furi_hal_spi_devices[FuriHalSpiDeviceIdMax] = {
  84. {
  85. .bus = &spi_r,
  86. .config = &furi_hal_spi_config_subghz,
  87. .chip_select = &gpio_subghz_cs,
  88. },
  89. {
  90. .bus = &spi_d,
  91. .config = &furi_hal_spi_config_display,
  92. .chip_select = &gpio_display_cs,
  93. },
  94. {
  95. .bus = &spi_d,
  96. .config = &furi_hal_spi_config_sd_fast,
  97. .chip_select = &gpio_sdcard_cs,
  98. },
  99. {
  100. .bus = &spi_d,
  101. .config = &furi_hal_spi_config_sd_slow,
  102. .chip_select = &gpio_sdcard_cs,
  103. },
  104. {.bus = &spi_r, .config = &furi_hal_spi_config_nfc, .chip_select = &gpio_nfc_cs},
  105. };