@@ -220,16 +220,10 @@ void SPIClass::setDataMode(uint8_t _pin, uint8_t _mode)
220
220
221
221
/* *
222
222
* @brief Deprecated function.
223
- * Configure the clock speed: 125kHz to 8MHz.
223
+ * Configure the clock speed
224
224
* @param _pin: CS pin associated to a configuration (optional).
225
- * @param _divider: can be one of the following parameters:
226
- * SPI_CLOCK_DIV2 (8MHz)
227
- * SPI_CLOCK_DIV4 (4MHz)
228
- * SPI_CLOCK_DIV8 (2MHz)
229
- * SPI_CLOCK_DIV16 (1MHz)
230
- * SPI_CLOCK_DIV32 (500kHz)
231
- * SPI_CLOCK_DIV64 (250kHz)
232
- * SPI_CLOCK_DIV128 (125kHz)
225
+ * @param _divider: the SPI clock can be divided by values from 1 to 255.
226
+ * If 0, default SPI speed is used.
233
227
*/
234
228
void SPIClass::setClockDivider (uint8_t _pin, uint8_t _divider)
235
229
{
@@ -240,23 +234,11 @@ void SPIClass::setClockDivider(uint8_t _pin, uint8_t _divider)
240
234
if (idx >= NB_SPI_SETTINGS) {
241
235
return ;
242
236
}
243
-
244
- /* Get clk freq of the SPI instance */
245
- uint32_t spiClkFreq = spi_getClkFreq (&_spi);
246
-
247
- switch (_divider) {
248
- case (SPI_CLOCK_DIV2) :
249
- case (SPI_CLOCK_DIV4) :
250
- case (SPI_CLOCK_DIV8) :
251
- case (SPI_CLOCK_DIV16) :
252
- case (SPI_CLOCK_DIV32) :
253
- case (SPI_CLOCK_DIV64) :
254
- case (SPI_CLOCK_DIV128) :
255
- spiSettings[idx].clk = spiClkFreq/_divider;
256
- break ;
257
- default :
258
- spiSettings[idx].clk = SPI_SPEED_CLOCK_DEFAULT;
259
- break ;
237
+ if (_divider == 0 ) {
238
+ spiSettings[idx].clk = SPI_SPEED_CLOCK_DEFAULT;
239
+ } else {
240
+ /* Get clk freq of the SPI instance and compute it */
241
+ spiSettings[idx].clk = spi_getClkFreq (&_spi)/_divider;
260
242
}
261
243
262
244
spi_init (&_spi, spiSettings[idx].clk ,
0 commit comments