diff options
Diffstat (limited to 'platforms/chibios/drivers')
-rw-r--r-- | platforms/chibios/drivers/i2c_master.c | 3 | ||||
-rw-r--r-- | platforms/chibios/drivers/spi_master.c | 33 | ||||
-rw-r--r-- | platforms/chibios/drivers/uart.c | 4 | ||||
-rw-r--r-- | platforms/chibios/drivers/uart.h | 16 |
4 files changed, 56 insertions, 0 deletions
diff --git a/platforms/chibios/drivers/i2c_master.c b/platforms/chibios/drivers/i2c_master.c index 63e85ae87..43591d56f 100644 --- a/platforms/chibios/drivers/i2c_master.c +++ b/platforms/chibios/drivers/i2c_master.c | |||
@@ -38,6 +38,9 @@ static const I2CConfig i2cconfig = { | |||
38 | I2C1_OPMODE, | 38 | I2C1_OPMODE, |
39 | I2C1_CLOCK_SPEED, | 39 | I2C1_CLOCK_SPEED, |
40 | I2C1_DUTY_CYCLE, | 40 | I2C1_DUTY_CYCLE, |
41 | #elif defined(WB32F3G71xx) | ||
42 | I2C1_OPMODE, | ||
43 | I2C1_CLOCK_SPEED, | ||
41 | #else | 44 | #else |
42 | // This configures the I2C clock to 400khz assuming a 72Mhz clock | 45 | // This configures the I2C clock to 400khz assuming a 72Mhz clock |
43 | // For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html | 46 | // For more info : https://www.st.com/en/embedded-software/stsw-stm32126.html |
diff --git a/platforms/chibios/drivers/spi_master.c b/platforms/chibios/drivers/spi_master.c index c592369dd..dde0bb059 100644 --- a/platforms/chibios/drivers/spi_master.c +++ b/platforms/chibios/drivers/spi_master.c | |||
@@ -54,6 +54,7 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { | |||
54 | return false; | 54 | return false; |
55 | } | 55 | } |
56 | 56 | ||
57 | #ifndef WB32F3G71xx | ||
57 | uint16_t roundedDivisor = 2; | 58 | uint16_t roundedDivisor = 2; |
58 | while (roundedDivisor < divisor) { | 59 | while (roundedDivisor < divisor) { |
59 | roundedDivisor <<= 1; | 60 | roundedDivisor <<= 1; |
@@ -62,6 +63,7 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { | |||
62 | if (roundedDivisor < 2 || roundedDivisor > 256) { | 63 | if (roundedDivisor < 2 || roundedDivisor > 256) { |
63 | return false; | 64 | return false; |
64 | } | 65 | } |
66 | #endif | ||
65 | 67 | ||
66 | #if defined(K20x) || defined(KL2x) | 68 | #if defined(K20x) || defined(KL2x) |
67 | spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1); | 69 | spiConfig.tar0 = SPIx_CTARn_FMSZ(7) | SPIx_CTARn_ASC(1); |
@@ -135,6 +137,37 @@ bool spi_start(pin_t slavePin, bool lsbFirst, uint8_t mode, uint16_t divisor) { | |||
135 | } | 137 | } |
136 | 138 | ||
137 | spiConfig.cpr = (roundedDivisor - 1) >> 1; | 139 | spiConfig.cpr = (roundedDivisor - 1) >> 1; |
140 | |||
141 | #elif defined(WB32F3G71xx) | ||
142 | if (!lsbFirst) { | ||
143 | osalDbgAssert(lsbFirst != FALSE, "unsupported lsbFirst"); | ||
144 | } | ||
145 | |||
146 | if (divisor < 1) { | ||
147 | return false; | ||
148 | } | ||
149 | |||
150 | spiConfig.SPI_BaudRatePrescaler = (divisor << 2); | ||
151 | |||
152 | switch (mode) { | ||
153 | case 0: | ||
154 | spiConfig.SPI_CPHA = SPI_CPHA_1Edge; | ||
155 | spiConfig.SPI_CPOL = SPI_CPOL_Low; | ||
156 | break; | ||
157 | case 1: | ||
158 | spiConfig.SPI_CPHA = SPI_CPHA_2Edge; | ||
159 | spiConfig.SPI_CPOL = SPI_CPOL_Low; | ||
160 | break; | ||
161 | case 2: | ||
162 | spiConfig.SPI_CPHA = SPI_CPHA_1Edge; | ||
163 | spiConfig.SPI_CPOL = SPI_CPOL_High; | ||
164 | break; | ||
165 | case 3: | ||
166 | spiConfig.SPI_CPHA = SPI_CPHA_2Edge; | ||
167 | spiConfig.SPI_CPOL = SPI_CPOL_High; | ||
168 | break; | ||
169 | } | ||
170 | |||
138 | #else | 171 | #else |
139 | spiConfig.cr1 = 0; | 172 | spiConfig.cr1 = 0; |
140 | 173 | ||
diff --git a/platforms/chibios/drivers/uart.c b/platforms/chibios/drivers/uart.c index 297c1892c..d2ea5d641 100644 --- a/platforms/chibios/drivers/uart.c +++ b/platforms/chibios/drivers/uart.c | |||
@@ -18,7 +18,11 @@ | |||
18 | 18 | ||
19 | #include "quantum.h" | 19 | #include "quantum.h" |
20 | 20 | ||
21 | #if defined(WB32F3G71xx) | ||
22 | static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE, SD1_WRDLEN, SD1_STPBIT, SD1_PARITY, SD1_ATFLCT}; | ||
23 | #else | ||
21 | static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE, SD1_CR1, SD1_CR2, SD1_CR3}; | 24 | static SerialConfig serialConfig = {SERIAL_DEFAULT_BITRATE, SD1_CR1, SD1_CR2, SD1_CR3}; |
25 | #endif | ||
22 | 26 | ||
23 | void uart_init(uint32_t baud) { | 27 | void uart_init(uint32_t baud) { |
24 | static bool is_initialised = false; | 28 | static bool is_initialised = false; |
diff --git a/platforms/chibios/drivers/uart.h b/platforms/chibios/drivers/uart.h index 5bc487590..603d51037 100644 --- a/platforms/chibios/drivers/uart.h +++ b/platforms/chibios/drivers/uart.h | |||
@@ -68,6 +68,22 @@ | |||
68 | # define SD1_CR3 0 | 68 | # define SD1_CR3 0 |
69 | #endif | 69 | #endif |
70 | 70 | ||
71 | #ifndef SD1_WRDLEN | ||
72 | # define SD1_WRDLEN 3 | ||
73 | #endif | ||
74 | |||
75 | #ifndef SD1_STPBIT | ||
76 | # define SD1_STPBIT 0 | ||
77 | #endif | ||
78 | |||
79 | #ifndef SD1_PARITY | ||
80 | # define SD1_PARITY 0 | ||
81 | #endif | ||
82 | |||
83 | #ifndef SD1_ATFLCT | ||
84 | # define SD1_ATFLCT 0 | ||
85 | #endif | ||
86 | |||
71 | void uart_init(uint32_t baud); | 87 | void uart_init(uint32_t baud); |
72 | 88 | ||
73 | void uart_write(uint8_t data); | 89 | void uart_write(uint8_t data); |