Created Mon, 13 Feb 2012 06:33:49 +0000 by WestfW
Mon, 13 Feb 2012 06:33:49 +0000
So I was looking that the Variants/xxx/Board_defs.h and Board_Data.h...
It seems a bit more cumbersome than needed. You have:
// In Board_defs.h
#define OPT_BOARD_DIGITAL_IO 0 //board does not extend digital i/o func
//And then in Board_data.c
#if (OPT_BOARD_DIGITAL_IO != 0)
int _board_pinMode(uint8_t pin, uint8_t mode) {
return 0;
}
// And in the core code:
#if (OPT_BOARD_DIGITAL_IO != 0)
/* Peform any board specific processing.
*/
int _board_digitalWrite(uint8_t pin, uint8_t val);
if (_board_digitalWrite(pin, val) != 0)
{
return;
}
#endif
I don't like having the prototypes for the external functions in the core c code, either. How about something like:
// In Board_defs.h
#define OPT_BOARD_DIGITALWRITE(p,v) 0 //board does not extend digital i/o func
// or
//extern int _board_digitalWrite(uint8_t pin, uint8_t val);
//#define OPT_BOARD_DIGITALWRITE(p,v) _board_digitalWrite(p, v)
//And then in Board_data.c, only if actually needed
int _board_pinMode(uint8_t pin, uint8_t mode) {
// real code
}
// And in the core code:
/* Peform any board specific processing.
*/
if (OPT_BOARD_DIGITALWRITE(pin, val) != 0) {
return;
}
#endif
This would use the compiler optimizer to leave out impossible clauses if OPT_BOARD_xxx was a consstant 0, removing a lot of the conditional compilation from elsewhere...