diff --git a/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.c b/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.c index d6171b57e49..fa4ddfd3a12 100644 --- a/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.c +++ b/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.c @@ -65,32 +65,34 @@ int16_t __adxl363_read_axis_data(uint8_t lsig_addr, uint8_t msig_addr, int *err) void __reset_variables(void) { - memset(&read_reg_req,0, sizeof(mxc_spi_req_t)); - memset(&write_reg_req,0, sizeof(mxc_spi_req_t)); - memset(&read_fifo_req,0, sizeof(mxc_spi_req_t)); + memset(&read_reg_req, 0, sizeof(mxc_spi_req_t)); + memset(&write_reg_req, 0, sizeof(mxc_spi_req_t)); + memset(&read_fifo_req, 0, sizeof(mxc_spi_req_t)); write_reg_pack[1] = 0; write_reg_pack[2] = 0; read_reg_pack[1] = 0; - memset(adxl_363_fifo_tx_buff + 1, 0, ADXL_363_FIFO_TX_BUFF_SIZE-1); + memset(adxl_363_fifo_tx_buff + 1, 0, ADXL_363_FIFO_TX_BUFF_SIZE - 1); memset(adxl_363_fifo_rx_buff, 0, ADXL_363_FIFO_RX_BUFF_SIZE); return; } - int adxl363_axis_read(int16_t *axis_data, adxl_axis_t axis_id) { int16_t local_axis_val = 0; int ret_val = 0; if (axis_id == X_AXIS) { - local_axis_val = __adxl363_read_axis_data(ADXL_363_REG_XDATA_L, ADXL_363_REG_XDATA_H, &ret_val); + local_axis_val = + __adxl363_read_axis_data(ADXL_363_REG_XDATA_L, ADXL_363_REG_XDATA_H, &ret_val); *axis_data = local_axis_val; } else if (axis_id == Y_AXIS) { - local_axis_val = __adxl363_read_axis_data(ADXL_363_REG_YDATA_L, ADXL_363_REG_YDATA_H, &ret_val); + local_axis_val = + __adxl363_read_axis_data(ADXL_363_REG_YDATA_L, ADXL_363_REG_YDATA_H, &ret_val); *axis_data = local_axis_val; } else if (axis_id == Z_AXIS) { - local_axis_val = __adxl363_read_axis_data(ADXL_363_REG_ZDATA_L, ADXL_363_REG_ZDATA_H, &ret_val); + local_axis_val = + __adxl363_read_axis_data(ADXL_363_REG_ZDATA_L, ADXL_363_REG_ZDATA_H, &ret_val); *axis_data = local_axis_val; } else { *axis_data = -1; @@ -121,7 +123,7 @@ int adxl363_fifo_enable_mode(uint8_t mode) uint8_t current_status = 0; // If the mode is between [0,3] - if ((mode & 0xFC) == 0 ) { + if ((mode & 0xFC) == 0) { ret_val = adxl363_reg_read(ADXL_363_REG_POWER_CTL, ¤t_status); if (ret_val == 0) { current_status = current_status & 0xfc; @@ -163,7 +165,7 @@ int adxl363_fifo_read(uint8_t *buff, uint16_t sample_count) ret_val = E_ADXL363_NULL_PARAM; } else { read_fifo_req.rxData = adxl_363_fifo_rx_buff; - + // 1 byte is spent during transaction to send READ_FIFO command. read_fifo_req.txLen = transaction_size + 1; read_fifo_req.txData = adxl_363_fifo_tx_buff; @@ -186,10 +188,9 @@ int adxl363_fifo_set_sample_count(uint16_t sample_count) uint8_t fifo_ctrl_reg_val = 0; if (sample_count <= MAX_FIFO_SAMPLE_COUNT) { - if (0xff < sample_count) { // We need to set AH bit to 1. However, we need to read - // FIFO control resister first not + // FIFO control resister first not adxl363_reg_read(ADXL_363_REG_FIFO_CONTROL, &fifo_ctrl_reg_val); adxl363_reg_write(ADXL_363_REG_FIFO_CONTROL, fifo_ctrl_reg_val | 8); @@ -234,48 +235,39 @@ int adxl363_init(adxl_363_spi_t spi_conf, adxl_363_controller_t adxl_conf) // ret_val = adxl363_reg_write(ADXL_363_REG_FILTER_CTL, adxl_conf.odr | adxl_conf.range); - // adxl363_spi_conf._16_4_ = spi_conf._0_4_; - // adxl363_conf = spi_conf.spi_speed; - // adxl363_spi_conf._0_4_ = (uint)(uint8_t)adxl_conf; - // adxl363_spi_conf.spi_speed = in_r1; - // adxl363_spi_conf.spi_pins._0_4_ = in_r2; - // adxl363_spi_conf.spi_pins._4_4_ = in_r3; } - + return ret_val; } -CODE_TO_COMMENT_OUT( - int adxl363_intmap_conf(uint8_t int_mask, uint8_t intpin_id) - { - adxl363_reg_t reg_addr; - int ret_val = 0; - - if (intpin_id == 1 || intpin_id == 2) { - if (intpin_id == 1) { - reg_addr = ADXL_363_REG_INTMAP1; - } else { - reg_addr = ADXL_363_REG_INTMAP2; - } +CODE_TO_COMMENT_OUT(int adxl363_intmap_conf(uint8_t int_mask, uint8_t intpin_id) { + adxl363_reg_t reg_addr; + int ret_val = 0; - ret_val = adxl363_reg_write(reg_addr, int_mask); + if (intpin_id == 1 || intpin_id == 2) { + if (intpin_id == 1) { + reg_addr = ADXL_363_REG_INTMAP1; } else { - ret_val = E_ADXL363_INVALID_PARAM; + reg_addr = ADXL_363_REG_INTMAP2; } - return ret_val; + + ret_val = adxl363_reg_write(reg_addr, int_mask); + } else { + ret_val = E_ADXL363_INVALID_PARAM; } -) + return ret_val; +}) int adxl363_reg_read(adxl363_reg_t reg_addr, uint8_t *read_buff) { int ret_val = 0; - uint8_t read_data[3] = {0}; + uint8_t read_data[3] = { 0 }; if (read_buff != NULL) { ret_val = __adxl363_reg_read(reg_addr, read_data, 1); *read_buff = read_data[2]; - }else{ - ret_val = E_ADXL363_NULL_PARAM; + } else { + ret_val = E_ADXL363_NULL_PARAM; } return ret_val; @@ -292,6 +284,34 @@ int adxl363_reg_write(adxl363_reg_t reg_addr, uint8_t val) return MXC_SPI_MasterTransaction(&write_reg_req); } +int adxl363_fifo_read_sample_set(uint8_t *buff, bool temp_data) +{ + int ret_val = 0; + uint8_t reg_data = 0; + uint16_t sample[4] = { 0 }; + + adxl363_reg_read(ADXL_363_REG_FIFO_CONTROL, ®_data); + + if (reg_data & (1 << 2)) { + // Temperature data will be in sample set. So, read 4 bytes. + ret_val = adxl363_fifo_read((uint8_t *)&sample, 4); + + } else { + // Temperature data is not in sample set. So, read 3 bytes. + ret_val = adxl363_fifo_read((uint8_t *)&sample, 3); + } + + if (0 < ret_val) { + if (temp_data) { + memcpy(buff, &sample, 8); + } else { + memcpy(buff, &sample, 6); + } + } + + return ret_val; +} + int adxl363_shutdown(void) { int ret_val = 0; diff --git a/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.h b/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.h index 0f1d5d19491..6488461c1a3 100644 --- a/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.h +++ b/Libraries/MiscDrivers/ACCEL/ADXL/adxl363.h @@ -221,6 +221,7 @@ int adxl363_init(adxl_363_spi_t spi_conf, adxl_363_controller_t adxl_conf); CODE_TO_COMMENT_OUT(int adxl363_intmap_conf(uint8_t int_mask, uint8_t intpin_id);) int adxl363_reg_read(adxl363_reg_t reg_addr, uint8_t * read_buff); +int adxl363_fifo_read_sample_set(uint8_t *buff, bool temp_data); int adxl363_reg_write(adxl363_reg_t reg_addr, uint8_t val); int adxl363_shutdown(void);