Skip to content

Commit 2569478

Browse files
committed
feat(repo): support MicroPython
1 parent 567f0b4 commit 2569478

24 files changed

+248
-47
lines changed

esp_panel_board_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// *INDENT-OFF*
1010

1111
/* Set to 1 if using a custom board */
12-
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (1) // 0/1
12+
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (0) // 0/1
1313

1414
#if ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM
1515

examples/LVGL/v8/Porting/esp_panel_board_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// *INDENT-OFF*
1010

1111
/* Set to 1 if using a custom board */
12-
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (1) // 0/1
12+
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (0) // 0/1
1313

1414
#if ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM
1515

examples/LVGL/v8/Rotation/esp_panel_board_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// *INDENT-OFF*
1010

1111
/* Set to 1 if using a custom board */
12-
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (1) // 0/1
12+
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (0) // 0/1
1313

1414
#if ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM
1515

examples/Panel/PanelTest/esp_panel_board_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// *INDENT-OFF*
1010

1111
/* Set to 1 if using a custom board */
12-
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (1) // 0/1
12+
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (0) // 0/1
1313

1414
#if ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM
1515

examples/PlatformIO/src/esp_panel_board_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// *INDENT-OFF*
1010

1111
/* Set to 1 if using a custom board */
12-
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (1) // 0/1
12+
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (0) // 0/1
1313

1414
#if ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM
1515

examples/SquareLine/v8/Porting/esp_panel_board_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// *INDENT-OFF*
1010

1111
/* Set to 1 if using a custom board */
12-
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (1) // 0/1
12+
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (0) // 0/1
1313

1414
#if ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM
1515

examples/SquareLine/v8/WiFiClock/esp_panel_board_custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// *INDENT-OFF*
1010

1111
/* Set to 1 if using a custom board */
12-
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (1) // 0/1
12+
#define ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM (0) // 0/1
1313

1414
#if ESP_PANEL_BOARD_DEFAULT_USE_CUSTOM
1515

