lcd背光控制信号和蜂鸣器控制信号交换
authorkyz <kongyuzhong@google.com>
Wed, 22 May 2024 06:10:01 +0000 (14:10 +0800)
committerkyz <kongyuzhong@google.com>
Wed, 22 May 2024 06:10:01 +0000 (14:10 +0800)
user/ht1622.c
user/user_app.c
user/user_ui.c
user/user_ui_h3.c

index 87fa5ac4c351f926062b264be84de7db984b78a0..81c73cb23d13c1c22632cc7ddfe78c5cca975a35 100644 (file)
@@ -98,9 +98,9 @@ void ht1622_data_dir_input(void)
     GPIO_InitTypeDef GPIO_InitStruct = {0};
 
     GPIO_InitStruct.Pin = LCD_SDA_Pin;
-    GPIO_InitStruct.Pin = LCD_INT_Pin;
     GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
     GPIO_InitStruct.Pull = GPIO_NOPULL;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
     HAL_GPIO_Init(LCD_SDA_GPIO_Port, &GPIO_InitStruct);
 }
 
@@ -133,7 +133,7 @@ void ht1622_read_bits( uint8_t *data, uint32_t bits )
         ht1622_delay_us(10);
         if( ht1622_data_read() )
             d |= 1<<i;
-        ht1622_rd_clk_l(); //max 75K
+        ht1622_rd_clk_h(); //max 75K
         ht1622_delay_us(10);
     }
     *data = d;
@@ -235,6 +235,29 @@ void ht1622_ram_write( uint8_t addr, uint8_t *data_8b, uint8_t data_nr )
         ht1622_delay_us(5);
     ht1622_cs_h();
 }
+void ht1622_ram_read( uint8_t addr, uint8_t *data_8b, uint8_t data_nr )
+{
+    ht1622_cs_h();
+    ht1622_data_dir_output();
+    ht1622_wr_clk_h();
+    ht1622_rd_clk_h();
+    ht1622_data_out_h();
+
+    ht1622_cs_l();        ht1622_delay_us(5);
+
+    ht1622_write_bits(  MODE_ID_READ, 3, 1 );
+    ht1622_write_bits(  addr, 6, 1 );
+       
+         ht1622_delay_us(5);
+         ht1622_data_dir_input();
+    for( int i=0; i<data_nr; i++ ){
+                               ht1622_read_bits(  &data_8b[i], 8 );
+               }
+         ht1622_delay_us(5);
+         ht1622_data_dir_output();
+    ht1622_delay_us(5);
+    ht1622_cs_h();
+}
 
 
 typedef struct{
index 15271790b42d8c0d04844fbb008a701ce1a9585d..401df2fcd4c38497ece731e41b24ffc9f3aec8de 100644 (file)
@@ -267,7 +267,8 @@ void user_beep_task( void* unused )
     osDelay( 500);
     HAL_TIM_PWM_Stop( &htim13, TIM_CHANNEL_1 );
 #endif
-  
+ 
+#if 0  
     //有源蜂鸣器,配置为输出脚
     HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
     GPIO_InitStruct.Pin = PF8_PWM_SPK_TIM13_CH1_Pin;
@@ -279,49 +280,69 @@ void user_beep_task( void* unused )
     HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
     osDelay(50);
     HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
-  
+#else
+//PE0_LCM_EN  改成蜂鸣器
+//PF8_PWM_SPK_TIM13_CH1 改成背光控制 PWM
+               #define BEEP_CTRL_PIN   LCM_EN_Pin       //GPIO_PIN_0
+               #define BEEP_CTRL_PORT  LCM_EN_GPIO_Port //GPIOE
+               #define BEEP_ON()  HAL_GPIO_WritePin(BEEP_CTRL_PORT, LCM_EN_Pin, GPIO_PIN_SET)
+               #define BEEP_OFF() HAL_GPIO_WritePin(BEEP_CTRL_PORT, LCM_EN_Pin, GPIO_PIN_RESET)
+
+               BEEP_OFF();
+    GPIO_InitStruct.Pin = BEEP_CTRL_PIN;
+    GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
+    GPIO_InitStruct.Pull = GPIO_NOPULL;
+    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
+    HAL_GPIO_Init(BEEP_CTRL_PORT, &GPIO_InitStruct);
+
+    BEEP_ON();
+    osDelay(50);
+    BEEP_OFF();
+
+#endif
+
     //TODO: 实际使用有源, 待修改代码
     while(1){
         //TODO: 按需要增加提示音管理
         if( g_dev.state & FLOWMETER_ERR ){
-            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
+                                               BEEP_ON();
             osDelay(100);
-            HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+                                               BEEP_OFF();
             osDelay(1000);
         }
         if( g_dev.state & CURR_SENSOR_ERR ){
             for( i=0; i<2; i++ ){
                 osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
-                osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+                                                               BEEP_ON();
+                                                               osDelay(100);
+                                                               BEEP_OFF();
             }
             osDelay(1000);
         }
         if( g_dev.state & PRESSURE_SENSOR_ERR ){
             for( i=0; i<3; i++ ){
                 osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
-                osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+                                                               BEEP_ON();
+                                                               osDelay(100);
+                                                               BEEP_OFF();
             }
             osDelay(1000);
         }
         if( g_dev.state & VALVE_CTRL_ERR ){
             for( i=0; i<4; i++ ){
                 osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
-                osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+                                                               BEEP_ON();
+                                                               osDelay(100);
+                                                               BEEP_OFF();
             }
             osDelay(1000);
         }
         if( g_dev.state & TEMP_ERR ){
             for( i=0; i<5; i++ ){
                 osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_SET);
-                osDelay(100);
-                HAL_GPIO_WritePin(PF8_PWM_SPK_TIM13_CH1_GPIO_Port, PF8_PWM_SPK_TIM13_CH1_Pin, GPIO_PIN_RESET);
+                                                               BEEP_ON();
+                                                               osDelay(100);
+                                                               BEEP_OFF();
             }
             osDelay(1000);
         }
index e66f77dcf1249b4b19a0d472d98265de33ef88d7..ea5d8b0e1d33806dc69e35029a7096917c86ac94 100644 (file)
@@ -352,12 +352,12 @@ void lcd_write_u16( uint16_t addr, uint16_t value )
 
 void lcd_power_on( void )
 {
-    HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_SET );
+//    HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_SET );
 }
 
 void lcd_power_off( void )
 {
-    HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_RESET );
+//    HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, GPIO_PIN_RESET );
 }
 
 static uint32_t remote_update_cfg_flag = 0;
