kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Wakeup: Move wakeup pin assert and latch out of patches.
rodzic
6cfcd80037
commit
a05a225262
|
@ -31,6 +31,9 @@ include(wakeup/micropython)
|
|||
# Configure wakeup for Enviro
|
||||
target_compile_definitions(usermod_wakeup INTERFACE
|
||||
-DWAKEUP_HAS_RTC=1
|
||||
-DWAKEUP_PIN_MASK=0b01000100
|
||||
-DWAKEUP_PIN_DIR=0b01000100
|
||||
-DWAKEUP_PIN_VALUE=0b01000100
|
||||
)
|
||||
|
||||
# LEDs & Matrices
|
||||
|
|
|
@ -33,6 +33,9 @@ include(wakeup/micropython)
|
|||
target_compile_definitions(usermod_wakeup INTERFACE
|
||||
-DWAKEUP_HAS_RTC=1
|
||||
-DWAKEUP_HAS_SHIFT_REGISTER=1
|
||||
-DWAKEUP_PIN_MASK=0b01000100
|
||||
-DWAKEUP_PIN_DIR=0b01000100
|
||||
-DWAKEUP_PIN_VALUE=0b01000100
|
||||
)
|
||||
|
||||
# LEDs & Matrices
|
||||
|
|
|
@ -5,7 +5,6 @@ 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
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
|
||||
.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, 00000
|
||||
|
||||
.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
|
||||
|
||||
// Enable 3v3 pin on the badger
|
||||
ldr r1, =0x40014054 // GPIO control register 10
|
||||
movs r2, 5 // SIO function
|
||||
str r2, [r1] // Set Enable 3v3 to SIO // https://github.com/raspberrypi/pico-sdk/blob/2e6142b15b8a75c1227dd3edbe839193b2bf9041/src/rp2_common/hardware_gpio/include/hardware/gpio.h#L96
|
||||
str r2, [r1, 120] // Also set LED (25) to SIO
|
||||
ldr r2, =0x02000400 // Pins 25 and 10
|
||||
str r2, [r3, 36] // Enable pins out
|
||||
str r2, [r3, 20] // Set pins high
|
||||
|
||||
bx lr // Return
|
|
@ -1,18 +1,30 @@
|
|||
#include "hardware/gpio.h"
|
||||
#include "wakeup.config.hpp"
|
||||
|
||||
extern uint32_t runtime_wakeup_gpio_state;
|
||||
|
||||
namespace {
|
||||
struct Wakeup {
|
||||
public:
|
||||
uint8_t shift_register_state = 0b0;
|
||||
uint32_t gpio_state = 0;
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
// Init all GPIOS not specified in the wakeup mask
|
||||
#if PICO_RP2350
|
||||
gpio_init_mask(~WAKEUP_PIN_MASK);
|
||||
gpio_set_dir_in_masked(~WAKEUP_PIN_MASK);
|
||||
#endif
|
||||
gpio_state = gpio_get_all();
|
||||
sleep_ms(5);
|
||||
gpio_state |= gpio_get_all();
|
||||
#if PICO_RP2350
|
||||
gpio_init_mask(~WAKEUP_PIN_MASK);
|
||||
#endif
|
||||
|
||||
#if WAKEUP_HAS_RTC==1
|
||||
// Set up RTC I2C pins and send reset command
|
||||
|
@ -59,11 +71,11 @@ extern "C" {
|
|||
#include "wakeup.h"
|
||||
|
||||
mp_obj_t Wakeup_get_gpio_state() {
|
||||
return mp_obj_new_int(runtime_wakeup_gpio_state);
|
||||
return mp_obj_new_int(wakeup.gpio_state);
|
||||
}
|
||||
|
||||
mp_obj_t Wakeup_reset_gpio_state() {
|
||||
runtime_wakeup_gpio_state = 0;
|
||||
wakeup.gpio_state = 0;
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue