The Cosa I2C slave LCD driver is now completed. The initial design has been refactored to a new Virtual LCD class (VLCD) which allows any Cosa LCD device driver to be connected (not just the HD44780 driver). The VLCD class contains two parts; 1) the client part acts as a LCD proxy, translating LCD API calls to I2C messages, 2) the server part acts as an adapter that decodes the I2C messages and calls the LCD implementation.
Below is the CosaLCDslave sketch. It uses the new Virtual LCD class and binding to the HD44780 driver with the 4-bit parallel port IO. This sketch is compiled for an ATtiny84 in the example above but may be compiled for any Cosa supported Arduino.
#include "Cosa/Watchdog.hh"
#include "Cosa/LCD/Driver/HD44780.hh"
#include "Cosa/VLCD.hh"
// Use a 4-bit parallel port for the HD44780 LCD (16X2 default)
HD44780::Port port;
HD44780 lcd(&port);
// And use the LCD for the implementation of the Virtual LCD slave
VLCD::Slave vlcd(&lcd);
void setup()
{
Watchdog::begin();
lcd.begin();
vlcd.begin();
}
void loop()
{
Event event;
Event::queue.await(&event);
event.dispatch();
}
The benchmark CosaLCDspeed.ino binds to the Virtual LCD and runs the measurements. It is the Arduino Nano in the picture above that runs this sketch.. See the code on github.
https://github.com/mikaelpatel/Cosa/blob/master/examples/TWI/CosaLCDslave/CosaLCDslave.ino
By implementing the IOStream::Device methods puts(), puts_P() and write() the performance can be boosted to 50-98% of the performance of the I2C IO expander at 400kHz. Below are some results from the benchmarking. The first table shows the performance (operations per second/frames per second), and compares the 4-bit and I2C IO expander implementations (at 100khz and 400 khz).
The above results are used as the baseline for the comparison with the second table below which is the ATtiny84 (internal clock 8Mhz) compiled version and the VLCD version. The comparison is between the 4-bit implementation and then the VLCD implementation (with optimizations).
VLCD may be viewed as a "template" for how to construct I2C slave devices.
http://dl.dropboxusercontent.com/u/993383/Cosa/doc/html/d1/d1f/classVLCD.html
Cheers!