Bladeren bron

配置key/led/beep

guohui 1 jaar geleden
bovenliggende
commit
ea58c4a7fd

+ 1 - 14
f407/applications/main.c

@@ -18,19 +18,6 @@
 extern void lwip_sys_init(void);
 
 
-
-static rt_device_t serial;
-static int log_init(void)
-{
-    serial = rt_device_find("uart1");
-    return 0;
-}
-static void log_print(char *ss)
-{
-    rt_device_write(serial, 0, ss, (sizeof(ss)));
-}
-
-
 static int net_init(const char *ip, int port)
 {
 #define SERVER_PORT 8080
@@ -120,7 +107,7 @@ static int user_init(void)
 {
     int r,n=0;
     
-    //ui_init();
+    ui_init();
     //rt_hw_lcd_init();
     //net_init("0.0.0.0", SERVER_PORT);
     

+ 1 - 0
f407/applications/thread.c

@@ -9,6 +9,7 @@ static thread_attr_t thdAttrs[THREAD_ID_MAX]={
     {"polling",     NULL,           NULL,           2*KB,           1},
     {"mqtt",        NULL,           NULL,           2*KB,           1},
     {"mail",        NULL,           NULL,           2*KB,           1},
+    {"ui",          NULL,           NULL,           2*KB,           1},
 };
 static thread_handle_t thdHandles[THREAD_ID_MAX]={0};
 

+ 1 - 0
f407/applications/thread.h

@@ -20,6 +20,7 @@ enum {
     THREAD_ID_POLL,
     THREAD_ID_MQTT,
     THREAD_ID_MAIL,
+    THREAD_ID_UI,
     
     THREAD_ID_MAX
 };

+ 2 - 10
f407/applications/ui/beep.c

@@ -1,22 +1,14 @@
 #include "gpio.h"
 #include "timer.h"
-#include "rtdbg.h"
+#include "log.h"
 #include "beep.h"
 #include "paras.h"
 #include <stdio.h>
 #include <sys/time.h>
 
 
-#if 1
-    #define LOGD  LOG_D
-    #define LOGE  LOG_E
-#else
-    #define LOGD  printf
-    #define LOGE  printf
-#endif
-
 
-#define BEEP_GPIO               103     //PD7=96+7
+#define BEEP_GPIO               GET_PIN(E, 15)
 #define BEEP_ON_LEVEL           1
 #define BEEP_OFF_LEVEL          0
 

+ 2 - 12
f407/applications/ui/gpio.c

@@ -1,23 +1,13 @@
 #include <string.h>
 #include <stdio.h>
 #include "gpio.h"
-#include "rtdbg.h"
-
-
-#if 1
-    #define LOGD  LOG_D
-    #define LOGE  LOG_E
-#else
-    #define LOGD  printf
-    #define LOGE  printf
-#endif
-
+#include "log.h"
 
 
 int gpio_init(int gpio, int io, int hl)
 {
     if(io==GPIO_IN) {
-        rt_pin_mode(gpio, PIN_MODE_OUTPUT);
+        rt_pin_mode(gpio, PIN_MODE_INPUT);
     }
     else {
         rt_pin_mode(gpio, PIN_MODE_OUTPUT);

+ 6 - 15
f407/applications/ui/key.c

@@ -4,25 +4,16 @@
 #include <sys/time.h>
 #include "key.h"
 #include "gpio.h"
-#include "rtdbg.h"
-
-
-#if 1
-    #define LOGD  LOG_D
-    #define LOGE  LOG_E
-#else
-    #define LOGD  printf
-    #define LOGE  printf
-#endif
+#include "log.h"
 
 
 #define KEY_NUM             3
 #define KEY_LONG_TIME       500
 #define KEY_PRESS_LEVEL     0
 
-#define K1_GPIO             101     //PD5, K1
-#define K2_GPIO             102     //PD6, K2
-#define K3_GPIO             104     //PD8, K3
+#define K1_GPIO             GET_PIN(E, 2)     //PE2, K1
+#define K2_GPIO             GET_PIN(E, 3)     //PE3, K2
+#define K3_GPIO             GET_PIN(E, 4)     //PE4, K3
 
 
 typedef struct {
@@ -31,8 +22,8 @@ typedef struct {
     uint8_t  active_level;
 }io_info_t;
 static io_info_t io_info[KEY_NUM]={
-    {K1_GPIO, KEY_OK,    KEY_PRESS_LEVEL},      //S2
-    {K2_GPIO, KEY_UP,    KEY_PRESS_LEVEL},      //S1
+    {K1_GPIO, KEY_UP,    KEY_PRESS_LEVEL},      //S1
+    {K2_GPIO, KEY_OK,    KEY_PRESS_LEVEL},      //S2
     {K3_GPIO, KEY_DOWN,  KEY_PRESS_LEVEL},      //S3
 };
 

+ 12 - 20
f407/applications/ui/lcd.c

@@ -5,26 +5,18 @@
 #include <string.h>
 #include "gpio.h"
 #include "lcd.h"
-#include "rtdbg.h"
+#include "log.h"
 
-#define BK_GPIO             98      //PD2
-#define DC_GPIO             99      //PD3, 96+3=99
-#define RST_GPIO            100     //PD4, 96+4=100
+#define BK_GPIO      GET_PIN(D, 9)     //PD9
+#define DC_GPIO      GET_PIN(D, 8)     //PD8
+#define RST_GPIO     GET_PIN(B, 14)    //PB14
 
-#if 1
-    #define LOGD  LOG_D
-    #define LOGE  LOG_E
-#else
-    #define LOGD  printf
-    #define LOGE  printf
-#endif
 
 #define BIT(x)              (1<<x)
 #define SWAP16(a)           ((uint16_t)((a<<8)|(a>>8)))
 
 
-#define DEV_PATH        "/dev/spidev1.0"
-
+#define DEV_PATH        "spi2"
 
 
 typedef struct {
@@ -42,7 +34,6 @@ typedef struct {
     int         fd;
     int         io;
     uint8_t     *buf;
-
     
     int         buflen;
 }lcd_handle_t;
@@ -58,7 +49,10 @@ static int lcd_hw_init(lcd_handle_t *h)
         return -1;
     }
 
+    gpio_init(BK_GPIO, GPIO_OUT, 0);
     gpio_init(DC_GPIO, GPIO_OUT, 0);
+    gpio_init(RST_GPIO, GPIO_OUT, 0);
+    
     h->buflen = h->width*h->height/8;
     h->buf = (uint8_t*)calloc(1, h->buflen);
     if (!h->buf) {
@@ -86,10 +80,7 @@ static int lcd_hw_init(lcd_handle_t *h)
 }
 static int lcd_hw_write(lcd_handle_t *h, void *data, int len)
 {
-    int r;
-    
-    
-    return 0;
+    return write(h->fd, data, len);
 }
 static void lcd_write_reg(lcd_handle_t *h, uint8_t reg)
 {
@@ -98,10 +89,10 @@ static void lcd_write_reg(lcd_handle_t *h, uint8_t reg)
 }
 static int ssd1309_reset(void)
 {
-    gpio_init(RST_GPIO, GPIO_OUT, 0);
+    gpio_set(RST_GPIO, 0);
     usleep(100*1000);
     gpio_set(RST_GPIO, 1);
-    gpio_deinit(RST_GPIO);
+    
     return 0;
 }
 static void ssd1309_on(lcd_handle_t *h, int flag)
@@ -168,6 +159,7 @@ static void ssd1309_refresh(lcd_handle_t *h)
 }
 static int lcd_hw_deinit(lcd_handle_t *h)
 {
+    gpio_deinit(BK_GPIO);
     gpio_deinit(DC_GPIO);
     gpio_deinit(RST_GPIO);
     

+ 10 - 19
f407/applications/ui/led.c

@@ -2,24 +2,15 @@
 #include "timer.h"
 #include "gpio.h"
 #include "paras.h"
-#include "rtdbg.h"
-
-
-#if 1
-    #define LOGD  LOG_D
-    #define LOGE  LOG_E
-#else
-    #define LOGD  printf
-    #define LOGE  printf
-#endif
+#include "log.h"
 
 
 #ifdef BOARD_EVB_ATK
     #define LEDR_GPIO    GET_PIN(F, 9)
     #define LEDG_GPIO    GET_PIN(F, 10)
 #else
-    #define LEDR_GPIO    GET_PIN(E, 6)
-    #define LEDG_GPIO    -1
+    #define LEDR_GPIO    -1
+    #define LEDG_GPIO    GET_PIN(E, 6)
 #endif
 
 
@@ -55,13 +46,13 @@ static led_para_t led_para[LED_MODE_MAX]={
     {LED_ID_RED,    200, 200,    25,  0},     //LED_MODE_FAULT
     {LED_ID_RED,    50,  50,     -1,  0},     //LED_MODE_FATAL
 #else
-    {LED_ID_RED,   0,   1000, -1, 0},      //LED_MODE_NORMAL
-    {LED_ID_RED,   300, 1000,  -1, 0},     //LED_MODE_UPGRADING
-    {LED_ID_RED,   500, 500,  300,  0},    //LED_MODE_WARN1,
-    {LED_ID_RED,   333, 333,  450,  0},    //LED_MODE_WARN2,
-    {LED_ID_RED,   500, 500,  10, 0},      //LED_MODE_ERROR,
-    {LED_ID_RED,   200, 200,  25, 0},      //LED_MODE_FAULT
-    {LED_ID_RED,   50,  50,   -1, 0},      //LED_MODE_FATAL
+    {LED_ID_GREEN,   0,   1000, -1, 0},      //LED_MODE_NORMAL
+    {LED_ID_GREEN,   300, 1000,  -1, 0},     //LED_MODE_UPGRADING
+    {LED_ID_GREEN,   500, 500,  300,  0},    //LED_MODE_WARN1,
+    {LED_ID_GREEN,   333, 333,  450,  0},    //LED_MODE_WARN2,
+    {LED_ID_GREEN,   500, 500,  10, 0},      //LED_MODE_ERROR,
+    {LED_ID_GREEN,   200, 200,  25, 0},      //LED_MODE_FAULT
+    {LED_ID_GREEN,   50,  50,   -1, 0},      //LED_MODE_FATAL
 #endif
 };
 static led_handle_t ledHandle={0};

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

@@ -5,7 +5,7 @@
 #include "led.h"
 #include "beep.h"
 #include "paras.h"
-#include "rtdbg.h"
+#include "log.h"
 #include "thread.h"
 #include "lang.h"
 #include "timer.h"
@@ -14,14 +14,6 @@
 #define REFRESH_TIME   300
 //#define TEXT_ALIGN
 
-#if 1
-    #define LOGD  LOG_D
-    #define LOGE  LOG_E
-#else
-    #define LOGD  printf
-    #define LOGE  printf
-#endif
-
 enum {
     MENU_SYSTEM=0,
     MENU_INPUT,

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

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

+ 3 - 0
f407/drivers/drv/stm32f4xx_hal_msp.c

@@ -62,6 +62,9 @@ void HAL_MspInit(void)
 
   __HAL_RCC_SYSCFG_CLK_ENABLE();
   __HAL_RCC_PWR_CLK_ENABLE();
+  __HAL_RCC_GPIOB_CLK_ENABLE();
+  __HAL_RCC_GPIOD_CLK_ENABLE();
+  __HAL_RCC_GPIOE_CLK_ENABLE();
 
   /* System interrupt init*/
 

+ 7 - 3
f407/project/app/app.uvoptx

@@ -120,7 +120,6 @@
         <SetRegEntry>
           <Number>0</Number>
           <Key>DLGUARM</Key>
-          <Name>d</Name>
         </SetRegEntry>
         <SetRegEntry>
           <Number>0</Number>
@@ -195,6 +194,11 @@
           <WinNumber>1</WinNumber>
           <ItemText>h</ItemText>
         </Ww>
+        <Ww>
+          <count>9</count>
+          <WinNumber>1</WinNumber>
+          <ItemText>kv-&gt;key</ItemText>
+        </Ww>
       </WatchWindow1>
       <MemoryWindow1>
         <Mm>
@@ -530,7 +534,7 @@
 
   <Group>
     <GroupName>applications/ui</GroupName>
-    <tvExp>0</tvExp>
+    <tvExp>1</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>
@@ -658,7 +662,7 @@
 
   <Group>
     <GroupName>packages/mb</GroupName>
-    <tvExp>0</tvExp>
+    <tvExp>1</tvExp>
     <tvExpOptDlg>0</tvExpOptDlg>
     <cbSel>0</cbSel>
     <RteFlg>0</RteFlg>