avr: Simplify spi mode setting

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-05-01 21:55:56 -04:00
parent c95705ba3a
commit ab5238317b
1 changed files with 1 additions and 22 deletions

View File

@ -73,28 +73,7 @@ spi_setup(uint32_t bus, uint8_t mode, uint32_t rate)
}
// Setup mode
config.spcr |= (1<<SPE) | (1<<MSTR);
switch(mode) {
case 0: {
// MODE 0 - CPOL=0, CPHA=0
break;
}
case 1: {
// MODE 1 - CPOL=0, CPHA=1
config.spcr |= (1<<CPHA);
break;
}
case 2: {
// MODE 2 - CPOL=1, CPHA=0
config.spcr |= (1<<CPOL);
break;
}
case 3: {
// MODE 3 - CPOL=1, CPHA=1
config.spcr |= (1<<CPOL) | (1<<CPHA);
break;
}
}
config.spcr |= (1<<SPE) | (1<<MSTR) | (mode << CPHA);
return config;
}