Skip to content

Commit

Permalink
Developments continued
Browse files Browse the repository at this point in the history
  • Loading branch information
kilicomercan committed Jun 28, 2024
1 parent 4932af5 commit c3ea8fd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 38 deletions.
96 changes: 58 additions & 38 deletions Libraries/MiscDrivers/ACCEL/ADXL/adxl363.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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, &current_status);
if (ret_val == 0) {
current_status = current_status & 0xfc;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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, &reg_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;
Expand Down
1 change: 1 addition & 0 deletions Libraries/MiscDrivers/ACCEL/ADXL/adxl363.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit c3ea8fd

Please sign in to comment.