Skip to content
Snippets Groups Projects
Select Git revision
  • a1567d590c68c15f3d14b71f0b1b1c65481956e6
  • master default protected
  • blink_multi_rocket
  • blink_rocket
  • msgctl/gfx_rle
  • msgctl/faultscreen
  • msgctl/textbuffer_api
  • schneider/bonding
  • schneider/bootloader-update-9a0d158
  • schneider/bsec
  • rahix/bma
  • rahix/bhi
  • schleicher-test
  • schneider/schleicher-test
  • freertos-btle
  • ch3/api-speed-eval2
  • schneider/mp-for-old-bl
  • ch3/leds-api
  • ch3/genapi-refactor
  • ch3/dual-core
  • dualcore
  • v0.0
22 results

default.nix

Blame
  • Forked from card10 / firmware
    Source project has a limited visibility.
    • q3k's avatar
      4d8af366
      feat: Add a nix expression · 4d8af366
      q3k authored and rahix's avatar rahix committed
      We provide a nix expression to build card10 firmware.
      
      On Linux/Darwin with Nix and NixOS, this can be used as follows:
      
        $ git submodule update --init
        $ nix build
        $ ls result/
        result/bootloader:
        bootloader.elf
      
        result/epicardium:
        epicardium.elf
      
        result/pycardium:
        pycardium.elf  pycardium_epicardium.bin
      
      This derivation can also be used for development:
      
        $ nix-shell
        $ meson --cross-file card10-cross.ini build/
        $ ninja -C build/ -j8
        $ # hack on things
        $ ninja -C build/ -j 8
        $ ls build/
        [ ... ]
      Verified
      4d8af366
      History
      feat: Add a nix expression
      q3k authored and rahix's avatar rahix committed
      We provide a nix expression to build card10 firmware.
      
      On Linux/Darwin with Nix and NixOS, this can be used as follows:
      
        $ git submodule update --init
        $ nix build
        $ ls result/
        result/bootloader:
        bootloader.elf
      
        result/epicardium:
        epicardium.elf
      
        result/pycardium:
        pycardium.elf  pycardium_epicardium.bin
      
      This derivation can also be used for development:
      
        $ nix-shell
        $ meson --cross-file card10-cross.ini build/
        $ ninja -C build/ -j8
        $ # hack on things
        $ ninja -C build/ -j 8
        $ ls build/
        [ ... ]
    max30001-sys.c 2.17 KiB
    #include "py/obj.h"
    #include "py/runtime.h"
    #include "py/builtin.h"
    #include "epicardium.h"
    #include "api/common.h"
    #include "mphalport.h"
    
    STATIC mp_obj_t mp_max30001_enable_sensor(size_t n_args, const mp_obj_t *args)
    {
    	struct max30001_sensor_config cfg = { 0 };
    	cfg.usb                           = mp_obj_is_true(args[0]);
    	cfg.bias                          = mp_obj_is_true(args[1]);
    	cfg.sample_rate                   = mp_obj_get_int(args[2]);
    	cfg.sample_buffer_len             = mp_obj_get_int(args[3]);
    
    	int stream_id = epic_max30001_enable_sensor(&cfg);
    
    	return MP_OBJ_NEW_SMALL_INT(stream_id);
    }
    
    STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(
    	mp_max30001_enable_sensor_obj, 4, 4, mp_max30001_enable_sensor
    );
    
    STATIC mp_obj_t mp_max30001_read_sensor(mp_obj_t stream_id_in)
    {
    	int16_t buf[256];
    	int stream_id = mp_obj_get_int(stream_id_in);
    
    	int n = epic_stream_read(stream_id, buf, sizeof(buf));
    
    	mp_obj_list_t *list = mp_obj_new_list(0, NULL);
    	for (int i = 0; i < n; i++) {
    		mp_obj_list_append(list, mp_obj_new_int(buf[i]));
    	}
    
    	return MP_OBJ_FROM_PTR(list);
    }
    
    STATIC MP_DEFINE_CONST_FUN_OBJ_1(
    	mp_max30001_read_sensor_obj, mp_max30001_read_sensor
    );
    
    STATIC mp_obj_t mp_max30001_disable_sensor(void)
    {
    	int ret = epic_max30001_disable_sensor();
    
    	return MP_OBJ_NEW_SMALL_INT(ret);
    }
    
    STATIC MP_DEFINE_CONST_FUN_OBJ_0(
    	mp_max30001_disable_sensor_obj, mp_max30001_disable_sensor
    );
    
    STATIC const mp_rom_map_elem_t max30001_module_globals_table[] = {
    	{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys_max30001) },
    	{ MP_ROM_QSTR(MP_QSTR_enable_sensor),
    	  MP_ROM_PTR(&mp_max30001_enable_sensor_obj) },
    	{ MP_ROM_QSTR(MP_QSTR_read_sensor),
    	  MP_ROM_PTR(&mp_max30001_read_sensor_obj) },
    	{ MP_ROM_QSTR(MP_QSTR_disable_sensor),
    	  MP_ROM_PTR(&mp_max30001_disable_sensor_obj) },
    };
    STATIC MP_DEFINE_CONST_DICT(
    	max30001_module_globals, max30001_module_globals_table
    );
    
    // Define module object.
    const mp_obj_module_t max30001_module = {
    	.base    = { &mp_type_module },
    	.globals = (mp_obj_dict_t *)&max30001_module_globals,
    };
    
    /* clang-format off */
    // Register the module to make it available in Python
    MP_REGISTER_MODULE(MP_QSTR_sys_max30001, max30001_module, MODULE_MAX30001_ENABLED);