-
Notifications
You must be signed in to change notification settings - Fork 935
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
adc: adc_read() not check for error (#1575) v2 #1599
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,15 +128,24 @@ static inline void adc_set_temp_sensor_enabled(bool enable) { | |
* | ||
* Performs an ADC conversion, waits for the result, and then returns it. | ||
* | ||
* \return Result of the conversion. | ||
* \return Result of the conversion or negative value on error. | ||
*/ | ||
static inline uint16_t adc_read(void) { | ||
static inline int32_t adc_read(void) { | ||
hw_set_bits(&adc_hw->cs, ADC_CS_START_ONCE_BITS); | ||
|
||
while ((adc_hw->cs & (ADC_CS_READY_BITS|ADC_CS_ERR_BITS|ADC_CS_ERR_STICKY_BITS))==0) { | ||
tight_loop_contents(); | ||
} | ||
|
||
while (!(adc_hw->cs & ADC_CS_READY_BITS)) | ||
tight_loop_contents(); | ||
|
||
return (uint16_t) adc_hw->result; | ||
if ((adc_hw->cs & ADC_CS_READY_BITS)>0) { | ||
return adc_hw->result & 0xfff; | ||
} | ||
if ((adc_hw->cs & ADC_CS_ERR_BITS)>0) { | ||
return -ADC_CS_ERR_BITS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit random to return -ADC_CS_ERR_BITS. It would be better to return a "standard" error code? Maybe PICO_ERROR_GENERIC or PICO_ERROR_NO_DATA? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see your point, but if we doing this we can't distinguished what caused the error. Use |
||
} | ||
/* clear sticky bit */ | ||
hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS); | ||
return -ADC_CS_ERR_STICKY_BITS; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
} | ||
|
||
/*! \brief Enable or disable free-running sampling mode | ||
|
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.
Might be better to use ADC_RESULT_BITS
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.
I will have a look if that will have benefit. The original code check for the ADC_CS_READY_BITS.
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.
I believe Peter meant use
ADC_RESULT_BITS
instead of0xfff
- see https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2040/hardware_regs/include/hardware/regs/adc.h#L111There 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.
Oh, :)
Thanks for the eye opener.