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
27include!("types.rs");
28include!(concat!(env!("OUT_DIR"), "/layouts_data.rs"));
29
30#[entry]
31fn main() -> ! {
32    let mut peripherals = Peripherals::take().unwrap();
33    let core = CorePeripherals::take().unwrap();
34    let mut clocks = GenericClockController::with_internal_8mhz(
35        peripherals.GCLK,
36        &mut peripherals.PM,
37        &mut peripherals.SYSCTRL,
38        &mut peripherals.NVMCTRL,
39    );
40
41    let pins = Pins::new(peripherals.PORT).split();
42
43    let gclk0 = clocks.gclk0();
44    let timer_clock = clocks.tcc2_tc3(&gclk0).unwrap();
45    let mut timer = TimerCounter::tc3_(&timer_clock, peripherals.TC3, &mut peripherals.PM);
46    timer.start(3.mhz());
47
48    // The neopixel sources power from a GPIO pin. It must be driven high to power
49    // up the neopixel before it can be used.
50    pins.neopixel
51        .power
52        .into_push_pull_output()
53        .set_high()
54        .unwrap();
55
56    let neopixel_data: OldOutputPin<_> = pins.neopixel.data.into_push_pull_output().into();
57    let mut neopixel = Ws2812::new(timer, neopixel_data);
58    let mut delay = Delay::new(core.SYST, &mut clocks);
59
60    loop {
61        for j in 0..255u8 {
62            neopixel
63                .write(
64                    [hsv2rgb(Hsv {
65                        hue: j,
66                        sat: 255,
67                        val: 16,
68                    })]
69                    .iter()
70                    .cloned(),
71                )
72                .unwrap();
73            delay.delay_ms(5u8);
74        }
75    }
76}