hiding interfaces
Posted: Wed May 31, 2017 7:26 pm
Hi all,
I'm trying to work out how to avoid having to pass the client end of an interface to every function that needs to use it.
Suppose I have a LED driver that's controlled via an I2C port. I'm using the I2C library, so the LED driver software needs to know about the client interface, but this information should be hidden from the code that makes use of it. I don't want to have to have to identify the interface to the driver functions every time.
In other words, I want to be able to call SetLed1(ON) rather than SetLed1(ON, i2c_if). Preferably this would work by having a member variable to store the interface, or a reference or pointer to it, which can then be used by functions within a module. That reference then only needs to be set up once.
I've tried creating a static interface member variable but XCC complains along the lines of "error: global variable `i2c_if' has type interface".
Any ideas?
Thanks
I'm trying to work out how to avoid having to pass the client end of an interface to every function that needs to use it.
Suppose I have a LED driver that's controlled via an I2C port. I'm using the I2C library, so the LED driver software needs to know about the client interface, but this information should be hidden from the code that makes use of it. I don't want to have to have to identify the interface to the driver functions every time.
In other words, I want to be able to call SetLed1(ON) rather than SetLed1(ON, i2c_if). Preferably this would work by having a member variable to store the interface, or a reference or pointer to it, which can then be used by functions within a module. That reference then only needs to be set up once.
I've tried creating a static interface member variable but XCC complains along the lines of "error: global variable `i2c_if' has type interface".
Any ideas?
Thanks