Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
Loading items

Target

Select target project
  • flow3r/flow3r-firmware
  • Vespasian/flow3r-firmware
  • alxndr42/flow3r-firmware
  • pl/flow3r-firmware
  • Kari/flow3r-firmware
  • raimue/flow3r-firmware
  • grandchild/flow3r-firmware
  • mu5tach3/flow3r-firmware
  • Nervengift/flow3r-firmware
  • arachnist/flow3r-firmware
  • TheNewCivilian/flow3r-firmware
  • alibi/flow3r-firmware
  • manuel_v/flow3r-firmware
  • xeniter/flow3r-firmware
  • maxbachmann/flow3r-firmware
  • yGifoom/flow3r-firmware
  • istobic/flow3r-firmware
  • EiNSTeiN_/flow3r-firmware
  • gnudalf/flow3r-firmware
  • 999eagle/flow3r-firmware
  • toerb/flow3r-firmware
  • pandark/flow3r-firmware
  • teal/flow3r-firmware
  • x42/flow3r-firmware
  • alufers/flow3r-firmware
  • dos/flow3r-firmware
  • yrlf/flow3r-firmware
  • LuKaRo/flow3r-firmware
  • ThomasElRubio/flow3r-firmware
  • ai/flow3r-firmware
  • T_X/flow3r-firmware
  • highTower/flow3r-firmware
  • beanieboi/flow3r-firmware
  • Woazboat/flow3r-firmware
  • gooniesbro/flow3r-firmware
  • marvino/flow3r-firmware
  • kressnerd/flow3r-firmware
  • quazgar/flow3r-firmware
  • aoid/flow3r-firmware
  • jkj/flow3r-firmware
  • naomi/flow3r-firmware