micropython.cmake

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is to be given as "make USER_C_MODULES=..." when building Micropython port
2+
3+
add_library(usermod_esp_display_panel INTERFACE)
4+
5+
# Find all source files in the `src` directory.
6+
set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
7+
file(GLOB_RECURSE SRCS_C ${SRC_DIR}/*.c)
8+
file(GLOB_RECURSE SRCS_CXX ${SRC_DIR}/*.cpp)
9+
10+
# Find all source files in the `micropython` directory.
11+
set(MPY_DIR ${CMAKE_CURRENT_LIST_DIR}/mpy_support)
12+
file(GLOB_RECURSE MPY_C ${MPY_DIR}/*.c)
13+
file(GLOB_RECURSE MPY_CXX ${MPY_DIR}/*.cpp)
14+
15+
# Add source files to the library.
16+
target_sources(usermod_esp_display_panel INTERFACE ${SRCS_C} ${SRCS_CXX} ${MPY_C} ${MPY_CXX})
17+
18+
# Add the current directory as an include directory.
19+
target_include_directories(usermod_esp_display_panel INTERFACE ${SRC_DIR} ${MPY_DIR})
20+
21+
# Add compile options. Since the target is not created by `idf_component_register()`, we need to add the `ESP_PLATFORM` define manually.
22+
target_compile_options(usermod_esp_display_panel INTERFACE -Wno-missing-field-initializers -DESP_PLATFORM)
23+
24+
# Link INTERFACE library to the usermod target.
25+
target_link_libraries(usermod INTERFACE usermod_esp_display_panel)

mpy_support/esp_panel_mp_board.cpp

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#include "esp_panel_utils.h"
7+
#include "board/esp_panel_board.hpp"
8+
#include "esp_panel_mp_types.h"
9+
#include "esp_panel_mp_board.h"
10+
11+
namespace esp_panel {
12+
13+
/**
14+
* MicroPython Wrappers
15+
*
16+
*/
17+
// Object
18+
struct MP_Board {
19+
mp_obj_base_t base;
20+
std::shared_ptr<Board> board = nullptr;
21+
};
22+
23+
static mp_obj_t board_del(mp_obj_t self_in)
24+
{
25+
MP_Board *self = static_cast<MP_Board *>(MP_OBJ_TO_PTR(self_in));
26+
27+
self->board = nullptr;
28+
29+
return mp_const_none;
30+
}
31+
static MP_DEFINE_CONST_FUN_OBJ_1_CXX(board_del_func_obj, board_del);
32+
33+
static mp_obj_t board_init(mp_obj_t self_in)
34+
{
35+
MP_Board *self = static_cast<MP_Board *>(MP_OBJ_TO_PTR(self_in));
36+
37+
return mp_obj_new_bool(self->board->init());
38+
}
39+
static MP_DEFINE_CONST_FUN_OBJ_1_CXX(board_init_func_obj, board_init);
40+
41+
static mp_obj_t board_begin(mp_obj_t self_in)
42+
{
43+
MP_Board *self = static_cast<MP_Board *>(MP_OBJ_TO_PTR(self_in));
44+
45+
return mp_obj_new_bool(self->board->begin());
46+
}
47+
static MP_DEFINE_CONST_FUN_OBJ_1_CXX(board_begin_func_obj, board_begin);
48+
49+
static mp_obj_t board_deinit(mp_obj_t self_in)
50+
{
51+
MP_Board *self = static_cast<MP_Board *>(MP_OBJ_TO_PTR(self_in));
52+
53+
return mp_obj_new_bool(self->board->del());
54+
}
55+
static MP_DEFINE_CONST_FUN_OBJ_1_CXX(board_deinit_func_obj, board_deinit);
56+
57+
static mp_obj_t board_color_bar_test(mp_obj_t self_in)
58+
{
59+
MP_Board *self = static_cast<MP_Board *>(MP_OBJ_TO_PTR(self_in));
60+
61+
return mp_obj_new_bool(self->board->getLcd()->colorBarTest(480, 480));
62+
}
63+
static MP_DEFINE_CONST_FUN_OBJ_1_CXX(board_color_bar_test_func_obj, board_color_bar_test);
64+
65+
// Local dict
66+
static const mp_rom_map_elem_t board_locals_dict_table[] = {
67+
{ MP_ROM_QSTR(MP_QSTR__del__), MP_ROM_PTR(&board_del_func_obj) },
68+
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&board_init_func_obj) },
69+
{ MP_ROM_QSTR(MP_QSTR_begin), MP_ROM_PTR(&board_begin_func_obj) },
70+
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&board_deinit_func_obj) },
71+
{ MP_ROM_QSTR(MP_QSTR_color_bar_test), MP_ROM_PTR(&board_color_bar_test_func_obj) },
72+
};
73+
static MP_DEFINE_CONST_DICT(board_locals_dict, board_locals_dict_table);
74+
75+
// Constructor
76+
static mp_obj_t board_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
77+
{
78+
MP_Board *self = mp_obj_malloc(MP_Board, &MP_Boardype);
79+
self->board = esp_utils::make_shared<Board>();
80+
81+
return MP_OBJ_FROM_PTR(self);
82+
}
83+
84+
// Print
85+
static void board_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
86+
{
87+
mp_printf(print, "Board");
88+
}
89+
90+
} // namespace esp_panel
91+
92+
// Type
93+
MP_DEFINE_CONST_OBJ_TYPE(
94+
MP_Boardype,
95+
MP_QSTR_Board,
96+
MP_TYPE_FLAG_NONE,
97+
make_new, (const void *)esp_panel::board_make_new,
98+
print, (const void *)esp_panel::board_print,
99+
locals_dict, &esp_panel::board_locals_dict
100+
);

mpy_support/esp_panel_mp_board.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
#pragma once
7+
8+
#ifdef __cplusplus
9+
extern "C" {
10+
#endif
11+
12+
#include "py/runtime.h"
13+
#include "py/obj.h"
14+
15+
extern const mp_obj_type_t esp_panel_mp_board_type;
16+
17+
#ifdef __cplusplus
18+
}
19+
#endif

0 commit comments

Comments
 (0)