加入eeprom驱动,用于保存屏幕触控的校准数据

This commit is contained in:
2021-08-08 14:49:30 +08:00
parent 4e864ed558
commit 30a814adb9
48 changed files with 23871 additions and 11153 deletions
+93
View File
@@ -0,0 +1,93 @@
/*
* eeprom.c
*
* Created on: Aug 8, 2021
* Author: wuwenfeng
*/
#include "eeprom.h"
extern I2C_HandleTypeDef hi2c2;
void IIC_SAND_DATE(uint16_t DEVICE_ADD,uint16_t IN_DEVICE_ADD,char *DATAS,uint16_t LONG)
{
HAL_I2C_Mem_Write(&hi2c2,DEVICE_ADD,IN_DEVICE_ADD,I2C_MEMADD_SIZE_8BIT,DATAS,LONG,100);
}
void IIC_READ_DATE(uint16_t DEVICE_ADD,uint16_t IN_DEVICE_ADD,char *DATAS,uint16_t LONG)
{
HAL_I2C_Mem_Read(&hi2c2,DEVICE_ADD,IN_DEVICE_ADD,I2C_MEMADD_SIZE_8BIT,DATAS,LONG,100);
}
eeprom_write_buff_info eeprom_write_buffer;
void EPPROM_SLOWWRITE_INIT()
{
eeprom_write_buffer.buff=NULL;
eeprom_write_buffer.end=NULL;
eeprom_write_buffer.head=NULL;
eeprom_write_buffer.save_timeout=5;
eeprom_write_buffer.save_busy=0;
}
void EEPROM_SLOWWRITE_SERVER()
{
eeprom_write_buff *buff;
char data;
if(eeprom_write_buffer.save_busy)
{
if(HAL_GetTick()>eeprom_write_buffer.save_time)
{
eeprom_write_buffer.save_busy=0;
}
}else
{
if(eeprom_write_buffer.head!=NULL)
{
eeprom_write_buffer.save_busy=1;
eeprom_write_buffer.save_time=HAL_GetTick()+eeprom_write_buffer.save_timeout;
buff=eeprom_write_buffer.head->next;
data=eeprom_write_buffer.head->date;
IIC_SAND_DATE(EEPROM_ADDRESS,eeprom_write_buffer.head->add,&data,1);
free(eeprom_write_buffer.head);
eeprom_write_buffer.head=buff;
}
}
}
void EEPROM_READ_BATY(uint16_t IN_DEVICE_ADD,char *DATAS,uint16_t LONG)
{
IIC_READ_DATE(EEPROM_ADDRESS,IN_DEVICE_ADD,DATAS,LONG);
}
void EEPROM_WRITE_BATY(uint16_t IN_DEVICE_ADD,char *DATAS,uint16_t LONG)
{
//IIC_SAND_DATE(EEPROM_ADDRESS,IN_DEVICE_ADD,DATAS,LONG);
uint16_t addoffset=0;
eeprom_write_buff *buff;
eeprom_write_buff *buff2;
while(LONG--)
{
buff =(eeprom_write_buff*)malloc(sizeof(eeprom_write_buff));
if(buff!=NULL)
{
buff->add=IN_DEVICE_ADD+addoffset;
buff->date=DATAS[addoffset];
buff->next=NULL;
}else{return ;}
if(eeprom_write_buffer.head==NULL)
{
eeprom_write_buffer.head=buff;
eeprom_write_buffer.end=buff;
}else
{
buff2=eeprom_write_buffer.end;
buff2->next=buff;
eeprom_write_buffer.end=buff;
}
addoffset++;
}
}
+38
View File
@@ -0,0 +1,38 @@
/*
* eeprom.h
*
* Created on: Aug 8, 2021
* Author: wuwenfeng
*/
#ifndef EEPROM_H_
#define EEPROM_H_
#include "main.h"
#define EEPROM_ADDRESS 0xa0
typedef struct eeprom_write_buff
{
struct eeprom_write_buff *next;
uint16_t add;
char date;
}eeprom_write_buff;
typedef struct eeprom_write_buff_info
{
eeprom_write_buff *buff;
eeprom_write_buff *head;
eeprom_write_buff *end;
uint32_t save_time;
uint8_t save_timeout;
uint8_t save_busy:1;
}eeprom_write_buff_info;
void EPPROM_SLOWWRITE_INIT();
void EEPROM_SLOWWRITE_SERVER();
void EEPROM_READ_BATY(uint16_t IN_DEVICE_ADD,char *DATAS,uint16_t LONG);
void EEPROM_WRITE_BATY(uint16_t IN_DEVICE_ADD,char *DATAS,uint16_t LONG);
#endif /* EEPROM_H_ */
+14 -1
View File
@@ -7,6 +7,8 @@
#include "touch.h"
#include "LCD.h"
#include "eeprom.h"
//默认为touchtype=0的数据.
#define CMD_RDX 0X90
#define CMD_RDY 0XD0
@@ -149,6 +151,13 @@ void TP_DrwaTrage(int x,int y,int r)
void TP_adjustment()
{
//判断是否需要校准,从eeprom获取数据
EEPROM_READ_BATY(16,(char *)&tconfig,sizeof(touch_config));
if(tconfig.begin==0xab&&tconfig.end==0xcd)
{
return;
}
char str[64];
uint16_t y_adc,x_adc,step=0,r=10;
uint16_t y1,y2,y3,y4,x1,x2,x3,x4;
@@ -286,13 +295,17 @@ void TP_adjustment()
tconfig.y_acc=acc_y;
tconfig.y_offset=offset_y;
tconfig.begin=0xab;
tconfig.end=0xcd;
sprintf(str,"x_acc=%f y_acc=%f",acc_x,acc_y);
LCD_ShowString(0,66+16+16+16+16,str,16,RED,RED);
sprintf(str,"x_offset=%d y_offset=%d",offset_x,offset_y);
LCD_ShowString(0,66+16+16+16+16+16,str,16,RED,RED);
}
EEPROM_WRITE_BATY(16,(char *)&tconfig,sizeof(touch_config));
HAL_Delay(1000);
return;