def elaborate(self, platform): m = Module() # Generate our domain clocks/resets. m.submodules.car = platform.clock_domain_generator() # Create our USB device interface... bus = platform.request(platform.default_usb_connection) m.submodules.usb = usb = USBDevice(bus=bus) # Add our standard control endpoint to the device. descriptors = self.create_descriptors() usb.add_standard_control_endpoint(descriptors) # 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), ] # ... and for now, attach our LEDs to our most recent control request. m.d.comb += [ platform.request_optional('led', 0, default=NullPin()).o .eq(usb.tx_activity_led), platform.request_optional('led', 1, default=NullPin()).o .eq(usb.rx_activity_led), platform.request_optional('led', 2, default=NullPin()).o .eq(usb.suspended), ] return m
def elaborate(self, platform): """ Generate the Blinky tester. """ m = Module() # Grab our I/O connectors. leds = [ platform.request_optional("led", i, default=NullPin()).o for i in range(0, 8) ] user_io = [ platform.request_optional("user_io", i, default=NullPin()).o for i in range(0, 8) ] # Clock divider / counter. counter = Signal(28) m.d.sync += counter.eq(counter + 1) # Attach the LEDs and User I/O to the MSBs of our counter. m.d.comb += Cat(leds).eq(counter[-7:-1]) m.d.comb += Cat(user_io).eq(counter[7:21]) # Return our elaborated module. return m
def elaborate(self, platform): m = Module() m.submodules += self.ila # Clock divider / counter. m.d.sync += self.counter.eq(self.counter + 1) # Set our ILA to trigger each time the counter is at a random value. # This shows off our example a bit better than counting at zero. m.d.comb += self.ila.trigger.eq(self.counter == 7) # Grab our I/O connectors. leds = [ platform.request_optional("led", i, default=NullPin(), dir="o") for i in range(0, 6) ] spi_bus = synchronize(m, platform.request('debug_spi')) # Attach the LEDs and User I/O to the MSBs of our counter. m.d.comb += Cat(leds).eq(self.counter[-7:-1]) # Connect our ILA up to our board's aux SPI. m.d.comb += self.ila.spi.connect(spi_bus) # Return our elaborated module. return m
def elaborate(self, platform): m = Module() board_spi = platform.request("debug_spi") # Create a set of registers, and expose them over SPI. spi_registers = SPIRegisterInterface( default_read_value=0x4C554E41) #default read = u'LUNA' m.submodules.spi_registers = spi_registers # Fill in some example registers. # (Register 0 is reserved for size autonegotiation). spi_registers.add_read_only_register(1, read=0xc001cafe) led_reg = spi_registers.add_register(2, size=6, name="leds") spi_registers.add_read_only_register(3, read=0xdeadbeef) # ... and tie our LED register to our LEDs. led_out = Cat([ platform.request_optional("led", i, default=NullPin()).o for i in range(0, 8) ]) m.d.comb += led_out.eq(led_reg) # Connect up our synchronized copies of the SPI registers. spi = synchronize(m, board_spi) m.d.comb += spi_registers.spi.connect(spi) 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(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
def elaborate(self, platform): m = Module() interface = self.interface setup = self.interface.setup # Grab a reference to the board's LEDs. leds = Cat(platform.request_optional("led", i, default=NullPin()).o for i in range(8)) # # Vendor request handlers. with m.If(setup.type == USBRequestType.VENDOR): with m.Switch(setup.request): # SET_LEDS request handler: handler that sets the board's LEDS # to a user provided value with m.Case(self.REQUEST_SET_LEDS): # If we have an active data byte, splat it onto the LEDs. # # For simplicity of this example, we'll accept any byte in # the packet; and not just the first one; each byte will # cause an update. This is fun; we can PWM the LEDs with # USB packets. :) with m.If(interface.rx.valid & interface.rx.next): m.d.usb += leds.eq(interface.rx.payload) # Once the receive is complete, respond with an ACK. with m.If(interface.rx_ready_for_response): m.d.comb += interface.handshakes_out.ack.eq(1) # If we reach the status stage, send a ZLP. with m.If(interface.status_requested): m.d.comb += self.send_zlp() with m.Case(): # # Stall unhandled requests. # with m.If(interface.status_requested | interface.data_requested): m.d.comb += interface.handshakes_out.stall.eq(1) return m
def elaborate(self, platform): m = Module() interface = self.interface setup = self.interface.setup # Grab a reference to the board's LEDs. leds = Cat( platform.request_optional("led", i, default=NullPin()).o for i in range(32)) # # Vendor request handlers. with m.If(setup.type == USBRequestType.VENDOR): with m.Switch(setup.request): # SET_LEDS request handler: handler that sets the board's LEDS # to a user provided value with m.Case(self.REQUEST_SET_LEDS): # If we have an active data byte, splat it onto the LEDs. # # For simplicity of this example, we'll accept any word in # the packet; and not just the first one; each word will # cause an update. This is fun; we can PWM the LEDs with # USB packets. :) for word in range(4): with m.If(interface.rx.valid[word]): led_byte = leds.word_select(word, 8) m.d.ss += led_byte.eq( interface.rx.payload.word_select(word, 8)) # Generate an ACK response once we receive the packet. # # Note that we generate an ACK no matter whether the packet was received correctly # or not. If it was received incorrectly, we'll set the ``retry`` bit. with m.If(interface.rx_complete | interface.rx_invalid): m.d.comb += [ interface.handshakes_out.retry_required.eq( interface.rx_invalid), interface.handshakes_out.next_sequence.eq(1), interface.handshakes_out.send_ack.eq(1) ] # Once the receive is complete, respond with an ACK. with m.If(interface.status_requested): m.d.comb += [ interface.handshakes_out.next_sequence.eq(1), interface.handshakes_out.send_ack.eq(1) ] with m.Default(): # # Stall unhandled requests. # have_opportunity_to_stall = (interface.rx_complete | interface.rx_invalid | interface.status_requested | interface.data_requested) with m.If(have_opportunity_to_stall): m.d.comb += interface.handshakes_out.send_stall.eq(1) return m