HAL_AVR: force all devices on SPI0 to low speed when one is low speed
this forces MS5611 to low speed when MPU6K is low speed
This commit is contained in:
parent
bea7e4c9bc
commit
5999a468ac
@ -17,6 +17,7 @@ extern const AP_HAL::HAL& hal;
|
||||
#define SPI0_SCK_PIN 52
|
||||
|
||||
AVRSemaphore AVRSPI0DeviceDriver::_semaphore;
|
||||
bool AVRSPI0DeviceDriver::_force_low_speed;
|
||||
|
||||
static volatile bool spi0_transferflag = false;
|
||||
|
||||
@ -40,6 +41,9 @@ void AVRSPI0DeviceDriver::_cs_assert()
|
||||
{
|
||||
const uint8_t valid_spcr_mask =
|
||||
(_BV(CPOL) | _BV(CPHA) | _BV(SPR1) | _BV(SPR0));
|
||||
if (_force_low_speed) {
|
||||
_spcr = _spcr_lowspeed;
|
||||
}
|
||||
uint8_t new_spcr = (SPCR & ~valid_spcr_mask) | (_spcr & valid_spcr_mask);
|
||||
SPCR = new_spcr;
|
||||
|
||||
@ -145,8 +149,10 @@ void AVRSPI0DeviceDriver::set_bus_speed(AVRSPI0DeviceDriver::bus_speed speed)
|
||||
{
|
||||
if (speed == AVRSPI0DeviceDriver::SPI_SPEED_HIGH) {
|
||||
_spcr = _spcr_highspeed;
|
||||
_force_low_speed = false;
|
||||
} else {
|
||||
_spcr = _spcr_lowspeed;
|
||||
_force_low_speed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ private:
|
||||
void _transfer16(const uint8_t *tx, uint8_t *rx);
|
||||
|
||||
static AP_HAL_AVR::AVRSemaphore _semaphore;
|
||||
static bool _force_low_speed;
|
||||
|
||||
AP_HAL_AVR::AVRDigitalSource *_cs_pin;
|
||||
const uint8_t _spcr_lowspeed;
|
||||
|
Loading…
Reference in New Issue
Block a user