Quellcode durchsuchen

lcd点亮,刷新还有问题

guohui vor 1 Jahr
Ursprung
Commit
970c51bce5

+ 20 - 1
f407/applications/dflt.c

@@ -41,7 +41,26 @@ const paras_data_t DFLT_PARAS={
 
         .misc = {
             .watchdog = 0,
-            .flip_time = 5,
+            
+        #ifdef FLIP_TIME
+            .flip_time = FLIP_TIME,
+        #else
+            .flip_time = 0,
+        #endif
+
+            .led = 0,
+        #ifdef USE_BEEP
+            .beep = 1,
+        #else
+            .beep = 0,
+        #endif
+
+        #ifdef ROTATE
+            .rotate = ROTATE,
+        #else
+            .rotate = 0,
+        #endif
+            
         },
 };
 

+ 1 - 1
f407/applications/main.c

@@ -111,7 +111,7 @@ static int sd_mount(void)
 
 static int user_init(void)
 {
-    //ui_init();
+    ui_init();
     sd_mount();
     
     power_init();

+ 30 - 24
f407/applications/ui/lcd.c

@@ -77,8 +77,7 @@ void lcd_init(int width, int height, uint32_t color)
     
     st77xx_init(h);
     
-    //lcd_draw_string(0, 0, LCD_WIDTH, LCD_HEIGHT/10, "SmartPDU", FONT_12, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
-    //lcd_hw_init(h);
+    lcd_draw_string(0, 60, LCD_WIDTH, LCD_HEIGHT/10, "SmartPDU", FONT_12, COLOR_WHITE, COLOR_BLACK, HORIZONTAL_CENTER, VERTICAL_CENTER);
 }
 
 void lcd_deinit(void)
@@ -233,29 +232,37 @@ void lcd_refresh(void)
     
 }
 
