To support multiple instances it is necessary to stop using global variables to store a driver's data in. Instead, you should store it in a structure, that you allocate and store on driver's init.
In the driver's private structure will probably at least be something like:
typedef struct MyDriver_private_data {
int fd; // file descriptor for the LCD device
int width, height; // dimension of the LCD (in characters, 1-based
int cellwidth, cellheight; // Size of each LCD cell, in pixels
unsigned char *framebuf; // Frame buffer...
} PrivateData;
You allocate and store this structure like this:
PrivateData *p; // Allocate and store private data p = (PrivateData *) malloc(sizeof(PrivateData)); if (p == NULL) return -1; if (drvthis->store_private_ptr( drvthis, p ) < 0) return -1; // initialize private data p->fd = -1; p->cellheight = 8; p->cellwidth = 6; (... continue with the rest of your init routine)
You retrieve this private data pointer by adding the following code to the beginning of your functions:
PrivateData *p = (PrivateData *) drvthis->private_data;
Then you can access your data like:
p->framebuf