Skip to content

Commit

Permalink
Fix compatiblity with esp-idf 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
pguyot committed Sep 4, 2023
1 parent 39b4e43 commit 11bf869
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ StatementMacros:
- M5_NIF_i2_v
- M5_NIF_i3_i3u_v
- M5_NIF_i3_v
- M5_NIF_ici2_v
- M5_NIF_i4_i4u_v
- M5_NIF_i4_v
- M5_NIF_i5_i5u_v
Expand All @@ -20,5 +21,6 @@ StatementMacros:
- M5_NIF_v_b
- M5_NIF_v_i
- M5_NIF_v_i4
- M5_NIF_i32o4_v
- M5_NIF_v_u_v
- M5_NIF_v_v
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ idf_component_register(
PRIV_REQUIRES "libatomvm" "avm_sys" "main" "M5Unified"
)

target_compile_features(${COMPONENT_LIB} INTERFACE cxx_std_14)

idf_build_set_property(
LINK_OPTIONS "-Wl,--whole-archive ${CMAKE_CURRENT_BINARY_DIR}/lib${COMPONENT_NAME}.a -Wl,--no-whole-archive"
LINK_OPTIONS "-Wl,--whole-archive;${CMAKE_CURRENT_BINARY_DIR}/lib${COMPONENT_NAME}.a;-Wl,--no-whole-archive"
APPEND
)
4 changes: 2 additions & 2 deletions nifs/atomvm_m5_display.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ M5_NIF_b_v(nif_display_set_auto_display, Display, setAutoDisplay)
M5_NIF_v_i(nif_display_get_rotation, Display, getRotation)
M5_NIF_i_v(nif_display_set_rotation, Display, setRotation)
M5_NIF_i4_v(nif_display_set_clip_rect, Display, setClipRect)
M5_NIF_v_i4(nif_display_get_clip_rect, Display, getClipRect)
M5_NIF_i32o4_v(nif_display_get_clip_rect, Display, getClipRect)
M5_NIF_v_v(nif_display_clear_clip_rect, Display, clearClipRect)
M5_NIF_i4_v(nif_display_set_scroll_rect, Display, setScrollRect)
M5_NIF_v_i4(nif_display_get_scroll_rect, Display, getScrollRect)
M5_NIF_i32o4_v(nif_display_get_scroll_rect, Display, getScrollRect)
M5_NIF_v_v(nif_display_clear_scroll_rect, Display, clearScrollRect)

static term nif_display_get_cursor(Context* ctx, int argc, term argv[])
Expand Down
10 changes: 5 additions & 5 deletions nifs/atomvm_m5_i2c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <memory.h>
#include <nifs.h>
#include <term.h>
//#define ENABLE_TRACE
// #define ENABLE_TRACE
#include <trace.h>

#include "atomvm_m5_nifs.h"
Expand All @@ -35,10 +35,10 @@

#define MAKE_ATOM(ctx, len, str) globalcontext_make_atom(ctx->global, ATOM_STR(len, str))

M5_NIF_i3_v(nif_in_i2c_set_port, In_I2C, setPort)
M5_NIF_i3_v(nif_ex_i2c_set_port, Ex_I2C, setPort)
M5_NIF_i3_v(nif_in_i2c_begin, In_I2C, begin)
M5_NIF_i3_v(nif_ex_i2c_begin, Ex_I2C, begin)
M5_NIF_ici2_v(nif_in_i2c_set_port, In_I2C, setPort, i2c_port_t)
M5_NIF_ici2_v(nif_ex_i2c_set_port, Ex_I2C, setPort, i2c_port_t)
M5_NIF_ici2_v(nif_in_i2c_begin, In_I2C, begin, i2c_port_t)
M5_NIF_ici2_v(nif_ex_i2c_begin, Ex_I2C, begin, i2c_port_t)

static constexpr std::array<std::pair<const char*, const struct Nif>, 2> IN_NIFS = { {
{ "set_port/3", { { NIFFunctionType }, nif_in_i2c_set_port } },
Expand Down
18 changes: 16 additions & 2 deletions nifs/atomvm_m5_nifs.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,20 @@
return OK_ATOM; \
}

#define M5_NIF_ici2_v(name, module, api_func, t) \
static term name(Context* ctx, int argc, term argv[]) \
{ \
UNUSED(argc); \
VALIDATE_VALUE(argv[0], term_is_integer); \
VALIDATE_VALUE(argv[1], term_is_integer); \
VALIDATE_VALUE(argv[2], term_is_integer); \
M5.module.api_func( \
(t)term_to_int(argv[0]), \
term_to_int(argv[1]), \
term_to_int(argv[2])); \
return OK_ATOM; \
}

#define M5_NIF_i4_v(name, module, api_func) \
static term name(Context* ctx, int argc, term argv[]) \
{ \
Expand All @@ -126,12 +140,12 @@
return OK_ATOM; \
}

#define M5_NIF_v_i4(name, module, api_func) \
#define M5_NIF_i32o4_v(name, module, api_func) \
static term name(Context* ctx, int argc, term argv[]) \
{ \
UNUSED(argc); \
UNUSED(argv); \
int x, y, w, h; \
int32_t x, y, w, h; \
M5.module.api_func(&x, &y, &w, &h); \
if (memory_ensure_free_opt(ctx, TUPLE_SIZE(4), MEMORY_CAN_SHRINK) != MEMORY_GC_OK) { \
RAISE_ERROR(OUT_OF_MEMORY_ATOM); \
Expand Down

0 comments on commit 11bf869

Please sign in to comment.