Pārlūkot izejas kodu

1、优化lcd刷新效率

guohui 1 gadu atpakaļ
vecāks
revīzija
0e036ccb28

+ 2 - 2
f407/applications/power.c

@@ -1466,7 +1466,7 @@ int power_set_stop_delay(power_ch_t *pch)
     uint16_t tmp[2],reg,offset;
     uint16_t tmp[2],reg,offset;
     power_handle_t *h=&pwrHandle;
     power_handle_t *h=&pwrHandle;
     
     
-    lock_off(h->lck);
+    lock_on(h->lck);
     switch(pch->info.type) {
     switch(pch->info.type) {
         case AC_SINGLE_S_TYPE:
         case AC_SINGLE_S_TYPE:
         case AC_SINGLE_B_TYPE:
         case AC_SINGLE_B_TYPE:
@@ -1514,7 +1514,7 @@ int power_set_stop_delay(power_ch_t *pch)
         r = -1;
         r = -1;
         break;
         break;
     }
     }
-    lock_on(h->lck);
+    lock_off(h->lck);
     
     
     return r;
     return r;
 }
 }

+ 4 - 4
f407/applications/thread.c

@@ -4,15 +4,15 @@
 
 
 static thread_attr_t thdAttrs[THREAD_ID_MAX]={
 static thread_attr_t thdAttrs[THREAD_ID_MAX]={
     //name          fn              arg             stacksize       prio
     //name          fn              arg             stacksize       prio
-    {"web",         NULL,           NULL,           8*KB,           20},
+    {"web",         NULL,           NULL,           4*KB,           20},
     {"snmp",        NULL,           NULL,           2*KB,           20},
     {"snmp",        NULL,           NULL,           2*KB,           20},
     {"power",       NULL,           NULL,           2*KB,           20},
     {"power",       NULL,           NULL,           2*KB,           20},
     {"polling",     NULL,           NULL,           2*KB,           20},
     {"polling",     NULL,           NULL,           2*KB,           20},
     {"mqtt",        NULL,           NULL,           2*KB,           20},
     {"mqtt",        NULL,           NULL,           2*KB,           20},
     {"mail",        NULL,           NULL,           2*KB,           20},
     {"mail",        NULL,           NULL,           2*KB,           20},
-    {"ui",          NULL,           NULL,           2*KB,           20},
-		{"cascade_scan",          NULL,           NULL,           1*KB,      20},
-		{"cascade_thread",        NULL,           NULL,           2*KB,      20},
+    {"ui",          NULL,           NULL,           3*KB,           20},
+    {"cascade_scan",          NULL,           NULL,           1*KB,      20},
+    {"cascade_thread",        NULL,           NULL,           2*KB,      20},
 };
 };
 static thread_handle_t thdHandles[THREAD_ID_MAX]={0};
 static thread_handle_t thdHandles[THREAD_ID_MAX]={0};
 static void* thread_fn(void *arg)
 static void* thread_fn(void *arg)

+ 21 - 45
f407/applications/ui/lcd.c

@@ -24,6 +24,7 @@ static lcd_handle_t lcdHandle={0};
 
 
 extern int st77xx_init(lcd_handle_t *h);
 extern int st77xx_init(lcd_handle_t *h);
 extern int st77xx_deinit(lcd_handle_t *h);
 extern int st77xx_deinit(lcd_handle_t *h);
+extern void st77xx_set_win(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h);
 extern void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, void *data, uint32_t len);
 extern void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, void *data, uint32_t len);
 extern void st77xx_rotate(lcd_handle_t *h, int rotate);
 extern void st77xx_rotate(lcd_handle_t *h, int rotate);
 extern void st77xx_draw_pixel(lcd_handle_t *hd, uint16_t x, uint16_t y, uint32_t color);
 extern void st77xx_draw_pixel(lcd_handle_t *hd, uint16_t x, uint16_t y, uint32_t color);
