1use crate::xs::Bits;
3pub const BASE: u32 = 0xd000_0000;
4
5pub const GPIO_OUT: *mut u32 = (BASE + 0x10) as *mut u32;
10pub const GPIO_OUT_SET: *mut u32 = (BASE + 0x14) as *mut u32;
12pub const GPIO_OUT_CLR: *mut u32 = (BASE + 0x18) as *mut u32;
14pub const GPIO_OUT_XOR: *mut u32 = (BASE + 0x1C) as *mut u32;
16pub const GPIO_OE: *mut u32 = (BASE + 0x20) as *mut u32;
18pub const GPIO_OE_SET: *mut u32 = (BASE + 0x24) as *mut u32;
20pub const GPIO_OE_CLR: *mut u32 = (BASE + 0x28) as *mut u32;
22pub const GPIO_OE_XOR: *mut u32 = (BASE + 0x2C) as *mut u32;
24pub fn gpio_oe_set(gpio: u32) {
27 GPIO_OE_SET.set(1 << gpio);
28}
29pub fn gpio_oe_clr(gpio: u32) {
30 GPIO_OE_CLR.clear(1 << gpio);
31}
32pub fn gpio_oe_xor(gpio: u32) {
33 GPIO_OE_XOR.xor(1 << gpio);
34}
35pub fn gpio_out_set(gpio: u32) {
36 GPIO_OUT_SET.set(1 << gpio);
37}
38pub fn gpio_out_clr(gpio: u32) {
39 GPIO_OUT_CLR.set(1 << gpio);
40}
41pub fn gpio_out_xor(gpio: u32) {
42 GPIO_OUT_XOR.xor(1 << gpio);
43}
44
45pub struct OutputSet {
47 gpio: u32,
48 base_address: *mut u32,
49 set: *mut u32,
50 clear: *mut u32,
51 xor: *mut u32,
52}
53
54impl OutputSet {
55 pub fn new(base_address: u32, gpio_pin: u32) -> Self {
56 Self {
57 gpio: gpio_pin,
58 base_address: base_address as *mut u32,
59 set: (base_address + 0x04) as *mut u32,
60 clear: (base_address + 0x08) as *mut u32,
61 xor: (base_address + 0x0c) as *mut u32,
62 }
63 }
64
65 pub fn set(&mut self) {
66 self.set.set(1 << self.gpio);
67 }
68
69 pub fn clr(&mut self) {
70 self.clear.set(1 << self.gpio);
71 }
72
73 pub fn xor(&mut self) {
74 self.xor.xor(1 << self.gpio);
75 }
76}
77
78pub fn gpio_input_value() -> u32 {
79 const GPIO_IN: *mut u32 = (BASE + 0x004) as *mut u32;
82 let value: u32;
83 unsafe {
84 value = GPIO_IN.read_volatile();
85 }
86 value
87}