Skip to content

Commit 120ce0f

Browse files
esp32: Fix.
1 parent 970e75c commit 120ce0f

11 files changed

Lines changed: 56 additions & 144 deletions

File tree

ports/esp32/boards/ESP32_GENERIC_P4/mpconfigboard.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ set(IDF_TARGET esp32p4)
22

33
set(SDKCONFIG_DEFAULTS
44
boards/sdkconfig.base
5+
boards/sdkconfig.p4
56
boards/ESP32_GENERIC_P4/sdkconfig.board
67
)

ports/esp32/boards/ESP32_GENERIC_P4/sdkconfig.board

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
2-
# Flash
3-
CONFIG_FLASHMODE_QIO=y
4-
#CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
5-
CONFIG_ESPTOOLPY_FLASHMODE="dio"
6-
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
7-
CONFIG_ESPTOOLPY_AFTER_NORESET=y
8-
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
9-
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=
10-
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
11-
12-
# Memory
13-
CONFIG_SPIRAM=y
14-
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
15-
CONFIG_SPIRAM_MODE_HEX=y
16-
CONFIG_SPIRAM_SPEED_200M=y
17-
CONFIG_SPIRAM_MEMTEST=
18-
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
19-
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
20-
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=50768
21-
22-
23-
# ULP : not fixed
24-
CONFIG_SOC_ULP_SUPPORTED=n
25-
CONFIG_ULP_COPROC_ENABLED=n
26-
CONFIG_ULP_COPROC_TYPE_FSM=n
27-
28-
291
# Wifi
302
#CONFIG_ESP_HOSTED_ENABLED=n
313
CONFIG_ESP_HOST_WIFI_ENABLED=y

ports/esp32/boards/ESP32_GENERIC_P4_WIFI/mpconfigboard.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ set(IDF_TARGET esp32p4)
22

33
set(SDKCONFIG_DEFAULTS
44
boards/sdkconfig.base
5+
boards/sdkconfig.p4
56
boards/ESP32_GENERIC_P4/sdkconfig.board
67
)

ports/esp32/boards/ESP32_GENERIC_P4_WIFI/mpconfigboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// specified.
33

44
#ifndef MICROPY_HW_BOARD_NAME
5-
#define MICROPY_HW_BOARD_NAME "Generic ESP32P4 module"
5+
#define MICROPY_HW_BOARD_NAME "Generic ESP32P4 module (wifi) "
66
#endif
77

88
#ifndef MICROPY_HW_MCU_NAME

ports/esp32/boards/ESP32_GENERIC_P4_WIFI/sdkconfig.board

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,3 @@
1-
2-
# Flash
3-
CONFIG_FLASHMODE_QIO=y
4-
#CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
5-
CONFIG_ESPTOOLPY_FLASHMODE="dio"
6-
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
7-
CONFIG_ESPTOOLPY_AFTER_NORESET=y
8-
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=
9-
CONFIG_ESPTOOLPY_FLASHSIZE_8MB=
10-
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
11-
12-
# Memory
13-
CONFIG_SPIRAM=y
14-
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
15-
CONFIG_SPIRAM_MODE_HEX=y
16-
CONFIG_SPIRAM_SPEED_200M=y
17-
CONFIG_SPIRAM_MEMTEST=
18-
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
19-
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
20-
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=50768
21-
22-
23-
# ULP : not fixed
24-
CONFIG_SOC_ULP_SUPPORTED=n
25-
CONFIG_ULP_COPROC_ENABLED=n
26-
CONFIG_ULP_COPROC_TYPE_FSM=n
27-
28-
29-
301
# Wifi
312
CONFIG_ESP_HOSTED_ENABLED=y
323
#CONFIG_ESP_HOST_WIFI_ENABLED=y

