MicroPython: Port wakeup GPIO latch to asm.

This commit is contained in:
Phil Howard 2022-08-02 09:46:04 +01:00 committed by Phil Howard
parent dfa13f2a39
commit a4b6d86ac7
3 changed files with 30 additions and 6 deletions

View File

@ -5,6 +5,7 @@ add_library(usermod_${MOD_NAME} INTERFACE)
target_sources(usermod_${MOD_NAME} INTERFACE target_sources(usermod_${MOD_NAME} INTERFACE
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c ${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.c
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp ${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.cpp
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.S
) )
target_include_directories(usermod_${MOD_NAME} INTERFACE target_include_directories(usermod_${MOD_NAME} INTERFACE

View File

@ -0,0 +1,26 @@
.syntax unified
.cpu cortex-m0plus
.thumb
#include "pico/asm_helper.S"
// This macro tells the pico runtime to call __wakeup_gpio_latch very early in boot
__pre_init __wakeup_gpio_latch, 00001
.section .data.wakeup_gpio_latch
.global wakeup_gpio_state
.align 4
wakeup_gpio_state:
.word 0x00000000
.section .text
.thumb_func
__wakeup_gpio_latch:
// Read GPIO state for front buttons and store
movs r3, 0xd0 // Load 0xd0 into r3
lsls r3, r3, 24 // Shift left 24 to get 0xd0000000
ldr r1, [r3, 4] // Load GPIO state (0xd0000004) into r1
ldr r2, =wakeup_gpio_state // Load output var addr into r2
str r1, [r2] // Store r1 to r2
bx lr // Return

View File

@ -12,19 +12,16 @@
#define WAKEUP_PIN_VALUE ((0b1 << 2) | (0b1 << 6)) #define WAKEUP_PIN_VALUE ((0b1 << 2) | (0b1 << 6))
#endif #endif
extern uint32_t wakeup_gpio_state;
namespace { namespace {
struct Wakeup { struct Wakeup {
public: public:
uint32_t wakeup_gpio_state;
Wakeup() { Wakeup() {
// Assert wakeup pins (indicator LEDs, VSYS hold etc) // Assert wakeup pins (indicator LEDs, VSYS hold etc)
gpio_init_mask(WAKEUP_PIN_MASK); gpio_init_mask(WAKEUP_PIN_MASK);
gpio_set_dir_masked(WAKEUP_PIN_MASK, WAKEUP_PIN_DIR); gpio_set_dir_masked(WAKEUP_PIN_MASK, WAKEUP_PIN_DIR);
gpio_put_masked(WAKEUP_PIN_MASK, WAKEUP_PIN_VALUE); gpio_put_masked(WAKEUP_PIN_MASK, WAKEUP_PIN_VALUE);
// Latch GPIO state into variable
Wakeup::wakeup_gpio_state = gpio_get_all();
} }
}; };
@ -35,7 +32,7 @@ extern "C" {
#include "wakeup.h" #include "wakeup.h"
mp_obj_t Wakeup_get_gpio_state() { mp_obj_t Wakeup_get_gpio_state() {
return mp_obj_new_int(wakeup.wakeup_gpio_state); return mp_obj_new_int(wakeup_gpio_state);
} }
} }