// CD4052B: dual 4-channel analog multiplexer/demultiplexer.
//
// Ports in pin order, named as in the datasheet.  The power pins, VEE (7),
// VSS (8) and VDD (16), are left out.
//
// Digital model of two analog switches with a common select B A: it passes
// the selected X and Y channels to X COM and Y COM.  INH = 1 opens all
// switches and both commons float.  Synthesizable while INH is 0.

module cd4052
(
    input  logic y0,     // Pin 1
    input  logic y2,     // Pin 2
    output logic y_com,  // Pin 3:  Y common in/out
    input  logic y3,     // Pin 4
    input  logic y1,     // Pin 5
    input  logic inh,    // Pin 6:  1 = all switches open
                         // Pin 7:  VEE
                         // Pin 8:  VSS
    input  logic b,      // Pin 9:  select, weight 2
    input  logic a,      // Pin 10: select, weight 1
    input  logic x3,     // Pin 11
    input  logic x0,     // Pin 12
    output logic x_com,  // Pin 13: X common in/out
    input  logic x1,     // Pin 14
    input  logic x2      // Pin 15
                         // Pin 16: VDD
);

    wire [1:0] sel = { b, a };
    wire [3:0] x   = { x3, x2, x1, x0 };
    wire [3:0] y   = { y3, y2, y1, y0 };

    assign x_com = inh ? 1'bz : x [sel];
    assign y_com = inh ? 1'bz : y [sel];

endmodule
