[X9D] Corrections from Mike on LCD driver. Addition of 2 grayscales in LCD functions.

This commit is contained in:
bsongis
2012-12-27 18:46:11 +00:00
parent 326f85dcd7
commit 759027cea4
17 changed files with 276 additions and 263 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk)
* @note CoOS may schedule when exiting this ISR.
*******************************************************************************
*/
void SysTick_Handler(void)
void SysTickk_Handler(void)
{
OSSchedLock++; /* Lock scheduler. */
OSTickCnt++; /* Increment systerm time. */
+5 -2
View File
@@ -108,8 +108,11 @@ extern uint16_t sessionTimer;
#define wdt_reset()
#endif
#define setBacklight(xx)
uint32_t check_soft_power();
#define check_soft_power() (e_power_on)
#define setBacklight(xx)
#define __BACKLIGHT_ON
#define __BACKLIGHT_OFF
#define IS_BACKLIGHT_ON() (1)
#endif
+1 -1
View File
@@ -807,7 +807,7 @@ void RlcFile::DisplayProgressBar(uint8_t x)
{
if (s_eeDirtyMsk || isWriting() || eeprom_buffer_size) {
uint8_t len = s_eeDirtyMsk ? 1 : limit((uint8_t)1, (uint8_t)(7 - (m_rlc_len/m_ratio)), (uint8_t)7);
lcd_filled_rect(x+1, 0, 5, FH, SOLID, WHITE);
lcd_filled_rect(x+1, 0, 5, FH, SOLID, ERASE);
lcd_filled_rect(x+2, 7-len, 3, len);
}
}
+6
View File
@@ -50,4 +50,10 @@
extern void sdPoll10ms();
#define SPEAKER_ON TCCR0A |= (1 << COM0A0)
#define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0)
#define __BACKLIGHT_ON PORTC |= (1 << OUT_C_LIGHT)
#define __BACKLIGHT_OFF PORTC &= ~(1 << OUT_C_LIGHT)
#define IS_BACKLIGHT_ON() (PORTC & (1<<OUT_C_LIGHT))
#endif
+40 -12
View File
@@ -234,13 +234,13 @@ void lcd_putcAtt(xcoord_t x, uint8_t y, const unsigned char c, LcdFlags mode)
void lcd_putc(xcoord_t x, uint8_t y, const unsigned char c)
{
lcd_putcAtt(x,y,c,0);
lcd_putcAtt(x, y, c, 0);
}
void lcd_putsiAtt(xcoord_t x, uint8_t y,const pm_char * s,uint8_t idx, LcdFlags flags)
{
uint8_t length;
length = pgm_read_byte(s++) ;
length = pgm_read_byte(s++);
lcd_putsnAtt(x,y,s+length*idx,length,flags & ~(BSS|ZCHAR));
}
@@ -437,26 +437,54 @@ void lcd_outdezNAtt(xcoord_t x, uint8_t y, int16_t val, LcdFlags flags, uint8_t
if (neg) lcd_putcAtt(x, y, '-', flags);
}
void lcd_mask(uint8_t *p, uint8_t mask, uint8_t att)
#if defined(PCBX9D)
void lcd_mask(uint8_t *p, uint8_t mask, LcdFlags att)
{
ASSERT_IN_DISPLAY(p);
if (att & BLACK)
if (!(att & GREY1)) {
if (att & FORCE)
*p |= mask;
else if (att & ERASE)
*p &= ~mask;
else
*p ^= mask;
}
if (!(att & GREY2)) {
p += DISPLAY_PLAN_SIZE;
ASSERT_IN_DISPLAY(p);
if (att & FORCE)
*p |= mask;
else if (att & ERASE)
*p &= ~mask;
else
*p ^= mask;
}
}
#else
void lcd_mask(uint8_t *p, uint8_t mask, LcdFlags att)
{
ASSERT_IN_DISPLAY(p);
if (att & FORCE)
*p |= mask;
else if (att & WHITE)
else if (att & ERASE)
*p &= ~mask;
else
*p ^= mask;
}
#endif
void lcd_plot(xcoord_t x, uint8_t y, uint8_t att)
void lcd_plot(xcoord_t x, uint8_t y, LcdFlags att)
{
uint8_t *p = &displayBuf[ y / 8 * DISPLAY_W + x ];
if (p<DISPLAY_END)
lcd_mask(p, BITMASK(y%8), att);
}
void lcd_hlineStip(xcoord_t x, uint8_t y, xcoord_t w, uint8_t pat, uint8_t att)
void lcd_hlineStip(xcoord_t x, uint8_t y, xcoord_t w, uint8_t pat, LcdFlags att)
{
if (y >= DISPLAY_H) return;
if (x+w > DISPLAY_W) { w = DISPLAY_W - x; }
@@ -476,7 +504,7 @@ void lcd_hlineStip(xcoord_t x, uint8_t y, xcoord_t w, uint8_t pat, uint8_t att)
}
}
void lcd_hline(xcoord_t x, uint8_t y, xcoord_t w, uint8_t att)
void lcd_hline(xcoord_t x, uint8_t y, xcoord_t w, LcdFlags att)
{
lcd_hlineStip(x, y, w, 0xff, att);
}
@@ -515,7 +543,7 @@ void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat)
}
#else
// allows the att parameter...
void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, uint8_t att)
void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, LcdFlags att)
{
if (x >= DISPLAY_W) return;
if (h<0) { y+=h; h=-h; }
@@ -554,7 +582,7 @@ void lcd_vline(xcoord_t x, int8_t y, int8_t h)
lcd_vlineStip(x, y, h, 0xff);
}
void lcd_rect(xcoord_t x, uint8_t y, xcoord_t w, uint8_t h, uint8_t pat, uint8_t att)
void lcd_rect(xcoord_t x, uint8_t y, xcoord_t w, uint8_t h, uint8_t pat, LcdFlags att)
{
lcd_vlineStip(x, y, h, pat);
lcd_vlineStip(x+w-1, y, h, pat);
@@ -563,10 +591,10 @@ void lcd_rect(xcoord_t x, uint8_t y, xcoord_t w, uint8_t h, uint8_t pat, uint8_t
lcd_hlineStip(x, y, w, pat);
}
void lcd_filled_rect(xcoord_t x, int8_t y, xcoord_t w, uint8_t h, uint8_t pat, uint8_t att)
void lcd_filled_rect(xcoord_t x, int8_t y, xcoord_t w, uint8_t h, uint8_t pat, LcdFlags att)
{
for (int8_t i=y; i<y+h; i++) {
if (i>=0 && i<64) lcd_hlineStip(x, i, w, pat, att);
if (i>=0 && i<DISPLAY_H) lcd_hlineStip(x, i, w, pat, att);
pat = (pat >> 1) + ((pat & 1) << 7);
}
}
+20 -11
View File
@@ -88,8 +88,8 @@
#define LEFT 0x80 /* align left */
/* line, rect, square flags */
#define BLACK 0x02
#define WHITE 0x04
#define FORCE 0x02
#define ERASE 0x04
#define ROUND 0x08
/* switches flags */
@@ -103,6 +103,8 @@
#define MIDSIZE 0x0100
#define SMLSIZE 0x0200
#define TINSIZE 0x0400
#define GREY1 0x1000
#define GREY2 0x2000
#else
#define MIDSIZE DBLSIZE
#define SMLSIZE 0x00
@@ -115,7 +117,14 @@
#define LcdFlags uint8_t
#endif
#define DISPLAY_BUF_SIZE (DISPLAY_W*((DISPLAY_H+7)/8))
#define DISPLAY_PLAN_SIZE (DISPLAY_W*((DISPLAY_H+7)/8))
#if defined(PCBX9D)
#define DISPLAY_BUF_SIZE (2*DISPLAY_PLAN_SIZE)
#else
#define DISPLAY_BUF_SIZE DISPLAY_PLAN_SIZE
#endif
extern uint8_t displayBuf[DISPLAY_BUF_SIZE];
extern uint8_t lcdLastPos;
@@ -173,21 +182,21 @@ extern void putsTime(xcoord_t x, uint8_t y, putstime_t tme, LcdFlags att, LcdFla
#define SOLID 0xff
#define DOTTED 0x55
extern void lcd_plot(xcoord_t x, uint8_t y, uint8_t att=0);
extern void lcd_hline(xcoord_t x, uint8_t y, xcoord_t w, uint8_t att=0);
extern void lcd_hlineStip(xcoord_t x, uint8_t y, xcoord_t w, uint8_t pat, uint8_t att=0);
extern void lcd_plot(xcoord_t x, uint8_t y, LcdFlags att=0);
extern void lcd_hline(xcoord_t x, uint8_t y, xcoord_t w, LcdFlags att=0);
extern void lcd_hlineStip(xcoord_t x, uint8_t y, xcoord_t w, uint8_t pat, LcdFlags att=0);
extern void lcd_vline(xcoord_t x, int8_t y, int8_t h);
#if defined(PCBSTD)
extern void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat);
#else
extern void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, uint8_t att=0);
extern void lcd_vlineStip(xcoord_t x, int8_t y, int8_t h, uint8_t pat, LcdFlags att=0);
#endif
extern void lcd_rect(xcoord_t x, uint8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, uint8_t att=0);
extern void lcd_filled_rect(xcoord_t x, int8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, uint8_t att=0);
extern void lcd_rect(xcoord_t x, uint8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, LcdFlags att=0);
extern void lcd_filled_rect(xcoord_t x, int8_t y, xcoord_t w, uint8_t h, uint8_t pat=SOLID, LcdFlags att=0);
extern void lcd_invert_line(int8_t y);
#define lcd_status_line() lcd_invert_line(7)
inline void lcd_square(xcoord_t x, uint8_t y, xcoord_t w, uint8_t att=0) { lcd_rect(x, y, w, w, SOLID, att); }
inline void lcd_square(xcoord_t x, uint8_t y, xcoord_t w, LcdFlags att=0) { lcd_rect(x, y, w, w, SOLID, att); }
#define DO_CROSS(xx,yy,ww) \
lcd_vline(xx,yy-ww/2,ww); \
@@ -221,7 +230,7 @@ const pm_char * bmpLoad(uint8_t *dest, const char *filename);
#ifdef SIMU
extern bool lcd_refresh;
extern uint8_t lcd_buf[DISPLAY_W*DISPLAY_H/8];
extern uint8_t lcd_buf[DISPLAY_BUF_SIZE];
#endif
#endif
+5 -5
View File
@@ -64,13 +64,13 @@ void displayScreenIndex(uint8_t index, uint8_t count, uint8_t attr)
#if !defined(PCBSTD)
void displayScrollbar(uint8_t x, uint8_t y, uint8_t h, uint16_t offset, uint16_t count, uint8_t visible)
{
lcd_vlineStip(x, y, h, SOLID, WHITE);
lcd_vlineStip(x, y, h, SOLID, ERASE);
lcd_vlineStip(x, y, h, DOTTED);
uint8_t yofs = (h * offset) / count;
uint8_t yhgt = (h * visible) / count;
if (yhgt + yofs > h)
yhgt = h - yofs;
lcd_vlineStip(x, y + yofs, yhgt, SOLID, BLACK);
lcd_vlineStip(x, y + yofs, yhgt, SOLID, FORCE);
}
#endif
@@ -626,7 +626,7 @@ const pm_char * s_global_warning = 0;
void displayBox()
{
lcd_filled_rect(10, 16, DISPLAY_W-20, 40, SOLID, WHITE);
lcd_filled_rect(10, 16, DISPLAY_W-20, 40, SOLID, ERASE);
lcd_rect(10, 16, DISPLAY_W-20, 40);
lcd_puts(16, 3*FH, s_warning);
// could be a place for a s_warning_info
@@ -745,7 +745,7 @@ const char * displayMenu(uint8_t event)
uint8_t display_count = min(s_menu_count, (uint16_t)MENU_MAX_LINES);
lcd_filled_rect(MENU_X, 16, MENU_W, display_count * (FH+1) + 2, SOLID, WHITE);
lcd_filled_rect(MENU_X, 16, MENU_W, display_count * (FH+1) + 2, SOLID, ERASE);
lcd_rect(MENU_X, 16, MENU_W, display_count * (FH+1) + 2);
for (uint8_t i=0; i<display_count; i++) {
@@ -811,7 +811,7 @@ void drawStatusLine()
statusLineTime = 0;
}
lcd_filled_rect(0, 8*FH-statusLineHeight, DISPLAY_W, 8, SOLID, WHITE);
lcd_filled_rect(0, 8*FH-statusLineHeight, DISPLAY_W, 8, SOLID, ERASE);
lcd_putsAtt(5, 8*FH+1-statusLineHeight, statusLineMsg, BSS);
lcd_filled_rect(0, 8*FH-statusLineHeight, DISPLAY_W, 8, SOLID);
}
+3 -3
View File
@@ -1345,7 +1345,7 @@ void DrawCurve(FnFuncP fn, uint8_t offset=0)
yv = (DISPLAY_H-1) - yv * (DISPLAY_H-1) / RESX;
if (prev_yv != 255) {
if (abs((int8_t)yv-prev_yv) <= 1)
lcd_plot(X0+xv-offset, prev_yv, BLACK);
lcd_plot(X0+xv-offset, prev_yv, FORCE);
else
lcd_vline(X0+xv-offset, prev_yv < yv ? yv : yv+1, prev_yv-yv);
}
@@ -1486,12 +1486,12 @@ void menuModelCurveOne(uint8_t event)
if (crv.custom && i>0 && i<crv.points-1)
xx = X0-1-WCHART + (100 + (100 + crv.crv[crv.points+i-1]) * (2*WCHART)) / 200;
lcd_filled_rect(xx, yy-1, 3, 3, SOLID, BLACK); // do markup square
lcd_filled_rect(xx, yy-1, 3, 3, SOLID, FORCE); // do markup square
if (s_editMode>0 && m_posHorz==i) {
if (s_editMode==1 || !BLINK_ON_PHASE) {
// do selection square
lcd_filled_rect(xx-1, yy-2, 5, 5, SOLID, BLACK);
lcd_filled_rect(xx-1, yy-2, 5, 5, SOLID, FORCE);
lcd_filled_rect(xx, yy-1, 3, 3, SOLID);
}
-33
View File
@@ -928,39 +928,6 @@ extern void backlightOn();
#define NUMBER_ANALOG 8
#endif
#if defined(PCBSKY9X)
// TODO remove
void read_9_adc(void);
#endif
#if defined(PCBACT)
#define __BACKLIGHT_ON
#define __BACKLIGHT_OFF
#define IS_BACKLIGHT_ON() (1)
#elif defined(PCBX9D)
#define __BACKLIGHT_ON GPIO_SetBits(GPIOB, GPIO_Pin_BL)
#define __BACKLIGHT_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_BL)
#define IS_BACKLIGHT_ON() (GPIOB & GPIO_Pin_BL)
#elif defined (PCBSKY9X)
#define __BACKLIGHT_ON (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
#define __BACKLIGHT_OFF (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
#define IS_BACKLIGHT_ON() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100)
#elif defined (PCBGRUVIN9X)
#define SPEAKER_ON TCCR0A |= (1 << COM0A0)
#define SPEAKER_OFF TCCR0A &= ~(1 << COM0A0)
#define __BACKLIGHT_ON PORTC |= (1 << OUT_C_LIGHT)
#define __BACKLIGHT_OFF PORTC &= ~(1 << OUT_C_LIGHT)
#define IS_BACKLIGHT_ON() (PORTC & (1<<OUT_C_LIGHT))
#elif defined(SP22)
#define __BACKLIGHT_ON PORTB &= ~(1 << OUT_B_LIGHT)
#define __BACKLIGHT_OFF PORTB |= (1 << OUT_B_LIGHT)
#define IS_BACKLIGHT_ON() (~PORTB & (1<<OUT_B_LIGHT))
#else
#define __BACKLIGHT_ON PORTB |= (1 << OUT_B_LIGHT)
#define __BACKLIGHT_OFF PORTB &= ~(1 << OUT_B_LIGHT)
#define IS_BACKLIGHT_ON() (PORTB & (1<<OUT_B_LIGHT))
#endif
#if defined(PCBSTD) && defined(VOICE) && !defined(SIMU)
#define BACKLIGHT_ON() (Voice.Backlight = 1)
#define BACKLIGHT_OFF() (Voice.Backlight = 0)
+2 -2
View File
@@ -593,7 +593,7 @@ uint32_t Card_CSD[4]; // TODO elsewhere
#endif
bool lcd_refresh = true;
uint8_t lcd_buf[DISPLAY_W*DISPLAY_H/8];
uint8_t lcd_buf[DISPLAY_BUF_SIZE];
void lcdSetRefVolt(uint8_t val)
{
@@ -601,6 +601,6 @@ void lcdSetRefVolt(uint8_t val)
void lcdRefresh()
{
memcpy(lcd_buf, displayBuf, sizeof(displayBuf));
memcpy(lcd_buf, displayBuf, DISPLAY_BUF_SIZE);
lcd_refresh = true;
}
+2 -2
View File
@@ -505,9 +505,9 @@ void Open9xSim::refreshDiplay()
}
}
bmp->setData (buf2,0);
bmp->setData(buf2,0);
bmp->render();
bmf->setBitmap( bmp );
bmf->setBitmap(bmp);
}
}
+7 -2
View File
@@ -121,8 +121,13 @@ uint32_t spi_operation( register uint8_t *tx, register uint8_t *rx, register uin
#define wdt_reset() WDT->WDT_CR = 0xA5000001
#endif
#define setBacklight(xx) PWM->PWM_CH_NUM[0].PWM_CDTYUPD = xx;
uint32_t check_soft_power();
#define setBacklight(xx) PWM->PWM_CH_NUM[0].PWM_CDTYUPD = xx
#define __BACKLIGHT_ON (PWM->PWM_CH_NUM[0].PWM_CDTY = g_eeGeneral.backlightBright)
#define __BACKLIGHT_OFF (PWM->PWM_CH_NUM[0].PWM_CDTY = 100)
#define IS_BACKLIGHT_ON() (PWM->PWM_CH_NUM[0].PWM_CDTY != 100)
void read_9_adc(void);
#endif
+10
View File
@@ -52,4 +52,14 @@ bool checkSlaveMode();
#define JACK_PPM_OUT() PORTG &= ~(1<<OUT_G_SIM_CTL)
#define JACK_PPM_IN() PORTG |= (1<<OUT_G_SIM_CTL)
#if defined(SP22)
#define __BACKLIGHT_ON PORTB &= ~(1 << OUT_B_LIGHT)
#define __BACKLIGHT_OFF PORTB |= (1 << OUT_B_LIGHT)
#define IS_BACKLIGHT_ON() (~PORTB & (1<<OUT_B_LIGHT))
#else
#define __BACKLIGHT_ON PORTB |= (1 << OUT_B_LIGHT)
#define __BACKLIGHT_OFF PORTB &= ~(1 << OUT_B_LIGHT)
#define IS_BACKLIGHT_ON() (PORTB & (1<<OUT_B_LIGHT))
#endif
#endif
+5 -2
View File
@@ -104,8 +104,11 @@ extern uint16_t sessionTimer;
#define wdt_reset()
#endif
#define setBacklight(xx)
uint32_t check_soft_power();
#define setBacklight(xx)
#define __BACKLIGHT_ON GPIO_SetBits(GPIOB, GPIO_Pin_BL)
#define __BACKLIGHT_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_BL)
#define IS_BACKLIGHT_ON() (GPIOB & GPIO_Pin_BL)
#endif
+162 -176
View File
@@ -15,14 +15,8 @@
#include "hal.h"
#include "Macro_define.h"
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
uint16_t EEPROM_ADDRESS;
/* Private functions ---------------------------------------------------------*/
/**
* @brief Configure the used I/O ports pin
* @param None
@@ -63,96 +57,118 @@ void I2C_Configuration(void)
short I2C_START()
{
SDA_H; I2C_delay();
SCL_H; I2C_delay();
//if(!SDA_read)return 0; //SDA线为低电平则总线忙,退出
SDA_L; I2C_delay();
//if(SDA_read) return 0; //SDA线为高电平则总线出错,退出
SCL_L; I2C_delay();
return 1;
SDA_H;
I2C_delay();
SCL_H;
I2C_delay();
// if (!SDA_read) return 0;
SDA_L;
I2C_delay();
// if (SDA_read) return 0;
SCL_L;
I2C_delay();
return 1;
}
void I2C_STOP()
{
SCL_L; I2C_delay();
SDA_L; I2C_delay();
SCL_H; I2C_delay();
SDA_H; I2C_delay();
SCL_L;
I2C_delay();
SDA_L;
I2C_delay();
SCL_H;
I2C_delay();
SDA_H;
I2C_delay();
}
void I2C_ACK()
{
SCL_L; I2C_delay();
SDA_L; I2C_delay();
SCL_H; I2C_delay();
SCL_L; I2C_delay();
SCL_L;
I2C_delay();
SDA_L;
I2C_delay();
SCL_H;
I2C_delay();
SCL_L;
I2C_delay();
}
void I2C_NO_ACK()
{
SCL_L; I2C_delay();
SDA_H; I2C_delay();
SCL_H; I2C_delay();
SCL_L; I2C_delay();
SCL_L;
I2C_delay();
SDA_H;
I2C_delay();
SCL_H;
I2C_delay();
SCL_L;
I2C_delay();
}
short I2C_WAIT_ACK() //返回为:=1有ACK,=0无ACK
{
short i=50;
SCL_L; I2C_delay();
SDA_H; I2C_delay();
SCL_H; I2C_delay();
while(i){
if(SDA_read)
{
I2C_delay();
i--;
}else{
i=2;
break;
}
}
SCL_L; I2C_delay();
return i;
short I2C_WAIT_ACK()
{
short i=50;
SCL_L;
I2C_delay();
SDA_H;
I2C_delay();
SCL_H;
I2C_delay();
while(i) {
if(SDA_read) {
I2C_delay();
i--;
}
else {
i=2;
break;
}
}
SCL_L;
I2C_delay();
return i;
}
void I2C_SEND_DATA(char SendByte)
{
short i=8;
while(i--)
{
SCL_L; I2C_delay();
if(SendByte&0x80)
SDA_H;
else
SDA_L;
SendByte<<=1; I2C_delay();
SCL_H; I2C_delay();
}
SCL_L; I2C_delay();
short i=8;
while (i--) {
SCL_L;
I2C_delay();
if (SendByte&0x80)
SDA_H;
else
SDA_L;
SendByte<<=1;
I2C_delay();
SCL_H;
I2C_delay();
}
SCL_L;
I2C_delay();
}
char I2C_READ() //数据从高位到低位//
char I2C_READ()
{
short i=8;
char ReceiveByte=0;
short i=8;
char ReceiveByte=0;
SDA_H;
while(i--)
{
ReceiveByte<<=1;
SCL_L; I2C_delay();
SCL_H; I2C_delay();
if(SDA_read)
{
ReceiveByte|=0x01;
}
}
SCL_L;
return ReceiveByte;
SDA_H;
while (i--) {
ReceiveByte <<= 1;
SCL_L;
I2C_delay();
SCL_H;
I2C_delay();
if (SDA_read) {
ReceiveByte|=0x01;
}
}
SCL_L;
return ReceiveByte;
}
void I2C_EE_Init()
{
/* GPIO Periph clock enable */
@@ -186,10 +202,8 @@ void I2C_EE_Init()
EEPROM_ADDRESS = EEPROM_Block3_ADDRESS;
#endif
#endif /* EE_M24C64_32 */
}
/**
* @brief Writes one byte to the I2C EEPROM.
* @param pBuffer : pointer to the buffer containing the data to be
@@ -199,21 +213,21 @@ 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_WAIT_ACK();
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
I2C_SEND_DATA((uint8_t)((WriteAddr&0xFF00)>>8) );
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr&0xFF));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)((WriteAddr&0xFF00)>>8) );
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr&0xFF));
I2C_WAIT_ACK();
#endif
I2C_SEND_DATA(*pBuffer);
I2C_WAIT_ACK();
I2C_STOP();
I2C_SEND_DATA(*pBuffer);
I2C_WAIT_ACK();
I2C_STOP();
}
/**
@@ -226,37 +240,37 @@ 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_WAIT_ACK();
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS |EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
I2C_SEND_DATA(ReadAddr);
I2C_WAIT_ACK();
I2C_SEND_DATA(ReadAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
I2C_SEND_DATA((uint8_t)((ReadAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(ReadAddr & 0x00FF));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)((ReadAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(ReadAddr & 0x00FF));
I2C_WAIT_ACK();
#endif
I2C_STOP();
I2C_STOP();
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_READ);
I2C_WAIT_ACK();
while(NumByteToRead)
{
if(NumByteToRead ==1){
*pBuffer =I2C_READ();
I2C_NO_ACK();
I2C_STOP();
}else{
*pBuffer =I2C_READ();
I2C_ACK();
pBuffer++;
}
NumByteToRead--;
}
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS | EE_CMD_READ);
I2C_WAIT_ACK();
while (NumByteToRead) {
if (NumByteToRead == 1) {
*pBuffer =I2C_READ();
I2C_NO_ACK();
I2C_STOP();
}
else {
*pBuffer =I2C_READ();
I2C_ACK();
pBuffer++;
}
NumByteToRead--;
}
}
/**
@@ -267,7 +281,6 @@ void I2C_EE_BufferRead(uint8_t* pBuffer, uint16_t ReadAddr, uint16_t NumByteToRe
* @param NumByteToWrite : number of bytes to write to the EEPROM.
* @retval None
*/
//整页的整页写 其他多字节写
void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteToWrite)
{
uint8_t NumOfPage = 0, NumOfSingle = 0, count = 0;
@@ -279,42 +292,34 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo
NumOfSingle = NumByteToWrite % I2C_FLASH_PAGESIZE;
/* If WriteAddr is I2C_FLASH_PAGESIZE aligned */
if(Addr == 0)
{
if (Addr == 0) {
/* If NumByteToWrite < I2C_FLASH_PAGESIZE */
if(NumOfPage == 0)
{
if (NumOfPage == 0) {
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
/* If NumByteToWrite > I2C_FLASH_PAGESIZE */
else
{
while(NumOfPage--)
{
else {
while (NumOfPage--) {
I2C_EE_PageWrite(pBuffer, WriteAddr, I2C_FLASH_PAGESIZE);
I2C_EE_WaitEepromStandbyState();
WriteAddr += I2C_FLASH_PAGESIZE;
WriteAddr += I2C_FLASH_PAGESIZE;
pBuffer += I2C_FLASH_PAGESIZE;
}
if(NumOfSingle!=0)
{
if (NumOfSingle != 0) {
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
}
/* If WriteAddr is not I2C_FLASH_PAGESIZE aligned */
else
{
else {
/* If NumByteToWrite < I2C_FLASH_PAGESIZE */
if(NumOfPage== 0)
{
if (NumOfPage== 0) {
/* If the number of data to be written is more than the remaining space
in the current page: */
if (NumByteToWrite > count)
{
if (NumByteToWrite > count) {
/* Write the data conained in same page */
I2C_EE_PageWrite(pBuffer, WriteAddr, count);
I2C_EE_WaitEepromStandbyState();
@@ -323,42 +328,36 @@ void I2C_EE_BufferWrite(uint8_t* pBuffer, uint16_t WriteAddr, uint16_t NumByteTo
I2C_EE_PageWrite((uint8_t*)(pBuffer + count), (WriteAddr + count), (NumByteToWrite - count));
I2C_EE_WaitEepromStandbyState();
}
else
{
else {
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
/* If NumByteToWrite > I2C_FLASH_PAGESIZE */
else
{
else {
NumByteToWrite -= count;
NumOfPage = NumByteToWrite / I2C_FLASH_PAGESIZE;
NumOfSingle = NumByteToWrite % I2C_FLASH_PAGESIZE;
if(count != 0)
{
if (count != 0) {
I2C_EE_PageWrite(pBuffer, WriteAddr, count);
I2C_EE_WaitEepromStandbyState();
WriteAddr += count;
pBuffer += count;
}
while(NumOfPage--)
{
while (NumOfPage--) {
I2C_EE_PageWrite(pBuffer, WriteAddr, I2C_FLASH_PAGESIZE);
I2C_EE_WaitEepromStandbyState();
WriteAddr += I2C_FLASH_PAGESIZE;
pBuffer += I2C_FLASH_PAGESIZE;
}
if(NumOfSingle != 0)
{
if (NumOfSingle != 0) {
I2C_EE_PageWrite(pBuffer, WriteAddr, NumOfSingle);
I2C_EE_WaitEepromStandbyState();
}
}
}
//I2C_EE_WaitEepromStandbyState();
}
/**
@@ -372,28 +371,27 @@ 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_WAIT_ACK();
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE);
I2C_WAIT_ACK();
#ifdef EE_M24C08
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
I2C_SEND_DATA(WriteAddr);
I2C_WAIT_ACK();
#elif defined(EE_M24C64_32)
I2C_SEND_DATA((uint8_t)((WriteAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr & 0x00FF));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)((WriteAddr & 0xFF00) >> 8));
I2C_WAIT_ACK();
I2C_SEND_DATA((uint8_t)(WriteAddr & 0x00FF));
I2C_WAIT_ACK();
#endif /* EE_M24C08 */
/* While there is data to be written */
while(NumByteToWrite--)
{
I2C_SEND_DATA(*pBuffer);
I2C_WAIT_ACK();
pBuffer++;
}
I2C_STOP();
/* While there is data to be written */
while (NumByteToWrite--) {
I2C_SEND_DATA(*pBuffer);
I2C_WAIT_ACK();
pBuffer++;
}
I2C_STOP();
}
/**
@@ -405,22 +403,10 @@ void I2C_EE_WaitEepromStandbyState(void)
{
/*__IO*/ volatile uint16_t SR1_Tmp = 0;
do
{
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE);
do {
I2C_START();
I2C_SEND_DATA(EEPROM_ADDRESS|EE_CMD_WRITE);
} while (0 == I2C_WAIT_ACK());
}while(0== I2C_WAIT_ACK());
I2C_STOP();
}
/**
* @}
*/
/**
* @}
*/
/******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/
+3 -7
View File
@@ -27,13 +27,9 @@
#include "stm32f2xx_conf.h"
#include "stdint.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
#define EE_CMD_WRITE (0)
#define EE_CMD_READ (1)
#define I2C_delay() do{delayUsec(5);}while(0)
#define EE_CMD_WRITE (0)
#define EE_CMD_READ (1)
#define I2C_delay() do { delayUsec(5); } while(0)
#define SCL_H do{GPIOB->BSRRL = I2C_EE_SCL;}while(0)
#define SCL_L do{GPIOB->BSRRH = I2C_EE_SCL;}while(0)
+4 -4
View File
@@ -26,14 +26,15 @@ void Set_Address(u8 x, u8 y)
void lcdRefresh()
{
for (uint8_t y=0; y<DISPLAY_H; y++) {
uint8_t *p = &displayBuf[y*DISPLAY_W];
uint8_t *p = &displayBuf[(y>>3)*DISPLAY_W];
uint8_t mask = (1 << (y%8));
Set_Address(0, y);
AspiCmd(0xAF);
for (uint8_t x=0; x<DISPLAY_W; x+=2) {
uint8_t data = (p[x] & mask ? 0x0F : 0) + (p[x+1] & mask ? 0xF0 : 0);
uint8_t data = (p[x] & mask ? 0xC0 : 0) + (p[x+1] & mask ? 0x0C : 0) + (p[DISPLAY_PLAN_SIZE+x] & mask ? 0x30 : 0) + (p[DISPLAY_PLAN_SIZE+x+1] & mask ? 0x03 : 0);
WriteData(data);
}
WriteData(0);
}
}
@@ -110,8 +111,7 @@ static void LCD_Init()
AspiCmd(0xF7); //ending row address of RAM program window.
AspiCmd(0x9F);
AspiCmd(0xAF); //dc2=1,IC into exit SLEEP MODE, dc3=1 gray=ON ¿ª»Ò½× ,dc4=1 Green Enhanc mode disabled ÂÌÉ«Ôöǿģʽ¹Ø
AspiCmd(0xAF); //dc2=1, IC into exit SLEEP MODE, dc3=1 gray=ON, dc4=1 Green Enhanc mode disabled
}
void lcdInit()