DISCLAIMER:
THIS IS EXPERIMENTAL SOFTWARE AND HARDWARE. USE AT YOUR OWN RISK. THE MAINTAINER(S) OF THESE PAGES AND THE DEVELOPER(S) OF SOFTWARE AND HARDWARE PRESENTED ON THESE PAGES CAN NOT BE HELD LIABLE UNDER ANY CIRCUMSTANCES FOR DAMAGE TO HARDWARE OR SOFTWARE, LOST DATA, OR OTHER DIRECT OR INDIRECT DAMAGE RESULTING FROM THE USE OF THIS SOFTWARE OR HARDWARE. IF YOU DO NOT AGREE TO THESE CONDITIONS, YOU ARE NOT PERMITTED TO USE OR FURTHER DISTRIBUTE THIS SOFTWARE OR TO USE ANY TEMPLATES FOR BUILDING HARDWARE PRESENTED HERE.
attention:
the additional support of direct I/O starting with version 1.92 requested a change in the API:
instead of int
filehandles a structure ppd
(parallel port descriptor) is now used.
serdisp_init()
now has an extra parameter that will be used in the future.
further infos on api-changes: HISTORY
serdisp_parport.h
offers some functions for opening and closing a parallel port using a parallel port descriptor ('ppd'
).ioctl
-calls or direct I/O using outp
-calls.PP_import()
.
serdisp_PP_t* PP_open (const char ppdev[]) opens a parport device ppdev ...device name or port-number of device to open eg: linux: "/dev/parport0" or "0x378" (for direct IO) freebsd: "/dev/ppi0" returns a parallel port descriptor or (serdisp_PP_t*)0 if operation was not successful
void PP_close (serdisp_PP_t* ppd) close the parport device ppd ... parallel port descriptor
serdisp_PP_t* PP_import (int directIO, int hport) import an existing already opened parport device / port and create a ppd struct out of it directIO ... 1: yes -> outp-calls, 0: no -> ioctl-calls hport ... if directIO: port (eg: 0x378), else: descriptor for parport dev returns a parallel port descriptor or (serdisp_PP_t*)0 if operation was not successful USE WITH CARE!!! all permissions and stuff like that must be ok before!! no checking for validity in here
serdisp_t* serdisp_init (serdisp_PP_t* ppd, const char dispname[], const char extra[]) initialises a display. all capabilities and basic values are set ppd ... parallel port descriptor dispname ... display name (for now: "OPTREX323", "PCD8544", "SED1565", "NOKIA7110") extra ... extra settings (will be used in the future. eg. for wiring or other non-standard settings) returns a display descriptorExample:
serdisp_t* dd; dd = serdisp_init(ppd, "PCD8544", "");
void serdisp_close (serdisp_t* dd) close (switch off) display dd ... display descriptor
int serdisp_getwidth (serdisp_t* dd) get width of the display dd ... display descriptor returns the width of the display
int serdisp_getheight (serdisp_t* dd) get height of the display dd ... display descriptor returns the height of the display
int serdisp_getcolours (serdisp_t* dd) get amount of colours supported by the display dd ... display descriptor returns the amount of supported colours
void serdisp_feature (serdisp_t* dd, int feature, int value) change a display feature dd ... display descriptor feature ... feature to change: FEATURE_CONTRAST .. change display contrast (value: 0-MAX_CONTRASTSTEP) FEATURE_BACKLIGHT .. 0: off, 1: on, 2: toggle FEATURE_REVERSE .. 0: normal display, 1: reversed display, 2: toggle FEATURE_ROTATE .. 0: normal, 1: bottom-up value ... value for option (see above)Examples:
serdisp_feature(dd, FEATURE_BACKLIGHT, FEATURE_TOGGLE); serdisp_feature(dd, CONTRAST, 5);
void serdisp_clearbuffer (serdisp_t* dd) resets the internal display-buffer that is used by serdisplib display is NOT redrawn here! dd ... display descriptor
void serdisp_clear (serdisp_t* dd) clear whole display dd ... display descriptor
void serdisp_update (serdisp_t* dd) update whole display dd ... display descriptor
void serdisp_rewrite (serdisp_t* dd) rewrite the whole display dd ... display descriptor
void serdisp_blink (serdisp_t* dd, int what, int cnt, int delta) blink the display dd ... display descriptor what ... 0: blinking using backlight, 1: blinking using display reversing cnt ... how often should there be blinking delta ... delay between two blinking intervals
void serdisp_setpixel (serdisp_t* dd, int x, int y, int colour) changes a pixel in the display buffer dd ... display descriptor x ... x-position y ... y-position colour ... monochrome: 0: clear (white), <>0: set (black); else: up to 16m colours (dependend on display)
void serdisp_setpixels (serdisp_t* dd, int x, int y, int w, int h, byte* data) changes an area in the display buffer dd ... display descriptor x ... x-position top/left y ... y-position top/left w ... width of content h ... height of content data ... pixel/colour data (if display supports <= 256 colours: one byte == one pixel else: four byte == one pixel (this may change in the future) )Example:
byte* data = .....; /* fill pixel/colour-data into 'data' .... .... /* draw a 5x5 area starting at position 5/10 */ serdisp_setpixels(dd, 5, 10, 5, 5, data);
int serdisp_getpixel (serdisp_t* dd, int x, int y) get colour of pixel at (x/y) dd ... display descriptor x ... x-position y ... y-position
char ppdev[] = "/dev/parport0"; serdisp_PP_t* ppd; serdisp_t* dd = 0; int i; /* opening the parallel port device */ ppd = PP_open(ppdev); if (ppd == (serdisp_PP_t*)0) { fprintf(stderr, "Error opening %s\n", ppdev); exit (1); } /* opening and initialising the display */ dd = serdisp_init(ppd, "PCD8544", ""); if (!dd) { fprintf(stderr, "Error opening display.\nExiting ...\n\n".); exit(1); } /* turning on backlight */ serdisp_feature(dd, FEATURE_BACKLIGHT, FEATURE_YES); /* clearing the display */ serdisp_clear(dd); /* draw a border (only internal display buffer is affected!!) */ for (i = 0; i < serdisp_getwidth(dd); i++) { serdisp_setpixel(dd, i, 0, 1); serdisp_setpixel(dd, i, serdisp_getheight(dd)-1, 1); } for (i = 1; i < serdisp_getheight(dd)-1; i++) { serdisp_setpixel(dd, 0, i, 1); serdisp_setpixel(dd, serdisp_getwidth(dd)-1, 1); } /* commit changes -> update the display using the internal display buffer */ serdisp_update(dd); /* some delay */ usleep(100000); /* close the display */ serdisp_close(dd); /* release parallel port */ PP_close(ppd);