~toykeeper/flashlight-firmware/fsm

« back to all changes in this revision

Viewing changes to ToyKeeper/spaghetti-monster/fsm-eeprom.c

  • Committer: Selene Scriven
  • Date: 2020-05-14 22:49:14 UTC
  • Revision ID: bzr@toykeeper.net-20200514224914-kibqnxybuuku65me
fixed eeprom_wl functions on attiny1634
(didn't build before, due to a data type mismatch)

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
 
68
68
#ifdef USE_EEPROM_WL
69
69
uint8_t eeprom_wl[EEPROM_WL_BYTES];
70
 
EEP_OFFSET_T eep_wl_prev_offset;
 
70
uint8_t * eep_wl_prev_offset;
71
71
 
72
72
uint8_t load_eeprom_wl() {
73
73
    #ifdef LED_ENABLE_PIN
77
77
    cli();
78
78
    // check if eeprom has been initialized; abort if it hasn't
79
79
    uint8_t found = 0;
80
 
    EEP_OFFSET_T offset;
 
80
    uint8_t * offset;
81
81
    for(offset = 0;
82
 
        offset < EEP_WL_SIZE - EEPROM_WL_BYTES - 1;
 
82
        offset < (uint8_t *)(EEP_WL_SIZE - EEPROM_WL_BYTES - 1);
83
83
        offset += (EEPROM_WL_BYTES + 1)) {
84
 
        if (eeprom_read_byte((uint8_t *)offset) == EEP_MARKER) {
 
84
        if (eeprom_read_byte(offset) == EEP_MARKER) {
85
85
            found = 1;
86
86
            eep_wl_prev_offset = offset;
87
87
            break;
91
91
    if (found) {
92
92
        // load the actual data
93
93
        for(uint8_t i=0; i<EEPROM_WL_BYTES; i++) {
94
 
            eeprom_wl[i] = eeprom_read_byte((uint8_t *)(offset+1+i));
 
94
            eeprom_wl[i] = eeprom_read_byte(offset+1+i);
95
95
        }
96
96
    }
97
97
    sei();
105
105
 
106
106
    cli();
107
107
    // erase old state
108
 
    EEP_OFFSET_T offset = eep_wl_prev_offset;
 
108
    uint8_t * offset = eep_wl_prev_offset;
109
109
    for (uint8_t i = 0; i < EEPROM_WL_BYTES+1; i ++) {
110
 
        eeprom_update_byte((uint8_t *)offset+i, 0xFF);
 
110
        eeprom_update_byte(offset+i, 0xFF);
111
111
    }
112
112
 
113
113
    // save new state
114
114
    offset += EEPROM_WL_BYTES+1;
115
 
    if (offset > EEP_WL_SIZE-EEPROM_WL_BYTES-1) offset = 0;
 
115
    if (offset > (uint8_t *)(EEP_WL_SIZE-EEPROM_WL_BYTES-1)) offset = 0;
116
116
    eep_wl_prev_offset = offset;
117
117
    // marker byte
118
118
    // FIXME: write the marker last, to signal completed transaction
119
 
    eeprom_update_byte((uint8_t *)offset, EEP_MARKER);
 
119
    eeprom_update_byte(offset, EEP_MARKER);
120
120
    offset ++;
121
121
    // user data
122
122
    for(uint8_t i=0; i<EEPROM_WL_BYTES; i++, offset++) {
123
 
        eeprom_update_byte((uint8_t *)(offset), eeprom_wl[i]);
 
123
        eeprom_update_byte(offset, eeprom_wl[i]);
124
124
    }
125
125
    sei();
126
126
}