concertina

Elecronic concertina
git clone https://git.woozle.org/neale/concertina.git

concertina / src
Neale Pickett  ·  2026-02-24

main.rs

 1#![no_std]
 2#![no_main]
 3
 4//! Neopixel example for the Adafruit QT Py board. Demonstrates powering up the
 5//! neopixel using the attached GPIO line.
 6//!
 7//! *NOTE*: This example currently only works in release mode.
 8
 9use hal::ehal::digital::v1_compat::OldOutputPin;
10use panic_halt as _;
11use smart_leds::hsv::hsv2rgb;
12use smart_leds::hsv::Hsv;
13use smart_leds::SmartLedsWrite;
14use ws2812_timer_delay::Ws2812;
15
16use bsp::entry;
17use bsp::hal;
18use bsp::Pins;
19use hal::clock::GenericClockController;
20use hal::delay::Delay;
21use hal::pac::CorePeripherals;
22use hal::pac::Peripherals;
23use hal::prelude::*;
24use hal::timer::TimerCounter;
25use qt_py_m0 as bsp;
26
27#[entry]
28fn main() -> ! {
29    let mut peripherals = Peripherals::take().unwrap();
30    let core = CorePeripherals::take().unwrap();
31    let mut clocks = GenericClockController::with_internal_8mhz(
32        peripherals.GCLK,
33        &mut peripherals.PM,
34        &mut peripherals.SYSCTRL,
35        &mut peripherals.NVMCTRL,
36    );
37
38    let pins = Pins::new(peripherals.PORT).split();
39
40    let gclk0 = clocks.gclk0();
41    let timer_clock = clocks.tcc2_tc3(&gclk0).unwrap();
42    let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.TC3, &mut peripherals.PM);
43    timer.start(3.mhz());
44
45    // The neopixel sources power from a GPIO pin. It must be driven high to power
46    // up the neopixel before it can be used.
47    pins.neopixel
48        .power
49        .into_push_pull_output()
50        .set_high()
51        .unwrap();
52
53    let neopixel_data: OldOutputPin<_> = pins.neopixel.data.into_push_pull_output().into();
54    let mut neopixel = Ws2812::new(timer, neopixel_data);
55    let mut delay = Delay::new(core.SYST, &mut clocks);
56
57    loop {
58        for j in 0..255u8 {
59            neopixel
60                .write(
61                    [hsv2rgb(Hsv {
62                        hue: j,
63                        sat: 255,
64                        val: 16,
65                    })]
66                    .iter()
67                    .cloned(),
68                )
69                .unwrap();
70            delay.delay_ms(5u8);
71        }
72    }
73}