[*] Goal: have a IT9851 e-Paper driver for the M5Paper (communicating via SPI) (M5Paper has 8MB of SPI_FLASH)
[*] My approach: provide a native module (as in https://docs.micropython.org/en/latest/ ... atmod.html)
[*] Alternative1: provide a built-in module similar to https://github.com/russhughes/st7789_mpy
(that seems to be not very flexible and I have to build/flash the firmware for each try)
[*] Alternative2: Provide a pure Python module, but that would be slow, and quite memory inefficient
Currently I'm taking examples from micropython/examples/natmod and try to make them SPI capable but that somehow feels like the wrong way. It looks like in order to be able to import "extmod/machine_spi.h" I have to fiddle with dozens of include directories in the Makefile, and currently I'm facing a compiler error that doesn't make sense to me:
Code: Select all
_Static_assert(portGET_ARGUMENT_COUNT() == 0, "portGET_ARGUMENT_COUNT() result does not match for 0 arguments");
Can someone provide an example for a working native module that deals with SPI already?
Anyway, my next step would be to take code from one of these projects:
* https://github.com/lovyan03/LovyanGFX/t ... x/v0/panel
* https://github.com/GregDMeyer/IT8951
.. and bring the code to the new module.
How would you do that? Is there a Micropython driver for IT9851 already?
Here is my current Makefile / source file:
Code: Select all
MPY_DIR = ../micropython
ISPIDF_DIR = ../esp-idf
MOD = it8951
SRC = it8951.c
ARCH = xtensawin
CFLAGS += -I$(MPY_DIR)/ports/esp32
CFLAGS += -I$(MPY_DIR)/ports/esp32/build-GENERIC/config
CFLAGS += -I$(ISPIDF_DIR)/components/xtensa/include
CFLAGS += -I$(ISPIDF_DIR)/components/xtensa/esp32/include
CFLAGS += -I$(ISPIDF_DIR)/components/freertos/include
CFLAGS += -I$(ISPIDF_DIR)/components/freertos/port/xtensa/include
CFLAGS += -I$(ISPIDF_DIR)/components/freertos/include/esp_additions/freertos
CFLAGS += -I$(ISPIDF_DIR)/components/esp_common/include
CFLAGS += -I$(ISPIDF_DIR)/components/esp_rom/include
CFLAGS += -I$(ISPIDF_DIR)/components/esp_system/include
CFLAGS += -I$(ISPIDF_DIR)/components/esp_hw_support/include
CFLAGS += -I$(ISPIDF_DIR)/components/soc/esp32/include
CFLAGS += -I$(ISPIDF_DIR)/components/soc/include
CFLAGS += -I$(ISPIDF_DIR)/components/hal/include
CFLAGS += -I$(ISPIDF_DIR)/components/hal/esp32/include
CFLAGS += -I$(ISPIDF_DIR)/components/esp_timer/include
CFLAGS += -I$(ISPIDF_DIR)/components/newlib/platform_include
CFLAGS += -I$(ISPIDF_DIR)/components/heap/include
CFLAGS += -I$(ISPIDF_DIR)/components/driver/include
include $(MPY_DIR)/py/dynruntime.mk
Code: Select all
#include "py/dynruntime.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "py/obj.h"
#include "py/objstr.h"
#include "py/objmodule.h"
#include "py/runtime.h"
#include "py/builtin.h"
#include "py/mphal.h"
#include "extmod/machine_spi.h"
// THE CODE BELOW IS JUST THE factorial EXAMPLE
// Helper function to compute factorial
STATIC mp_int_t factorial_helper(mp_int_t x) {
if (x == 0) {
return 1;
}
return x * factorial_helper(x - 1);
}
// This is the function which will be called from Python, as factorial(x)
STATIC mp_obj_t factorial(mp_obj_t x_obj) {
// Extract the integer from the MicroPython input object
mp_int_t x = mp_obj_get_int(x_obj);
// Calculate the factorial
mp_int_t result = factorial_helper(x);
// Convert the result to a MicroPython integer object and return it
return mp_obj_new_int(result);
}
// Define a Python reference to the function above
STATIC MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial);
// This is the entry point and is called when the module is imported
mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) {
// This must be first, it sets up the globals dict and other things
MP_DYNRUNTIME_INIT_ENTRY
// Make the function available in the module's namespace
mp_store_global(MP_QSTR_factorial, MP_OBJ_FROM_PTR(&factorial_obj));
// This must be last, it restores the globals dict
MP_DYNRUNTIME_INIT_EXIT
}