Esempio n. 1
0
    def elaborate(self, platform):
        m = Module()

        # Generate our domain clocks/resets.
        m.submodules.car = platform.clock_domain_generator()

        # Create the 32-bit counter we'll be using as our status signal.
        counter = Signal(32)
        m.d.usb += counter.eq(counter + 1)

        # Create our USB device interface...
        ulpi = platform.request(platform.default_usb_connection)
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        usb.add_standard_control_endpoint(descriptors)

        # Create an interrupt endpoint which will carry the value of our counter to the host
        # each time our interrupt EP is polled.
        status_ep = USBSignalInEndpoint(width=32,
                                        endpoint_number=1,
                                        endianness="big")
        usb.add_endpoint(status_ep)
        m.d.comb += status_ep.signal.eq(counter)

        # Connect our device as a high speed device by default.
        m.d.comb += [
            usb.connect.eq(1),
            usb.full_speed_only.eq(1 if os.getenv('LUNA_FULL_ONLY') else 0),
        ]

        return m
Esempio n. 2
0
    def elaborate(self, platform):
        m = Module()

        # Generate our domain clocks/resets.
        m.submodules.car = platform.clock_domain_generator()

        # Create our USB device interface...
        ulpi = platform.request("target_phy")
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        usb.add_standard_control_endpoint(descriptors)

        # Add a stream endpoint to our device.
        stream_ep = USBStreamInEndpoint(endpoint_number=BULK_ENDPOINT_NUMBER,
                                        max_packet_size=MAX_BULK_PACKET_SIZE)
        usb.add_endpoint(stream_ep)

        # Send entirely zeroes, as fast as we can.
        m.d.comb += [
            stream_ep.stream.valid.eq(1),
            stream_ep.stream.payload.eq(0)
        ]

        # Connect our device as a high speed device by default.
        m.d.comb += [
            usb.connect.eq(1),
            usb.full_speed_only.eq(1 if os.getenv('LUNA_FULL_ONLY') else 0),
        ]

        return m
Esempio n. 3
0
	def elaborate(self, platform):
		m = Module()

		m.submodules.car = platform.clock_domain_generator()

		ulpi = platform.request('ulpi')
		m.submodules.usb = usb = USBDevice(bus=ulpi)

		descriptors = self.create_descriptors()
		usb.add_standard_control_endpoint(descriptors)

		stream_ep = USBStreamInEndpoint(
			endpoint_number=self.BULK_ENDPOINT_NUMBER,
			max_packet_size=self.MAX_BULK_PACKET_SIZE,
		)
		usb.add_endpoint(stream_ep)

		counter = Signal(8)
		with m.If(stream_ep.stream.ready):
			m.d.usb += counter.eq(counter + 1)

		m.d.comb += [
			stream_ep.stream.valid  .eq(1),
			stream_ep.stream.payload.eq(counter),
		]

		m.d.comb += [
			usb.connect        	.eq(1),
			usb.full_speed_only	.eq(0),
		]

		return m
Esempio n. 4
0
    def elaborate(self, platform):
        m = Module()

        # Generate our domain clocks/resets.
        m.submodules.car = platform.clock_domain_generator()

        # Create our USB device interface...
        ulpi = platform.request(platform.default_usb_connection)
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        usb.add_standard_control_endpoint(descriptors)

        # Add a stream endpoint to our device.
        iso_ep = USBIsochronousInEndpoint(
            endpoint_number=self.ISO_ENDPOINT_NUMBER,
            max_packet_size=self.MAX_ISO_PACKET_SIZE)
        usb.add_endpoint(iso_ep)

        # We'll tie our address directly to our value, ensuring that we always
        # count as each offset is increased.
        m.d.comb += [
            iso_ep.bytes_in_frame.eq(self.MAX_ISO_PACKET_SIZE * 3),
            iso_ep.value.eq(iso_ep.address)
        ]

        # Connect our device as a high speed device by default.
        m.d.comb += [
            usb.connect.eq(1),
            usb.full_speed_only.eq(1 if os.getenv('LUNA_FULL_ONLY') else 0),
        ]

        return m
