This commit is contained in:
wu58430 2023-12-20 11:30:21 +08:00
parent f57f344672
commit 6e35fb8ea1
4 changed files with 58 additions and 95 deletions

View file

@ -22,12 +22,8 @@
<component name="ChangeListManager">
<list default="true" id="cea36e80-e289-4d69-9030-7186d540ac0e" name="更改" comment="中英文字符对齐">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Makefile" beforeDir="false" afterPath="$PROJECT_DIR$/Makefile" afterDir="false" />
<change beforePath="$PROJECT_DIR$/driver/bk4819.c" beforeDir="false" afterPath="$PROJECT_DIR$/driver/bk4819.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/font.h" beforeDir="false" afterPath="$PROJECT_DIR$/font.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/driver/eeprom.c" beforeDir="false" afterPath="$PROJECT_DIR$/driver/eeprom.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/main.c" beforeDir="false" afterPath="$PROJECT_DIR$/main.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/settings.c" beforeDir="false" afterPath="$PROJECT_DIR$/settings.c" afterDir="false" />
<change beforePath="$PROJECT_DIR$/uv-k5font/font_new/font.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/uv-k5font/font_new/font.cpp" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -100,7 +96,7 @@
<recent name="C:\Users\RUPC\Desktop\UV-K6\uv-k5-firmware-chinese" />
</key>
</component>
<component name="RunManager" selected="Shell Script.win docker">
<component name="RunManager" selected="Shell Script.linux docker">
<configuration name="clean" type="MAKEFILE_TARGET_RUN_CONFIGURATION" factoryName="Makefile" temporary="true">
<makefile filename="$PROJECT_DIR$/Makefile" target="clean" workingDirectory="" arguments="">
<envs />
@ -115,7 +111,6 @@
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="C:\Users\RUPC\py32\python.exe" />
<option name="SDK_NAME" value="Python 3.5 (uv-k5-firmware-chinese)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/MDC_WRITE" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
@ -161,7 +156,7 @@
</configuration>
<configuration name="win" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="" />
<option name="INDEPENDENT_SCRIPT_PATH" value="false" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="$PROJECT_DIR$/win_make.bat" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="true" />
@ -228,6 +223,7 @@
<workItem from="1702888356614" duration="3552000" />
<workItem from="1702896385700" duration="1302000" />
<workItem from="1702910927065" duration="2432000" />
<workItem from="1703038736949" duration="3997000" />
</task>
<task id="LOCAL-00041" summary="MDC RX">
<created>1701692190748</created>

View file

