nrf: give more flexibility in picking SPI speeds

Instead of only allowing a limited number of speeds, use the provided
speed as an upper bound on the allowed speed. The reasoning is that
picking a higher speed than requrested will likely result in malfunction
while picking a lower speed will usually only result in slower
operation.
This behavior matches the ESP32 at least.
Этот коммит содержится в:
Ayke van Laethem 2020-10-18 19:52:00 +02:00 коммит произвёл Ron Evans
родитель d382f3a259
коммит 47dc76fc34

Просмотреть файл

@ -357,23 +357,25 @@ func (spi SPI) Configure(config SPIConfig) {
// set frequency
var freq uint32
switch config.Frequency {
case 125000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_K125
case 250000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_K250
case 500000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_K500
case 1000000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_M1
case 2000000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_M2
case 4000000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_M4
case 8000000:
if config.Frequency == 0 {
config.Frequency = 4000000 // 4MHz
}
switch {
case config.Frequency >= 8000000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_M8
default:
case config.Frequency >= 4000000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_M4
case config.Frequency >= 2000000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_M2
case config.Frequency >= 1000000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_M1
case config.Frequency >= 500000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_K500
case config.Frequency >= 250000:
freq = nrf.SPI_FREQUENCY_FREQUENCY_K250
default: // below 250kHz, default to the lowest speed available
freq = nrf.SPI_FREQUENCY_FREQUENCY_K125
}
spi.Bus.FREQUENCY.Set(freq)