libpruio  0.6.8
Fast and easy Digital/Analog Input/Output for Beaglebones
pruiotools.bas
Go to the documentation of this file.
1 
15 
16 
17 #DEFINE PMUX_NAME "pruio-"
18 TYPE AS UBYTE UInt8
19 ' Convenience declarations.
20 #INCLUDE ONCE "../pruio/pruio_pins.bi"
21 
22 
23 DIM SHARED AS STRING M(109)
24 
25 DIM SHARED AS STRING USER_ADD_ON
26 
27 DIM SHARED AS LONG MULTI_FLAG = 0
28 
29 
30 
31 #DEFINE ALL_START _
32  "// dts file auto generated by pruio_config (don't edit)" _
33  !"\n/dts-v1/;" _
34  !"\n/plugin/;" _
35  !"\n" _
36  !"\n/ {" _
37  !"\n compatible = " & COMPATIBL & """ti,beaglebone"";" _
38  !"\n" _
39  !"\n // identification" _
40  !"\n board-name = """ & FILE_NAME & """;" _
41  !"\n manufacturer = ""TJF"";" _
42  !"\n part-number = ""PruIoBBB"";" _
43  !"\n version = """ & VERS_NAME & """;" _
44  !"\n" _
45  !"\n // state the resources this cape uses" _
46  !"\n exclusive-use ="
47 
48 
49 #DEFINE ENTRY_EXCL(_T_) !"\n """ & _T_ & ""","
50 
51 
52 #DEFINE ALL_END _
53  !"\n fragment@2 {" _
54  !"\n target = <&pruss>;" _
55  !"\n __overlay__ {" _
56  !"\n status = ""okay"";"_
57  !"\n };" _
58  !"\n };" _
59  & USER_ADD_ON & _
60  !"\n };"
61 
62 
63 
64 #DEFINE FRAG0_START _
65  !"\n ""pruss"";" _
66  !"\n" _
67  !"\n fragment@0 {" _
68  !"\n target = <&am33xx_pinmux>;" _
69  !"\n __overlay__ {"
70 
71 
72 #DEFINE FRAG0_END _
73  !"\n };" _
74  !"\n };"
75 
76 
77 
78 #DEFINE FRAG1_START _
79  !"\n fragment@1 {" _
80  !"\n target = <&ocp>;" _
81  !"\n __overlay__ {"
82 
83 
84 #DEFINE FRAG1_END _
85  !"\n };" _
86  !"\n };"
87 
88 
89 #MACRO CREATE()
90  IF LEN(COMPATIBL) THEN COMPATIBL = """" & COMPATIBL & """, "
91  VAR fnam = FILE_NAME & "-" & VERS_NAME, _
92  fnr = FREEFILE
93  'IF OPEN CONS(FOR OUTPUT AS #fnr) THEN '' alternative for console output
94  '?"failed openig console"
95  IF OPEN(fnam & ".dts" FOR OUTPUT AS fnr) THEN
96  ?"failed writing file: " & fnam & ".dts"
97  ELSE
98  PRINT #fnr, ALL_START;
99  FOR i AS LONG = 0 TO UBOUND(M)
100  VAR x = IIF(LEN(M(i)), nameBall(i), 0)
101  IF x THEN PRINT #fnr, ENTRY_EXCL(*x); : IF LEN(M(i)) > 1 THEN MULTI_FLAG += 1
102  NEXT
103 
104  PRINT #fnr, FRAG0_START;
105  FOR i AS LONG = 0 TO UBOUND(M)
106  IF LEN(M(i)) THEN PRINT #fnr, f0entry(i);
107  NEXT
108  PRINT #fnr, FRAG0_END;
109 
110  PRINT #fnr, FRAG1_START;
111  FOR i AS LONG = 0 TO UBOUND(M)
112  IF LEN(M(i)) THEN PRINT #fnr, f1entry(i);
113  NEXT
114  PRINT #fnr, FRAG1_END;
115  PRINT #fnr, ALL_END;
116  CLOSE #fnr
117 
118  IF LEN(COMMAND(1)) THEN TARG_PATH = COMMAND(1)
119  IF RIGHT(TARG_PATH, 1) <> "/" THEN TARG_PATH &= "/"
120  IF SHELL("dtc -W no-unit_address_vs_reg -@ -I dts -O dtb -o " & TARG_PATH & fnam & ".dtbo " & fnam & ".dts") THEN
121  ?"=> File " & fnam & ".dts generated. Compile and install by executing"
122  ?" sudo dtc -@ -I dts -O dtb -o /lib/firmware/" & fnam & ".dtbo " & fnam & ".dts"
123  ELSE
124  ?"=> Blob /lib/firmware/" & fnam & ".dtbo installed"
125  END IF
126  IF MULTI_FLAG THEN
127  ?"Blob needs root privilegues (containing " & MULTI_FLAG & " multiple ball settings)"
128  ELSE
129  ?"Blob ready for user space (no multiple ball settings, no root privilegues necessary)"
130  END IF
131  END IF
132 #ENDMACRO
133 
134 
135 ENUM PinModes
136  NP = &b001000
137  PU = &b010000
138  PD = &b000000
139  RX = &b100000
140 
141  _O_ = NP
142  _I_ = RX + PD
143  I_O = RX + NP
144  IOD = RX + NP
145 
146  TMRi = _I_
147  TMRo = _O_
148  CAPi = _I_
149  CAPo = _O_
150  QEPi = IOD
151  QEPo = _O_
152  PWMi = _I_
153  PWMo = _O_
154 END ENUM
155 
156 
157 #DEFINE GPIO_DEF CHR( _
158  7 + RX + NP _ ' input, open (no resistor)
159  , 7 + RX + PU _ ' input, pullup resistor
160  , 7 + RX + PD _ ' input, pulldown resistor
161  , 7 + NP _ ' output (no resistor)
162  )
163 
164 
165 #DEFINE PIN_DEL(_A_) FOR i AS LONG = 0 TO UBOUND(_A_) : M(_A_(i)) = "" : NEXT
166 
167 
168 
181 FUNCTION f0entry(BYVAL I AS UBYTE) AS STRING
182  VAR r = "" _
183  , b0 = HEX(I, 2) _
184  , b4 = HEX(I * 4, 3)
185 
186  SELECT CASE AS CONST I
187  CASE 89 : b4 = "1A0 0x2F 0x" & b4
188  CASE 104 : b4 = "164 0x2F 0x" & b4
189  CASE 106 : b4 = "1B4 0x2F 0x" & b4
190  CASE 108 : b4 = "1A8 0x2F 0x" & b4
191  END SELECT
192 
193  FOR j AS LONG = 0 TO LEN(M(I)) - 1
194  VAR x = HEX(M(I)[j], 2) _
195  , n = b0 & "_" & x
196  r &= _
197  !"\n B" & n & ": " & n _
198  & " {pinctrl-single,pins = <0x" & b4 & " 0x" & x & ">;};"
199  NEXT : RETURN r
200 END FUNCTION
201 
202 
203 
215 FUNCTION f1entry(BYVAL I AS UBYTE) AS STRING
216  VAR _
217  j = 0 _
218  , tn = HEX(I, 2) _
219  , t0 = _
220  !"\n " & PMUX_NAME & tn & " {" _
221  !"\n compatible = ""bone-pinmux-helper"";" _
222  !"\n status = ""okay"";" _
223  !"\n pinctrl-names = " _
224  , t1 = _
225  !"\n };" _
226  , l = "" _
227  , n = ""
228 
229  IF MULTI_FLAG THEN
230  FOR j = 0 TO LEN(M(I)) - 1
231  VAR t = HEX(M(I)[j], 2)
232  n &= ", ""x" & t & """"
233  l &= !"\n pinctrl-" & j & " = <&B" & tn & "_" & t & ">;"
234  NEXT
235  ELSE
236  n &= ", ""default"""
237  l &= !"\n pinctrl-" & j & " = <&B" & tn & "_" & HEX(M(I)[j], 2) & ">;"
238  END IF : RETURN t0 & MID(n, 3) & ";" & l & t1
239 END FUNCTION
240 
241 
242 
255 FUNCTION nameBall CDECL(BYVAL Ball AS UBYTE) AS ZSTRING PTR
256  SELECT CASE AS CONST Ball ' find name
257  CASE P8_03 : RETURN @"P8.03"
258  CASE P8_04 : RETURN @"P8.04"
259  CASE P8_05 : RETURN @"P8.05"
260  CASE P8_06 : RETURN @"P8.06"
261  CASE P8_07 : RETURN @"P8.07"
262  CASE P8_08 : RETURN @"P8.08"
263  CASE P8_09 : RETURN @"P8.09"
264  CASE P8_10 : RETURN @"P8.10"
265  CASE P8_11 : RETURN @"P8.11"
266  CASE P8_12 : RETURN @"P8.12"
267  CASE P8_13 : RETURN @"P8.13"
268  CASE P8_14 : RETURN @"P8.14"
269  CASE P8_15 : RETURN @"P8.15"
270  CASE P8_16 : RETURN @"P8.16"
271  CASE P8_17 : RETURN @"P8.17"
272  CASE P8_18 : RETURN @"P8.18"
273  CASE P8_19 : RETURN @"P8.19"
274  CASE P8_20 : RETURN @"P8.20"
275  CASE P8_21 : RETURN @"P8.21"
276  CASE P8_22 : RETURN @"P8.22"
277  CASE P8_23 : RETURN @"P8.23"
278  CASE P8_24 : RETURN @"P8.24"
279  CASE P8_25 : RETURN @"P8.25"
280  CASE P8_26 : RETURN @"P8.26"
281  CASE P8_27 : RETURN @"P8.27"
282  CASE P8_28 : RETURN @"P8.28"
283  CASE P8_29 : RETURN @"P8.29"
284  CASE P8_30 : RETURN @"P8.30"
285  CASE P8_31 : RETURN @"P8.31"
286  CASE P8_32 : RETURN @"P8.32"
287  CASE P8_33 : RETURN @"P8.33"
288  CASE P8_34 : RETURN @"P8.34"
289  CASE P8_35 : RETURN @"P8.35"
290  CASE P8_36 : RETURN @"P8.36"
291  CASE P8_37 : RETURN @"P8.37"
292  CASE P8_38 : RETURN @"P8.38"
293  CASE P8_39 : RETURN @"P8.39"
294  CASE P8_40 : RETURN @"P8.40"
295  CASE P8_41 : RETURN @"P8.41"
296  CASE P8_42 : RETURN @"P8.42"
297  CASE P8_43 : RETURN @"P8.43"
298  CASE P8_44 : RETURN @"P8.44"
299  CASE P8_45 : RETURN @"P8.45"
300  CASE P8_46 : RETURN @"P8.46"
301  CASE P9_11 : RETURN @"P9.11"
302  CASE P9_12 : RETURN @"P9.12"
303  CASE P9_13 : RETURN @"P9.13"
304  CASE P9_14 : RETURN @"P9.14"
305  CASE P9_15 : RETURN @"P9.15"
306  CASE P9_16 : RETURN @"P9.16"
307  CASE P9_17 : RETURN @"P9.17"
308  CASE P9_18 : RETURN @"P9.18"
309  CASE P9_19 : RETURN @"P9.19"
310  CASE P9_20 : RETURN @"P9.20"
311  CASE P9_21 : RETURN @"P9.21"
312  CASE P9_22 : RETURN @"P9.22"
313  CASE P9_23 : RETURN @"P9.23"
314  CASE P9_24 : RETURN @"P9.24"
315  CASE P9_25 : RETURN @"P9.25"
316  CASE P9_26 : RETURN @"P9.26"
317  CASE P9_27 : RETURN @"P9.27"
318  CASE P9_28 : RETURN @"P9.28"
319  CASE P9_29 : RETURN @"P9.29"
320  CASE P9_30 : RETURN @"P9.30"
321  CASE P9_31 : RETURN @"P9.31"
322  CASE P9_41 : RETURN @"P9.41"
323  CASE P9_42 : RETURN @"P9.42"
324  CASE JT_04 : RETURN @"JT_04"
325  CASE JT_05 : RETURN @"JT_05"
326  CASE SD_01 : RETURN @"SD_01"
327  CASE SD_02 : RETURN @"SD_02"
328  CASE SD_03 : RETURN @"SD_03"
329  CASE SD_05 : RETURN @"SD_05"
330  CASE SD_07 : RETURN @"SD_07"
331  CASE SD_08 : RETURN @"SD_08"
332  CASE SD_10 : RETURN @"SD_10"
333  END SELECT : RETURN 0
334 END FUNCTION
335