Skip to content

Commit b4c85e0

Browse files
committed
switch to axp192 from rcloran
1 parent ad47396 commit b4c85e0

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

m5stack-core2/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "spooky-m5stack-core2"
3-
version = "0.9.0"
3+
version = "0.10.0"
44
authors = ["Juraj Michálek <[email protected]>"]
55
edition = "2021"
66
license = "MIT"
@@ -34,8 +34,7 @@ spooky-core = { path = "../spooky-core", default-features = false, features = [
3434
spooky-embedded = { path = "../spooky-embedded", default-features = false, features = [ "esp32", "static_maze", "resolution_320x240", "mpu6886" ] }
3535
esp-println = { version = "0.7.0", features = [ "esp32", "log" ] }
3636
log = { version = "0.4.18" }
37-
axp192 = { git = "https://github.com/georgik/axp192-rs.git", rev = "80e4fd27dfab"}
38-
#axp192 = { path = "../../axp192", optional = true }
37+
axp192 = { version = "0.1.1" }
3938
spi-dma-displayinterface = { path = "../spi-dma-displayinterface", features = [ "esp32" ] }
4039

4140
[features]

m5stack-core2/src/main.rs

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,69 @@ use mpu6886::Mpu6886;
5555
use spooky_core::engine::Engine;
5656
use shared_bus::BusManagerSimple;
5757

58-
use embedded_hal::digital::v2::OutputPin;
58+
use embedded_hal::{
59+
digital::v2::OutputPin,
60+
blocking::i2c::{ Read, Write, WriteRead }
61+
};
5962

60-
use axp192::{ I2CPowerManagementInterface, Axp192 };
63+
use axp192::{ Axp192 };
6164

6265
pub struct Universe<D> {
6366
pub engine: Engine<D>,
6467
}
6568

69+
// Source: https://github.com/rcloran/axp192-rs/blob/main/examples/m5stack-core2.rs
70+
fn m5sc2_init<I2C, E>(axp: &mut axp192::Axp192<I2C>, delay: &mut Delay) -> Result<(), E>
71+
where
72+
I2C: Read<Error = E>
73+
+ Write<Error = E>
74+
+ WriteRead<Error = E>,
75+
{
76+
// Default setup for M5Stack Core 2
77+
axp.set_dcdc1_voltage(3350)?; // Voltage to provide to the microcontroller (this one!)
78+
79+
axp.set_ldo2_voltage(3300)?; // Peripherals (LCD, ...)
80+
axp.set_ldo2_on(true)?;
81+
82+
axp.set_ldo3_voltage(2000)?; // Vibration motor
83+
axp.set_ldo3_on(false)?;
84+
85+
axp.set_dcdc3_voltage(2800)?; // LCD backlight
86+
axp.set_dcdc3_on(true)?;
87+
88+
axp.set_gpio1_mode(axp192::GpioMode12::NmosOpenDrainOutput)?; // Power LED
89+
axp.set_gpio1_output(false)?; // In open drain modes, state is opposite to what you might
90+
// expect
91+
92+
axp.set_gpio2_mode(axp192::GpioMode12::NmosOpenDrainOutput)?; // Speaker
93+
axp.set_gpio2_output(true)?;
94+
95+
axp.set_key_mode(
96+
// Configure how the power button press will work
97+
axp192::ShutdownDuration::Sd4s,
98+
axp192::PowerOkDelay::Delay64ms,
99+
true,
100+
axp192::LongPress::Lp1000ms,
101+
axp192::BootTime::Boot512ms,
102+
)?;
103+
104+
axp.set_gpio4_mode(axp192::GpioMode34::NmosOpenDrainOutput)?; // LCD reset control
105+
106+
axp.set_battery_voltage_adc_enable(true)?;
107+
axp.set_battery_current_adc_enable(true)?;
108+
axp.set_acin_current_adc_enable(true)?;
109+
axp.set_acin_voltage_adc_enable(true)?;
110+
111+
// Actually reset the LCD
112+
axp.set_gpio4_output(false)?;
113+
axp.set_ldo3_on(true)?; // Buzz the vibration motor while intializing ¯\_(ツ)_/¯
114+
delay.delay_ms(100u32);
115+
axp.set_gpio4_output(true)?;
116+
axp.set_ldo3_on(false)?;
117+
delay.delay_ms(100u32);
118+
119+
Ok(())
120+
}
66121

67122
#[entry]
68123
fn main() -> ! {
@@ -93,11 +148,10 @@ fn main() -> ! {
93148

94149
let bus = BusManagerSimple::new(i2c_bus);
95150

96-
let axp_interface = I2CPowerManagementInterface::new(bus.acquire_i2c());
97-
let mut axp = Axp192::new(axp_interface);
98-
axp.init().unwrap();
151+
let mut axp = axp192::Axp192::new(bus.acquire_i2c());
99152

100153
// M5Stack CORE 2 - https://docs.m5stack.com/en/core/core2
154+
m5sc2_init(&mut axp, &mut delay).unwrap();
101155

102156
let lcd_sclk = io.pins.gpio18;
103157
let lcd_mosi = io.pins.gpio23;

0 commit comments

Comments
 (0)