summaryrefslogtreecommitdiff
path: root/platforms/chibios/drivers/spi_master.c
diff options
context:
space:
mode:
Diffstat (limited to 'platforms/chibios/drivers/spi_master.c')
-rw-r--r--platforms/chibios/drivers/spi_master.c31
1 files changed, 28 insertions, 3 deletions
diff --git a/platforms/chibios/drivers/spi_master.c b/platforms/chibios/drivers/spi_master.c
index 28ddcbb2ba..c592369dde 100644
--- a/platforms/chibios/drivers/spi_master.c
+++ b/platforms/chibios/drivers/spi_master.c
@@ -42,9 +42,9 @@ __attribute__((weak)) void spi_init(void) {
palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), SPI_MOSI_PAL_MODE);
palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), SPI_MISO_PAL_MODE);
#else
- palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
- palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
- palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE) | PAL_STM32_OTYPE_PUSHPULL | PAL_STM32_OSPEED_HIGHEST);
+ palSetPadMode(PAL_PORT(SPI_SCK_PIN), PAL_PAD(SPI_SCK_PIN), PAL_MODE_ALTERNATE(SPI_SCK_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
+ palSetPadMode(PAL_PORT(SPI_MOSI_PIN), PAL_PAD(SPI_MOSI_PIN), PAL_MODE_ALTERNATE(SPI_MOSI_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
+ palSetPadMode(PAL_PORT(SPI_MISO_PIN), PAL_PAD(SPI_MISO_PIN), PAL_MODE_ALTERNATE(SPI_MISO_PAL_MODE) | PAL_OUTPUT_TYPE_PUSHPULL | PAL_OUTPUT_SPEED_HIGHEST);
#endif
}
}
@@ -110,6 +110,31 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) {
spiConfig.tar0 |= SPIx_CTARn_BR(8);
break;
}
+
+#elif defined(HT32)
+ spiConfig.cr0 = SPI_CR0_SELOEN;
+ spiConfig.cr1 = SPI_CR1_MODE | 8; // 8 bits and in master mode
+
+ if (lsbFirst) {
+ spiConfig.cr1 |= SPI_CR1_FIRSTBIT;
+ }
+
+ switch (mode) {
+ case 0:
+ spiConfig.cr1 |= SPI_CR1_FORMAT_MODE0;
+ break;
+ case 1:
+ spiConfig.cr1 |= SPI_CR1_FORMAT_MODE1;
+ break;
+ case 2:
+ spiConfig.cr1 |= SPI_CR1_FORMAT_MODE2;
+ break;
+ case 3:
+ spiConfig.cr1 |= SPI_CR1_FORMAT_MODE3;
+ break;
+ }
+
+ spiConfig.cpr = (roundedDivisor - 1) >> 1;
#else
spiConfig.cr1 = 0;