-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
base: main
Are you sure you want to change the base?
add ad5293 drivers #2361
Conversation
/AzurePipelines run |
Azure Pipelines successfully started running 2 pipeline(s). |
There was a problem hiding this 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.
Hi, |
} | ||
|
||
*device = dev; | ||
printf("Initializing succeed.\r\n "); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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_ |
There was a problem hiding this comment.
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_ | ||
/*****************************************************************************/ |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
11.17
|
any build error information from LinuxBuilds cppcheck? |
here's the log if you dont have access to it:
|
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]>
11.18
|
BTY I found the access to check logs, thanks :> |
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? |
There was a problem hiding this 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
Pull Request Description
drivers includes
has formatted according to #2352 code style with astyle.sh
PR Type
PR Checklist