components/
sk68xx.rs

1// Licensed under the Apache License, Version 2.0 or the MIT License.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3// Copyright Tock Contributors 2025.
4
5//! Component for the sk68xx LED.
6
7use core::mem::MaybeUninit;
8use kernel::component::Component;
9use kernel::hil;
10
11/// T0H clock divider for an ESP32-C3 with a 160MHz clock speed.
12pub const ESP32C3_160MHZ_T0H: usize = 3;
13
14#[macro_export]
15macro_rules! sk68xx_component_static {
16    ($P:ty, $T0H:expr $(,)?) => {
17        kernel::static_buf!(capsules_extra::sk68xx::Sk68xx<'static, $P, $T0H>)
18    };
19}
20
21/// Custom version of the static for the ESP32-C3 board with a fixed clock speed.
22#[macro_export]
23macro_rules! sk68xx_component_static_esp32c3_160mhz {
24    ($P:ty $(,)?) => {
25        $crate::sk68xx_component_static!($P, { $crate::sk68xx::ESP32C3_160MHZ_T0H })
26    };
27}
28
29pub struct Sk68xxComponent<P: 'static + hil::gpio::Pin, const T0H: usize> {
30    led_pin: &'static P,
31    nop: fn(),
32}
33
34impl<P: 'static + hil::gpio::Pin, const T0H: usize> Sk68xxComponent<P, T0H> {
35    pub fn new(led_pin: &'static P, nop: fn()) -> Self {
36        Self { led_pin, nop }
37    }
38}
39
40impl<P: 'static + hil::gpio::Pin, const T0H: usize> Component for Sk68xxComponent<P, T0H> {
41    type StaticInput = &'static mut MaybeUninit<capsules_extra::sk68xx::Sk68xx<'static, P, T0H>>;
42    type Output = &'static capsules_extra::sk68xx::Sk68xx<'static, P, T0H>;
43
44    fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
45        let sk68xx =
46            static_buffer.write(capsules_extra::sk68xx::Sk68xx::new(self.led_pin, self.nop));
47        sk68xx.init();
48        sk68xx
49    }
50}
51
52#[macro_export]
53macro_rules! sk68xx_led_component_static {
54    ($P:ty,  $T0H:expr $(,)?) => {
55        kernel::static_buf!(capsules_extra::sk68xx::Sk68xxLed<'static, $P, $T0H>)
56    };
57}
58
59/// Custom version of the static for the ESP32-C3 board with a fixed clock speed.
60#[macro_export]
61macro_rules! sk68xx_led_component_static_esp32c3_160mhz {
62    ($P:ty $(,)?) => {
63        $crate::sk68xx_led_component_static!($P, { $crate::sk68xx::ESP32C3_160MHZ_T0H })
64    };
65}
66
67pub type Sk68xxLedComponentType<P, const T0H: usize> =
68    capsules_extra::sk68xx::Sk68xxLed<'static, P, T0H>;
69
70pub struct Sk68xxLedComponent<P: 'static + hil::gpio::Pin, const T0H: usize> {
71    sk68xx: &'static capsules_extra::sk68xx::Sk68xx<'static, P, T0H>,
72    index: usize,
73}
74
75impl<P: 'static + hil::gpio::Pin, const T0H: usize> Sk68xxLedComponent<P, T0H> {
76    pub fn new(
77        sk68xx: &'static capsules_extra::sk68xx::Sk68xx<'static, P, T0H>,
78        index: usize,
79    ) -> Self {
80        Self { sk68xx, index }
81    }
82}
83
84impl<P: 'static + hil::gpio::Pin, const T0H: usize> Component for Sk68xxLedComponent<P, T0H> {
85    type StaticInput = &'static mut MaybeUninit<capsules_extra::sk68xx::Sk68xxLed<'static, P, T0H>>;
86    type Output = &'static capsules_extra::sk68xx::Sk68xxLed<'static, P, T0H>;
87
88    fn finalize(self, static_buffer: Self::StaticInput) -> Self::Output {
89        let sk68xx_led = static_buffer.write(capsules_extra::sk68xx::Sk68xxLed::new(
90            self.sk68xx,
91            self.index,
92        ));
93        sk68xx_led
94    }
95}