41 results
Select Git revision
Loading items
Show changes
Showing
with 15248 additions and 0 deletions
#include "osc_fm.h"
radspa_descriptor_t osc_fm_desc = {
.name = "osc_fm",
.id = 4202,
.description = "[DEPRECATED, replacement: osc] simple audio band oscillator with classic waveforms and linear fm input",
.create_plugin_instance = osc_fm_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
#define OSC_FM_NUM_SIGNALS 6
#define OSC_FM_OUTPUT 0
#define OSC_FM_PITCH 1
#define OSC_FM_WAVEFORM 2
#define OSC_FM_LIN_FM 3
#define OSC_FM_PITCH_THRU 4
#define OSC_FM_PITCH_OFFSET 5
radspa_t * osc_fm_create(uint32_t init_var){
radspa_t * osc_fm = radspa_standard_plugin_create(&osc_fm_desc, OSC_FM_NUM_SIGNALS, sizeof(osc_fm_data_t), 0);
osc_fm->render = osc_fm_run;
radspa_signal_set(osc_fm, OSC_FM_OUTPUT, "output", RADSPA_SIGNAL_HINT_OUTPUT, 0);
radspa_signal_set(osc_fm, OSC_FM_PITCH, "pitch", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_SCT, RADSPA_SIGNAL_VAL_SCT_A440);
radspa_signal_set(osc_fm, OSC_FM_WAVEFORM, "waveform", RADSPA_SIGNAL_HINT_INPUT, -16000);
radspa_signal_set(osc_fm, OSC_FM_LIN_FM, "lin_fm", RADSPA_SIGNAL_HINT_INPUT, 0);
radspa_signal_set(osc_fm, OSC_FM_PITCH_THRU, "fm_pitch_thru", RADSPA_SIGNAL_HINT_OUTPUT | RADSPA_SIGNAL_HINT_SCT, RADSPA_SIGNAL_VAL_SCT_A440);
radspa_signal_set(osc_fm, OSC_FM_PITCH_OFFSET, "fm_pitch_offset", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_SCT, RADSPA_SIGNAL_VAL_SCT_A440);
osc_fm_data_t * data = osc_fm->plugin_data;
data->output_sig = radspa_signal_get_by_index(osc_fm, OSC_FM_OUTPUT);
data->pitch_sig = radspa_signal_get_by_index(osc_fm, OSC_FM_PITCH);
data->waveform_sig = radspa_signal_get_by_index(osc_fm, OSC_FM_WAVEFORM);
data->lin_fm_sig = radspa_signal_get_by_index(osc_fm, OSC_FM_LIN_FM);
data->fm_pitch_thru_sig = radspa_signal_get_by_index(osc_fm, OSC_FM_PITCH_THRU);
data->fm_pitch_offset_sig = radspa_signal_get_by_index(osc_fm, OSC_FM_PITCH_OFFSET);
data->waveform_sig->unit = "{SINE:-32767} {TRI:-10922} {SQUARE:10922} {SAW:32767}";
return osc_fm;
}
static inline int16_t triangle(int32_t saw){
saw -= 16384;
if(saw < -32767) saw += 65535;
if(saw > 0) saw = -saw;
return saw * 2 + 32767;
}
static inline int16_t waveshaper(int32_t saw, int16_t shape){
int32_t tmp = saw;
uint8_t sh = ((uint16_t) shape) >> 14;
sh = (sh + 2)%4;
switch(sh){
case 0: //sine
tmp = triangle(tmp);
if(tmp > 0){
tmp = 32767 - tmp;
tmp = (tmp*tmp)>>15;
tmp = 32767 - tmp;
} else {
tmp = 32767 + tmp;
tmp = (tmp*tmp)>>15;
tmp = tmp - 32767;
}
break;
case 1: //tri
tmp = triangle(tmp);
break;
case 2: //square:
if(tmp > 0){
tmp = 32767;
} else {
tmp = -32767;
}
break;
default: //saw
break;
}
return tmp;
}
void osc_fm_run(radspa_t * osc_fm, uint16_t num_samples, uint32_t render_pass_id){
osc_fm_data_t * data = osc_fm->plugin_data;
int16_t pitch_const = radspa_signal_get_const_value(data->pitch_sig, render_pass_id);
int16_t fm_pitch_offset_const = radspa_signal_get_const_value(data->fm_pitch_offset_sig, render_pass_id);
int16_t wave_const = radspa_signal_get_const_value(data->waveform_sig, render_pass_id);
int16_t lin_fm_const = radspa_signal_get_const_value(data->lin_fm_sig, render_pass_id);
int16_t pitch = pitch_const;
int32_t fm_pitch_offset = fm_pitch_offset_const;
int16_t wave = wave_const;
int32_t lin_fm = lin_fm_const;
if(pitch_const != -32768){
if(pitch != data->prev_pitch){
data->incr = radspa_sct_to_rel_freq(pitch, 0);
data->prev_pitch = pitch;
}
}
bool fm_thru_const = (pitch_const != -32768) && (fm_pitch_offset_const != -32768);
if(fm_thru_const) radspa_signal_set_const_value(data->fm_pitch_thru_sig, pitch_const + fm_pitch_offset_const - RADSPA_SIGNAL_VAL_SCT_A440);
for(uint16_t i = 0; i < num_samples; i++){
if(pitch_const == -32768){
pitch = radspa_signal_get_value(data->pitch_sig, i, render_pass_id);
if(pitch != data->prev_pitch){
data->incr = radspa_sct_to_rel_freq(pitch, 0);
data->prev_pitch = pitch;
}
}
if(wave_const == -32768) wave = radspa_signal_get_value(data->waveform_sig, i, render_pass_id);
if(lin_fm_const == -32768) lin_fm = radspa_signal_get_value(data->lin_fm_sig, i, render_pass_id);
data->counter += data->incr;
if(lin_fm){
data->counter += lin_fm * (data->incr >> 15);
}
int32_t tmp = (data->counter) >> 16;
tmp = tmp - 32767;
tmp = waveshaper(tmp, wave);
radspa_signal_set_value(data->output_sig, i, tmp);
if(fm_pitch_offset_const == -32768) fm_pitch_offset = radspa_signal_get_value(data->fm_pitch_offset_sig, i, render_pass_id);
if(!fm_thru_const) radspa_signal_set_value(data->fm_pitch_thru_sig, i, pitch + fm_pitch_offset - RADSPA_SIGNAL_VAL_SCT_A440);
}
}
#pragma once
#include "radspa.h"
#include "radspa_helpers.h"
typedef struct {
uint32_t counter;
int16_t prev_pitch;
int32_t incr;
radspa_signal_t * output_sig;
radspa_signal_t * pitch_sig;
radspa_signal_t * waveform_sig;
radspa_signal_t * lin_fm_sig;
radspa_signal_t * fm_pitch_thru_sig;
radspa_signal_t * fm_pitch_offset_sig;
} osc_fm_data_t;
extern radspa_descriptor_t osc_fm_desc;
radspa_t * osc_fm_create(uint32_t init_var);
void osc_fm_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
#include "poly_squeeze.h"
radspa_descriptor_t poly_squeeze_desc = {
.name = "poly_squeeze",
.id = 172,
.description = "Multiplexes a number of trigger and pitch inputs into a lesser number of trigger pitch output pairs. "
"The latest triggered inputs are forwarded to the output. If such an input receives a stop trigger it is disconnected "
"from its output. If another inputs is in triggered state but not forwarded at the same time it will be connected to that "
"output and the output is triggered. Pitch is constantly streamed to the outputs if they are connected, else the last "
"connected value is being held."
"\ninit_var: lsb: number of outputs, 1..16, default 3; lsb+1: number of inputs, <lsb>..32, default 10; ",
.create_plugin_instance = poly_squeeze_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
#define NUM_MPX 2
// mpx block 1
#define TRIGGER_INPUT 0
#define PITCH_INPUT 1
// mpx block 2
#define TRIGGER_OUTPUT 0
#define PITCH_OUTPUT 1
static void assign_note_voices(poly_squeeze_data_t * data){
poly_squeeze_note_t * note = data->active_notes_top;
if(note == NULL) return;
uint32_t active_voices = 0xFFFFFFFFUL << data->num_voices;
for(uint8_t i = 0; i < data->num_voices; i++){
if(note == NULL) break;
if(note->voice >= 0) active_voices = active_voices | (1UL<<note->voice);
note = note->lower;
}
while(note != NULL){
note->voice = -1;
note = note->lower;
}
if(active_voices == UINT32_MAX) return;
note = data->active_notes_top;
for(uint8_t i = 0; i < data->num_voices; i++){
if(note == NULL) break;
if(note->voice < 0){
int8_t voice = -1;
for(int8_t v = 0; v < data->num_voices; v++){
if((~active_voices) & (1<<v)){
active_voices = active_voices | (1<<v);
voice = v;
break;
}
}
note->voice = voice;
}
note = note->lower;
}
}
static poly_squeeze_note_t * get_note_with_voice(poly_squeeze_data_t * data, int8_t voice){
poly_squeeze_note_t * note = data->active_notes_top;
for(uint8_t i = 0; i < data->num_voices; i++){
if(note == NULL) break;
if(note->voice == voice) return note;
note = note->lower;
}
return NULL;
}
void take_note(poly_squeeze_data_t * data, poly_squeeze_note_t * note){
if(note == NULL) return;
if(data->free_notes == note) data->free_notes = note->lower;
if(data->active_notes_bottom == note) data->active_notes_bottom = note->higher;
if(data->active_notes_top == note) data->active_notes_top = note->lower;
if(note->higher != NULL) note->higher->lower = note->lower;
if(note->lower != NULL) note->lower->higher = note->higher;
note->higher = NULL;
note->lower = NULL;
}
static int8_t put_note_on_top(poly_squeeze_data_t * data, poly_squeeze_note_t * note){
if(note == NULL) return -1;
if(note == data->active_notes_top) return note->voice;
take_note(data, note);
note->lower = data->active_notes_top;
if(note->lower != NULL) note->lower->higher = note;
data->active_notes_top = note;
if(note->lower == NULL) data->active_notes_bottom = note;
assign_note_voices(data);
return note->voice;
}
static int8_t free_note(poly_squeeze_data_t * data, poly_squeeze_note_t * note){
if(note == NULL) return -1;
take_note(data, note);
int8_t ret = note->voice;
note->voice = -1;
note->lower = data->free_notes;
if(note->lower != NULL) note->lower->higher = note;
data->free_notes = note;
assign_note_voices(data);
return ret;
}
static void voice_start(poly_squeeze_voice_t * voice, int16_t pitch, int16_t vol){
voice->pitch_out = pitch;
int16_t tmp = voice->_start_trigger;
radspa_trigger_start(vol, &tmp);
voice->trigger_out = tmp;
}
static void voice_stop(poly_squeeze_voice_t * voice){
int16_t tmp = voice->_start_trigger;
radspa_trigger_stop(&tmp);
voice->trigger_out = tmp;
}
void poly_squeeze_run(radspa_t * poly_squeeze, uint16_t num_samples, uint32_t render_pass_id){
poly_squeeze_data_t * data = poly_squeeze->plugin_data;
poly_squeeze_note_t * notes = (void *) (&(data[1]));
poly_squeeze_input_t * inputs = (void *) (&(notes[data->num_notes]));
poly_squeeze_voice_t * voices = (void *) (&(inputs[data->num_inputs]));
for(uint8_t j = 0; j < data->num_inputs; j++){
uint16_t pitch_index;
int16_t trigger_in = radspa_trigger_get_const(&poly_squeeze->signals[TRIGGER_INPUT + NUM_MPX*j],
&inputs[j].trigger_in_hist, &pitch_index, num_samples, render_pass_id);
notes[j].pitch = radspa_signal_get_value(&poly_squeeze->signals[PITCH_INPUT + NUM_MPX*j], pitch_index, render_pass_id);
// should order events by pitch index some day maybe
if(trigger_in > 0){
notes[j].vol = trigger_in;
int8_t voice = put_note_on_top(data, &(notes[j]));
if(voice >= 0) voice_start(&(voices[voice]), notes[j].pitch, notes[j].vol);
} else if(trigger_in < 0){
int8_t voice = free_note(data, &(notes[j]));
if(voice >= 0){
poly_squeeze_note_t * note = get_note_with_voice(data, voice);
if(note == NULL){
voice_stop(&(voices[voice]));
} else {
voice_start(&(voices[voice]), note->pitch, note->vol);
}
}
}
}
for(uint8_t j = 0; j < data->num_inputs; j++){
if((notes[j].voice != -1) && (notes[j].voice < data->num_voices)){
voices[notes[j].voice].pitch_out = notes[j].pitch;
}
}
for(uint8_t j = 0; j < data->num_voices; j++){
uint8_t k = data->num_inputs + j;
radspa_signal_set_const_value(&poly_squeeze->signals[TRIGGER_OUTPUT + NUM_MPX * k], voices[j].trigger_out);
radspa_signal_set_const_value(&poly_squeeze->signals[PITCH_OUTPUT + NUM_MPX * k], voices[j].pitch_out);
voices[j]._start_trigger = voices[j].trigger_out;
}
}
radspa_t * poly_squeeze_create(uint32_t init_var){
if(!init_var) init_var = 3 + (1UL<<8) + 9 * (1UL<<16);
uint8_t num_voices = init_var & 0xFF;
if(num_voices > 32) num_voices = 32;
if(num_voices < 1) num_voices = 1;
init_var = init_var >> 8;
uint8_t num_inputs = init_var & 0xFF;
if(num_inputs > 32) num_inputs = 32;
if(num_inputs < num_voices) num_inputs = num_voices;
uint8_t num_notes = num_inputs;
uint32_t num_signals = num_voices * NUM_MPX + num_inputs * NUM_MPX;
size_t data_size = sizeof(poly_squeeze_data_t);
data_size += sizeof(poly_squeeze_voice_t) * num_voices;
data_size += sizeof(poly_squeeze_note_t) * num_notes;
data_size += sizeof(poly_squeeze_input_t) * num_inputs;
radspa_t * poly_squeeze = radspa_standard_plugin_create(&poly_squeeze_desc, num_signals, data_size, 0);
if(poly_squeeze == NULL) return NULL;
poly_squeeze->render = poly_squeeze_run;
radspa_signal_set_group(poly_squeeze, num_inputs, NUM_MPX, TRIGGER_INPUT, "trigger_in",
RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
radspa_signal_set_group(poly_squeeze, num_inputs, NUM_MPX, PITCH_INPUT, "pitch_in",
RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_SCT, RADSPA_SIGNAL_VAL_SCT_A440);
radspa_signal_set_group(poly_squeeze, num_voices, NUM_MPX, TRIGGER_OUTPUT + NUM_MPX*num_inputs, "trigger_out",
RADSPA_SIGNAL_HINT_OUTPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
radspa_signal_set_group(poly_squeeze, num_voices, NUM_MPX, PITCH_OUTPUT + NUM_MPX*num_inputs, "pitch_out",
RADSPA_SIGNAL_HINT_OUTPUT | RADSPA_SIGNAL_HINT_SCT, RADSPA_SIGNAL_VAL_SCT_A440);
poly_squeeze_data_t * data = poly_squeeze->plugin_data;
data->num_voices = num_voices;
data->num_notes = num_notes;
data->num_inputs = num_inputs;
poly_squeeze_note_t * notes = (void *) (&(data[1]));
poly_squeeze_input_t * inputs = (void *) (&(notes[data->num_notes]));
poly_squeeze_voice_t * voices = (void *) (&(inputs[data->num_inputs]));
data->active_notes_top = NULL;
data->active_notes_bottom = NULL;
data->free_notes = &(notes[0]);
for(uint8_t i = 0; i < num_voices; i++){
voices[i].trigger_out = 0;
voices[i].pitch_out = RADSPA_SIGNAL_VAL_SCT_A440;
voices[i]._start_trigger = voices[i].trigger_out;
}
for(uint8_t i = 0; i < num_notes; i++){
notes[i].pitch = -32768;
notes[i].voice = -1;
if(i){
notes[i].higher = &(notes[i-1]);
} else{
notes[i].higher = NULL;
}
if(i != (num_notes - 1)){
notes[i].lower = &(notes[i+1]);
} else {
notes[i].lower = NULL;
}
}
for(uint8_t i = 0; i < num_inputs; i++){
inputs[i].trigger_in_hist = 0;
}
return poly_squeeze;
}
#pragma once
#include "radspa.h"
#include "radspa_helpers.h"
typedef struct _poly_squeeze_note_t {
int16_t pitch;
int16_t vol;
int8_t voice;
struct _poly_squeeze_note_t * lower;
struct _poly_squeeze_note_t * higher;
} poly_squeeze_note_t;
typedef struct {
int16_t trigger_out;
int16_t pitch_out;
int16_t _start_trigger;
} poly_squeeze_voice_t;
typedef struct {
int16_t trigger_in_hist;
} poly_squeeze_input_t;
typedef struct {
uint8_t num_voices;
uint8_t num_notes;
uint8_t num_inputs;
poly_squeeze_note_t * active_notes_top;
poly_squeeze_note_t * active_notes_bottom;
poly_squeeze_note_t * free_notes;
} poly_squeeze_data_t;
extern radspa_descriptor_t poly_squeeze_desc;
radspa_t * poly_squeeze_create(uint32_t init_var);
void poly_squeeze_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
#include "range_shifter.h"
radspa_t * range_shifter_create(uint32_t init_var);
radspa_descriptor_t range_shifter_desc = {
.name = "range_shifter",
.id = 69,
.description = "saturating multiplication and addition",
.create_plugin_instance = range_shifter_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
#define RANGE_SHIFTER_NUM_SIGNALS 7
#define RANGE_SHIFTER_OUTPUT 0
#define RANGE_SHIFTER_OUTPUT_A 1
#define RANGE_SHIFTER_OUTPUT_B 2
#define RANGE_SHIFTER_INPUT 3
#define RANGE_SHIFTER_INPUT_A 4
#define RANGE_SHIFTER_INPUT_B 5
#define RANGE_SHIFTER_SPEED 6
#define GET_GAIN { \
output_a = radspa_signal_get_value(output_a_sig, k, render_pass_id); \
output_b = radspa_signal_get_value(output_b_sig, k, render_pass_id); \
input_a = radspa_signal_get_value(input_a_sig, k, render_pass_id); \
input_b = radspa_signal_get_value(input_b_sig, k, render_pass_id); \
output_span = output_b - output_a; \
input_span = input_b - input_a; \
gain = (output_span << 14) / input_span; \
}
#define APPLY_GAIN { \
if(ret == input_a){ \
ret = output_a; \
} else if(ret == input_b){ \
ret = output_b; \
} else { \
ret -= input_a; \
ret = (ret * gain) >> 14; \
ret += output_a; \
} \
}
void range_shifter_run(radspa_t * range_shifter, uint16_t num_samples, uint32_t render_pass_id){
radspa_signal_t * output_sig = radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_OUTPUT);
radspa_signal_t * output_a_sig = radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_OUTPUT_A);
radspa_signal_t * output_b_sig = radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_OUTPUT_B);
radspa_signal_t * input_sig = radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_INPUT);
radspa_signal_t * input_a_sig = radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_INPUT_A);
radspa_signal_t * input_b_sig = radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_INPUT_B);
radspa_signal_t * speed_sig = radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_SPEED);
int16_t speed = radspa_signal_get_value(speed_sig, 0, render_pass_id);
int32_t output_a = radspa_signal_get_const_value(output_a_sig, render_pass_id);
int32_t output_b = radspa_signal_get_const_value(output_b_sig, render_pass_id);
int32_t input_a = radspa_signal_get_const_value(input_a_sig, render_pass_id);
int32_t input_b = radspa_signal_get_const_value(input_b_sig, render_pass_id);
int32_t input = radspa_signal_get_const_value(input_sig, render_pass_id);
bool range_const = true;
if(speed >= 10922){
range_const = range_const && (output_a != RADSPA_SIGNAL_NONCONST) && (output_b != RADSPA_SIGNAL_NONCONST);
range_const = range_const && (input_a != RADSPA_SIGNAL_NONCONST) && (input_b != RADSPA_SIGNAL_NONCONST);
}
bool input_const = true;
if(speed > -10922){
input_const = input != RADSPA_SIGNAL_NONCONST;
}
int32_t output_span;
int32_t input_span;
int32_t gain;
if(range_const){
uint16_t k = 0;
GET_GAIN
if(!output_span){
radspa_signal_set_const_value(output_sig, output_a);
} else if(!input_span){
radspa_signal_set_const_value(output_sig, (output_b - output_a)>>1);
} else if(input_const){
int32_t ret = radspa_signal_get_value(input_sig, 0, render_pass_id);
APPLY_GAIN
radspa_signal_set_const_value(output_sig, ret);
} else {
for(uint16_t i = 0; i < num_samples; i++){
int32_t ret = radspa_signal_get_value(input_sig, i, render_pass_id);
APPLY_GAIN
radspa_signal_set_value(output_sig, i, ret);
}
}
} else {
for(uint16_t i = 0; i < num_samples; i++){
uint16_t k = i;
GET_GAIN
if(!output_span){
radspa_signal_set_value(output_sig, i, output_a);
} else if(!input_span){
radspa_signal_set_value(output_sig, i, (output_b - output_a)>>1);
} else {
int32_t ret = radspa_signal_get_value(input_sig, i, render_pass_id);
APPLY_GAIN
radspa_signal_set_value(output_sig, i, ret);
}
}
}
}
radspa_t * range_shifter_create(uint32_t init_var){
radspa_t * range_shifter = radspa_standard_plugin_create(&range_shifter_desc, RANGE_SHIFTER_NUM_SIGNALS, sizeof(char), 0);
if(range_shifter == NULL) return NULL;
range_shifter->render = range_shifter_run;
radspa_signal_set(range_shifter, RANGE_SHIFTER_OUTPUT, "output", RADSPA_SIGNAL_HINT_OUTPUT, 0);
radspa_signal_set_group(range_shifter, 2, 1, RANGE_SHIFTER_OUTPUT_A, "output_range", RADSPA_SIGNAL_HINT_INPUT, -32767);
radspa_signal_set(range_shifter, RANGE_SHIFTER_INPUT, "input", RADSPA_SIGNAL_HINT_INPUT, 0);
radspa_signal_set_group(range_shifter, 2, 1, RANGE_SHIFTER_INPUT_A, "input_range", RADSPA_SIGNAL_HINT_INPUT, -32767);
radspa_signal_set(range_shifter, RANGE_SHIFTER_SPEED, "speed", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_DEPRECATED, 32767);
radspa_signal_get_by_index(range_shifter, RANGE_SHIFTER_SPEED)->unit = "{SLOW:-32767} {SLOW_RANGE:0} {FAST:32767}";
range_shifter->signals[RANGE_SHIFTER_OUTPUT_B].value = 32767;
range_shifter->signals[RANGE_SHIFTER_INPUT_B].value = 32767;
return range_shifter;
}
#pragma once
#include <radspa.h>
#include <radspa_helpers.h>
extern radspa_descriptor_t range_shifter_desc;
radspa_t * range_shifter_create(uint32_t init_var);
void range_shifter_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
#include "sampler.h"
radspa_t * sampler_create(uint32_t init_var);
radspa_descriptor_t sampler_desc = {
.name = "sampler",
.id = 696969,
.description = "simple sampler that stores a copy of the sample in ram and has basic recording functionality."
"\ninit_var: length of pcm sample memory\ntable layout: [0:2] read head position (uint32_t), [2:4] write head position (uint32_t), "
"[4:6] sample start (uint32_t), [6:8] sample length (uint32_t), [8:10] sample rate (uint32_t), [10] sampler status "
"(int16_t bitmask), , [11:init_var+11] pcm sample data (int16_t)",
.create_plugin_instance = sampler_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
#define SAMPLER_NUM_SIGNALS 5
#define SAMPLER_OUTPUT 0
#define SAMPLER_TRIGGER 1
#define SAMPLER_PITCH_SHIFT 2
#define SAMPLER_REC_TRIGGER 3
#define SAMPLER_REC_IN 4
#define READ_HEAD_POS 0
#define WRITE_HEAD_POS 2
#define SAMPLE_START 4
#define SAMPLE_LEN 6
#define SAMPLE_RATE 8
#define STATUS 10
#define STATUS_PLAYBACK_ACTIVE 0
#define STATUS_PLAYBACK_LOOP 1
#define STATUS_RECORD_ACTIVE 2
#define STATUS_RECORD_OVERFLOW 3
#define STATUS_RECORD_NEW_EVENT 4
#define BUFFER_OFFSET 11
void sampler_run(radspa_t * sampler, uint16_t num_samples, uint32_t render_pass_id){
radspa_signal_t * output_sig = radspa_signal_get_by_index(sampler, SAMPLER_OUTPUT);
radspa_signal_t * trigger_sig = radspa_signal_get_by_index(sampler, SAMPLER_TRIGGER);
radspa_signal_t * rec_trigger_sig = radspa_signal_get_by_index(sampler, SAMPLER_REC_TRIGGER);
radspa_signal_t * rec_in_sig = radspa_signal_get_by_index(sampler, SAMPLER_REC_IN);
radspa_signal_t * pitch_shift_sig = radspa_signal_get_by_index(sampler, SAMPLER_PITCH_SHIFT);
sampler_data_t * data = sampler->plugin_data;
int16_t trigger = radspa_signal_get_const_value(trigger_sig, render_pass_id);
bool trigger_const = trigger != RADSPA_SIGNAL_NONCONST;
if(trigger_const) trigger = radspa_trigger_get(trigger, &(data->trigger_prev));
int16_t rec_trigger = radspa_signal_get_const_value(rec_trigger_sig, render_pass_id);
bool rec_trigger_const = rec_trigger != RADSPA_SIGNAL_NONCONST;
if(rec_trigger_const) rec_trigger = radspa_trigger_get(rec_trigger, &(data->rec_trigger_prev));
/*
if((!data->playback_active) && (!data->rec_active) && (trigger_const) && (rec_trigger_const) && (!rec_trigger) && (!trigger)){
radspa_signal_set_const_value(output_sig, 0);
return;
}
*/
int16_t * buf = sampler->plugin_table;
uint32_t * buf32 = (uint32_t *) buf;
uint32_t sample_len = buf32[SAMPLE_LEN/2];
uint32_t sample_start = buf32[SAMPLE_START/2];
uint32_t sample_rate = buf32[SAMPLE_RATE/2];
if(!sample_rate){
sample_rate = 1;
buf32[SAMPLE_RATE/2] = 1;
}
uint32_t buffer_size = sampler->plugin_table_len - BUFFER_OFFSET;
uint64_t buffer_size_long = buffer_size * 48000;
if(sample_len >= buffer_size) sample_len = buffer_size - 1;
if(sample_start >= buffer_size) sample_start = buffer_size - 1;
bool output_mute = !data->playback_active;
bool output_const = sample_rate < 100;
if(output_const){
sample_rate *= num_samples;
num_samples = 1;
}
int32_t ret = 0;
for(uint16_t i = 0; i < num_samples; i++){
if((!rec_trigger_const) || (!i)){
if(!rec_trigger_const) rec_trigger = radspa_trigger_get(radspa_signal_get_value(rec_trigger_sig, i, render_pass_id), &(data->rec_trigger_prev));
if(rec_trigger > 0){
data->rec_active = true;
data->write_head_pos_long = 0;
data->write_steps = 0;
data->write_head_pos_prev = -1;
data->write_overflow = false;
buf[STATUS] |= 1<<(STATUS_RECORD_NEW_EVENT);
} else if((rec_trigger < 0) && data->rec_active){
data->rec_active = false;
}
}
if(data->rec_active){
int16_t rec_in = radspa_signal_get_value(rec_in_sig, i, render_pass_id);
int32_t write_head_pos = (data->write_head_pos_long * 699) >> 25; // equiv to x/48000 (acc 0.008%)
if(data->write_head_pos_prev == write_head_pos){
if(data->write_steps){
data->rec_acc += rec_in;
} else {
data->rec_acc = buf[write_head_pos + BUFFER_OFFSET];
}
data->write_steps++;
} else {
if(data->write_steps) buf[data->write_head_pos_prev + BUFFER_OFFSET] = data->rec_acc/data->write_steps;
data->write_steps = 0;
if(write_head_pos > data->write_head_pos_prev){
for(uint32_t j = data->write_head_pos_prev + 1; j <= write_head_pos; j++){
buf[j + BUFFER_OFFSET] = rec_in;
}
} else {
uint32_t write_head_max = write_head_pos + buffer_size;
for(uint32_t j = data->write_head_pos_prev + 1; j <= write_head_max; j++){
uint32_t index = j;
if(index >= buffer_size) index -= buffer_size;
buf[index + BUFFER_OFFSET] = rec_in;
}
}
}
if(!data->write_overflow) data->write_overflow = write_head_pos < data->write_head_pos_prev;
data->write_head_pos_prev = write_head_pos;
if(data->write_overflow & (!(buf[STATUS] & (1<<(STATUS_RECORD_OVERFLOW))))){
data->rec_active = false;
} else {
if(data->write_overflow){
sample_start = (data->write_head_pos_long * 699) >> 25;
sample_len = buffer_size;
} else {
sample_start = 0;
sample_len = (data->write_head_pos_long * 699) >> 25;
}
data->write_head_pos_long += sample_rate;
while(data->write_head_pos_long >= buffer_size_long) data->write_head_pos_long -= buffer_size_long;
}
}
if((!trigger_const) || (!i)){
if(!trigger_const) trigger = radspa_trigger_get(radspa_signal_get_value(trigger_sig, i, render_pass_id), &(data->trigger_prev));
if(trigger > 0){
data->playback_active = true;
data->read_head_pos_long = 0;
data->playback_sample_start = sample_start;
data->volume = trigger;
if(output_mute){
radspa_signal_set_values(output_sig, 0, i, 0);
output_mute = false;
}
} else if(trigger < 0){
data->playback_active = false;
}
}
int32_t read_head_pos;
int8_t read_head_pos_subsample;
if(data->playback_active){
read_head_pos = (data->read_head_pos_long * 699) >> (25-6); // equiv to (x<<6)/48000 (acc 0.008%)
read_head_pos_subsample = read_head_pos & 0b111111;
read_head_pos = read_head_pos >> 6;
if(read_head_pos >= sample_len){
if(buf[STATUS] & (1<<(STATUS_PLAYBACK_LOOP))){
while(read_head_pos > sample_len){
if(sample_len){
data->read_head_pos_long -= (uint64_t) sample_len * 48000;
read_head_pos -= sample_len;
} else {
data->read_head_pos_long = 0;
read_head_pos = 0;
break;
}
}
} else {
data->playback_active = false;
}
}
}
if(data->playback_active){
uint32_t sample_offset_pos = read_head_pos + data->playback_sample_start;
while(sample_offset_pos >= sample_len){
if(sample_len){
sample_offset_pos -= sample_len;
} else {
sample_offset_pos = 0;
break;
}
}
ret = buf[sample_offset_pos + BUFFER_OFFSET];
if(read_head_pos_subsample){
ret *= (64 - read_head_pos_subsample);
sample_offset_pos++;
if(sample_offset_pos >= sample_len) sample_offset_pos -= sample_len;
ret += buf[sample_offset_pos + BUFFER_OFFSET] * read_head_pos_subsample;
ret = ret >> 6;
}
ret = radspa_mult_shift(ret, data->volume);
radspa_signal_set_value(output_sig, i, ret);
int32_t pitch_shift = radspa_signal_get_value(pitch_shift_sig, i, render_pass_id);
if(pitch_shift != data->pitch_shift_prev){
data->pitch_shift_mult = radspa_sct_to_rel_freq(radspa_clip(pitch_shift - 18376 - 10986 - 4800), 0);
if(data->pitch_shift_mult > (1<<13)) data->pitch_shift_mult = (1<<13);
data->pitch_shift_prev = pitch_shift;
}
data->read_head_pos_long += (sample_rate * data->pitch_shift_mult) >> 11;
} else {
if(!output_mute) radspa_signal_set_value(output_sig, i, 0);
}
}
if(output_mute || output_const) radspa_signal_set_const_value(output_sig, ret);
buf32[SAMPLE_START/2] = sample_start;
buf32[SAMPLE_LEN/2] = sample_len;
if(data->playback_active){
buf[STATUS] |= 1<<(STATUS_PLAYBACK_ACTIVE);
buf32[READ_HEAD_POS/2] = (data->read_head_pos_long * 699) >> 25;;
} else {
buf[STATUS] &= ~(1<<(STATUS_PLAYBACK_ACTIVE));
buf32[READ_HEAD_POS/2] = 0;
}
if(data->rec_active){
buf[STATUS] |= 1<<(STATUS_RECORD_ACTIVE);
buf32[WRITE_HEAD_POS/2] = (data->write_head_pos_long * 699) >> 25;;
} else {
buf[STATUS] &= ~(1<<(STATUS_RECORD_ACTIVE));
buf32[WRITE_HEAD_POS/2] = 0;
}
}
#define MAX_SAMPLE_LEN (48000UL*300)
radspa_t * sampler_create(uint32_t init_var){
if(init_var == 0) return NULL; //doesn't make sense
if(init_var > MAX_SAMPLE_LEN) init_var = MAX_SAMPLE_LEN;
uint32_t buffer_size = init_var;
radspa_t * sampler = radspa_standard_plugin_create(&sampler_desc, SAMPLER_NUM_SIGNALS, sizeof(sampler_data_t), buffer_size + BUFFER_OFFSET);
if(sampler == NULL) return NULL;
sampler->render = sampler_run;
radspa_signal_set(sampler, SAMPLER_OUTPUT, "playback_output", RADSPA_SIGNAL_HINT_OUTPUT, 0);
radspa_signal_set(sampler, SAMPLER_TRIGGER, "playback_trigger", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
radspa_signal_set(sampler, SAMPLER_PITCH_SHIFT, "playback_speed", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_SCT, 18367);
radspa_signal_set(sampler, SAMPLER_REC_IN, "record_input", RADSPA_SIGNAL_HINT_INPUT, 0);
radspa_signal_set(sampler, SAMPLER_REC_TRIGGER, "record_trigger", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
sampler_data_t * data = sampler->plugin_data;
data->pitch_shift_mult = 1<<11;
int16_t * buf = sampler->plugin_table;
uint32_t * buf32 = (uint32_t *) buf;
buf32[SAMPLE_RATE/2] = 48000;
buf[STATUS] = 1<<(STATUS_RECORD_OVERFLOW);
return sampler;
}
#pragma once
#include <radspa.h>
#include <radspa_helpers.h>
typedef struct {
int64_t write_head_pos_long;
int64_t read_head_pos_long;
uint32_t playback_sample_start;
int16_t pitch_shift_prev;
int16_t trigger_prev;
int16_t rec_trigger_prev;
int16_t volume;
uint32_t pitch_shift_mult;
int32_t rec_acc;
int32_t write_head_pos_prev;
int16_t write_steps;
bool rec_active;
bool write_overflow;
bool playback_active;
} sampler_data_t;
extern radspa_descriptor_t sampler_desc;
radspa_t * sampler_create(uint32_t init_var);
void sampler_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
#include "sequencer.h"
radspa_descriptor_t sequencer_desc = {
.name = "sequencer",
.id = 56709,
.description = "sequencer that can output triggers or general control signals, best enjoyed through the "
"'sequencer' patch.\ninit_var: 1st byte (lsb): number of tracks, 2nd byte: number of steps"
"\ntable encoding (all int16_t): index 0: track type (-32767: trigger track, 32767: direct "
"track). next 'number of steps' indices: track data (repeat for number of tracks)",
.create_plugin_instance = sequencer_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
#define SEQUENCER_NUM_SIGNALS 7
#define SEQUENCER_STEP 0
#define SEQUENCER_SYNC_OUT 1
#define SEQUENCER_SYNC_IN 2
#define SEQUENCER_START_STEP 3
#define SEQUENCER_END_STEP 4
#define SEQUENCER_BPM 5
#define SEQUENCER_BEAT_DIV 6
// mpx'd
#define SEQUENCER_OUTPUT 7
static uint64_t target(uint64_t step_len, uint64_t bpm, uint64_t beat_div){
if(bpm == 0) return 0;
return (48000ULL * 60 * 4) / (bpm * beat_div);
}
void sequencer_run(radspa_t * sequencer, uint16_t num_samples, uint32_t render_pass_id){
bool output_request = false;
sequencer_data_t * data = sequencer->plugin_data;
sequencer_track_data_t * tracks = (void *) (&data[1]);
radspa_signal_t * track_sigs[data->num_tracks];
radspa_signal_t * step_sig = radspa_signal_get_by_index(sequencer, SEQUENCER_STEP);
if(step_sig->buffer != NULL) output_request = true;
radspa_signal_t * sync_out_sig = radspa_signal_get_by_index(sequencer, SEQUENCER_SYNC_OUT);
if(sync_out_sig->buffer != NULL) output_request = true;
radspa_signal_t * sync_in_sig = radspa_signal_get_by_index(sequencer, SEQUENCER_SYNC_IN);
radspa_signal_t * start_step_sig = radspa_signal_get_by_index(sequencer, SEQUENCER_START_STEP);
radspa_signal_t * end_step_sig = radspa_signal_get_by_index(sequencer, SEQUENCER_END_STEP);
radspa_signal_t * bpm_sig = radspa_signal_get_by_index(sequencer, SEQUENCER_BPM);
radspa_signal_t * beat_div_sig = radspa_signal_get_by_index(sequencer, SEQUENCER_BEAT_DIV);
for(uint8_t j = 0; j < data->num_tracks; j++){
track_sigs[j] = radspa_signal_get_by_index(sequencer, SEQUENCER_OUTPUT+j);
if(track_sigs[j]->buffer != NULL) output_request = true;
}
if(!output_request) return;
int16_t * table = sequencer->plugin_table;
int16_t s1 = radspa_signal_get_value(end_step_sig, 0, render_pass_id);
int16_t s2 = data->track_step_len - 1;
data->step_end = s1 > 0 ? (s1 > s2 ? s2 : s1) : 0;
data->step_start = radspa_signal_get_value(start_step_sig, 0, render_pass_id);
int16_t bpm = radspa_signal_get_value(bpm_sig, 0, render_pass_id);
int16_t beat_div = radspa_signal_get_value(beat_div_sig, 0, render_pass_id);
if((bpm != data->bpm_prev) || (beat_div != data->beat_div_prev)){
data->counter_target = target(data->track_step_len, bpm, beat_div);
data->bpm_prev = bpm;
data->beat_div_prev = beat_div;
}
for(uint16_t i = 0; i < num_samples; i++){
int16_t sync_in = radspa_trigger_get(radspa_signal_get_value(sync_in_sig, i, render_pass_id),
&(data->sync_in_hist));
if(sync_in){
data->counter = 0;
data->step = data->step_start;
bool start = sync_in > 0;
data->is_stopped = !start;
data->sync_out_start = start;
data->sync_out_stop = !start;
if(!start){
for(uint8_t j = 0; j < data->num_tracks; j++){
int16_t type = table[j * (data->track_step_len + 1)];
int16_t stage_val = table[data->step + 1 + (1 + data->track_step_len) * j];
if(type == -32767) stage_val = -1;
if((!tracks[j].changed) && (tracks[j].stage_val_prev != stage_val)){
tracks[j].changed = true;
tracks[j].stage_val_prev = stage_val;
for(uint16_t k = 0; k < i; k++){
radspa_signal_set_value(track_sigs[j], k, tracks[j].track_fill);
}
}
if(type == 32767){
tracks[j].track_fill = stage_val;
} else if(type == -32767){
if(stage_val > 0){
radspa_trigger_start(stage_val, &(tracks[j].track_fill));
} else if(stage_val < 0){
radspa_trigger_stop(&(tracks[j].track_fill));
}
}
tracks[j].stage_val_prev = stage_val;
}
}
} else {
data->sync_out_start = false;
data->sync_out_stop = false;
}
if(!data->is_stopped && data->counter_target){
if(data->counter >= data->counter_target){
data->counter = 0;
data->step++;
if(data->step > data->step_end){
data->step = data->step_start;
data->sync_out_start = true;
}
}
if(!data->counter){ //event just happened
for(uint8_t j = 0; j < data->num_tracks; j++){
int16_t type = table[j * (data->track_step_len + 1)];
int16_t stage_val = table[data->step + 1 + (1 + data->track_step_len) * j];
if((!tracks[j].changed) && (tracks[j].stage_val_prev != stage_val)){
tracks[j].changed = true;
tracks[j].stage_val_prev = stage_val;
for(uint16_t k = 0; k < i; k++){
radspa_signal_set_value(track_sigs[j], k, tracks[j].track_fill);
}
}
if(type == 32767){
tracks[j].track_fill = stage_val;
} else if(type == -32767){
if(stage_val > 0){
radspa_trigger_start(stage_val, &(tracks[j].track_fill));
} else if(stage_val < 0){
radspa_trigger_stop(&(tracks[j].track_fill));
}
}
tracks[j].stage_val_prev = stage_val;
}
}
data->counter++;
}
for(uint8_t j = 0; j < data->num_tracks; j++){
if(tracks[j].changed) radspa_signal_set_value(track_sigs[j], i, tracks[j].track_fill);
}
int16_t sync_out = 0;
if(data->sync_out_start){
sync_out = radspa_trigger_start(sync_in, &(data->sync_out_hist));
} else if(data->sync_out_stop){
sync_out = radspa_trigger_stop(&(data->sync_out_hist));
}
radspa_signal_set_value(sync_out_sig, i, sync_out);
}
for(uint8_t j = 0; j < data->num_tracks; j++){
if(!tracks[j].changed){
int16_t type = table[j * (data->track_step_len + 1)];
if(type == 32767){
tracks[j].track_fill = table[data->step + 1 + (1 + data->track_step_len) * j];
tracks[j].stage_val_prev = tracks[j].track_fill;
}
radspa_signal_set_const_value(track_sigs[j], tracks[j].track_fill);
} else {
tracks[j].changed = false;
}
}
radspa_signal_set_const_value(step_sig, data->step);
}
radspa_t * sequencer_create(uint32_t init_var){
uint32_t num_tracks = 4;
uint32_t num_steps = 16;
if(init_var){
num_tracks = init_var & 0xFF;
num_steps = (init_var>>8) & 0xFF;
}
if(!num_tracks) return NULL;
if(!num_steps) return NULL;
uint32_t table_size = num_tracks * (num_steps + 1);
uint32_t num_signals = num_tracks + SEQUENCER_NUM_SIGNALS; //one for each channel output
size_t data_size = sizeof(sequencer_data_t) + sizeof(sequencer_track_data_t) * num_tracks;
radspa_t * sequencer = radspa_standard_plugin_create(&sequencer_desc, num_signals, data_size, table_size);
if(sequencer == NULL) return NULL;
sequencer->render = sequencer_run;
sequencer_data_t * data = sequencer->plugin_data;
data->track_step_len = num_steps;
data->num_tracks = num_tracks;
data->bpm_prev = 120;
data->beat_div_prev = 16;
data->counter_target = target(data->track_step_len, data->bpm_prev, data->beat_div_prev);
radspa_signal_set(sequencer, SEQUENCER_STEP, "step", RADSPA_SIGNAL_HINT_OUTPUT, 0);
radspa_signal_set(sequencer, SEQUENCER_SYNC_OUT, "sync_out", RADSPA_SIGNAL_HINT_OUTPUT, 0);
radspa_signal_set(sequencer, SEQUENCER_SYNC_IN, "sync_in", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_TRIGGER, 32767);
radspa_signal_set(sequencer, SEQUENCER_START_STEP, "step_start", RADSPA_SIGNAL_HINT_INPUT, 0);
radspa_signal_set(sequencer, SEQUENCER_END_STEP, "step_end", RADSPA_SIGNAL_HINT_INPUT, num_steps-1);
radspa_signal_set(sequencer, SEQUENCER_BPM, "bpm", RADSPA_SIGNAL_HINT_INPUT, data->bpm_prev);
radspa_signal_set(sequencer, SEQUENCER_BEAT_DIV, "beat_div", RADSPA_SIGNAL_HINT_INPUT, data->beat_div_prev);
radspa_signal_set_group(sequencer, data->num_tracks, 1, SEQUENCER_OUTPUT, "track",
RADSPA_SIGNAL_HINT_OUTPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
data->counter = 0;
data->sync_in_hist = 0;
data->sync_out_hist = 0;
data->sync_out_start = false;
data->sync_out_stop = false;
data->is_stopped = true;
sequencer_track_data_t * tracks = (void *) (&data[1]);
for(uint8_t j = 0; j < data->num_tracks; j++){
tracks[j].changed = false;
tracks[j].track_fill = 0;
tracks[j].stage_val_prev = 0;
}
return sequencer;
}
#pragma once
#include <math.h>
#include "radspa.h"
#include "radspa_helpers.h"
typedef struct {
int16_t track_fill;
int16_t stage_val_prev;
bool changed;
} sequencer_track_data_t;
typedef struct {
uint8_t num_tracks;
uint16_t track_step_len;
uint8_t step_end;
uint8_t step_start;
uint8_t step;
uint64_t counter;
uint64_t counter_target;
int16_t sync_in_hist;
int16_t sync_out_hist;
bool sync_out_start;
bool sync_out_stop;
bool is_stopped;
int16_t bpm_prev;
int16_t beat_div_prev;
} sequencer_data_t;
extern radspa_descriptor_t sequencer_desc;
radspa_t * sequencer_create(uint32_t init_var);
void sequencer_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
#include "slew_rate_limiter.h"
radspa_descriptor_t slew_rate_limiter_desc = {
.name = "slew_rate_limiter",
.id = 23,
.description = "very cheap nonlinear filter",
.create_plugin_instance = slew_rate_limiter_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
#define SLEW_RATE_LIMITER_NUM_SIGNALS 3
#define SLEW_RATE_LIMITER_OUTPUT 0
#define SLEW_RATE_LIMITER_INPUT 1
#define SLEW_RATE_LIMITER_SLEW_RATE 2
radspa_t * slew_rate_limiter_create(uint32_t init_var){
radspa_t * slew_rate_limiter = radspa_standard_plugin_create(&slew_rate_limiter_desc, SLEW_RATE_LIMITER_NUM_SIGNALS, sizeof(slew_rate_limiter_data_t), 0);
slew_rate_limiter->render = slew_rate_limiter_run;
radspa_signal_set(slew_rate_limiter, SLEW_RATE_LIMITER_OUTPUT, "output", RADSPA_SIGNAL_HINT_OUTPUT, 0);
radspa_signal_set(slew_rate_limiter, SLEW_RATE_LIMITER_INPUT, "input", RADSPA_SIGNAL_HINT_INPUT, 0);
radspa_signal_set(slew_rate_limiter, SLEW_RATE_LIMITER_SLEW_RATE, "slew_rate", RADSPA_SIGNAL_HINT_INPUT, 1000);
return slew_rate_limiter;
}
void slew_rate_limiter_run(radspa_t * slew_rate_limiter, uint16_t num_samples, uint32_t render_pass_id){
radspa_signal_t * output_sig = radspa_signal_get_by_index(slew_rate_limiter, SLEW_RATE_LIMITER_OUTPUT);
if(output_sig->buffer == NULL) return;
radspa_signal_t * input_sig = radspa_signal_get_by_index(slew_rate_limiter, SLEW_RATE_LIMITER_INPUT);
radspa_signal_t * slew_rate_sig = radspa_signal_get_by_index(slew_rate_limiter, SLEW_RATE_LIMITER_SLEW_RATE);
slew_rate_limiter_data_t * data = slew_rate_limiter->plugin_data;
int32_t ret = 0;
for(uint16_t i = 0; i < num_samples; i++){
int32_t input = radspa_signal_get_value(input_sig, i, render_pass_id);
int32_t slew_rate = (uint16_t) radspa_signal_get_value(slew_rate_sig, i, render_pass_id);
ret = data->prev;
if(input - ret > slew_rate){
ret += slew_rate;
} else if(ret - input > slew_rate){
ret -= slew_rate;
} else {
ret = input;
}
radspa_signal_set_value(output_sig, i, ret);
}
}
#pragma once
#include "radspa.h"
#include "radspa_helpers.h"
typedef struct {
int32_t prev;
} slew_rate_limiter_data_t;
extern radspa_descriptor_t slew_rate_limiter_desc;
radspa_t * slew_rate_limiter_create(uint32_t init_var);
void slew_rate_limiter_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
#include "trigger_merge.h"
#include <stdio.h>
radspa_descriptor_t trigger_merge_desc = {
.name = "trigger_merge",
.id = 38,
.description = "merges multiple trigger inputs together. lazy. if a start and a stop "
"collide the stop is preferred."
"\ninit_var: number of inputs, default 0, max 127",
.create_plugin_instance = trigger_merge_create,
.destroy_plugin_instance = radspa_standard_plugin_destroy
};
typedef struct {
int16_t trigger_out_prev;
int16_t blocked_stop;
int16_t trigger_in_prev[];
} trigger_merge_data_t;
void trigger_merge_run(radspa_t * plugin, uint16_t num_samples, uint32_t render_pass_id){
int num_inputs = plugin->len_signals - 1;
trigger_merge_data_t * data = plugin->plugin_data;
bool block_stop_events = plugin->plugin_table[0];
int16_t i;
int16_t merged_trigger = 0;
int16_t last_timestamp = -1;
for(uint8_t j = 0; j < num_inputs; j++){
int16_t trigger_in = radspa_trigger_get_const(&plugin->signals[j], &data->trigger_in_prev[j], (uint16_t *) &i, num_samples, render_pass_id);
if((last_timestamp > i) || (!trigger_in)) continue;
if((trigger_in > 0) && (last_timestamp == i)){
if(merged_trigger != -1){
merged_trigger = merged_trigger > trigger_in ? merged_trigger : trigger_in;
}
} else {
merged_trigger = trigger_in;
}
last_timestamp = i;
}
if(merged_trigger > 0){
radspa_trigger_start(merged_trigger, &(data->trigger_out_prev));
data->blocked_stop = false;
} else if(data->blocked_stop && (!block_stop_events)){
radspa_trigger_stop(&(data->trigger_out_prev));
data->blocked_stop = false;
} else if(merged_trigger < 0){
if(!block_stop_events){
radspa_trigger_stop(&(data->trigger_out_prev));
} else {
data->blocked_stop = true;
}
}
radspa_signal_set_const_value(&plugin->signals[num_inputs], data->trigger_out_prev);
}
radspa_t * trigger_merge_create(uint32_t init_var){
if(init_var > 127) init_var = 127;
if(!init_var) init_var = 1;
uint32_t size = sizeof(trigger_merge_data_t) + init_var * sizeof(int16_t);
radspa_t * plugin = radspa_standard_plugin_create(&trigger_merge_desc, init_var + 1, size, 1);
if(plugin == NULL) return NULL;
plugin->render = trigger_merge_run;
radspa_signal_set_group(plugin, init_var, 1, 0, "input", RADSPA_SIGNAL_HINT_INPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
radspa_signal_set(plugin, init_var, "output", RADSPA_SIGNAL_HINT_OUTPUT | RADSPA_SIGNAL_HINT_TRIGGER, 0);
return plugin;
}
#pragma once
#include <radspa.h>
#include <radspa_helpers.h>
extern radspa_descriptor_t trigger_merge_desc;
radspa_t * trigger_merge_create(uint32_t init_var);
void trigger_merge_run(radspa_t * osc, uint16_t num_samples, uint32_t render_pass_id);
idf_component_register(
SRCS
bmi270.c
bmi2.c
INCLUDE_DIRS
.
)
Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
BSD-3-Clause
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
# Sensor API for the BMI2's OIS interface
## Table of Contents
- [Introduction](#Intro)
- [Integration details](#Integration)
- [Driver files information](#file)
- [Sensor interfaces](#interface)
- [Integration Examples](#examples)
### Introduction<a name=Intro></a>
This package contains Bosch Sensortec's BMI2 Sensor API.
### Integration details<a name=Integration></a>
- Integrate _bmi2.c_, _bmi2.h_, _bmi2_ois.c_, _bmi2_ois.h_, _bmi2_defs.h_ and the required variant files in your project.
- User has to include _bmi2_ois.h_ in the code to call OIS related APIs and a _variant header_ for initialization as
well as BMI2 related API calls, as shown below:
``` c
#include "bmi261.h"
#include "bmi2_ois.h"
````
### Driver files information<a name=file></a>
- *_bmi2_ois.c_*
* This file has function definitions of OIS related API interfaces.
- *_bmi2_ois.h_*
* This header file has necessary include files, function declarations, required to make OIS related API calls.
### Sensor interfaces<a name=interface></a>
#### _Host Interface_
- I2C interface
- SPI interface
_Note: By default, the interface is I2C._
#### _OIS Interface_
- SPI interface
### Integration examples<a name=examples></a>
#### Configuring SPI/I2C for host interface.
To configure host interface, an instance of the bmi2_dev structure should be
created for initializing BMI2 sensor. "_Refer **README** for initializing BMI2
sensor._"
#### Configuring SPI for OIS interface.
To configure OIS interface, an instance of the bmi2_ois_dev structure should be
created. The following parameters are required to be updated in the structure,
by the user.
Parameters | Details
--------------|-----------------------------------
_intf_ptr_ | device address reference of SPI interface
_ois_read_ | read through SPI interface
_ois_write_ | read through SPI interface
_ois_delay_us_| delay in micro seconds
_acc_en_ | for enabling accelerometer
_gyr_en_ | for enabling gyroscope
``` c
int8_t rslt = 0;
struct bmi2_ois_dev ois_dev = {
.intf_ptr = intf_ptr will contain the chip selection info of SPI CS pin,
.ois_read = user_spi_reg_read,
.ois_write = user_spi_reg_write,
.ois_delay_us = user_delay_us
};
```
>**_Important Note_**: For initializing and configuring BMI2 sensors, which is
done through host interface, the API's are to be used from bmi2.c file. Rest
of the API's, for OIS configurations and the reading of OIS data, which is done
through OIS interface, are to be used from bmi2_ois.c file.
##### Get accelerometer and gyroscope data through OIS interface
``` c
int8_t rslt;
/* Array to enable sensor through host interface */
uint8_t sens_list[2] = {BMI2_ACCEL, BMI2_GYRO};
/* Array to enable sensor through OIS interface */
uint8_t sens_sel[2] = {BMI2_OIS_ACCEL, BMI2_OIS_GYRO};
/* Initialize the configuration structure */
struct bmi2_sens_config sens_cfg = {0};
/* Initialize BMI2 */
rslt = bmi2_init(&dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
/* Enable accelerometer and gyroscope through host interface */
rslt = bmi2_sensor_enable(sens_list, 2, &dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
/* Setting of OIS Range is done through host interface */
/* Select the gyroscope sensor for OIS Range configuration */
sens_cfg.type = BMI2_GYRO;
/* Get gyroscope configuration */
rslt = bmi2_get_sensor_config(&sens_cfg, 1, &dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
/* Set the desired OIS Range */
sens_cfg.cfg.gyr.ois_range = BMI2_GYR_OIS_2000;
/* Set gyroscope configuration for default values */
rslt = bmi2_set_sensor_config(&sens_cfg, 1, &dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
/* Enable OIS through host interface */
rslt = bmi2_set_ois_interface(BMI2_ENABLE, &dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
/* Disable Advance Power Save Mode through host interface */
rslt = bmi2_set_adv_power_save(BMI2_DISABLE, &dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
/* Get configurations for OIS through OIS interface for default values */
rslt = bmi2_ois_get_config(&ois_dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
/* Enable accelerometer and gyroscope for reading OIS data */
ois_dev.acc_en = BMI2_ENABLE;
ois_dev.gyr_en = BMI2_ENABLE;
/* Set configurations for OIS through OIS interface */
rslt = bmi2_ois_set_config(&ois_dev);
if (rslt == BMI2_OK) {
/* Get OIS accelerometer and gyroscope data through OIS interface */
rslt = bmi2_ois_read_data(sens_sel, 2, &ois_dev);
if (rslt == BMI2_OK) {
/* Print accelerometer data */
printf("OIS Accel x-axis = %d\t", ois_dev.acc_data.x);
printf("OIS Accel y-axis= %d\t", ois_dev.acc_data.y);
printf("OIS Accel z-axis = %d\r\n", ois_dev.acc_data.z);
/* Print gyroscope data */
printf("OIS Gyro x-axis = %d\t", ois_dev.gyr_data.x);
printf("OIS Gyro y-axis= %d\t", ois_dev.gyr_data.y);
printf("OIS Gyro z-axis = %d\r\n", ois_dev.gyr_data.z);
}
}
if (rslt != BMI2_OK) {
printf("Error code: %d\n", rslt);
return;
}
/* Enable Advance Power Save Mode through host interface */
rslt = bmi2_set_adv_power_save(BMI2_ENABLE, &dev);
if (rslt != BMI2_OK) {
printf("Error: %d\n", rslt);
return;
}
```
\ No newline at end of file
BMI270 Sensor API
> This package contains the sensor APIs for the BMI270 sensor
## Sensor Overview
The BMI270 is a small, low power, low noise inertial measurement unit designed for use in mobile applications like augmented reality or indoor navigation which require highly accurate, real-time sensor data.
## Applications
### BMI270 (base)
- Any motion, No motion, Significant motion detectors
- Wrist worn Step counter and Step detector (Pedometer)
- Activity change recognition
- Still
- Walking
- Running
- Wrist gestures
- Push arm down
- Pivot up
- Wrist shake jiggle
- Flick in
- Flick out
- Wrist wear wake up
### BMI270 Context
- Step counter and Step detector (Pedometer)
- Activity change recognition
- Still
- Walking
- Running
### BMI270 Legacy
- Any motion, No motion, Significant motion detector
- Orientation detector (Advanced Potrait-Landscape)
- High-G, Low-G (Freefall) detector
- Flat detector
- Tap detection (Single, Double, Triple taps)
- Smartphone Step counter and Step detector (Pedometer)
- Activity change recognition
- Still
- Walking
- Running
### BMI270 Maximum FIFO
- Supports a 6kB FIFO
For more information refer product page [Link](https://www.bosch-sensortec.com/products/motion-sensors/imus/bmi270.html)
---
\ No newline at end of file
Source diff could not be displayed: it is too large. Options to address this: view the blob.
/**
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bmi2.h
* @date 2023-05-03
* @version v2.86.1
*
*/
/*!
* @defgroup bmi2xy BMI2XY
*/
/**
* \ingroup bmi2xy
* \defgroup bmi2 BMI2
* @brief Sensor driver for BMI2 sensor
*/
#ifndef BMI2_H_
#define BMI2_H_
/*! CPP guard */
#ifdef __cplusplus
extern "C" {
#endif
/***************************************************************************/
/*! Header files
****************************************************************************/
#include "bmi2_defs.h"
/***************************************************************************/
/*! BMI2XY User Interface function prototypes
****************************************************************************/
/**
* \ingroup bmi2
* \defgroup bmi2ApiInit Initialization
* @brief Initialize the sensor and device structure
*/
/*!
* \ingroup bmi2ApiInit
* \page bmi2_api_bmi2_sec_init bmi2_sec_init
* \code
* int8_t bmi2_sec_init(struct bmi2_dev *dev);
* \endcode
* @details This API is the entry point for bmi2 sensor. It selects between
* I2C/SPI interface, based on user selection. It also reads the chip-id of
* the sensor.
*
* @param[in,out] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_sec_init(struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInit
* \page bmi2_api_bmi2_set_spi_en bmi2_set_spi_en
* \code
* int8_t bmi2_set_spi_en(uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API sets the status of SPI enable .
*
* @param[in] enable : To enable/disable SPI interface.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Enable I2C
* BMI2_ENABLE | Enable SPI
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_spi_en(uint8_t enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInit
* \page bmi2_api_bmi2_get_spi_en bmi2_get_spi_en
* \code
* int8_t bmi2_get_spi_en(uint8_t *enable, struct bmi2_dev *dev);
* \endcode
* @details This API gets the status of SPI enable .
*
* @param[in] enable : Pointer to get enable/disable SPI interface.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Enable I2C
* BMI2_ENABLE | Enable SPI
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_spi_en(uint8_t *enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInit
* \page bmi2_api_bmi2_set_spi3_interface_mode bmi2_set_spi3_interface_mode
* \code
* int8_t bmi2_set_spi3_interface_mode(uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API sets the status of SPI interface.
*
* @param[in] enable : To enable/disable SPI 3/4 wire interface.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Enable SPI 4 wire mode
* BMI2_ENABLE | Enable SPI 3 wire mode
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_spi3_interface_mode(uint8_t enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInit
* \page bmi2_api_bmi2_get_spi3_interface_mode bmi2_get_spi3_interface_mode
* \code
* int8_t bmi2_get_spi3_interface_mode(uint8_t *enable, struct bmi2_dev *dev);
* \endcode
* @details This API gets the status of SPI interface.
*
* @param[in] enable : Pointer to get enable/disable SPI 3/4 wire interface.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Enable SPI 4 wire mode
* BMI2_ENABLE | Enable SPI 3 wire mode
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_spi3_interface_mode(uint8_t *enable, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiI2C I2c watchdog init
* @brief Initialize the watchdog for i2c
*/
/*!
* \ingroup bmi2ApiI2C
* \page bmi2_api_bmi2_set_i2c_wdt_en bmi2_set_i2c_wdt_en
* \code
* int8_t bmi2_set_i2c_wdt_en(uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API enables/disables the i2c watchdog timer .
*
* @param[in] enable : To enable/disable i2c watchdog timer.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Disable I2C watchdog timer
* BMI2_ENABLE | Enable I2C watchdog timer
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_i2c_wdt_en(uint8_t enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiI2C
* \page bmi2_api_bmi2_get_i2c_wdt_en bmi2_get_i2c_wdt_en
* \code
* int8_t bmi2_get_i2c_wdt_en(uint8_t *enable, struct bmi2_dev *dev);
* \endcode
* @details This API gets the enable/disable status of the i2c watchdog timer .
*
* @param[in] enable : Pointer to get status of enable/disable i2c watchdog timer.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Disable I2C watchdog timer
* BMI2_ENABLE | Enable I2C watchdog timer
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_i2c_wdt_en(uint8_t *enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiI2C
* \page bmi2_api_bmi2_set_i2c_wdt_sel bmi2_set_i2c_wdt_sel
* \code
* int8_t bmi2_set_i2c_wdt_sel(uint8_t watchdog_select, struct bmi2_dev *dev);
* \endcode
* @details This API sets i2c watchdog timer .
*
* @param[in] watchdog_select : To set watchdog timer for i2c.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Watchdog_select | Description
* ----------------------|---------------
* BMI2_DISABLE | I2C watchdog timeout after 1.25ms
* BMI2_ENABLE | I2c watchdog timeout after 40ms
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_i2c_wdt_sel(uint8_t watchdog_select, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiI2C
* \page bmi2_api_bmi2_get_i2c_wdt_sel bmi2_get_i2c_wdt_sel
* \code
* int8_t bmi2_get_i2c_wdt_sel(uint8_t *watchdog_select, struct bmi2_dev *dev);
* \endcode
* @details This API sets i2c watchdog timer .
*
* @param[in] watchdog_select : Pointer to get watchdog timer for i2c.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Watchdog_select | Description
* --------------------- |---------------
* BMI2_DISABLE | I2C watchdog timeout after 1.25ms
* BMI2_ENABLE | I2c watchdog timeout after 40ms
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_i2c_wdt_sel(uint8_t *watchdog_select, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiRegs Registers
* @brief Set / Get data from the given register address of the sensor
*/
/*!
* \ingroup bmi2ApiRegs
* \page bmi2_api_bmi2_get_regs bmi2_get_regs
* \code
* int8_t bmi2_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, const struct bmi2_dev *dev);
* \endcode
* @details This API reads the data from the given register address of bmi2
* sensor.
*
* @param[in] reg_addr : Register address from which data is read.
* @param[out] data : Pointer to data buffer where read data is stored.
* @param[in] len : No. of bytes of data to be read.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note For most of the registers auto address increment applies, with the
* exception of a few special registers, which trap the address. For e.g.,
* Register address - 0x26, 0x5E.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_regs(uint8_t reg_addr, uint8_t *data, uint16_t len, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiRegs
* \page bmi2_api_bmi2_set_regs bmi2_set_regs
* \code
* int8_t bmi2_set_regs(uint8_t reg_addr, const uint8_t *data, uint16_t len, struct bmi2_dev *dev);
* \endcode
* @details This API writes data to the given register address of bmi2 sensor.
*
* @param[in] reg_addr : Register address to which the data is written.
* @param[in] data : Pointer to data buffer in which data to be written
* is stored.
* @param[in] len : No. of bytes of data to be written.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_regs(uint8_t reg_addr, const uint8_t *data, uint16_t len, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiSR Soft reset
* @brief Set / Get data from the given register address of the sensor
*/
/*!
* \ingroup bmi2ApiSR
* \page bmi2_api_bmi2_soft_reset bmi2_soft_reset
* \code
* int8_t bmi2_soft_reset(struct bmi2_dev *dev);
* \endcode
* @details This API resets bmi2 sensor. All registers are overwritten with
* their default values.
*
* @note If selected interface is SPI, an extra dummy byte is read to bring the
* interface back to SPI from default, after the soft reset command.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_soft_reset(struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiConfig Configuration
* @brief Functions related to configuration of the sensor
*/
/*!
* \ingroup bmi2ApiConfig
* \page bmi2_api_bmi2_get_config_file_version bmi2_get_config_file_version
* \code
* int8_t bmi2_get_config_file_version(uint8_t *config_major, uint8_t *config_minor, struct bmi2_dev *dev);
* \endcode
* @details This API is used to get the config file major and minor information.
*
* @param[in] dev : Structure instance of bmi2_dev.
* @param[out] config_major : pointer to data buffer to store the config major.
* @param[out] config_minor : pointer to data buffer to store the config minor.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_config_file_version(uint8_t *config_major, uint8_t *config_minor, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiPowersave Advanced power save mode
* @brief Set / Get Advanced power save mode of the sensor
*/
/*!
* \ingroup bmi2ApiPowersave
* \page bmi2_api_bmi2_set_adv_power_save bmi2_set_adv_power_save
* \code
* int8_t bmi2_set_adv_power_save(uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API enables/disables the advance power save mode in the sensor.
*
* @param[in] enable : To enable/disable advance power mode.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Disables advance power save.
* BMI2_ENABLE | Enables advance power save.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_adv_power_save(uint8_t enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiPowersave
* \page bmi2_api_bmi2_get_adv_power_save bmi2_get_adv_power_save
* \code
* int8_t bmi2_get_adv_power_save(uint8_t *aps_status, struct bmi2_dev *dev);
* \endcode
* @details This API gets the status of advance power save mode in the sensor.
*
* @param[out] aps_status : Pointer to get the status of APS mode.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* aps_status | Description
* -------------|---------------
* BMI2_DISABLE | Advance power save disabled.
* BMI2_ENABLE | Advance power save enabled.
*@endverbatim
*
* @return Result of API execution status
*
* @retval BMI2_OK - Success.
* @retval BMI2_E_NULL_PTR - Error: Null pointer error
* @retval BMI2_E_COM_FAIL - Error: Communication fail
* @retval BMI2_E_SET_APS_FAIL - Error: Set Advance Power Save Fail
*/
int8_t bmi2_get_adv_power_save(uint8_t *aps_status, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiPowersave
* \page bmi2_api_bmi2_set_fast_power_up bmi2_set_fast_power_up
* \code
* int8_t bmi2_set_fast_power_up(uint8_t fast_power_up, struct bmi2_dev *dev);
* \endcode
* @details This API enables/disables the fast power up mode in the sensor.
*
* @param[in] fast_power_up : To enable/disable advance power mode.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Fast_power_up | Description
* --------------------|---------------
* BMI2_DISABLE | Disables fast power up.
* BMI2_ENABLE | Enables fast power up.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_fast_power_up(uint8_t fast_power_up, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiPowersave
* \page bmi2_api_bmi2_get_fast_power_up bmi2_get_fast_power_up
* \code
* int8_t bmi2_get_fast_power_up(uint8_t *fast_power_up, struct bmi2_dev *dev);
* \endcode
* @details This API gets the enable/disable status of the fast power up mode in the sensor.
*
* @param[in] fast_power_up : Pointer to get the enable/disable advance power mode.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Fast power up | Description
* --------------------|---------------
* BMI2_DISABLE | Disables fast power up.
* BMI2_ENABLE | Enables fast power up.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_fast_power_up(uint8_t *fast_power_up, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiConfig
* \page bmi2_api_bmi2_write_config_file bmi2_write_config_file
* \code
* int8_t bmi2_write_config_file(struct bmi2_dev *dev);
* \endcode
* @details This API loads the configuration file to the bmi2 sensor.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_write_config_file(struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiInt Interrupt
* @brief Interrupt operations of the sensor
*/
/*!
* \ingroup bmi2ApiInt
* \page bmi2_api_bmi2_set_int_pin_config bmi2_set_int_pin_config
* \code
* int8_t bmi2_set_int_pin_config(const struct bmi2_int_pin_config *int_cfg, struct bmi2_dev *dev);
* \endcode
* @details This API sets:
* 1) The input output configuration of the selected interrupt pin:
* INT1 or INT2.
* 2) The interrupt mode: permanently latched or non-latched.
*
* @param[in] int_cfg : Structure instance of bmi2_int_pin_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_int_pin_config(const struct bmi2_int_pin_config *int_cfg, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInt
* \page bmi2_api_bmi2_get_int_pin_config bmi2_get_int_pin_config
* \code
* int8_t bmi2_get_int_pin_config(struct bmi2_int_pin_config *int_cfg, const struct bmi2_dev *dev);
* \endcode
* @details This API gets:
* 1) The input output configuration of the selected interrupt pin:
* INT1 or INT2.
* 2) The interrupt mode: permanently latched or non-latched.
*
* @param[in,out] int_cfg : Structure instance of bmi2_int_pin_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_int_pin_config(struct bmi2_int_pin_config *int_cfg, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInt
* \page bmi2_api_bmi2_get_int_status bmi2_get_int_status
* \code
* int8_t bmi2_get_int_status(uint16_t *int_status, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the interrupt status of both feature and data
* interrupts.
*
* @param[out] int_status : Pointer to get the status of the interrupts.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* int_status | Status
* -----------|------------
* 0x00 | BIT0
* 0x01 | BIT1
* 0x02 | BIT2
* 0x03 | BIT3
* 0x04 | BIT4
* 0x05 | BIT5
* 0x06 | BIT6
* 0x07 | BIT7
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_int_status(uint16_t *int_status, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiSensorC Sensor Configuration
* @brief Enable / Disable feature configuration of the sensor
*/
/*!
* \ingroup bmi2ApiSensorC
* \page bmi2_api_bmi2_set_sensor_config bmi2_set_sensor_config
* \code
* int8_t bmi2_set_sensor_config(struct bmi2_sens_config *sens_cfg, uint8_t n_sens, struct bmi2_dev *dev);
* \endcode
* @details This API sets the sensor/feature configuration.
*
* @param[in] sens_cfg : Structure instance of bmi2_sens_config.
* @param[in] n_sens : Number of sensors selected.
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @note Sensors/features that can be configured
*
*@verbatim
* sens_list | Values
* ----------------------------|-----------
* BMI2_ACCEL | 0
* BMI2_GYRO | 1
* BMI2_AUX | 2
* BMI2_GYRO_GAIN_UPDATE | 9
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_sensor_config(struct bmi2_sens_config *sens_cfg, uint8_t n_sens, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiSensorC
* \page bmi2_api_bmi2_get_sensor_config bmi2_get_sensor_config
* \code
* int8_t bmi2_get_sensor_config(struct bmi2_sens_config *sens_cfg, uint8_t n_sens, struct bmi2_dev *dev);
* \endcode
* @details This API gets the sensor/feature configuration.
*
* @param[in] sens_cfg : Structure instance of bmi2_sens_config.
* @param[in] n_sens : Number of sensors selected.
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @note Sensors/features whose configurations can be read.
*
*@verbatim
* sens_list | Values
* -------------------------|-----------
* BMI2_ACCEL | 0
* BMI2_GYRO | 1
* BMI2_AUX | 2
* BMI2_GYRO_GAIN_UPDATE | 9
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_sensor_config(struct bmi2_sens_config *sens_cfg, uint8_t n_sens, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiSensor Feature Set
* @brief Enable / Disable features of the sensor
*/
/*!
* \ingroup bmi2ApiSensor
* \page bmi2_api_bmi2_sensor_enable bmi2_sensor_enable
* \code
* int8_t bmi2_sensor_enable(const uint8_t *sens_list, uint8_t n_sens, struct bmi2_dev *dev);
* \endcode
* @details This API selects the sensors/features to be enabled.
*
* @param[in] sens_list : Pointer to select the sensor/feature.
* @param[in] n_sens : Number of sensors selected.
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @note Sensors/features that can be enabled.
*
*@verbatim
* sens_list | Values
* -------------------------|-----------
* BMI2_ACCEL | 0
* BMI2_GYRO | 1
* BMI2_AUX | 2
* BMI2_TEMP | 31
*@endverbatim
*
* @note :
* example uint8_t sens_list[2] = {BMI2_ACCEL, BMI2_GYRO};
* uint8_t n_sens = 2;
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_sensor_enable(const uint8_t *sens_list, uint8_t n_sens, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiSensor
* \page bmi2_api_bmi2_sensor_disable bmi2_sensor_disable
* \code
* int8_t bmi2_sensor_disable(const uint8_t *sens_list, uint8_t n_sens, struct bmi2_dev *dev);
* \endcode
* @details This API selects the sensors/features to be disabled.
*
* @param[in] sens_list : Pointer to select the sensor/feature.
* @param[in] n_sens : Number of sensors selected.
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @note Sensors/features that can be disabled.
*
*@verbatim
* sens_list | Values
* ----------------------------|-----------
* BMI2_ACCEL | 0
* BMI2_GYRO | 1
* BMI2_AUX | 2
* BMI2_TEMP | 31
*@endverbatim
*
* @note :
* example uint8_t sens_list[2] = {BMI2_ACCEL, BMI2_GYRO};
* uint8_t n_sens = 2;
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_sensor_disable(const uint8_t *sens_list, uint8_t n_sens, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiSensorD Sensor Data
* @brief Get sensor data
*/
/*!
* \ingroup bmi2ApiSensorD
* \page bmi2_api_bmi2_get_feature_data bmi2_get_feature_data
* \code
* int8_t bmi2_get_feature_data(struct bmi2_feat_sensor_data *feat_sensor_data, uint8_t n_sens, struct bmi2_dev *dev);
* \endcode
* @details This API gets the feature data for gyroscope user-gain update and gyroscope cross sensitivity
*
* @param[out] feat_sensor_data : Structure instance of bmi2_feat_sensor_data.
* @param[in] n_sens : Number of sensors selected.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note Sensors/features whose data can be read
*
*@verbatim
* sens_list | Values
* ---------------------|-----------
* BMI2_GYRO_GAIN_UPDATE| 12
* BMI2_GYRO_CROSS_SENSE| 28
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_feature_data(struct bmi2_feat_sensor_data *feat_sensor_data, uint8_t n_sens, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiSensorD
* \page bmi2_api_bmi2_get_sensor_data bmi2_get_sensor_data
* \code
* int8_t bmi2_get_sensor_data(struct bmi2_sens_data *data, struct bmi2_dev *dev);
* \endcode
* @details This API gets the sensor data for accelerometer, gyroscope and auxiliary sensor
*
* @param[out] data : Structure instance of bmi2_sens_data.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_sensor_data(struct bmi2_sens_data *data, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiTemperature Temperature
* @brief Read temperature of the sensor.
*/
/*!
* \ingroup bmi2ApiTemperature
* \page bmi2_api_bmi2_get_temperature_data bmi2_get_temperature_data
* \code
* int8_t bmi2_get_temperature_data(uint16_t *temp_data, struct bmi2_dev *dev);
* \endcode
* @details This API reads the raw temperature data from the register and can be
* converted into degree celsius using the below formula.
* Formula: temperature_value = (float)(((float)((int16_t)temperature_data)) / 512.0) + 23.0
* @note Enable gyro to read temperature
*
* @param[out] temp_data : Pointer variable which stores the raw temperature value.
* @param[in] dev : Structure instance of bmi2_dev.
*
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_temperature_data(uint16_t *temp_data, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiSensorD
* \page bmi2_api_bmi2_parse_sensor_data bmi2_parse_sensor_data
* \code
* int8_t bmi2_parse_sensor_data(const uint8_t *sensor_data, struct bmi2_sens_data *data, const struct bmi2_dev *dev);
* \endcode
* @details This API parses the sensor data for accelerometer, gyroscope and auxiliary sensor
*
* @param[in] sensor_data : Array of register data (24 bytes from Register 0x03 to 0x1A)
* @param[out] data : Structure instance of bmi2_sens_data.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_parse_sensor_data(const uint8_t *sensor_data, struct bmi2_sens_data *data, const struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiFIFO FIFO
* @brief FIFO operations of the sensor
*/
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_set_fifo_config bmi2_set_fifo_config
* \code
* int8_t bmi2_set_fifo_config(uint16_t config, uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API sets the FIFO configuration in the sensor.
*
* @param[in] config : FIFO configurations to be enabled/disabled.
* @param[in] enable : Enable/Disable FIFO configurations.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* enable | Description
* -------------|---------------
* BMI2_DISABLE | Disables FIFO configuration.
* BMI2_ENABLE | Enables FIFO configuration.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_fifo_config(uint16_t config, uint8_t enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_get_fifo_config bmi2_get_fifo_config
* \code
* int8_t bmi2_get_fifo_config(uint16_t *fifo_config, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the FIFO configuration from the sensor.
*
* @param[out] fifo_config : Pointer variable to get FIFO configuration value.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_fifo_config(uint16_t *fifo_config, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_read_fifo_data bmi2_read_fifo_data
* \code
* int8_t bmi2_read_fifo_data(struct bmi2_fifo_frame *fifo, const struct bmi2_dev *dev);
* \endcode
* @details This API reads FIFO data.
*
* @param[in, out] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note APS has to be disabled before calling this function.
* @note Dummy byte (for SPI Interface) required for FIFO data read
* must be given as part of data pointer in struct bmi2_fifo_frame
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_read_fifo_data(struct bmi2_fifo_frame *fifo, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_extract_accel bmi2_extract_accel
* \code
* int8_t bmi2_extract_accel(struct bmi2_sens_axes_data *accel_data,
* uint16_t *accel_length,
* struct bmi2_fifo_frame *fifo,
* const struct bmi2_dev *dev);
* \endcode
* @details This API parses and extracts the accelerometer frames from FIFO data read by
* the "bmi2_read_fifo_data" API and stores it in the "accel_data" structure
* instance.
*
* @param[out] accel_data : Structure instance of bmi2_sens_axes_data
* where the parsed data bytes are stored.
* @param[in,out] accel_length : Number of accelerometer frames.
* @param[in,out] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_extract_accel(struct bmi2_sens_axes_data *accel_data,
uint16_t *accel_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_extract_aux bmi2_extract_aux
* \code
* int8_t bmi2_extract_aux(struct bmi2_aux_fifo_data *aux,
* uint16_t *aux_length,
* struct bmi2_fifo_frame *fifo,
* const struct bmi2_dev *dev);
*
* \endcode
* @details This API parses and extracts the auxiliary frames from FIFO data
* read by the "bmi2_read_fifo_data" API and stores it in "aux_data" buffer.
*
* @param[out] aux : Pointer to structure where the parsed auxiliary
* data bytes are stored.
* @param[in,out] aux_length : Number of auxiliary frames.
* @param[in,out] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_extract_aux(struct bmi2_aux_fifo_data *aux,
uint16_t *aux_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_extract_gyro bmi2_extract_gyro
* \code
* int8_t bmi2_extract_gyro(struct bmi2_sens_axes_data *gyro_data,
* uint16_t *gyro_length,
* struct bmi2_fifo_frame *fifo,
* const struct bmi2_dev *dev);
* \endcode
* @details This API parses and extracts the gyroscope frames from FIFO data read by the
* "bmi2_read_fifo_data" API and stores it in the "gyro_data"
* structure instance.
*
* @param[out] gyro_data : Structure instance of bmi2_sens_axes_data
* where the parsed data bytes are stored.
* @param[in,out] gyro_length : Number of gyroscope frames.
* @param[in,out] fifo : Structure instance of bmi2_fifo_frame.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_extract_gyro(struct bmi2_sens_axes_data *gyro_data,
uint16_t *gyro_length,
struct bmi2_fifo_frame *fifo,
const struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiCmd Command Register
* @brief Write commands to the sensor
*/
/*!
* \ingroup bmi2ApiCmd
* \page bmi2_api_bmi2_set_command_register bmi2_set_command_register
* \code
* int8_t bmi2_set_command_register(uint8_t command, struct bmi2_dev *dev);
* \endcode
* @details This API writes the available sensor specific commands to the sensor.
*
* @param[in] command : Commands to be given to the sensor.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Commands | Values
* ---------------------|---------------------
* BMI2_SOFT_RESET_CMD | 0xB6
* BMI2_FIFO_FLUSH_CMD | 0xB0
* BMI2_USR_GAIN_CMD | 0x03
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_command_register(uint8_t command, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_set_fifo_self_wake_up bmi2_set_fifo_self_wake_up
* \code
* int8_t bmi2_set_fifo_self_wake_up(uint8_t fifo_self_wake_up, struct bmi2_dev *dev);
* \endcode
* @details This API sets the FIFO self wake up functionality in the sensor.
*
* @param[in] fifo_self_wake_up : Variable to set FIFO self wake-up.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* fifo_self_wake_up | Description
* -------------------|---------------
* BMI2_DISABLE | Disables self wake-up.
* BMI2_ENABLE | Enables self wake-up.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_fifo_self_wake_up(uint8_t fifo_self_wake_up, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_get_fifo_self_wake_up bmi2_get_fifo_self_wake_up
* \code
* int8_t bmi2_get_fifo_self_wake_up(uint8_t *fifo_self_wake_up, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the FIFO self wake up functionality from the sensor.
*
* @param[out] fifo_self_wake_up : Pointer variable to get the status of FIFO
* self wake-up.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* fifo_self_wake_up | Description
* -------------------|---------------
* BMI2_DISABLE | Self wake-up disabled
* BMI2_ENABLE | Self wake-up enabled.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_fifo_self_wake_up(uint8_t *fifo_self_wake_up, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_set_fifo_wm bmi2_set_fifo_wm
* \code
* int8_t bmi2_set_fifo_wm(uint16_t fifo_wm, struct bmi2_dev *dev);
* \endcode
* @details This API sets the FIFO water mark level which is set in the sensor.
*
* @param[in] fifo_wm : Variable to set FIFO water-mark level.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_fifo_wm(uint16_t fifo_wm, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_get_fifo_wm bmi2_get_fifo_wm
* \code
* int8_t bmi2_get_fifo_wm(uint16_t *fifo_wm, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the FIFO water mark level which is set in the sensor.
*
* @param[out] fifo_wm : Pointer variable to store FIFO water-mark level.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_fifo_wm(uint16_t *fifo_wm, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_set_fifo_filter_data bmi2_set_fifo_filter_data
* \code
* int8_t bmi2_set_fifo_filter_data(uint8_t sens_sel, uint8_t fifo_filter_data, struct bmi2_dev *dev);
* \endcode
* @details This API sets either filtered or un-filtered FIFO accelerometer or
* gyroscope data.
*
* @param[in] sens_sel : Selects either accelerometer or
* gyroscope sensor.
* @param[in] fifo_filter_data : Variable to set the filter data.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* sens_sel | values
* -----------------|----------
* BMI2_ACCEL | 0x01
* BMI2_GYRO | 0x02
*@endverbatim
*
*@verbatim
* Value | fifo_filter_data
* ---------|---------------------
* 0x00 | Un-filtered data
* 0x01 | Filtered data
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_fifo_filter_data(uint8_t sens_sel, uint8_t fifo_filter_data, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_get_fifo_filter_data bmi2_get_fifo_filter_data
* \code
* int8_t bmi2_get_fifo_filter_data(uint8_t sens_sel, uint8_t *fifo_filter_data, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the FIFO accelerometer or gyroscope filter data.
*
* @param[in] sens_sel : Selects either accelerometer or
* gyroscope sensor.
* @param[out] fifo_filter_data : Pointer variable to get the filter data.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* sens_sel | values
* -----------------|----------
* BMI2_ACCEL | 0x01
* BMI2_GYRO | 0x02
*@endverbatim
*
*@verbatim
* Value | fifo_filter_data
* ---------|---------------------
* 0x00 | Un-filtered data
* 0x01 | Filtered data
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_fifo_filter_data(uint8_t sens_sel, uint8_t *fifo_filter_data, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_set_fifo_down_sample bmi2_set_fifo_down_sample
* \code
* int8_t bmi2_set_fifo_down_sample(uint8_t sens_sel, uint8_t fifo_down_samp, struct bmi2_dev *dev);
* \endcode
* @details This API sets the down sampling rate for FIFO accelerometer or
* gyroscope FIFO data.
*
* @param[in] sens_sel : Selects either either accelerometer or
* gyroscope sensor.
* @param[in] fifo_down_samp : Variable to set the down sampling rate.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* sens_sel | values
* ----------------|----------
* BMI2_ACCEL | 0x01
* BMI2_GYRO | 0x02
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_fifo_down_sample(uint8_t sens_sel, uint8_t fifo_down_samp, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_get_fifo_down_sample bmi2_get_fifo_down_sample
* \code
* int8_t bmi2_get_fifo_down_sample(uint8_t sens_sel, uint8_t *fifo_down_samp, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the down sampling rate, configured for FIFO
* accelerometer or gyroscope data.
*
* @param[in] sens_sel : Selects either either accelerometer or
* gyroscope sensor.
* @param[out] fifo_down_samp : Pointer variable to store the down sampling rate
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* sens_sel | values
* ----------------|----------
* BMI2_ACCEL | 0x01
* BMI2_GYRO | 0x02
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_fifo_down_sample(uint8_t sens_sel, uint8_t *fifo_down_samp, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_get_fifo_length bmi2_get_fifo_length
* \code
* int8_t bmi2_get_fifo_length(uint16_t *fifo_length, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the length of FIFO data available in the sensor in
* bytes.
*
* @param[out] fifo_length : Pointer variable to store the value of FIFO byte
* counter.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note The byte counter is updated each time a complete frame is read or
* written.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_fifo_length(uint16_t *fifo_length, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFIFO
* \page bmi2_api_bmi2_get_saturation_status bmi2_get_saturation_status
* \code
* int8_t bmi2_get_saturation_status(uint8_t *status, struct bmi2_dev *dev);
* \endcode
* @details This API reads the saturation status of the sensor.
*
* @param[in] status : Pointer to read the status of saturation.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Macro | Status
* -----------------------------|---------------
* BMI2_SATURATION_ACC_X_MASK | 0X01
* BMI2_SATURATION_ACC_Y_MASK | 0X02
* BMI2_SATURATION_ACC_Z_MASK | 0X04
* BMI2_SATURATION_GYR_X_MASK | 0X08
* BMI2_SATURATION_GYR_Y_MASK | 0X10
* BMI2_SATURATION_GYR_Z_MASK | 0X20
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_saturation_status(uint8_t *status, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiOIS OIS
* @brief OIS operations of the sensor
*/
/*!
* \ingroup bmi2ApiOIS
* \page bmi2_api_bmi2_set_ois_interface bmi2_set_ois_interface
* \code
* int8_t bmi2_set_ois_interface(uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API enables/disables OIS interface.
*
* @param[in] enable : To enable/disable OIS interface.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Disables OIS interface.
* BMI2_ENABLE | Enables OIS interface.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_ois_interface(uint8_t enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiOIS
* \page bmi2_api_bmi2_get_spi3_ois_mode bmi2_get_spi3_ois_mode
* \code
* int8_t bmi2_get_spi3_ois_mode(uint8_t *enable, struct bmi2_dev *dev);
* \endcode
* @details This API gets the status of SPI OIS interface.
*
* @param[in] enable : Pointer to read SPI OIS 3/4 wire interface.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Enable SPI OIS 4 wire mode
* BMI2_ENABLE | Enable SPI OIS 3 wire mode
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_spi3_ois_mode(uint8_t *enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApisensorC
* \page bmi2_api_bmi2_set_drv_reg bmi2_set_drv_reg
* \code
* int8_t bmi2_set_drv_reg(uint8_t drv_reg, struct bmi2_dev *dev);
* \endcode
* @details This API sets the drive strength of the sensor
*
* @param[in] drv_reg : To set the drive strength of the sensor.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_drv_reg(uint8_t drv_reg, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApisensorC
* \page bmi2_api_bmi2_get_drv_reg bmi2_get_drv_reg
* \code
* int8_t bmi2_get_drv_reg(uint8_t *drv_reg, struct bmi2_dev *dev);
* \endcode
* @details This API gets the drive strength of the sensor
*
* @param[in] drv_reg : Pointer to get the drive strength of the sensor.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_drv_reg(uint8_t *drv_reg, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiOIS
* \page bmi2_api_bmi2_set_spi3_ois_mode bmi2_set_spi3_ois_mode
* \code
* int8_t bmi2_set_spi3_ois_mode(uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API sets the status of SPI OIS interface.
*
* @param[in] enable : To enable/disable SPI OIS 3/4 wire interface.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Enable | Description
* -------------|---------------
* BMI2_DISABLE | Enable SPI OIS 4 wire mode
* BMI2_ENABLE | Enable SPI OIS 3 wire mode
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_spi3_ois_mode(uint8_t enable, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiAux Auxiliary sensor
* @brief Auxiliary sensor operations of the sensor
*/
/*!
* \ingroup bmi2ApiAux
* \page bmi2_api_bmi2_read_aux_man_mode bmi2_read_aux_man_mode
* \code
* int8_t bmi2_read_aux_man_mode(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, struct bmi2_dev *dev);
* \endcode
* @details This API reads the user-defined bytes of data from the given register
* address of auxiliary sensor in manual mode.
*
* @param[in] reg_addr : Address from where data is read.
* @param[out] aux_data : Pointer to the stored buffer.
* @param[in] len : Total length of data to be read.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note Change of BMI2_AUX_RD_ADDR is only allowed if AUX is not busy.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_read_aux_man_mode(uint8_t reg_addr, uint8_t *aux_data, uint16_t len, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiAux
* \page bmi2_api_bmi2_write_aux_man_mode bmi2_write_aux_man_mode
* \code
* int8_t bmi2_write_aux_man_mode(uint8_t reg_addr, const uint8_t *aux_data, uint16_t len, struct bmi2_dev *dev);
* \endcode
* @details This API writes the user-defined bytes of data and the address of
* auxiliary sensor where data is to be written in manual mode.
*
* @param[in] reg_addr : AUX address where data is to be written.
* @param[in] aux_data : Pointer to data to be written.
* @param[in] len : Total length of data to be written.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @note Change of BMI2_AUX_WR_ADDR is only allowed if AUX is not busy.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_write_aux_man_mode(uint8_t reg_addr, const uint8_t *aux_data, uint16_t len, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiStatus Sensor Status
* @brief Get sensor status
*/
/*!
* \ingroup bmi2ApiStatus
* \page bmi2_api_bmi2_get_status bmi2_get_status
* \code
* int8_t bmi2_get_status(uint8_t *status, const struct bmi2_dev *dev);
* \endcode
* @details This API gets the data ready status of accelerometer, gyroscope,
* auxiliary, ready status of command decoder and busy status of auxiliary.
*
* @param[out] status : Pointer variable to the status.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Value | Status
* ---------|---------------------
* 0x80 | DRDY_ACC
* 0x40 | DRDY_GYR
* 0x20 | DRDY_AUX
* 0x10 | CMD_RDY
* 0x04 | AUX_BUSY
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_status(uint8_t *status, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiWSync Sync commands
* @brief Write sync commands
*/
/*!
* \ingroup bmi2ApiWSync
* \page bmi2_api_bmi2_write_sync_commands bmi2_write_sync_commands
* \code
* int8_t bmi2_write_sync_commands(const uint8_t *command, uint8_t n_comm, struct bmi2_dev *dev);
* \endcode
* @details This API can be used to write sync commands like ODR, sync period,
* frequency and phase, resolution ratio, sync time and delay time.
*
* @param[in] command : Sync command to be written.
* @param[in] n_comm : Length of the command.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_write_sync_commands(const uint8_t *command, uint8_t n_comm, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiASelftest Accel self test
* @brief Perform accel self test
*/
/*!
* \ingroup bmi2ApiASelftest
* \page bmi2_api_bmi2_perform_accel_self_test bmi2_perform_accel_self_test
* \code
* int8_t bmi2_perform_accel_self_test(struct bmi2_dev *dev);
* \endcode
* @details This API performs self-test to check the proper functionality of the
* accelerometer sensor.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_perform_accel_self_test(struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInt
* \page bmi2_api_bmi2_map_feat_int bmi2_map_feat_int
* \code
* int8_t bmi2_map_feat_int(const struct bmi2_sens_int_config *sens_int, struct bmi2_dev *dev);
* \endcode
* @details This API maps/unmaps feature interrupts to that of interrupt pins.
*
* @param[in] sens_int : Structure instance of bmi2_sens_int_config.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_map_feat_int(uint8_t type, enum bmi2_hw_int_pin hw_int_pin, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInt
* \page bmi2_api_bmi2_map_data_int bmi2_map_data_int
* \code
* int8_t bmi2_map_data_int(uint8_t data_int, enum bmi2_hw_int_pin int_pin, struct bmi2_dev *dev);
* \endcode
* @details This API maps/un-maps data interrupts to that of interrupt pins.
*
* @param[in] int_pin : Interrupt pin selected.
* @param[in] data_int : Type of data interrupt to be mapped.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* data_int | Mask values
* ---------------------|---------------------
* BMI2_FFULL_INT | 0x01
* BMI2_FWM_INT | 0x02
* BMI2_DRDY_INT | 0x04
* BMI2_ERR_INT | 0x08
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_map_data_int(uint8_t data_int, enum bmi2_hw_int_pin int_pin, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiRemap Remap Axes
* @brief Set / Get remap axes values from the sensor
*/
/*!
* \ingroup bmi2ApiRemap
* \page bmi2_api_bmi2_get_remap_axes bmi2_get_remap_axes
* \code
* int8_t bmi2_get_remap_axes(struct bmi2_remap *remapped_axis, struct bmi2_dev *dev);
* \endcode
* @details This API gets the re-mapped x, y and z axes from the sensor and
* updates the values in the device structure.
*
* @param[out] remapped_axis : Structure that stores re-mapped axes.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_remap_axes(struct bmi2_remap *remapped_axis, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiRemap
* \page bmi2_api_bmi2_set_remap_axes bmi2_set_remap_axes
* \code
* int8_t bmi2_set_remap_axes(const struct bmi2_remap *remapped_axis, struct bmi2_dev *dev);
* \endcode
* @details This API sets the re-mapped x, y and z axes to the sensor and
* updates them in the device structure.
*
* @param[in] remapped_axis : Structure that stores re-mapped axes.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_remap_axes(const struct bmi2_remap *remapped_axis, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiGyroOC Gyro Offset Compensation
* @brief Gyro Offset Compensation operations of the sensor
*/
/*!
* \ingroup bmi2ApiGyroOC
* \page bmi2_api_bmi2_set_gyro_offset_comp bmi2_set_gyro_offset_comp
* \code
* int8_t bmi2_set_gyro_offset_comp(uint8_t enable, struct bmi2_dev *dev);
* \endcode
* @details This API enables/disables gyroscope offset compensation. It adds the
* offsets defined in the offset register with gyroscope data.
*
* @param[in] enable : Enables/Disables gyroscope offset compensation.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* enable | Description
* -------------|---------------
* BMI2_ENABLE | Enables gyroscope offset compensation.
* BMI2_DISABLE | Disables gyroscope offset compensation.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_gyro_offset_comp(uint8_t enable, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiGyroOC
* \page bmi2_api_bmi2_set_gyro_offset_comp bmi2_get_gyro_offset_comp
* \code
* int8_t bmi2_get_gyro_offset_comp(uint8_t *offset, struct bmi2_dev *dev);
* \endcode
* @details This API reads the gyroscope offset compensation.
*
* @param[in, out] offset : The value of the offset compensation.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* enable | Description
* -------------|---------------
* BMI2_ENABLE | Enables gyroscope offset compensation.
* BMI2_DISABLE | Disables gyroscope offset compensation.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_gyro_offset_comp(uint8_t *offset, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiGyroOC
* \page bmi2_api_bmi2_set_gyro_offset_comp bmi2_set_gyro_gain
* \code
* int8_t bmi2_set_gyro_gain(uint8_t gyro_gain, struct bmi2_dev *dev);
* \endcode
* @details This API enables/disables gyroscope gain for Sensitivity Error Compensation.
*
* @param[in] gyro_gain : Enables/Disables gyroscope gain.
* @param[in] dev : Structure instance of bmi2_dev.
*
*@verbatim
* enable | Description
* -------------|---------------
* BMI2_ENABLE | Enables gyroscope gain.
* BMI2_DISABLE | Disables gyroscope gain.
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_gyro_gain(uint8_t gyro_gain, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiGyroOC
* \page bmi2_api_bmi2_set_gyro_offset_comp bmi2_get_gyro_gain
* \code
* int8_t bmi2_get_gyro_gain(uint8_t *gyro_gain, struct bmi2_dev *dev);
* \endcode
* @details This API reads the Gyro gain.
*
* @param[in, out] gyro_gain : The value of the Gyro gain.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_gyro_gain(uint8_t *gyro_gain, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiGyroOC
* \page bmi2_api_bmi2_read_gyro_offset_comp_axes bmi2_read_gyro_offset_comp_axes
* \code
* int8_t bmi2_read_gyro_offset_comp_axes(struct bmi2_sens_axes_data *gyr_off_comp_axes, const struct bmi2_dev *dev);
* \endcode
* @details This API reads the gyroscope bias values for each axis which is used
* for gyroscope offset compensation.
*
* @param[out] gyr_off_comp_axes: Structure to store gyroscope offset
* compensated values.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_read_gyro_offset_comp_axes(struct bmi2_sens_axes_data *gyr_off_comp_axes, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiGyroOC
* \page bmi2_api_bmi2_write_gyro_offset_comp_axes bmi2_write_gyro_offset_comp_axes
* \code
* int8_t bmi2_write_gyro_offset_comp_axes(const struct bmi2_sens_axes_data *gyr_off_comp_axes, struct bmi2_dev *dev);
* \endcode
* @details This API writes the gyroscope bias values for each axis which is used
* for gyroscope offset compensation.
*
* @param[in] gyr_off_comp_axes : Structure to store gyroscope offset
* compensated values.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_write_gyro_offset_comp_axes(const struct bmi2_sens_axes_data *gyr_off_comp_axes, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiGyroCS Gyro cross sensitivity
* @brief Gyro Cross sensitivity operation
*/
/*!
* \ingroup bmi2ApiGyroCS
* \page bmi2_api_bmi2_get_gyro_cross_sense bmi2_get_gyro_cross_sense
* \code
* int8_t bmi2_get_gyro_cross_sense(struct bmi2_dev *dev);
* \endcode
* @details This API updates the cross sensitivity coefficient between gyroscope's
* X and Z axes.
*
* @param[in, out] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_gyro_cross_sense(struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiInts Internal Status
* @brief Get Internal Status of the sensor
*/
/*!
* \ingroup bmi2ApiInts
* \page bmi2_api_bmi2_get_internal_status bmi2_get_internal_status
* \code
* int8_t bmi2_get_internal_status(uint8_t *int_stat, const struct bmi2_dev *dev);
* \endcode
* @details This API gets error bits and message indicating internal status.
*
* @param[in] dev : Structure instance of bmi2_dev.
* @param[out] int_stat : Pointer variable to store error bits and
* message.
*
*@verbatim
* Internal status | *int_stat
* ---------------------|---------------------
* BMI2_NOT_INIT | 0x00
* BMI2_INIT_OK | 0x01
* BMI2_INIT_ERR | 0x02
* BMI2_DRV_ERR | 0x03
* BMI2_SNS_STOP | 0x04
* BMI2_NVM_ERROR | 0x05
* BMI2_START_UP_ERROR | 0x06
* BMI2_COMPAT_ERROR | 0x07
* BMI2_VFM_SKIPPED | 0x10
* BMI2_AXES_MAP_ERROR | 0x20
* BMI2_ODR_50_HZ_ERROR | 0x40
* BMI2_ODR_HIGH_ERROR | 0x80
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_internal_status(uint8_t *int_stat, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInts
* \page bmi2_api_bmi2_get_internal_error_status bmi2_get_internal_error_status
* \code
* int8_t bmi2_get_internal_error_status(uint8_t *status, struct bmi2_dev *dev);
* \endcode
* @details This API gets Interanl error status.
*
* @param[in] status : Pointer variable to store the status of the error
* @param[out] int_stat : Pointer variable to store error bits and
* message.
*
*@verbatim
* Internal status | status
* ---------------------------|---------------------
* BMI2_INTERNAL_ERROR_1_MASK | 0X02
* BMI2_INTERNAL_ERROR_2_MASK | 0X04
* BMI2_FEAT_ENG_DIS_MASK | 0X10
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_internal_error_status(uint8_t *status, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInts
* \page bmi2_api_bmi2_get_err_reg_mask bmi2_get_err_reg_mask
* \code
* int8_t bmi2_get_err_reg_mask(uint8_t *err_reg, struct bmi2_dev *dev);
* \endcode
* @details This API gets error status of interrupt.
*
* @param[in] err_reg : Pointer variable to store the status of the error
* @param[out] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Internal status | err_reg
* ---------------------------|---------------------
* BMI2_FATAL_ERR_MASK | 0X01
* BMI2_INTERNAL_ERR_MASK | 0X1E
* BMI2_FIFO_ERR_MASK | 0X40
* BMI2_AUX_ERR_MASK | 0x80
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_err_reg_mask(uint8_t *err_reg, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiInts
* \page bmi2_api_bmi2_set_err_reg_mask bmi2_set_err_reg_mask
* \code
* int8_t bmi2_set_err_reg_mask(uint8_t err_reg, struct bmi2_dev *dev);
* \endcode
* @details This API sets error interrupt.
*
* @param[in] err_reg : Variable to store the status of the error
* @param[out] dev : Structure instance of bmi2_dev.
*
*@verbatim
* Internal status | err_reg
* ---------------------------|---------------------
* BMI2_FATAL_ERR_MASK | 0X01
* BMI2_INTERNAL_ERR_MASK | 0X1E
* BMI2_FIFO_ERR_MASK | 0X40
* BMI2_AUX_ERR_MASK | 0x80
*@endverbatim
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_err_reg_mask(uint8_t err_reg, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiFOC FOC
* @brief FOC operations of the sensor
*/
/*!
* \ingroup bmi2ApiFOC
* \page bmi2_api_bmi2_perform_accel_foc bmi2_perform_accel_foc
* \code
* int8_t bmi2_perform_accel_foc(const struct bmi2_accel_foc_g_value *accel_g_value, struct bmi2_dev *dev);
* \endcode
* @details This API performs Fast Offset Compensation for accelerometer.
*
* @param[in] accel_g_value : This parameter selects the accel foc
* axis to be performed
*
* input format is {x, y, z, sign}. '1' to enable. '0' to disable
*
* eg to choose x axis {1, 0, 0, 0}
* eg to choose -x axis {1, 0, 0, 1}
*
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_perform_accel_foc(const struct bmi2_accel_foc_g_value *accel_g_value, struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiFOC
* \page bmi2_api_bmi2_perform_gyro_foc bmi2_perform_gyro_foc
* \code
* int8_t bmi2_perform_gyro_foc(struct bmi2_dev *dev);
* \endcode
* @details This API performs Fast Offset Compensation for gyroscope.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_perform_gyro_foc(struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiCRT CRT
* @brief CRT operations of the sensor
*/
/*!
* \ingroup bmi2ApiCRT
* \page bmi2_api_bmi2_do_crt bmi2_do_crt
* \code
* int8_t bmi2_do_crt(struct bmi2_dev *dev);
* \endcode
* @details API performs Component Re-Trim calibration (CRT).
*
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*
* @note CRT calibration takes approximately 500ms & maximum time out configured as 2 seconds
*/
int8_t bmi2_do_crt(struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiCRTSt CRT and self test
* @brief Enable / Abort CRT and self test operations of gyroscope
*/
/*!
* \ingroup bmi2ApiCRTSt
* \page bmi2_api_bmi2_abort_crt_gyro_st bmi2_abort_crt_gyro_st
* \code
* int8_t bmi2_abort_crt_gyro_st(struct bmi2_dev *dev);
* \endcode
* @details This api is used to abort ongoing crt or gyro self test.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_abort_crt_gyro_st(struct bmi2_dev *dev);
/*!
* \ingroup bmi2ApiASelftest
* \page bmi2_api_bmi2_do_gyro_st bmi2_do_gyro_st
* \code
* int8_t bmi2_do_gyro_st
* \endcode
* @details this api is used to perform gyroscope self test.
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_do_gyro_st(struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2ApiNVM NVM
* @brief NVM operations of the sensor
*/
/*!
* \ingroup bmi2ApiNVM
* \page bmi2_api_bmi2_nvm_prog bmi2_nvm_prog
* \code
* int8_t bmi2_nvm_prog
* \endcode
* @details This api is used for programming the non volatile memory(nvm)
*
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_nvm_prog(struct bmi2_dev *dev);
/*!
* @brief This API extracts the input feature configuration
* details like page and start address from the look-up table.
*
* @param[out] feat_config : Structure that stores feature configurations.
* @param[in] type : Type of feature or sensor.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Returns the feature found flag.
*
* @retval BMI2_FALSE : Feature not found
* BMI2_TRUE : Feature found
*/
uint8_t bmi2_extract_input_feat_config(struct bmi2_feature_config *feat_config, uint8_t type,
const struct bmi2_dev *dev);
/*!
* @brief This API is used to get the feature configuration from the
* selected page.
*
* @param[in] sw_page : Switches to the desired page.
* @param[out] feat_config : Pointer to the feature configuration.
* @param[in] dev : Structure instance of bmi2_dev.
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_feat_config(uint8_t sw_page, uint8_t *feat_config, struct bmi2_dev *dev);
/**
* \ingroup bmi2
* \defgroup bmi2AccelOffset Accelerometer Offset Compensation
* @brief Enable / Disable Accelerometer Offset Compensation
*/
/*!
* \ingroup bmi2AccelOffset
* \page bmi2_api_bmi2_set_accel_offset_comp bmi2_set_accel_offset_comp
* \code
* int8_t bmi2_set_accel_offset_comp(uint8_t offset_en, struct bmi2_dev *dev);
* \endcode
* @brief This internal API enables/disables the offset compensation for
* filtered and un-filtered accelerometer data.
*
* @param[in] offset_en : enables/disables offset compensation.
* @param[in] dev : Structure instance of bmi2_dev
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_set_accel_offset_comp(uint8_t offset_en, struct bmi2_dev *dev);
/*!
* \ingroup bmi2AccelOffset
* \page bmi2_api_bmi2_get_accel_offset_comp bmi2_get_accel_offset_comp
* \code
* int8_t bmi2_get_accel_offset_comp(uint8_t *accel_offset, struct bmi2_dev *dev);
* \endcode
* @brief This internal API reads the accelerometer offset compensation value.
*
* @param[in] accel_offset : Pointer to an array of size 3 to hold Accel Axis X, Y, Z,
* Offset Compensation.
* @param[in] dev : Structure instance of bmi2_dev
*
* @return Result of API execution status
* @retval 0 -> Success
* @retval < 0 -> Fail
*/
int8_t bmi2_get_accel_offset_comp(uint8_t *accel_offset, struct bmi2_dev *dev);
#ifdef __cplusplus
}
#endif /* End of CPP guard */
#endif /* BMI2_H_ */