@@ -93,10 +94,8 @@ void lcd_deinit(void)
 void lcd_rotate(int rotate)
 void lcd_rotate(int rotate)
 {
 {
     lcd_handle_t *h=&lcdHandle;
     lcd_handle_t *h=&lcdHandle;
-
-    if(rotate==0 || rotate==180) {
-        h->rotate = rotate;
-    }
+    h->rotate = rotate;
+    st77xx_rotate(h, rotate);
 }
 }
 
 
 
 
@@ -218,6 +217,10 @@ void lcd_draw_rect(int x, int y, int w, int h, uint32_t color)
 void lcd_fill_rect(int x, int y, int w, int h, uint32_t color)
 void lcd_fill_rect(int x, int y, int w, int h, uint32_t color)
 {
 {
     lcd_handle_t *hd=&lcdHandle;
     lcd_handle_t *hd=&lcdHandle;
+    
+    if(w==0 || h==0) {
+        return;
+    }
     st77xx_fill_rect(hd, x, y, w, h, color);
     st77xx_fill_rect(hd, x, y, w, h, color);
 }
 }
 
 
@@ -241,7 +244,6 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
     font_data_t fdata;
     font_data_t fdata;
     int i,j,x0=x,y0=y;
     int i,j,x0=x,y0=y;
     int x1=x0,y1=y0;
     int x1=x0,y1=y0;
-    int x2=x0+w,y2=y0+h;
     
     
     fdata = font_data(font, c);
     fdata = font_data(font, c);
     if(h>fdata.height) {
     if(h>fdata.height) {
@@ -253,58 +255,33 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
         }
         }
         y = y1;
         y = y1;
     }
     }
+    int x2=x0+fdata.width,y2=y0+h;
     
     
-#if 0
-    for(i=0; i<fdata.dlen; i++)  {
-        tmp = fdata.data[i];
-        for(j=0; j<8; j++)  {
-            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
-            {
-                if(tmp&0x01) {
-                    set_point(hd, x, y, color);
-                }
-                else {
-                    set_point(hd, x, y, bgcolor);
-                }
-            }
-            tmp >>= 1;
-            y++;
-
-            if((y-y1)>=fdata.height) {
-                y=y1; x++;
-                break;
-            }
-        }
-    }
-#else
-    #if 0
+#if 1
+    set_color(hd, bgcolor, h*fdata.width);
     for(i=0; i<fdata.dlen; i++)  {
     for(i=0; i<fdata.dlen; i++)  {
         tmp = fdata.data[i];
         tmp = fdata.data[i];
         for(j=0; j<8; j++)  {
         for(j=0; j<8; j++)  {
-            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
-            {
-                int dx=x-x1,dy=y-y1;
-                
+            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) {
+                int dx=x-x0,dy=y-y0;
                 if(tmp&0x01) {
                 if(tmp&0x01) {
                     hd->buf[dy*fdata.width+dx] = color;
                     hd->buf[dy*fdata.width+dx] = color;
                 }
                 }
             }
             }
             tmp >>= 1;
             tmp >>= 1;
             y++;
             y++;
-
             if((y-y1)>=fdata.height) {
             if((y-y1)>=fdata.height) {
                 y=y1; x++;
                 y=y1; x++;
                 break;
                 break;
             }
             }
         }
         }
     }
     }
-    st77xx_refresh(hd, x1, y1, fdata.width, fdata.height, hd->buf, fdata.width*fdata.height*2);
-    #else
+    st77xx_refresh(hd, x0, y0, fdata.width, h, hd->buf, fdata.width*h*2);
+#else
     for(i=0; i<fdata.dlen; i++)  {
     for(i=0; i<fdata.dlen; i++)  {
         tmp = fdata.data[i];
         tmp = fdata.data[i];
         for(j=0; j<8; j++)  {
         for(j=0; j<8; j++)  {
-            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
-            {
+            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) {
                 if(tmp&0x01) {
                 if(tmp&0x01) {
                     set_point(hd, x, y, color);
                     set_point(hd, x, y, color);
                 }
                 }
@@ -321,8 +298,6 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
             }
             }
         }
         }
     }
     }
