Commit Graph

17 Commits

Author SHA1 Message Date
Markus Hitter 6e8067208e i2c.c: simplify error handling.
If all error conditions are handled the same, there's not much
point to use distinct code for each of them.

Also, handle collisions like the other error conditions.

This saves a nice 52 bytes of program memory.

  Program:  24404 bytes
     Data:   1543 bytes
   EEPROM:     32 bytes
2016-04-27 23:54:14 +02:00
Markus Hitter ea2a10fa76 i2c.c: recover from error conditions.
This is
- clearing 'i2c_should_end', so i2c_write() doesn't hang and
- draining the buffer on errors.

This way we loose the remaining transmission, which is typically
half a character, but we no longer stall the entire firmware main
loop.

Actually, such error conditions are surprisingly frequent, at
least on the test hardware. Now they result in some flickering
of the displayed numbers.
2016-04-26 15:36:11 +02:00
Markus Hitter dcc970d2fd i2c.c: add debugging aid.
No functional change.
2016-04-26 15:36:11 +02:00
Markus Hitter 0f224afac8 I2C: warn when trying to use untested code.
No code change.
2016-04-20 21:42:45 +02:00
Markus Hitter eb21ac7485 I2C: wrap the currently abandoned code for reading properly.
Not removed entirely, because it might be needed later.
2016-04-20 21:15:12 +02:00
Markus Hitter 8e8946dd37 I2C: remove parameter 'address' from i2c_write().
As we usually talk to one device only, there's not much point in
carrying around the address all the time. Surprise, this saves
only 16 bytes binary size despite of heavy usage.
2016-04-20 21:15:11 +02:00
Markus Hitter 55be863b84 I2C: provide a busy-detection.
Nowhere used so far, so no binary size change.
2016-04-20 21:15:11 +02:00
Markus Hitter 2298973343 I2C: distinguish between individual transmissions.
So far calling code had to wait long enough between individual
transmissions to make sure they end up in distinc ones. Now
calling code can stuff as fast as it wants, i2c_write() takes
care of the distinction.
2016-04-20 21:15:11 +02:00
Markus Hitter d088930664 I2C: use ringbuffer for data buffering.
This removes the need to write in full blocks, so data can be
sent from loops and/or program memory.

This capability allows to clear the screen without too much
effort, see i2c_test.c.

Still two weaknesses left:

 - Transmission end is currently detected by ringbuffer becoming
   empty, so delays are needed to make sure a transmission is
   completed before the next one is sent to the buffer.

 - Error handling is still only half existent. Any error on the
   bus will stop I2C entirely. A recovery strategy is required.

Sizes show, taking into account the additional screen clearing
code, no significant change:

    FLASH  : 23216 bytes
    RAM    :  2052 bytes
    EEPROM :    32 bytes
2016-04-20 21:15:11 +02:00
Markus Hitter e71eab04d0 I2C: join these two send commands.
Splitting them is no longer neccessary.
2016-04-20 21:15:11 +02:00
Markus Hitter 61ab29e6b6 I2C: no need to initialise with an address in master mode. 2016-04-20 21:15:11 +02:00
Markus Hitter 194e5d5b98 I2C: use pinio.h to handle pins.
This removes the need for four user configuration options.
2016-04-20 21:15:11 +02:00
Markus Hitter 6ef9e1a2ee I2C: encapsulate bus states.
No functional changes.
2016-04-20 21:15:11 +02:00
Markus Hitter 061225f72d I2C: get rid of these unimplemented error handlers.
Naively restarting I2C immediately is certainly not the solution
and just leads to an interrupt flood. As I2C is currently meant
to drive displays, where successful data transmission isn't
crucial, we now simply stop transmission on errors.

This saves another 80 bytes binary size:

    FLASH  : 23094 bytes
    RAM    :  2051 bytes
    EEPROM :    32 bytes
2016-04-20 21:15:11 +02:00
Markus Hitter 3ced6aae4a I2C: handling another master sending is part of slave mode.
At least, avr-libc says so. Saves some 36 bytes in interrupt
context.
2016-04-20 21:15:11 +02:00
Markus Hitter e4067dc235 I2C: use avr-libc bus status names.
No need to reinvent the wheel.
2016-04-20 21:15:11 +02:00
Ruslan Popov 619560c112 I2C: initial support.
This commit squashes in some fixes found after debugging on the
topic branch. Test code by Traumflug, collected from Ruslan's
code on the topic branch.

Before, same as now without I2C:

    FLASH  : 22408 bytes
    RAM    :  1393 bytes
    EEPROM :    32 bytes

Now with I2C:

    FLASH  : 23224 bytes
    RAM    :  2057 bytes
    EEPROM :    32 bytes

This totals to some 800 bytes with a whole lot of test code, so
implementation is pretty small :-)
2016-04-20 21:15:11 +02:00