Skip to content

Commit f8f8639

Browse files
committed
更新小智MCP控制屏幕亮度
1 parent dfa7d6b commit f8f8639

File tree

14 files changed

+204
-62
lines changed

14 files changed

+204
-62
lines changed

libraries/HAL_Drivers/drv_pwm.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ struct ifx_pwm
3333

3434
static struct ifx_pwm ifx_pwm_obj[] =
3535
{
36-
#ifdef TCPWM_0_GRP_1_PWM_9_CONFIG
37-
TCPWM_0_GRP_1_PWM_9_CONFIG
36+
#ifdef BSP_USING_PWM18
37+
#ifdef TCPWM_0_GRP_1_PWM_9_CONFIG
38+
TCPWM_0_GRP_1_PWM_9_CONFIG,
39+
#endif
3840
#endif
3941
};
4042

43+
4144
#ifndef IFX_PWM_MAX_TICKS
4245
#define IFX_PWM_MAX_TICKS 65535U
4346
#endif

libraries/HAL_Drivers/drv_pwm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
extern "C" {
1919
#endif
2020

21-
#ifdef BSP_USING_PWM0
21+
#ifdef BSP_USING_PWM18
2222

2323
#ifndef TCPWM_0_GRP_1_PWM_9_CONFIG
2424
#define TCPWM_0_GRP_1_PWM_9_CONFIG \
@@ -33,7 +33,7 @@ extern "C" {
3333
}
3434
#endif /* TCPWM_0_GRP_1_PWM_9_CONFIG */
3535

36-
#endif /* BSP_USING_PWM0 */
36+
#endif /* BSP_USING_PWM18 */
3737

3838
#ifdef __cplusplus
3939
}

projects/Edgi_Talk_M55_XiaoZhi/.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1632,7 +1632,7 @@ CONFIG_BSP_USING_HYPERAM_SIZE=0x800000
16321632
CONFIG_BSP_USING_SDCARD=y
16331633
CONFIG_BSP_USING_FS=y
16341634
CONFIG_BSP_USING_PWM=y
1635-
CONFIG_BSP_USING_PWM0=y
1635+
CONFIG_BSP_USING_PWM18=y
16361636
# CONFIG_BSP_USING_TIM is not set
16371637
# CONFIG_BSP_USING_WDT is not set
16381638
CONFIG_BSP_USING_LCD=y

projects/Edgi_Talk_M55_XiaoZhi/applications/main.c

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,6 @@
2222
/* LED Pin */
2323
#define LED_PIN_GREEN GET_PIN(16, 6)
2424

25-
/* Power Control Pins */
26-
#define PIN_ES8388_PWR GET_PIN(16, 2) /* ES8388 power enable */
27-
#define PIN_SPEAKER_EN GET_PIN(21, 6) /* Speaker amplifier enable */
28-
#define PIN_WIFI_PWR GET_PIN(16, 3) /* WiFi power enable */
29-
#define PIN_WIFI_REG GET_PIN(11, 6) /* WiFi register switch */
30-
#define PIN_DCDC_CTRL GET_PIN(7, 2) /* 3V3 DCDC power control */
31-
#define PIN_LCD_BL GET_PIN(15, 7) /* LCD backlight power */
32-
#define PIN_LCD_PWR GET_PIN(15, 6) /* LCD IC power */
33-
#define PIN_LCD_PWM GET_PIN(20, 6) /* LCD PWM brightness */
34-
3525
/* UI initialization timeout (ms) */
3626
#define UI_INIT_TIMEOUT_MS 5000
3727

@@ -42,39 +32,6 @@ extern void xiaozhi_ui_init(void);
4232
extern rt_err_t xiaozhi_ui_wait_ready(rt_int32_t timeout);
4333
extern void wifi_manager_init(void);
4434

