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 1 commit
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 @@ -72,6 +72,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
47 changes: 47 additions & 0 deletions rp2040-hal/src/vreg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//! 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::{vreg::{VregVoltage, vreg_set_voltage}, pac};
//! let mut pac = pac::Peripherals::take().unwrap();
//! // Set voltage to 1.20V
//! vreg_set_voltage(&mut pac.VREG_AND_CHIP_RESET, VregVoltage::Voltage1_20);
//! ```

use crate::pac::VREG_AND_CHIP_RESET;

#[repr(u8)]
/// Possible voltage values that can be applied to the on-chip voltage regulator
pub enum VregVoltage {
/// 0.85V
Voltage0_85 = 0b0110u8,
/// 0.90V
Voltage0_90 = 0b0111u8,
/// 0.95V
Voltage0_95 = 0b1000u8,
/// 1.00V
Voltage1_00 = 0b1001u8,
/// 1.05V
Voltage1_05 = 0b1010u8,
/// 1.10V (default)
Voltage1_10 = 0b1011u8,
/// 1.15V
Voltage1_15 = 0b1100u8,
/// 1.20V
Voltage1_20 = 0b1101u8,
/// 1.25V
Voltage1_25 = 0b1110u8,
/// 1.30V
Voltage1_30 = 0b1111u8,
}

/// Set voltage to the on-chip voltage regulator
///
/// * `voltage` - The voltage (from enumeration \ref vreg_voltage) to apply to the voltage regulator
pub fn vreg_set_voltage(vreg_dev: &mut VREG_AND_CHIP_RESET, voltage: VregVoltage) {
AkiyukiOkayasu marked this conversation as resolved.
Show resolved Hide resolved
vreg_dev
.vreg
.write(|w| unsafe { w.vsel().bits(voltage as u8) });
}
Loading