Skip to content

Adding display drivers

Adam Dej edited this page Jan 23, 2014 · 1 revision

Before adding your own display device driver you should already know how to use this library and be familiar with the library structure.

This is not a complete how-to, just a document to get the basic idea. You can be creative if results of your creativity aren't against the library philosophy and conventions.

Files

Driver files are placed in the devices/ directory. Every display driver consists of one .c and one .h

Low-level interface

Find out what interface the display uses, and come up with the most universal interface functions you will want pointers to. It is important that those functions are implementable on as much platforms as possible. Usually those functions should return bool whether the operation was successful.

Create your private data structure

Usually private data structure holds pointers to low-level interface driver functions implemented by user, however, it is completely up to you. Some display don't support reading from VRAM, so a framebuffer may also be required.

Implement required functions

For example if you are implementing 1-bit display device required functions are:

bool set_pixel(uintpix x, uintpix y, void *data);
bool unset_pixel(uintpix x, uintpix y, void *data);
bool clear_display(void *data);
bool commit(void *data);

You can assume that the void *data pointer will be every time pointing to your private data structure.

Create function for constructing the device instance

Usually those functions are named make_device_xy, except for virtual devices. As parameters, you should request pointers to low-level interface driver functions implemented by user and any other parameters you see fit.

Firstly you'll probably want to allocate the private data structure. If the allocation fails, return NULL. Then, assign the appropriate pointers or other data in your structure.

Then, allocate the DISPLAY_XY structure. Assign pointers to common display functions implemented by you and also instance of your private data structure. If the allocation fails return NULL (pay attention to memory leaks, remember to free memory used by private data structure before returning NULL).

Optionally: issue a pull request and add pages to this wiki

Your contribution will be greatly appreciated!