Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2ca96fb

Browse files
Merge pull request #11804 from lucasssvaz/feat/p4_ble
feat(ble): Enable BLE for ESP32-P4 through esp-hosted
2 parents 07c08e3 + 99c7ceb commit 2ca96fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+520
-300
lines changed

‎CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ set(CORE_SRCS
3232
cores/esp32/esp32-hal-cpu.c
3333
cores/esp32/esp32-hal-dac.c
3434
cores/esp32/esp32-hal-gpio.c
35+
cores/esp32/esp32-hal-hosted.c
3536
cores/esp32/esp32-hal-i2c.c
3637
cores/esp32/esp32-hal-i2c-ng.c
3738
cores/esp32/esp32-hal-i2c-slave.c

‎cores/esp32/esp32-hal-hosted.c‎

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// Copyright 2015-2025 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "sdkconfig.h"
16+
#if defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE) || defined(CONFIG_ESP_WIFI_REMOTE_ENABLED)
17+
18+
#include "esp32-hal-hosted.h"
19+
#include "esp32-hal-log.h"
20+
21+
#include "esp_hosted_transport_config.h"
22+
extern esp_err_t esp_hosted_init();
23+
extern esp_err_t esp_hosted_deinit();
24+
25+
static bool hosted_initialized = false;
26+
static bool hosted_ble_active = false;
27+
static bool hosted_wifi_active = false;
28+
29+
static sdio_pin_config_t sdio_pin_config = {
30+
#ifdef BOARD_HAS_SDIO_ESP_HOSTED
31+
.pin_clk = BOARD_SDIO_ESP_HOSTED_CLK,
32+
.pin_cmd = BOARD_SDIO_ESP_HOSTED_CMD,
33+
.pin_d0 = BOARD_SDIO_ESP_HOSTED_D0,
34+
.pin_d1 = BOARD_SDIO_ESP_HOSTED_D1,
35+
.pin_d2 = BOARD_SDIO_ESP_HOSTED_D2,
36+
.pin_d3 = BOARD_SDIO_ESP_HOSTED_D3,
37+
.pin_reset = BOARD_SDIO_ESP_HOSTED_RESET
38+
#else
39+
.pin_clk = CONFIG_ESP_SDIO_PIN_CLK,
40+
.pin_cmd = CONFIG_ESP_SDIO_PIN_CMD,
41+
.pin_d0 = CONFIG_ESP_SDIO_PIN_D0,
42+
.pin_d1 = CONFIG_ESP_SDIO_PIN_D1,
43+
.pin_d2 = CONFIG_ESP_SDIO_PIN_D2,
44+
.pin_d3 = CONFIG_ESP_SDIO_PIN_D3,
45+
.pin_reset = CONFIG_ESP_SDIO_GPIO_RESET_SLAVE
46+
#endif
47+
};
48+
49+
static bool hostedInit() {
50+
if (!hosted_initialized) {
51+
log_i("Initializing ESP-Hosted");
52+
log_d(
53+
"SDIO pins: clk=%d, cmd=%d, d0=%d, d1=%d, d2=%d, d3=%d, rst=%d", sdio_pin_config.pin_clk, sdio_pin_config.pin_cmd, sdio_pin_config.pin_d0,
54+
sdio_pin_config.pin_d1, sdio_pin_config.pin_d2, sdio_pin_config.pin_d3, sdio_pin_config.pin_reset
55+
);
56+
hosted_initialized = true;
57+
struct esp_hosted_sdio_config conf = INIT_DEFAULT_HOST_SDIO_CONFIG();
58+
conf.pin_clk.pin = sdio_pin_config.pin_clk;
59+
conf.pin_cmd.pin = sdio_pin_config.pin_cmd;
60+
conf.pin_d0.pin = sdio_pin_config.pin_d0;
61+
conf.pin_d1.pin = sdio_pin_config.pin_d1;
62+
conf.pin_d2.pin = sdio_pin_config.pin_d2;
63+
conf.pin_d3.pin = sdio_pin_config.pin_d3;
64+
conf.pin_reset.pin = sdio_pin_config.pin_reset;
65+
// esp_hosted_sdio_set_config() will fail on second attempt but here temporarily to not cause exception on reinit
66+
if (esp_hosted_sdio_set_config(&conf) != ESP_OK || esp_hosted_init() != ESP_OK) {
67+
log_e("esp_hosted_init failed!");
68+
hosted_initialized = false;
69+
return false;
70+
}
71+
log_i("ESP-Hosted initialized!");
72+
}
73+
74+
// Attach pins to PeriMan here
75+
// Slave chip model is CONFIG_IDF_SLAVE_TARGET
76+
// sdio_pin_config.pin_clk
77+
// sdio_pin_config.pin_cmd
78+
// sdio_pin_config.pin_d0
79+
// sdio_pin_config.pin_d1
80+
// sdio_pin_config.pin_d2
81+
// sdio_pin_config.pin_d3
82+
// sdio_pin_config.pin_reset
83+
84+
return true;
85+
}
86+
87+
static bool hostedDeinit() {
88+
if (!hosted_initialized) {
89+
log_e("ESP-Hosted is not initialized");
90+
return false;
91+
}
92+
93+
if (esp_hosted_deinit() != ESP_OK) {
94+
log_e("esp_hosted_deinit failed!");
95+
return false;
96+
}
97+
98+
hosted_initialized = false;
99+
return true;
100+
}
101+
102+
bool hostedInitBLE() {
103+
log_i("Initializing ESP-Hosted for BLE");
104+
hosted_ble_active = true;
105+
return hostedInit();
106+
}
107+
108+
bool hostedInitWiFi() {
109+
log_i("Initializing ESP-Hosted for WiFi");
110+
hosted_wifi_active = true;
111+
return hostedInit();
112+
}
113+
114+
bool hostedDeinitBLE() {
115+
log_i("Deinitializing ESP-Hosted for BLE");
116+
hosted_ble_active = false;
117+
if (!hosted_wifi_active) {
118+
return hostedDeinit();
119+
} else {
120+
log_i("ESP-Hosted is still being used by Wi-Fi. Skipping deinit.");
121+
return true;
122+
}
123+
}
124+
125+
bool hostedDeinitWiFi() {
126+
log_i("Deinitializing ESP-Hosted for WiFi");
127+
hosted_wifi_active = false;
128+
if (!hosted_ble_active) {
129+
return hostedDeinit();
130+
} else {
131+
log_i("ESP-Hosted is still being used by BLE. Skipping deinit.");
132+
return true;
133+
}
134+
}
135+
136+
bool hostedSetPins(int8_t clk, int8_t cmd, int8_t d0, int8_t d1, int8_t d2, int8_t d3, int8_t rst) {
137+
if (clk < 0 || cmd < 0 || d0 < 0 || d1 < 0 || d2 < 0 || d3 < 0 || rst < 0) {
138+
log_e("All SDIO pins must be defined");
139+
return false;
140+
}
141+
142+
if (hosted_initialized) {
143+
int8_t current_clk, current_cmd, current_d0, current_d1, current_d2, current_d3, current_rst;
144+
hostedGetPins(&current_clk, &current_cmd, &current_d0, &current_d1, &current_d2, &current_d3, &current_rst);
145+
log_e("SDIO pins must be set before ESP-Hosted is initialized");
146+
log_e(
147+
"Current pins used: clk=%d, cmd=%d, d0=%d, d1=%d, d2=%d, d3=%d, rst=%d", current_clk, current_cmd, current_d0, current_d1, current_d2, current_d3,
148+
current_rst
149+
);
150+
return false;
151+
}
152+
153+
sdio_pin_config.pin_clk = clk;
154+
sdio_pin_config.pin_cmd = cmd;
155+
sdio_pin_config.pin_d0 = d0;
156+
sdio_pin_config.pin_d1 = d1;
157+
sdio_pin_config.pin_d2 = d2;
158+
sdio_pin_config.pin_d3 = d3;
159+
sdio_pin_config.pin_reset = rst;
160+
return true;
161+
}
162+
163+
void hostedGetPins(int8_t *clk, int8_t *cmd, int8_t *d0, int8_t *d1, int8_t *d2, int8_t *d3, int8_t *rst) {
164+
*clk = sdio_pin_config.pin_clk;
165+
*cmd = sdio_pin_config.pin_cmd;
166+
*d0 = sdio_pin_config.pin_d0;
167+
*d1 = sdio_pin_config.pin_d1;
168+
*d2 = sdio_pin_config.pin_d2;
169+
*d3 = sdio_pin_config.pin_d3;
170+
*rst = sdio_pin_config.pin_reset;
171+
}
172+
173+
bool hostedIsBLEActive() {
174+
return hosted_ble_active;
175+
}
176+
177+
bool hostedIsWiFiActive() {
178+
return hosted_wifi_active;
179+
}
180+
181+
bool hostedIsInitialized() {
182+
return hosted_initialized;
183+
}
184+
185+
#endif /* defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE) || defined(CONFIG_ESP_WIFI_REMOTE_ENABLED) */

‎cores/esp32/esp32-hal-hosted.h‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2015-2025 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef MAIN_ESP32_HAL_HOSTED_H_
16+
#define MAIN_ESP32_HAL_HOSTED_H_
17+
18+
#include "sdkconfig.h"
19+
#if defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE) || defined(CONFIG_ESP_WIFI_REMOTE_ENABLED)
20+
21+
#include "stdint.h"
22+
#include "stdbool.h"
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
typedef struct {
29+
uint8_t pin_clk;
30+
uint8_t pin_cmd;
31+
uint8_t pin_d0;
32+
uint8_t pin_d1;
33+
uint8_t pin_d2;
34+
uint8_t pin_d3;
35+
uint8_t pin_reset;
36+
} sdio_pin_config_t;
37+
38+
bool hostedInitBLE();
39+
bool hostedInitWiFi();
40+
bool hostedDeinitBLE();
41+
bool hostedDeinitWiFi();
42+
bool hostedIsInitialized();
43+
bool hostedIsBLEActive();
44+
bool hostedIsWiFiActive();
45+
bool hostedSetPins(int8_t clk, int8_t cmd, int8_t d0, int8_t d1, int8_t d2, int8_t d3, int8_t rst);
46+
void hostedGetPins(int8_t *clk, int8_t *cmd, int8_t *d0, int8_t *d1, int8_t *d2, int8_t *d3, int8_t *rst);
47+
48+
#ifdef __cplusplus
49+
}
50+
#endif
51+
52+
#endif /* defined(CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE) || defined(CONFIG_ESP_WIFI_REMOTE_ENABLED) */
53+
#endif /* MAIN_ESP32_HAL_HOSTED_H_ */

