Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix i2c for empty data and external memory. #2694

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/resources/i2c_esp32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,10 @@ static Object* write_i2c(Process* process, I2cResourceGroup* i2c, int i2c_addres

const uint8* data = buffer.address();
word length = buffer.length();
if (!esp_ptr_internal(data)) {
// Copy buffer to malloc heap, if the buffer is not in memory.
uint8* copy = unvoid_cast<uint8*>(malloc(length));
if (length > 0 && !esp_ptr_internal(data)) {
// Copy buffer to internal malloc heap, if the buffer is not in memory.
const int caps_flags = MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT;
uint8* copy = unvoid_cast<uint8*>(heap_caps_malloc(length, caps_flags));
if (copy == null) FAIL(MALLOC_FAILED);
memcpy(copy, data, length);
data = copy;
Expand Down
4 changes: 2 additions & 2 deletions src/resources/uart_esp32.cc
Original file line number Diff line number Diff line change
Expand Up @@ -822,12 +822,12 @@ PRIMITIVE(create) {
}

const int caps_flags = MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT;
init.rx_buffer = static_cast<uint8*>(heap_caps_malloc(rx_buffer_size, caps_flags));
init.rx_buffer = unvoid_cast<uint8*>(heap_caps_malloc(rx_buffer_size, caps_flags));
if (!init.rx_buffer) {
FAIL(MALLOC_FAILED);
}

init.tx_buffer = static_cast<uint8*>(heap_caps_malloc(tx_buffer_size, caps_flags));
init.tx_buffer = unvoid_cast<uint8*>(heap_caps_malloc(tx_buffer_size, caps_flags));
if (!init.tx_buffer) {
FAIL(MALLOC_FAILED);
}
Expand Down
Loading