45-
/*****************************************************************************
46-
* Private Functions
47-
*****************************************************************************/
48-
49-
/**
50-
* @brief Initialize board power control GPIOs
51-
* @return 0 on success
52-
*/
53-
static int board_power_init(void)
54-
{
55-
/* WiFi power */
56-
rt_pin_mode(PIN_WIFI_PWR, PIN_MODE_OUTPUT);
57-
rt_pin_write(PIN_WIFI_PWR, PIN_HIGH);
58-
59-
rt_pin_mode(PIN_WIFI_REG, PIN_MODE_OUTPUT);
60-
rt_pin_write(PIN_WIFI_REG, PIN_HIGH);
61-
62-
/* Audio power */
63-
rt_pin_mode(PIN_ES8388_PWR, PIN_MODE_OUTPUT);
64-
rt_pin_write(PIN_ES8388_PWR, PIN_HIGH);
65-
66-
rt_pin_mode(PIN_SPEAKER_EN, PIN_MODE_OUTPUT);
67-
rt_pin_write(PIN_SPEAKER_EN, PIN_HIGH);
68-
69-
/* LCD power */
70-
rt_pin_mode(PIN_LCD_BL, PIN_MODE_OUTPUT);
71-
rt_pin_mode(PIN_LCD_PWR, PIN_MODE_OUTPUT);
72-
rt_pin_mode(PIN_LCD_PWM, PIN_MODE_OUTPUT);
73-
74-
return 0;
75-
}
76-
INIT_BOARD_EXPORT(board_power_init);
77-
7835
/*****************************************************************************
7936
* Main Entry
8037
*****************************************************************************/

projects/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi/iot/screen.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
extern "C"
1414
{
1515
#include "../ui/xiaozhi_ui.h"
16+
extern void set_brightness(rt_uint8_t percent);
17+
extern rt_uint8_t get_brightness(void);
1618
}
1719

1820
#define TAG "Screen"
@@ -21,7 +23,7 @@ namespace iot
2123
{
2224

2325
// 屏幕状态
24-
static int screen_brightness = 100;
26+
static int screen_brightness = 80;
2527
static std::string current_emoji = "neutral";
2628

2729
class Screen : public Thing
@@ -31,7 +33,7 @@ namespace iot
3133
{
3234
// 属性:亮度
3335
properties_.AddNumberProperty("brightness", "亮度", [this]() -> int
34-
{ return screen_brightness; });
36+
{ return get_brightness(); });
3537

3638
// 方法:设置表情
3739
methods_.AddMethod("SetEmoji", "设置表情", ParameterList({Parameter("emoji", "表情名称", kValueTypeString, true)}), [this](const ParameterList &parameters)
@@ -46,7 +48,7 @@ namespace iot
4648
int brightness = parameters["brightness"].number();
4749
if (brightness < 0) brightness = 0;
4850
if (brightness > 100) brightness = 100;
49-
screen_brightness = brightness;
51+
set_brightness(brightness);
5052
rt_kprintf("[%s] SetBrightness: %d\n", TAG, screen_brightness); });
5153
}
5254
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from building import *
3+
4+
# Add source code
5+
src = Glob('*.c')
6+
group = DefineGroup('Applications', src, depend = [''])
7+
8+
Return('group')
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <rtthread.h>
2+
#include <rtdevice.h>
3+
4+
#define PWM_DEV_NAME "pwm18"
5+
#define PWM_DEV_CHANNEL 0
6+
#define PWM_PERIOD_NS 200000
7+
8+
static struct rt_device_pwm *pwm_dev = RT_NULL;
9+
10+
static rt_uint8_t current_brightness = 0;
11+
12+
void set_brightness(rt_uint8_t percent)
13+
{
14+
if (percent > 100)
15+
percent = 100;
16+
17+
current_brightness = percent;
18+
19+
rt_uint32_t pulse = (PWM_PERIOD_NS * percent) / 100;
20+
21+
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, PWM_PERIOD_NS, pulse);
22+
}
23+
24+
rt_uint8_t get_brightness(void)
25+
{
26+
return current_brightness;
27+
}
28+
29+
static int pwm_bl_init(void)
30+
{
31+
if (pwm_dev == RT_NULL)
32+
{
33+
pwm_dev = (struct rt_device_pwm *)rt_device_find(PWM_DEV_NAME);
34+
if (pwm_dev == RT_NULL)
35+
{
36+
rt_kprintf("Cannot find %s device!\n", PWM_DEV_NAME);
37+
return -1;
38+
}
39+
40+
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, PWM_PERIOD_NS, 0);
41+
rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL);
42+
}
43+
44+
set_brightness(80);
45+
46+
return 0;
47+
}
48+
INIT_DEVICE_EXPORT(pwm_bl_init);

