Skip to content

Commit d92258e

Browse files
committed
Use Amaranth SoC GPIO peripheral.
1 parent 95e88e8 commit d92258e

File tree

5 files changed

+73
-40
lines changed

5 files changed

+73
-40
lines changed

chipflow_lib/providers/board_ulx3s.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
from amaranth import *
44
from amaranth_boards.ulx3s import *
55
from amaranth.lib.cdc import ResetSynchronizer
6-
from amaranth.lib import io
6+
from amaranth.lib import io, wiring
7+
from amaranth.lib.wiring import In
8+
9+
from amaranth_soc import gpio
710

811
from amaranth_orchard.memory.spimemio import QSPIPins
9-
from amaranth_orchard.base.gpio import GPIOPins
1012
from amaranth_orchard.io.uart import UARTPins
1113
from amaranth_orchard.memory.hyperram import HyperRAMPins
1214

@@ -47,29 +49,27 @@ def elaborate(self, platform):
4749
return m
4850

4951

50-
class LEDGPIOProvider(Elaboratable):
51-
def __init__(self):
52-
self.pins = GPIOPins(width=8)
52+
class LEDGPIOProvider(wiring.Component):
53+
pins: In(gpio.PinSignature()).array(8)
5354

5455
def elaborate(self, platform):
5556
m = Module()
5657
for i in range(8):
5758
led = io.Buffer("o", platform.request("led", i, dir="-"))
5859
m.submodules[f"led_{i}"] = led
59-
m.d.comb += led.o.eq(self.pins.o[i])
60+
m.d.comb += led.o.eq(self.pins[i].o)
6061
return m
6162

6263

63-
class ButtonGPIOProvider(Elaboratable):
64-
def __init__(self):
65-
self.pins = GPIOPins(width=2)
64+
class ButtonGPIOProvider(wiring.Component):
65+
pins: In(gpio.PinSignature()).array(2)
6666

6767
def elaborate(self, platform):
6868
m = Module()
6969
for i in range(2):
7070
btn = io.Buffer("i", platform.request("button_fire", i, dir="-"))
7171
m.submodules[f"btn_{i}"] = btn
72-
m.d.comb += self.pins.i[i].eq(btn.i)
72+
m.d.comb += self.pins[i].i.eq(btn.i)
7373
return m
7474

7575

chipflow_lib/providers/silicon.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
from amaranth import *
44
from amaranth.lib.cdc import FFSynchronizer
5+
from amaranth.lib import wiring
6+
from amaranth.lib.wiring import In
7+
8+
from amaranth_soc import gpio
59

610
from amaranth_orchard.memory.spimemio import QSPIPins
7-
from amaranth_orchard.base.gpio import GPIOPins
811
from amaranth_orchard.io.uart import UARTPins
912
from amaranth_orchard.memory.hyperram import HyperRAMPins
1013

@@ -29,34 +32,32 @@ def elaborate(self, platform):
2932
return m
3033

3134

32-
class LEDGPIOProvider(Elaboratable):
33-
def __init__(self):
34-
self.pins = GPIOPins(width=8)
35+
class LEDGPIOProvider(wiring.Component):
36+
pins: In(gpio.PinSignature()).array(8)
3537

3638
def elaborate(self, platform):
3739
m = Module()
3840
for index in range(8):
3941
pin = platform.request(f"gpio_{index}")
4042
m.d.comb += [
41-
self.pins.i[index].eq(pin.i),
42-
pin.o.eq(self.pins.o[index]),
43-
pin.oe.eq(self.pins.oe[index])
43+
self.pins[index].i.eq(pin.i),
44+
pin.o.eq(self.pins[index].o),
45+
pin.oe.eq(self.pins[index].oe),
4446
]
4547
return m
4648

4749

48-
class ButtonGPIOProvider(Elaboratable):
49-
def __init__(self):
50-
self.pins = GPIOPins(width=2)
50+
class ButtonGPIOProvider(wiring.Component):
51+
pins: In(gpio.PinSignature()).array(2)
5152

5253
def elaborate(self, platform):
5354
m = Module()
5455
for index in range(2):
5556
pin = platform.request(f"btn_{index}")
5657
m.d.comb += [
57-
self.pins.i[index].eq(pin.i),
58-
pin.o.eq(self.pins.o[index]),
59-
pin.oe.eq(self.pins.oe[index])
58+
self.pins[index].i.eq(pin.i),
59+
pin.o.eq(self.pins[index].o),
60+
pin.oe.eq(self.pins[index].oe),
6061
]
6162
return m
6263

