/*
 * Exercise B9 on Tiny Tapeout: the adder.  DIP switches 3-0 are A,
 * switches 7-4 are B; the 7-segment display of the demo board shows the
 * sum the way the 4511 does, and the dot shows the carry.
 *
 * Add adder_display.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
);

    wire [3:0] sum;
    wire       carry;
    wire [6:0] abcdefg_a, abcdefg_b, abcdefg_sum;

    adder_display i_adder_display (
        .a           ( ui_in [3:0] ),
        .b           ( ui_in [7:4] ),
        .sum         ( sum         ),
        .carry       ( carry       ),
        .abcdefg_a   ( abcdefg_a   ),
        .abcdefg_b   ( abcdefg_b   ),
        .abcdefg_sum ( abcdefg_sum )
    );

    // 7-segment display: uo_out [0] is segment a, ..., uo_out [6] is g,
    // uo_out [7] is the dot.  abcdefg has a at the top, so the bits go in
    // reverse order.  The board has one digit, so A and B are not shown:
    // read them from the switches.  The bidirectional pins show the sum in
    // binary, for a logic analyzer or LEDs on the BIDIR Pmod.

    assign uo_out  = { carry, abcdefg_sum [0], abcdefg_sum [1], abcdefg_sum [2], abcdefg_sum [3],
                       abcdefg_sum [4], abcdefg_sum [5], abcdefg_sum [6] };

    assign uio_out = { 3'b0, carry, sum };
    assign uio_oe  = 8'b0001_1111;

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

    wire _unused = & { ena, clk, rst_n, uio_in, abcdefg_a, abcdefg_b, 1'b0 };

endmodule
