Skip to content

Commit cef1921

Browse files
committed
gateware.usb2.endpoints: use amaranth.lib.streams for isochronous endpoints
1 parent 4fe910d commit cef1921

File tree

3 files changed

+43
-23
lines changed

3 files changed

+43
-23
lines changed

luna/gateware/stream/future.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# This file is part of LUNA.
3+
#
4+
# Copyright (c) 2025 Great Scott Gadgets <[email protected]>
5+
# SPDX-License-Identifier: BSD-3-Clause
6+
7+
""" Core stream definitions for supporting native Amaranth 0.5 streams. """
8+
9+
from amaranth import *
10+
from amaranth.lib import data
11+
12+
class Packet(data.StructLayout):
13+
def __init__(self, data_layout, first=True, last=True):
14+
layout = (first and { "first": unsigned(1) } or {}) \
15+
| (last and { "last": unsigned(1) } or {})
16+
super().__init__(layout | {
17+
"data": data_layout
18+
})

luna/gateware/usb/usb2/endpoints/isochronous_in.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
#
22
# This file is part of LUNA.
33
#
4-
# Copyright (c) 2020 Great Scott Gadgets <[email protected]>
4+
# Copyright (c) 2020-2025 Great Scott Gadgets <[email protected]>
55
# SPDX-License-Identifier: BSD--3-Clause
66
""" Endpoint interfaces for isochronous endpoints.
77
88
These interfaces provide interfaces for connecting streams or stream-like
99
interfaces to hosts via isochronous pipes.
1010
"""
1111

12-
from amaranth import Elaboratable, Module, Signal, unsigned
13-
# TODO from amaranth.lib import stream
12+
from amaranth import *
13+
from amaranth.lib import stream
1414

15-
from ..endpoint import EndpointInterface
16-
from ...stream import StreamInterface # TODO
15+
from ..endpoint import EndpointInterface
1716

1817

1918
class USBIsochronousStreamInEndpoint(Elaboratable):
@@ -69,10 +68,7 @@ def __init__(self, *, endpoint_number, max_packet_size):
6968
# I/O Port
7069
#
7170
self.interface = EndpointInterface()
72-
# TODO self.stream = stream.Interface(
73-
# stream.Signature(unsigned(8))
74-
# )
75-
self.stream = StreamInterface()
71+
self.stream = stream.Interface(stream.Signature(unsigned(8)))
7672
self.data_requested = Signal()
7773
self.frame_finished = Signal()
7874

luna/gateware/usb/usb2/endpoints/isochronous_out.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# This file is part of LUNA.
33
#
4-
# Copyright (c) 2020 Great Scott Gadgets <[email protected]>
4+
# Copyright (c) 2020-2025 Great Scott Gadgets <[email protected]>
55
# SPDX-License-Identifier: BSD-3-Clause
66

77
""" Endpoint interfaces for isochronous endpoints.
@@ -10,11 +10,14 @@
1010
interfaces to hosts via isochronous pipes.
1111
"""
1212

13-
from amaranth import Elaboratable, Module, Signal
13+
from amaranth import *
14+
from amaranth.lib import stream, wiring
15+
from amaranth.lib .wiring import In, Out
1416

15-
from ..endpoint import EndpointInterface
16-
from ...stream import StreamInterface, USBOutStreamBoundaryDetector
17-
from ....memory import TransactionalizedFIFO
17+
from ..endpoint import EndpointInterface
18+
from ...stream import USBOutStreamBoundaryDetector
19+
from ....stream.future import Packet
20+
from ....memory import TransactionalizedFIFO
1821

1922

2023
class USBIsochronousStreamOutEndpoint(Elaboratable):
@@ -52,10 +55,13 @@ def __init__(self, *, endpoint_number, max_packet_size, buffer_size=None):
5255
#
5356
# I/O port
5457
#
55-
self.stream = StreamInterface()
58+
self.stream = stream.Interface(
59+
stream.Signature(
60+
Packet(unsigned(8))
61+
)
62+
)
5663
self.interface = EndpointInterface()
5764

58-
5965
def elaborate(self, platform):
6066
m = Module()
6167

@@ -122,17 +128,17 @@ def elaborate(self, platform):
122128

123129
# Our stream data always comes directly out of the FIFO; and is valid
124130
# whenever our FIFO actually has data for us to read.
125-
stream.valid .eq(~fifo.empty),
126-
stream.payload .eq(fifo.read_data[0:8]),
131+
stream.valid .eq(~fifo.empty),
132+
stream.p.data .eq(fifo.read_data[0:8]),
127133

128134
# Our `last` bit comes directly from the FIFO; and we know a `first` bit immediately
129135
# follows a `last` one.
130-
stream.last .eq(fifo.read_data[8]),
131-
stream.first .eq(fifo.read_data[9]),
136+
stream.p.last .eq(fifo.read_data[8]),
137+
stream.p.first .eq(fifo.read_data[9]),
132138

133-
# Move to the next byte in the FIFO whenever our stream is advaced.
134-
fifo.read_en .eq(stream.ready),
135-
fifo.read_commit .eq(1)
139+
# Move to the next byte in the FIFO whenever our stream is advanced.
140+
fifo.read_en .eq(stream.ready),
141+
fifo.read_commit .eq(1)
136142
]
137143

138144
# Count bytes in packet.

0 commit comments

Comments
 (0)