-    #endif
-    
 #endif
 #endif
 
 
     return fdata.width;
     return fdata.width;
@@ -354,8 +329,8 @@ void lcd_draw_string(int x, int y, int w, int h, char *str, int font, uint32_t c
         return;
         return;
     }
     }
     
     
-    if(rect.x+sw>=hd->width) {
-        rect.w = hd->width-rect.x;
+    if(rect.x+sw>=w) {
+        rect.w = w-rect.x;
     }
     }
     else {
     else {
         rect.w = sw;
         rect.w = sw;
@@ -363,15 +338,16 @@ void lcd_draw_string(int x, int y, int w, int h, char *str, int font, uint32_t c
     rect.y = y;
     rect.y = y;
     rect.h = h;
     rect.h = h;
 
 
-    while(*pstr)  {
+    lcd_fill_rect(x, y, rect.x-x, h, bgcolor);
+    while(*pstr) {
         r = lcd_draw_char(hd, rect.x, rect.y, rect.w, rect.h, pstr, font, color, bgcolor, vert);
         r = lcd_draw_char(hd, rect.x, rect.y, rect.w, rect.h, pstr, font, color, bgcolor, vert);
-        rect.x += r;
         if(!pstr || x>=xmax) {
         if(!pstr || x>=xmax) {
             break;
             break;
         }
         }
-        
+        rect.x += r;
         pstr = font_next(pstr);
         pstr = font_next(pstr);
     }
     }
+    lcd_fill_rect(rect.x, y, x+w-rect.x, h, bgcolor);
 }
 }
 
 
 
 

+ 1 - 1
f407/applications/ui/lcd.h

@@ -109,7 +109,7 @@ void lcd_fill(uint32_t color);
 void lcd_draw_line(int x1, int y1, int x2, int y2, uint32_t color);
 void lcd_draw_line(int x1, int y1, int x2, int y2, uint32_t color);
 void lcd_draw_rect(int x1, int y1, int w, int h, uint32_t color);
 void lcd_draw_rect(int x1, int y1, int w, int h, uint32_t color);
 void lcd_fill_rect(int x1, int y1, int w, int h, uint32_t color);
 void lcd_fill_rect(int x1, int y1, int w, int h, uint32_t color);
-
+int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int font, uint32_t color, uint32_t bgcolor, int vert);
 void lcd_draw_string(int x, int y, int width, int height, char *str, int font, uint32_t color, uint32_t bgcolor, int hori, int vert);
 void lcd_draw_string(int x, int y, int width, int height, char *str, int font, uint32_t color, uint32_t bgcolor, int hori, int vert);
 void lcd_refresh(void);
 void lcd_refresh(void);
 #endif
 #endif

+ 34 - 33
f407/applications/ui/menu.c

@@ -117,25 +117,27 @@ static int is_ph3_out(menu_handle_t *h)
     }
     }
     return 0;
     return 0;
 }
 }
-static int get_input(menu_handle_t *h, int ph, power_t *power)
+static int get_input(menu_handle_t *h, int ph, total_t *ttl)
 {
 {
-    int i=0;
-    power_ch_t *pch=NULL;
-
-    if (is_ph3_in(h) && ph>0) {
-        
-    }
-    else {
-        //*pwr = h->dm->_globalPowerManger._PowerInfo;
+    power_data_t pd=power_data_get();
+    if(pd.chs==0 || !ttl) {
+        return -1;
     }
     }
-    return -1;
+    *ttl = pd.ttl.total[ph];
+    return 0;
 }
 }