chipflow_lib/providers/sim.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# SPDX-License-Identifier: BSD-2-Clause
22

33
from amaranth import *
4+
from amaranth.lib import wiring
5+
from amaranth.lib.wiring import In
6+
7+
from amaranth_soc import gpio
48

59
from amaranth_orchard.memory.spimemio import QSPIPins
6-
from amaranth_orchard.base.gpio import GPIOPins
710
from amaranth_orchard.io.uart import UARTPins
811
from amaranth_orchard.memory.hyperram import HyperRAMPins
912

@@ -16,21 +19,20 @@ def elaborate(self, platform):
1619
return platform.add_model("spiflash_model", self.pins, edge_det=['clk_o', 'csn_o'])
1720

1821

19-
class LEDGPIOProvider(Elaboratable):
20-
def __init__(self):
21-
self.pins = GPIOPins(width=8)
22+
class LEDGPIOProvider(wiring.Component):
23+
pins: In(gpio.PinSignature()).array(8)
2224

2325
def elaborate(self, platform):
2426
return Module()
2527

2628

27-
class ButtonGPIOProvider(Elaboratable):
28-
def __init__(self):
29-
self.pins = GPIOPins(width=2)
29+
class ButtonGPIOProvider(wiring.Component):
30+
pins: In(gpio.PinSignature()).array(2)
3031

3132
def elaborate(self, platform):
3233
m = Module()
33-
m.d.comb += self.pins.i.eq(platform.buttons)
34+
for i in range(2):
35+
m.d.comb += self.pins[i].i.eq(platform.buttons[i])
3436
return m
3537

3638

chipflow_lib/software/drivers/gpio.h

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,45 @@
44

55
#include <stdint.h>
66

7-
typedef struct __attribute__((packed, aligned(4))) {
8-
uint32_t out;
9-
uint32_t oe;
10-
uint32_t in;
7+
typedef struct __attribute__((packed, aligned(2))) {
8+
uint16_t mode;
9+
uint8_t input;
10+
uint8_t output;
11+
uint16_t setclr;
1112
} gpio_regs_t;
1213

14+
typedef enum {
15+
#define _GPIO_PIN(n) \
16+
GPIO_PIN ## n ## _INPUT_ONLY = (0 << 2 * (n)), \
17+
GPIO_PIN ## n ## _PUSH_PULL = (1 << 2 * (n)), \
18+
GPIO_PIN ## n ## _OPEN_DRAIN = (2 << 2 * (n)), \
19+
GPIO_PIN ## n ## _ALTERNATE = (3 << 2 * (n))
20+
21+
_GPIO_PIN(0),
22+
_GPIO_PIN(1),
23+
_GPIO_PIN(2),
24+
_GPIO_PIN(3),
25+
_GPIO_PIN(4),
26+
_GPIO_PIN(5),
27+
_GPIO_PIN(6),
28+
_GPIO_PIN(7),
29+
#undef _GPIO_PIN
30+
} gpio_mode_t;
31+
32+
typedef enum {
33+
#define _GPIO_PIN(n) \
34+
GPIO_PIN ## n ## _SET = (1 << 2 * (n)), \
35+
GPIO_PIN ## n ## _CLEAR = (2 << 2 * (n))
36+
37+
_GPIO_PIN(0),
38+
_GPIO_PIN(1),
39+
_GPIO_PIN(2),
40+
_GPIO_PIN(3),
41+
_GPIO_PIN(4),
42+
_GPIO_PIN(5),
43+
_GPIO_PIN(6),
44+
_GPIO_PIN(7),
45+
#undef _GPIO_PIN
46+
} gpio_setclr_t;
47+
1348
#endif

chipflow_lib/software/soft_gen.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ def start(self):
126126
blt a0, a1, loop_init_bss
127127
end_init_bss:
128128
129-
# Update LEDs
130-
li a0, 0xb1000000
131-
li a1, 2
132-
sw a1, 0(a0)
133-
134129
# call main
135130
call main
136131
loop:

0 commit comments

Comments
 (0)