Skip to content

Commit

Permalink
Updated i2c
Browse files Browse the repository at this point in the history
  • Loading branch information
aeraterta committed Jan 22, 2025
1 parent 21feb5c commit f616cdb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 35 deletions.
44 changes: 22 additions & 22 deletions src/adxl345.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/

int8_t adxl345_write_register_value(uint8_t dev_addr, uint8_t *data_buffer) {
return i2c_write_bytes(dev_addr, data_buffer);
return i2c_write_byte(dev_addr, data_buffer);
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ int8_t adxl345_set_power_mode(adxl345_dev *device, adxl345_power_mode mode) {
device->power_mode = mode;

uint8_t data_buffer[] = {ADXL345_REG_BW_RATE, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand Down Expand Up @@ -178,7 +178,7 @@ int8_t adxl345_set_measure_mode(adxl345_dev *device,
device->measure = measure;

uint8_t data_buffer[] = {ADXL345_REG_POWER_CTL, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand Down Expand Up @@ -215,7 +215,7 @@ int8_t adxl345_set_odr(adxl345_dev *device, adxl345_odr odr) {
device->odr = odr;

uint8_t data_buffer[] = {ADXL345_REG_BW_RATE, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand Down Expand Up @@ -260,7 +260,7 @@ int8_t adxl345_set_scale(adxl345_dev *device, adxl345_scale_config scale) {
}

uint8_t data_buffer[] = {ADXL345_REG_DATA_FORMAT, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand Down Expand Up @@ -314,7 +314,7 @@ int8_t adxl345_set_resolution(adxl345_dev *device,
}

uint8_t data_buffer[] = {ADXL345_REG_DATA_FORMAT, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand All @@ -335,7 +335,7 @@ int8_t adxl345_set_offset_x(adxl345_dev *device, int8_t offset) {
device->offset_config.x = offset;

uint8_t data_buffer[] = {ADXL345_REG_OFFSET_X, offset};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand All @@ -356,7 +356,7 @@ int8_t adxl345_set_offset_y(adxl345_dev *device, int8_t offset) {
device->offset_config.y = offset;

uint8_t data_buffer[] = {ADXL345_REG_OFFSET_Y, offset};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand All @@ -377,7 +377,7 @@ int8_t adxl345_set_offset_z(adxl345_dev *device, int8_t offset) {
device->offset_config.z = offset;

uint8_t data_buffer[] = {ADXL345_REG_OFFSET_Z, offset};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

/**
Expand All @@ -397,31 +397,31 @@ int8_t adxl345_set_tap_threshold(adxl345_dev *device, uint8_t threshold) {
device->tap_config.threshold = threshold;

uint8_t data_buffer[] = {ADXL345_REG_THRESH_TAP, threshold};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// Add doxygen
int8_t adxl345_set_tap_duration(adxl345_dev *device, int8_t duration) {
device->tap_config.duration = duration;

uint8_t data_buffer[] = {ADXL345_REG_DUR, duration};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
int8_t adxl345_set_tap_latency(adxl345_dev *device, int8_t latency) {
device->tap_config.latency = latency;

uint8_t data_buffer[] = {ADXL345_REG_LATENT, latency};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
int8_t adxl345_set_tap_window(adxl345_dev *device, int8_t window) {
device->tap_config.window = window;

uint8_t data_buffer[] = {ADXL345_REG_WINDOW, window};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
Expand All @@ -440,23 +440,23 @@ int8_t adxl345_tap_axes_enable(adxl345_dev *device,
device->tap_config.tap_en = tap_en;

uint8_t data_buffer[] = {ADXL345_REG_TAP_AXES, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
int8_t adxl345_set_activity_threshold(adxl345_dev *device, int8_t threshold) {
device->activity_config.activity_threshold = threshold;

uint8_t data_buffer[] = {ADXL345_REG_THRESH_ACT, threshold};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
int8_t adxl345_set_inactivity_threshold(adxl345_dev *device, int8_t threshold) {
device->activity_config.inactivity_threshold = threshold;

uint8_t data_buffer[] = {ADXL345_REG_THRESH_INACT, threshold};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
Expand All @@ -475,7 +475,7 @@ int8_t adxl345_set_activity_axes_enable(adxl345_dev *device,
device->activity_config.activity_en = activity_en;

uint8_t data_buffer[] = {ADXL345_REG_ACT_INACT_CTL, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
Expand All @@ -494,23 +494,23 @@ int8_t adxl345_set_inactivity_axes_enable(adxl345_dev *device,
device->activity_config.inactivity_en = inactivity_en;

uint8_t data_buffer[] = {ADXL345_REG_ACT_INACT_CTL, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
int8_t adxl345_set_freefall_threshold(adxl345_dev *device, int8_t threshold) {
device->freefall_config.threshold = threshold;

uint8_t data_buffer[] = {ADXL345_REG_THRESH_FF, threshold};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
int8_t adxl345_set_freefall_timeout(adxl345_dev *device, int8_t timeout) {
device->freefall_config.timeout = timeout;

uint8_t data_buffer[] = {ADXL345_REG_TIME_FF, timeout};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
Expand Down Expand Up @@ -544,7 +544,7 @@ int8_t adxl345_set_interrupt_enable(adxl345_dev *device, uint8_t interrupt,
val = val | enable << interrupt;

uint8_t data_buffer[] = {ADXL345_REG_INT_ENABLE, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
Expand All @@ -559,7 +559,7 @@ int8_t adxl345_set_interrupt_map(adxl345_dev *device, uint8_t interrupt,
val = val | map << interrupt;

uint8_t data_buffer[] = {ADXL345_REG_INT_MAP, val};
return i2c_write_bytes(ADXL345_I2C_ADDRESS, data_buffer);
return i2c_write_byte(ADXL345_I2C_ADDRESS, data_buffer);
}

// ADD DOXYGEN
Expand Down
2 changes: 1 addition & 1 deletion src/utils
Submodule utils updated 3 files
+22 −1 i2c.c
+4 −1 i2c.h
+2 −2 utils.c
24 changes: 12 additions & 12 deletions test/test_adxl345.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ void test_adxl345_set_power_mode(void) {
i2c_read_byte_IgnoreArg_read_data();
i2c_read_byte_ReturnThruPtr_read_data(&read_data_result);

i2c_write_bytes_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
i2c_write_byte_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
ADXL345_STATUS_SUCCESS);
i2c_write_bytes_IgnoreArg_data_buffer();
i2c_write_byte_IgnoreArg_data_buffer();

TEST_ASSERT_EQUAL(ADXL345_STATUS_SUCCESS,
adxl345_set_power_mode(&dev, ADXL345_NORMAL_MODE));
Expand All @@ -45,9 +45,9 @@ void test_adxl345_set_measure_mode(void) {
i2c_read_byte_IgnoreArg_read_data();
i2c_read_byte_ReturnThruPtr_read_data(&read_data_result);

i2c_write_bytes_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
i2c_write_byte_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
ADXL345_STATUS_SUCCESS);
i2c_write_bytes_IgnoreArg_data_buffer();
i2c_write_byte_IgnoreArg_data_buffer();

TEST_ASSERT_EQUAL(ADXL345_STATUS_SUCCESS,
adxl345_set_measure_mode(&dev, ADXL345_MEASURE_MODE));
Expand All @@ -61,9 +61,9 @@ void test_adxl345_set_odr_sucessful(void) {
i2c_read_byte_IgnoreArg_read_data();
i2c_read_byte_ReturnThruPtr_read_data(&read_data_result);

i2c_write_bytes_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
i2c_write_byte_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
ADXL345_STATUS_SUCCESS);
i2c_write_bytes_IgnoreArg_data_buffer();
i2c_write_byte_IgnoreArg_data_buffer();

TEST_ASSERT_EQUAL(ADXL345_STATUS_SUCCESS,
adxl345_set_odr(&dev, ADXL345_ODR_200HZ));
Expand All @@ -89,9 +89,9 @@ void test_adxl345_set_scale(void) {
i2c_read_byte_IgnoreArg_read_data();
i2c_read_byte_ReturnThruPtr_read_data(&read_data_result);

i2c_write_bytes_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
i2c_write_byte_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
ADXL345_STATUS_SUCCESS);
i2c_write_bytes_IgnoreArg_data_buffer();
i2c_write_byte_IgnoreArg_data_buffer();

TEST_ASSERT_EQUAL(ADXL345_STATUS_SUCCESS, adxl345_set_scale(&dev, scale));
TEST_ASSERT_EQUAL(dev.scale.scale, ADXL345_SCALE_8G);
Expand All @@ -108,9 +108,9 @@ void test_adxl345_set_resolution(void) {
i2c_read_byte_IgnoreArg_read_data();
i2c_read_byte_ReturnThruPtr_read_data(&read_data_result);

i2c_write_bytes_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
i2c_write_byte_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
ADXL345_STATUS_SUCCESS);
i2c_write_bytes_IgnoreArg_data_buffer();
i2c_write_byte_IgnoreArg_data_buffer();

TEST_ASSERT_EQUAL(ADXL345_STATUS_SUCCESS,
adxl345_set_resolution(&dev, resolution));
Expand All @@ -120,9 +120,9 @@ void test_adxl345_set_resolution(void) {
}

void test_adxl345_set_tap_threshold(void) {
i2c_write_bytes_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
i2c_write_byte_ExpectAndReturn(ADXL345_I2C_ADDRESS, NULL,
ADXL345_STATUS_SUCCESS);
i2c_write_bytes_IgnoreArg_data_buffer();
i2c_write_byte_IgnoreArg_data_buffer();
TEST_ASSERT_EQUAL(ADXL345_STATUS_SUCCESS,
adxl345_set_tap_threshold(&dev, 0x10));
TEST_ASSERT_EQUAL(dev.tap_config.threshold, 0x10);
Expand Down

0 comments on commit f616cdb

Please sign in to comment.