-static int get_output(menu_handle_t *h, int ch, int ph, power_t *power)
+static int get_output(menu_handle_t *h, int ch, int ph, power_t *pwr)
 {
 {
     int i=-1,j=0;
     int i=-1,j=0;
-    
+    paras_data_t *p=paras_get();
+    power_data_t pd=power_data_get();
 
 
-    return -1;
+    if(ch>pd.chs==0 || !pwr || ch>pd.chs) {
+        return -1;
+    }
+    *pwr = pd.pch[ch].power[ph];
+    
+    return 0;
 }
 }
 static void refresh_handler(void *arg, int last)
 static void refresh_handler(void *arg, int last)
 {
 {
@@ -168,7 +170,7 @@ static void menu_system_paint(menu_handle_t *h, int font1, int font2, int item_h
 {
 {
     char time[40],tmp[60];
     char time[40],tmp[60];
 
 
-    lcd_fill(COLOR_BLACK);
+    //lcd_fill(COLOR_BLACK);
     sprintf(tmp, "SmartPDU");
     sprintf(tmp, "SmartPDU");
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
 
@@ -181,48 +183,47 @@ static void menu_system_paint(menu_handle_t *h, int font1, int font2, int item_h
 
 
     sprintf(tmp, "IP:%s", "11.11.11.11");//getLocalIpAddress("eth0"));
     sprintf(tmp, "IP:%s", "11.11.11.11");//getLocalIpAddress("eth0"));
     lcd_draw_string(0, item_h*3, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h*3, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
-    lcd_refresh();
+    //lcd_refresh();
 }
 }
 static void menu_input_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
 static void menu_input_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
 {
 {
     int r;
     int r;
     char tmp[100];
     char tmp[100];
-    power_t *pwr,info={0};
+    total_t *pttl,ttl;
 
 
-    pwr = &info;
+    pttl = &ttl;
     sprintf(tmp, "%s", lang_get_str(h->lang, STR_ID_INPUT));
     sprintf(tmp, "%s", lang_get_str(h->lang, STR_ID_INPUT));
 
 
-    r = get_input(h, h->ph_in, &info);
+    r = get_input(h, h->ph_in, pttl);
     if(r==0) {
     if(r==0) {
         if(h->menu.menu_lv==1 && h->ph_in>0) {
         if(h->menu.menu_lv==1 && h->ph_in>0) {
             sprintf(tmp, "%s-L%d", lang_get_str(h->lang, STR_ID_INPUT), h->ph_in);
             sprintf(tmp, "%s-L%d", lang_get_str(h->lang, STR_ID_INPUT), h->ph_in);
         }
         }
     }
     }
 
 
-    lcd_fill(COLOR_BLACK);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
 
 #ifdef TEXT_ALIGN
 #ifdef TEXT_ALIGN
-    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_VOLTAGE), pwr->voltage);
+    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_VOLTAGE), pttl->voltage);
     lcd_draw_string(0, item_h, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
-    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_CURRENT), pwr->current);
+    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_CURRENT), pttl->current);
     lcd_draw_string(LCD_WIDTH/2, item_h, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(LCD_WIDTH/2, item_h, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
 
 
-    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_POWER), pwr->power);
+    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_POWER), pttl->power);
     lcd_draw_string(0, item_h*2, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h*2, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
-    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_FACTOR), pwr->factor);
+    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_FACTOR), pttl->total[0].factor);
     lcd_draw_string(LCD_WIDTH/2, item_h*2, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(LCD_WIDTH/2, item_h*2, LCD_WIDTH/2, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
 #else
 #else
-    sprintf(tmp, "%s:%0.2f %s:%0.2f", lang_get_str(h->lang, STR_ID_VOLTAGE), pwr->voltage, lang_get_str(h->lang, STR_ID_CURRENT), pwr->current);
+    sprintf(tmp, "%s:%0.2f %s:%0.2f", lang_get_str(h->lang, STR_ID_VOLTAGE), pttl->voltage, lang_get_str(h->lang, STR_ID_CURRENT), pttl->current);
     lcd_draw_string(0, item_h, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
 
 
-    sprintf(tmp, "%s:%0.2f %s:%0.2f", lang_get_str(h->lang, STR_ID_POWER), pwr->power, lang_get_str(h->lang, STR_ID_FACTOR), pwr->factor);
+    sprintf(tmp, "%s:%0.2f %s:%0.2f", lang_get_str(h->lang, STR_ID_POWER), pttl->power, lang_get_str(h->lang, STR_ID_FACTOR), pttl->factor);
     lcd_draw_string(0, item_h*2, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h*2, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
 #endif
 #endif
-    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_CONSUMP), pwr->consump);
+    sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_CONSUMP), pttl->consump);
     lcd_draw_string(0, item_h*3, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h*3, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
 
 
-    lcd_refresh();
+    //lcd_refresh();
     
     
 }
 }
 static void menu_output_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
 static void menu_output_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
