adc: adc_read() not check for error (#1575) v2 #1599

Open
ruehlchris wants to merge 1 commit from ruehlchris/develop into develop
ruehlchris commented 2024-01-01 19:56:26 -06:00 (Migrated from github.com)

Implementation of adc_read() not check for errors in the ADC_CS register.

  • change the return type from uint16_t to int32_t
  • check for ADC_CS_READY_BITS and error ADC_CS_ERR_BITS or ADC_CS_ERR_STICKY_BITS
  • return the ADC value (12bits) or the negative value of ADC_CS_ERR_BITS or ADC_CS_ERR_STICKY_BITS depending on the error

v2:

  • update the code, optimize the workflow
  • no reset required , so removed it.
Implementation of adc_read() not check for errors in the ADC_CS register. - change the return type from uint16_t to int32_t - check for ADC_CS_READY_BITS and error ADC_CS_ERR_BITS or ADC_CS_ERR_STICKY_BITS - return the ADC value (12bits) or the negative value of ADC_CS_ERR_BITS or ADC_CS_ERR_STICKY_BITS depending on the error v2: - update the code, optimize the workflow - no reset required , so removed it.
peterharperuk (Migrated from github.com) reviewed 2024-01-02 04:38:26 -06:00
@ -140,0 +144,4 @@
return -ADC_CS_ERR_BITS;
}
/* clear sticky bit */
hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);
peterharperuk (Migrated from github.com) commented 2024-01-02 04:36:02 -06:00

Might be better to use ADC_RESULT_BITS

Might be better to use ADC_RESULT_BITS
@ -140,2 +147,4 @@
hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);
return -ADC_CS_ERR_STICKY_BITS;
}
peterharperuk (Migrated from github.com) commented 2024-01-02 04:37:55 -06:00

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?

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?
peterharperuk (Migrated from github.com) commented 2024-01-02 04:38:08 -06:00

same comment as above

same comment as above
ruehlchris (Migrated from github.com) reviewed 2024-01-03 03:39:24 -06:00
@ -140,0 +144,4 @@
return -ADC_CS_ERR_BITS;
}
/* clear sticky bit */
hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);
ruehlchris (Migrated from github.com) commented 2024-01-03 03:39:24 -06:00

I will have a look if that will have benefit. The original code check for the ADC_CS_READY_BITS.

I will have a look if that will have benefit. The original code check for the ADC_CS_READY_BITS.
ruehlchris (Migrated from github.com) reviewed 2024-01-03 03:46:43 -06:00
@ -140,2 +147,4 @@
hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);
return -ADC_CS_ERR_STICKY_BITS;
}
ruehlchris (Migrated from github.com) commented 2024-01-03 03:46:43 -06:00

I see your point, but if we doing this we can't distinguished what caused the error.

Use
PICO_ERROR_NO_DATA
and additional, define a new code:
PICO_ERROR_ADC_STICKY_BIT

I see your point, but if we doing this we can't distinguished what caused the error. Use PICO_ERROR_NO_DATA and additional, define a new code: PICO_ERROR_ADC_STICKY_BIT
lurch (Migrated from github.com) reviewed 2024-01-03 05:08:15 -06:00
@ -140,0 +144,4 @@
return -ADC_CS_ERR_BITS;
}
/* clear sticky bit */
hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);
lurch (Migrated from github.com) commented 2024-01-03 05:08:15 -06:00
I believe Peter meant use `ADC_RESULT_BITS` instead of `0xfff` - see https://github.com/raspberrypi/pico-sdk/blob/master/src/rp2040/hardware_regs/include/hardware/regs/adc.h#L111
ruehlchris (Migrated from github.com) reviewed 2024-01-03 18:44:44 -06:00
@ -140,0 +144,4 @@
return -ADC_CS_ERR_BITS;
}
/* clear sticky bit */
hw_set_bits(&adc_hw->cs, ADC_CS_ERR_STICKY_BITS);
ruehlchris (Migrated from github.com) commented 2024-01-03 18:44:44 -06:00

Oh, :)
Thanks for the eye opener.

Oh, :) Thanks for the eye opener.
peterharperuk (Migrated from github.com) requested changes 2024-01-12 04:36:18 -06:00
peterharperuk (Migrated from github.com) left a comment

Looks good but see previous comments concerning minor changes

Looks good but see previous comments concerning minor changes
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'ruehlchris/develop:ruehlchris/develop'
git switch 'ruehlchris/develop'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'develop'
git merge --no-ff 'ruehlchris/develop'
git switch 'ruehlchris/develop'
git rebase 'develop'
git switch 'develop'
git merge --ff-only 'ruehlchris/develop'
git switch 'ruehlchris/develop'
git rebase 'develop'
git switch 'develop'
git merge --no-ff 'ruehlchris/develop'
git switch 'develop'
git merge --squash 'ruehlchris/develop'
git switch 'develop'
git merge --ff-only 'ruehlchris/develop'
git switch 'develop'
git merge 'ruehlchris/develop'
git push origin 'develop'
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-raspberrypi/pico-sdk!1599
No description provided.