Skip to content

Commit

Permalink
Merge branch 'main' into add-vscode-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottGibb authored Dec 17, 2024
2 parents 886229c + d73c694 commit 61f906e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
---
name: Default Pull Request Template
about: Default template for all pull requests
title: ''
labels: ''
assignees: ''
---
## Description
# Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context. List any dependencies that are required for this change.

Expand Down
2 changes: 1 addition & 1 deletion examples/esp32-c3/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ runner = "espflash flash --monitor"
esp32c3 = "run --release --features=esp32c3 --target=riscv32imc-unknown-none-elf"

[env]
ESP_LOGLEVEL = "INFO"
ESP_LOG = "INFO"

[build]
rustflags = [
Expand Down
11 changes: 8 additions & 3 deletions examples/esp32-c3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[package]
name = "esp32-c3"
version = "0.1.0"
authors = ["Scott Gibb <[email protected]>"]
authors = [
"Scott Gibb <[email protected]",
"Pete Kubiak <[email protected]>",
"James Sizeland <[email protected]>",
]
edition = "2021"

[dependencies]
Expand All @@ -12,8 +16,9 @@ esp-backtrace = { version = "0.14.0", features = [
"panic-handler",
"println",
] }
esp-hal = { version = "0.20.1", features = ["esp32c3"] }
esp-println = { version = "0.11.0", features = ["esp32c3", "log"] }

esp-hal = { version = "0.22.0", features = ["esp32c3"] }
esp-println = { version = "0.12.0", features = ["esp32c3", "log"] }
log = { version = "0.4.21" }
tmag5273 = { path = "../../", features = ["log"] }

Expand Down
36 changes: 16 additions & 20 deletions examples/esp32-c3/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,34 @@
#![no_std]
#![no_main]

use embedded_hal::i2c::{I2c, SevenBitAddress};
use embedded_hal::i2c::I2c as I2C_HAL;
use esp_backtrace as _;
use esp_hal::delay::Delay;
use esp_hal::{
clock::ClockControl, gpio::Io, i2c::I2C, peripherals::Peripherals, prelude::*,
system::SystemControl,
};
use esp_hal::i2c::master::I2c;
use esp_hal::{delay::Delay, prelude::*};
use tmag5273::types::{DeviceVersion, TMag5273Error};
use tmag5273::TMag5273;

/// Simple Main Function to run the example
/// This will set up the I2C bus, create a TMag5273 Sensor, print out some device stats, set up the device and then loop round getting some data
/// The data will be the X, Y and Z axis readings and the temperature
/// The loop will sleep for 100 milliseconds between each reading
/// This example is designed to run the Adafruit QT Py ESP32-C3 Board
/// https://learn.adafruit.com/adafruit-qt-py-esp32-c3-wifi-dev-board/pinouts
#[entry]
fn main() -> ! {
esp_println::logger::init_logger(log::LevelFilter::Info);
let peripherals = Peripherals::take();
let system = SystemControl::new(peripherals.SYSTEM);
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);

let clocks = ClockControl::max(system.clock_control).freeze();
let delay = Delay::new(&clocks);
let peripherals = esp_hal::init({
let mut config = esp_hal::Config::default();
// Configure the CPU to run at the maximum frequency.
config.cpu_clock = CpuClock::max();
config
});
let delay = Delay::new();
esp_println::println!("Running 1 Basic Readings!");
// Set up your I2C
let i2c = I2C::new(
peripherals.I2C0,
io.pins.gpio10,
io.pins.gpio8,
400.kHz(),
&clocks,
);
let i2c = I2c::new(peripherals.I2C0, esp_hal::i2c::master::Config::default())
.with_sda(peripherals.GPIO5)
.with_scl(peripherals.GPIO6);

let mut mag_sensor = TMag5273::new(i2c, DeviceVersion::TMAG5273B1)
.unwrap()
Expand All @@ -52,7 +48,7 @@ fn main() -> ! {
/// Print out some device starts by reading the Device ID and Manufacturer ID, panic if it cant be done
fn print_device_stats<I2C>(mag_sensor: &mut TMag5273<I2C>) -> Result<(), TMag5273Error>
where
I2C: I2c<SevenBitAddress>,
I2C: I2C_HAL,
{
let device_id = mag_sensor.get_device_id()?;
esp_println::println!("Device ID: {:?}", device_id);
Expand Down

0 comments on commit 61f906e

Please sign in to comment.