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

Play with trinkey #669

Draft
wants to merge 47 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
15d5c85
Working copy pasted base code.
paulz Jan 22, 2023
b16e310
Adding so far unused import
paulz Jan 22, 2023
ba13a1a
Run with cargo hf2 --release --example blinky_usb_morse_out --feature…
paulz Jan 22, 2023
226ed1b
Modify (inelegantly) the readme
paulz Jan 22, 2023
375ee59
Starting to build morse output...
imf Jan 22, 2023
7adafe3
Renamed example to usb_morse for a little less typing.
imf Jan 22, 2023
466a02d
Finish the morse letter to dot/dash conversion switch case.
imf Jan 22, 2023
c7d6419
add blinking led to usb example
paulz Jan 23, 2023
c293f33
Made the Xiao blink with the milspec preferred blink style of 3 on, 1…
imf Jan 30, 2023
6986c20
Rename board interface.
imf Jan 31, 2023
3edb47e
Add (partially implemented) example.
imf Feb 5, 2023
5981dfb
Start extracing env.
paulz Feb 5, 2023
16119c4
Get peripherals from environment.
paulz Feb 5, 2023
cb8c4c1
Extract core.
paulz Feb 5, 2023
b3209a9
Use core.
paulz Feb 5, 2023
cdef9dd
use morse code to display some LED color
paulz Feb 5, 2023
82c1043
Put our command line in the readme.
imf Feb 5, 2023
ead7a9a
Merge branch 'master' of github.com:paulz/atsamd
imf Feb 5, 2023
a64cd92
Add a character queue.
imf Feb 5, 2023
5c84491
There's a thing to poll to see what state to set the LEDs to for
imf Feb 6, 2023
98bb044
Add FixedSliceVec to project to support embedded Vec (for queues)
imf Feb 6, 2023
a9dfe17
I can dequeue a pin control state. (But I don't in the right place
imf Feb 6, 2023
4a7cf1a
Remove commented code.
imf Feb 6, 2023
bd63fc8
Speed up loop.
imf Feb 6, 2023
5d6de9e
When the pin state queue is empty, return an low voltage request
imf Feb 6, 2023
bd78698
We drain the queue of pin states. We don't refill it yet, but
imf Feb 6, 2023
14add25
Adjust fake data.
imf Feb 6, 2023
11ed143
Fix case where counter decrements below zero (because of a zero
imf Feb 6, 2023
8d30654
Correct fake data to send S-M-S.
imf Feb 6, 2023
c42e772
Fix off by one error in next state queue drain. (It would never
imf Feb 6, 2023
21db3f9
Make the queue into a circular queue to push into... (But the pop
imf Feb 6, 2023
c699856
Convert popState() to treat PIN_CONTROL_QUEUE as a circular
imf Feb 6, 2023
3c6369c
Make the read and writ heads on the pin control queue move
imf Feb 6, 2023
6a0d04d
Working morse emitter.
imf Feb 6, 2023
2a229ed
Clean up some cruft. Conform to more rust standard naming.
imf Feb 6, 2023
8913d3a
Implenent a char queue.
imf Feb 7, 2023
3c30b80
Use new char buffer, for more compact representation.
imf Feb 8, 2023
85332af
Only push new chars into the pin buffer when it's been drained.
imf Feb 8, 2023
958d4e1
Add numbers, space and punctuation.
imf Feb 8, 2023
6ea95d5
Fix word_interval -> space. CHatGPT assumed I'd called it something
imf Feb 8, 2023
3509349
Also fix where copilot thought I wanted a " instead of a '
imf Feb 8, 2023
8e93323
Increased char buffer size to 1K.
imf Feb 8, 2023
10408db
Fix incorrect 'n' encoding.
imf Feb 8, 2023
dc0c558
Extract morse queues and character generation into a module.
imf Feb 12, 2023
bad9fb8
Initial implemenation of hex to rgb function for trinkey
jazKatalyst Feb 12, 2023
410cf03
Merge branch 'master' of github.com:paulz/atsamd
imf Feb 12, 2023
6ab56ba
Extracted morse specific library code into separate module.
imf Feb 12, 2023
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
2 changes: 2 additions & 0 deletions boards/neo_trinkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ cortex-m-rt = { version = "0.7", optional = true }
usb-device = { version = "0.2", optional = true }
smart-leds = { version = "0.3.0", optional = true }
ws2812-timer-delay = { version = "0.3.0", features = ["slow"], optional = true }
cargo-hf2 = "0.3.3"
fixed-slice-vec = "0.10.0"

[dependencies.atsamd-hal]
version = "0.14"
Expand Down
13 changes: 13 additions & 0 deletions boards/neo_trinkey/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
### How to run our first example:

```
cargo hf2 --release --example usb_morse --features usb,leds
```
Connect to the device at /dev/cu.usbmodemTRINKEY_MORSE1
```bash
$ screen /dev/cu.usbmodemTRINKEY_MORSE1 9600
```


```

# Adafruit Neo Trinkey Board Support Crate

This crate provides a type-safe API for working with the [Adafruit Neo Trinkey
Expand Down
53 changes: 53 additions & 0 deletions boards/neo_trinkey/examples/hex_color_converter.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#![no_std]
#![no_main]

pub fn hex_to_rgb(hex: &str) -> Result<(u8, u8, u8), &str> {
let hex = hex.trim_start_matches('#');

let result: Result<(u8, u8, u8), &str> = if hex.len() == 6 {
let r = u8::from_str_radix(&hex[0..2], 16).unwrap();
let g = u8::from_str_radix(&hex[2..4], 16).unwrap();
let b = u8::from_str_radix(&hex[4..6], 16).unwrap();
Ok((r, g, b))
} else if hex.len() == 3 {
let r = u8::from_str_radix(&hex[0..1], 16).unwrap();
let g = u8::from_str_radix(&hex[1..2], 16).unwrap();
let b = u8::from_str_radix(&hex[2..3], 16).unwrap();
Ok((r * 16 + r, g * 16 + g, b * 16 + b))
} else {
Err("Invalid color")
};

result
}

#[cfg(test)]
mod tests {
use super::hex_to_rgb;

#[test]
fn test_valid_hex_to_rgb() {
let success_cases: [(&str, (u8, u8, u8)); 7] = [
("#000000", (0, 0, 0)),
("#ffffff", (255, 255, 255)),
("#FF0000", (255, 0, 0)),
("#00FF00", (0, 255, 0)),
("#0000FF", (0, 0, 255)),
("#F0F0F0", (240, 240, 240)),
("#abcdef", (171, 205, 239)),
];

for case in success_cases.iter() {
let (hex, expected) = case;
let result = hex_to_rgb(hex);

assert_eq!(result.ok().unwrap(), *expected, "hex: {}", hex);
}
}

#[test]
fn test_invalid_hex_to_rgb() {
let invalid_result = hex_to_rgb("invalid");
assert_eq!(invalid_result.err().unwrap(), "Invalid color");
}
}
Loading