Skip to content
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 on-chip voltage regulator (VREG) voltage setting function #757

Merged
merged 5 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rp2040-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub mod typelevel;
pub mod uart;
pub mod usb;
pub mod vector_table;
pub mod vreg;
pub mod watchdog;
pub mod xosc;

Expand Down
37 changes: 37 additions & 0 deletions rp2040-hal/src/vreg.rs
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()
}
Loading