// Exercise BB6, chip-level version: the chips and wires of schematic 2 and
// of the breadboard.  Same ports as priority_encoder.sv.  The display and
// its resistors are not in the design: its outputs are the outputs of the
// 4532 and of the 4511.
//
// Generated by tools/bb_lib.py from the checked breadboard wire list;
// change the layout in tools/bb_bb6.py, not this file.  Synthesizable.

module priority_encoder_chips
(
    input  logic [7:0] d,
    output logic [2:0] q,
    output logic       gs,
    output logic       eo,
    output logic [6:0] abcdefg
);

    // The power rails of the breadboard, for tied-off inputs

    wire gnd = 1'b0;
    wire vdd = 1'b1;

    //------------------------------------------------------------------------

    // U1: CD4532 8-bit priority encoder, pin 1 in column 8

    cd4532 i_u1
    (
        .d4 ( d [4] ),  // Pin 1 <- button D4
        .d5 ( d [5] ),  // Pin 2 <- button D5
        .d6 ( d [6] ),  // Pin 3 <- button D6
        .d7 ( d [7] ),  // Pin 4 <- button D7
        .ei ( vdd   ),  // Pin 5 <- +5V
        .q2 ( q [2] ),  // Pin 6 -> Q2
        .q1 ( q [1] ),  // Pin 7 -> Q1
        .q0 ( q [0] ),  // Pin 9 -> Q0
        .d0 ( d [0] ),  // Pin 10 <- button D0
        .d1 ( d [1] ),  // Pin 11 <- button D1
        .d2 ( d [2] ),  // Pin 12 <- button D2
        .d3 ( d [3] ),  // Pin 13 <- button D3
        .gs ( gs    ),  // Pin 14 -> GS
        .eo ( eo    )   // Pin 15 -> EO
    );

    //------------------------------------------------------------------------

    // U2: CD4511 BCD-to-7-segment latch, decoder and driver, pin 1 in column 20

    cd4511 i_u2
    (
        .bcd_b        ( q [1]       ),  // Pin 1 <- U1 pin 7 (Q1)
        .bcd_c        ( q [2]       ),  // Pin 2 <- U1 pin 6 (Q2)
        .lamp_test_n  ( vdd         ),  // Pin 3 <- +5V
        .blank_n      ( vdd         ),  // Pin 4 <- +5V
        .latch_enable ( gnd         ),  // Pin 5 <- GND
        .bcd_d        ( gnd         ),  // Pin 6 <- GND
        .bcd_a        ( q [0]       ),  // Pin 7 <- U1 pin 9 (Q0)
        .seg_e        ( abcdefg [2] ),  // Pin 9 -> e
        .seg_d        ( abcdefg [3] ),  // Pin 10 -> d
        .seg_c        ( abcdefg [4] ),  // Pin 11 -> c
        .seg_b        ( abcdefg [5] ),  // Pin 12 -> b
        .seg_a        ( abcdefg [6] ),  // Pin 13 -> a
        .seg_g        ( abcdefg [0] ),  // Pin 14 -> g
        .seg_f        ( abcdefg [1] )   // Pin 15 -> f
    );

endmodule
