Skip to content

Conversation

seov-nordic
Copy link
Member

Change the npm13xx_charger fetch function to first trigger a sample and then block until the result is available.

@seov-nordic seov-nordic force-pushed the npm13xx-charger-improve-measurement-fetching branch from 72ae685 to 7ea2956 Compare August 21, 2025 08:26
Copy link

Copy link
Contributor

@nordic-auko nordic-auko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick

};

return i2c_write_dt(&config->i2c, buff, sizeof(buff));
return i2c_transfer_dt(&config->i2c, msg, 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick:

Suggested change
return i2c_transfer_dt(&config->i2c, msg, 2);
return i2c_transfer_dt(&config->i2c, msg, ARRAY_SIZE(msg));

@seov-nordic
Copy link
Member Author

@anangl or @masz-nordic, could you please take a look?

@carlescufi carlescufi assigned nordic-auko and unassigned anangl and masz-nordic Oct 2, 2025
@carlescufi
Copy link
Member

Reassigned, see

- nordic-auko

@henrikbrixandersen
Copy link
Member

Retriggered CI.

@anangl
Copy link
Member

anangl commented Oct 2, 2025

@seov-nordic This PR needs to be rebased to solve the CI failures.

Change the npm13xx_charger fetch function to first trigger a sample
and then block until the result is available.

Signed-off-by: Sergei Ovchinnikov <[email protected]>
@seov-nordic seov-nordic force-pushed the npm13xx-charger-improve-measurement-fetching branch from 7ea2956 to 8b6d2ec Compare October 15, 2025 06:37
Copy link

@kartben kartben requested a review from Copilot October 15, 2025 09:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves the sample fetching mechanism in the npm13xx_charger driver by changing the approach from triggering measurements individually to batching them together and waiting for completion. The key change is to trigger all ADC measurements at once and then block until the results are available, making the sampling process more efficient.

  • Replaced sequential ADC triggering with burst triggering for all measurements
  • Added proper timing synchronization with a calculated wait period
  • Updated the MFD driver to support burst writes instead of individual register writes

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
include/zephyr/drivers/mfd/npm13xx.h Updated function signature and documentation for burst write functionality
drivers/sensor/nordic/npm13xx_charger/npm13xx_charger.c Restructured sample fetching to batch ADC triggers and wait for completion
drivers/mfd/mfd_npm13xx.c Implemented burst write function using I2C message transfer

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +310 to +311
ret = mfd_npm13xx_reg_write_burst(config->mfd, ADC_BASE, ADC_OFFSET_TASK_VBAT,
(uint8_t []){1U, 1U, 1U}, 3U);
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The compound literal array should be assigned to a named constant for better readability and maintainability. Consider defining a constant like static const uint8_t adc_trigger_pattern[] = {1U, 1U, 1U};

Copilot uses AI. Check for mistakes.

Comment on lines +363 to +365
int ret = mfd_npm13xx_reg_write_burst(
config->mfd, CHGR_BASE, CHGR_OFFSET_NTC_TEMPS + (idx * 2U),
code >> NTCTEMP_MSB_SHIFT, code & NTCTEMP_LSB_MASK);
(uint8_t []){code >> NTCTEMP_MSB_SHIFT, code & NTCTEMP_LSB_MASK},
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The compound literal array should be assigned to a named variable for better readability. Consider creating a temporary array variable like uint8_t ntc_data[] = {code >> NTCTEMP_MSB_SHIFT, code & NTCTEMP_LSB_MASK};

Copilot uses AI. Check for mistakes.

Comment on lines +387 to +389
int ret = mfd_npm13xx_reg_write_burst(
config->mfd, CHGR_BASE, CHGR_OFFSET_DIE_TEMPS + (idx * 2U),
code >> DIETEMP_MSB_SHIFT, code & DIETEMP_LSB_MASK);
(uint8_t []){code >> DIETEMP_MSB_SHIFT, code & DIETEMP_LSB_MASK},
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The compound literal array should be assigned to a named variable for better readability. Consider creating a temporary array variable like uint8_t temp_data[] = {code >> DIETEMP_MSB_SHIFT, code & DIETEMP_LSB_MASK};

Copilot uses AI. Check for mistakes.

Comment on lines +593 to +594
ret = mfd_npm13xx_reg_write_burst(config->mfd, CHGR_BASE, CHGR_OFFSET_ISET,
(uint8_t []){idx / 2U, idx & 1U}, 2U);
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The compound literal array should be assigned to a named variable for better readability. Consider creating a temporary array variable like uint8_t charge_data[] = {idx / 2U, idx & 1U};

Suggested change
ret = mfd_npm13xx_reg_write_burst(config->mfd, CHGR_BASE, CHGR_OFFSET_ISET,
(uint8_t []){idx / 2U, idx & 1U}, 2U);
uint8_t charge_data[] = {idx / 2U, idx & 1U};
ret = mfd_npm13xx_reg_write_burst(config->mfd, CHGR_BASE, CHGR_OFFSET_ISET,
charge_data, 2U);

Copilot uses AI. Check for mistakes.

Comment on lines +599 to +602
ret = mfd_npm13xx_reg_write_burst(
config->mfd, CHGR_BASE, CHGR_OFFSET_ISET_DISCHG,
npm1300_discharge_limits[config->dischg_limit_idx] / 2U,
npm1300_discharge_limits[config->dischg_limit_idx] & 1U);
(uint8_t []){npm1300_discharge_limits[config->dischg_limit_idx] / 2U,
npm1300_discharge_limits[config->dischg_limit_idx] & 1U}, 2U);
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The compound literal array should be assigned to a named variable for better readability. Consider creating a temporary array variable like uint8_t discharge_data[] = {npm1300_discharge_limits[config->dischg_limit_idx] / 2U, npm1300_discharge_limits[config->dischg_limit_idx] & 1U};

Copilot uses AI. Check for mistakes.

@seov-nordic
Copy link
Member Author

@kartben I don't feel like addressing Copilot's nitpicks if it's fine by you :)

@jhedberg jhedberg merged commit 3ae0d39 into zephyrproject-rtos:main Oct 15, 2025
26 checks passed
@kartben
Copy link
Contributor

kartben commented Oct 15, 2025

@kartben I don't feel like addressing Copilot's nitpicks if it's fine by you :)

I wouldn't necessarily say these qualify as nitpicks, but sure :)

@seov-nordic seov-nordic deleted the npm13xx-charger-improve-measurement-fetching branch October 16, 2025 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.