Merge pull request #2889 from jepler/gamepad-tick

Gamepad, GamepadShift: Fix after lower-power by enabling supervisor tick
This commit is contained in:
Scott Shawcroft 2020-05-13 11:53:23 -07:00 committed by GitHub
commit db4dbe0752
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 4 deletions

View File

@ -31,6 +31,7 @@
#include "shared-bindings/audiocore/RawSample.h" #include "shared-bindings/audiocore/RawSample.h"
#include "shared-bindings/audiocore/WaveFile.h" #include "shared-bindings/audiocore/WaveFile.h"
#include "supervisor/shared/tick.h"
#include "py/mpstate.h" #include "py/mpstate.h"
#include "py/runtime.h" #include "py/runtime.h"
@ -60,6 +61,7 @@ void audio_dma_free_channel(uint8_t channel) {
assert(audio_dma_allocated[channel]); assert(audio_dma_allocated[channel]);
audio_dma_disable_channel(channel); audio_dma_disable_channel(channel);
audio_dma_allocated[channel] = false; audio_dma_allocated[channel] = false;
supervisor_disable_tick();
} }
void audio_dma_disable_channel(uint8_t channel) { void audio_dma_disable_channel(uint8_t channel) {
@ -71,6 +73,7 @@ void audio_dma_disable_channel(uint8_t channel) {
void audio_dma_enable_channel(uint8_t channel) { void audio_dma_enable_channel(uint8_t channel) {
if (channel >= AUDIO_DMA_CHANNEL_COUNT) if (channel >= AUDIO_DMA_CHANNEL_COUNT)
return; return;
supervisor_enable_tick();
dma_enable_channel(channel); dma_enable_channel(channel);
} }
@ -318,6 +321,9 @@ void audio_dma_reset(void) {
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) { for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
audio_dma_state[i] = NULL; audio_dma_state[i] = NULL;
audio_dma_pending[i] = false; audio_dma_pending[i] = false;
if (audio_dma_allocated[i]) {
supervisor_disable_tick();
}
audio_dma_allocated[i] = false; audio_dma_allocated[i] = false;
audio_dma_disable_channel(i); audio_dma_disable_channel(i);
dma_descriptor(i)->BTCTRL.bit.VALID = false; dma_descriptor(i)->BTCTRL.bit.VALID = false;

View File

@ -33,6 +33,7 @@
#include "shared-bindings/gamepad/__init__.h" #include "shared-bindings/gamepad/__init__.h"
#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DigitalInOut.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
#include "supervisor/shared/tick.h"
//| .. currentmodule:: gamepad //| .. currentmodule:: gamepad
@ -105,9 +106,11 @@ STATIC mp_obj_t gamepad_make_new(const mp_obj_type_t *type, size_t n_args,
gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton); gamepad_obj_t* gamepad_singleton = MP_STATE_VM(gamepad_singleton);
if (!gamepad_singleton || if (!gamepad_singleton ||
!MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton), &gamepad_type)) { !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton), &gamepad_type)) {
gamepad_singleton = m_new_obj(gamepad_obj_t); gamepad_singleton = m_new_ll_obj(gamepad_obj_t);
gamepad_singleton->base.type = &gamepad_type; gamepad_singleton->base.type = &gamepad_type;
gamepad_singleton = gc_make_long_lived(gamepad_singleton); if (!MP_STATE_VM(gamepad_singleton)) {
supervisor_enable_tick();
}
MP_STATE_VM(gamepad_singleton) = gamepad_singleton; MP_STATE_VM(gamepad_singleton) = gamepad_singleton;
} }
common_hal_gamepad_gamepad_init(gamepad_singleton, args, n_args); common_hal_gamepad_gamepad_init(gamepad_singleton, args, n_args);

View File

