kopia lustrzana https://github.com/pimoroni/pimoroni-pico
MicroPython: Early wakeup GPIO latch module.
rodzic
82756a3fc9
commit
dfa13f2a39
|
@ -43,6 +43,7 @@ include(pcf85063a/micropython)
|
|||
|
||||
# Utility
|
||||
include(adcfft/micropython)
|
||||
include(wakeup/micropython)
|
||||
|
||||
# LEDs & Matrices
|
||||
include(plasma/micropython)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
set(MOD_NAME wakeup)
|
||||
string(TOUPPER ${MOD_NAME} MOD_NAME_UPPER)
|
||||
add_library(usermod_${MOD_NAME} INTERFACE)
|
||||
|
||||
target_sources(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
|
||||
)
|
||||
|
||||
target_include_directories(usermod_${MOD_NAME} INTERFACE
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_compile_definitions(usermod_${MOD_NAME} INTERFACE
|
||||
-DMODULE_${MOD_NAME_UPPER}_ENABLED=1
|
||||
)
|
||||
|
||||
target_link_libraries(usermod INTERFACE usermod_${MOD_NAME})
|
||||
|
||||
set_source_files_properties(
|
||||
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
|
||||
PROPERTIES COMPILE_FLAGS
|
||||
"-Wno-discarded-qualifiers"
|
||||
)
|
|
@ -0,0 +1,20 @@
|
|||
#include "wakeup.h"
|
||||
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_0(Wakeup_get_gpio_state_obj, Wakeup_get_gpio_state);
|
||||
|
||||
STATIC const mp_map_elem_t wakeup_globals_table[] = {
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_wakeup) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_get_gpio_state), MP_ROM_PTR(&Wakeup_get_gpio_state_obj) }
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mp_module_wakeup_globals, wakeup_globals_table);
|
||||
|
||||
const mp_obj_module_t wakeup_user_cmodule = {
|
||||
.base = { &mp_type_module },
|
||||
.globals = (mp_obj_dict_t*)&mp_module_wakeup_globals,
|
||||
};
|
||||
|
||||
#if MICROPY_VERSION <= 70144
|
||||
MP_REGISTER_MODULE(MP_QSTR_wakeup, wakeup_user_cmodule, MODULE_WAKEUP_ENABLED);
|
||||
#else
|
||||
MP_REGISTER_MODULE(MP_QSTR_wakeup, wakeup_user_cmodule);
|
||||
#endif
|
|
@ -0,0 +1,41 @@
|
|||
#include "hardware/gpio.h"
|
||||
|
||||
#ifndef WAKEUP_PIN_MASK
|
||||
#define WAKEUP_PIN_MASK ((0b1 << 2) | (0b1 << 6))
|
||||
#endif
|
||||
|
||||
#ifndef WAKEUP_PIN_DIR
|
||||
#define WAKEUP_PIN_DIR ((0b1 << 2) | (0b1 << 6))
|
||||
#endif
|
||||
|
||||
#ifndef WAKEUP_PIN_VALUE
|
||||
#define WAKEUP_PIN_VALUE ((0b1 << 2) | (0b1 << 6))
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
struct Wakeup {
|
||||
public:
|
||||
uint32_t wakeup_gpio_state;
|
||||
|
||||
Wakeup() {
|
||||
// Assert wakeup pins (indicator LEDs, VSYS hold etc)
|
||||
gpio_init_mask(WAKEUP_PIN_MASK);
|
||||
gpio_set_dir_masked(WAKEUP_PIN_MASK, WAKEUP_PIN_DIR);
|
||||
gpio_put_masked(WAKEUP_PIN_MASK, WAKEUP_PIN_VALUE);
|
||||
|
||||
// Latch GPIO state into variable
|
||||
Wakeup::wakeup_gpio_state = gpio_get_all();
|
||||
}
|
||||
};
|
||||
|
||||
Wakeup wakeup __attribute__ ((init_priority (101)));
|
||||
};
|
||||
|
||||
extern "C" {
|
||||
#include "wakeup.h"
|
||||
|
||||
mp_obj_t Wakeup_get_gpio_state() {
|
||||
return mp_obj_new_int(wakeup.wakeup_gpio_state);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
#include "py/runtime.h"
|
||||
#include "py/objstr.h"
|
||||
|
||||
extern mp_obj_t Wakeup_get_gpio_state();
|
Ładowanie…
Reference in New Issue