Esempio n. 5
0
    def elaborate(self, platform):
        m = Module()

        # Generate our domain clocks/resets.
        m.submodules.car = platform.clock_domain_generator()

        # Create our USB device interface...
        ulpi = platform.request(platform.default_usb_connection)
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        control_ep = usb.add_standard_control_endpoint(descriptors)

        # Create an interrupt endpoint which will carry the value of our counter to the host
        # each time our interrupt EP is polled.

        # Create the 32-bit counter we'll be using as our status signal.
        counter = Signal(32)
        m.d.usb += counter.eq(counter + 1)

        status_ep = USBSignalInEndpoint(
            width=32,
            endpoint_number=INTERRUPT_ENDPOINT_NUMBER,
            endianness="big")
        usb.add_endpoint(status_ep)

        m.d.comb += status_ep.signal.eq(counter)

        # Add a stream endpoint to our device.

        iso_ep = USBIsochronousInEndpoint(endpoint_number=ISO_ENDPOINT_NUMBER,
                                          max_packet_size=MAX_ISO_PACKET_SIZE)
        usb.add_endpoint(iso_ep)

        # We'll tie our address directly to our value, ensuring that we always
        # count as each offset is increased.
        m.d.comb += [
            iso_ep.bytes_in_frame.eq(MAX_ISO_PACKET_SIZE),
            iso_ep.value.eq(iso_ep.address)
        ]

        # Connect our device as a high speed device by default.
        m.d.comb += [
            usb.connect.eq(1),
            usb.full_speed_only.eq(1 if os.getenv('LUNA_FULL_ONLY') else 0),
        ]

        return m
Esempio n. 6
0
    def elaborate(self, platform):
        m = Module()

        # Generate our domain clocks/resets.
        m.submodules.car = platform.clock_domain_generator()

        # Create our USB device interface...
        ulpi = platform.request("target_phy")
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        usb.add_standard_control_endpoint(descriptors)

        # Add a stream endpoint to our device.
        stream_out_ep = USBStreamOutEndpoint(
            endpoint_number=self.BULK_ENDPOINT_NUMBER,
            max_packet_size=self.MAX_BULK_PACKET_SIZE,
        )
        usb.add_endpoint(stream_out_ep)

        # Add a stream endpoint to our device.
        stream_in_ep = USBStreamInEndpoint(
            endpoint_number=self.BULK_ENDPOINT_NUMBER,
            max_packet_size=self.MAX_BULK_PACKET_SIZE
        )
        usb.add_endpoint(stream_in_ep)

        # Connect our endpoints together.
        stream_in = stream_in_ep.stream
        stream_out = stream_out_ep.stream

        m.d.comb += [
            stream_in.payload           .eq(stream_out.payload),
            stream_in.valid             .eq(stream_out.valid),
            stream_in.first             .eq(stream_out.first),
            stream_in.last              .eq(stream_out.last),
            stream_out.ready            .eq(stream_in.ready),

            platform.request("led", 0)  .eq(stream_out.valid),


            usb.connect                 .eq(1)
        ]

        return m
Esempio n. 7
0
    def elaborate(self, platform: Platform) -> Module:
        m = Module()

        ulpi = platform.request(platform.default_usb_connection)
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        control_ep = usb.add_standard_control_endpoint(descriptors)

        # Attach class-request handlers that stall any vendor or reserved requests,
        # as we don't have or need any.
        stall_condition = lambda setup : \
            (setup.type == USBRequestType.VENDOR) | \
            (setup.type == USBRequestType.RESERVED)
        control_ep.add_request_handler(
            StallOnlyRequestHandler(stall_condition))

        ep1_out = USBStreamOutEndpoint(
            endpoint_number=1,  # EP 1 OUT
            max_packet_size=self.MAX_PACKET_SIZE)
        usb.add_endpoint(ep1_out)

        if self.with_midi_in:
            ep1_in = USBStreamInEndpoint(
                endpoint_number=1,  # EP 1 IN
                max_packet_size=self.MAX_PACKET_SIZE)
            usb.add_endpoint(ep1_in)

        for endpoint in self.additional_endpoints:
            usb.add_endpoint(endpoint)

        connect_button = 0  #platform.request("button", 0)
        m.d.comb += [
            usb.connect.eq(~connect_button),
            # Connect our device as a high speed device
            usb.full_speed_only.eq(0),
            self.stream_out.stream_eq(ep1_out.stream),
            self.usb_tx_active_out.eq(usb.tx_activity_led),
            self.usb_rx_active_out.eq(usb.rx_activity_led),
            self.usb_suspended_out.eq(usb.suspended),
            self.usb_reset_detected_out.eq(usb.reset_detected),
        ]

        return m
