demux.comp
1 component demux """Select one of several output pins selected either by 2 an integer input or individual bits. Or even both"""; 3 4 description """This component creates a number of output bits defined 5 by the "personality" command-line parameter. One of these bits will be 6 set based on interpreting the bit-inputs as a binary number and then 7 adding on the integer input. Most uses will use only one 8 or the other, but it is possible to use the bits as a ""shift"" if 9 required. 10 An optional operating mode is enabled by setting the "bargraph" 11 parameter to true, in this case all bits up to the selected bit will be 12 set, as might be required for an LED bargraph display"""; 13 14 pin in bit sel-bit-## [5] "Binary-number bit selectors"; 15 pin in unsigned sel-u32 "Integer selection input"; 16 pin out bit out-## [32:personality] "The set of output bits"; 17 18 option default_personality 32; 19 param rw bit bargraph = 0; 20 21 license "GPL 2+"; 22 author "andypugh"; 23 24 function _; 25 26 ;; 27 28 FUNCTION(_){ 29 int i, bit; 30 31 bit = sel_u32 + sel_bit(0) + (sel_bit(1) << 1) + (sel_bit(2) << 2) 32 + (sel_bit(3) << 3) + (sel_bit(4) << 4); 33 if (bit >= personality) bit = personality - 1; 34 for (i = 0; i < personality ; i++) { 35 out(i) = (bargraph) ? (bit > i) : (bit == i); 36 } 37 }