-
-
Notifications
You must be signed in to change notification settings - Fork 40k
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 analog support for RP2040 #19453
Conversation
With #17915 being merged to |
The ADCv2 bodge defined `ADC_CFGR1_RES_10BIT` and other similar constants, so that the same code as on STM32 could be used.
3f478f9
to
09ef8b6
Compare
The joystick code also builds and works with the fix from #19602. The temperature sensor could be read with |
Also change the priority from 2 to 3 to match the ChibiOS tests.
I changed the priority to 3 to match the value used by ChibiOS tests:
This should still work, but I can't actually test this at the moment. |
Co-authored-by: Ryan <[email protected]>
Works fine. |
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.
Could you update the rp2040 platform dev line about the ADC driver? https://github.com/qmk/qmk_firmware/blob/master/docs/platformdev_rp2040.md#L7 The other changes LGTM.
Also I suppose that the What about the |
Looks like it is possible to get something like diff --git a/platforms/chibios/drivers/analog.c b/platforms/chibios/drivers/analog.c
index 84ca99be3c..a8ce21bb6d 100644
--- a/platforms/chibios/drivers/analog.c
+++ b/platforms/chibios/drivers/analog.c
@@ -241,10 +241,10 @@ __attribute__((weak)) adc_mux pinToMux(pin_t pin) {
// STM32F103x[C-G] in 144-pin packages also have analog inputs on F6...F10, but they are on ADC3, and the
// ChibiOS ADC driver for STM32F1xx currently supports only ADC1, therefore these pins are not usable.
#elif defined(RP2040)
- case GP26: return TO_MUX(0, 0);
- case GP27: return TO_MUX(1, 0);
- case GP28: return TO_MUX(2, 0);
- case GP29: return TO_MUX(3, 0);
+ case 26U: return TO_MUX(0, 0);
+ case 27U: return TO_MUX(1, 0);
+ case 28U: return TO_MUX(2, 0);
+ case 29U: return TO_MUX(3, 0);
#endif
}
Would this be acceptable? (If it would, then the STM32 cases above should probably be changed to use something like |
The converter support overrides Most other drivers don't have this problem, because the pin names are passed externally in defines (which, BTW, would contain the source pin names in case a converter is used), and the only places where explicit pin names are used in the driver code are some defaults which the converters override anyway. |
According to docs/platformdev_rp2040.md, the `GENERIC_PROMICRO_RP2040` board should enable the peripherals that match the Sparkfun Pro Micro RP2040 pinout in `mcuconf.h`, but leave the corresponding options in `halconf.h` disabled (so the options that enable the peripherals don't actually do anything in the default state, but just enabling the options in `halconf.h` is enough to make the Pro Micro compatible peripherals work). Make the ADC feature behave the same way: enable the `RP_ADC_USE_ADC1` option in the board config, so that just enabling `HAL_USE_ADC` would be enough to use the ADC. After this change the `handwired/onekey/rp2040` keyboard no longer needs the ADC configuration in `mcuconf.h`, so it is removed again.
With this change keyboards using Pro Micro or Elite-C that were also using analog input on the F4…F7 pins could work with RP2040-based converters that map the GP26…GP29 pins to the same locations. Unfortulately, some keyboards could be using analog input on other pins (the Pro Micro pinout has 9 pins which support analog input on ATmega32U4, and the Elite-C pinout adds 2 more such pins, but RP2040 has only 4 analog pins), and those keyboards won't work with RP2040-based controllers, but that problem won't be detected at compile time (ADC reads for unsupported pins would just return 0 at runtime). The `analog.c` code needs to be changed to use raw pin numbers instead of the `GPxx` defines, because those defines are not available when using a converter.
To be inline with the expectation that a converter "just works" this should be done.
Yes, I think the ADC peripheral should be enabled as well without activating the HAL driver. |
The whole |
It's been ripe for replacing |
From my perspective, I dont care too much if converters fail. Long term it would be expected to work, but it shouldnt be a blocker for getting ADC support in. |
Actually the converters should work with the latest code here. The only issue is that some keyboards may use analog inputs on Pro Micro/Elite-C pins outside of the |
So this sounds like the PR is ready to go in?! The refactoring should be done in a separate PR imho. |
Can iterate on later PRs if required. |
Co-authored-by: Ryan <[email protected]>
Description
Add analog support for RP2040.
The low-level driver is already present in ChibiOS-Contrib, but the fix from ChibiOS/ChibiOS-Contrib#355 is required to make it actually work; without that fix the code will compile, but
adc_read()
will work only once (on the second call it will lockup).TODO:
RP_IRQ_ADC1_PRIORITY
to the defaultmcuconf.h
files.Types of Changes
Checklist