Esempio n. 8
0
    def elaborate(self, platform):
        m = Module()

        # Generate our domain clocks/resets.
        m.submodules.car = platform.clock_domain_generator()

        # Create our USB device interface...
        ulpi = platform.request(platform.default_usb_connection)
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        usb.add_standard_control_endpoint(descriptors)

        # Add a stream endpoint to our device.
        stream_ep = USBStreamOutEndpoint(
            endpoint_number=self.BULK_ENDPOINT_NUMBER,
            max_packet_size=self.MAX_BULK_PACKET_SIZE)
        usb.add_endpoint(stream_ep)

        leds = Cat(
            platform.request_optional("led", i, default=NullPin())
            for i in range(6))
        user_io = Cat(
            platform.request_optional("user_io", i, default=NullPin())
            for i in range(4))

        # Always stream our USB data directly onto our User I/O and LEDS.
        with m.If(stream_ep.stream.valid):
            m.d.usb += [
                leds.eq(stream_ep.stream.payload),
                user_io.eq(stream_ep.stream.payload),
            ]

        # Always accept data as it comes in.
        m.d.comb += stream_ep.stream.ready.eq(1)

        # Connect our device as a high speed device by default.
        m.d.comb += [
            usb.connect.eq(1),
            usb.full_speed_only.eq(1 if os.getenv('LUNA_FULL_ONLY') else 0),
        ]

        return m
Esempio n. 9
0
    def elaborate(self, platform):
        m = Module()

        # Generate our domain clocks/resets.
        m.submodules.car = platform.clock_domain_generator()

        # Create our USB device interface...
        ulpi = platform.request("target_phy")
        m.submodules.usb = usb = USBDevice(bus=ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        usb.add_standard_control_endpoint(descriptors)

        # Add a stream endpoint to our device.
        stream_ep = USBStreamInEndpoint(
            endpoint_number=self.BULK_ENDPOINT_NUMBER,
            max_packet_size=self.MAX_BULK_PACKET_SIZE
        )
        usb.add_endpoint(stream_ep)

        # Always generate a monotonic count for our stream, which counts every time our
        # stream endpoint accepts a data byte.
        counter = Signal(8)
        with m.If(stream_ep.stream.ready):
            m.d.usb += counter.eq(counter + 1)

        m.d.comb += [
            stream_ep.stream.valid    .eq(1),
            stream_ep.stream.payload  .eq(counter)
        ]


        # Connect our device as a high speed device by default.
        m.d.comb += [
            usb.connect          .eq(1),
            usb.full_speed_only  .eq(1 if os.getenv('LUNA_FULL_ONLY') else 0),
        ]


        return m
Esempio n. 10
0
    def elaborate(self, platform):
        m = Module()

        # Generate our clock domains.
        clocking = LunaECP5DomainGenerator()
        m.submodules.clocking = clocking

        # Create our UTMI translator.
        ulpi = platform.request("target_phy")
        m.submodules.utmi = utmi = UTMITranslator(ulpi=ulpi)

        # Strap our power controls to be in VBUS passthrough by default,
        # on the target port.
        m.d.comb += [
            platform.request("power_a_port").o.eq(0),
            platform.request("pass_through_vbus").o.eq(1),
        ]

        # Set up our parameters.
        m.d.comb += [

            # Set our mode to non-driving and to the desired speed.
            utmi.op_mode.eq(0b01),
            utmi.xcvr_select.eq(self.usb_speed),

            # Disable all of our terminations, as we want to participate in
            # passive observation.
            utmi.dm_pulldown.eq(0),
            utmi.dm_pulldown.eq(0),
            utmi.term_select.eq(0)
        ]

        # Create our USB uplink interface...
        uplink_ulpi = platform.request("host_phy")
        m.submodules.usb = usb = USBDevice(bus=uplink_ulpi)

        # Add our standard control endpoint to the device.
        descriptors = self.create_descriptors()
        usb.add_standard_control_endpoint(descriptors)

        # Add a stream endpoint to our device.
        stream_ep = USBStreamInEndpoint(endpoint_number=BULK_ENDPOINT_NUMBER,
                                        max_packet_size=MAX_BULK_PACKET_SIZE)
        usb.add_endpoint(stream_ep)

        # Create a USB analyzer, and connect a register up to its output.
        m.submodules.analyzer = analyzer = USBAnalyzer(utmi_interface=utmi)

        m.d.comb += [
            # USB stream uplink.
            stream_ep.stream.stream_eq(analyzer.stream),
            usb.connect.eq(1),

            # LED indicators.
            platform.request("led", 0).o.eq(analyzer.capturing),
            platform.request("led", 1).o.eq(analyzer.stream.valid),
            platform.request("led", 2).o.eq(analyzer.overrun),
            platform.request("led", 3).o.eq(utmi.session_valid),
            platform.request("led", 4).o.eq(utmi.rx_active),
            platform.request("led", 5).o.eq(utmi.rx_error),
        ]

        # Return our elaborated module.
        return m