Skip to content

Commit

Permalink
Update i2c calls to use updated/corrected function names
Browse files Browse the repository at this point in the history
  • Loading branch information
drashna committed Feb 25, 2025
1 parent 7fc6c5d commit 5552197
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
10 changes: 5 additions & 5 deletions users/drashna/features/rtc/ds1307.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ i2c_status_t ds1307_set_time(rtc_time_t t) {
};
// clang-format on

if (i2c_writeReg(DS1307_I2C_ADDRESS << 1, DS1307_TIME_REG, data, ARRAY_SIZE(data), DS1307_I2C_TIMEOUT) !=
if (i2c_write_register(DS1307_I2C_ADDRESS << 1, DS1307_TIME_REG, data, ARRAY_SIZE(data), DS1307_I2C_TIMEOUT) !=
I2C_STATUS_SUCCESS) {
uprintf("Error while sending time to RTC!\n");
return I2C_STATUS_ERROR;
Expand All @@ -51,7 +51,7 @@ i2c_status_t ds1307_get_time(rtc_time_t *time) {
uint8_t data[7] = {0, 0, 0, 0, 0, 0, 0};

i2c_status_t status =
i2c_readReg(DS1307_I2C_ADDRESS << 1, DS1307_TIME_REG, data, ARRAY_SIZE(data), DS1307_I2C_TIMEOUT);
i2c_read_register(DS1307_I2C_ADDRESS << 1, DS1307_TIME_REG, data, ARRAY_SIZE(data), DS1307_I2C_TIMEOUT);
if (status != I2C_STATUS_SUCCESS) {
return status;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ i2c_status_t ds1307_get_time(rtc_time_t *time) {
*/
bool ds1307_has_lost_power(void) {
uint8_t status[1] = {0};
i2c_readReg(DS1307_I2C_ADDRESS << 1, DS1307_TIME_REG, status, ARRAY_SIZE(status), DS1307_I2C_TIMEOUT);
i2c_read_register(DS1307_I2C_ADDRESS << 1, DS1307_TIME_REG, status, ARRAY_SIZE(status), DS1307_I2C_TIMEOUT);
return status[0] >> 7;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ i2c_status_t ds1307_read_nvram(uint8_t address, uint8_t *data, uint16_t len) {
} else if (address + len > 0x3F) {
len = 0x3F - address;
}
return i2c_readReg(DS1307_I2C_ADDRESS << 1, address, data, len, DS1307_I2C_TIMEOUT);
return i2c_read_register(DS1307_I2C_ADDRESS << 1, address, data, len, DS1307_I2C_TIMEOUT);
}

/**
Expand All @@ -185,5 +185,5 @@ i2c_status_t ds1307_write_nvram(uint8_t address, uint8_t *data, uint16_t len) {
} else if (address + len > 0x3F) {
len = 0x3F - address;
}
return i2c_writeReg(DS1307_I2C_ADDRESS << 1, address, data, len, DS1307_I2C_TIMEOUT);
return i2c_write_register(DS1307_I2C_ADDRESS << 1, address, data, len, DS1307_I2C_TIMEOUT);
}
17 changes: 9 additions & 8 deletions users/drashna/features/rtc/ds3231.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@ i2c_status_t ds3231_set_time(rtc_time_t t) {
};
// clang-format on

if (i2c_writeReg(DS3231_I2C_ADDRESS << 1, DS3231_TIME_REG, data, ARRAY_SIZE(data), DS3231_I2C_TIMEOUT) !=
if (i2c_write_register(DS3231_I2C_ADDRESS << 1, DS3231_TIME_REG, data, ARRAY_SIZE(data), DS3231_I2C_TIMEOUT) !=
I2C_STATUS_SUCCESS) {
dprintf("Error while sending time to RTC!\n");
return I2C_STATUS_ERROR;
}

uint8_t status[1] = {0};

if (i2c_readReg(DS3231_I2C_ADDRESS << 1, DS3231_STATUS_REG, status, ARRAY_SIZE(status), DS3231_I2C_TIMEOUT) !=
if (i2c_read_register(DS3231_I2C_ADDRESS << 1, DS3231_STATUS_REG, status, ARRAY_SIZE(status), DS3231_I2C_TIMEOUT) !=
I2C_STATUS_SUCCESS) {
dprintf("Error while reading status!\n");
return I2C_STATUS_ERROR;
}

status[0] &= ~0x80; // flip OSF bit

return i2c_writeReg(DS3231_I2C_ADDRESS << 1, DS3231_STATUS_REG, status, ARRAY_SIZE(status), DS3231_I2C_TIMEOUT);
return i2c_write_register(DS3231_I2C_ADDRESS << 1, DS3231_STATUS_REG, status, ARRAY_SIZE(status),
DS3231_I2C_TIMEOUT);
}

/**
Expand All @@ -62,7 +63,7 @@ i2c_status_t ds3231_get_time(rtc_time_t *time) {
uint8_t data[7] = {0, 0, 0, 0, 0, 0, 0};

i2c_status_t status =
i2c_readReg(DS3231_I2C_ADDRESS << 1, DS3231_TIME_REG, data, ARRAY_SIZE(data), DS3231_I2C_TIMEOUT);
i2c_read_register(DS3231_I2C_ADDRESS << 1, DS3231_TIME_REG, data, ARRAY_SIZE(data), DS3231_I2C_TIMEOUT);
if (status != I2C_STATUS_SUCCESS) {
return status;
}
Expand Down Expand Up @@ -95,7 +96,7 @@ i2c_status_t ds3231_get_time(rtc_time_t *time) {
*/
bool ds3231_has_lost_power(void) {
uint8_t status[1] = {0};
i2c_readReg(DS3231_I2C_ADDRESS << 1, DS3231_STATUS_REG, status, ARRAY_SIZE(status), DS3231_I2C_TIMEOUT);
i2c_read_register(DS3231_I2C_ADDRESS << 1, DS3231_STATUS_REG, status, ARRAY_SIZE(status), DS3231_I2C_TIMEOUT);
return status[0] >> 7;
}

Expand All @@ -106,7 +107,7 @@ bool ds3231_has_lost_power(void) {
*/
int8_t ds3231_get_aging_offset(void) {
uint8_t offset[1] = {0};
i2c_readReg(DS3231_I2C_ADDRESS << 1, DS3231_AGING_OFFSET_REG, offset, ARRAY_SIZE(offset), DS3231_I2C_TIMEOUT);
i2c_read_register(DS3231_I2C_ADDRESS << 1, DS3231_AGING_OFFSET_REG, offset, ARRAY_SIZE(offset), DS3231_I2C_TIMEOUT);
return (int8_t)offset[0];
}

Expand All @@ -117,7 +118,7 @@ int8_t ds3231_get_aging_offset(void) {
*/
void ds3231_set_aging_offset(int8_t offset) {
uint8_t data[1] = {(uint8_t)offset};
i2c_writeReg(DS3231_I2C_ADDRESS << 1, DS3231_AGING_OFFSET_REG, data, ARRAY_SIZE(data), DS3231_I2C_TIMEOUT);
i2c_write_register(DS3231_I2C_ADDRESS << 1, DS3231_AGING_OFFSET_REG, data, ARRAY_SIZE(data), DS3231_I2C_TIMEOUT);
}

/**
Expand All @@ -128,7 +129,7 @@ void ds3231_set_aging_offset(int8_t offset) {
float ds3231_get_temperature(void) {
uint8_t temp[2] = {0};

i2c_readReg(DS3231_I2C_ADDRESS << 1, DS3231_TEMPERATURE_REG, temp, ARRAY_SIZE(temp), DS3231_I2C_TIMEOUT);
i2c_read_register(DS3231_I2C_ADDRESS << 1, DS3231_TEMPERATURE_REG, temp, ARRAY_SIZE(temp), DS3231_I2C_TIMEOUT);
return (float)temp[0] + (float)(temp[1] >> 6) * 0.25;
}

Expand Down
16 changes: 8 additions & 8 deletions users/drashna/features/rtc/pcf8523.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ i2c_status_t pcf8523_set_time(rtc_time_t t) {
rtc_bin2bcd(t.year - 2000U)
};

if (i2c_writeReg(PCF8523_I2C_ADDRESS << 1, PCF8523_TIME_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT) != I2C_STATUS_SUCCESS) {
if (i2c_write_register(PCF8523_I2C_ADDRESS << 1, PCF8523_TIME_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT) != I2C_STATUS_SUCCESS) {
uprintf("Error while sending time to RTC!\n");
return I2C_STATUS_ERROR;
}

uint8_t status[1] = {0}; // set to battery switchover mode
return i2c_writeReg(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_3_REG, status, ARRAY_SIZE(status), PCF8523_I2C_TIMEOUT);
return i2c_write_register(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_3_REG, status, ARRAY_SIZE(status), PCF8523_I2C_TIMEOUT);
}

/**
Expand All @@ -49,7 +49,7 @@ i2c_status_t pcf8523_set_time(rtc_time_t t) {
i2c_status_t pcf8523_get_time(rtc_time_t *time) {
uint8_t data[7] = {0, 0, 0, 0, 0, 0, 0};

i2c_status_t status = i2c_readReg(PCF8523_I2C_ADDRESS << 1, PCF8523_TIME_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
i2c_status_t status = i2c_read_register(PCF8523_I2C_ADDRESS << 1, PCF8523_TIME_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
if (status != I2C_STATUS_SUCCESS) {
return status;
}
Expand Down Expand Up @@ -82,7 +82,7 @@ i2c_status_t pcf8523_get_time(rtc_time_t *time) {
*/
bool pcf8523_has_lost_power(void) {
uint8_t status[1] = {0};
i2c_readReg(PCF8523_I2C_ADDRESS << 1, PCF8523_STATUS_REG, status, ARRAY_SIZE(status), PCF8523_I2C_TIMEOUT);
i2c_read_register(PCF8523_I2C_ADDRESS << 1, PCF8523_STATUS_REG, status, ARRAY_SIZE(status), PCF8523_I2C_TIMEOUT);
return status[0] >> 7;
}

Expand All @@ -100,7 +100,7 @@ bool pcf8523_init(rtc_time_t *time) {
i2c_init();

uint8_t data[1] = {0};
i2c_status_t status = i2c_readReg(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_3_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
i2c_status_t status = i2c_read_register(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_3_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
pcf8523_initialized = (status == I2C_STATUS_SUCCESS) && ((data[0] & 0xE0) != 0xE0) ;
if (pcf8523_initialized) {
pcf8523_initialized = true;
Expand All @@ -123,11 +123,11 @@ bool pcf8523_init(rtc_time_t *time) {
}

// check clock stop bit
i2c_readReg(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_1_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
i2c_read_register(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_1_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
// if clock is stopped, start it
if (data[0] & (1<<5)) {
data[0] &= ~(1<<5);
i2c_writeReg(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_1_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
i2c_write_register(PCF8523_I2C_ADDRESS << 1, PCF8523_CONTROL_1_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
};
return pcf8523_initialized;
}
Expand All @@ -141,7 +141,7 @@ bool pcf8523_init(rtc_time_t *time) {
*/
i2c_status_t pcf8523_calibate(pcf8523_offset_mode_t mode, int8_t offset) {
uint8_t data[1] = { ((uint8_t)offset & 0x7F) | mode };
return i2c_writeReg(PCF8523_I2C_ADDRESS << 1, PCF8523_OFFSET_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
return i2c_write_register(PCF8523_I2C_ADDRESS << 1, PCF8523_OFFSET_REG, data, ARRAY_SIZE(data), PCF8523_I2C_TIMEOUT);
}

/**
Expand Down

0 comments on commit 5552197

Please sign in to comment.