Skip to content

Commit

Permalink
Get aux and UI working
Browse files Browse the repository at this point in the history
  • Loading branch information
simmsb committed Mar 7, 2024
1 parent d2fc618 commit c1cd162
Show file tree
Hide file tree
Showing 21 changed files with 1,209 additions and 283 deletions.
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ default = ["space_saving", "logging"]
logging = ["dep:ufmt"]
space_saving = ["time_u32"]
time_u32 = []
has_fet = []

[dependencies]
avr-device = { version = "0.5.3", features = ["rt", "attiny1616", "critical-section-impl"] }
Expand Down Expand Up @@ -37,6 +38,12 @@ avr-progmem = "0.4.0"
embedded-io = "0.6.1"
paste = "1.0.14"

cichlid = { git = "https://github.com/simmsb/cichlid", version = "0.2.1", default-features = false, features = [
"nightly",
"no-std",
] }
fixed = "1.25.1"

[dependencies.avr-hal-generic]
git = "https://github.com/rahix/avr-hal.git"

Expand Down
30 changes: 15 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
flash:
cargo build --release --no-default-features --features "space_saving has_fet"
cargo objcopy -q --release --no-default-features --features "space_saving" -- -O ihex target/out.hex
pymcuprog -d attiny1616 -t uart -u /dev/cu.usbserial-A50285BI write -f target/out.hex --erase --verify

flash_nofet:
cargo build --release --no-default-features --features "space_saving"
cargo objcopy -q --release --no-default-features --features "space_saving" -- -O ihex target/out.hex
pymcuprog -d attiny1616 -t uart -u /dev/cu.usbserial-A50285BI write -f target/out.hex --erase --verify
Expand Down
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Before upgrading check that everything is available on all tier1 targets here:
# https://rust-lang.github.io/rustup-components-history
[toolchain]
channel = "nightly-2024-02-04"
components = [ "rust-src" ]
channel = "nightly-2024-03-02"
components = [ "rust-src", "llvm-tools", "rust-analyzer" ]
profile = "minimal"
target = "avr-specs/avr-attiny1616.json"
14 changes: 10 additions & 4 deletions src/adc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::{marker::PhantomData, task::Poll};
use core::{marker::PhantomData, ops::Div, task::Poll};

use atxtiny_hal::vref::{ADCReferenceVoltage, ReferenceVoltage, VrefExt};
use avr_device::attiny1616::{
Expand Down Expand Up @@ -114,18 +114,24 @@ impl Temperature<u16> {
pub struct Voltage<T>(pub T);

impl Voltage<u16> {
pub fn volts_times_40(self) -> u8 {
pub const fn volts_times_40(self) -> u8 {
let r = self.0 << 4;
const NUMERATOR: u32 = (40.0 * 1.5 * 4096.0) as u32;

(NUMERATOR / (r >> 4) as u32) as u8
let n = (r >> 4) as u32;

if n == 0 {
return 0;
}

(NUMERATOR / n) as u8
}

pub const fn volts_to_adc_output(volts: f32) -> Voltage<u16> {
Voltage((6144.0 / volts) as u16)
}

pub fn volts_times_100(self) -> u16 {
pub const fn volts_times_100(self) -> u16 {
let r = self.volts_times_40() as u16;
r * 2 + r / 2
}
Expand Down
Loading

0 comments on commit c1cd162

Please sign in to comment.