summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2016-03-12 21:46:43 +0100
committerDaniel Friesel <derf@finalrewind.org>2016-03-12 21:46:43 +0100
commit31d40607ceaae5dcb78f41fcfe7dbd777f75d485 (patch)
tree58699d4a19421c956aa73071910fe2dce9a23cca
parentad34553b5afe0e38fa06e372fdf616d540ceb888 (diff)
preparations for >255byte patterns
the rest of the code (display etc.) isn't well-tested yet and will follow in another commit
-rw-r--r--src/static_patterns.h4
-rw-r--r--src/storage.cc23
-rw-r--r--src/storage.h11
3 files changed, 34 insertions, 4 deletions
diff --git a/src/static_patterns.h b/src/static_patterns.h
index 5df47a0..e91c219 100644
--- a/src/static_patterns.h
+++ b/src/static_patterns.h
@@ -13,6 +13,10 @@
#include <avr/pgmspace.h>
+/*
+ * Note: Static patterns must not be longer than 128 bytes (headers excluded)
+ */
+
const uint8_t PROGMEM shutdownPattern[] = {
0x20, 0x40,
0x01, 0x0f,
diff --git a/src/storage.cc b/src/storage.cc
index bd35780..e965589 100644
--- a/src/storage.cc
+++ b/src/storage.cc
@@ -260,12 +260,27 @@ bool Storage::hasData()
void Storage::load(uint8_t idx, uint8_t *data)
{
- uint8_t page_offset;
- uint8_t header[2];
i2c_read(0, 1 + idx, 1, &page_offset);
- i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32, 2, header);
- i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32, header[1] + 4, data);
+ // always read headers
+ i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32, 4, data);
+
+ header[0] = data[0];
+ header[1] = data[1];
+
+ if (header[0] & 0x0f) {
+ // read whole byte block
+ i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4, 128, data + 4);
+ i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4 + 128, 128, data + 4 + 128);
+ } else {
+ i2c_read(1 + (page_offset / 8), (page_offset % 8) * 32 + 4, header[1], data + 4);
+ }
+}
+
+void Storage::loadChunk(uint8_t chunk, uint8_t *data)
+{
+ uint8_t this_page_offset = page_offset + (4 * chunk);
+ i2c_read(1 + (this_page_offset / 8), (this_page_offset % 8) * 32 + 4, 128, data);
}
void Storage::save(uint8_t *data)
diff --git a/src/storage.h b/src/storage.h
index cb99afd..e7feedb 100644
--- a/src/storage.h
+++ b/src/storage.h
@@ -15,6 +15,8 @@
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);
@@ -83,6 +85,15 @@ class Storage {
void load(uint8_t idx, uint8_t *data);
/**
+ * Load partial pattern chunk (without header) from EEPROM.
+ *
+ * @param chunk 128 byte-offset inside pattern (starting with 0)
+ * @param data pointer to data structure for the pattern. Must be
+ * at least 128 bytes
+ */
+ void loadChunk(uint8_t chunk, uint8_t *data);
+
+ /**
* Save (possibly partial) pattern on the EEPROM. 32 bytes of
* dattern data will be read and stored, regardless of the
* pattern header.