ports/esp32/boards/sdkconfig.p4

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Flash
2+
CONFIG_FLASHMODE_QIO=y
3+
#CONFIG_ESPTOOLPY_FLASHMODE_QIO=y
4+
CONFIG_ESPTOOLPY_FLASHMODE="dio"
5+
CONFIG_ESPTOOLPY_FLASHFREQ_80M=y
6+
CONFIG_ESPTOOLPY_AFTER_NORESET=y
7+
CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y
8+
9+
# Memory
10+
CONFIG_SPIRAM=y
11+
CONFIG_IDF_EXPERIMENTAL_FEATURES=y
12+
CONFIG_SPIRAM_MODE_HEX=y
13+
CONFIG_SPIRAM_SPEED_200M=y
14+
CONFIG_SPIRAM_MEMTEST=
15+
CONFIG_SPIRAM_IGNORE_NOTFOUND=y
16+
CONFIG_MBEDTLS_DEFAULT_MEM_ALLOC=y
17+
CONFIG_SPIRAM_MALLOC_RESERVE_INTERNAL=50768
18+
19+
20+
# ULP : not fixed
21+
CONFIG_SOC_ULP_SUPPORTED=n
22+
CONFIG_ULP_COPROC_ENABLED=n
23+
CONFIG_ULP_COPROC_TYPE_FSM=n

ports/esp32/boards/sdkconfig.p4usb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
CONFIG_USB_OTG_SUPPORTED=y
22
CONFIG_TINYUSB_CDC_ENABLED=y
3-
CONFIG_TINYUSB_HID_COUNT=1

ports/esp32/boards/sdkconfig.usb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
CONFIG_USB_OTG_SUPPORTED=y
22
CONFIG_TINYUSB_CDC_ENABLED=y
3-
CONFIG_TINYUSB_HID_COUNT=1
43
CONFIG_TINYUSB_CDC_RX_BUFSIZE=256
54
CONFIG_TINYUSB_CDC_TX_BUFSIZE=256

ports/esp32/machine_i2c.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* This file is part of the MicroPython project, http://micropython.org/
2+
* This file is part of the MicroPython project, http://micropython.org/
33
*
44
* The MIT License (MIT)
55
*
@@ -68,7 +68,7 @@
6868

6969
#define I2C_DEFAULT_TIMEOUT_US (50000) // 50ms
7070

