atsam: Add get_pclock_frequency() helper function

Add get_pclock_frequency() and use it to calculate peripheral clocks.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2021-11-20 13:47:17 -05:00
parent 92ca111986
commit bb08dc7ae9
7 changed files with 22 additions and 12 deletions

View File

@@ -47,7 +47,7 @@ gpio_adc_setup(uint8_t pin)
if (!is_enabled_pclock(ID_ADC)) {
// Setup ADC
enable_pclock(ID_ADC);
uint32_t prescal = SystemCoreClock / (2 * ADC_FREQ_MAX) - 1;
uint32_t prescal = get_pclock_frequency(ID_ADC) / (2*ADC_FREQ_MAX) - 1;
ADC->ADC_MR = (ADC_MR_PRESCAL(prescal)
| ADC_MR_STARTUP_SUT768
| ADC_MR_TRANSFER(1));