From 1fc10c8fe6eff76bd5b2e5041c86a332e342f919 Mon Sep 17 00:00:00 2001 From: fleur <spacecarrot@fleurshax.net> Date: Thu, 15 Aug 2019 09:47:33 +0200 Subject: [PATCH] debloated, docs added. listen to theme song from m.a.s.k. cartoon when merging this. oh also pb.c is now obsolete. well it was before, but even more now. --- epicardium/epicardium.h | 17 ++++---- epicardium/modules/buttons.c | 29 +------------ pycardium/modules/buttons.c | 81 +++--------------------------------- pycardium/modules/qstrdefs.h | 13 +++--- 4 files changed, 18 insertions(+), 122 deletions(-) diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 54fd254ae..3d5eb7682 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -86,11 +86,6 @@ typedef _Bool bool; #define API_LIGHT_SENSOR_STOP 0x82 #define API_BUTTONS_READ 0x90 -#define API_BUTTONS_UPDATE 0x91 -#define API_BUTTONS_READ_BOTTOM_LEFT_FROMCACHE 0x92 -#define API_BUTTONS_READ_BOTTOM_RIGHT_FROMCACHE 0x93 -#define API_BUTTONS_READ_TOP_RIGHT_FROMCACHE 0x94 -#define API_BUTTONS_READ_RESET_FROMCACHE 0x95 /* clang-format on */ typedef uint32_t api_int_id_t; @@ -232,12 +227,14 @@ API_ISR(EPIC_INT_CTRL_C, epic_isr_ctrl_c); * */ +/** + * Reads buttons. Returns nonzero value if unmasked buttons are pushed. + * + * Always reads all buttons, use mask=15 for not wasting slow-ish API calls and extract values in pycardium. Note: The reset button cannot be unmapped from reset functionality afaik. + * + * :param uint8_t mask: The first 4 LSBs enable readout from corresponding button. The zeroeth bit corresponds to bottom left pin, increasing counterclockwise. If buttons module is imported in micropython also the designators BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT and RESET can be used with the latter two being identical. + */ API(API_BUTTONS_READ, uint8_t epic_buttons_read(uint8_t mask)); -API(API_BUTTONS_UPDATE, void epic_buttons_update(void)); -API(API_BUTTONS_READ_BOTTOM_LEFT_FROMCACHE, uint8_t epic_buttons_read_bottom_left_fromcache(void)); -API(API_BUTTONS_READ_BOTTOM_RIGHT_FROMCACHE, uint8_t epic_buttons_read_bottom_right_fromcache(void)); -API(API_BUTTONS_READ_TOP_RIGHT_FROMCACHE, uint8_t epic_buttons_read_top_right_fromcache(void)); -API(API_BUTTONS_READ_RESET_FROMCACHE, uint8_t epic_buttons_read_reset_fromcache(void)); /** * LEDs diff --git a/epicardium/modules/buttons.c b/epicardium/modules/buttons.c index 4b77b0b24..d5b740069 100644 --- a/epicardium/modules/buttons.c +++ b/epicardium/modules/buttons.c @@ -1,4 +1,3 @@ -//#include "pb.h" #include "portexpander.h" #include "MAX77650-Arduino-Library.h" #include <stdint.h> @@ -9,19 +8,8 @@ static const uint8_t ButtonPin[] = {BOTTOM_LEFT,BOTTOM_RIGHT,TOP_RIGHT}; static uint8_t button_states[4]; //as defined by button pin, 3->reset button -#if 0 -uint8_t epic_buttons_poll(uint8_t mask){ //legacy af - uint8_t button_status=0; - for(int i=0; i<4; i++){ - if((mask>>i)&1){ - button_status += PB_Get(i+1)<<i; - } - } - return button_status; -} -#endif -void epic_buttons_update(){ +static void epic_buttons_update(){ button_states[3] = MAX77650_getDebounceStatusnEN0(); if(portexpander_detected()){ uint8_t button_status = portexpander_get(); @@ -42,18 +30,3 @@ uint8_t epic_buttons_read(uint8_t mask){ return button_status; } -uint8_t epic_buttons_read_bottom_left_fromcache(){ - return button_states[0]; -} - -uint8_t epic_buttons_read_bottom_right_fromcache(){ - return button_states[1]; -} - -uint8_t epic_buttons_read_top_right_fromcache(){ - return button_states[2]; -} - -uint8_t epic_buttons_read_reset_fromcache(){ - return button_states[3]; -} diff --git a/pycardium/modules/buttons.c b/pycardium/modules/buttons.c index 7e11235ee..ad412d9fa 100644 --- a/pycardium/modules/buttons.c +++ b/pycardium/modules/buttons.c @@ -5,73 +5,6 @@ #include "epicardium.h" -static mp_obj_t mp_buttons_update() -{ - epic_buttons_update(); - return mp_const_none; -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_update_obj, mp_buttons_update); - -static mp_obj_t mp_buttons_read_bottom_left() -{ - epic_buttons_update(); - uint8_t retval = epic_buttons_read_bottom_left_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_bottom_left_obj, mp_buttons_read_bottom_left); - -static mp_obj_t mp_buttons_read_bottom_right() -{ - epic_buttons_update(); - uint8_t retval = epic_buttons_read_bottom_right_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_bottom_right_obj, mp_buttons_read_bottom_right); - -static mp_obj_t mp_buttons_read_top_right() -{ - epic_buttons_update(); - uint8_t retval = epic_buttons_read_top_right_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_top_right_obj, mp_buttons_read_top_right); - -static mp_obj_t mp_buttons_read_reset() -{ - epic_buttons_update(); - uint8_t retval = epic_buttons_read_reset_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_reset_obj, mp_buttons_read_reset); - -static mp_obj_t mp_buttons_read_bottom_left_fromcache() -{ - uint8_t retval = epic_buttons_read_bottom_left_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_bottom_left_fromcache_obj, mp_buttons_read_bottom_left_fromcache); - -static mp_obj_t mp_buttons_read_bottom_right_fromcache() -{ - uint8_t retval = epic_buttons_read_bottom_right_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_bottom_right_fromcache_obj, mp_buttons_read_bottom_right_fromcache); - -static mp_obj_t mp_buttons_read_top_right_fromcache() -{ - uint8_t retval = epic_buttons_read_top_right_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_top_right_fromcache_obj, mp_buttons_read_top_right_fromcache); - -static mp_obj_t mp_buttons_read_reset_fromcache() -{ - uint8_t retval = epic_buttons_read_reset_fromcache(); - return MP_OBJ_NEW_SMALL_INT(retval); -} -static MP_DEFINE_CONST_FUN_OBJ_0(buttons_read_reset_fromcache_obj, mp_buttons_read_reset_fromcache); - static mp_obj_t mp_buttons_read(mp_obj_t mask_in) { uint8_t mask = mp_obj_get_int(mask_in); @@ -83,15 +16,11 @@ static MP_DEFINE_CONST_FUN_OBJ_1(buttons_read_obj, mp_buttons_read); static const mp_rom_map_elem_t buttons_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_buttons) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&buttons_read_obj) }, - { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&buttons_update_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_bottom_left), MP_ROM_PTR(&buttons_read_bottom_left_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_bottom_right), MP_ROM_PTR(&buttons_read_bottom_right_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_top_right), MP_ROM_PTR(&buttons_read_top_right_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_reset), MP_ROM_PTR(&buttons_read_reset_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_bottom_left_fromcache), MP_ROM_PTR(&buttons_read_bottom_left_fromcache_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_bottom_right_fromcache), MP_ROM_PTR(&buttons_read_bottom_right_fromcache_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_top_right_fromcache), MP_ROM_PTR(&buttons_read_top_right_fromcache_obj) }, - { MP_ROM_QSTR(MP_QSTR_read_reset_fromcache), MP_ROM_PTR(&buttons_read_reset_fromcache_obj) }, + { MP_ROM_QSTR(MP_QSTR_BOTTOM_LEFT), MP_OBJ_NEW_SMALL_INT(0) }, + { MP_ROM_QSTR(MP_QSTR_BOTTOM_RIGHT), MP_OBJ_NEW_SMALL_INT(1) }, + { MP_ROM_QSTR(MP_QSTR_TOP_RIGHT), MP_OBJ_NEW_SMALL_INT(2) }, + { MP_ROM_QSTR(MP_QSTR_TOP_LEFT), MP_OBJ_NEW_SMALL_INT(3) }, + { MP_ROM_QSTR(MP_QSTR_RESET), MP_OBJ_NEW_SMALL_INT(3) }, }; static MP_DEFINE_CONST_DICT(buttons_module_globals, buttons_module_globals_table); diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index cf199510d..2affb9a0e 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -27,14 +27,11 @@ Q(TOP_RIGHT) /* buttons */ Q(buttons) Q(read) -Q(read_bottom_left) -Q(read_bottom_right) -Q(read_top_right) -Q(read_reset) -Q(read_bottom_left_fromcache) -Q(read_bottom_right_fromcache) -Q(read_top_right_fromcache) -Q(read_reset_fromcache) +Q(BOTTOM_LEFT) +Q(TOP_LEFT) +Q(BOTTOM_RIGHT) +Q(TOP_RIGHT) +Q(RESET) /* utime */ Q(utime) -- GitLab