Skip to content

Commit

Permalink
Merge commit '3bb6db222eafe13be2b73054421bec22d7357011'
Browse files Browse the repository at this point in the history
  • Loading branch information
lukash committed Aug 27, 2024
2 parents 851431a + 3bb6db2 commit 7777d33
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 11 deletions.
2 changes: 1 addition & 1 deletion vesc_pkg_lib/examples/ssd1306/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static lbm_value ssd_drawline(lbm_value *args, lbm_uint argn) {
return res;
}

uint8_t *pixbuf = (uint8_t*)(((lbm_array_header_t *)VESC_IF->lbm_car(args[0]))->data);
uint8_t *pixbuf = (uint8_t*)VESC_IF->lbm_dec_str(args[0]);
int x0 = VESC_IF->lbm_dec_as_i32(args[1]);
int y0 = VESC_IF->lbm_dec_as_i32(args[2]);
int x1 = VESC_IF->lbm_dec_as_i32(args[3]);
Expand Down
4 changes: 2 additions & 2 deletions vesc_pkg_lib/stdperiph_stm32f4/CMSIS/ST/stm32f405xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* This file contains:
* - Data structures and the address mapping for all peripherals
* - Peripheral's registers declarations and bits definition
* - Macros to access peripheral�s registers hardware
* - Macros to access peripherals registers hardware
*
******************************************************************************
* @attention
Expand Down Expand Up @@ -609,7 +609,7 @@ typedef struct
{
__IO uint32_t POWER; /*!< SDIO power control register, Address offset: 0x00 */
__IO uint32_t CLKCR; /*!< SDI clock control register, Address offset: 0x04 */
__IO uint32_t ARG; /*!< SDIO argument register, Address offset: 0x08 */
__IO uint32_t ARGR; /*!< SDIO argument register, Address offset: 0x08 */
__IO uint32_t CMD; /*!< SDIO command register, Address offset: 0x0C */
__I uint32_t RESPCMD; /*!< SDIO command response register, Address offset: 0x10 */
__I uint32_t RESP1; /*!< SDIO response 1 register, Address offset: 0x14 */
Expand Down
4 changes: 2 additions & 2 deletions vesc_pkg_lib/stdperiph_stm32f4/CMSIS/ST/stm32f407xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* This file contains:
* - Data structures and the address mapping for all peripherals
* - Peripheral's registers declarations and bits definition
* - Macros to access peripheral�s registers hardware
* - Macros to access peripherals registers hardware
*
******************************************************************************
* @attention
Expand Down Expand Up @@ -704,7 +704,7 @@ typedef struct
{
__IO uint32_t POWER; /*!< SDIO power control register, Address offset: 0x00 */
__IO uint32_t CLKCR; /*!< SDI clock control register, Address offset: 0x04 */
__IO uint32_t ARG; /*!< SDIO argument register, Address offset: 0x08 */
__IO uint32_t ARGR; /*!< SDIO argument register, Address offset: 0x08 */
__IO uint32_t CMD; /*!< SDIO command register, Address offset: 0x0C */
__I uint32_t RESPCMD; /*!< SDIO command response register, Address offset: 0x10 */
__I uint32_t RESP1; /*!< SDIO response 1 register, Address offset: 0x14 */
Expand Down
80 changes: 74 additions & 6 deletions vesc_pkg_lib/vesc_c_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ typedef float lbm_float;

typedef struct {
uint8_t *buf;
size_t buf_size;
uint32_t buf_pos;
lbm_uint buf_size;
lbm_uint buf_pos;
} lbm_flat_value_t;

typedef struct {
Expand Down Expand Up @@ -207,6 +207,7 @@ typedef bool (*load_extension_fptr)(char*,extension_fptr);

typedef void* lib_thread;
typedef void* lib_mutex;
typedef void* lib_semaphore;

typedef enum {
VESC_PIN_COMM_RX = 0,
Expand All @@ -222,6 +223,8 @@ typedef enum {
VESC_PIN_HALL5,
VESC_PIN_HALL6,
VESC_PIN_PPM,
VESC_PIN_HW_1,
VESC_PIN_HW_2,
} VESC_PIN;

typedef enum {
Expand Down Expand Up @@ -275,6 +278,25 @@ typedef enum {
CFG_PARAM_IMU_rot_roll,
CFG_PARAM_IMU_rot_pitch,
CFG_PARAM_IMU_rot_yaw,
CFG_PARAM_IMU_ahrs_mode,
CFG_PARAM_IMU_sample_rate,
CFG_PARAM_IMU_accel_offset_x,
CFG_PARAM_IMU_accel_offset_y,
CFG_PARAM_IMU_accel_offset_z,
CFG_PARAM_IMU_gyro_offset_x,
CFG_PARAM_IMU_gyro_offset_y,
CFG_PARAM_IMU_gyro_offset_z,

CFG_PARAM_app_shutdown_mode,

// Motor Additional Info
CFG_PARAM_si_motor_poles,
CFG_PARAM_si_gear_ratio,
CFG_PARAM_si_wheel_diameter,
CFG_PARAM_si_battery_type,
CFG_PARAM_si_battery_cells,
CFG_PARAM_si_battery_ah,
CFG_PARAM_si_motor_nl_current,
} CFG_PARAM;

typedef struct {
Expand All @@ -288,7 +310,10 @@ typedef struct {

/*
* Function pointer struct. Always add new function pointers to the end in order to not
* break compatibility with old binaries.
* break compatibility with old binaries. If a function is not available (e.g. in an
* old firmware) it will be a null-pointer. If you make a package that is meant to
* run on older firmware too you can check if the newer functions are null pointers to
* know if they are available.
*/
typedef struct {
// LBM
Expand All @@ -313,7 +338,7 @@ typedef struct {

lbm_value (*lbm_enc_i)(lbm_int x);
lbm_value (*lbm_enc_u)(lbm_uint x);
lbm_value (*lbm_enc_char)(char x);
lbm_value (*lbm_enc_char)(uint8_t x);
lbm_value (*lbm_enc_float)(float f);
lbm_value (*lbm_enc_u32)(uint32_t u);
lbm_value (*lbm_enc_i32)(int32_t i);
Expand All @@ -322,7 +347,7 @@ typedef struct {
float (*lbm_dec_as_float)(lbm_value val);
uint32_t (*lbm_dec_as_u32)(lbm_value val);
int32_t (*lbm_dec_as_i32)(lbm_value val);
char (*lbm_dec_char)(lbm_value x);
uint8_t (*lbm_dec_char)(lbm_value x);
char* (*lbm_dec_str)(lbm_value);
lbm_uint (*lbm_dec_sym)(lbm_value x);

Expand Down Expand Up @@ -533,7 +558,7 @@ typedef struct {
volatile gnss_data* (*mc_gnss)(void);

// Mutex
lib_mutex (*mutex_create)(void);
lib_mutex (*mutex_create)(void); // Use VESC_IF->free on the mutex when done with it
void (*mutex_lock)(lib_mutex);
void (*mutex_unlock)(lib_mutex);

Expand Down Expand Up @@ -592,6 +617,46 @@ typedef struct {
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);

// Functions below were added in firmware 6.05

// Flat values
bool (*lbm_start_flatten)(lbm_flat_value_t *v, size_t buffer_size);
bool (*lbm_finish_flatten)(lbm_flat_value_t *v);
bool (*f_cons)(lbm_flat_value_t *v);
bool (*f_sym)(lbm_flat_value_t *v, lbm_uint sym);
bool (*f_i)(lbm_flat_value_t *v, lbm_int i);
bool (*f_b)(lbm_flat_value_t *v, uint8_t b);
bool (*f_i32)(lbm_flat_value_t *v, int32_t w);
bool (*f_u32)(lbm_flat_value_t *v, uint32_t w);
bool (*f_float)(lbm_flat_value_t *v, float f);
bool (*f_i64)(lbm_flat_value_t *v, int64_t w);
bool (*f_u64)(lbm_flat_value_t *v, uint64_t w);
bool (*f_lbm_array)(lbm_flat_value_t *v, uint32_t num_elts, uint8_t *data);

// Unblock unboxed
bool (*lbm_unblock_ctx_unboxed)(lbm_cid cid, lbm_value unboxed);

// Time since boot in system ticks. Resolution: 100 uS.
// Use ts_to_age_s to get the age of a timestamp in
// seconds. ts_to_age_s should handle overflows.
systime_t (*system_time_ticks)(void);
void (*sleep_ticks)(systime_t ticks);

// FOC Audio
bool (*foc_beep)(float freq, float time, float voltage);
bool (*foc_play_tone)(int channel, float freq, float voltage);
void (*foc_stop_audio)(bool reset);
bool (*foc_set_audio_sample_table)(int channel, float *samples, int len);
const float* (*foc_get_audio_sample_table)(int channel);
bool (*foc_play_audio_samples)(const int8_t *samples, int num_samp, float f_samp, float voltage);

// Semaphore
lib_semaphore (*sem_create)(void); // Use VESC_IF->free on the semaphore when done with it
void (*sem_wait)(lib_semaphore);
void (*sem_signal)(lib_semaphore);
bool (*sem_wait_to)(lib_semaphore, systime_t); // Returns false on timeout
void (*sem_reset)(lib_semaphore);
} vesc_c_if;

typedef struct {
Expand All @@ -600,6 +665,9 @@ typedef struct {
uint32_t base_addr;
} lib_info;

// System tick rate. Can be used to convert system ticks to time
#define SYSTEM_TICK_RATE_HZ 10000

// VESC-interface with function pointers
#define VESC_IF ((vesc_c_if*)(0x1000F800))

Expand Down

0 comments on commit 7777d33

Please sign in to comment.