Skip to content

Commit b227b79

Browse files
committed
Fix micropython#3504: Don't use time module in pew.tick()
The time.sleep() and time.monotonic() functions break the timer interrupt on which PewPew10 display relies, so we can't use them anymore. Instead I'm adding a time-keeping function to the display code itself, which then can be used in pew.tick() internally.
1 parent c7d87ce commit b227b79

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

ports/atmel-samd/common-hal/_pew/PewPew.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141

4242
static uint8_t pewpew_tc_index = 0xff;
43+
static volatile uint16_t pewpew_ticks = 0;
4344

4445

4546
void pewpew_interrupt_handler(uint8_t index) {
@@ -52,6 +53,7 @@ void pewpew_interrupt_handler(uint8_t index) {
5253
}
5354

5455
pew_tick();
56+
++pewpew_ticks;
5557

5658
// Clear the interrupt bit.
5759
tc->COUNT16.INTFLAG.reg = TC_INTFLAG_MC0;
@@ -123,3 +125,8 @@ void pew_reset(void) {
123125
}
124126
MP_STATE_VM(pew_singleton) = NULL;
125127
}
128+
129+
uint16_t pew_get_ticks() {
130+
return pewpew_ticks;
131+
}
132+

ports/atmel-samd/common-hal/_pew/PewPew.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,6 @@ typedef struct {
4444
void pew_init(void);
4545
void pewpew_interrupt_handler(uint8_t index);
4646
void pew_reset(void);
47+
uint16_t pew_get_ticks(void);
4748

4849
#endif // MICROPY_INCLUDED_PEW_PEWPEW_H

shared-bindings/_pew/__init__.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "PewPew.h"
3030
#include "common-hal/_pew/PewPew.h"
3131

32+
3233
STATIC mp_obj_t get_pressed(void) {
3334
pew_obj_t *pew = MP_STATE_VM(pew_singleton);
3435
if (!pew) {
@@ -41,12 +42,19 @@ STATIC mp_obj_t get_pressed(void) {
4142
STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_pressed_obj, get_pressed);
4243

4344

45+
STATIC mp_obj_t get_ticks(void) {
46+
return mp_obj_new_int(pew_get_ticks());
47+
}
48+
STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_ticks_obj, get_ticks);
49+
50+
4451
//| """LED matrix driver"""
4552
//|
4653
STATIC const mp_rom_map_elem_t pew_module_globals_table[] = {
4754
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__pew) },
4855
{ MP_OBJ_NEW_QSTR(MP_QSTR_PewPew), MP_ROM_PTR(&pewpew_type)},
4956
{ MP_OBJ_NEW_QSTR(MP_QSTR_get_pressed), MP_ROM_PTR(&get_pressed_obj)},
57+
{ MP_OBJ_NEW_QSTR(MP_QSTR_get_ticks), MP_ROM_PTR(&get_ticks_obj)},
5058
};
5159
STATIC MP_DEFINE_CONST_DICT(pew_module_globals,
5260
pew_module_globals_table);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy