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

DRAFT - Rewrite of ADC code #811

Draft
wants to merge 14 commits into
base: feat/adc-v2
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions boards/atsame54_xpro/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.10.1](https://github.com/atsamd-rs/atsamd/compare/atsame54_xpro-0.10.0...atsame54_xpro-0.10.1) - 2024-12-11

### Other

- updated the following local packages: atsamd-hal

## [0.10.0](https://github.com/atsamd-rs/atsamd/compare/atsame54_xpro-0.9.0...atsame54_xpro-0.10.0) - 2024-11-28

### Added
Expand Down
4 changes: 2 additions & 2 deletions boards/atsame54_xpro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "atsame54_xpro"
version = "0.10.0"
version = "0.10.1"
authors = [
"Karsten Große <[email protected]>",
"John Little <[email protected]>"
Expand All @@ -23,7 +23,7 @@ features = ["critical-section-single-core"]

[dependencies.atsamd-hal]
path = "../../hal"
version = "0.20.0"
version = "0.20.2"
default-features = false

[dependencies.usb-device]
Expand Down
6 changes: 6 additions & 0 deletions boards/feather_m0/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.1](https://github.com/atsamd-rs/atsamd/compare/feather_m0-0.17.0...feather_m0-0.17.1) - 2024-12-11

### Other

- updated the following local packages: atsamd-hal

## [0.17.0](https://github.com/atsamd-rs/atsamd/compare/feather_m0-0.16.0...feather_m0-0.17.0) - 2024-11-28

### Added
Expand Down
4 changes: 2 additions & 2 deletions boards/feather_m0/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "feather_m0"
version = "0.17.0"
version = "0.17.1"
authors = ["Ben Bergman <[email protected]>"]
description = "Board Support crate for the Adafruit Feather M0"
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
Expand All @@ -21,7 +21,7 @@ optional = true

[dependencies.atsamd-hal]
path = "../../hal"
version = "0.20.0"
version = "0.20.2"
default-features = false

[dependencies.cortex-m]
Expand Down
6 changes: 6 additions & 0 deletions boards/feather_m4/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.15.1](https://github.com/atsamd-rs/atsamd/compare/feather_m4-0.15.0...feather_m4-0.15.1) - 2024-12-11

### Other

- updated the following local packages: atsamd-hal

## [0.15.0](https://github.com/atsamd-rs/atsamd/compare/feather_m4-0.14.0...feather_m4-0.15.0) - 2024-11-28

### Added
Expand Down
4 changes: 2 additions & 2 deletions boards/feather_m4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "feather_m4"
version = "0.15.0"
version = "0.15.1"
edition = "2021"
authors = ["Theodore DeRego <[email protected]>"]
description = "Board Support crate for the Adafruit Feather M4"
Expand All @@ -25,7 +25,7 @@ features = ["critical-section-single-core"]

[dependencies.atsamd-hal]
path = "../../hal"
version = "0.20.0"
version = "0.20.2"
default-features = false

[dependencies.usb-device]
Expand Down
6 changes: 6 additions & 0 deletions boards/metro_m0/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.17.1](https://github.com/atsamd-rs/atsamd/compare/metro_m0-0.17.0...metro_m0-0.17.1) - 2024-12-11

### Other

- updated the following local packages: atsamd-hal

## [0.17.0](https://github.com/atsamd-rs/atsamd/compare/metro_m0-0.16.0...metro_m0-0.17.0) - 2024-11-28

### Added
Expand Down
4 changes: 2 additions & 2 deletions boards/metro_m0/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metro_m0"
version = "0.17.0"
version = "0.17.1"
authors = ["Wez Furlong <[email protected]>"]
description = "Board Support crate for the Adafruit Metro M0"
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
Expand All @@ -24,7 +24,7 @@ features = ["critical-section-single-core"]

[dependencies.atsamd-hal]
path = "../../hal"
version = "0.20.0"
version = "0.20.2"
default-features = false

[dependencies.usb-device]
Expand Down
2 changes: 1 addition & 1 deletion boards/metro_m0/examples/blinky_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ mod app {
use hal::clock::{ClockGenId, ClockSource, GenericClockController};
use hal::pac::Peripherals;
use hal::prelude::*;
use hal::rtc::{Count32Mode, Duration, Rtc};
use hal::rtc::{rtic::v1::Duration, Count32Mode, Rtc};

#[local]
struct Local {}
Expand Down
6 changes: 6 additions & 0 deletions boards/metro_m4/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.16.1](https://github.com/atsamd-rs/atsamd/compare/metro_m4-0.16.0...metro_m4-0.16.1) - 2024-12-11

### Other

- updated the following local packages: atsamd-hal

## [0.16.0](https://github.com/atsamd-rs/atsamd/compare/metro_m4-0.15.0...metro_m4-0.16.0) - 2024-11-28

### Added
Expand Down
4 changes: 2 additions & 2 deletions boards/metro_m4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metro_m4"
version = "0.16.0"
version = "0.16.1"
authors = ["Paul Sajna <[email protected]>", "Wez Furlong <[email protected]>"]
description = "Board Support crate for the Adafruit Metro M4"
keywords = ["no-std", "arm", "cortex-m", "embedded-hal"]
Expand All @@ -20,7 +20,7 @@ optional = true

[dependencies.atsamd-hal]
path = "../../hal"
version = "0.20.0"
version = "0.20.2"
default-features = false

[dependencies.usb-device]
Expand Down
6 changes: 6 additions & 0 deletions boards/pygamer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.13.1](https://github.com/atsamd-rs/atsamd/compare/pygamer-0.13.0...pygamer-0.13.1) - 2024-12-11

### Examples

- *(pygamer)* Restore neopixel examples using SPI driver

## [0.13.0](https://github.com/atsamd-rs/atsamd/compare/pygamer-0.12.0...pygamer-0.13.0) - 2024-11-28

### Added
Expand Down
30 changes: 28 additions & 2 deletions boards/pygamer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
name = "pygamer"
readme = "README.md"
repository = "https://github.com/atsamd-rs/atsamd"
version = "0.13.0"
version = "0.13.1"

[dependencies]
cortex-m = {version = "0.7", features = ["critical-section-single-core"]}
Expand All @@ -27,12 +27,17 @@ version = "0.7"
[dependencies.atsamd-hal]
default-features = false
path = "../../hal"
version = "0.20.0"
version = "0.20.2"

[dependencies.usb-device]
optional = true
version = "0.3.2"

[dependencies.ws2812-spi]
version = "0.5.0"
features = ["mosi_idle_high"]
optional = true

[dev-dependencies]
embedded-graphics = "0.8.1"
embedded-sdmmc = "0.8.0"
Expand All @@ -52,6 +57,7 @@ max-channels = ["dma", "atsamd-hal/max-channels"]
panic_led = []
rt = ["cortex-m-rt", "atsamd-hal/samd51j-rt"]
usb = ["atsamd-hal/usb", "usb-device"]
neopixel-spi = ["dep:ws2812-spi"]
# Enable async support from atsamd-hal
async = ["atsamd-hal/async"]

Expand Down Expand Up @@ -89,3 +95,23 @@ name = "timer"
[[example]]
name = "usb_poll"
required-features = ["usb"]

[[example]]
name = "neopixel_adc_battery"
required-features = ["neopixel-spi"]

[[example]]
name = "neopixel_adc_light"
required-features = ["neopixel-spi"]

[[example]]
name = "neopixel_button"
required-features = ["neopixel-spi"]

[[example]]
name = "neopixel_easing"
required-features = ["neopixel-spi"]

[[example]]
name = "neopixel_rainbow"
required-features = ["neopixel-spi"]
89 changes: 89 additions & 0 deletions boards/pygamer/examples/neopixel_adc_battery.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//! Display battery percentage on the neopixels.
//!
//! Note leds may appear white during debug. Either build for release or add
//! opt-level = 2 to profile.dev in Cargo.toml

#![no_std]
#![no_main]

#[cfg(not(feature = "panic_led"))]
use panic_halt as _;
use pygamer::{entry, hal, pac, Pins};

use hal::adc::Adc;
use hal::{clock::GenericClockController, delay::Delay};

use pac::gclk::pchctrl::Genselect::Gclk11;

use hal::ehal::delay::DelayNs;

use pac::{CorePeripherals, Peripherals};
use smart_leds::{brightness, SmartLedsWrite, RGB8};

#[entry]
fn main() -> ! {
let mut peripherals = Peripherals::take().unwrap();
let core = CorePeripherals::take().unwrap();
let mut clocks = GenericClockController::with_internal_32kosc(
peripherals.gclk,
&mut peripherals.mclk,
&mut peripherals.osc32kctrl,
&mut peripherals.oscctrl,
&mut peripherals.nvmctrl,
);
let pins = Pins::new(peripherals.port).split();

let mut adc0 = Adc::adc0(peripherals.adc0, &mut peripherals.mclk, &mut clocks, Gclk11);
let mut battery = pins.battery.init();

// neopixels
let mut neopixel = pins.neopixel.init_spi(
&mut clocks,
// Unfortunately, the SPI driver requires a clock pin, even though it's not used by the
// neopixels.
pins.i2c.scl,
peripherals.sercom2,
&mut peripherals.mclk,
);

let mut delay = Delay::new(core.SYST, &mut clocks);

//todo put this on a .. 10minute, 30min, update timer
loop {
let battery_data = battery.read(&mut adc0);

let mut colors = [
RGB8::default(),
RGB8::default(),
RGB8::default(),
RGB8::default(),
RGB8::default(),
];

if battery_data < 3.6 {
enable_leds(1, &mut colors);
} else if (3.6..3.8).contains(&battery_data) {
enable_leds(2, &mut colors);
} else if (3.8..3.9).contains(&battery_data) {
enable_leds(3, &mut colors);
} else if (3.9..4.0).contains(&battery_data) {
enable_leds(4, &mut colors);
} else {
enable_leds(5, &mut colors);
};

neopixel
.write(brightness(colors.iter().cloned(), 1))
.unwrap();

// Reset the LEDs
delay.delay_ms(10);
}
}

/// Turn on the specified number of LEDs and set the color to red.
fn enable_leds(num_leds: usize, colors: &mut [RGB8]) {
for color in colors.iter_mut().take(num_leds) {
*color = RGB8::from((255, 0, 0));
}
}
Loading
Loading