blob: 9058de0cc6a83902c70fe23cd8b854b4596371c8 [file] [log] [blame]
Austin Schuh208337d2022-01-01 14:29:11 -08001/*
2 * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include "pico.h"
8#include "hardware/adc.h"
9#include "hardware/resets.h"
10
11void adc_init(void) {
12 // ADC is in an unknown state. We should start by resetting it
13 reset_block(RESETS_RESET_ADC_BITS);
14 unreset_block_wait(RESETS_RESET_ADC_BITS);
15
16 // Now turn it back on. Staging of clock etc is handled internally
17 adc_hw->cs = ADC_CS_EN_BITS;
18
19 // Internal staging completes in a few cycles, but poll to be sure
20 while (!(adc_hw->cs & ADC_CS_READY_BITS)) {
21 tight_loop_contents();
22 }
23}