Commit Graph

1394 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 a13312d9a9 Display: introduce display queue.
Now we shouldn't experience wait cycles in i2c_write() during
typical display writes any longer. It should also distribute CPU
load of display writes a lot better.

Previously writing a line of text to the display would take
almost as long as it took to actually send it to the display,
because the I2C queue could hold only one transmission, which
effectively meant only one character. This could hold the main
loop for several milliseconds.

Now we queue characters, send them one by one, and return to the
main loop in between.

This costs 160 bytes program memory. Only 18 bytes RAM, because
the I2C queue was reduced accordingly. Now:

  Program:  24456 bytes
     Data:   1543 bytes
   EEPROM:     32 bytes
2016-04-27 23:54:14 +02:00
Markus Hitter aabce8ed15 usb_serial.h: refine the note.
Thanks for the hint, @phord.
2016-04-27 23:53:42 +02:00
Markus Hitter 9b2c5e61c6 dda_lookahead.c: replace Windows EOL by the usual Unix EOL.
No functional change.
2016-04-26 17:41:21 +02:00
Markus Hitter 0d91b44436 dda_lookahead.c: remove redundant macro.
No functional change.
2016-04-26 17:41:07 +02:00
Markus Hitter c9056e376d dda_lookahead.c: remove two obsolete #includes.
No functional change.
2016-04-26 17:40:57 +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 a47c4b40df Display: add a primitive status display.
This isn't pretty at all, but it shows the principle.
Unfortunately it also exploits a bug in the I2C sending mechanism,
I2C sending hangs a few seconds after reset.
2016-04-26 15:36:11 +02:00
Markus Hitter 62190caaa5 USB Serial: note about all the redundant code. 2016-04-26 15:35:40 +02:00
Markus Hitter e633222cd3 Make message/text sending aware of the sending destination.
Point of this change is to allow using these functions for
writing to the display, too, without duplicating all the code.

