Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for LTC7841 #2397

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

MCabuena
Copy link

@MCabuena MCabuena commented Dec 12, 2024

Pull Request Description

Please replace this with a detailed description and motivation of the changes.
You can tick the checkboxes below with an 'x' between square brackets or just check them after publishing the PR.
If this PR contains a breaking change, list dependent PRs and try to push all related PRs at the same time.

PR Type

  • Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)

PR Checklist

  • I have followed the Coding style guidelines
  • I have performed a self-review of the changes
  • I have commented my code, at least hard-to-understand parts
  • I have build all projects affected by the changes in this PR
  • I have tested in hardware affected projects, at the relevant boards
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe etc), if applies

@MCabuena MCabuena marked this pull request as ready for review December 12, 2024 02:33
@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from fcc8863 to 5b005cb Compare December 13, 2024 01:40
@MCabuena
Copy link
Author

V2:

  1. Removed from src.mk ltc7841_regs.c and ltc7841_regs.h requirement for building

@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from c57b81e to 16af219 Compare December 13, 2024 08:46
@MCabuena
Copy link
Author

V3:

  1. fixed src.mk file inside ltc7841 project folder

@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

drivers/power/ltc7841/ltc7841.h Show resolved Hide resolved
uint8_t read_length;
uint8_t write_length = 1;
uint8_t size = get_register_size(cmd);
uint8_t write_buffer[write_length];
Copy link
Contributor

Choose a reason for hiding this comment

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

doesn't need to be an array

drivers/power/ltc7841/ltc7841.c Outdated Show resolved Hide resolved
if (ret)
return ret;
// read part of write_read, 1 at the end for stop bit sending
ret = no_os_i2c_read(desc->comm_desc, g_i2c0_read_buffer, read_length, 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

You should store the register value in data.

drivers/power/ltc7841/ltc7841.c Outdated Show resolved Hide resolved
Comment on lines 345 to 423
static struct iio_attribute ltc7841_chan_attrs[] = {
{
.name = "raw",
.show = ltc7841_iio_read_raw
},
END_ATTRIBUTES_ARRAY
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the scale of every channel equal to 1? Otherwise, you also need the scale attribute here.

Copy link
Author

Choose a reason for hiding this comment

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

The scale of every channel is the same at 10mV per bit.

Copy link
Author

Choose a reason for hiding this comment

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

on my next commit, I'll add as you stated below a scale attribute for the channel

Copy link
Contributor

Choose a reason for hiding this comment

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

When implementing review suggestions, you don't need to create a new commit (unless you add new functionality, which should have its own commit). Just modify the current one and push the changes again. After that, you should add a changelog comment in this PR stating what you did since the last push.

drivers/power/ltc7841/iio_ltc7841.c Outdated Show resolved Hide resolved
}
case LTC7841_IIO_IIN_CHAN:
ret = ltc7841_reg_read(ltc7841, (uint8_t)LTC7841_READ_IIN, read_value);
if (0 == ret) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use inverse logic:

if (ret)
    break;

drivers/power/ltc7841/iio_ltc7841.c Outdated Show resolved Hide resolved
Comment on lines 64 to 66
#define PEC_SIZE 0x100
#define BYTE_LENGTH 1
#define WORD_LENGTH 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the LTC7841_ prefix. Otherwise, generic names like these could create conflicts with other macros.

.max_speed_hz = LTC7841_I2C_CLK_SPEED,
.slave_address = LTC7841_I2C_ADDR,
.platform_ops = &max_i2c_ops,
.extra = (void *)&ltc7841_i2c_extra,
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to cast.

Copy link
Collaborator

Choose a reason for hiding this comment

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

unresolving this conversation since it's not resolved yet.

@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from 298e71f to 6423294 Compare December 17, 2024 03:34
@MCabuena
Copy link
Author

V4:

  1. changed commenting style to /* */
  2. removed void in common_data.c for ltc7841_i2c_extra
  3. removed PEC_SIZE since this device doesn't support PEC
  4. added LTC7841_ name to BYTE_LENGTH and WORD_LENGTH in ltc7841.h
  5. when computing for current input and current output, unit usage is now in uA for initial calculations, only when calculating for scale values does it show in A
  6. changed iio_ltc7841.c all reverse logic for checking ret
  7. added scaled value as an attribute
  8. functions in ltc7841.c now return directly
  9. changed write_buffer into a uint8_t type only, and not as an array
  10. changed license file of ltc7841.h

@buha
Copy link
Contributor

buha commented Dec 17, 2024

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

drivers/power/ltc7841/ltc7841.h Outdated Show resolved Hide resolved
projects/ltc7841/src.mk Outdated Show resolved Hide resolved
projects/ltc7841/src/platform/maxim/platform_src.mk Outdated Show resolved Hide resolved
@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from 34f8560 to 3674149 Compare December 18, 2024 02:13
@MCabuena
Copy link
Author

V5:

  1. changed src.mk file to use NO_OS_INC_DIRS instead of INC +=
  2. removed ltc7841_reg_st inside ltc7841_init_param
  3. added a blank space before the final return as suggested
  4. added a space in between the {} of functions

@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@kister-jimenez
Copy link
Collaborator

kister-jimenez commented Jan 10, 2025

Hi,

I'm not sure why my README file inside drivers/power/README.rst cannot be found. I'll try recommitting the same files and check if the issue happens again.

That's the cause of the issue, but if you check the 3rd commit, the file is included.

You have a typo in part number inside the README.rst.

You can leave as it is for now, I'm currently going through the code and submit the comments today.

@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from b0d0011 to 228b995 Compare January 15, 2025 05:28
@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

projects/ltc7841/src/common/common_data.c Outdated Show resolved Hide resolved
drivers/power/ltc7841/iio_ltc7841.h Outdated Show resolved Hide resolved
drivers/power/ltc7841/iio_ltc7841.c Outdated Show resolved Hide resolved
drivers/power/ltc7841/iio_ltc7841.c Outdated Show resolved Hide resolved
projects/ltc7841/src/platform/maxim/astyle.exe Outdated Show resolved Hide resolved
projects/ltc7841/src/common/common_data.c Outdated Show resolved Hide resolved
.max_speed_hz = LTC7841_I2C_CLK_SPEED,
.slave_address = LTC7841_I2C_ADDR,
.platform_ops = &max_i2c_ops,
.extra = (void *)&ltc7841_i2c_extra,
Copy link
Collaborator

Choose a reason for hiding this comment

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

unresolving this conversation since it's not resolved yet.

projects/ltc7841/src/examples/basic/basic_example.c Outdated Show resolved Hide resolved
drivers/power/ltc7841/ltc7841.h Outdated Show resolved Hide resolved
projects/ltc7841/src/examples/iio_example/iio_example.c Outdated Show resolved Hide resolved
@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from 6646390 to 7d0d840 Compare January 21, 2025 08:23
@MCabuena
Copy link
Author

V9

  1. changed CURRENT_SCALE to manual computation with a parameter input for rsense : RSENSE_VALUE_DC2798A, in case user wants to use a different rsense value from DC2798A, he can change the input to common_data.c for the LTC7841_rsense_value
  2. removed astyle.exe files and astyle_config files
  3. changed int32_t type to int32 in iio_ltc7841.c file for the return type
  4. hopefully all nits?

@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Contributor

@buha buha left a comment

Choose a reason for hiding this comment

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

It looks good but you'll have to update the project to the new project infrastructure.

Here's the PR with the changes with 3 modified projects as example: #2412

And here's a pending PR where I gave feedback with pretty much that needs to be changed, same applies to your PR.
#2411

Copy link
Collaborator

@kister-jimenez kister-jimenez left a comment

Choose a reason for hiding this comment

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

The EXAMPLE= has been implemented in the previous comments so I just added the comments related to the other changes needed for the recently merged examples infra.

Addition minor changes on the rsense placement.

drivers/power/ltc7841/iio_ltc7841.c Outdated Show resolved Hide resolved
drivers/power/ltc7841/ltc7841.h Outdated Show resolved Hide resolved
projects/ltc7841/src/common/common_data.c Outdated Show resolved Hide resolved
projects/ltc7841/src/examples/basic/basic_example.c Outdated Show resolved Hide resolved
projects/ltc7841/src/platform/platform_includes.h Outdated Show resolved Hide resolved
projects/ltc7841/src.mk Outdated Show resolved Hide resolved
projects/ltc7841/src/examples/examples_src.mk Outdated Show resolved Hide resolved
projects/ltc7841/src/platform/maxim/main.c Outdated Show resolved Hide resolved
projects/ltc7841/src/platform/maxim/main.c Outdated Show resolved Hide resolved
@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch 2 times, most recently from 1e50ae5 to 34a77d8 Compare January 23, 2025 03:34
@MCabuena
Copy link
Author

V10

  1. moved rsense parameter to ltc7841_iio_init parameter
  2. followed Kister's instructions to change the project files

@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Add initial header and source files for LTC7841 driver

Signed-off-by: Marvin Neil Cabuenas <MarvinNeil.Cabuenas@analog.com>
@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from 196fcc0 to dc95dcb Compare January 23, 2025 07:13
Add initial header and source file for LTC7841 IIO driver.

Signed-off-by: Marvin Neil Cabuenas <MarvinNeil.Cabuenas@analog.com>
Add README.rst documentation file for LTC7841 alongside other
documentation related files.

Signed-off-by: Marvin Neil Cabuenas <MarvinNeil.Cabuenas@analog.com>
@MCabuena
Copy link
Author

V11

  1. removed \ at the end of SRCS += $(DRIVERS)/power/ltc7841/iio_ltc7841.c in examples_src.mk

@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from 045ffa0 to 6b453ea Compare January 23, 2025 07:41
@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Add initial project files for both basic and IIO examples for LTC7841.

Signed-off-by: Marvin Neil Cabuenas <MarvinNeil.Cabuenas@analog.com>
@MCabuena MCabuena force-pushed the ltc7841_my_changes_to_run_ci branch from dc99896 to ec9a451 Compare January 23, 2025 23:11
Add README.rst documentation file for project alongside other
documentation related files.

Signed-off-by: Marvin Neil Cabuenas <MarvinNeil.Cabuenas@analog.com>
@MCabuena
Copy link
Author

V12

  1. performed astyle.exe --options= on basic_example.c

@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants