Cosa/Boosting LCD 1602 performance (7X SR4W, 6.5X 4-bit parallel, 1.7-2.3X I2C)

Here are the numbers from the latest improvements of the Cosa LCD device driver. The table also contains the ratio compared to the New LiquidCrystal Library benchmark.
https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home#!performance-and-benchmakrs
Please note that the ATtiny84/85 benchmarking uses the internal 8Mhz clock.

The following I2C optimizations are included:

  1. Packaging I2C IO expander updates to a single TWI message for putchar(). To send a byte (data or command) to the LCD four TWI messages (address and 1 byte data) was previously sent (LiquidCrystal_I2C). This is compressed to a single TWI message with address and the four bytes needed to send the byte (via the 4-bit parallel interface) to the LCD.

  2. Packaging multiple encoded bytes into a single message for puts(). Applying the first optimization to a sequence of characters sent to the I2C IO expander. This allows (again) the TWI address to be removed. The default internal buffer size is 32 bytes. This gives 7 byte address reduction for an 8 byte string.

The second optimization shows up in the puts() to puts_P() ratio as program strings may contain control characters and are not compressed. Ratio 77/60 = 1.28X further improvement. This also shows up as an improvement when printing numbers (dec/bin in benchmark).

For ATmega with TWI hardware the processor will go into sleep mode during the wait for the completion of the I2C operation (write). A further optimization would be to allow the processor to continue and only sync when a new operation is issued. This would require some additional buffering. The Cosa TWI driver allows asynchronous calls but this feature is not yet used by the LCD driver. The current ATtiny USI based TWI is a bit-banging implementation with micro-second level delays. A redesign of the Cosa RTC (micro second level timer) for ATtiny is necessary to allow asynchronous TWI operation with ISR. This is due to a timer conflict.

The last column in the table above contains the results when using an ATtiny84 as an I2C LCD adapter and reducing the I2C message communication even further. The improvement is then 2.3X.

Read more on the blog Cosa: Object-Oriented LCD management

A port adapter for SR (74HC595) will be added to the Cosa LCD device driver library soon. Waiting for some more hardware to play with :wink:

Cheers!