@ -31,6 +31,7 @@
#include "shared-bindings/gamepadshift/GamePadShift.h" #include "shared-bindings/gamepadshift/GamePadShift.h"
#include "shared-bindings/gamepadshift/__init__.h" #include "shared-bindings/gamepadshift/__init__.h"
#include "supervisor/shared/translate.h" #include "supervisor/shared/translate.h"
#include "supervisor/shared/tick.h"
//| .. currentmodule:: gamepadshift //| .. currentmodule:: gamepadshift
//| //|
@ -72,9 +73,11 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args,
if (!gamepad_singleton || if (!gamepad_singleton ||
!MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton), !MP_OBJ_IS_TYPE(MP_OBJ_FROM_PTR(gamepad_singleton),
&gamepadshift_type)) { &gamepadshift_type)) {
gamepad_singleton = m_new_obj(gamepadshift_obj_t); gamepad_singleton = m_new_ll_obj(gamepadshift_obj_t);
gamepad_singleton->base.type = &gamepadshift_type; gamepad_singleton->base.type = &gamepadshift_type;
gamepad_singleton = gc_make_long_lived(gamepad_singleton); if (!MP_STATE_VM(gamepad_singleton)) {
supervisor_enable_tick();
}
MP_STATE_VM(gamepad_singleton) = gamepad_singleton; MP_STATE_VM(gamepad_singleton) = gamepad_singleton;
} }
common_hal_gamepadshift_gamepadshift_init(gamepad_singleton, clock_pin, data_pin, latch_pin); common_hal_gamepadshift_gamepadshift_init(gamepad_singleton, clock_pin, data_pin, latch_pin);

View File

@ -27,6 +27,7 @@
#include "py/mpstate.h" #include "py/mpstate.h"
#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-bindings/gamepad/GamePad.h" #include "shared-bindings/gamepad/GamePad.h"
#include "supervisor/shared/tick.h"
void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad, void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad,
const mp_obj_t pins[], size_t n_pins) { const mp_obj_t pins[], size_t n_pins) {
@ -54,4 +55,5 @@ void common_hal_gamepad_gamepad_init(gamepad_obj_t *gamepad,
void common_hal_gamepad_gamepad_deinit(gamepad_obj_t *self) { void common_hal_gamepad_gamepad_deinit(gamepad_obj_t *self) {
MP_STATE_VM(gamepad_singleton) = NULL; MP_STATE_VM(gamepad_singleton) = NULL;
supervisor_disable_tick();
} }

View File

@ -29,6 +29,7 @@
#include "py/mpstate.h" #include "py/mpstate.h"
#include "shared-bindings/gamepad/__init__.h" #include "shared-bindings/gamepad/__init__.h"
#include "shared-bindings/gamepad/GamePad.h" #include "shared-bindings/gamepad/GamePad.h"
#include "supervisor/shared/tick.h"
#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DigitalInOut.h"
@ -59,5 +60,8 @@ void gamepad_tick(void) {
} }
void gamepad_reset(void) { void gamepad_reset(void) {
if (MP_STATE_VM(gamepad_singleton)) {
supervisor_disable_tick();
}
MP_STATE_VM(gamepad_singleton) = NULL; MP_STATE_VM(gamepad_singleton) = NULL;
} }

View File

@ -27,6 +27,7 @@
#include "py/mpstate.h" #include "py/mpstate.h"
#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DigitalInOut.h"
#include "shared-module/gamepadshift/GamePadShift.h" #include "shared-module/gamepadshift/GamePadShift.h"
#include "supervisor/shared/tick.h"
void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift, void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift,
digitalio_digitalinout_obj_t *clock_pin, digitalio_digitalinout_obj_t *clock_pin,
@ -46,4 +47,5 @@ void common_hal_gamepadshift_gamepadshift_init(gamepadshift_obj_t *gamepadshift,
void common_hal_gamepadshift_gamepadshift_deinit(gamepadshift_obj_t *gamepadshift) { void common_hal_gamepadshift_gamepadshift_deinit(gamepadshift_obj_t *gamepadshift) {
MP_STATE_VM(gamepad_singleton) = NULL; MP_STATE_VM(gamepad_singleton) = NULL;
supervisor_disable_tick();
} }