diff --git a/lispBM/c_libs/vesc_c_if.h b/lispBM/c_libs/vesc_c_if.h index 333ad15e..6e20a05a 100755 --- a/lispBM/c_libs/vesc_c_if.h +++ b/lispBM/c_libs/vesc_c_if.h @@ -582,6 +582,16 @@ typedef struct { bool (*read_nvm)(uint8_t *v, unsigned int len, unsigned int address); bool (*write_nvm)(uint8_t *v, unsigned int len, unsigned int address); bool (*wipe_nvm)(void); + + // FOC + float (*foc_get_id)(void); + float (*foc_get_iq)(void); + float (*foc_get_vd)(void); + float (*foc_get_vq)(void); + void (*foc_set_openloop_current)(float current, float rpm); + void (*foc_set_openloop_phase)(float current, float phase); + void (*foc_set_openloop_duty)(float dutyCycle, float rpm); + void (*foc_set_openloop_duty_phase)(float dutyCycle, float phase); } vesc_c_if; typedef struct { diff --git a/lispBM/lispif_c_lib.c b/lispBM/lispif_c_lib.c index 3641470d..c763ef56 100644 --- a/lispBM/lispif_c_lib.c +++ b/lispBM/lispif_c_lib.c @@ -42,6 +42,7 @@ #include "servo_dec.h" #include "servo_simple.h" #include "flash_helper.h" +#include "mcpwm_foc.h" // Function prototypes otherwise missing void packet_init(void (*s_func)(unsigned char *data, unsigned int len), @@ -806,11 +807,6 @@ lbm_value ext_load_native_lib(lbm_value *args, lbm_uint argn) { cif.cif.read_eeprom_var = conf_general_read_eeprom_var_custom; cif.cif.store_eeprom_var = conf_general_store_eeprom_var_custom; - // NVM - cif.cif.read_nvm = flash_helper_read_nvm; - cif.cif.write_nvm = flash_helper_write_nvm; - cif.cif.wipe_nvm = flash_helper_wipe_nvm; - // Timeout cif.cif.timeout_reset = timeout_reset; cif.cif.timeout_has_timeout = timeout_has_timeout; @@ -878,6 +874,21 @@ lbm_value ext_load_native_lib(lbm_value *args, lbm_uint argn) { cif.cif.get_ppm_age = lib_get_ppm_age; cif.cif.app_is_output_disabled = app_is_output_disabled; + // NVM + cif.cif.read_nvm = flash_helper_read_nvm; + cif.cif.write_nvm = flash_helper_write_nvm; + cif.cif.wipe_nvm = flash_helper_wipe_nvm; + + // FOC + cif.cif.foc_get_id = mcpwm_foc_get_id_filter; + cif.cif.foc_get_iq = mcpwm_foc_get_iq_filter; + cif.cif.foc_get_vd = mcpwm_foc_get_vd; + cif.cif.foc_get_vq = mcpwm_foc_get_vq; + cif.cif.foc_set_openloop_current = mcpwm_foc_set_openloop_current; + cif.cif.foc_set_openloop_phase = mcpwm_foc_set_openloop_phase; + cif.cif.foc_set_openloop_duty = mcpwm_foc_set_openloop_duty; + cif.cif.foc_set_openloop_duty_phase = mcpwm_foc_set_openloop_duty_phase; + lib_init_done = true; } diff --git a/lispBM/lispif_vesc_extensions.c b/lispBM/lispif_vesc_extensions.c index cecfef90..e083250c 100644 --- a/lispBM/lispif_vesc_extensions.c +++ b/lispBM/lispif_vesc_extensions.c @@ -957,7 +957,7 @@ static lbm_value ext_eeprom_store_i(lbm_value *args, lbm_uint argn) { } eeprom_var v; - v.as_i32 = lbm_dec_as_float(args[1]); + v.as_i32 = lbm_dec_as_i32(args[1]); return conf_general_store_eeprom_var_custom(&v, addr) ? ENC_SYM_TRUE : ENC_SYM_NIL; }