~ruther/avr-guess-the-number

ref: d496c1b47a62846703277a36d073c601511bb501 avr-guess-the-number/src/sipo.rs -rw-r--r-- 1.2 KiB
d496c1b4 — František Boháček feat: add avr-device lib 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
use atmega_hal::port::{Pin, mode};

pub struct Sipo {
    srclk : Pin<mode::Output>,
    srclr : Pin<mode::Output>,
    ser : Pin<mode::Output>,
    rclk : Pin<mode::Output>,
}

impl Sipo {
    pub fn create(srclk: Pin<mode::Output>, srclr: Pin<mode::Output>, ser: Pin<mode::Output>, rclk: Pin<mode::Output>) -> Sipo {
        let mut sipo = Sipo {
            srclk,
            srclr,
            ser,
            rclk
        };

        sipo.setup();
        return sipo;
    }

    #[inline]
    pub fn setup(&mut self) {
        self.clear();
        self.show();
    }

    pub fn set(&mut self, value: bool) {
        if value {
            self.ser.set_high();
        } else {
            self.ser.set_low();
        }
    }

    pub fn shift(&mut self) {
        self.srclk.set_low();
        self.srclk.set_high();
        self.srclk.set_low();
    }

    pub fn shift_value(&mut self, value: bool) {
        self.set(value);
        self.shift();
    }

    pub fn show(&mut self) {
        self.rclk.set_low();
        self.rclk.set_high();
        self.rclk.set_low();
    }

    pub fn clear(&mut self) {
        self.srclr.set_low();
        self.srclr.set_high();
    }
}
Do not follow this link