@@ -239,7 +240,7 @@ static void menu_output_paint(menu_handle_t *h, int font1, int font2, int item_h
         sprintf(tmp, "%s CH%d", lang_get_str(h->lang, STR_ID_OUTPUT), h->ch_out+1);
         sprintf(tmp, "%s CH%d", lang_get_str(h->lang, STR_ID_OUTPUT), h->ch_out+1);
     }
     }
 
 
-    lcd_fill(COLOR_BLACK);
+    //lcd_fill(COLOR_BLACK);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
 
     char *pon=((pwr->status)?lang_get_str(h->lang, STR_ID_ON):lang_get_str(h->lang, STR_ID_OFF));
     char *pon=((pwr->status)?lang_get_str(h->lang, STR_ID_ON):lang_get_str(h->lang, STR_ID_OFF));
@@ -263,14 +264,14 @@ static void menu_output_paint(menu_handle_t *h, int font1, int font2, int item_h
     sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_CONSUMP), pwr->consump);
     sprintf(tmp, "%s:%0.2f", lang_get_str(h->lang, STR_ID_CONSUMP), pwr->consump);
     lcd_draw_string(0, item_h*3, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h*3, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
 
 
-    lcd_refresh();
+    //lcd_refresh();
     
     
 }
 }
 static void menu_sensor_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
 static void menu_sensor_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
 {
 {
     char tmp[100];
     char tmp[100];
 
 
-    lcd_fill(COLOR_BLACK);
+    //lcd_fill(COLOR_BLACK);
     sprintf(tmp, "%s/%s", lang_get_str(h->lang, STR_ID_TEMP), lang_get_str(h->lang, STR_ID_HUMI));
     sprintf(tmp, "%s/%s", lang_get_str(h->lang, STR_ID_TEMP), lang_get_str(h->lang, STR_ID_HUMI));
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
 
@@ -292,7 +293,7 @@ static void menu_sensor_paint(menu_handle_t *h, int font1, int font2, int item_h
     lcd_draw_string(0, item_h*2, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
     lcd_draw_string(0, item_h*2, LCD_WIDTH, item_h, tmp, font2, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_LEFT, VERTICAL_CENTER);
 #endif
 #endif
 
 
-    lcd_refresh();
+    //lcd_refresh();
     
     
 }
 }
 static void menu_modbus_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
 static void menu_modbus_paint(menu_handle_t *h, int font1, int font2, int item_h, key_val_t *kv)
@@ -306,7 +307,7 @@ static void menu_modbus_paint(menu_handle_t *h, int font1, int font2, int item_h
         flash_cnt++;
         flash_cnt++;
     }
     }
 
 
-    lcd_fill(COLOR_BLACK);
+    //lcd_fill(COLOR_BLACK);
 
 
     sprintf(tmp, "MODBUS %s", lang_get_str(h->lang, STR_ID_SETT));
     sprintf(tmp, "MODBUS %s", lang_get_str(h->lang, STR_ID_SETT));
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
     lcd_draw_string(0, 0, LCD_WIDTH, item_h, tmp, font1, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
@@ -357,7 +358,7 @@ static void menu_modbus_paint(menu_handle_t *h, int font1, int font2, int item_h
     }
     }
     lcd_draw_string(LCD_WIDTH/2, item_h*3, LCD_WIDTH/2, item_h, tmp, font2, font_color, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
     lcd_draw_string(LCD_WIDTH/2, item_h*3, LCD_WIDTH/2, item_h, tmp, font2, font_color, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 
 
-    lcd_refresh();
+    //lcd_refresh();
 }
 }
 /////////////////////////////////////////////////
 /////////////////////////////////////////////////
 
 

+ 59 - 57
f407/applications/ui/st77xx.c

@@ -5,6 +5,7 @@
 #define INVERSE                 1
 #define INVERSE                 1
 #define ST_OFFSET               80
 #define ST_OFFSET               80
 
 
+#define BIT(x) (1<<x)
 #define ST77XX_CASET            0x2A
 #define ST77XX_CASET            0x2A
 #define ST77XX_RASET            0x2B
 #define ST77XX_RASET            0x2B
 #define ST77XX_RAMWR            0x2C
 #define ST77XX_RAMWR            0x2C
@@ -13,15 +14,13 @@
 #define ST77XX_MADCTL           0x36
 #define ST77XX_MADCTL           0x36
 #define ST77XX_PIXEL_FORMAT     0x3A
 #define ST77XX_PIXEL_FORMAT     0x3A
 
 
-#define ST77XX_MADCTL_MV        0x20
-#define ST77XX_MADCTL_MX        0x40
-#define ST77XX_MADCTL_MY        0x80
-
-#define ST77XX_MADCTL_MH        0x04
-#define ST77XX_MADCTL_ML        0x10
+#define ST77XX_MADCTL_MH        BIT(2)
+#define ST77XX_MADCTL_ML        BIT(4)
+#define ST77XX_MADCTL_MV        BIT(5)
+#define ST77XX_MADCTL_MX        BIT(6)
+#define ST77XX_MADCTL_MY        BIT(7)
 #define ST77XX_MADCTL_RGB       0x00
 #define ST77XX_MADCTL_RGB       0x00
-#define ST77XX_MADCTL_BGR       0x08
-
+#define ST77XX_MADCTL_BGR       BIT(3)
 
 
 #define delay_ms(x)             rt_thread_mdelay(x)
 #define delay_ms(x)             rt_thread_mdelay(x)
 
 
@@ -86,21 +85,22 @@ void st77xx_rotate(lcd_handle_t *h, int rotate)
     write_cmd_data(h, ST77XX_MADCTL, madctl);
     write_cmd_data(h, ST77XX_MADCTL, madctl);
 }
 }
 
 
