Skip to content
Snippets Groups Projects
Select Git revision
  • c729efb4c7cc54fca17821edb38b82448dfd72a4
  • main default protected
  • blm_dev_chan
  • release/1.4.0 protected
  • widgets_draw
  • return_of_melodic_demo
  • task_cleanup
  • mixer2
  • dx/fb-save-restore
  • dx/dldldld
  • fpletz/flake
  • dx/jacksense-headset-mic-only
  • release/1.3.0 protected
  • fil3s-limit-filesize
  • allow-reloading-sunmenu
  • wifi-json-error-handling
  • app_text_viewer
  • shoegaze-fps
  • media_has_video_has_audio
  • fil3s-media
  • more-accurate-battery
  • v1.4.0
  • v1.3.0
  • v1.2.0
  • v1.2.0+rc1
  • v1.1.1
  • v1.1.0
  • v1.1.0+rc1
  • v1.0.0
  • v1.0.0+rc6
  • v1.0.0+rc5
  • v1.0.0+rc4
  • v1.0.0+rc3
  • v1.0.0+rc2
  • v1.0.0+rc1
35 results

__init__.py

Blame
  • interrupt.c 2.61 KiB
    #include "interrupt.h"
    
    #include "api/common.h"
    #include "epicardium.h"
    
    #include "py/builtin.h"
    #include "py/obj.h"
    #include "py/runtime.h"
    
    // TODO: these should be intialized as mp_const_none
    mp_obj_t callbacks[EPIC_INT_NUM] = {
    	0,
    };
    
    void epic_isr_default_handler(api_int_id_t id)
    {
    	// TODO: check if id is out of rante
    	// TOOD: check against mp_const_none
    	if (id < EPIC_INT_NUM) {
    		if (callbacks[id]) {
    			mp_sched_schedule(
    				callbacks[id], MP_OBJ_NEW_SMALL_INT(id)
    			);
    		}
    	}
    }
    
    mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj)
    {
    	api_int_id_t id = mp_obj_get_int(id_in);
    	if (callback_obj != mp_const_none &&
    	    !mp_obj_is_callable(callback_obj)) {
    		mp_raise_ValueError("handler must be None or callable");
    	}
    
    	// TODO: throw error if id is out of range
    	if (id < EPIC_INT_NUM) {
    		callbacks[id] = callback_obj;
    	}
    
    	return mp_const_none;
    }
    
    mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in)
    {
    	api_int_id_t id = mp_obj_get_int(id_in);
    
    	// TODO: throw error if id is out of range or epic_interrupt_enable failed
    	if (epic_interrupt_enable(id) < 0) {
    	}
    
    	return mp_const_none;
    }
    
    mp_obj_t mp_interrupt_disable_callback(mp_obj_t id_in)
    {
    	api_int_id_t id = mp_obj_get_int(id_in);
    
    	// TODO: throw error if id is out of range or epic_interrupt_enable failed
    	if (epic_interrupt_disable(id) < 0) {
    	}
    
    	return mp_const_none;
    }
    
    static MP_DEFINE_CONST_FUN_OBJ_2(
    	interrupt_set_callback_obj, mp_interrupt_set_callback
    );
    static MP_DEFINE_CONST_FUN_OBJ_1(
    	interrupt_enable_callback_obj, mp_interrupt_enable_callback
    );
    static MP_DEFINE_CONST_FUN_OBJ_1(
    	interrupt_disable_callback_obj, mp_interrupt_disable_callback
    );
    
    static const mp_rom_map_elem_t interrupt_module_globals_table[] = {
    	{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_interrupt) },
    	{ MP_ROM_QSTR(MP_QSTR_set_callback),
    	  MP_ROM_PTR(&interrupt_set_callback_obj) },
    	{ MP_ROM_QSTR(MP_QSTR_enable_callback),
    	  MP_ROM_PTR(&interrupt_enable_callback_obj) },
    	{ MP_ROM_QSTR(MP_QSTR_disable_callback),
    	  MP_ROM_PTR(&interrupt_disable_callback_obj) },
    
    	/* Interrupt Numbers */
    	{ MP_ROM_QSTR(MP_QSTR_BHI160),
    	  MP_OBJ_NEW_SMALL_INT(EPIC_INT_BHI160_TEST) },
    	{ MP_ROM_QSTR(MP_QSTR_RTC_ALARM),
    	  MP_OBJ_NEW_SMALL_INT(EPIC_INT_RTC_ALARM) },
    };
    static MP_DEFINE_CONST_DICT(
    	interrupt_module_globals, interrupt_module_globals_table
    );
    
    // Define module object.
    const mp_obj_module_t interrupt_module = {
    	.base    = { &mp_type_module },
    	.globals = (mp_obj_dict_t *)&interrupt_module_globals,
    };
    
    /* clang-format off */
    // Register the module to make it available in Python
    MP_REGISTER_MODULE(MP_QSTR_interrupt, interrupt_module, MODULE_INTERRUPT_ENABLED);