1 /*
2  * Copyright 2019 Martin Åberg
3  *
4  * This file is part of Footag.
5  *
6  * Footag is free software: you can redistribute it and/or modify it under the
7  * terms of the GNU General Public License as published by the Free Software
8  * Foundation, either version 3 of the License, or (at your option) any later
9  * version.
10  *
11  * Footag is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU General Public License along with
17  * this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "priv.h"
21 #include <footag/ipc7351b.h>
22 
23 static const struct footag_typeinfo info = {
24         .type   = FOOTAG_TYPE_CHIPARRAY,
25         .name   = "CHIPARRAY",
26         .brief  = "Chip array components",
27         .desc   = "Resistor, capacitor and inductor arrays etc., Side concave oscillator",
28 };
29 
30 /* BOURNS CAT16-J4 chip resistor array with concave terminations */
31 static const struct footag_param temp[] = {
32         PARAM_TOPIC("Body"),
33         PARAM_L(BODY_L,  "Length",    "D",  3.20),
34         PARAM_T(BODY_W,  "Width",     "E",  1.55, 0.25),
35         PARAM_I(BODY_N,  "Pins",      "N",  8, 2, 2, 512),
36         PARAM_E(BODY_Nx, "Terminals", "-",  0, 3, "Concave", "Convex", "Flat"),
37 
38         PARAM_TOPIC("Lead"),
39         PARAM_L(LEAD_P,  "Pitch",     "e",  0.80),
40         PARAM_T(LEAD_L,  "Length",    "L",  0.30, 0.20),
41         PARAM_T(LEAD_W,  "Width",     "b",  0.40, 0.15),
42         PARAM_CALC_IPC7351B,
43         PARAM_PADSTACK_SMD_RECTS,
44         PARAM_TERM,
45 };
46 
calc(struct footag_ctx * ctx)47 static int calc(struct footag_ctx *ctx)
48 {
49         struct footag_spec *const s = &ctx->spec;
50         struct ipcb_twospec spec;
51         const struct ipcb_comp comp = {
52                 .l = GETID(ctx, BODY_W)->t,
53                 .t = GETID(ctx, LEAD_L)->t,
54                 .w = GETID(ctx, LEAD_W)->t,
55         };
56         const struct ipcb_attr attr = {
57                 .density = footag_get_density(&GETID(ctx, CALC_D)->e),
58                 .f = GETID(ctx, CALC_F)->l,
59                 .p = GETID(ctx, CALC_P)->l,
60         };
61         const int npads = intmax(2, GETID(ctx, BODY_N)->i.val);
62         int ret;
63 
64         ret = footag_realloc_pads(ctx, npads);
65         if (ret) { return ret; }
66 
67         {
68                 const int style = GETID(ctx, BODY_Nx)->e.val;
69                 if (style == 0) {
70                         ret = ipcb_get_concavearray(&spec, &comp, &attr);
71                 } else if (style == 1) {
72                         ret = ipcb_get_convexarray(&spec, &comp, &attr);
73                 } else {
74                         ret = ipcb_get_flatarray(&spec, &comp, &attr);
75                 }
76         }
77         if (ret) { return ret; }
78 
79         footag_gentworow(
80                 s->pads,
81                 spec.land.dist,
82                 spec.land.w, spec.land.h,
83                 GETID(ctx, LEAD_P)->l,
84                 npads,
85                 GETID(ctx, CALC_STACK)->e.val
86         );
87         s->body = footag_crlimit(
88                 GETID(ctx, BODY_W)->t.nom,
89                 GETID(ctx, BODY_L)->l
90         );
91         footag_ipc7351b_setrrectpads(&ctx->spec);
92         footag_snap(s, ROUNDOFF_TO_GRID[GETID(ctx, CALC_ROUND)->e.val]);
93         footag_setcourtyard(s, spec.cyexc);
94         footag_setref_ipc7351b(s, &spec.ref);
95 
96         return 0;
97 }
98 
99 const struct footag_op footag_op_chiparray = {
100         .size   = sizeof (struct footag_ctx),
101         .init   = footag_init_default,
102         .fini   = footag_fini_default,
103         .calc   = calc,
104         .info   = &info,
105         .temp   = &temp[0],
106 };
107 
108