spi.c fix output of warning for wrong baudrate

* do crude cpp-calculation for case when we want to warn
master
Matthias Merz 15 years ago
parent 0eccb96b39
commit 14d0743d8b

@ -45,9 +45,18 @@ void spi_init(){
return d-1; // the -1 because minimum divisor is /2 return d-1; // the -1 because minimum divisor is /2
} }
/* do pseudo-calculation in preprocessor, to get warnings
* we right-shift 8 times; if result >0, d will be >7
* so output warning in that case
*/
#define D_VAL (F_CPU / SPI_BAUDRATE)
#if ((D_VAL >> 8) > 0 )
#warning "spi baudrate too slow, cannot be set"
#endif
d = spi_clock_divisor(); d = spi_clock_divisor();
if(d>7){ if(d>7){
#warning "spi baudrate too slow, cannot be set" // warning was (hopefully) output previously by cpp
d=7; d=7;
} }

Loading…
Cancel
Save