71-
// ---------------- 内部数据结构 ----------------
71+
// ---------------- Internal Data Structures ----------------
7272
typedef struct _machine_hw_i2c_obj_t {
7373
mp_obj_base_t base;
7474
i2c_master_bus_handle_t bus_handle;
@@ -80,21 +80,21 @@ typedef struct _machine_hw_i2c_obj_t {
8080

8181
static machine_hw_i2c_obj_t machine_hw_i2c_obj[I2C_NUM_MAX];
8282

83-
// ---------------- 初始化 ----------------
83+
// ---------------- Initialization ----------------
8484
static void machine_hw_i2c_init(machine_hw_i2c_obj_t *self,
8585
uint32_t freq,
8686
uint32_t timeout_us,
8787
bool first_init) {
8888

89-
// 1. 若已初始化,先卸载旧驱动
89+
// 1. If already initialized, first remove the old driver
9090
if (!first_init && self->bus_handle) {
9191
i2c_master_bus_rm_device(self->dev_handle);
9292
i2c_del_master_bus(self->bus_handle);
9393
self->bus_handle = NULL;
9494
self->dev_handle = NULL;
9595
}
9696

97-
// 2. 配置总线
97+
// 2. Configure the bus
9898
i2c_master_bus_config_t bus_cfg = {
9999
.i2c_port = self->port,
100100
.scl_io_num = self->scl,
@@ -105,10 +105,10 @@ static void machine_hw_i2c_init(machine_hw_i2c_obj_t *self,
105105
};
106106
ESP_ERROR_CHECK(i2c_new_master_bus(&bus_cfg, &self->bus_handle));
107107

108-
// 3. 添加设备(占位地址,后面真正传输时再动态改)
108+
// 3. Add device (placeholder address, dynamically changed later during actual transmission)
109109
i2c_device_config_t dev_cfg = {
110110
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
111-
.device_address = 0x00, // 占位
111+
.device_address = 0x00, // Placeholder
112112
.scl_speed_hz = freq,
113113
};
114114
ESP_ERROR_CHECK(i2c_master_bus_add_device(self->bus_handle, &dev_cfg, &self->dev_handle));
@@ -122,16 +122,16 @@ int machine_hw_i2c_transfer(mp_obj_base_t *self_in,
122122
{
123123
machine_hw_i2c_obj_t *self = MP_OBJ_TO_PTR(self_in);
124124

125-
/* 0. 先探测地址是否有设备回应 */
125+
/* 0. First, probe the address to see if a device responds */
126126
esp_err_t err = i2c_master_probe(self->bus_handle, addr, 1000);
127127
if (err != ESP_OK) {
128-
return -MP_ENODEV; /* 地址无设备,直接返回 */
128+
return -MP_ENODEV; /* No device at address, return directly */
129129
}
130-
/* 1. 为本次事务创建临时 device 句柄 */
130+
/* 1. Create a temporary device handle for this transaction */
131131
i2c_device_config_t dev_cfg = {
132132
.dev_addr_length = I2C_ADDR_BIT_LEN_7,
133133
.device_address = addr,
134-
.scl_speed_hz = 100000, /* 沿用总线频率即可 */
134+
.scl_speed_hz = 100000, /* Use the bus frequency */
135135
};
136136
i2c_master_dev_handle_t dev_handle;
137137
err = i2c_master_bus_add_device(self->bus_handle, &dev_cfg, &dev_handle);
@@ -141,21 +141,21 @@ int machine_hw_i2c_transfer(mp_obj_base_t *self_in,
141141

142142
int data_len = 0;
143143

144-
/* 2. 若有 WRITE1 段,先写一段 */
144+
/* 2. If there is a WRITE1 segment, write it first */
145145
if (flags & MP_MACHINE_I2C_FLAG_WRITE1) {
146146
if (bufs->len) {
147147
err = i2c_master_transmit(dev_handle,
148148
bufs->buf,
149149
bufs->len,
150-
1000); /* 阻塞超时 1 s */
150+
1000); /* Blocking timeout 1 s */
151151
if (err != ESP_OK) goto cleanup;
152152
}
153153
data_len += bufs->len;
154154
--n;
155155
++bufs;
156156
}
157157
if (flags & MP_MACHINE_I2C_FLAG_READ) {
158-
/* 3. 主循环:剩余段 */
158+
/* 3. Main loop: remaining segments */
159159
for (; n--; ++bufs) {
160160
if (bufs->len == 0) continue;
161161
err = i2c_master_receive(dev_handle,
@@ -168,52 +168,52 @@ int machine_hw_i2c_transfer(mp_obj_base_t *self_in,
168168
data_len += bufs->len;
169169
}
170170
} else {
171-
// 写操作逻辑
171+
// Write operation logic
172172
size_t total_len = 0;
173-
mp_machine_i2c_buf_t *original_bufs = bufs; // 保存原始指针
174-
size_t yuann=n;
173+
mp_machine_i2c_buf_t *original_bufs = bufs; // Save the original pointer
174+
size_t old_n=n;
175175

176-
// 计算总长度
176+
// Calculate total length
177177
for (; n--; ++bufs) {
178178
total_len += bufs->len;
179179
}
180180

181-
// 重置指针
181+
// Reset pointer
182182
bufs = original_bufs;
183-
// 重置n
184-
n = yuann;
185-
// 动态分配 write_buf
183+
// Reset n
184+
n = old_n;
185+
// Dynamically allocate write_buf
186186
uint8_t *write_buf = (uint8_t *)malloc(total_len);
187187
if (write_buf == NULL) return -MP_ENOMEM;
188188

189-
// 复制数据到 write_buf
189+
// Copy data to write_buf
190190
size_t index = 0;
191191
for (; n--; ++bufs) {
192192
memcpy(write_buf + index, bufs->buf, bufs->len);
193193
index += bufs->len;
194194
}
195195

196-
// 发送数据
196+
// Send data
197197
err = i2c_master_transmit(dev_handle, write_buf, total_len, 1000);
198198
if (err != ESP_OK) goto cleanup;
199199

200-
// 释放动态分配的内存
200+
// Free dynamically allocated memory
201201
free(write_buf);
202202
}
203203

204204
cleanup:
205-
/* 4. 立即销毁临时句柄 */
205+
/* 4. Immediately destroy the temporary handle */
206206
i2c_master_bus_rm_device(dev_handle);
207207

208-
/* 5. 出错映射 */
208+
/* 5. Error mapping */
209209
if (err == ESP_FAIL) return -MP_ENODEV;
210210
if (err == ESP_ERR_TIMEOUT) return -MP_ETIMEDOUT;
211211
if (err != ESP_OK) return -abs(err);
212212

213213
return data_len;
214214
}
215215

216-
// ---------------- 打印 ----------------
216+
// ---------------- Printing ----------------
217217
static void machine_hw_i2c_print(const mp_print_t *print,
218218
mp_obj_t self_in,
219219
mp_print_kind_t kind) {
@@ -222,7 +222,7 @@ static void machine_hw_i2c_print(const mp_print_t *print,
222222
self->port, self->scl, self->sda);
223223
}
224224

225-
// ---------------- 构造函数 ----------------
225+
// ---------------- Constructor ----------------
226226
mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type,
227227
size_t n_args, size_t n_kw,
228228
const mp_obj_t *all_args) {
@@ -272,7 +272,7 @@ mp_obj_t machine_hw_i2c_make_new(const mp_obj_type_t *type,
272272
return MP_OBJ_FROM_PTR(self);
273273
}
274274

275-
// ---------------- 协议表 ----------------
275+
// ---------------- Protocol Table ----------------
276276
static const mp_machine_i2c_p_t machine_hw_i2c_p = {
277277
.transfer_supports_write1 = true,
278278
.transfer = machine_hw_i2c_transfer,

shared/tinyusb/mp_usbd.c

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -63,52 +63,4 @@ void mp_usbd_hex_str(char *out_str, const uint8_t *bytes, size_t bytes_len) {
6363
}
6464
out_str[hex_len] = 0;
6565
}
66-
#if CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32P4
67-
const uint8_t hid_report_descriptor[] = {
68-
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(HID_ITF_PROTOCOL_KEYBOARD)),
69-
TUD_HID_REPORT_DESC_MOUSE(HID_REPORT_ID(HID_ITF_PROTOCOL_MOUSE))
70-
};
71-
72-
/**
73-
* @brief String descriptor
74-
*/
75-
const char* hid_string_descriptor[5] = {
76-
// array of pointer to string descriptors
77-
(char[]){0x09, 0x04}, // 0: is supported language is English (0x0409)
78-
"TinyUSB", // 1: Manufacturer
79-
"TinyUSB Device", // 2: Product
80-
"123456", // 3: Serials, should use chip ID
81-
"Example HID interface", // 4: HID
82-
};
83-
84-
/********* TinyUSB HID callbacks ***************/
85-
86-
// Invoked when received GET HID REPORT DESCRIPTOR request
87-
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
88-
uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance)
89-
{
90-
// We use only one interface and one HID report descriptor, so we can ignore parameter 'instance'
91-
return hid_report_descriptor;
92-
}
93-
94-
// Invoked when received GET_REPORT control request
95-
// Application must fill buffer report's content and return its length.
96-
// Return zero will cause the stack to STALL request
97-
uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
98-
{
99-
(void) instance;
100-
(void) report_id;
101-
(void) report_type;
102-
(void) buffer;
103-
(void) reqlen;
104-
105-
return 0;
106-
}
107-
108-
// Invoked when received SET_REPORT control request or
109-
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
110-
void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
111-
{
112-
}
113-
#endif
11466
#endif // MICROPY_HW_ENABLE_USBDEV

0 commit comments

Comments
 (0)