/*--------------------------------------------*/ void SaveLoad_Class::saveCVDpotVals(byte val1, byte val2, byte val3, byte val4) { eepromWrite(cvCalibrators_pos, val1, false); eepromWrite(cvCalibrators_pos + 1, val2, false); eepromWrite(cvCalibrators_pos + 2, val3, false); eepromWrite(cvCalibrators_pos + 3, val4, false); }
bool eeCopyModel(uint8_t dst, uint8_t src) { eeCheck(true); uint32_t eepromWriteSourceAddr = eepromHeader.files[src+1].zoneIndex * EEPROM_ZONE_SIZE; uint32_t eepromWriteDestinationAddr = eepromHeader.files[dst+1].zoneIndex * EEPROM_ZONE_SIZE; // erase blocks eepromEraseBlock(eepromWriteDestinationAddr); eepromEraseBlock(eepromWriteDestinationAddr+EEPROM_BLOCK_SIZE); // write model for (int pos=0; pos<EEPROM_ZONE_SIZE; pos+=EEPROM_BUFFER_SIZE) { eepromRead(eepromWriteSourceAddr+pos, eepromWriteBuffer, EEPROM_BUFFER_SIZE); eepromWrite(eepromWriteDestinationAddr+pos, eepromWriteBuffer, EEPROM_BUFFER_SIZE); } // write FAT eepromHeader.files[dst+1].exists = 1; eepromIncFatAddr(); eepromWriteState = EEPROM_WRITE_NEW_FAT; eepromWriteWait(); modelHeaders[dst] = modelHeaders[src]; return true; }
void oscSetAutosendInterval(uint32_t interval) { if (interval != osc.autosendPeriod && interval > 1 && interval < OSC_AUTOSEND_MAX_INTERVAL) { osc.autosendPeriod = interval; eepromWrite(EEPROM_OSC_ASYNC_INTERVAL, interval); } }
void write16(const u32 address, const u16 value) { switch (address >> 24) { case 8: if (address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8) { rtcWrite(address, value); } break; case 13: if (game.hasEEPROM()) { eepromWrite(address, (u8)value); } break; case 14: if (game.hasSRAM()) { sramWrite(address, (u8)value); } else if (game.hasFlash()) { flashWrite(address, (u8)value); } break; default: break; } }
void oscUdpSetListenPort(int port) { if (osc.udpListenPort != port) { osc.udpListenPort = port; eepromWrite(EEPROM_OSC_UDP_LISTEN_PORT, port); } }
void oscSetAutosendDestination(OscChannel oc) { if (osc.autosendDestination != oc) { osc.autosendDestination = oc; eepromWrite(EEPROM_OSC_ASYNC_DEST, oc); } }
void oscUdpSetReplyPort(int port) { if (osc.udpReplyPort != port) { osc.udpReplyPort = port; eepromWrite(EEPROM_OSC_UDP_SEND_PORT, port); } }
/*--------------------------------------------*/ void SaveLoad_Class::saveUserButtons() { for(uint8_t i = 0; i < 4; i++) { uint8_t v = utils->getUserButtonVal(i); eepromWrite(userButtons_pos + i, v, false); // EEPROM.write(userButtons_pos + i, v); } }
void eepromFormat() { eepromFatAddr = 0; eepromHeader.mark = EEPROM_MARK; eepromHeader.index = 0; for (int i=0; i<EEPROM_MAX_FILES; i++) { eepromHeader.files[i].exists = 0; eepromHeader.files[i].zoneIndex = i+1; } eepromEraseBlock(0); eepromEraseBlock(EEPROM_BLOCK_SIZE); eepromWrite(0, (uint8_t *)&eepromHeader, sizeof(eepromHeader)); }
/*--------------------------------------------*/ void SaveLoad_Class::load(bool lcdWrite) { utils->currentPatch = currentLoad; if(currentLoad == 0) { utils->newpatches->makeNewPatch(false); writeLoad_lcd(true); // eepromWrite(lastPatch_pos, currentLoad, false); return; } utils->patchChanged = false; utils->patchChangedSincePerformMode = true; utils->getLoadArray(utils->currentPatch); for(int h=0; h<4; h++) utils->curves->curvesVals->objectAt(h)->performModeVal = loadArrayRead(utils->loadArray[curveMode_pos + h], false); utils->effects->setCurrentEffect( loadArrayRead(utils->loadArray[effectMode_pos], false)); for(int i=0; i<4; i++) utils->gates->gateVals->objectAt(i)->performModeVal = loadArrayRead(utils->loadArray[gateType_pos + i], false); for(int j=0; j<4; j++) utils->lags->framerateVals->objectAt(j)->performModeVal = loadArrayRead(utils->loadArray[framerateArray_pos + j], false); for(int k=0; k<4; k++) utils->links->linkToVals->objectAt(k)->performModeVal = loadArrayRead(utils->loadArray[linkToArray_pos + k], true); for(int l=0; l<4; l++) utils->links->linkTypeVals->objectAt(l)->performModeVal = loadArrayRead(utils->loadArray[linkFunctionArray_pos + l], false); for(int m=0; m<4; m++) utils->sweetspots->startVals->objectAt(m)->performModeVal = loadArrayRead(utils->loadArray[sweetspotPos_pos + m], false); for(int n=0; n<4; n++) utils->quantizes->stepsVals->objectAt(n)->performModeVal = loadArrayRead(utils->loadArray[quantizeSteps_pos + n], false); for(int o=0; o<4; o++) utils->sweetspots->endVals->objectAt(o)->performModeVal = loadArrayRead(utils->loadArray[sweetspotSize_pos + o], false); for(int p=0; p<4; p++) fu2->dpotVals[p] = fu2->dpotVals2b[p] = loadArrayRead(utils->loadArray[dpotVals_pos + p], false); utils->voltagegates->threshold->performModeVal = loadArrayRead(utils->loadArray[gateVoltageTrigger_pos], false); // for(int h=0; h<4; h++) utils->curves->curvesVals->objectAt(h)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + curveMode_pos + h, false); // utils->effects->setCurrentEffect( eepromRead((bytesPerPreset * currentLoad) + effectMode_pos, false)); // for(int i=0; i<4; i++) utils->gates->gateVals->objectAt(i)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + gateType_pos + i, false); // for(int j=0; j<4; j++) utils->lags->framerateVals->objectAt(j)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + framerateArray_pos + j, false); // for(int k=0; k<4; k++) utils->links->linkToVals->objectAt(k)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + linkToArray_pos + k, true); // for(int l=0; l<4; l++) utils->links->linkTypeVals->objectAt(l)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + linkFunctionArray_pos + l, false); // for(int m=0; m<4; m++) utils->sweetspots->startVals->objectAt(m)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + sweetspotPos_pos + m, false); // for(int n=0; n<4; n++) utils->quantizes->stepsVals->objectAt(n)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + quantizeSteps_pos + n, false); // for(int o=0; o<4; o++) utils->sweetspots->endVals->objectAt(o)->performModeVal = eepromRead((bytesPerPreset * currentLoad) + sweetspotSize_pos + o, false); // for(int p=0; p<4; p++) fu2->dpotVals[p] = fu2->dpotVals2b[p] = eepromRead((bytesPerPreset * currentLoad) + dpotVals_pos + p, false); // utils->voltagegates->threshold->performModeVal = eepromRead((bytesPerPreset * currentLoad) + gateVoltageTrigger_pos, false); utils->initHoldPots(); if(lcdWrite) writeLoad_lcd(true); // EEPROM.write(lastPatch_pos, currentLoad); eepromWrite(lastPatch_pos, currentLoad, false); }
static void dIMUWriteCalib(void) { #ifdef DIMU_HAVE_EEPROM char *lineBuf; uint8_t *buf; int n; int i, j, k; if (!(lineBuf = (char *)aqCalloc(128, sizeof(char)))) { AQ_NOTICE("DIMU: Error writing to EEPROM, cannot allocate memory.\n"); return; } buf = eepromOpenWrite(); k = 0; for (i = 0; i < sizeof(dImuCalibParameters) / sizeof(uint16_t); i++) { n = configFormatParam(lineBuf, dImuCalibParameters[i]); for (j = 0; j < n; j++) { buf[k++] = lineBuf[j]; if (k == DIMU_EEPROM_BLOCK_SIZE) { eepromWrite(); k = 0; } } } if (k != 0) eepromWrite(); if (lineBuf) aqFree(lineBuf, 128, sizeof(char)); AQ_NOTICE("DIMU: wrote calibration parameters to EEPROM\n"); eepromClose(); #endif }
//EEPROM section is 0x31 void instrCall_EEPROM(char instruction, char* data, char dataLength) { switch (instruction) { case EEPROM_WRITE: { eepromWrite(data, dataLength); //only writes the first byte break; } case EEPROM_READ: { eepromRead(data); break; } } }
void write8(const u32 address, const u8 value) { switch (address >> 24) { case 13: if (game.hasEEPROM()) { eepromWrite(address, value); } break; case 14: if (game.hasSRAM()) { sramWrite(address, value); } else if (game.hasFlash()) { flashWrite(address, value); } break; default: break; } }
/*--------------------------------------------*/ void SaveLoad_Class::save() { utils->currentPatch = currentSave; utils->patchChanged = false; for(int h=0; h<4; h++) eepromWrite((bytesPerPreset * currentSave) + curveMode_pos + h, utils->curves->curvesVals->objectAt(h)->performModeVal, false); eepromWrite( (bytesPerPreset * currentSave) + effectMode_pos, utils->effects->currentEffect, false); for(int i=0; i<4; i++) eepromWrite((bytesPerPreset * currentSave) + gateType_pos + i, utils->gates->gateVals->objectAt(i)->performModeVal, false); for(int j=0; j<4; j++) eepromWrite((bytesPerPreset * currentSave) + framerateArray_pos + j, utils->lags->framerateVals->objectAt(j)->performModeVal, false); for(int k=0; k<4; k++) eepromWrite((bytesPerPreset * currentSave) + linkToArray_pos + k, utils->links->linkToVals->objectAt(k)->performModeVal, true); for(int l=0; l<4; l++) eepromWrite((bytesPerPreset * currentSave) + linkFunctionArray_pos + l, utils->links->linkTypeVals->objectAt(l)->performModeVal, false); for(int m=0; m<4; m++) eepromWrite((bytesPerPreset * currentSave) + sweetspotPos_pos + m, utils->sweetspots->startVals->objectAt(m)->performModeVal, false); for(int n=0; n<4; n++) eepromWrite((bytesPerPreset * currentSave) + quantizeSteps_pos + n, utils->quantizes->stepsVals->objectAt(n)->performModeVal, false); for(int o=0; o<4; o++) eepromWrite((bytesPerPreset * currentSave) + sweetspotSize_pos + o, utils->sweetspots->endVals->objectAt(o)->performModeVal, false); for(int p=0; p<4; p++) eepromWrite((bytesPerPreset * currentSave) + dpotVals_pos + p, fu2->dpotVals[p] + utils->cvInVals[p], false); eepromWrite( (bytesPerPreset * currentSave) + gateVoltageTrigger_pos, utils->voltagegates->threshold->performModeVal, false); // writeSave_lcd(true); // EEPROM.write(lastPatch_pos, currentSave); // eepromWrite(lastPatch_pos, currentSave, false); }
//Function to enter password or reset password void enterVault() { char display[8]; pass[0] = 0x00; pass[1] = 0x00; pass[2] = 0x00; if(buttonPressed(BTN_ROTARY)) //Section for entering password { UINT8 mem[3]; eepromRead(0x0000, 3, mem); //Read stored password from eeprom int y; y = 0; lcdInstruction("j"); lcdString(" Enter Key "); lcdInstruction("1;0H"); lcdString(" "); sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]); lcdString(display); while(TRUE) { int x; x = 0; if(buttonPressed(BTN_ROTARY)) y++; x = readRotaryKnob(); if(x != 0 || y == 3) { if(switchState(SWITCH_ROTARY)) x = x*8; pass[y] += x; lcdInstruction("j"); lcdString(" Enter Key "); lcdInstruction("1;0H"); lcdString(" "); sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]); lcdString(display); if(y == 3) { lcdInstruction("j"); if(mem[0] == pass[0] && mem[1] == pass[1] && mem[2] == pass[2]) //Compare passwords { lcdString(" Key Correct! "); while(!secondTick()); while(!secondTick()); vault(); //If correct go to data editing function break; } else { lcdString(" Key Incorrect! "); //If incorrect print message and break while(!secondTick()); while(!secondTick()); break; } } } } } else if(buttonPressed(BTN3)) //Section for resetting password { char data[17] = "abcdefghijklmnop"; //Used to reset data on eeprom int y; y = 0; lcdInstruction("j"); lcdString(" Reset Key "); lcdInstruction("1;0H"); lcdString(" "); sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]); lcdString(display); while(TRUE) { int x; x = 0; if(buttonPressed(BTN_ROTARY)) y++; x = readRotaryKnob(); if(x != 0 || y == 3) { if(switchState(SWITCH_ROTARY)) x = x*8; pass[y] += x; lcdInstruction("j"); lcdString(" Reset Key "); lcdInstruction("1;0H"); lcdString(" "); sprintf(display, "%2.2X-%2.2X-%2.2X", pass[0], pass[1], pass[2]); lcdString(display); if(y == 3) { lcdInstruction("j"); lcdString(" Key Reset! "); eepromWrite(0x0000, 3, pass); //store new password while(!secondTick()); while(!secondTick()); while(!secondTick()); eepromWrite(0x0003, 16, data); //reset data vault(); break; } } } } }
void eepromWriteProcess() { // TRACE("eepromWriteProcess(state=%d)", eepromWriteState); switch (eepromWriteState) { case EEPROM_ERASING_FILE_BLOCK1: case EEPROM_ERASING_FILE_BLOCK2: case EEPROM_WRITING_BUFFER: case EEPROM_ERASING_FAT_BLOCK: case EEPROM_WRITING_NEW_FAT: if (Spi_complete) { eepromWriteState = EepromWriteState(eepromWriteState + 1); } break; case EEPROM_ERASING_FILE_BLOCK1_WAIT: case EEPROM_ERASING_FILE_BLOCK2_WAIT: case EEPROM_WRITING_BUFFER_WAIT: case EEPROM_ERASING_FAT_BLOCK_WAIT: case EEPROM_WRITING_NEW_FAT_WAIT: if ((eepromReadStatus() & 1) == 0) { eepromWriteState = EepromWriteState(eepromWriteState + 1); } break; case EEPROM_START_WRITE: eepromWriteState = EEPROM_ERASING_FILE_BLOCK1; eepromEraseBlock(eepromWriteDestinationAddr, false); break; case EEPROM_ERASE_FILE_BLOCK2: eepromWriteState = EEPROM_ERASING_FILE_BLOCK2; eepromEraseBlock(eepromWriteDestinationAddr + EEPROM_BLOCK_SIZE, false); break; case EEPROM_WRITE_BUFFER: { EepromFileHeader * header = (EepromFileHeader *)eepromWriteBuffer; header->fileIndex = eepromWriteFileIndex; header->size = eepromWriteSize; uint32_t size = min<uint32_t>(EEPROM_BUFFER_SIZE-sizeof(EepromFileHeader), eepromWriteSize); memcpy(eepromWriteBuffer+sizeof(EepromFileHeader), eepromWriteSourceAddr, size); eepromWriteState = EEPROM_WRITING_BUFFER; eepromWrite(eepromWriteDestinationAddr, eepromWriteBuffer, sizeof(EepromFileHeader)+size, false); eepromWriteSourceAddr += size; eepromWriteDestinationAddr += sizeof(EepromFileHeader)+size; eepromWriteSize -= size; break; } case EEPROM_WRITE_NEXT_BUFFER: { uint32_t size = min<uint32_t>(EEPROM_BUFFER_SIZE, eepromWriteSize); if (size > 0) { memcpy(eepromWriteBuffer, eepromWriteSourceAddr, size); eepromWriteState = EEPROM_WRITING_BUFFER; eepromWrite(eepromWriteDestinationAddr, eepromWriteBuffer, size, false); eepromWriteSourceAddr += size; eepromWriteDestinationAddr += size; eepromWriteSize -= size; break; } else if (eepromFatAddr == 0 || eepromFatAddr == EEPROM_BLOCK_SIZE) { eepromWriteState = EEPROM_ERASING_FAT_BLOCK; eepromEraseBlock(eepromFatAddr, false); break; } } /* no break */ case EEPROM_WRITE_NEW_FAT: eepromWriteState = EEPROM_WRITING_NEW_FAT; eepromWrite(eepromFatAddr, (uint8_t *)&eepromHeader, sizeof(eepromHeader), false); break; case EEPROM_END_WRITE: eepromWriteState = EEPROM_IDLE; break; default: break; } }
const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name) { char *buf = reusableBuffer.modelsel.mainname; FIL restoreFile; UINT read; eeCheck(true); if (!sdMounted()) { return STR_NO_SDCARD; } strcpy(buf, STR_MODELS_PATH); buf[sizeof(MODELS_PATH)-1] = '/'; strcpy(&buf[sizeof(MODELS_PATH)], model_name); strcpy(&buf[strlen(buf)], STR_MODELS_EXT); FRESULT result = f_open(&restoreFile, buf, FA_OPEN_EXISTING | FA_READ); if (result != FR_OK) { return SDCARD_ERROR(result); } if (f_size(&restoreFile) < 8) { f_close(&restoreFile); return STR_INCOMPATIBLE; } result = f_read(&restoreFile, (uint8_t *)buf, 8, &read); if (result != FR_OK || read != 8) { f_close(&restoreFile); return SDCARD_ERROR(result); } uint8_t version = (uint8_t)buf[4]; if (*(uint32_t*)&buf[0] != O9X_FOURCC || version < FIRST_CONV_EEPROM_VER || version > EEPROM_VER || buf[5] != 'M') { f_close(&restoreFile); return STR_INCOMPATIBLE; } if (eeModelExists(i_fileDst)) { eeDeleteModel(i_fileDst); } uint16_t size = min<uint16_t>(sizeof(g_model), *(uint16_t*)&buf[6]); uint32_t address = eepromHeader.files[i_fileDst+1].zoneIndex * EEPROM_ZONE_SIZE; // erase blocks eepromEraseBlock(address); eepromEraseBlock(address+EEPROM_BLOCK_SIZE); // write header EepromFileHeader * header = (EepromFileHeader *)eepromWriteBuffer; header->fileIndex = i_fileDst+1; header->size = size; int offset = 4; // write model do { uint16_t blockSize = min<uint16_t>(size, EEPROM_BUFFER_SIZE-offset); result = f_read(&restoreFile, eepromWriteBuffer+offset, blockSize, &read); if (result != FR_OK || read != blockSize) { f_close(&g_oLogFile); return SDCARD_ERROR(result); } eepromWrite(address, eepromWriteBuffer, blockSize+offset); size -= blockSize; address += EEPROM_BUFFER_SIZE; offset = 0; } while (size > 0); // write FAT eepromHeader.files[i_fileDst+1].exists = 1; eepromIncFatAddr(); eepromWriteState = EEPROM_WRITE_NEW_FAT; eepromWriteWait(); eeLoadModelHeader(i_fileDst, &modelHeaders[i_fileDst]); #if defined(PCBSKY9X) if (version < EEPROM_VER) { ConvertModel(i_fileDst, version); loadModel(g_eeGeneral.currModel); } #endif return NULL; }
//Function to store and edit user data void vault() { char cursor[5]; //used to format cursor UINT8 data[17]; //used to store the user data while(!secondTick()); while(!secondTick()); eepromRead(0x0003, 16, data); lcdInstruction("j"); lcdString(" Edit Data: "); lcdInstruction("1;0H"); lcdString(data); lcdInstruction("1;0H"); lcdInstruction("1c"); int y; y = 0; while(TRUE) { int x; x = 0; if(buttonPressed(BTN_ROTARY)) { y++; if(y == 16) y = 0; sprintf(cursor, "1;%dH", y); lcdInstruction(cursor); } x = readRotaryKnob(); if(x != 0) //To edit data { if(switchState(SWITCH_ROTARY)) x = x*8; data[y] += x; if((int)data[y] >= 123) { int k; k = (int)data[y] -123;// = k; 97; data[y] = 97 + k; } if((int)data[y] <= 96) { int k; k = 96 - (int)data[y]; data[y] = 122 - k; } lcdInstruction("j"); lcdString(" Edit Data: "); lcdInstruction("1c"); lcdInstruction("1;0H"); lcdString(data); sprintf(cursor, "1;%dH", y); lcdInstruction(cursor); } if(buttonPressed(BTN1)) //To exit data entry { lcdInstruction("j"); lcdInstruction("0c"); lcdString(" Data Saved "); eepromWrite(0x0003, 16, data); button1 = TRUE; while(!secondTick()); while(!secondTick()); break; } } }