Austin Schuh | 208337d | 2022-01-01 14:29:11 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 11 | void 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 | } |