Skip to content

refactor transaction code #164

@mzero

Description

@mzero

The code to manage the transactions, and to send commands and data is duplicated in several places. The code contains some tricky branches because of support for various connection methods, and uses several macros.

Furthermore, code that sends commands is hard to read because device commands are often split between calls that send fixed PROGMEM arrays, and run-time bytes.

I propose to clean this all up with an internal Transaction class that places all the code for starting and stopping the transaction, as well as managing the byte sending process, in one place.

The current working code is here:
https://github.com/mzero/Adafruit_SSD1306/commits/transaction

The resulting version is:

  • makes code that sends commands much more readable, see begin() for an example
  • ensures that transactions are always properly framed
  • makes multi-command transactions more efficient (existing code often excessively starts/ends I2C transactions)
  • and as if that weren't enough, compiles smaller and takes less total flash: Saves 280 bytes in the OLED_Featherwing sketch, 672 in the 128x32 i2c sketch, and 356 in my personal project's sketch.

Notes:

  1. I've kept the various macros at the top of the file, but since these are each now used only in one place (with one exception), they clearly could be removed and folded into the Transaction class.
  2. I've added a more useful set of methods for user access to sending SSD1306 commands. The prior single exposed function I don't think worked if you needed to send a multibyte command (since it would start and stop a transaction for each byte).
  3. I think this code would enable @grafalex82 's device driver refactor to integrate more smoothly. (see Extracting HW specific code to a driver class #87), since his driver class would be reduced to just three methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions