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 ad5293 drivers #2361

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

add ad5293 drivers #2361

wants to merge 1 commit into from

Conversation

mi-zeng
Copy link
Contributor

@mi-zeng mi-zeng commented Nov 9, 2024

Pull Request Description

drivers includes

  1. no-os initilization
  2. calibration, wiper r/w ,hard/soft reset and other operation
  3. daisy-chain multiple chip support

has formatted according to #2352 code style with astyle.sh

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

@kister-jimenez
Copy link
Collaborator

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Copy link
Contributor

@amiclaus amiclaus left a comment

Choose a reason for hiding this comment

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

there are some build issues that need addressing in the first place. have a look at #2351 for example on how documentation should be integrated.

@mi-zeng
Copy link
Contributor Author

mi-zeng commented Nov 13, 2024

Hi,
I have ref to #2351, modified related sphinx source file and a make html is build successful, please take a look.
best

}

*device = dev;
printf("Initializing succeed.\r\n ");
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 put these messages in the device driver

*
* @param dev - The device structure.
*
* @return NAN
Copy link
Contributor

Choose a reason for hiding this comment

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

void

goto error;

// spi initialization
init_param->spi_init.mode = NO_OS_SPI_MODE_1; //CPOL=0, CPHA=1
Copy link
Contributor

Choose a reason for hiding this comment

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

the comment is redundant, but as you wish

chp = (struct ad5293_chip_info*)no_os_malloc(dev->chip_num * sizeof(* chp));
if (! chp) {
ret = - ENOMEM;
goto error;
Copy link
Contributor

Choose a reason for hiding this comment

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

if you jump from here to error label, execution will attempt to free the unallocated chp pointer which is undefined behavior

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will add explicity initilazation to pointer dev and chp as NULL, then it won't affect even if chp is not allocated a address

Copy link
Contributor

Choose a reason for hiding this comment

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

that works too

if (! dev)
return - ENOMEM;

printf("Initializing ad5293, number of chips %d.\r\n", init_param->chip_num);
Copy link
Contributor

Choose a reason for hiding this comment

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

remove all printf statements from the device driver, they only belong to the application

you may use debug pr_* statements from no_os_print_log.h, but not printf directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be removed

SOFTWARE.
*******************************************************************************/

#ifndef _ad5293_H_
Copy link
Contributor

Choose a reason for hiding this comment

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

lower/upper case mix


#ifndef _ad5293_H_
#define _ad5293_H_
/*****************************************************************************/
Copy link
Contributor

Choose a reason for hiding this comment

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

delete these comment delimiters, they are completely useless

i know we have a lot of them in our code but we should get rid of them

};

/* SDO mode */
enum SDO_mode_t {
Copy link
Contributor

Choose a reason for hiding this comment

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

lower/uppser case mix

1. Serial peripheral interface (SPI) is necessary to access device
2. Daisy-chain mode is required for multiple chip use, in this configuration
chip select line remains low untill all bytes are shifted out
3. High impedence mode of SDO pin is not recommanded,
Copy link
Contributor

Choose a reason for hiding this comment

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

this sentence needs rephrasing

3. High impedence mode of SDO pin is not recommanded,
as tested somehow this could cause communications
unfunctional

Copy link
Contributor

Choose a reason for hiding this comment

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

also i think more details are needed in the documentation

i just searched a random device driver .rst to use as template:
https://github.com/analogdevicesinc/no-OS/blob/main/drivers/adc/adm1177/README.rst

{
struct ad5293_dev* dev;
struct ad5293_chip_info* chp;
int32_t ret = 0;
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 for explicit initialization.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will remove = 0


// hardware reset pin initialization
if (init_param->gpio_reset) {
ret |= no_os_gpio_get_optional(& dev->gpio_reset, init_param->gpio_reset);
Copy link
Contributor

Choose a reason for hiding this comment

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

check ret after each assignment. avoid propagating errors with |=

if (init_param->gpio_reset) {
ret |= no_os_gpio_get_optional(& dev->gpio_reset, init_param->gpio_reset);
ret |= no_os_gpio_set_value(dev->gpio_reset, NO_OS_GPIO_HIGH);
if (ret < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (ret) check all occurences.

#include "no_os_util.h"

/* SPI Read/Write commands */
#define CMD_NOP 0b0000
Copy link
Contributor

Choose a reason for hiding this comment

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

go for hex values here entirely.


/*******************************functions prototype*******************************/
/* Initialize the ad5293 device structure. */
int32_t ad5293_init(struct ad5293_dev **device,
Copy link
Contributor

Choose a reason for hiding this comment

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

all functions should return int

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do I have to return an error code?
I returned data in last 2 get operation functions

@mi-zeng
Copy link
Contributor Author

mi-zeng commented Nov 17, 2024

11.17
several change according to review

  1. reorgnize document README.rst, add more description
  2. fix void function return description
  3. turn ret initialization as non-explicit
  4. remove printf information
  5. check ret for each ret assignment, simplify if(ret<0) as if(ret)
  6. chp init as NULL to prevent undefined memory release behavior
  7. simplify return and function return in same line
  8. fix lower/upper case mix
  9. remove redundant delimiters
  10. marco define turn form binary to hex

@mi-zeng
Copy link
Contributor Author

mi-zeng commented Nov 18, 2024

any build error information from LinuxBuilds cppcheck?

@buha
Copy link
Contributor

buha commented Nov 18, 2024

here's the log if you dont have access to it:

drivers/potentiometer/ad5293/ad5293.c:149:6: error: Uninitialized variable: ret [uninitvar]
 if (ret)
     ^
drivers/potentiometer/ad5293/ad5293.c:313:9: error: Uninitialized variable: ret [uninitvar]
 return ret;
        ^
drivers/potentiometer/ad5293/ad5293.c:338:9: error: Uninitialized variable: ret [uninitvar]
 return ret;
        ^

1. no-os initilization
2. calibration, wiper r/w ,hard/soft reset and other operation
3. signle chip/daisy-chain multiple chips support

Signed-off-by: Mize <[email protected]>
@mi-zeng
Copy link
Contributor Author

mi-zeng commented Nov 18, 2024

11.18

  1. fix build error related code
  2. add chip num check in init function
  3. add struct member memory free in initilazation error part
  4. add single chip setup description

@mi-zeng
Copy link
Contributor Author

mi-zeng commented Nov 18, 2024

BTY I found the access to check logs, thanks :>

@mi-zeng
Copy link
Contributor Author

mi-zeng commented Nov 20, 2024

HI,I guess there is something wrong with the Mbed projects chkecks. Since #20241118.5 on pipline the Mbed failed several time. So maybe someone gonna fix it and recheck this PR afterwards?

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.

yes, the mbed issue seems unrelated, i'm ok with merging like this, that will be fixed by someone else

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