I’m using GCC/Eclipse for the LPC2148, and I’d like to integrate my own output devices so I can treat them like a standard stdio item. I want to be able to do something like:
fHnd = fopen("I2C_LCD","+r");
fputc('x',fHnd);
And have that call my I/O open function, and my function for sending a character.
I already have all of my own IO functions written for UART support on my development board, (and I hope to make LCD over I2C soon). I just want to use the standard C way of getting data to/from them.
I considered ‘wrapping’ everything and using ‘xfopen’ to forward commands to ‘myfopen’ or ‘fopen’ based on the input, but that is crufty. Can anyone suggest a good way to do this, or point me in the right direction to someplace on how I could do this?
Can I even do this without recompiling the gcc libraries?
This (stdio) is a linker-level thing. One way to do it is to use newlib and provide a device table with your low-level IO functions (stdin, stdout, stderr, etc). I found this guy’s newlib-based tarball really helpful as an example:
You can also use funopen() or fopencookie(), which aren’t completely std parts of stdio, but is reasonably common and sounds like it does what you want. (glibc and uclibc both have fopencookie().)
Hi wiml. Can you please point me to an example of using fopencookie(), it’s really hard to find any examples of how to set up cookie IO out there. Thanks!