void ms2100_init( void ) { ms2100_arch_init(); uint8_t i; for (i=0; i<MS2100_NB_AXIS; i++) ms2100_values[i] = 0; ms2100_status = MS2100_IDLE; }
void ms2100_init(struct Ms2100 *ms, struct spi_periph *spi_p, uint8_t slave_idx) { /* set spi_peripheral */ ms->spi_p = spi_p; /* configure spi transaction for the request */ ms->req_trans.cpol = SPICpolIdleLow; ms->req_trans.cpha = SPICphaEdge1; ms->req_trans.dss = SPIDss8bit; ms->req_trans.bitorder = SPIMSBFirst; ms->req_trans.cdiv = SPIDiv64; ms->req_trans.slave_idx = slave_idx; ms->req_trans.select = SPISelectUnselect; ms->req_trans.output_buf = ms->req_buf; ms->req_trans.output_length = 1; ms->req_trans.input_buf = NULL; ms->req_trans.input_length = 0; // ms2100 has to be reset before each measurement: implemented in ms2100_arch.c ms->req_trans.before_cb = ms2100_reset_cb; ms->req_trans.status = SPITransDone; /* configure spi transaction to read the result */ ms->read_trans.cpol = SPICpolIdleLow; ms->read_trans.cpha = SPICphaEdge1; ms->read_trans.dss = SPIDss8bit; ms->read_trans.bitorder = SPIMSBFirst; ms->read_trans.cdiv = SPIDiv64; ms->read_trans.slave_idx = slave_idx; ms->read_trans.select = SPISelectUnselect; ms->read_trans.output_buf = NULL; ms->read_trans.output_length = 0; ms->read_trans.input_buf = ms->read_buf; ms->read_trans.input_length = 2; ms->read_trans.before_cb = NULL; ms->read_trans.after_cb = NULL; ms->read_trans.status = SPITransDone; ms2100_arch_init(); INT_VECT3_ZERO(ms->data.vect); ms->cur_axe = 0; ms->status = MS2100_IDLE; }