1+ #include " board_hardware.h"
2+ #include " ../mcp/rgbled_mcp.h"
3+ #include " rtthread.h"
4+ #include " drv_io.h"
5+ #include " stdio.h"
6+ #include " string.h"
7+ #include " drivers/rt_drv_pwm.h"
8+ #include " bf0_hal.h"
9+ #include " bf0_pm.h"
10+ #include " xiaozhi_client_public.h"
11+ #include " bts2_global.h"
12+ #include " bts2_app_pan.h"
13+ #include " bt_connection_manager.h"
14+ #include " bt_env.h"
15+ #include < webclient.h>
16+ #include < cJSON.h>
17+ #include < lwip/dns.h>
18+ #include < lwip/sys.h>
19+ #include " lwip/api.h"
20+ #include " lwip/dns.h"
21+ #include " lwip/apps/websocket_client.h"
22+ #include " lwip/apps/mqtt_priv.h"
23+ #include " lwip/apps/mqtt.h"
24+ #include " lwip/tcpip.h"
25+ #include " lv_timer.h"
26+ #include " lv_display.h"
27+ #include " lv_obj_pos.h"
28+ #include " lv_tiny_ttf.h"
29+ #include " lv_obj.h"
30+ #include " lv_label.h"
31+ #include " bf0_sys_cfg.h"
32+ #include " drv_flash.h"
33+ #include " gui_app_pm.h"
34+ extern " C"
35+ {
36+ void open_led ()
37+ {
38+ int index = 0 ;
39+ while (RGBLEDTool::is_color_cycling_)
40+ {
41+ uint32_t color = rgb_color_arry[index].color ;
42+ GetRGBLEDController ().SetColor (color);
43+ index = (index + 1 ) % (sizeof (rgb_color_arry)/sizeof (rgb_color_arry[0 ]));
44+ rt_thread_mdelay (500 );
45+
46+ }
47+ }
48+ void close_led ()
49+ {
50+ if (RGBLEDTool::is_color_cycling_)
51+ {
52+ RGBLEDTool::is_color_cycling_ = false ;
53+ rt_thread_mdelay (100 );
54+ GetRGBLEDController ().SetColor (0x000000 ); // 关灯
55+ }
56+ }
57+ void set_mode_led ()
58+ {
59+
60+ }
61+
62+ void set_pinmux ()
63+ {
64+ unsigned int *addr2 = (unsigned int *)0x50003088 ; // 21
65+ *addr2 = 0x00000200 ;
66+ unsigned int *addr = (unsigned int *)0x500030B0 ; // 31
67+ *addr = 0x00000200 ;
68+
69+ // senser
70+ HAL_PIN_Set (PAD_PA30, GPIO_A30, PIN_PULLDOWN, 1 );
71+ BSP_GPIO_Set (30 , 0 , 1 );
72+ HAL_PIN_Set (PAD_PA39, GPIO_A39, PIN_PULLDOWN, 1 );
73+ HAL_PIN_Set (PAD_PA40, GPIO_A40, PIN_PULLDOWN, 1 );
74+ }
75+
76+ HAL_RAM_RET_CODE_SECT (PowerDownCustom, void PowerDownCustom (void ))
77+ {
78+ rt_kprintf (" PowerDownCustom\n " );
79+
80+ HAL_PMU_SelectWakeupPin (0 , 19 ); // PA43
81+ HAL_PMU_EnablePinWakeup (0 , 0 );
82+
83+ HAL_PIN_Set (PAD_PA24, GPIO_A24, PIN_PULLDOWN, 1 );
84+ for (uint32_t i = PAD_PA28; i <= PAD_PA44; i++)
85+ {
86+ HAL_PIN_Set (i, (pin_function)(i - PAD_PA28 + GPIO_A28), PIN_PULLDOWN, 1 );
87+ }
88+ hwp_pmuc->PERI_LDO &= ~(PMUC_PERI_LDO_EN_LDO18 | PMUC_PERI_LDO_EN_VDD33_LDO2 | PMUC_PERI_LDO_EN_VDD33_LDO3);
89+ hwp_pmuc->WKUP_CNT = 0x000F000F ;
90+
91+
92+
93+ rt_hw_interrupt_disable ();
94+ rt_kprintf (" PowerDownCustom2\n " );
95+ HAL_PMU_ConfigPeriLdo (PMU_PERI_LDO2_3V3, false , false );
96+ HAL_PMU_ConfigPeriLdo (PMU_PERI_LDO_1V8, false , false );
97+ HAL_PMU_EnterHibernate ();
98+ rt_kprintf (" PowerDownCustom3\n " );
99+ }
100+
101+ void check_poweron_reason (void )
102+ {
103+ switch (SystemPowerOnModeGet ())
104+ {
105+ case PM_REBOOT_BOOT:
106+ case PM_COLD_BOOT:
107+ {
108+ // power on as normal
109+ break ;
110+ }
111+ case PM_HIBERNATE_BOOT:
112+ case PM_SHUTDOWN_BOOT:
113+ {
114+ if (PMUC_WSR_RTC & pm_get_wakeup_src ())
115+ {
116+ // RTC唤醒
117+ NVIC_EnableIRQ (RTC_IRQn);
118+ // power on as normal
119+ }
120+ #ifdef BSP_USING_CHARGER
121+ else if ((PMUC_WSR_PIN0 << (pm_get_charger_pin_wakeup ())) & pm_get_wakeup_src ())
122+ {
123+ }
124+ #endif
125+ else if (PMUC_WSR_PIN_ALL & pm_get_wakeup_src ())
126+ {
127+ rt_thread_mdelay (1000 ); // 延时1秒
128+ int val = rt_pin_read (BSP_KEY2_PIN);
129+ rt_kprintf (" Power key level after 1s: %d\n " , val);
130+ if (val != KEY2_ACTIVE_LEVEL)
131+ {
132+ // 按键已松开,认为是误触发,直接关机
133+ rt_kprintf (" Not long press, shutdown now.\n " );
134+ PowerDownCustom ();
135+ while (1 ) {};
136+ }
137+ else
138+ {
139+ // 长按,正常开机
140+ rt_kprintf (" Long press detected, power on as normal.\n " );
141+ }
142+ }
143+ else if (0 == pm_get_wakeup_src ())
144+ {
145+ RT_ASSERT (0 );
146+ }
147+ break ;
148+ }
149+ default :
150+ {
151+ RT_ASSERT (0 );
152+ }
153+ }
154+ }
155+
156+ }
0 commit comments