Skip to content
Snippets Groups Projects
Commit a7083229 authored by fleur's avatar fleur
Browse files

minor performance optimisation and code style stuff

parent 1fc10c8f
Branches
No related tags found
No related merge requests found
......@@ -5,28 +5,30 @@
#define BOTTOM_RIGHT 3
#define TOP_RIGHT 6
static const uint8_t ButtonPin[] = {BOTTOM_LEFT,BOTTOM_RIGHT,TOP_RIGHT};
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
static void epic_buttons_update(){
button_states[3] = MAX77650_getDebounceStatusnEN0();
if(portexpander_detected()){
static void epic_buttons_update(uint8_t mask)
{
if (mask > 7) {
button_states[3] = MAX77650_getDebounceStatusnEN0();
}
if (portexpander_detected() && (mask % 8)) {
uint8_t button_status = portexpander_get();
for(int i=0; i<3; i++){
for (int i = 0; i < 3; i++) {
button_states[i] = (button_status >> ButtonPin[i]) & 1;
}
}
}
uint8_t epic_buttons_read(uint8_t mask){
epic_buttons_update();
uint8_t button_status=0;
for(int i=0; i<4; i++){
if((mask>>i)&1){
button_status += button_states[i]<<i;
uint8_t epic_buttons_read(uint8_t mask)
{
epic_buttons_update(mask);
uint8_t button_status = 0;
for (int i = 0; i < 4; i++) {
if ((mask >> i) & 1) {
button_status += button_states[i] << i;
}
}
return button_status;
}
......@@ -7,7 +7,7 @@
static mp_obj_t mp_buttons_read(mp_obj_t mask_in)
{
uint8_t mask = mp_obj_get_int(mask_in);
uint8_t mask = mp_obj_get_int(mask_in);
uint8_t button_states = epic_buttons_read(mask);
return MP_OBJ_NEW_SMALL_INT(button_states);
}
......@@ -22,10 +22,12 @@ static const mp_rom_map_elem_t buttons_module_globals_table[] = {
{ 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);
static MP_DEFINE_CONST_DICT(
buttons_module_globals, buttons_module_globals_table
);
const mp_obj_module_t buttons_module = {
.base = { &mp_type_module },
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&buttons_module_globals,
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment