Skip to content

Commit e019dae

Browse files
committed
Use Amaranth SoC GPIO peripheral.
1 parent e7d52b2 commit e019dae

File tree

3 files changed

+50
-33
lines changed

3 files changed

+50
-33
lines changed

my_design/design.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
from amaranth.lib import wiring
77
from amaranth.lib.wiring import connect
88

9-
from amaranth_soc import csr, wishbone
9+
from amaranth_soc import csr, wishbone, gpio
1010
from amaranth_soc.csr.wishbone import WishboneCSRBridge
1111

1212
from amaranth_vexriscv.vexriscv import VexRiscv
1313

14-
from amaranth_orchard.base.gpio import GPIOPeripheral
1514
from amaranth_orchard.memory.spimemio import SPIMemIO
1615
from amaranth_orchard.io.uart import UARTPeripheral
1716
from amaranth_orchard.memory.sram import SRAMPeripheral
@@ -86,12 +85,16 @@ def elaborate(self, platform):
8685
# LED GPIOs
8786

8887
led_gpio_provider = platform.providers.LEDGPIOProvider()
89-
led_gpio = GPIOPeripheral(pins=led_gpio_provider.pins)
90-
csr_decoder.add(led_gpio.bus, name="led_gpio", addr=self.csr_led_gpio_base - self.csr_base)
88+
led_gpio = gpio.Peripheral(pin_count=8, addr_width=4, data_width=8)
9189

9290
m.submodules.led_gpio_provider = led_gpio_provider
9391
m.submodules.led_gpio = led_gpio
9492

93+
for n in range(8):
94+
connect(m, led_gpio.pins[n], led_gpio_provider.pins[n])
95+
96+
csr_decoder.add(led_gpio.bus, name="led_gpio", addr=self.csr_led_gpio_base - self.csr_base)
97+
9598
# UART
9699

97100
uart_provider = platform.providers.UARTProvider()
@@ -119,12 +122,16 @@ def elaborate(self, platform):
119122
# Button GPIOs
120123

121124
#btn_gpio_provider = platform.providers.ButtonGPIOProvider()
122-
#btn_gpio = GPIOPeripheral(pins=btn_gpio_provider.pins)
123-
#csr_decoder.add(btn_gpio.bus, name="btn_gpio", addr=self.csr_btn_gpio_base - self.csr_base)
125+
#btn_gpio = gpio.Peripheral(pin_count=2, addr_width=4, data_width=8)
124126

125127
#m.submodules.btn_gpio_provider = btn_gpio_provider
126128
#m.submodules.btn_gpio = btn_gpio
127129

130+
#for n in range(2):
131+
# connect(m, btn_gpio.pins[n], btn_gpio_provider.pins[n])
132+
133+
#csr_decoder.add(btn_gpio.bus, name="btn_gpio", addr=self.csr_btn_gpio_base - self.csr_base)
134+
128135
# Wishbone-CSR bridge
129136

130137
wb_to_csr = WishboneCSRBridge(csr_decoder.bus, data_width=32)

my_design/software/main.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ static const uintptr_t kernel_base = 0x00800000;
77
static const uintptr_t dtb_base = 0x00f80000;
88

99
void main() {
10-
unsigned last_buttons = 0, next_buttons = 0;
11-
1210
puts("🐱: nyaa~!\r\n");
1311

1412
puts("SoC type: ");
@@ -29,13 +27,15 @@ void main() {
2927

3028
puts("Initialised!\r\n");
3129

32-
while (1) {
33-
// // Listen for button presses
34-
// next_buttons = BTN_GPIO->in;
35-
// if ((next_buttons & 1U) && !(last_buttons & 1U))
36-
// puts("button 1 pressed!\n");
37-
// if ((next_buttons & 2U) && !(last_buttons & 2U))
38-
// puts("button 2 pressed!\n");
39-
// last_buttons = next_buttons;
40-
};
30+
//unsigned last_buttons = 0;
31+
//unsigned next_buttons = 0;
32+
//while (1) {
33+
// // Listen for button presses
34+
// next_buttons = BTN_GPIO->input;
35+
// if ((next_buttons & 1U) && !(last_buttons & 1U))
36+
// puts("button 1 pressed!\n");
37+
// if ((next_buttons & 2U) && !(last_buttons & 2U))
38+
// puts("button 2 pressed!\n");
39+
// last_buttons = next_buttons;
40+
//};
4141
}

pdm.lock

Lines changed: 26 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)