‎cores/esp32/esp32-hal.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ void yield(void);
100100
#include "esp32-hal-psram.h"
101101
#include "esp32-hal-rgb-led.h"
102102
#include "esp32-hal-cpu.h"
103+
#include "esp32-hal-hosted.h"
103104

104105
void analogWrite(uint8_t pin, int value);
105106
void analogWriteFrequency(uint8_t pin, uint32_t freq);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
3-
"requires": [
4-
"CONFIG_SOC_BLE_SUPPORTED=y"
3+
"requires_any": [
4+
"CONFIG_SOC_BLE_SUPPORTED=y",
5+
"CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y"
56
]
67
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
3-
"requires": [
4-
"CONFIG_SOC_BLE_SUPPORTED=y"
3+
"requires_any": [
4+
"CONFIG_SOC_BLE_SUPPORTED=y",
5+
"CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y"
56
]
67
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
3-
"requires": [
4-
"CONFIG_SOC_BLE_SUPPORTED=y"
3+
"requires_any": [
4+
"CONFIG_SOC_BLE_SUPPORTED=y",
5+
"CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y"
56
]
67
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
3-
"requires": [
4-
"CONFIG_SOC_BLE_SUPPORTED=y"
3+
"requires_any": [
4+
"CONFIG_SOC_BLE_SUPPORTED=y",
5+
"CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y"
56
]
67
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
3-
"requires": [
4-
"CONFIG_SOC_BLE_SUPPORTED=y"
3+
"requires_any": [
4+
"CONFIG_SOC_BLE_SUPPORTED=y",
5+
"CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y"
56
]
67
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"fqbn_append": "PartitionScheme=huge_app",
3-
"requires": [
4-
"CONFIG_SOC_BLE_SUPPORTED=y"
3+
"requires_any": [
4+
"CONFIG_SOC_BLE_SUPPORTED=y",
5+
"CONFIG_ESP_HOSTED_ENABLE_BT_NIMBLE=y"
56
]
67
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /