Skip to content

Commit

Permalink
Merge pull request atomvm#898 from bettio/stm32_gpio_driver-fixes
Browse files Browse the repository at this point in the history
STM32 GPIO driver fixes

This PR fixes few issues introduced with atomvm#836.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
  • Loading branch information
bettio committed Oct 27, 2023
2 parents 8c3e7d1 + 05e98e4 commit f274873
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
12 changes: 3 additions & 9 deletions src/platforms/stm32/src/lib/gpio_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,10 @@
static NativeHandlerResult consume_gpio_mailbox(Context *ctx);

static const char *const gpio_atom = ATOM_STR("\x4", "gpio");
static const char *const gpio_driver_atom = ATOM_STR("\xB", "gpio_driver");

#define INVALID_EXTI_TRIGGER 0xEE
#define GPIO_INTERRUPT_ATOM globalcontext_make_atom(ctx->global, ATOM_STR("\xE", "gpio_interrupt"))

static term gpio_driver;

struct GPIOListenerData
{
struct ListHead gpio_listener_list_head;
Expand Down Expand Up @@ -483,8 +480,7 @@ static term gpio_digital_read(Context *ctx, term gpio_pin_tuple)

void gpiodriver_init(GlobalContext *glb)
{
int index = globalcontext_insert_atom(glb, gpio_driver_atom);
gpio_driver = term_from_atom_index(index);
UNUSED(glb);
}

static Context *gpio_driver_create_port(GlobalContext *global, term opts)
Expand Down Expand Up @@ -549,16 +545,14 @@ void gpio_interrupt_callback(Context *ctx, uint32_t exti)

struct GPIOData *gpio_data = ctx->platform_data;
struct ListHead *item;
struct ListHead *tmp;
MUTABLE_LIST_FOR_EACH (item, tmp, &gpio_data->gpio_listeners) {
LIST_FOR_EACH (item, &gpio_data->gpio_listeners) {
struct GPIOListenerData *gpio_listener = GET_LIST_ENTRY(item, struct GPIOListenerData, gpio_listener_list_head);
if (gpio_listener->exti == exti) {
listening_pid = gpio_listener->target_local_pid;
gpio_bank = gpio_listener->bank_atom;
gpio_pin = gpio_listener->gpio_pin;

// 1 header + 2 elements, second element is tuple with 2 elements
BEGIN_WITH_STACK_HEAP(1 + 2 + 2, heap);
BEGIN_WITH_STACK_HEAP(TUPLE_SIZE(2) + TUPLE_SIZE(2), heap);

term int_msg = term_alloc_tuple(2, &heap);
term gpio_tuple = term_alloc_tuple(2, &heap);
Expand Down
6 changes: 2 additions & 4 deletions src/platforms/stm32/src/lib/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

#define TAG "sys"

static const char *const stm32_atom = ATOM_STR("\x5", "stm32");

struct PortDriverDefListItem *port_driver_list;
struct NifCollectionDefListItem *nif_collection_list;

Expand Down Expand Up @@ -100,7 +98,7 @@ bool sys_lock_pin(GlobalContext *glb, uint32_t gpio_bank, uint16_t pin_num)
}

struct LockedPin *data = malloc(sizeof(struct LockedPin));
if (UNLIKELY(IS_NULL_PTR(data))) {
if (IS_NULL_PTR(data)) {
AVM_LOGE(TAG, "Out of memory!");
AVM_ABORT();
}
Expand Down Expand Up @@ -132,7 +130,7 @@ bool sys_unlock_pin(GlobalContext *glb, uint32_t gpio_bank, uint16_t pin_num)

void sys_init_platform(GlobalContext *glb)
{
globalcontext_make_atom(glb, stm32_atom);
UNUSED(glb);
}

void sys_free_platform(GlobalContext *glb)
Expand Down

0 comments on commit f274873

Please sign in to comment.