MicroPython: Port wakeup GPIO latch to asm.

pull/480/head
Phil Howard 2022-08-02 09:46:04 +01:00 zatwierdzone przez Phil Howard
rodzic dfa13f2a39
commit a4b6d86ac7
3 zmienionych plików z 30 dodań i 6 usunięć

Wyświetl plik

@ -5,6 +5,7 @@ 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
${CMAKE_CURRENT_LIST_DIR}/${MOD_NAME}.S
)
target_include_directories(usermod_${MOD_NAME} INTERFACE

Wyświetl plik

@ -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

Wyświetl plik

@ -12,19 +12,16 @@
#define WAKEUP_PIN_VALUE ((0b1 << 2) | (0b1 << 6))
#endif
extern uint32_t wakeup_gpio_state;
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();
}
};
@ -35,7 +32,7 @@ extern "C" {
#include "wakeup.h"
mp_obj_t Wakeup_get_gpio_state() {
return mp_obj_new_int(wakeup.wakeup_gpio_state);
return mp_obj_new_int(wakeup_gpio_state);
}
}