Skip to content

Commit

Permalink
Fix i2c and spi esp32 drivers with ports
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Guyot <[email protected]>
  • Loading branch information
pguyot committed Jan 14, 2025
1 parent 44191fc commit c2e099d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/platforms/esp32/components/avm_builtins/gpio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,11 @@ static term gpiodriver_set_int(Context *ctx, int32_t target_pid, term cmd)
term trigger = term_get_tuple_element(cmd, 2);
if (term_get_tuple_arity(cmd) == 4) {
term pid = term_get_tuple_element(cmd, 3);
if (UNLIKELY(!term_is_pid(pid) && !term_is_atom(pid))) {
if (UNLIKELY(!term_is_local_pid(pid) && !term_is_atom(pid))) {
ESP_LOGE(TAG, "Invalid listener parameter, must be a pid() or registered process!");
return ERROR_ATOM;
}
if (term_is_pid(pid)) {
if (term_is_local_pid(pid)) {
target_local_pid = term_to_local_process_id(pid);
} else {
int pid_atom_index = term_to_atom_index(pid);
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/esp32/components/avm_builtins/i2c_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,8 @@ static NativeHandlerResult i2cdriver_consume_mailbox(Context *ctx)

I2CAcquireResult i2c_driver_acquire(term i2c_port, i2c_port_t *i2c_num, GlobalContext *global)
{
if (UNLIKELY(!term_is_pid(i2c_port))) {
ESP_LOGW(TAG, "acquire: given term is not a PID.");
if (UNLIKELY(!term_is_local_port(i2c_port))) {
ESP_LOGW(TAG, "acquire: given term is not a port.");
return I2CAcquireInvalidPeripheral;
}

Expand All @@ -660,7 +660,7 @@ I2CAcquireResult i2c_driver_acquire(term i2c_port, i2c_port_t *i2c_num, GlobalCo

void i2c_driver_release(term i2c_port, GlobalContext *global)
{
if (UNLIKELY(!term_is_pid(i2c_port))) {
if (UNLIKELY(!term_is_local_port(i2c_port))) {
ESP_LOGW(TAG, "release: given term is not a PID.");
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/platforms/esp32/components/avm_builtins/socket_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ static void do_connect(Context *ctx, const GenMessage *gen_message)
term active_term = interop_proplist_get_value_default(params, ACTIVE_ATOM, TRUE_ATOM);
term controlling_process_term = interop_proplist_get_value(params, CONTROLLING_PROCESS_ATOM);

bool ok = term_is_pid(controlling_process_term);
bool ok = term_is_local_pid(controlling_process_term);
if (UNLIKELY(!ok)) {
do_send_error_reply(ctx, ERR_ARG, ref_ticks, pid);
return;
Expand Down Expand Up @@ -1022,7 +1022,7 @@ void do_udp_open(Context *ctx, const GenMessage *gen_message)
term active_term = interop_proplist_get_value_default(params, ACTIVE_ATOM, TRUE_ATOM);
term controlling_process_term = interop_proplist_get_value(params, CONTROLLING_PROCESS_ATOM);

bool ok = term_is_pid(controlling_process_term);
bool ok = term_is_local_pid(controlling_process_term);
if (UNLIKELY(!ok)) {
do_send_error_reply(ctx, ERR_ARG, ref_ticks, pid);
return;
Expand Down Expand Up @@ -1369,7 +1369,7 @@ static void do_controlling_process(Context *ctx, const GenMessage *gen_message)
return;
}
term new_pid_term = term_get_tuple_element(gen_message->req, 1);
if (UNLIKELY(!term_is_pid(new_pid_term))) {
if (UNLIKELY(!term_is_local_pid(new_pid_term))) {
do_send_error_reply(ctx, ERR_ARG, ref_ticks, pid);
} else {
term return_msg;
Expand Down
2 changes: 1 addition & 1 deletion src/platforms/esp32/components/avm_builtins/spi_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ static NativeHandlerResult spidriver_consume_mailbox(Context *ctx)

bool spi_driver_get_peripheral(term spi_port, spi_host_device_t *host_dev, GlobalContext *global)
{
if (UNLIKELY(!term_is_pid(spi_port))) {
if (UNLIKELY(!term_is_local_port(spi_port))) {
ESP_LOGW(TAG, "Given term is not a SPI port driver.");
return false;
}
Expand Down

0 comments on commit c2e099d

Please sign in to comment.