-static void st77xx_set_win(lcd_handle_t *hd, int x, int y, int w, int h)
+void st77xx_set_win(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h)
 {
 {
     int x1=x,y1=y;
     int x1=x,y1=y;
+    int x2=x+w-1,y2=y+h-1;
     
     
     write_cmd (hd,ST77XX_CASET);
     write_cmd (hd,ST77XX_CASET);
     write_data(hd,x1>>8);
     write_data(hd,x1>>8);
-    write_data(hd,x1&0xff);
-    write_data(hd,(x1+w-1)>>8);
-    write_data(hd,(x1+w-1)&0xff);
+    write_data(hd,x1);
+    write_data(hd,x2>>8);
+    write_data(hd,x2);
 
 
     write_cmd (hd,ST77XX_RASET);
     write_cmd (hd,ST77XX_RASET);
     write_data(hd,y1>>8);
     write_data(hd,y1>>8);
-    write_data(hd,y1&0xff);
-    write_data(hd,(y1+h-1)>>8);
-    write_data(hd,(y1+h-1)&0xff);
+    write_data(hd,y1);
+    write_data(hd,y2>>8);
+    write_data(hd,y2);
 
 
     write_cmd (hd,ST77XX_RAMWR);
     write_cmd (hd,ST77XX_RAMWR);
 }
 }
@@ -113,7 +113,7 @@ void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16
         return;
         return;
     }
     }
     
     
