Sfoglia il codice sorgente

整理ch编号,0代表总通道,从1开始表示实际通道

guohui 1 anno fa
parent
commit
fa30e923ac

+ 1 - 1
f407/applications/cfg.h

@@ -51,7 +51,7 @@
     //#define PROD_TYPE                           PDU_AC_I3O3
     #define PROD_TYPE                           PDU_AC_I3O1_H
     
-    //#define USE_UI
+    #define USE_UI
 
 
 #else

+ 55 - 28
f407/applications/power.c

@@ -23,6 +23,7 @@ typedef struct {
     
     uint8_t         chs;                    //所有控制板的总通道数
     power_ch_t      **pch;                  //动态指针
+    power_ch_t      ch0;
     
     uint8_t         cnt;                    //实际扫到的板子个数,不可大于BRD_MAX
     uint8_t         brd_max;
@@ -34,7 +35,22 @@ typedef struct {
     product_data_t *prod;
     power_data_t   pdat;
 }power_handle_t;
-power_handle_t pwrHandle={0};
+static board_fn_t board_fn={
+    .get_power = NULL,
+    .get_alarm = NULL,
+    .set_ch = NULL,
+    .set_open_delay = NULL,
+    .set_close_delay = NULL,
+    .set_kb_value = NULL,
+    .set_threshold = NULL,
+    .reset_consump = NULL,
+
+    .detect = NULL,
+    .get_info = NULL,
+    //.get_board = NULL,
+    .set_all = NULL,
+};
+static power_handle_t pwrHandle={0};
 
 
 
@@ -747,7 +763,7 @@ int power_set(int ch, power_ch_t *pch)
 
 static int power_map(power_handle_t *h, int chs)
 {
-    int i,j,r,idx=0;
+    int i,j,r,idx=1;
     board_data_t *pbrd=NULL;
     uint8_t pwr_type=paras_get()->prod.pwr_type;
     
@@ -756,11 +772,16 @@ static int power_map(power_handle_t *h, int chs)
         h->pch = (power_ch_t**)calloc(1, sizeof(power_ch_t*)*chs);
         if(h->pch) {
             h->chs = chs;
+            h->pch[0] = &h->ch0;
+            strcpy(h->pch[0]->info.name, "ALL");
+            
             for(i=1; i<=h->brd_max; i++) {
                 pbrd = h->pbrd[i];
                 if(pbrd) {
                     for(j=0; j<pbrd->chs; j++) {
-                        h->pch[idx++] = &h->pbrd[i]->pch[j];
+                        h->pch[idx] = &h->pbrd[i]->pch[j];
+                        sprintf(h->pch[idx]->info.name, "CH%d", idx);
+                        idx++;
                     }
                 }
             } 
@@ -773,6 +794,8 @@ static int power_map(power_handle_t *h, int chs)
 static int power_clear(power_handle_t *h)
 {
     int i,j;
+    
+    memset(&h->ch0, 0, sizeof(h->ch0));
     for(i=0; i<=h->brd_max; i++) {
         if(h->pbrd[i]) {
             for(j=0; j<h->pbrd[i]->chs; j++) {
@@ -794,8 +817,8 @@ static int power_clear(power_handle_t *h)
 }
 int power_scan(void)
 {
-    int r,i,j,total_chs=0;
-    int ch_idx=0,brd_idx=0;
+    int r,i,j,total_chs=1;
+    int ch_idx=1,brd_idx=0;
     power_ch_t *pch=NULL;
     board_key_t *pkey=NULL;
     board_data_t *pbrd=NULL;
@@ -805,6 +828,10 @@ int power_scan(void)
     lock_on(h->lck);
     power_clear(h);
     
+    pch = &h->ch0;
+    pch->info.addr = 0;
+    pch->info.ch = 0;
+    
     for(i=1; i<=h->brd_max; i++) {
         r = get_key(h, i, &h->key[i]);
         if(r==0) {
@@ -844,11 +871,11 @@ int power_scan(void)
                 pch[j].info.stop_delay  = 1000*times;
                 
                 if(h->prod->pwr_type==PDU_AC_I3O3) {
-                    pch[j].info.ch  = ch_idx+j/3;       //序号程序从0开始
+                    pch[j].info.ch  = ch_idx+j/3;       //序号从1开始, 发给控制板需从0开始
                     pch[j].info.ph_id = j%3;
                 }
                 else {
-                    pch[j].info.ch  = ch_idx+j;         //序号程序从0开始
+                    pch[j].info.ch  = ch_idx+j;         //序号从1开始, 发给控制板需从0开始
                     pch[j].info.ph_id = 0;
                 }
             }
@@ -890,10 +917,10 @@ int power_reset(void)
                 {
                     uint16_t tmp[8];
                     offset = POWER_AC_CH_STAT_L;
-                    for(i=0; i<pbrd->chs; i++) {
+                    for(i=1; i<=pbrd->chs; i++) {
                         tmp[i] = pbrd->pch[i].power[0].status;
                     }
-                    r = write_reg(h, pbrd->addr, offset, tmp, pbrd->chs);
+                    r = write_reg(h, pbrd->addr, offset, tmp+1, pbrd->chs-1);
                 }
                 break;
                 
@@ -944,7 +971,7 @@ int power_reset(void)
                         break;
                     }
                     
-                    for (i=0; i<pbrd->chs; i++) {
+                    for (i=1; i<=pbrd->chs; i++) {
                         memset(data_temp, 0, sizeof(data_temp));
                         offset = POWER_AC3_OUT_ENABLE + i;
                         data_temp[0] = pbrd->pch[i].power[0].status;
@@ -991,7 +1018,7 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
         case AC_SINGLE_S_TYPE:
         case AC_SINGLE_B_TYPE:
         {
-            offset = POWER_AC_CH_STAT_L + pch->info.ch;
+            offset = POWER_AC_CH_STAT_L + pch->info.ch-1;
             tmp[0] = st; tmp[1] = 0;
             r = write_reg(h, pc.info.addr, offset, tmp, 2);
         }
@@ -1000,11 +1027,11 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
         case DCPDU_TYPE:
         {
             uint16_t mask;
-            offset = POWER_DC_STAT_INFO+pch->info.ch;
+            offset = POWER_DC_STAT_INFO+pch->info.ch-1;
             
-            mask = ~(1 << pch->info.ch);
+            mask = ~(1 << (pch->info.ch-1));
             tmp[0] &= mask;
-            tmp[0] |= (st << pch->info.ch);
+            tmp[0] |= (st << (pch->info.ch-1));
             r = write_reg(h, pc.info.addr, offset, tmp, 2);
         }
         break;
@@ -1021,7 +1048,7 @@ int power_set_ch_sw(uint8_t ch, uint8_t on)
             }
             
             tmp[0] = st;
-            offset = reg + +pch->info.ch;
+            offset = reg + +pch->info.ch-1;
             r = write_reg(h, pc.info.addr, offset, tmp, 2);
         }
         break;
@@ -1042,7 +1069,7 @@ static int set_board_sw(board_data_t *pbrd, uint8_t on)
         return -1;
     }
     
-    for(i=0; i<pbrd->chs; i++) {
+    for(i=1; i<=pbrd->chs; i++) {
         r = get_ch(h, i, &pc);
         if(r==0) {
             power_set_ch_sw(pc.info.ch, on);
@@ -1081,33 +1108,33 @@ int power_set_alarm(power_ch_t *pch)
         case AC_SINGLE_S_TYPE:
         case AC_SINGLE_B_TYPE:
         {
-            if (pch->info.ch<0) {
+            if (pch->info.ch==0) {
                 offset = POWER_AC_ALARM_CTRL_TOTAL;
             }
             else {
-                offset = POWER_AC_ALARM_CTRL + pch->info.ch;
+                offset = POWER_AC_ALARM_CTRL + pch->info.ch-1;
             }
         }
         break;
         
         case DCPDU_TYPE:
         {
-            if (pch->info.ch<0) {
+            if (pch->info.ch==0) {
                 offset = POWER_DC_ALARM_CTRL_TOTAL;
             }
             else {
-                offset = POWER_DC_ALARM_CTRL + pch->info.ch;
+                offset = POWER_DC_ALARM_CTRL + pch->info.ch-1;
             }
         }
         break;
         
         case TREE_AC_TYPE:
         {
-            if (pch->info.ch<0) {
+            if (pch->info.ch==0) {
                 offset = POWER_AC3_ALARM_CTRL_TOTAL;
             }
             else {
-                offset = POWER_AC3_ALARM_CTRL + pch->info.ch;
+                offset = POWER_AC3_ALARM_CTRL + pch->info.ch-1;
             }
         }
         break;
@@ -1180,11 +1207,11 @@ int power_set_threshold(power_ch_t *pch)
             data_buf[14] = data_temp;
             data_buf[15] = data_temp>>16;
 
-            if(pch->info.ch<0) {
+            if(pch->info.ch==0) {
                 offset = POWER_AC_TOTAL_THRESHOLD;
             }
             else  {
-                offset = POWER_AC_THRESHOLD_L+pch->info.ch*16;
+                offset = POWER_AC_THRESHOLD_L+(pch->info.ch-1)*16;
             }
 
             r = write_reg(h, pch->info.addr, offset, data_buf, 16);
@@ -1319,7 +1346,7 @@ int power_set_start_delay(power_ch_t *pch)
         case AC_SINGLE_B_TYPE:
         {
             tmp[0] = pch->info.start_delay;
-            offset = POWER_AC_START_DELAY_TIME_L+pch->info.ch;
+            offset = POWER_AC_START_DELAY_TIME_L+pch->info.ch-1;
             r = write_reg(h, pch->info.addr, offset, tmp, 1);
         }
         break;
@@ -1329,7 +1356,7 @@ int power_set_start_delay(power_ch_t *pch)
             uint32_t time=pch->info.start_delay/1000;
             tmp[0] = time & 0xffff;
             tmp[1] = (time >> 16) & 0xffff;
-            offset = POWER_DC_SET_START_DELAY+pch->info.ch;
+            offset = POWER_DC_SET_START_DELAY+pch->info.ch-1;
             r = write_reg(h, pch->info.addr, offset, tmp, 2);
         }
         break;
@@ -1378,7 +1405,7 @@ int power_set_stop_delay(power_ch_t *pch)
         case AC_SINGLE_B_TYPE:
         {
             tmp[0] = pch->info.start_delay;
-            offset = POWER_AC_STOP_DELAY_TIME_L+pch->info.ch;
+            offset = POWER_AC_STOP_DELAY_TIME_L+pch->info.ch-1;
             r = write_reg(h, pch->info.addr, offset, tmp, 1);
         }
         break;
@@ -1388,7 +1415,7 @@ int power_set_stop_delay(power_ch_t *pch)
             uint32_t time=pch->info.stop_delay/1000;
             tmp[0] = time & 0xffff;
             tmp[1] = (time >> 16) & 0xffff;
-            offset = POWER_DC_SET_STOP_DELAY+pch->info.ch;
+            offset = POWER_DC_SET_STOP_DELAY+pch->info.ch-1;
             //r = write_reg(h, pch->info.addr, offset, tmp, 2);
         }
         break;

+ 2 - 3
f407/applications/ui/lcd.c

@@ -67,13 +67,12 @@ static int get_color_bits(int color)
 }
 
 ////////////////////////////////////////////////////////////
-void lcd_init(int width, int height, uint32_t color)
+void lcd_init(int width, int height, int rotate)
 {
     lcd_handle_t *h=&lcdHandle;
     h->width  = width;
     h->height = height;
-    h->color  = color;
-    h->rotate = 0;
+    h->rotate = rotate;
     
     st77xx_init(h);
     

+ 28 - 33
f407/applications/ui/lcd.h

@@ -30,46 +30,41 @@ enum {
 #define CS_PIN      GET_PIN(B, 12)
 #define BK_PIN      GET_PIN(D, 9)     //PD9
 #define DC_PIN      GET_PIN(D, 8)     //PD8
-#define RST_PIN     GET_PIN(B, 14)    //PB14
+#define RST_PIN     GET_PIN(F, 14)    //PF14
 
 
-
-#define LCD_COLOR   COLOR_RGB565
-
 #if 0
 #define LCD_WIDTH   128
 #define LCD_HEIGHT  64
 #else
-#define LCD_WIDTH   128//240
-#define LCD_HEIGHT  160//240
+#define LCD_WIDTH   240
+#define LCD_HEIGHT  240
 #endif
 
 
-
-/* 颜色 */
-#if 1
-    #define COLOR_WHITE         	 0xFFFF
-    #define COLOR_BLACK         	 0x0000	  
-    #define COLOR_BLUE               0x001F  
-    #define COLOR_BRED               0XF81F
-    #define COLOR_GRED               0XFFE0
-    #define COLOR_GBLUE              0X07FF
-    #define COLOR_RED           	 0xF800
-    #define COLOR_MAGENTA       	 0xF81F
-    #define COLOR_GREEN         	 0x07E0
-    #define COLOR_CYAN          	 0x7FFF
-    #define COLOR_YELLOW        	 0xFFE0
-    #define COLOR_BROWN 			 0XBC40
-    #define COLOR_BRRED 			 0XFC07
-    #define COLOR_GRAY  			 0X8430
-#elif (LCD_COLOR==COLOR_RGB666)
-    
-#elif (LCD_COLOR==COLOR_RGB888)
-
-#else
-
-
-#endif
+#define RGB565(r, g, b) ((((r)&0xF8) << 8) | (((g)&0xFC) << 3) | ((b) >> 3))
+#define BGR565(r, g, b) ((((b)&0xF8) << 8) | (((g)&0xFC) << 3) | ((r) >> 3))
+#define RGB               RGB565
+
+#define COLOR_BLACK       RGB(0, 0, 0)
+#define COLOR_NAVY        RGB(0, 0, 123)
+#define COLOR_DARKGREEN   RGB(0, 125, 0)
+#define COLOR_DARKCYAN    RGB(0, 125, 123)
+#define COLOR_MAROON      RGB(123, 0, 0)
+#define COLOR_PURPLE      RGB(123, 0, 123)
+#define COLOR_OLIVE       RGB(123, 125, 0)
+#define COLOR_LIGHTGREY   RGB(198, 195, 198)
+#define COLOR_DARKGREY    RGB(123, 125, 123)
+#define COLOR_BLUE        RGB(0, 0, 255)
+#define COLOR_GREEN       RGB(0, 255, 0)
+#define COLOR_CYAN        RGB(0, 255, 255)
+#define COLOR_RED         RGB(255, 0, 0)
+#define COLOR_MAGENTA     RGB(255, 0, 255)
+#define COLOR_YELLOW      RGB(255, 255, 0)
+#define COLOR_WHITE       RGB(255, 255, 255)
+#define COLOR_ORANGE      RGB(255, 165, 0)
+#define COLOR_GREENYELLOW RGB(173, 255, 41)
+#define COLOR_PINK        RGB(255, 130, 198)
 
 
 enum {
@@ -104,10 +99,10 @@ typedef struct {
     int         buflen;
 }lcd_handle_t;
 
-void lcd_init(int width, int height, uint32_t color);
+void lcd_init(int width, int height, int rotate);
 void lcd_deinit(void);
 
-void lcd_rotate(int angle);
+void lcd_rotate(int rotate);
 int lcd_get_rotate(void);
 void lcd_set_backlight(int on);
 void lcd_fill(uint32_t color);

+ 1 - 2
f407/applications/ui/menu.c

@@ -382,8 +382,7 @@ int menu_init(void)
     key_init();
     led_init();
     beep_init();
-    lcd_init(LCD_WIDTH,LCD_HEIGHT,LCD_COLOR);
-    lcd_rotate(misc->rotate);
+    lcd_init(LCD_WIDTH,LCD_HEIGHT, misc->rotate);
     
     return 0;
 }

+ 299 - 0
f407/applications/ui/st77xx.c

@@ -0,0 +1,299 @@
+#include "lcd.h"
+#include "log.h"
+
+#define DIV_NUM                 10
+#define INVERSE                 1
+#define X_OFFSET                0//80
+#define Y_OFFSET                80
+
+
+#define ST77XX_CASET            0x2A
+#define ST77XX_RASET            0x2B
+#define ST77XX_RAMWR            0x2C
+#define ST77XX_RAMRD            0x2E
+
+#define ST77XX_MADCTL           0x36
+#define ST77XX_PIXEL_FORMAT     0x3A
+
+#define ST77XX_MADCTL_MY        0x80
+#define ST77XX_MADCTL_MX        0x40
+#define ST77XX_MADCTL_MV        0x20
+#define ST77XX_MADCTL_ML        0x10
+#define ST77XX_MADCTL_RGB       0x00
+#define ST77XX_MADCTL_BGR       0x08
+#define ST77XX_MADCTL_MH        0x04
+
+
+
+
+#define delay_ms(x)             rt_thread_mdelay(x)
+
+static void st77xx_fill(lcd_handle_t *h, uint16_t color);
+
+static void write_cmd(lcd_handle_t *h, uint8_t reg)
+{
+    gpio_set(DC_PIN, 0);
+    rt_spi_send(h->dev, &reg, 1);
+}
+static void write_data(lcd_handle_t *h, uint8_t data)
+{
+    gpio_set(DC_PIN, 1);
+    rt_spi_send(h->dev, &data, 1);
+}
+static void write_cmd_data(lcd_handle_t *h, uint8_t reg, uint16_t data)
+{
+    write_cmd (h,reg);
+    write_data(h,data);
+}
+static void read_data(lcd_handle_t *h, uint8_t *data, int length)
+{
+    gpio_set(DC_PIN, 1);
+    rt_spi_transfer(h->dev, RT_NULL, data, length);
+}
+static void write_16bit(lcd_handle_t *h, uint16_t data)
+{
+    uint8_t buf[2];
+    
+    buf[0] = data >> 8;
+    buf[1] = data & 0xff;
+    
+    gpio_set(DC_PIN, 1);
+    rt_spi_send(h->dev, buf, 2);
+}
+
+void st77xx_rotate(lcd_handle_t *h, int rotate)
+{
+    uint8_t madctl=0,mode=INVERSE?ST77XX_MADCTL_BGR:ST77XX_MADCTL_RGB;
+    
+    switch (rotate)
+    {
+        case 0:
+        madctl = (0 << 3) | (0 << 5) | (0 << 6) | (0 << 7);
+        break;
+        
+        case 90:
+        madctl = (0 << 3) | (1 << 5) | (1 << 6) | (0 << 7);
+        break;
+        
+        case 180:
+        madctl = (0 << 3) | (0 << 5) | (1 << 6) | (1 << 7);
+        break;
+        
+        case 270:
+        madctl = (0 << 3) | (1 << 5) | (0 << 6) | (1 << 7);
+        break;
+        
+        default:
+        break;
+    }
+    write_cmd_data(h, ST77XX_MADCTL, madctl);
+}
+
+static void st77xx_set_win(lcd_handle_t *hd, int x, int y, int w, int h)
+{
+    int x1=X_OFFSET+x,y1=Y_OFFSET+y;
+     
+    write_cmd (hd,ST77XX_CASET);
+    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_cmd (hd,ST77XX_RASET);
+    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_cmd (hd,ST77XX_RAMWR);
+}
+
+
+
+void st77xx_refresh(lcd_handle_t *hd, uint16_t x, uint16_t y, uint16_t w, uint16_t h, void *data, uint32_t len)
+{
+    if(x>=hd->width || y>=hd->height) {
+        return;
+    }
+    
+    st77xx_set_win(hd, x, y, x+w, y+h);
+    gpio_set(DC_PIN, 1);
+    rt_spi_send(hd->dev, data, len);
+}
+
+
+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,0xB2); //Porch Setting
+    write_data(h,0x0C);
+    write_data(h,0x0C);
+    write_data(h,0x00);
+    write_data(h,0x33);
+    write_data(h,0x33);
+
+    write_cmd (h,0xB7); //Gate Control
+    write_data(h,0x46);
+
+    write_cmd (h,0xBB); //VCOM Setting
+    write_data(h,0x1B);
+
+    write_cmd (h,0xC0); //LCM Control
+    write_data(h,0x2C);
+
+    write_cmd (h,0xC2); //VDV and VRH Command Enable
+    write_data(h,0x01);
+               
+    write_cmd (h,0xC3); //VRH set
+    write_data(h,0x0F);
+               
+    write_cmd (h,0xC4); //VDV set
+    write_data(h,0x20);
+               
+    write_cmd (h,0xC6); //Frame Rate Control
+    write_data(h,0x0F);
+               
+    write_cmd (h,0xD0); //Power Control 1
+    write_data(h,0xA4);
+    write_data(h,0xA1);
+               
+    write_cmd (h,0xD6);
+    write_data(h,0xA1);
+               
+    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,0x05);
+    write_data(h,0x31);
+    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,0x38);
+    write_data(h,0x14);
+    write_data(h,0x14);
+    write_data(h,0x2C);
+    write_data(h,0x32);
+
+    write_cmd (h,0x21); // Dispaly Inversion On
+
+    write_cmd (h,0x29); // Display On
+
+    write_cmd (h,ST77XX_RAMWR); // Memory Write
+}
+
+static void st77xx_reset(lcd_handle_t *h)
+{
+    gpio_set(RST_PIN, 1);       /* LCD Hardware Reset */
+    delay_ms(120);
+    gpio_set(RST_PIN, 0);       /* LCD Hardware Reset */
+    delay_ms(120);
+    gpio_set(RST_PIN, 1);
+    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)
+{
+    int i,cnt2=(cnt<=h->buflen/2)?cnt:h->buflen/2;
+    for(i=0; i<cnt2; i++) {
+        h->buf[i] = color;
+    }
+}
+static void write_color(lcd_handle_t *h, uint16_t color, int cnt)
+{
+    int i;
+    for(i=0; i<cnt; i++) {
+        write_16bit(h, color);
+    }
+}
+static void st77xx_fill(lcd_handle_t *h, uint16_t color)
+{
+    int i,height=h->height/DIV_NUM;
+    
+    fill_color(h, color, h->buflen/2);
+    for(i=0; i<DIV_NUM; i++) {
+        st77xx_refresh(h, 0, i*height, h->width, height, h->buf, h->buflen);
+    }
+}
+
+
+#define SPI_BUS  "spi2"
+#define SPI_DEV_NAME   "spi2.0"
+int st77xx_init(lcd_handle_t *h)
+{
+    int r;
+    struct rt_spi_configuration sc;
+    
+    gpio_init(BK_PIN, GPIO_OUT, 0);
+    gpio_init(DC_PIN, GPIO_OUT, 0);
+    gpio_init(RST_PIN, GPIO_OUT, 0);
+    
+    r = rt_hw_spi_device_attach(SPI_BUS, SPI_DEV_NAME, CS_PIN);
+    if(r!=RT_EOK) {
+        return -1;
+    }
+    
+    h->dev = (struct rt_spi_device*)rt_device_find(SPI_DEV_NAME);
+    if(h->dev==NULL) {
+        return -1;
+    }
+    
+    sc.data_width = 8;
+    sc.max_hz = 32 * 1000 * 1000;
+    sc.mode = RT_SPI_MASTER | RT_SPI_MODE_0 | RT_SPI_MSB;
+    r = rt_spi_configure(h->dev, &sc);
+    
+    h->buflen = (h->width*h->height*2)/DIV_NUM;
+    h->buf = (uint16_t*)malloc(h->buflen);
+    if (!h->buf) {
+        LOGE("malloc buffer falied\n");
+        return -1;
+    }
+    
+    st77xx_reset(h);
+    st77xx_reg_init(h);
+    st77xx_rotate(h, h->rotate);
+    gpio_set(BK_PIN, 1);
+    
+    st77xx_fill(h, COLOR_BLACK);
+    
+
+    return 0;
+}
+int st77xx_deinit(lcd_handle_t *h)
+{
+    gpio_deinit(BK_PIN);
+    gpio_deinit(DC_PIN);
+    gpio_deinit(RST_PIN);
+    
+    free(h->buf);
+    
+    return 0;
+}
+
+
+

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

@@ -38,7 +38,7 @@ int ui_init(void)
 {
     ui_handle_t *h=&uiHandle;
 
-    menu_init();
+    //menu_init();
 #if 0//def USE_UI
     thread_start(THREAD_ID_UI, ui_thread, h);
 #endif

+ 1 - 8
f407/drivers/drv/stm32f4xx_hal_msp.c

@@ -414,14 +414,7 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
     GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
     GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
     HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
-    GPIO_InitStruct.Pin = GPIO_PIN_13;
-    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
-    GPIO_InitStruct.Pull = GPIO_NOPULL;
-    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
-    GPIO_InitStruct.Alternate = GPIO_AF5_SPI2;
-    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
+      
   /* USER CODE BEGIN SPI2_MspInit 1 */
 
   /* USER CODE END SPI2_MspInit 1 */

+ 17 - 25
f407/project/app/app.uvoptx

@@ -120,7 +120,6 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>DLGUARM</Key>
-          <Name>d</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -148,24 +147,7 @@
           <Name>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_1024 -FS08000000 -FL0100000 -FP0($$Device:STM32F407ZGTx$CMSIS\Flash\STM32F4xx_1024.FLM))</Name>
         </SetRegEntry>
       </TargetDriverDllRegistry>
-      <Breakpoint>
-        <Bp>
-          <Number>0</Number>
-          <Type>0</Type>
-          <LineNumber>314</LineNumber>
-          <EnabledFlag>1</EnabledFlag>
-          <Address>134523420</Address>
-          <ByteObject>0</ByteObject>
-          <HtxType>0</HtxType>
-          <ManyObjects>0</ManyObjects>
-          <SizeOfObject>0</SizeOfObject>
-          <BreakByAccess>0</BreakByAccess>
-          <BreakIfRCount>1</BreakIfRCount>
-          <Filename>&lt;1&gt;..\..\applications\ui\st77xx.c</Filename>
-          <ExecCommand></ExecCommand>
-          <Expression>\\app\../../applications/ui/st77xx.c\314</Expression>
-        </Bp>
-      </Breakpoint>
+      <Breakpoint/>
       <WatchWindow1>
         <Ww>
           <count>0</count>
@@ -175,34 +157,44 @@
         <Ww>
           <count>1</count>
           <WinNumber>1</WinNumber>
-          <ItemText>y,0x0A</ItemText>
+          <ItemText>x+w-1,0x0A</ItemText>
         </Ww>
         <Ww>
           <count>2</count>
           <WinNumber>1</WinNumber>
-          <ItemText>fdata.width,0x0A</ItemText>
+          <ItemText>y</ItemText>
         </Ww>
         <Ww>
           <count>3</count>
           <WinNumber>1</WinNumber>
-          <ItemText>h,0x0A</ItemText>
+          <ItemText>y+h-1,0x0A</ItemText>
         </Ww>
         <Ww>
           <count>4</count>
           <WinNumber>1</WinNumber>
-          <ItemText>x0,0x0A</ItemText>
+          <ItemText>color</ItemText>
         </Ww>
         <Ww>
           <count>5</count>
           <WinNumber>1</WinNumber>
-          <ItemText>y0,0x0A</ItemText>
+          <ItemText>dy,0x0A</ItemText>
+        </Ww>
+        <Ww>
+          <count>6</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>dx</ItemText>
+        </Ww>
+        <Ww>
+          <count>7</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>fdata.width</ItemText>
         </Ww>
       </WatchWindow1>
       <MemoryWindow1>
         <Mm>
           <WinNumber>1</WinNumber>
           <SubType>10</SubType>
-          <ItemText>hd-&gt;buf</ItemText>
+          <ItemText>hd-&gt;buf+hd-&gt;buflen/2-232</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow1>

+ 1 - 1
f407/tools/web/data.js

@@ -705,7 +705,7 @@ XXX.hdr = function() {
         }
         
         var data = bin.slice(hdr.len);
-        if(data.byteLength>0 && hdr.len==data.byteLength) {
+        if(data.byteLength>0 && hdr.dlen==data.byteLength) {
             switch(hdr.type) {
                 case PKT_TYPE.PKT_TYPE_POWER_CH:
                     hdr.powerc = BIN.powerc.b2j(data);

+ 15 - 22
f407/tools/wsServer/mg.cpp

@@ -58,16 +58,7 @@ static float rand_float(float min, float max) {
 static void powert_rand(power_total_t* pt)
 {
     int i, cnt = 1;
-#if 0
-    pt->voltage = 1.1f;
-    pt->current = 2.2f;
-    pt->freq = 3.3f;
-    pt->power = 4.4f;
-    pt->consump = 5.5f;
-    pt->active = 6.6f;
-    pt->reactive = 7.7f;
-    pt->apparent = 8.8f;
-#else
+
     if (pt->type >= PDU_AC_I3O3) {
         cnt = 3;
     }
@@ -80,7 +71,6 @@ static void powert_rand(power_total_t* pt)
         pt->total[i].active = rand_float(1.0f, 100.0f);
         pt->total[i].reactive = rand_float(1.0f, 100.0f);
     }
-#endif
 }
 static void powerc_rand(power_ch_t* pc, uint8_t addr, uint8_t ch, uint8_t sch)
 {
@@ -114,29 +104,32 @@ static void powerc_rand(power_ch_t* pc, uint8_t addr, uint8_t ch, uint8_t sch)
 
     pc->time = 0;
 }
+
+typedef struct {
+    uint8_t chs;
+    power_ch_t pch[CH_MAX];
+}powerc_data_t;
+static powerc_data_t powerc_data = {.chs=0};
 static void send_powerc(struct mg_connection* c)
 {
     int i, j, ch = 0;
-    power_ch_t pc;
-#if 1
-#define BOARD_CNT       2
-#define BOARC_CH_CNT    2
+
+    #define BOARD_CNT       2
+    #define BOARC_CH_CNT    2
 
     //uint8_t addr[BOARD_CNT] = {2,4,6,7,8};
     uint8_t addr[BOARD_CNT] = { 2,4 };
-#else
-#define BOARD_CNT       1
-#define BOARC_CH_CNT    1
 
-    uint8_t addr[BOARD_CNT] = { 2 };
-#endif
+    powerc_data_t* pc = &powerc_data;
+    pc->chs = BOARD_CNT * BOARC_CH_CNT;
     for (i = 0; i < BOARD_CNT; i++) {
         for (j = 0; j < BOARC_CH_CNT; j++) {
-            powerc_rand(&pc, addr[i], ch, j);
-            ws_send(c, PKT_TYPE_POWER_CH, &pc, sizeof(pc));
+            powerc_rand(&pc->pch[ch], addr[i], ch, j);
             ch++;
         }
     }
+
+    ws_send(c, PKT_TYPE_POWER_CH, pc->pch, sizeof(power_ch_t)*pc->chs);
 }
 static void send_powert(struct mg_connection* c)
 {