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
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
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
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
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
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