Skip to content

Commit

Permalink
Merge pull request #757 from AkiyukiOkayasu/vreg
Browse files Browse the repository at this point in the history
Add on-chip voltage regulator (VREG) voltage setting function
  • Loading branch information
jannic authored Feb 28, 2024
2 parents a9b91ea + 6c5db05 commit deca3a5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
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()
}

0 comments on commit deca3a5

Please sign in to comment.