/*
 * Exercise BB4b on Tiny Tapeout: a dual 4-channel multiplexer, with the DIP switches as
 * inputs and the 7-segment display of the demo board as lamps.
 *
 * Add mux_4_dual.sv to source_files in info.yaml next to project.v.
 * Rename the module to tt_um_<your GitHub name>_<project name> and use the
 * same name as top_module in info.yaml.
 */

`default_nettype none

module tt_um_example (
    input  wire [7:0] ui_in,    // DIP switches, INPUT Pmod, RP2350 GPIO17-24
    output wire [7:0] uo_out,   // 7-segment display, OUTPUT Pmod, RP2350 GPIO33-40
    input  wire [7:0] uio_in,   // BIDIR Pmod, RP2350 GPIO25-32
    output wire [7:0] uio_out,  //   (same pins)
    output wire [7:0] uio_oe,   //   1 = your design drives the pin
    input  wire       ena,      // set by the on-chip project mux, not a board pin
    input  wire       clk,      // RP2350 GPIO16
    input  wire       rst_n     // RP2350 GPIO14
);

    // Switches 1-0 are sel
    // The channels are fixed at X3-X0 = 1101 and Y3-Y0 = 0110, as the wires
    // on the breadboard. INH is held at 0: an FPGA has no high-impedance
    // wires inside.

    wire x_com;
    wire y_com;

    mux_4_dual i_mux_4_dual (
        .sel   ( ui_in [1:0] ),
        .x_ch  ( 4'b1101     ),
        .y_ch  ( 4'b0110     ),
        .inh   ( 1'b0        ),
        .x_com ( x_com       ),
        .y_com ( y_com       )
    );

    // 7-segment display: uo_out [0] is segment a, ..., uo_out [6] is g,
    // uo_out [7] is the dot.  Each output lights one segment:
    // a (top) x_com, b (top right) y_com.

    assign uo_out  = { 6'b0, y_com, x_com };

    assign uio_out = 8'b0;
    assign uio_oe  = 8'b0;

    // The circuit needs no clock or reset.
    // List all unused inputs to prevent warnings

    wire _unused = & { ena, clk, rst_n, ui_in [7:2], uio_in, 1'b0 };

endmodule
