diff --git a/src/Makefile b/src/Makefile index 08646335f..129da7e02 100644 --- a/src/Makefile +++ b/src/Makefile @@ -469,7 +469,7 @@ RUN_FROM_FLASH = 1 ifeq ($(PCB), ACT) # ACT radio OPT = 2 - CPPDEFS += -DPCBACT -DCPUARM -DEEPROM_VARIANT=0 -DAUDIO -DPXX -DDSM2 -DDSM2_PPM -DROTARY_ENCODERS=1 -DLCD260 -DSTM32F10X_LD + CPPDEFS += -DPCBACT -DCPUARM -DEEPROM_VARIANT=0 -DAUDIO -DPXX -DDSM2 -DDSM2_PPM -DROTARY_ENCODERS=1 -DLCD260 -DSTM32F10X_HD EXTRAINCDIRS += sky9x CoOS/kernel CoOS/portable EXTRAINCDIRS += act/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/inc act/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x BOARDSRC = x9d/board_x9d.cpp @@ -491,7 +491,7 @@ ifeq ($(PCB), X9D) BOARDSRC = x9d/board_x9d.cpp EXTRABOARDSRC += x9d/lcd_driver.cpp x9d/aspi.cpp x9d/i2c_ee.c SRC += CoOS/kernel/core.c CoOS/kernel/hook.c CoOS/kernel/task.c CoOS/kernel/event.c CoOS/kernel/time.c CoOS/kernel/timer.c CoOS/kernel/flag.c CoOS/kernel/mutex.c CoOS/kernel/serviceReq.c CoOS/portable/GCC/port.c CoOS/portable/arch.c - EEPROMSRC = eeprom_arm.cpp eeprom_conversions.cpp + EEPROMSRC = eeprom_avr.cpp # TODO later eeprom_conversions.cpp PULSESSRC = pulses_arm.cpp CPPSRC += sky9x/audio.cpp CPPSRC += x9d/pwr_driver.cpp x9d/eeprom_driver.cpp x9d/pulses_driver.cpp x9d/keys_driver.cpp x9d/audio_driver.cpp diff --git a/src/eeprom_arm.cpp b/src/eeprom_arm.cpp index 6aa1b5b48..61965f673 100644 --- a/src/eeprom_arm.cpp +++ b/src/eeprom_arm.cpp @@ -40,7 +40,7 @@ volatile uint32_t Spi_complete; // TODO in the driver ? uint8_t s_eeDirtyMsk; uint16_t s_eeDirtyTime10ms; -// Logic for storing to EERPOM/loading from EEPROM +// Logic for storing to EEPROM/loading from EEPROM // If main needs to wait for the eeprom, call mainsequence without actioning menus // General configuration // 'main' set flag STORE_GENERAL @@ -63,8 +63,6 @@ uint8_t Spi_rx_buf[24] ; struct t_file_entry File_system[MAX_MODELS+1] ; -char ModelNames[MAX_MODELS][sizeof(g_model.name)] ; // Allow for general - // TODO check everything here uint8_t Eeprom32_process_state = E32_IDLE; uint8_t Eeprom32_state_after_erase ; @@ -89,8 +87,8 @@ void handle_serial( void ) ; uint32_t get_current_block_number( uint32_t block_no, uint16_t *p_size, uint32_t *p_seq ) ; void write32_eeprom_block( uint32_t eeAddress, register uint8_t *buffer, uint32_t size, uint32_t immediate=0 ) ; -void ee32_read_model_names( void ) ; -void ee32LoadModelName(uint8_t id, char *buf, uint8_t len) ; +void eeLoadModelNames( void ) ; +uint16_t eeLoadModelName(uint8_t id, char *name); // New file system @@ -118,7 +116,7 @@ void eeDeleteModel(uint8_t id) { eeCheck(true); - memset(ModelNames[id], 0, sizeof(g_model.name)); + memset(modelNames[id], 0, sizeof(g_model.name)); Eeprom32_source_address = (uint8_t *)&g_model ; // Get data from here Eeprom32_data_size = 0 ; // This much @@ -135,9 +133,9 @@ bool eeCopyModel(uint8_t dst, uint8_t src) read32_eeprom_data( (File_system[src+1].block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&Eeprom_buffer.data.model_data, size) ; if (size > sizeof(g_model.name)) - memcpy(ModelNames[dst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); + memcpy(modelNames[dst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); else - memset(ModelNames[dst], 0, sizeof(g_model.name)); + memset(modelNames[dst], 0, sizeof(g_model.name)); Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here Eeprom32_data_size = sizeof(g_model) ; // This much @@ -161,10 +159,10 @@ void eeSwapModels(uint8_t id1, uint8_t id2) // TODO flash saving with function above ... if (id2_size > sizeof(g_model.name)) { read32_eeprom_data( (id2_block_no << 12) + sizeof( struct t_eeprom_header), ( uint8_t *)&Eeprom_buffer.data.model_data, id2_size); - memcpy(ModelNames[id1], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); + memcpy(modelNames[id1], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); } else { - memset(ModelNames[id1], 0, sizeof(g_model.name)); + memset(modelNames[id1], 0, sizeof(g_model.name)); } Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here @@ -403,8 +401,7 @@ void eeLoadModel(uint8_t id) resetAll(); if (pulsesStarted()) { - checkTHR(); - checkSwitches(); + checkAll(); resumePulses(); clearKeyEvents(); } @@ -438,15 +435,24 @@ bool eeModelExists(uint8_t id) return ( File_system[id+1].size > 0 ) ; } -void ee32LoadModelName(uint8_t id, char *buf, uint8_t len) +uint16_t eeLoadModelName(uint8_t id, char *name) { + memclear(name, sizeof(g_model.name)); if (id < MAX_MODELS) { id += 1; - memset(buf, 0, len); if (File_system[id].size > sizeof(g_model.name) ) { - read32_eeprom_data( ( File_system[id].block_no << 12) + 8, ( uint8_t *)buf, sizeof(g_model.name)) ; + read32_eeprom_data( ( File_system[id].block_no << 12) + 8, ( uint8_t *)name, sizeof(g_model.name)); + return File_system[id].size; } } + return 0; +} + +void eeLoadModelNames() +{ + for (uint32_t i=0; i sizeof(g_model.name)) - memcpy(ModelNames[i_fileDst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); + memcpy(modelNames[i_fileDst], Eeprom_buffer.data.model_data.name, sizeof(g_model.name)); else - memset(ModelNames[i_fileDst], 0, sizeof(g_model.name)); + memset(modelNames[i_fileDst], 0, sizeof(g_model.name)); Eeprom32_source_address = (uint8_t *)&Eeprom_buffer.data.model_data; // Get data from here Eeprom32_data_size = sizeof(g_model); // This much diff --git a/src/eeprom_arm.h b/src/eeprom_arm.h index 5d3f45009..4439b94e8 100644 --- a/src/eeprom_arm.h +++ b/src/eeprom_arm.h @@ -74,7 +74,6 @@ struct t_eeprom_header }; extern struct t_file_entry File_system[] ; -extern char ModelNames[][sizeof(g_model.name)] ; // Allow for general extern EEGeneral g_eeGeneral; extern ModelData g_model; diff --git a/src/eeprom_avr.cpp b/src/eeprom_avr.cpp index f5d8b3341..b69b6a90f 100644 --- a/src/eeprom_avr.cpp +++ b/src/eeprom_avr.cpp @@ -37,12 +37,11 @@ #include "string.h" uint8_t s_write_err = 0; // error reasons -uint8_t s_sync_write = false; uint8_t s_eeDirtyMsk; uint16_t s_eeDirtyTime10ms; -RlcFile theFile; //used for any file operation -EeFs eeFs; +RlcFile theFile; //used for any file operation +EeFs eeFs; void eeDirty(uint8_t msk) { @@ -50,16 +49,18 @@ void eeDirty(uint8_t msk) s_eeDirtyTime10ms = get_tmr10ms(); } +#if !defined(CPUARM) +uint8_t s_sync_write = false; uint16_t eeprom_pointer; -const char* eeprom_buffer_data; +const char * eeprom_buffer_data; volatile int8_t eeprom_buffer_size = 0; #if !defined(SIMU) - inline void eeprom_write_byte() { EEAR = eeprom_pointer; EEDR = *eeprom_buffer_data; +// TODO add some define here #if defined (PCBGRUVIN9X) EECR |= 1< 0) wdt_reset(); } } +#endif -static uint8_t EeFsRead(uint8_t blk, uint8_t ofs) +static uint8_t EeFsRead(blkid_t blk, uint8_t ofs) { uint8_t ret; -#ifdef SIMU +#if defined(PCBX9D) + eeprom_read_block(&ret, (uint16_t)(blk*BS+ofs+BLOCKS_OFFSET), 1); +#elif defined(SIMU) eeprom_read_block(&ret, (const void*)(uint64_t)(blk*BS+ofs+BLOCKS_OFFSET), 1); #else eeprom_read_block(&ret, (const void*)(blk*BS+ofs+BLOCKS_OFFSET), 1); @@ -119,47 +122,53 @@ static uint8_t EeFsRead(uint8_t blk, uint8_t ofs) return ret; } -static uint8_t EeFsGetLink(uint8_t blk) +static blkid_t EeFsGetLink(blkid_t blk) { +#if defined(CPUARM) + blkid_t ret; + eeprom_read_block((uint8_t *)&ret, blk*BS+BLOCKS_OFFSET, sizeof(blkid_t)); + return ret; +#else return EeFsRead(blk, 0); +#endif } -static void EeFsSetLink(uint8_t blk, uint8_t val) +static void EeFsSetLink(blkid_t blk, blkid_t val) { - static uint8_t s_link; // we write asynchronously, then nothing on the stack! + static blkid_t s_link; // we write asynchronously, then nothing on the stack! s_link = val; - eeWriteBlockCmp(&s_link, (blk*BS)+BLOCKS_OFFSET, 1); + eeWriteBlockCmp((uint8_t *)&s_link, (blk*BS)+BLOCKS_OFFSET, sizeof(blkid_t)); } -static uint8_t EeFsGetDat(uint8_t blk,uint8_t ofs) +static uint8_t EeFsGetDat(blkid_t blk, uint8_t ofs) { - return EeFsRead(blk, ofs+1); + return EeFsRead(blk, ofs+sizeof(blkid_t)); } -static void EeFsSetDat(uint8_t blk,uint8_t ofs,uint8_t*buf,uint8_t len) +static void EeFsSetDat(blkid_t blk, uint8_t ofs, uint8_t *buf, uint8_t len) { - eeWriteBlockCmp(buf, blk*BS+ofs+1+BLOCKS_OFFSET, len); + eeWriteBlockCmp(buf, (blk*BS)+ofs+sizeof(blkid_t)+BLOCKS_OFFSET, len); } static void EeFsFlushFreelist() { - eeWriteBlockCmp(&eeFs.freeList, offsetof(EeFs, freeList), sizeof(eeFs.freeList)); + eeWriteBlockCmp((uint8_t *)&eeFs.freeList, offsetof(EeFs, freeList), sizeof(eeFs.freeList)); } static void EeFsFlushDirEnt(uint8_t i_fileId) { - eeWriteBlockCmp(&eeFs.files[i_fileId], offsetof(EeFs, files) + sizeof(DirEnt)*i_fileId, sizeof(DirEnt)); + eeWriteBlockCmp((uint8_t *)&eeFs.files[i_fileId], offsetof(EeFs, files) + sizeof(DirEnt)*i_fileId, sizeof(DirEnt)); } static void EeFsFlush() { - eeWriteBlockCmp(&eeFs, 0, sizeof(eeFs)); + eeWriteBlockCmp((uint8_t *)&eeFs, 0, sizeof(eeFs)); } uint16_t EeFsGetFree() { int16_t ret = 0; - uint8_t i = eeFs.freeList; + blkid_t i = eeFs.freeList; while (i) { ret += BS-1; i = EeFsGetLink(i); @@ -170,10 +179,10 @@ uint16_t EeFsGetFree() } /// free one or more blocks -static void EeFsFree(uint8_t blk) +static void EeFsFree(blkid_t blk) { - uint8_t i = blk; - uint8_t tmp; + blkid_t i = blk; + blkid_t tmp; while ((tmp=EeFsGetLink(i))) i = tmp; EeFsSetLink(i, eeFs.freeList); eeFs.freeList = blk; //chain in front @@ -182,16 +191,15 @@ static void EeFsFree(uint8_t blk) int8_t EeFsck() { - s_sync_write = true; + ENABLE_SYNC_WRITE(true); uint8_t *bufp = reusableBuffer.eefs_buffer; memclear(bufp, BLOCKS); - uint8_t blk ; - int8_t ret = 0; + blkid_t blk ; - for(uint8_t i = 0; i <= MAXFILES; i++) { - uint8_t *startP = (i==MAXFILES ? &eeFs.freeList : &eeFs.files[i].startBlk); - uint8_t lastBlk = 0; + for (uint8_t i=0; i<=MAXFILES; i++) { + blkid_t *startP = (i==MAXFILES ? &eeFs.freeList : &eeFs.files[i].startBlk); + blkid_t lastBlk = 0; blk = *startP; while (blk) { if (blk < FIRSTBLK || // bad blk index @@ -222,31 +230,31 @@ int8_t EeFsck() } } - s_sync_write = false; + ENABLE_SYNC_WRITE(false); - return ret; + return 0; } void EeFsFormat() { - s_sync_write = true; + ENABLE_SYNC_WRITE(true); memclear(&eeFs, sizeof(eeFs)); eeFs.version = EEFS_VERS; eeFs.mySize = sizeof(eeFs); eeFs.freeList = 0; eeFs.bs = BS; - for(uint8_t i = FIRSTBLK; i < BLOCKS-1; i++) EeFsSetLink(i,i+1); + for (blkid_t i=FIRSTBLK; i len) i_len = len; + + uint8_t remaining = i_len; + while (remaining) { + if (!m_currBlk) break; + *buf++ = EeFsGetDat(m_currBlk, m_ofs++); - if(m_ofs>=(BS-1)){ - m_ofs=0; - m_currBlk=EeFsGetLink(m_currBlk); + if (m_ofs >= BS-sizeof(blkid_t)) { + m_ofs = 0; + m_currBlk = EeFsGetLink(m_currBlk); } - len--; + remaining--; } - m_pos += i_len - len; - return i_len - len; + + i_len -= remaining; + m_pos += i_len; + return i_len; } /* * Read runlength (RLE) compressed bytes into buf. */ -#ifdef TRANSLATIONS -uint16_t RlcFile::readRlc12(uint8_t*buf,uint16_t i_len, bool rlc2) -#else -uint16_t RlcFile::readRlc(uint8_t *buf,uint16_t i_len) -#endif +uint16_t RlcFile::readRlc(uint8_t *buf, uint16_t i_len) { - uint16_t i=0; - for( ; 1; ){ - uint8_t l = min(m_zeroes,i_len-i); - memclear(&buf[i], l); - i += l; - m_zeroes -= l; - if(m_zeroes) break; + uint16_t i = 0; + for( ; 1; ) { + uint8_t ln = min(m_zeroes, i_len-i); + memclear(&buf[i], ln); + i += ln; + m_zeroes -= ln; + if (m_zeroes) break; - l=min(m_bRlc,i_len-i); - uint8_t lr = read(&buf[i],l); + ln = min(m_bRlc, i_len-i); + uint8_t lr = read(&buf[i], ln); i += lr ; m_bRlc -= lr; if(m_bRlc) break; - if(read(&m_bRlc,1)!=1) break; //read how many bytes to read + if (read(&m_bRlc, 1) !=1) break; // read how many bytes to read assert(m_bRlc & 0x7f); -#ifdef TRANSLATIONS - if (rlc2) { -#endif - if(m_bRlc&0x80){ // if contains high byte - m_zeroes =(m_bRlc>>4) & 0x7; - m_bRlc = m_bRlc & 0x0f; - } - else if(m_bRlc&0x40){ - m_zeroes = m_bRlc & 0x3f; - m_bRlc = 0; - } - //else m_bRlc -#ifdef TRANSLATIONS + + if (m_bRlc&0x80) { // if contains high byte + m_zeroes =(m_bRlc>>4) & 0x7; + m_bRlc = m_bRlc & 0x0f; } - else { - if(m_bRlc&0x80){ // if contains high byte - m_zeroes = m_bRlc & 0x7f; - m_bRlc = 0; - } + else if(m_bRlc&0x40) { + m_zeroes = m_bRlc & 0x3f; + m_bRlc = 0; } -#endif } return i; } @@ -400,7 +395,7 @@ void RlcFile::write(uint8_t *buf, uint8_t i_len) do { nextWriteStep(); - } while (s_sync_write && m_write_len && !s_write_err); + } while (IS_SYNC_WRITE_ENABLE() && m_write_len && !s_write_err); } void RlcFile::nextWriteStep() @@ -426,9 +421,9 @@ void RlcFile::nextWriteStep() s_write_err = ERR_FULL; break; } - if (m_ofs >= (BS-1)) { + if (m_ofs >= (BS-sizeof(blkid_t))) { m_ofs = 0; - uint8_t nextBlk = EeFsGetLink(m_currBlk); + blkid_t nextBlk = EeFsGetLink(m_currBlk); if (!nextBlk) { if (!eeFs.freeList) { s_write_err = ERR_FULL; @@ -452,7 +447,7 @@ void RlcFile::nextWriteStep() EeFsSetLink(m_currBlk, 0); return; } - uint8_t tmp = BS-1-m_ofs; if(tmp>m_write_len) tmp=m_write_len; + uint8_t tmp = BS-sizeof(blkid_t)-m_ofs; if(tmp>m_write_len) tmp = m_write_len; m_write_buf += tmp; m_write_len -= tmp; m_ofs += tmp; @@ -467,7 +462,7 @@ void RlcFile::nextWriteStep() m_write_len = 0; m_cur_rlc_len = 0; } - else if (!s_sync_write) { + else if (!IS_SYNC_WRITE_ENABLE()) { nextRlcWriteStep(); } } @@ -479,7 +474,7 @@ void RlcFile::create(uint8_t i_fileId, uint8_t typ, uint8_t sync_write) eeFs.files[FILE_TMP].typ = typ; eeFs.files[FILE_TMP].size = 0; m_fileId = i_fileId; - s_sync_write = sync_write; + ENABLE_SYNC_WRITE(sync_write); } /* @@ -491,18 +486,19 @@ bool RlcFile::copy(uint8_t i_fileDst, uint8_t i_fileSrc) theFile2.openRd(i_fileSrc); create(i_fileDst, FILE_TYP_MODEL/*optimization, only model files are copied. should be eeFs.files[i_fileSrc].typ*/, true); - uint8_t buf[15]; + + uint8_t buf[BS-sizeof(blkid_t)]; uint8_t len; - while ((len=theFile2.read(buf, 15))) + while ((len=theFile2.read(buf, BS-sizeof(blkid_t)))) { write(buf, len); if (write_errno() != 0) { - s_sync_write = false; + ENABLE_SYNC_WRITE(false); return false; } } - uint8_t fri=0; + blkid_t fri=0; if (m_currBlk && (fri=EeFsGetLink(m_currBlk))) EeFsSetLink(m_currBlk, 0); @@ -644,21 +640,21 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name) do { result = f_read(&g_oLogFile, (uint8_t *)buf, 15, &read); if (result != FR_OK) { - s_sync_write = false; + ENABLE_SYNC_WRITE(false); f_close(&g_oLogFile); return SDCARD_ERROR(result); } if (read > 0) { theFile.write((uint8_t *)buf, read); if (write_errno() != 0) { - s_sync_write = false; + ENABLE_SYNC_WRITE(false); f_close(&g_oLogFile); return STR_EEPROMOVERFLOW; } } } while (read == 15); - uint8_t fri=0; + blkid_t fri=0; if (theFile.m_currBlk && (fri=EeFsGetLink(theFile.m_currBlk))) EeFsSetLink(theFile.m_currBlk, 0); @@ -672,7 +668,7 @@ const pm_char * eeRestoreModel(uint8_t i_fileDst, char *model_name) } #endif -void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t*buf, uint16_t i_len, uint8_t sync_write) +void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t *buf, uint16_t i_len, uint8_t sync_write) { create(i_fileId, typ, sync_write); @@ -686,7 +682,7 @@ void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t*buf, uint16_t i_le do { nextRlcWriteStep(); - } while (s_sync_write && m_write_step && !s_write_err); + } while (IS_SYNC_WRITE_ENABLE() && m_write_step && !s_write_err); } void RlcFile::nextRlcWriteStep() @@ -704,14 +700,14 @@ void RlcFile::nextRlcWriteStep() return; } - bool run0 = m_rlc_buf[0] == 0; + bool run0 = (m_rlc_buf[0] == 0); - if(m_rlc_len==0) goto close; + if (m_rlc_len==0) goto close; for (i=1; 1; i++) // !! laeuft ein byte zu weit !! { bool cur0 = m_rlc_buf[i] == 0; - if (cur0 != run0 || cnt==0x3f || (cnt0 && cnt==0xf)|| i==m_rlc_len){ + if (cur0 != run0 || cnt==0x3f || (cnt0 && cnt==0x0f) || i==m_rlc_len) { if (run0) { assert(cnt0==0); if (cnt<8 && i!=m_rlc_len) @@ -747,10 +743,10 @@ void RlcFile::nextRlcWriteStep() switch(m_write_step) { case WRITE_START_STEP: { - uint8_t fri=0; + blkid_t fri=0; if (m_currBlk && (fri=EeFsGetLink(m_currBlk))) { - uint8_t prev_freeList = eeFs.freeList; + blkid_t prev_freeList = eeFs.freeList; eeFs.freeList = fri; while( EeFsGetLink(fri)) fri = EeFsGetLink(fri); m_write_step = WRITE_FREE_UNUSED_BLOCKS_STEP1; @@ -790,17 +786,19 @@ void RlcFile::nextRlcWriteStep() } } +#if !defined(CPUARM) void RlcFile::flush() { while (eeprom_buffer_size > 0) wdt_reset(); - s_sync_write = true; + ENABLE_SYNC_WRITE(true); while (m_write_len && !s_write_err) nextWriteStep(); while (isWriting() && !s_write_err) nextRlcWriteStep(); - s_sync_write = false; + ENABLE_SYNC_WRITE(false); } +#endif #if defined (EEPROM_PROGRESS_BAR) void RlcFile::DisplayProgressBar(uint8_t x) @@ -843,7 +841,7 @@ bool eeLoadGeneral() uint16_t eeLoadModelName(uint8_t id, char *name) { memclear(name, sizeof(g_model.name)); - if (id=0; i--) { - if (mode & CONDENSED && i<=1) break; + if (flags & CONDENSED && i<=1) break; uint8_t b1=0, b2=0; if (i>1) { b1 = pgm_read_byte(q++); /*top byte*/ @@ -123,76 +137,72 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode) } } #if defined(PCBX9D) - else if (mode & MIDSIZE) { + else if (flags & MIDSIZE) { /* each letter consists of ten top bytes followed by * by ten bottom bytes (20 bytes per * char) */ q = &font_8x10[((uint16_t)c-0x20)*16]; for (int8_t i=9; i>=0; i--) { uint8_t b1=0, b2=0; - if (mode & CONDENSED && i<=1) break; + if (flags & CONDENSED && i<=1) break; if (i!=0 && i!=9) { b1 = pgm_read_byte(q++); /*top byte*/ b2 = pgm_read_byte(q++); /*top byte*/ } if (inv) { - b1=~b1; - b2=~b2; + b1 = ~b1; + b2 = ~b2; } uint8_t ym8 = (y % 8); if (&p[DISPLAY_W+1] < DISPLAY_END) { - ASSERT_IN_DISPLAY(p); - ASSERT_IN_DISPLAY(p+DISPLAY_W); - *p = (*p & (~(0xff << ym8))) + (b1 << ym8); + LCD_BYTE_FILTER(p, ~(0xff << ym8), b1 << ym8); uint8_t *r = p + DISPLAY_W; if (r> (8-ym8)))) + (b1 >> (8-ym8)); - *r = (*r & (~(0x0f << ym8))) + ((b2&0x0f) << ym8); + LCD_BYTE_FILTER(r, ~(0xff >> (8-ym8)), b1 >> (8-ym8)); + LCD_BYTE_FILTER(r, ~(0x0f << ym8), (b2&0x0f) << ym8); if (ym8) { r = r + DISPLAY_W; if (r> (8-ym8)))) + ((b2&0x0f) >> (8-ym8)); + LCD_BYTE_FILTER(r, ~(0x0f >> (8-ym8)), (b2&0x0f) >> (8-ym8)); } } p++; } } } - else if (mode & SMLSIZE) { + else if (flags & SMLSIZE) { q = &font_4x6[((uint16_t)c-0x20)*5+4]; uint8_t ym8 = (y % 8); p += 4; for (int8_t i=4; i>=0; i--) { uint8_t b = pgm_read_byte(q--); if (inv) b = ~b & 0x7f; - if (p> (8-ym8)))) + (b >> (8-ym8)); + LCD_BYTE_FILTER(r, ~(0x7f >> (8-ym8)), b >> (8-ym8)); } } p--; } } - else if (mode & TINSIZE) { + else if (flags & TINSIZE) { q = &font_3x5[((uint16_t)c-0x2D)*3+2]; uint8_t ym8 = (y % 8); p += 2; for (int8_t i=2; i>=0; i--) { uint8_t b = pgm_read_byte(q--); if (inv) b = ~b & 0x3f; - if (p> (8-ym8)))) + (b >> (8-ym8)); + LCD_BYTE_FILTER(r, ~(0x3f >> (8-ym8)), b >> (8-ym8)); } } p--; @@ -202,7 +212,7 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode) else { uint8_t condense=0; - if (mode & CONDENSED) { + if (flags & CONDENSED) { *p = inv ? ~0 : 0; condense=1; } @@ -220,14 +230,14 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode) if (p> (8-ym8)))) + (b >> (8-ym8)); + LCD_BYTE_FILTER(r, ~(0xff >> (8-ym8)), b >> (8-ym8)); } #ifdef BOLD_FONT - if (mode & BOLD) { + if (flags & BOLD) { ASSERT_IN_DISPLAY(p+1); if (inv) *(p+1) &= (b << ym8); @@ -431,8 +441,10 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags flags, uint8_t if (xn) { if (midsize) { - if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) + if ((flags&INVERS) && ((~flags & BLINK) || BLINK_ON_PHASE)) { + lcd_vline(xn, y, 12); lcd_vline(xn+1, y, 12); + } lcd_hline(xn, y+9, 2); lcd_hline(xn, y+10, 2); } diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 84e5ee761..53092e378 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -216,13 +216,14 @@ void menuModelSelect(uint8_t event) { TITLE(STR_MENUMODELSEL); -#if defined(CPUARM) +#if defined(PCBSKY9X) #define REFRESH(x) #elif defined(PCBGRUVIN9X) && defined(SDCARD) static bool refresh = true; #define REFRESH(x) refresh = (x) #else -#define refresh event + #define refresh event + #define REFRESH(x) #endif if (s_warning_result) { @@ -430,7 +431,7 @@ void menuModelSelect(uint8_t event) } -#if !defined(CPUARM) +#if !defined(PCBSKY9X) lcd_puts(9*FW-(LEN_FREE-4)*FW, 0, STR_FREE); if (refresh) reusableBuffer.models.eepromfree = EeFsGetFree(); lcd_outdezAtt(17*FW, 0, reusableBuffer.models.eepromfree, 0); @@ -470,7 +471,7 @@ void menuModelSelect(uint8_t event) if (eeModelExists(k)) { #if defined(CPUARM) - putsModelName(4*FW, y, ModelNames[k], k, 0); + putsModelName(4*FW, y, modelNames[k], k, 0); #else uint16_t & size = reusableBuffer.models.listsizes[i]; char * name = reusableBuffer.models.listnames[i]; @@ -489,7 +490,7 @@ void menuModelSelect(uint8_t event) if (s_warning) { #if defined(CPUARM) - s_warning_info = ModelNames[sub]; + s_warning_info = modelNames[sub]; #else char * name = reusableBuffer.models.mainname; if (refresh) eeLoadModelName(sub, name); @@ -666,7 +667,7 @@ void menuModelSetup(uint8_t event) case ITEM_MODEL_NAME: editName(MODEL_SETUP_2ND_COLUMN, y, g_model.name, sizeof(g_model.name), event, attr, m_posHorz); #if defined(CPUARM) - memcpy(ModelNames[g_eeGeneral.currModel], g_model.name, sizeof(g_model.name)); + memcpy(modelNames[g_eeGeneral.currModel], g_model.name, sizeof(g_model.name)); #endif break; diff --git a/src/open9x.cpp b/src/open9x.cpp index 948e47cab..2d7e735f6 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -64,8 +64,14 @@ OS_FlagID audioFlag; OS_MutexID audioMutex; OS_MutexID mixerMutex; + +char modelNames[MAX_MODELS][sizeof(g_model.name)]; +#if defined(PCBX9D) +uint16_t modelSizes[MAX_MODELS]; #endif +#endif // defined(CPUARM) + #if defined(SPLASH) const pm_uchar splashdata[] PROGMEM = { 'S','P','S',0, #if defined(PCBACT) @@ -2870,11 +2876,15 @@ void perMain() } #endif -#if defined(CPUARM) +// TODO merge these 2 branches +#if defined(PCBSKY9X) if (Eeprom32_process_state != E32_IDLE) ee32_process(); else if (TIME_TO_WRITE) eeCheck(); +#elif defined(CPUARM) + if (TIME_TO_WRITE) + eeCheck(); #else if (!eeprom_buffer_size) { if (theFile.isWriting()) diff --git a/src/open9x.h b/src/open9x.h index 1f5c3fd0c..7372b349f 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -212,10 +212,23 @@ extern void boardInit(); #endif #if defined(CPUARM) +extern char modelNames[MAX_MODELS][sizeof(g_model.name)]; +#endif + +#if defined(PCBX9D) +extern uint16_t modelSizes[MAX_MODELS]; +#endif + +// TODO try to merge the 2 include files +#if defined(PCBSKY9X) #include "eeprom_arm.h" -#include "pulses_arm.h" #else #include "eeprom_avr.h" +#endif + +#if defined(CPUARM) +#include "pulses_arm.h" +#else #include "pulses_avr.h" #endif @@ -1000,7 +1013,6 @@ void saveTimers(); #define saveTimers() #endif -void eeWriteBlockCmp(const void *i_pointer_ram, uint16_t i_pointer_eeprom, size_t size); void eeDirty(uint8_t msk); void eeCheck(bool immediately=false); void eeReadAll(); @@ -1287,7 +1299,7 @@ union ReusableBuffer { /* 128 bytes on stock */ -#if !defined(CPUARM) +#if !defined(PCBSKY9X) uint8_t eefs_buffer[BLOCKS]; // 128bytes used by EeFsck #endif @@ -1333,7 +1345,7 @@ void putsTelemetryValue(uint8_t x, uint8_t y, int16_t val, uint8_t unit, uint8_t #if defined(CPUARM) uint8_t zlen(const char *str, uint8_t size); char * strcat_zchar(char * dest, char * name, uint8_t size, const char *defaultName, uint8_t defaultNameSize, uint8_t defaultIdx); -#define strcat_modelname(dest, idx) strcat_zchar(dest, ModelNames[idx], LEN_MODEL_NAME, STR_MODEL, PSIZE(TR_MODEL), idx+1) +#define strcat_modelname(dest, idx) strcat_zchar(dest, modelNames[idx], LEN_MODEL_NAME, STR_MODEL, PSIZE(TR_MODEL), idx+1) #define strcat_phasename_default(dest, idx) strcat_zchar(dest, NULL, 0, STR_FP, PSIZE(TR_FP), idx) #define strcat_phasename_nodefault(dest, idx) strcat_zchar(dest, g_model.phaseData[idx].name, LEN_FP_NAME, NULL, 0, 0) #define strcat_mixername_nodefault(dest, idx) strcat_zchar(dest, g_model.mixData[idx].name, LEN_EXPOMIX_NAME, NULL, 0, 0) diff --git a/src/pulses_avr.cpp b/src/pulses_avr.cpp index 1a1c0a752..7696e5326 100644 --- a/src/pulses_avr.cpp +++ b/src/pulses_avr.cpp @@ -732,18 +732,18 @@ void setupPulses() PORTH |= 0x80; // PORTH:7 LOW->HIGH signals start of setupPulses() #endif -#if defined (PCBGRUVIN9X) && defined(TX_CADDY) + if (s_pulses_paused) + required_protocol = PROTO_NONE; + + if (s_current_protocol != required_protocol) { + +#if defined(PCBGRUVIN9X) && defined(TX_CADDY) if (required_protocol == PROTO_DSM2) PORTH &= ~0x80; else PORTH |= 0x80; #endif - if (s_pulses_paused) - required_protocol = PROTO_NONE; - - if (s_current_protocol != required_protocol) { - #if defined(DSM2_SERIAL) && defined(FRSKY) if (s_current_protocol == 255 || s_current_protocol == PROTO_DSM2) { FRSKY_Init(); diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index a95fa773f..05bbefba6 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -58,7 +58,7 @@ Dacc dacc; Adc Adc0; #endif -#if defined(CPUARM) +#if defined(PCBSKY9X) uint32_t eeprom_pointer; char* eeprom_buffer_data; volatile int32_t eeprom_buffer_size; @@ -257,6 +257,7 @@ uint16_t getTmr16KHz() return get_tmr10ms() * 160; } +#if !defined(PCBX9D) bool eeprom_thread_running = true; void *eeprom_write_function(void *) { @@ -300,6 +301,7 @@ void *eeprom_write_function(void *) } return 0; } +#endif uint8_t main_thread_running = 0; char * main_thread_error = NULL; @@ -385,33 +387,57 @@ void StartEepromThread(const char *filename) eeprom_write_sem = (sem_t *)malloc(sizeof(sem_t)); sem_init(eeprom_write_sem, 0, 0); #endif + +#if !defined(PCBX9D) eeprom_thread_running = true; assert(!pthread_create(&eeprom_thread_pid, NULL, &eeprom_write_function, NULL)); +#endif } void StopEepromThread() { +#if !defined(PCBX9D) eeprom_thread_running = false; sem_post(eeprom_write_sem); pthread_join(eeprom_thread_pid, NULL); +#endif } -void eeprom_read_block (void *pointer_ram, - const void *pointer_eeprom, - size_t size) +#if defined(PCBX9D) +void eeprom_read_block (void *pointer_ram, uint16_t pointer_eeprom, size_t size) +#else +void eeprom_read_block (void *pointer_ram, const void *pointer_eeprom, size_t size) +#endif { assert(size); if (fp) { - memset(pointer_ram, 0, size); - if (fseek(fp, (long) pointer_eeprom, SEEK_SET)==-1) perror("error in seek"); - if (fread(pointer_ram, size, 1, fp) <= 0) perror("error in read"); + // printf("EEPROM read (pos=%d, size=%d)\n", pointer_eeprom, size); fflush(stdout); + if (fseek(fp, (long)pointer_eeprom, SEEK_SET)==-1) perror("error in fseek"); + if (fread(pointer_ram, size, 1, fp) <= 0) perror("error in fread"); } else { memcpy(pointer_ram, &eeprom[(uint64_t)pointer_eeprom], size); } } +#if defined(PCBX9D) +void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t size) +{ + assert(size); + + if (fp) { + // printf("EEPROM write (pos=%d, size=%d)\n", pointer_eeprom, size); fflush(stdout); + if (fseek(fp, (long)pointer_eeprom, SEEK_SET)==-1) perror("error in fseek"); + if (fwrite(pointer_ram, size, 1, fp) <= 0) perror("error in fwrite"); + } + else { + memcpy(&eeprom[(uint64_t)pointer_eeprom], pointer_ram, size); + } +} + +#endif + #if defined(CPUARM) uint16_t stack_free(uint8_t) #else diff --git a/src/simpgmspace.h b/src/simpgmspace.h index bf30f0051..05d9f2d61 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -137,12 +137,16 @@ extern Pwm pwm; #endif extern sem_t *eeprom_write_sem; -#if defined(CPUARM) + +#if defined(PCBSKY9X) extern uint32_t eeprom_pointer; extern char* eeprom_buffer_data; extern volatile int32_t eeprom_buffer_size; extern bool eeprom_read_operation; extern volatile uint32_t Spi_complete; +#endif + +#if defined(CPUARM) extern void startPdcUsartReceive() ; extern uint32_t txPdcUsart( uint8_t *buffer, uint32_t size ); extern uint32_t txPdcPending(); @@ -313,9 +317,11 @@ void StartMainThread(bool tests=true); void StartEepromThread(const char *filename="eeprom.bin"); extern const char *eepromFile; -void eeprom_read_block (void *pointer_ram, - const void *pointer_eeprom, - size_t size); +#if defined(PCBX9D) +void eeprom_read_block (void *pointer_ram, uint16_t pointer_eeprom, size_t size); +#else +void eeprom_read_block (void *pointer_ram, const void *pointer_eeprom, size_t size); +#endif #define wdt_reset() sleep(1/*ms*/) #define boardInit() diff --git a/src/x9d/board_x9d.h b/src/x9d/board_x9d.h index 2e3939271..b6c8db54c 100644 --- a/src/x9d/board_x9d.h +++ b/src/x9d/board_x9d.h @@ -50,7 +50,6 @@ #define SD_IS_HC() (1) #endif - extern "C" { extern void init_SDcard(); extern void sdInit(); @@ -114,4 +113,11 @@ uint32_t check_soft_power(); #define udelay(x) do { uint32_t temp; temp=((x+0)<<3); while(--temp); } while (0) #define delayUsec(x) udelay(x) +#if !defined(SIMU) +#define eeprom_read_block I2C_EE_BufferRead +#define eeWriteBlockCmp I2C_EE_BufferWrite +#else +void eeWriteBlockCmp(const void *pointer_ram, uint16_t pointer_eeprom, size_t size); +#endif + #endif diff --git a/src/x9d/eeprom_driver.cpp b/src/x9d/eeprom_driver.cpp index 9b5a2fe2c..c74cdd2b4 100644 --- a/src/x9d/eeprom_driver.cpp +++ b/src/x9d/eeprom_driver.cpp @@ -39,17 +39,3 @@ void eepromInit() I2C_EE_Init(); #endif } - -void eeprom_write_enable() -{ -} - -uint32_t eeprom_read_status() -{ - return !Spi_complete; -} - -uint32_t spi_PDC_action( register uint8_t *command, register uint8_t *tx, register uint8_t *rx, register uint32_t comlen, register uint32_t count ) -{ - return 0; -} diff --git a/src/x9d/hal.h b/src/x9d/hal.h index 2299e0ccb..6dfa5f32d 100644 --- a/src/x9d/hal.h +++ b/src/x9d/hal.h @@ -167,30 +167,10 @@ #define AudioFreq I2S_AudioFreq_44k // EEPROM and CAT5137 -#define EE_M24C08 /* Support the device: M24C08. */ -//#define EE_M24C64_32 /* Support the devices: M24C32 and M24C64 */ #define I2C_Speed 200000 - -#if defined (EE_M24C08) - #define I2C_FLASH_PAGESIZE (16) -#elif defined (EE_M24C64_32) - #define I2C_FLASH_PAGESIZE (32) -#endif - -#ifdef EE_M24C64_32 - #define EEPROM_HW_ADDRESS 0xA0 /* E0 = E1 = E2 = 0 */ -#elif defined (EE_M24C08) -//#define EEPROM_Block0_ADDRESS 0xA0 /* 000*/ -#define EEPROM_Block1_ADDRESS 0xA2 /* E3 E2 E1= 001 */ -//#define EEPROM_Block2_ADDRESS 0xA4 /* 010 */ -//#define EEPROM_Block3_ADDRESS 0xA6 /* 011 */ -#endif - -#define USE_CAT5137 /*Support the Volume Control*/ - -#ifdef USE_CAT5137 -#define I2C_CAT5137_ADDRESS 0x5C//0101110 -#endif +#define I2C_FLASH_PAGESIZE (64) +#define I2C_EEPROM_ADDRESS 0xA0 +#define I2C_CAT5137_ADDRESS 0x5C //0101110 // SD card----SPI2 // demo uses a command line option to define this (see Makefile): diff --git a/src/x9d/i2c_ee.c b/src/x9d/i2c_ee.c index ecd1e4fde..3775841ce 100644 --- a/src/x9d/i2c_ee.c +++ b/src/x9d/i2c_ee.c @@ -12,15 +12,12 @@ #include "../open9x.h" -uint16_t EEPROM_ADDRESS; - /** * @brief Configure the used I/O ports pin * @param None * @retval None */ -static -void I2C_GPIO_Configuration(void) +static void I2C_GPIO_Configuration(void) { GPIO_InitTypeDef GPIO_InitStructure; @@ -41,17 +38,6 @@ void I2C_GPIO_Configuration(void) GPIO_Init(I2C_EE_GPIO, &GPIO_InitStructure); } -/** - * @brief I2C Configuration - * @param None - * @retval None - */ -//when use harware I2C -void I2C_Configuration(void) -{ -} - - short I2C_START() { SDA_H; @@ -173,32 +159,6 @@ void I2C_EE_Init() /* GPIO configuration */ I2C_GPIO_Configuration(); - -#if defined (EE_M24C64_32) - /* Select the EEPROM address according to the state of E0, E1, E2 pins */ - EEPROM_ADDRESS = EEPROM_HW_ADDRESS; -#elif defined (EE_M24C08) - /* depending on the EEPROM Address selected in the i2c_ee.h file */ - #ifdef EEPROM_Block0_ADDRESS - /* Select the EEPROM Block0 to write on */ - EEPROM_ADDRESS = EEPROM_Block0_ADDRESS; - #endif - - #ifdef EEPROM_Block1_ADDRESS - /* Select the EEPROM Block1 to write on */ - EEPROM_ADDRESS = EEPROM_Block1_ADDRESS; - #endif - - #ifdef EEPROM_Block2_ADDRESS - /* Select the EEPROM Block2 to write on */ - EEPROM_ADDRESS = EEPROM_Block2_ADDRESS; - #endif - - #ifdef EEPROM_Block3_ADDRESS - /* Select the EEPROM Block3 to write on */ - EEPROM_ADDRESS = EEPROM_Block3_ADDRESS; - #endif -#endif /* EE_M24C64_32 */ } /** @@ -211,12 +171,12 @@ void I2C_EE_Init() void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr) { I2C_START(); - I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_WRITE); + I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE); I2C_WAIT_ACK(); -#ifdef EE_M24C08 +#ifdef EE_M24C08 I2C_SEND_DATA(WriteAddr); I2C_WAIT_ACK(); -#elif defined(EE_M24C64_32) +#else I2C_SEND_DATA((uint8_t)((WriteAddr&0xFF00)>>8) ); I2C_WAIT_ACK(); I2C_SEND_DATA((uint8_t)(WriteAddr&0xFF)); @@ -238,13 +198,12 @@ void I2C_EE_ByteWrite(uint8_t* pBuffer, uint16_t WriteAddr) void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRead) { I2C_START(); - I2C_SEND_DATA(EEPROM_ADDRESS |EE_CMD_WRITE); + I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE); I2C_WAIT_ACK(); - -#ifdef EE_M24C08 +#ifdef EE_M24C08 I2C_SEND_DATA(ReadAddr); I2C_WAIT_ACK(); -#elif defined(EE_M24C64_32) +#else I2C_SEND_DATA((uint8_t)((ReadAddr & 0xFF00) >> 8)); I2C_WAIT_ACK(); I2C_SEND_DATA((uint8_t)(ReadAddr & 0x00FF)); @@ -253,7 +212,7 @@ void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRe I2C_STOP(); I2C_START(); - I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_READ); + I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_READ); I2C_WAIT_ACK(); while (NumByteToRead) { if (NumByteToRead == 1) { @@ -369,13 +328,13 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWrite) { I2C_START(); - I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE); + I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE); I2C_WAIT_ACK(); #ifdef EE_M24C08 I2C_SEND_DATA(WriteAddr); I2C_WAIT_ACK(); -#elif defined(EE_M24C64_32) +#else I2C_SEND_DATA((uint8_t)((WriteAddr & 0xFF00) >> 8)); I2C_WAIT_ACK(); I2C_SEND_DATA((uint8_t)(WriteAddr & 0x00FF)); @@ -398,11 +357,9 @@ void I2C_EE_PageWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint8_t NumByteToWri */ void I2C_EE_WaitEepromStandbyState(void) { - /*__IO*/ volatile uint16_t SR1_Tmp = 0; - do { I2C_START(); - I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE); + I2C_SEND_DATA(I2C_EEPROM_ADDRESS|EE_CMD_WRITE); } while (0 == I2C_WAIT_ACK()); I2C_STOP(); diff --git a/src/x9d/i2c_ee.h b/src/x9d/i2c_ee.h index 1bbded899..c60f4aaac 100644 --- a/src/x9d/i2c_ee.h +++ b/src/x9d/i2c_ee.h @@ -22,9 +22,6 @@ #ifndef __I2C_EE_H #define __I2C_EE_H -// #include "stm32f2xx.h" -// #include "stm32f2xx_conf.h" - #define EE_CMD_WRITE (0) #define EE_CMD_READ (1) #define I2C_delay() do { delayUsec(5); } while(0)