Skip to content

Commit

Permalink
Add support for Compute Module 5 Lite
Browse files Browse the repository at this point in the history
  • Loading branch information
golemparts committed Dec 9, 2024
1 parent 5297dbf commit 6514378
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
15 changes: 1 addition & 14 deletions examples/gpio_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,19 +142,6 @@ fn main() -> Result<(), Box<dyn Error>> {
print_header(&header_rev1[..MAX_PINS_SHORT])
}
Model::RaspberryPiA | Model::RaspberryPiBRev2 => print_header(&HEADER[..MAX_PINS_SHORT]),
Model::RaspberryPiAPlus
| Model::RaspberryPiBPlus
| Model::RaspberryPi2B
| Model::RaspberryPi3APlus
| Model::RaspberryPi3B
| Model::RaspberryPi3BPlus
| Model::RaspberryPi4B
| Model::RaspberryPi5
| Model::RaspberryPiZero
| Model::RaspberryPiZeroW => print_header(&HEADER[..MAX_PINS_LONG]),
model => {
eprintln!("Error: No GPIO header information available for {}", model);
process::exit(1);
}
_ => print_header(&HEADER[..MAX_PINS_LONG]),
}
}
9 changes: 8 additions & 1 deletion src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,14 @@ impl I2c {
match DeviceInfo::new()?.model() {
// Pi B Rev 1 uses I2C0
Model::RaspberryPiBRev1 => I2c::with_bus(0),
Model::RaspberryPi4B | Model::RaspberryPi400 | Model::RaspberryPi5 => {
Model::RaspberryPi4B
| Model::RaspberryPi400
| Model::RaspberryPiComputeModule4
| Model::RaspberryPiComputeModule4S
| Model::RaspberryPi5
| Model::RaspberryPi500
| Model::RaspberryPiComputeModule5
| Model::RaspberryPiComputeModule5Lite => {
// Pi 4B/400 could have I2C3 enabled on pins 3 and 5
I2c::with_bus(1).or_else(|_| I2c::with_bus(3))
}
Expand Down
30 changes: 18 additions & 12 deletions src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub enum Model {
RaspberryPiComputeModule4,
RaspberryPiComputeModule4S,
RaspberryPiComputeModule5,
RaspberryPiComputeModule5Lite,
RaspberryPiZero,
RaspberryPiZeroW,
RaspberryPiZero2W,
Expand Down Expand Up @@ -114,6 +115,7 @@ impl fmt::Display for Model {
Model::RaspberryPiComputeModule4 => write!(f, "Raspberry Pi Compute Module 4"),
Model::RaspberryPiComputeModule4S => write!(f, "Raspberry Pi Compute Module 4S"),
Model::RaspberryPiComputeModule5 => write!(f, "Raspberry Pi Compute Module 5"),
Model::RaspberryPiComputeModule5Lite => write!(f, "Raspberry Pi Compute Module 5 Lite"),
Model::RaspberryPiZero => write!(f, "Raspberry Pi Zero"),
Model::RaspberryPiZeroW => write!(f, "Raspberry Pi Zero W"),
Model::RaspberryPiZero2W => write!(f, "Raspberry Pi Zero 2 W"),
Expand Down Expand Up @@ -212,7 +214,9 @@ fn parse_proc_cpuinfo() -> Result<Model> {
0x14 => Model::RaspberryPiComputeModule4,
0x15 => Model::RaspberryPiComputeModule4S,
0x17 => Model::RaspberryPi5,
0x18 => Model::RaspberryPiComputeModule5,
0x19 => Model::RaspberryPi500,
0x1a => Model::RaspberryPiComputeModule5Lite,
_ => return Err(Error::UnknownModel),
}
} else {
Expand Down Expand Up @@ -320,6 +324,7 @@ fn parse_base_model() -> Result<Model> {
"Raspberry Pi Compute Module 4S" => Model::RaspberryPiComputeModule4S,
"Raspberry Pi 5 Model B" => Model::RaspberryPi5,
"Raspberry Pi Compute Module 5" => Model::RaspberryPiComputeModule5,
"Raspberry Pi Compute Module 5 Lite" => Model::RaspberryPiComputeModule5Lite,
"Raspberry Pi 500" => Model::RaspberryPi500,
_ => return Err(Error::UnknownModel),
};
Expand Down Expand Up @@ -423,18 +428,19 @@ impl DeviceInfo {
pwm_chip: 0,
pwm_channels: [0, 1],
}),
Model::RaspberryPi5 | Model::RaspberryPi500 | Model::RaspberryPiComputeModule5 => {
Ok(DeviceInfo {
model,
soc: SoC::Bcm2712,
peripheral_base: PERIPHERAL_BASE_RP1,
gpio_offset: GPIO_OFFSET_RP1,
gpio_lines: GPIO_LINES_RP1,
gpio_interface: GpioInterface::Rp1,
pwm_chip: 2,
pwm_channels: [2, 3],
})
}
Model::RaspberryPi5
| Model::RaspberryPi500
| Model::RaspberryPiComputeModule5
| Model::RaspberryPiComputeModule5Lite => Ok(DeviceInfo {
model,
soc: SoC::Bcm2712,
peripheral_base: PERIPHERAL_BASE_RP1,
gpio_offset: GPIO_OFFSET_RP1,
gpio_lines: GPIO_LINES_RP1,
gpio_interface: GpioInterface::Rp1,
pwm_chip: 2,
pwm_channels: [2, 3],
}),
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ use libc::{c_int, O_NOCTTY, O_NONBLOCK};
use libc::{TIOCM_CAR, TIOCM_CTS, TIOCM_DSR, TIOCM_DTR, TIOCM_RNG, TIOCM_RTS};

use crate::gpio::{self, Gpio, IoPin, Mode};
use crate::system::{self, DeviceInfo, Model};
use crate::system::{self, DeviceInfo, Model, SoC};

#[cfg(any(
feature = "embedded-hal-0",
Expand Down Expand Up @@ -422,8 +422,8 @@ impl Uart {
// On the Raspberry Pi 5, by default /dev/serial0 will point to the UART on the debug header,
// which is /dev/ttyAMA10. Check if /dev/ttyAMA0 exists first, which would mean the user
// enabled UART on GPIO14/15 and likely wants to use that one instead.
let path = match DeviceInfo::new()?.model() {
Model::RaspberryPi5 | Model::RaspberryPiComputeModule5 => {
let path = match DeviceInfo::new()?.soc() {
SoC::Bcm2712 => {
if Path::new("/dev/ttyAMA0").exists() {
"/dev/ttyAMA0"
} else {
Expand Down

0 comments on commit 6514378

Please sign in to comment.