@ -21,103 +21,72 @@
#include "driver/i2c.h"
#include "driver/system.h"
void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size)
{
I2C_Start();
I2C_Write(0xA0);
I2C_Write((Address >> 8) & 0xFF);
I2C_Write((Address >> 0) & 0xFF);
I2C_Start();
I2C_Write(0xA1);
I2C_ReadBuffer(pBuffer, Size);
I2C_Stop();
}
void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer)
{
if (pBuffer == NULL || Address >= 0x2000)
return;
uint8_t buffer[8];
EEPROM_ReadBuffer(Address, buffer, 8);
if (memcmp(pBuffer, buffer, 8) != 0)
{
void EEPROM_ReadBuffer(uint32_t Address, void *pBuffer, uint8_t Size) {
if(Address<0x10000) {
I2C_Start();
I2C_Write(0xA0);
I2C_Write((Address >> 8) & 0xFF);
I2C_Write((Address >> 0) & 0xFF);
I2C_WriteBuffer(pBuffer, 8);
I2C_Start();
I2C_Write(0xA1);
I2C_ReadBuffer(pBuffer, Size);
I2C_Stop();
}
} else{
I2C_Start();
uint8_t P0 = (StartAddr / 0x10000) << 1;
// give the EEPROM time to burn the data in (apparently takes 5ms)
SYSTEM_DelayMs(8);
}
I2C_Write(0xA4|P0);
#define AT24C1024_ADDRESS 0xA4
#define AT24C1024_PAGE_SIZE 64
void E1EPROM_ReadBuffer_1024(uint32_t Address, void *pBuffer, uint16_t Size) {
if (pBuffer == NULL || Address >= 0x20000) // Address limit for AT24C1024 (17-bit address)
return;
uint16_t bytesRead = 0;
uint8_t* dataPointer = (uint8_t*)pBuffer;
while (bytesRead < Size) {
uint16_t bytesToRead = (Size - bytesRead < AT24C1024_PAGE_SIZE) ? (Size - bytesRead) : AT24C1024_PAGE_SIZE;
uint16_t offset = Address % AT24C1024_PAGE_SIZE;
I2C_Write((Address >> 8) & 0xFF);
I2C_Write((Address >> 0) & 0xFF);
I2C_Start();
I2C_Write(AT24C1024_ADDRESS | ((Address >> 16) & 0x01)); // Sending device address and MSB of memory address
I2C_Write((uint8_t)(Address >> 8)); // Sending address high byte
I2C_Write((uint8_t)(Address & 0xFF)); // Sending address low byte
I2C_Start();
I2C_Write(AT24C1024_ADDRESS | 0x01); // Sending device address with read bit
uint8_t buffer[AT24C1024_PAGE_SIZE];
I2C_ReadBuffer(buffer, AT24C1024_PAGE_SIZE);
I2C_Write((0xA4|P0)+1);
// Copy the relevant portion of the buffer to the output buffer
memcpy(dataPointer, buffer + offset, bytesToRead);
bytesRead += bytesToRead;
dataPointer += bytesToRead;
Address += bytesToRead;
I2C_ReadBuffer(pBuffer, Size);
I2C_Stop();
}
}
void E1EPROM_WriteBuffer_1024(uint32_t Address, const void *pBuffer, uint16_t Size) {
if (pBuffer == NULL || Address >= 0x20000) // Address limit for AT24C1024 (17-bit address)
void EEPROM_WriteBuffer(uint32_t Address, const void *pBuffer) {
if (pBuffer == NULL || Address >= 0x20000)
return;
if (Address < 0x10000) {
uint8_t buffer[AT24C1024_PAGE_SIZE];
uint32_t endAddress = Address + Size;
for (uint32_t addr = Address; addr < endAddress; addr += AT24C1024_PAGE_SIZE) {
uint16_t bytesToWrite = (endAddress - addr < AT24C1024_PAGE_SIZE) ? (endAddress - addr) : AT24C1024_PAGE_SIZE;
uint16_t offset = Address % AT24C1024_PAGE_SIZE;
uint16_t remaining = AT24C1024_PAGE_SIZE - offset;
bytesToWrite = (bytesToWrite < remaining) ? bytesToWrite : remaining;
EEPROM_ReadBuffer(addr - offset, buffer, AT24C1024_PAGE_SIZE);
if (memcmp(pBuffer, buffer + offset, bytesToWrite) != 0) {
uint8_t buffer[8];
EEPROM_ReadBuffer(Address, buffer, 8);
if (memcmp(pBuffer, buffer, 8) != 0) {
I2C_Start();
I2C_Write(AT24C1024_ADDRESS | ((addr >> 16) & 0x01)); // Sending device address and MSB of memory address
I2C_Write((uint8_t)(addr >> 8)); // Sending address high byte
I2C_Write((uint8_t)(addr & 0xFF)); // Sending address low byte
I2C_WriteBuffer(pBuffer, bytesToWrite);
I2C_Write(0xA0);
I2C_Write((Address >> 8) & 0xFF);
I2C_Write((Address >> 0) & 0xFF);
I2C_WriteBuffer(pBuffer, 8);
I2C_Stop();
}
pBuffer += bytesToWrite;
// give the EEPROM time to burn the data in (assuming 5ms per page write)
SYSTEM_DelayMs(5);
// give the EEPROM time to burn the data in (apparently takes 5ms)
SYSTEM_DelayMs(8);
} else {
uint8_t P0 = (Address / 0x10000) << 1;
I2C_Start();
I2C_Write(0xA4 | P0);
I2C_Write((Address >> 8) & 0xFF);
I2C_Write((Address >> 0) & 0xFF);
I2C_WriteBuffer(pBuffer, 64);
I2C_Stop();
SYSTEM_DelayMs(8);
}
}

View file

@ -19,10 +19,8 @@
#include <stdint.h>
void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size);
void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer);
void E1EPROM_ReadBuffer_1024(uint32_t Address, void *pBuffer, uint16_t Size) ;
void E1EPROM_WriteBuffer_1024(uint32_t Address, const void *pBuffer, uint16_t Size) ;
void EEPROM_ReadBuffer(uint32_t Address, void *pBuffer, uint8_t Size);
void EEPROM_WriteBuffer(uint32_t Address, const void *pBuffer);
#endif

12
main.c
View file

@ -212,14 +212,14 @@ void Main(void)
// for (int i =MDC_ADD[0]; i < MDC_ADD[0]+16; ++i) {
// EEPROM_WriteBuffer(i,&A[i-MDC_ADD[0]]);
// }
uint8_t B[64];
memset(B,'B',sizeof (B));
E1EPROM_WriteBuffer_1024(0x10000,B,64);
E1EPROM_ReadBuffer_1024(0x10000,B,64);
UART_Send(B,64);
while(1)
{
uint8_t B[64];
memset(B,'B',sizeof (B));
EEPROM_ReadBuffer(0x10000,B,64);
EEPROM_ReadBuffer(0x10000,B,64);
UART_Send(B,64);
}
while (1)
{