projects/Edgi_Talk_M55_XiaoZhi/board/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ menu "On-chip Peripheral Drivers"
170170
select RT_USING_PWM
171171
default n
172172
if BSP_USING_PWM
173-
config BSP_USING_PWM0
174-
bool "Enable PWM0"
173+
config BSP_USING_PWM18
174+
bool "Enable PWM18"
175175
default y
176176
endif
177177

projects/Edgi_Talk_M55_XiaoZhi/board/board.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,35 @@ void poweroff(void)
6363
#ifdef RT_USING_MSH
6464
MSH_CMD_EXPORT(poweroff, The software enables the system to shut down. Simply press the button to restart it.);
6565
#endif
66+
67+
//Mos管控制
68+
#define ES8388_CTRL GET_PIN(16, 2) //ES8388 电源 Enable引脚
69+
#define SPEAKER_OE_CTRL GET_PIN(21, 6) //功放 Enable引脚
70+
#define WIFI_OE_CTRL GET_PIN(16, 3) //WIFI Enable引脚
71+
#define WIFI_WL_REG_OE_CTRL GET_PIN(11, 6) //WiFi寄存器开关
72+
#define CTRL GET_PIN(7, 2) //底板 3V3 DCDC电源控制
73+
#define LCD_BL_GPIO_NUM GET_PIN(15, 7) //LCD 背光电源开关
74+
#define LCD_DISP_GPIO_NUM GET_PIN(15, 6) //LCD IC电源开关
75+
int en_gpio(void)
76+
{
77+
rt_pin_mode(WIFI_OE_CTRL, PIN_MODE_OUTPUT);
78+
rt_pin_write(WIFI_OE_CTRL, PIN_HIGH);
79+
80+
rt_pin_mode(WIFI_WL_REG_OE_CTRL, PIN_MODE_OUTPUT);
81+
rt_pin_write(WIFI_WL_REG_OE_CTRL, PIN_HIGH);
82+
83+
rt_pin_mode(ES8388_CTRL, PIN_MODE_OUTPUT);
84+
rt_pin_write(ES8388_CTRL, PIN_HIGH);
85+
86+
rt_pin_mode(SPEAKER_OE_CTRL, PIN_MODE_OUTPUT);
87+
rt_pin_write(SPEAKER_OE_CTRL, PIN_HIGH);
88+
89+
rt_pin_mode(LCD_BL_GPIO_NUM, PIN_MODE_OUTPUT);
90+
rt_pin_mode(LCD_DISP_GPIO_NUM, PIN_MODE_OUTPUT);
91+
92+
rt_pin_write(LCD_DISP_GPIO_NUM, PIN_HIGH);
93+
rt_pin_write(LCD_BL_GPIO_NUM, PIN_HIGH);
94+
95+
return 0;
96+
}
97+
INIT_BOARD_EXPORT(en_gpio);

projects/Edgi_Talk_M55_XiaoZhi/rtconfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@
565565
#define BSP_USING_SDCARD
566566
#define BSP_USING_FS
567567
#define BSP_USING_PWM
568-
#define BSP_USING_PWM0
568+
#define BSP_USING_PWM18
569569
#define BSP_USING_LCD
570570
#define COMPONENT_MTB_DISPLAY_tl043wvv02
571571
#define USING_LVGL

0 commit comments

Comments
 (0)