Wouter wrote me an email regarding xpcc and below is my original long answer with a minor edit regarding connecting GPIOs in the configuration handler.
GpioB3::connect(I2cMaster1::Sda);
// yes, this works!
GpioB4::connect(I2cMaster1::Scl);
SpiMaster::initialize<systemClock, MHz1>();
SpiMaster::setBitOrder(SpiMaster::BitOrder::MsbFirst);
}
[21]:
https://github.com/roboterclubaachen/xpcc/blob/develop/src/xpcc/architecture/platform/driver/i2c/generic/i2c_master.hpp#L31-L33[22]:
http://xpcc.io/api/classxpcc_1_1_i2c_device.html- are the pins 'provided' by an extender as usable as normal GPIO pins (for instance to connect and LCD, or a cascaded extender)?
There is no concept for that in our code generation, however, we have had to solve this issue before, when we wanted to drive a HD44780 display [23] using a I2C IO-expander.
We suddenly had the problem, that we couldn’t pass the I2C expander to the LCD driver, since we never assumed that GPIOs could be dynamic ;-)
So the solution was to create a class with the same static functions as expected by the driver and wrap the I2C expander like this:
extern xpcc::Pca9535<I2cMaster1> expander;
// either extern or static
class GpioExt4 {
…
static void set() {
expander.set(Pin::P4);
}
}
Let me be clear: This is not efficient, due to the I2C bus access and its blocking! But it worked.
I haven’t tried passing these GPIO classes to our SoftwareI2cMaster so that we can cascade another I2C expander as you suggested in your talk, but it might work ;-)
[23]:
http://xpcc.io/api/classxpcc_1_1_hd44780.html- what kind of error messages does the user get when inappropriate (template) arguments are provided?
C++ Template errors are really terrible and cryptic. I don’t know why compiler developers hate us so much.
We mainly use `static_assert` to confirm some basic functionality.
An example would be the width of the bus in our `GpioPort` classes [25] or directly asserting the correct bus width in the HD44780 driver [26]. And of course there is the afore-mentioned baudrate computation.
Unfortunately there is no way of confirming that a Template parameter confirms to a specific interface, however, this functionality called “ConceptC++” was actually a C++0x proposal [27], but it did not make it into C++11 nor C++14. Maybe C++17?
[24]:
https://www.youtube.com/watch?v=mGS2tKQhdhY[25]:
https://github.com/roboterclubaachen/xpcc/blob/develop/src/xpcc/architecture/platform/driver/gpio/at90_tiny_mega/gpio.hpp.in#L349-L356[26]:
https://github.com/roboterclubaachen/xpcc/blob/develop/src/xpcc/driver/display/hd44780_base.hpp#L154-L155[27]:
http://www.generic-programming.org/languages/conceptcpp/tutorial/Kind regards,
Niklas