-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #757 from AkiyukiOkayasu/vreg
Add on-chip voltage regulator (VREG) voltage setting function
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//! On-chip voltage regulator (VREG) | ||
//! | ||
//! See [Chapter 2, Section 10](https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf) of the datasheet for more details | ||
//! | ||
//! ## Usage | ||
//! ```no_run | ||
//! use rp2040_hal::pac::vreg_and_chip_reset::vreg::VSEL_A; | ||
//! use rp2040_hal::{vreg::set_voltage, pac}; | ||
//! let mut pac = pac::Peripherals::take().unwrap(); | ||
//! // Set voltage to 1.20V | ||
//! set_voltage(&mut pac.VREG_AND_CHIP_RESET, VSEL_A::VOLTAGE1_20); | ||
//! ``` | ||
|
||
use crate::pac::vreg_and_chip_reset::vreg::VSEL_A; | ||
use crate::pac::VREG_AND_CHIP_RESET; | ||
|
||
/// Set voltage to the on-chip voltage regulator. | ||
/// | ||
/// There is no guarantee that the device will operate at all of the available voltages. | ||
/// Appropriate values should be selected in consideration of the system clock frequency and other factors to be set. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `vreg_dev` - VREG peripheral | ||
/// * `voltage` - Voltage to set | ||
pub fn set_voltage(vreg_dev: &mut VREG_AND_CHIP_RESET, voltage: VSEL_A) { | ||
vreg_dev.vreg().write(|w| w.vsel().variant(voltage)); | ||
} | ||
|
||
/// Get voltage from the on-chip voltage regulator | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `vreg_dev` - VREG peripheral | ||
pub fn get_voltage(vreg_dev: &VREG_AND_CHIP_RESET) -> Option<VSEL_A> { | ||
vreg_dev.vreg().read().vsel().variant() | ||
} |