-
Notifications
You must be signed in to change notification settings - Fork 0
Adding display drivers
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.
Driver files are placed in the devices/
directory. Every display driver consists of one .c
and one .h
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.
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.
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.
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).
Your contribution will be greatly appreciated!