To reduce confusion, functions were renamed (they're no longer
'serial', after all:

  serwrite_xxx() -> write_xxx()
  sersendf_P()   -> sendf_P()

To avoid changing all the existing code, a couple of macros
with the old names are provided. They might even be handy as
convenience macros.

Nicely, this addition costs no additional RAM. Not surprising, it
costs quite some binary size, 278 bytes. Sizes now:

Program:  24058 bytes      168%       79%       38%       19%
   Data:   1525 bytes      149%       75%       38%       19%
 EEPROM:     32 bytes        4%        2%        2%        1%

Regarding USB Serial: code was adjusted without testing on
hardware.
2016-04-26 15:23:15 +02:00
Markus Hitter 6577578051 Display: introduce display_writechar().
You see where the journey is going? This is the equivalent to the
function to write a character to the serial line, so we can
basically swap these two in other functions.
2016-04-26 14:45:59 +02:00
Markus Hitter bb8d6e0ad2 Display: create and use display_set_cursor().
Having this in a seperate function will be helpful later.
2016-04-26 14:31:56 +02:00
Markus Hitter cec45a2fec Display: create infrastructure for distinct displays.
Dropped all the funtions for specific messages because plans on
how to handle this have changed.
2016-04-26 14:31:47 +02:00
Markus Hitter 9dd53a1722 display_ssd1306.c: support monospaced fonts.
Monospaced fonts require a bit less space, right now it saves a
nice 110 bytes binary size.

Actually, the distinction between monospaced and proportional
fonts was in font.h already, so not supporting them was a bug.
But so far we have no monospaced font, so nobody noticed.
2016-04-26 14:29:39 +02:00
Markus Hitter 455b07eb6e display_ssd1306.c: read symbol index only once.
Saves just 2 bytes, but more than nothing.
2016-04-26 14:29:39 +02:00
Ruslan Popov e3fd9eaea7 Display: first text on OLED.
Note by Traumflug: this code was written by Ruslan Popov a lot
earlier already. I picked it to i2c_test.c to get "something"
visible running. This is the commit finally adjusted to the new
display infrastructure.
2016-04-26 14:29:36 +02:00
Markus Hitter 5f95784c0b Display: introduce font.h, paraphrase handling distinct fonts.
While this could also be done properly now, with a couple of
additional fonts, this would require quite some time. However,
it's more important to have at least one display working now,
rather than having a ton of sophisticated eye-candy, which isn't
even user-visible, because the upper layers are still missing.
2016-04-26 14:13:20 +02:00
Ruslan Popov cb696701f8 Display: add font 8x4 ASCII. 2016-04-26 14:13:20 +02:00
Markus Hitter a97ec8a376 Display: introduce displaybus.h.
This is a broker for mapping display bus calls to the bus actually
in use.
2016-04-26 14:13:15 +02:00
Markus Hitter 8c110da610 Makefile-AVR: correct reported program sizes.
What 'make size' previously reported was misleading, because
it didn't count the .data section as Flash usage. However, this
section is actually written to Flash.

The .data section holds the data needed for inititalising
variables. As such it counts to both, Flash and RAM usage.

Nice verification: reported 'Program' size now matches upload
size reported by avrdude exactly.

There's now the tool 'avr-size', which makes reading such stuff
much easier:

  avr-size -C build/teacup.elf

Example output:

  AVR Memory Usage
  ----------------
  Device: Unknown

  Program:   23704 bytes
  (.text + .data + .bootloader)

  Data:       1543 bytes
  (.data + .bss + .noinit)

  EEPROM:       32 bytes
  (.eeprom)
2016-04-21 19:19:29 +02:00
Markus Hitter 13c76244b6 Configtool: allow and use user friendly names for choices.
So far for choices based on boolean sets, only, because choices
for values typically need no more readable names.

This elegantly removes the somewhat ugly check for '(', too.
2016-04-20 22:02:10 +02:00
Markus Hitter a0fa1bbeb6 displaypage.py: disable display type choice if there is no bus. 2016-04-20 22:02:10 +02:00
Markus Hitter 2541d7a82c Configtool: introduce boolChoices.
This handles sets of booleans "magically" and is now used for
DISPLAY_BUS and DISPLAY_TYPE.
2016-04-20 22:02:10 +02:00
Markus Hitter a95a1c8855 Configtool: record False boolean #defines, too.
This will be helpful for handling sets of booleans better.
2016-04-20 22:02:09 +02:00
Markus Hitter bdacd8c9bc Configtool: remove unused reCommDefBL and reCommDefBoolBL. 2016-04-20 22:02:09 +02:00
Markus Hitter 4645715f18 Configtool: make KINEMATICS a set of booleans, too.
Reasons:

 - Less code, easier handling.

 - An entire case of configuration handling could be removed.

 - Better class-like encapsulation.
2016-04-20 22:02:07 +02:00
Markus Hitter 1fad0036a7 Configtool: replace DISPLAY_TYPE with a set of booleans, too.
Same reason, same procedure as the previous commit.
2016-04-20 22:00:47 +02:00
Markus Hitter 90969978df Configtool: replace DISPLAY_BUS parameter with a set of booleans.
Having a choice with a defined set of options is nice, but it
also requires these options to be #defined somewhere _before_
entering config.h. To keep class-like encapsulation, we'd need
two header files for each code unit, one for the options, another
one for the usual header.

That said, we use other examples of such options, e.g. CPU, F_CPU
or KINEMATICS. For CPU and F_CPU it works fine, because their
options are numbers or other values known by the compiler. For
KINEMATICS it kind of works, because this #define is used in only
one place ... and there it's suboptimal already, because no option-
set.

Anyways, I was unsure about this change and if it turns out to be
a poor decision later, it can be reverted.
2016-04-20 22:00:05 +02:00
Markus Hitter 4d37d35f29 Configtool: add debugging aid.
All comments, no functional change. One unused line of code
removed.
2016-04-20 21:56:54 +02:00
Ruslan Popov 212eca7f8e Configtool: add display page implementation.
Most work by Ruslan Popov, collected from various commits and
made compatible with regression tests by Traumflug.

Display test code is now enabled by #defining DISPLAY_BUS to
i2c_twi.
2016-04-20 21:56:39 +02:00
Ruslan Popov 071cb9067b Configtool: introduce a function for registering a page.
No functional and purely internal change, this should make adding
a page easier.
2016-04-20 21:49:33 +02:00
Markus Hitter fce7337e01 git-regtest: abort on regression test failure.
I wonder a bit why this wasn't done this way before ...
2016-04-20 21:46:37 +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 ecaab2423c I2C: describe configuration options more extensively.
No code change.
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 aab447567c I2C: rewrite demo to use program memory.
Advantages are apparent: much less RAM usage.

$ avr-size -C --mcu=atmega1284p build/teacup.elf
AVR Memory Usage
----------------
Device: atmega1284p

Program:   23750 bytes (18.1% Full)
(.text + .data + .bootloader)

Data:       2053 bytes (12.5% Full)
(.data + .bss + .noinit)

EEPROM:       32 bytes (0.8% Full)
(.eeprom)

$ avr-size -C --mcu=atmega1284p build/teacup.elf
AVR Memory Usage
----------------
Device: atmega1284p

Program:   23720 bytes (18.1% Full)
(.text + .data + .bootloader)

Data:       1543 bytes (9.4% Full)
(.data + .bss + .noinit)

EEPROM:       32 bytes (0.8% Full)
(.eeprom)

A note about size reports: what 'make size' currently reports is
a bit misleading, because it doesn't count the .data section as
Flash usage. However, this section is actually written there as
it's the section which initialises RAM.
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 1daaad2447 Serial: move ringbuffer logic into a separate header file.
This way we can re-use these macros elsewhere.
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