index 9d7df7fffde97aae3b6f3a31506dc7045861d3e8..dd63442e26a4809bf68edc489c4dfee6392c69cd 100644 (file)
@@ -104,15 +104,24 @@ int32_t is_btn_pressed_repeat( ui_ev_t *ev, uint8_t btn )
 
 
 static uint8_t bl_level = 0; //0 - 10;
-
-extern void pwm_isr( void )
+static int32_t curr_bl = 0;
+uint32_t bl_compare[11] = {50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000 };
+
+void lcd_bl( uint32_t level )
+{ 
+       if( level > 10 )
+               level = 10;
+       __HAL_TIM_SET_COMPARE(&htim13, TIM_CHANNEL_1,  bl_compare[level] );
+}
+       
+void lcd_bl_init( void )
 {
-       static uint8_t bl_timer_count = 0;    
-       HAL_GPIO_WritePin( LCM_EN_GPIO_Port, LCM_EN_Pin, ( bl_timer_count < bl_level )?GPIO_PIN_SET:GPIO_PIN_RESET );
-       if( bl_timer_count>= 9 )
-               bl_timer_count = 0;
-       else
-               bl_timer_count++;
+       bl_level = 5;
+       curr_bl = 5;
+
+       HAL_TIM_PWM_Start( &htim13, TIM_CHANNEL_1 );
+       __HAL_TIM_SET_COMPARE(&htim13, TIM_CHANNEL_1, 500 );
+       lcd_bl( curr_bl );
 }
 
 #define DEV_MODE_WORK    0
@@ -231,9 +240,17 @@ void ui_evt_handle( ui_ev_t *ev )
                                        HAL_GPIO_WritePin( PB3_LEDG_GPIO_Port, PB3_LEDG_Pin, GPIO_PIN_RESET );
                                        HAL_GPIO_WritePin( PB3_LEDR_GPIO_Port, PB3_LEDR_Pin, (now%1000)<500?GPIO_PIN_SET:GPIO_PIN_RESET );
                                }
+                               //backlight
+                               {
+                                       if(curr_bl != bl_level ){ //bl 0--10
+                                                curr_bl = bl_level;
+                                                lcd_bl( curr_bl );
+                                       }
+                               }
     }
 }
 
+
 void lcd_init( void );
 void user_ui_h3_task( void* unused )
 {
@@ -246,6 +263,7 @@ void user_ui_h3_task( void* unused )
     tick = xTaskGetTickCount();
 
          lcd_init();
+    lcd_bl_init();
 
     while(1){
         //dbg_t1 = TIM7->CNT;