-
+static void set_color(lcd_handle_t *h, uint32_t color, int cnt)
+{
+    int i,xcnt=(cnt>h->buflen/2)?h->buflen/2:cnt;
+    for(i=0; i<xcnt; i++) {
+        h->buf[i] = 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)
 {
     uint8_t tmp;
     font_data_t fdata;
-    int i,j,x0=x,y0=y,x1=x+w,y1=y+h;
+    int i,j,x0=x,y0=y;
+    int x1=x0,y1=y0;
+    int x2=x0+w,y2=y0+h;
     
     fdata = font_data(font, c);
     if(h>fdata.height) {
         if(vert==VERTICAL_CENTER) {
-            y0 += (h-fdata.height)/2;
+            y1 += (h-fdata.height)/2;
         }
         else if (vert==VERTICAL_BOTTOM) {
-            y0 += h-fdata.height;
+            y1 += h-fdata.height;
         }
-        y = y0;
+        y = y1;
     }
     
 #if 0
     for(i=0; i<fdata.dlen; i++)  {
         tmp = fdata.data[i];
         for(j=0; j<8; j++)  {
-            if((x<x1 && x<hd->width) && (y<y1 && y<hd->height)) 
+            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
             {
                 if(tmp&0x01) {
                     set_point(hd, x, y, color);
@@ -267,37 +274,35 @@ int lcd_draw_char(lcd_handle_t *hd, int x, int y, int w, int h, uint8_t *c, int
             tmp >>= 1;
             y++;
 
-            if((y-y0)>=fdata.height) {
-                y=y0; x++;
+            if((y-y1)>=fdata.height) {
+                y=y1; x++;
                 break;
             }
         }
     }
 #else
+    set_color(hd, bgcolor, fdata.width*h);
     for(i=0; i<fdata.dlen; i++)  {
         tmp = fdata.data[i];
         for(j=0; j<8; j++)  {
-            if((x<x1 && x<hd->width) && (y<y1 && y<hd->height)) 
+            if((x<x2 && x<hd->width) && (y<y2 && y<hd->height)) 
             {
-                int x1=x-x0,y1=y-y0;
+                int dx=x-x0,dy=y-y0;
                 
                 if(tmp&0x01) {
-                    hd->buf[y1*fdata.width+x1] = color;
-                }
-                else {
-                    hd->buf[y1*fdata.width+x1] = bgcolor;
+                    hd->buf[dy*fdata.width+dx] = color;
                 }
             }
             tmp >>= 1;
             y++;
 
-            if((y-y0)>=fdata.height) {
-                y=y0; x++;
+            if((y-y1)>=fdata.height) {
+                y=y1; x++;
                 break;
             }
         }
     }
-    st77xx_refresh(hd, x0, y0, fdata.width, fdata.height, hd->buf, fdata.width*fdata.height*2);
+    st77xx_refresh(hd, x0, y0, fdata.width, h, hd->buf, fdata.width*h*2);
 #endif
 
     return fdata.width;
@@ -309,7 +314,7 @@ void lcd_draw_string(int x, int y, int w, int h, char *str, int font, uint32_t c
     int r,sw,xmax=x+w;
     lcd_rect_t rect;
     uint8_t *pstr=(uint8_t*)str;
-    lcd_handle_t *h2=&lcdHandle;
+    lcd_handle_t *hd=&lcdHandle;
 
     sw = font_width_str(font, pstr);
     if(sw>w) {
@@ -329,8 +334,8 @@ void lcd_draw_string(int x, int y, int w, int h, char *str, int font, uint32_t c
         return;
     }
     
-    if(rect.x+sw>=h2->width) {
-        rect.w = h2->width-rect.x;
+    if(rect.x+sw>=hd->width) {
+        rect.w = hd->width-rect.x;
     }
     else {
         rect.w = sw;
@@ -339,12 +344,13 @@ void lcd_draw_string(int x, int y, int w, int h, char *str, int font, uint32_t c
     rect.h = h;
 
     while(*pstr)  {
-        r = lcd_draw_char(h2, 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;
-        pstr = font_next(pstr);
         if(!pstr || x>=xmax) {
             break;
         }
+        
+        pstr = font_next(pstr);
     }
 }
 

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

@@ -40,8 +40,8 @@ enum {
 #define LCD_WIDTH   128
 #define LCD_HEIGHT  64
 #else
-#define LCD_WIDTH   240
-#define LCD_HEIGHT  240
+#define LCD_WIDTH   128//240
+#define LCD_HEIGHT  160//240
 #endif
 
 

+ 3 - 4
f407/applications/ui/ui.c

@@ -19,7 +19,7 @@ static void msleep(int ms)
 {
     usleep(ms*1000);
 }
-static void *ui_thread(void *arg)
+static void ui_thread(void *arg)
 {
     int r;
     thread_handle_t *th=(thread_handle_t*)arg;
@@ -31,15 +31,14 @@ static void *ui_thread(void *arg)
         msleep(50);
     }
     menu_deinit();
-    
-    pthread_exit(NULL);
 }
 /////////////////////////////////////////////////////
 
 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

+ 14 - 76
f407/applications/web.c

@@ -11,15 +11,9 @@
 #define TIMER_INTERVAL     1000
 typedef void (*http_fn_t)(void *arg);
 
-#define USE_MG716
-
-
-#ifdef USE_MG716
+typedef struct mg_mgr mg_mgr_t;
 typedef struct mg_tls_opts mg_tls_t;
-#else
-typedef struct mg_serve_http_opts mg_opts_t;
-#define MG_PATH_MAX  128
-#endif
+typedef struct mg_connection mg_conn_t;
 
 typedef struct {
     struct mg_connection *c;
@@ -30,12 +24,8 @@ typedef struct {
 typedef struct {
     pthread_t       tid;
     
-    struct mg_mgr   mgr;
-#ifdef USE_MG716
+    mg_mgr_t        mgr;
     mg_tls_t        tls;
-#else
-    mg_opts_t       opts;
-#endif
     
     handle_t        list;
     char            rootDir[MG_PATH_MAX];
@@ -44,27 +34,18 @@ typedef struct {
 }web_handle_t;
 static web_handle_t webHandle={0};
 
-static int is_ws(struct mg_connection *c)
+static int is_ws(mg_conn_t *c)
 {
-    int r=0;
-#ifdef USE_MG716
-    r = c->is_websocket;
-#else
-    r = (c->flags & MG_F_IS_WEBSOCKET)?1:0;
-#endif
+    return c->is_websocket;
 }
-static int ws_send(struct mg_connection *c, void *data, int len, int isbin)
+static int ws_send(mg_conn_t *c, void *data, int len, int isbin)
 {
     LOGD("____ws_send, len: %d\n", len);
-#ifdef USE_MG716
     mg_ws_send(c, data, len, isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT);
-#else
-    mg_send_websocket_frame(c, isbin?WEBSOCKET_OP_BINARY:WEBSOCKET_OP_TEXT, data, len);
-#endif
     
     return 0;
 }
-static int ws_send_pkt(web_handle_t *h, struct mg_connection *c, uint8_t type, void *data, int len, int isbin)
+static int ws_send_pkt(web_handle_t *h, mg_conn_t *c, uint8_t type, void *data, int len, int isbin)
 {
     pkt_hdr_t *hdr=NULL;
     
@@ -85,7 +66,7 @@ static int ws_send_pkt(web_handle_t *h, struct mg_connection *c, uint8_t type, v
     return 0;
 }
 
-static void send_powerc(web_handle_t *h, struct mg_connection *c)
+static void send_powerc(web_handle_t *h, mg_conn_t *c)
 {
     int i,xlen,offset;
     pkt_hdr_t *hdr=NULL;
@@ -95,7 +76,7 @@ static void send_powerc(web_handle_t *h, struct mg_connection *c)
         ws_send_pkt(h, c, PKT_TYPE_POWER_CH, &pd.pch[i], sizeof(power_ch_t), 1);
     }
 }
-static void send_powerc_once(web_handle_t *h, struct mg_connection *c)
+static void send_powerc_once(web_handle_t *h, mg_conn_t *c)
 {
     int i,xlen,offset;
     pkt_hdr_t *hdr=NULL;
@@ -132,7 +113,7 @@ static void send_powerc_once(web_handle_t *h, struct mg_connection *c)
 }
 
 
-static void send_powert(web_handle_t *h, struct mg_connection *c)
+static void send_powert(web_handle_t *h, mg_conn_t *c)
 {
     int i,r;
     power_data_t pd=power_data_get();
@@ -142,7 +123,7 @@ static void send_powert(web_handle_t *h, struct mg_connection *c)
 
 
 
-static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, struct mg_connection *c)
+static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, mg_conn_t *c)
 {
     int r=0;
     
@@ -258,12 +239,11 @@ static int ws_handle(web_handle_t *h, pkt_hdr_t *hdr, struct mg_connection *c)
     }
 }
 
-static void http_fn(struct mg_connection *c, int ev, void *ev_data)
+static void http_fn(mg_conn_t *c, int ev, void *ev_data)
 {
     int r,flag=0;
     web_handle_t *h=&webHandle;
 
-#ifdef USE_MG716
     if (ev == MG_EV_HTTP_MSG) {
         struct mg_http_message *hm = (struct mg_http_message *) ev_data;
         if (mg_match(hm->uri, mg_str("/ws"), NULL)) {
@@ -286,49 +266,18 @@ static void http_fn(struct mg_connection *c, int ev, void *ev_data)
         pkt_hdr_t *hdr=(pkt_hdr_t*)wm->data.buf;
         ws_handle(h, hdr, c);
     }
-#else
-    if (ev == MG_EV_HTTP_REQUEST) {
-        mg_serve_http(c, (struct http_message *)ev_data, h->opts);
-    }
-    else if(ev == MG_EV_WEBSOCKET_HANDSHAKE_DONE) {
-        paras_data_t *p=paras_get();
-        //ws_send(h, c, PKT_TYPE_PARAS, p, sizeof(paras_data_t), 1);
-        //set_timer(c, TIMER_INTERVAL);
-    }
-    else if(ev == MG_EV_WEBSOCKET_FRAME) {
-        struct websocket_message *wm = (struct websocket_message *) ev_data;
-        pkt_hdr_t *hdr=(pkt_hdr_t*)wm->data;
-        ws_handle(h, hdr, c);
-    }
-    else if(ev==MG_EV_TIMER) {
-        
-    #if 0
-        list_node_t *ln=NULL;
-        r = list_take_node(h->list, &ln, 0);
-        if(r==0) {
-            node_t *n=&ln->data;
-            ws_send(h, c, n->tp, n->buf, n->dlen, 1);
-            list_back_node(h->list, ln);
-        }
-   #endif
-    }
-#endif
 }
 static void timer_fn(void *arg)
 {
     int r;
     web_handle_t *h=(web_handle_t*)arg;
     list_node_t *ln=NULL;
-    struct mg_connection* c;
+    mg_conn_t* c;
     
     r = list_take_node(h->list, &ln, 0);
     if(r==0) {
         node_t *n=&ln->data;
-#ifdef USE_MG716
         for (c = h->mgr.conns; c != NULL; c = c->next) {
-#else
-        for (c = mg_next(&h->mgr, NULL); c != NULL; c = mg_next(&h->mgr, c)) {
-#endif
             ws_send_pkt(h, c, n->tp, n->buf, n->dlen, 1);
         }
         list_back_node(h->list, ln);
@@ -336,13 +285,12 @@ static void timer_fn(void *arg)
 }
 static void web_thread(void *arg)
 {
-    struct mg_connection *nc;
+    mg_conn_t *nc;
     const char *http_addr="http://[::]:80";
     const char *https_addr="https://[::]:443";
     thread_handle_t *th=(thread_handle_t*)arg;
     web_handle_t *h=(web_handle_t*)th->attr->arg;
 
-#ifdef USE_MG716
     mg_log_set(MG_LL_DEBUG);
     mg_mgr_init(&h->mgr);
 
@@ -361,16 +309,6 @@ static void web_thread(void *arg)
     //mh->tls.cert = mg_str(file_load2("/root/run/app/cert/server.crt",0));
     //mh->tls.key = mg_str(file_load2("/root/run/app/cert/server.key",0));
     //mh->tls.name = mg_url_host(https_addr);
-#else
-    mg_mgr_init(&h->mgr, NULL);
-    nc = mg_bind(&h->mgr, "80", http_fn);
-
-    strcpy(h->rootDir, "/web");
-    
-    mg_set_protocol_http_websocket(nc);
-    h->opts.document_root = h->rootDir;
-    h->opts.enable_directory_listing = "yes";
-#endif
     
     while(th->quit==0) {
         mg_mgr_poll(&h->mgr, 300);

+ 5 - 9
f407/drivers/drv/stm32f4xx_hal_msp.c

@@ -405,16 +405,15 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi)
     __HAL_RCC_GPIOC_CLK_ENABLE();
     __HAL_RCC_GPIOB_CLK_ENABLE();
     /**SPI2 GPIO Configuration
-    PC2     ------> SPI2_MISO
-    PC3     ------> SPI2_MOSI
+    PB15     ------> SPI2_MOSI
     PB13     ------> SPI2_SCK
     */
-    GPIO_InitStruct.Pin = GPIO_PIN_2|GPIO_PIN_3;
+    GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
     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(GPIOC, &GPIO_InitStruct);
+    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
     GPIO_InitStruct.Pin = GPIO_PIN_13;
     GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
@@ -468,13 +467,10 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi)
     __HAL_RCC_SPI2_CLK_DISABLE();
 
     /**SPI2 GPIO Configuration
-    PC2     ------> SPI2_MISO
-    PC3     ------> SPI2_MOSI
+    PB15     ------> SPI2_MOSI
     PB13     ------> SPI2_SCK
     */
-    HAL_GPIO_DeInit(GPIOC, GPIO_PIN_2|GPIO_PIN_3);
-
-    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13);
+    HAL_GPIO_DeInit(GPIOB, GPIO_PIN_13|GPIO_PIN_15);
 
   /* USER CODE BEGIN SPI2_MspDeInit 1 */
 

+ 18 - 29
f407/project/app/app.uvoptx

@@ -152,68 +152,57 @@
         <Bp>
           <Number>0</Number>
           <Type>0</Type>
-          <LineNumber>229</LineNumber>
+          <LineNumber>314</LineNumber>
           <EnabledFlag>1</EnabledFlag>
-          <Address>134218756</Address>
+          <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;..\..\rt-thread\libcpu\arm\cortex-m4\context_rvds.S</Filename>
+          <Filename>&lt;1&gt;..\..\applications\ui\st77xx.c</Filename>
           <ExecCommand></ExecCommand>
-          <Expression>\\app\../../rt-thread/libcpu/arm/cortex-m4/context_rvds.S\229</Expression>
-        </Bp>
-        <Bp>
-          <Number>1</Number>
-          <Type>0</Type>
-          <LineNumber>831</LineNumber>
-          <EnabledFlag>1</EnabledFlag>
-          <Address>134244068</Address>
-          <ByteObject>0</ByteObject>
-          <HtxType>0</HtxType>
-          <ManyObjects>0</ManyObjects>
-          <SizeOfObject>0</SizeOfObject>
-          <BreakByAccess>0</BreakByAccess>
-          <BreakIfRCount>1</BreakIfRCount>
-          <Filename>&lt;1&gt;..\..\rt-thread\src\memheap.c</Filename>
-          <ExecCommand></ExecCommand>
-          <Expression>\\app\../../rt-thread/src/memheap.c\831</Expression>
+          <Expression>\\app\../../applications/ui/st77xx.c\314</Expression>
         </Bp>
       </Breakpoint>
       <WatchWindow1>
         <Ww>
           <count>0</count>
           <WinNumber>1</WinNumber>
-          <ItemText>io-&gt;len,0x0A</ItemText>
+          <ItemText>x</ItemText>
         </Ww>
         <Ww>
           <count>1</count>
           <WinNumber>1</WinNumber>
-          <ItemText>xlen,0x0A</ItemText>
+          <ItemText>y,0x0A</ItemText>
         </Ww>
         <Ww>
           <count>2</count>
           <WinNumber>1</WinNumber>
-          <ItemText>n,0x0A</ItemText>
+          <ItemText>fdata.width,0x0A</ItemText>
         </Ww>
         <Ww>
           <count>3</count>
           <WinNumber>1</WinNumber>
-          <ItemText>len,0x0A</ItemText>
+          <ItemText>h,0x0A</ItemText>
         </Ww>
         <Ww>
           <count>4</count>
           <WinNumber>1</WinNumber>
-          <ItemText>alloc_len,0x0A</ItemText>
+          <ItemText>x0,0x0A</ItemText>
+        </Ww>
+        <Ww>
+          <count>5</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>y0,0x0A</ItemText>
         </Ww>
       </WatchWindow1>
       <MemoryWindow1>
         <Mm>
           <WinNumber>1</WinNumber>
-          <SubType>2</SubType>
-          <ItemText>0x10003070</ItemText>
+          <SubType>10</SubType>
+          <ItemText>hd-&gt;buf</ItemText>
           <AccSizeX>0</AccSizeX>
         </Mm>
       </MemoryWindow1>
@@ -271,7 +260,7 @@
 
   <Group>
     <GroupName>applications</GroupName>
-    <tvExp>0</tvExp>
+    <tvExp>1</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
@@ -2831,7 +2820,7 @@
 
   <Group>
     <GroupName>drivers/drv</GroupName>
-    <tvExp>0</tvExp>
+    <tvExp>1</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>