@@ -59,16 +59,19 @@ void common_hal_keypad_keys_construct(keypad_keys_obj_t *self, mp_uint_t num_pin
5959 self -> currently_pressed = (bool * )gc_alloc (sizeof (bool ) * num_pins , false, false);
6060 self -> previously_pressed = (bool * )gc_alloc (sizeof (bool ) * num_pins , false, false);
6161 self -> value_when_pressed = value_when_pressed ;
62+ self -> last_scan_ticks = port_get_raw_ticks (NULL );
6263
6364 // Event queue is 16-bit values.
64- ringbuf_alloc (self -> encoded_events , max_events * 2 , false);
65+ ringbuf_alloc (& self -> encoded_events , max_events * 2 , false);
6566
6667 // Add self to the list of active Keys objects.
6768
6869 supervisor_acquire_lock (& keypad_keys_linked_list_lock );
6970 self -> next = MP_STATE_VM (keypad_keys_linked_list );
7071 MP_STATE_VM (keypad_keys_linked_list ) = self ;
7172 supervisor_release_lock (& keypad_keys_linked_list_lock );
73+
74+ supervisor_enable_tick ();
7275}
7376
7477void common_hal_keypad_keys_deinit (keypad_keys_obj_t * self ) {
@@ -113,19 +116,19 @@ bool common_hal_keypad_keys_pressed(keypad_keys_obj_t *self, mp_uint_t key_num)
113116}
114117
115118mp_obj_t common_hal_keypad_keys_next_event (keypad_keys_obj_t * self ) {
116- int encoded_event = ringbuf_get16 (self -> encoded_events );
119+ int encoded_event = ringbuf_get16 (& self -> encoded_events );
117120 if (encoded_event == -1 ) {
118121 return MP_ROM_NONE ;
119122 }
120123
121124 keypad_event_obj_t * event = m_new_obj (keypad_event_obj_t );
122- self -> base .type = & keypad_event_type ;
125+ event -> base .type = & keypad_event_type ;
123126 common_hal_keypad_event_construct (event , encoded_event & EVENT_KEY_NUM_MASK , encoded_event & EVENT_PRESSED );
124127 return MP_OBJ_FROM_PTR (event );
125128}
126129
127130void common_hal_keypad_keys_clear_events (keypad_keys_obj_t * self ) {
128- ringbuf_clear (self -> encoded_events );
131+ ringbuf_clear (& self -> encoded_events );
129132}
130133
131134static void keypad_keys_scan (keypad_keys_obj_t * self ) {
@@ -143,17 +146,17 @@ static void keypad_keys_scan(keypad_keys_obj_t *self) {
143146 self -> previously_pressed [key_num ] = previous ;
144147
145148 // Get the current state.
146- const bool current = common_hal_digitalio_digitalinout_get_value (self -> digitalinouts -> items [key_num ]) ==
149+ const bool current =
150+ common_hal_digitalio_digitalinout_get_value (self -> digitalinouts -> items [key_num ]) ==
147151 self -> value_when_pressed ;
148152 self -> currently_pressed [key_num ] = current ;
149-
150153 // Record any transitions.
151154 if (previous != current ) {
152- if (ringbuf_num_empty (self -> encoded_events ) == 0 ) {
155+ if (ringbuf_num_empty (& self -> encoded_events ) == 0 ) {
153156 // Discard oldest if full.
154- ringbuf_get16 (self -> encoded_events );
157+ ringbuf_get16 (& self -> encoded_events );
155158 }
156- ringbuf_put16 (self -> encoded_events , key_num | (current ? EVENT_PRESSED : EVENT_RELEASED ));
159+ ringbuf_put16 (& self -> encoded_events , key_num | (current ? EVENT_PRESSED : EVENT_RELEASED ));
157160 }
158161 }
159162}
0 commit comments