summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-03-13 00:13:58 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-03-13 00:13:58 +0100
commitfbfffc2193fc9e58333c6f11f16ded8191767e0f (patch)
tree06d8964d201593ca4ca9fe45dc0e84e4ea0fe7f1
parent0ee7d763090e32118829fb897ff8ad4261c3c27e (diff)
storage: shave off one i2c_read() in load, remove now unneeded header storage
-rw-r--r--src/storage.cc18
-rw-r--r--src/storage.h1
2 files changed, 10 insertions, 9 deletions
diff --git a/src/storage.cc b/src/storage.cc
index 7cf404b..05a1d44 100644
--- a/src/storage.cc
+++ b/src/storage.cc
@@ -262,19 +262,21 @@ void Storage::load(uint8_t idx, uint8_t *data)
{
i2c_read(0, 1 + idx, 1, &page_offset);
- // always read headers
- i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32, 4, data);
-
- header[0] = data[0];
- header[1] = data[1];
-
- // always read 128 bytes - the system will ignore trailing bytes
- i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4, 128, data + 4);
+ /*
+ * Unconditionally read 132 bytes. The data buffer must hold at least
+ * 132 bytes anyways, and this way we can save one I2C transaction. If
+ * there is any speed penalty cause by this I wasn't able to notice it.
+ * Also note that the EEPROM automatically wraps around when the end of
+ * memory is reached, so this edge case doesn't need to be accounted for.
+ */
+ i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32, 132, data);
}
void Storage::loadChunk(uint8_t chunk, uint8_t *data)
{
uint8_t this_page_offset = page_offset + (4 * chunk);
+
+ // Note that we do not load headers here -> 128 instead of 132 bytes
i2c_read(1 + (this_page_offset / 8), (this_page_offset % 8) * 32 + 4, 128, data);
}
diff --git a/src/storage.h b/src/storage.h
index c72b766..cf66730 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -16,7 +16,6 @@ class Storage {
private:
uint8_t num_anims;
uint8_t page_offset;
- uint8_t header[2];
uint8_t first_free_page;
uint8_t i2c_start_write(void);
uint8_t i2c_start_read(void);