-    st77xx_set_win(hd, x, y, x+w, y+h);
+    st77xx_set_win(hd, x, y, w, h);
     gpio_set(DC_PIN, 1);
     gpio_set(DC_PIN, 1);
     rt_spi_send(hd->dev, data, len);
     rt_spi_send(hd->dev, data, len);
 }
 }
@@ -121,18 +121,15 @@ void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16
 
 
 void st77xx_draw_pixel(lcd_handle_t *hd, uint16_t x, uint16_t y, uint32_t color)
 void st77xx_draw_pixel(lcd_handle_t *hd, uint16_t x, uint16_t y, uint32_t color)
 {
 {
-    st77xx_set_win(hd, x, y, x+1, y+1);
+    st77xx_set_win(hd, x, y, 1, 1);
     write_16bit(hd, color);
     write_16bit(hd, color);
 }
 }
 
 
 
 
 static void st77xx_reg_init(lcd_handle_t *h)
 static void st77xx_reg_init(lcd_handle_t *h)
 {
 {
-    write_cmd (h,ST77XX_MADCTL);
-    write_data(h,0);
-
-    write_cmd (h,ST77XX_PIXEL_FORMAT);
-    write_data(h,0x05); //03=RGB444,05=RGB565,06=RGB666
+    write_cmd (h,0x11);
+    delay_ms(150);
 
 
     write_cmd (h,0xB2); //Porch Setting
     write_cmd (h,0xB2); //Porch Setting
     write_data(h,0x0C);
     write_data(h,0x0C);
@@ -140,12 +137,21 @@ static void st77xx_reg_init(lcd_handle_t *h)
     write_data(h,0x00);
     write_data(h,0x00);
     write_data(h,0x33);
     write_data(h,0x33);
     write_data(h,0x33);
     write_data(h,0x33);
+    
+    write_cmd (h,0x35);
+    write_data(h,0x00);
+    
+    write_cmd (h,ST77XX_MADCTL);
+    write_data(h,0x00);
 
 
-    write_cmd (h,0xB7); //Gate Control
-    write_data(h,0x46);
+    write_cmd (h,ST77XX_PIXEL_FORMAT);
+    write_data(h,0x05); //03=RGB444,05=RGB565,06=RGB666
+    
+    write_cmd (h,0xb7); //Gate Control
+    write_data(h,0x35);
 
 
-    write_cmd (h,0xBB); //VCOM Setting
-    write_data(h,0x1B);
+    write_cmd (h,0xbb); //VCOM Setting
+    write_data(h,0x2d);
 
 
     write_cmd (h,0xC0); //LCM Control
     write_cmd (h,0xC0); //LCM Control
     write_data(h,0x2C);
     write_data(h,0x2C);
@@ -154,7 +160,7 @@ static void st77xx_reg_init(lcd_handle_t *h)
     write_data(h,0x01);
     write_data(h,0x01);
                
                
     write_cmd (h,0xC3); //VRH set
     write_cmd (h,0xC3); //VRH set
-    write_data(h,0x0F);
+    write_data(h,0x15);
                
                
     write_cmd (h,0xC4); //VDV set
     write_cmd (h,0xC4); //VDV set
     write_data(h,0x20);
     write_data(h,0x20);
@@ -170,41 +176,39 @@ static void st77xx_reg_init(lcd_handle_t *h)
     write_data(h,0xA1);
     write_data(h,0xA1);
                
                
     write_cmd (h,0xE0);   /* set Positive Voltage Gamma */
     write_cmd (h,0xE0);   /* set Positive Voltage Gamma */
-    write_data(h,0xF0);
-    write_data(h,0x00);
-    write_data(h,0x06);
-    write_data(h,0x04);
-    write_data(h,0x05);
+    write_data(h,0x70);
     write_data(h,0x05);
     write_data(h,0x05);
-    write_data(h,0x31);
+    write_data(h,0x0a);
+    write_data(h,0x0b);
+    write_data(h,0x0a);
+    write_data(h,0x27);
+    write_data(h,0x2f);
     write_data(h,0x44);
     write_data(h,0x44);
-    write_data(h,0x48);
-    write_data(h,0x36);
-    write_data(h,0x12);
-    write_data(h,0x12);
-    write_data(h,0x2B);
-    write_data(h,0x34);
-
-    write_cmd (h,0xE1);   /* set Negative Voltage Gamma */
-    write_data(h,0xF0);
-    write_data(h,0x0B);
-    write_data(h,0x0F);
-    write_data(h,0x0F);
-    write_data(h,0x0D);
-    write_data(h,0x26);
-    write_data(h,0x31);
-    write_data(h,0x43);
     write_data(h,0x47);
     write_data(h,0x47);
-    write_data(h,0x38);
+    write_data(h,0x37);
     write_data(h,0x14);
     write_data(h,0x14);
     write_data(h,0x14);
     write_data(h,0x14);
-    write_data(h,0x2C);
-    write_data(h,0x32);
+    write_data(h,0x29);
+    write_data(h,0x2f);
 
 
-    write_cmd (h,0x21); // Dispaly Inversion On
+    write_cmd (h,0xE1);   /* set Negative Voltage Gamma */
+    write_data(h,0x70);
+    write_data(h,0x07);
+    write_data(h,0x0c);
+    write_data(h,0x08);
+    write_data(h,0x08);
+    write_data(h,0x04);
+    write_data(h,0x2f);
+    write_data(h,0x33);
+    write_data(h,0x46);
+    write_data(h,0x18);
+    write_data(h,0x15);
+    write_data(h,0x15);
+    write_data(h,0x2b);
+    write_data(h,0x2d);
 
 
+    write_cmd (h,0x21); // Dispaly Inversion On
     write_cmd (h,0x29); // Display On
     write_cmd (h,0x29); // Display On
-
     write_cmd (h,ST77XX_RAMWR); // Memory Write
     write_cmd (h,ST77XX_RAMWR); // Memory Write
 }
 }
 
 
