Extending interface (but need to add a port)

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

Extending interface (but need to add a port)

Post by ahenshaw »

I'm working on a project using an LCD panel that is connected to my startKit via SPI. I have the base functionality running, but I thought I could clean up my library by writing the graphics calls as extended interfaces to the SPI Interface library, for example:

Code: Select all

extends client interface spi_master_if  : {
    void pushColor(client spi_master_if self, short w) {
        self.transfer8(w >> 8);
        self.transfer8(w & 0xFF);
    }
}
Unfortunately, with this particular LCD panel, I have to use a single-bit port to declare whether an SPI transfer is data or command (declared as out port dcport). Therefore, since interface extensions cannot reference global variables, I would need to pass dcport with every function call, which destroys the elegance of this approach.

Any suggestions?


User avatar
Folknology
XCore Legend
Posts: 1274
Joined: Thu Dec 10, 2009 10:20 pm

Post by Folknology »

How about either passing into pushColor interface a port reference to dcport, or an interface to a port GPIO driver that controls the dcport?
User avatar
ahenshaw
Experienced Member
Posts: 96
Joined: Mon Mar 22, 2010 8:55 pm

Post by ahenshaw »

Well, I was hoping to just extend the SPI interface (talking to the SPI server) that is the main component of the code. My intent was to have a user API that looks like

Code: Select all

spi_master_if lcd;

lcd.drawText(x, y, "some text");
lcd.drawFilledRect(x, y, w, h, color);
...
However, because an interface extension can't use a global, the user API would need the port passed in for every call, which I think is a bit ugly.

If I don't just extend the SPI interface, but instead, I create my own server (which would subsume the SPI interface) and associated interface, then I could initialize the server by passing in the SPI interface and the port (which may have been what you were suggesting).

I think that this is what I'll wind up doing.

So, in summary, I don't think that an interface extension will work (as I was hoping), but a new server and interface would.