@@ -214,8 +218,6 @@ static void st77xx_reset(lcd_handle_t *h)
     delay_ms(100);
     delay_ms(100);
     gpio_set(RST_PIN, 1);
     gpio_set(RST_PIN, 1);
     delay_ms(120);              /* Delay 120ms */
     delay_ms(120);              /* Delay 120ms */
-    write_cmd(h,0x11);          /* Sleep out */
-    delay_ms(120);              /* Delay 120ms */
 }
 }
 
 
 static void fill_color(lcd_handle_t *h, uint16_t color, int cnt)
 static void fill_color(lcd_handle_t *h, uint16_t color, int cnt)
@@ -289,7 +291,7 @@ int st77xx_init(lcd_handle_t *h)
         LOGE("malloc buffer falied\n");
         LOGE("malloc buffer falied\n");
         return -1;
         return -1;
     }
     }
-return 0;    
+    
     st77xx_reset(h);
     st77xx_reset(h);
     st77xx_reg_init(h);
     st77xx_reg_init(h);
     st77xx_rotate(h, h->rotate);
     st77xx_rotate(h, h->rotate);

+ 1 - 8
f407/applications/ui/ui.c

@@ -6,8 +6,6 @@
 #include "thread.h"
 #include "thread.h"
 #include "cfg.h"
 #include "cfg.h"
 
 
-
-
 typedef struct {
 typedef struct {
     int fd;
     int fd;
     
     
@@ -37,12 +35,7 @@ static void ui_thread(void *arg)
 int ui_init(void)
 int ui_init(void)
 {
 {
     ui_handle_t *h=&uiHandle;
     ui_handle_t *h=&uiHandle;
-
-    //menu_init();
-#ifdef USE_UI
-    //thread_start(THREAD_ID_UI, ui_thread, h);
-#endif
-
+    thread_start(THREAD_ID_UI, ui_thread, h);
     return 0;
     return 0;
 }
 }