32 #INCLUDE ONCE "BBB/pruio.bi"
34 #INCLUDE ONCE "BBB/pruio_pins.bi"
45 IF .Cap->Value(C_IN, @
f0, NULL)
THEN _
46 ?"Cap->Value failed (" & *.Errr &
")" :
EXIT DO
69 .DRam[1] = PRUIO_COM_GPIO_CONF
SHL 24
73 #DEFINE FUNC(_O_)
IF .Gpio->setValue(
GOUT, _O_)
THEN _
74 ?"GPIO setValue failed (" & *.Errr &
")" :
EXIT DO
83 IF .Errr
THEN ?"initialisation failed (" & *.Errr &
")" :
EXIT DO
85 IF .Gpio->setValue(
GOUT, 0)
THEN _
86 ?"GOUT configuration failed (" & *.Errr &
")" :
EXIT DO
88 IF .Gpio->config(
G_IN, PRUIO_GPIO_IN)
THEN _
89 ?"G_IN configuration failed (" & *.Errr &
")" :
EXIT DO
91 IF .Cap->config(C_IN, 1000)
THEN _
92 ?"C_IN configuration failed (" & *.Errr &
")" :
EXIT DO
94 IF .Adc->setStep(1, 0, 0, 0, 0)
THEN _
95 ?"ADC setStep failed (" & *.Errr &
")" :
EXIT DO
97 IF .config(1, 1
SHL 1)
THEN _
98 ?"config failed (" & *.Errr &
")" :
EXIT DO
100 DIM AS CONST ZSTRING PTR desc(...) = _
101 { @
"Open loop, direct GPIO" _
102 , @
"Open loop, function Gpio->Value" _
103 , @
"Closed loop, direct GPIO to direct GPIO" _
104 , @
"Closed loop, function Gpio->Value to direct GPIO" _
105 , @
"Closed loop, function Gpio->Value to function Gpio->setValue" _
106 , @
"Closed loop, Adc->Value to direct GPIO" _
107 , @
"Closed loop, Adc->Value to function Gpio->Value"}
118 ,
m1 = 1
SHL (
r1 AND 31) _
121 ,
m0 = 1
SHL (
r0 AND 31) _
124 ,
ad = .Gpio->Conf(
g0)->DeAd + &h100 _
125 ,
oe = .Gpio->Conf(
g0)->OE
127 FOR i
AS INTEGER = 0
TO UBOUND(
desc)
133 FOR i
AS INTEGER = 0
TO c
139 FOR i
AS INTEGER = 0
TO c
146 FOR i
AS INTEGER = 0
TO c
148 WHILE 0 = (.Gpio->Raw(
g1)->Mix
AND m1) :
WEND
151 WHILE m1 = (.Gpio->Raw(
g1)->Mix
AND m1) :
WEND
155 FOR i
AS INTEGER = 0
TO c
157 WHILE .Gpio->Value(
G_IN) < 1 :
WEND
160 WHILE .Gpio->Value(
G_IN) > 0 :
WEND
164 FOR i
AS INTEGER = 0
TO c
166 WHILE .Gpio->Value(
G_IN) < 1 :
WEND
169 WHILE .Gpio->Value(
G_IN) > 0 :
WEND
173 FOR i
AS INTEGER = 0
TO c
175 WHILE .Adc->Value[1] <= &h7FFF :
WEND
178 WHILE .Adc->Value[1] > &h7FFF :
WEND
182 FOR i
AS INTEGER = 0
TO c
184 WHILE .Adc->Value[1] <= &h7FFF :
WEND
187 WHILE .Adc->Value[1] > &h7FFF :
WEND
193 FOR i
AS INTEGER = 0
TO UBOUND(
desc)
196 ?" Avarage: ";
sf(i) /
n
200 IF .Errr
THEN ?"press any key to quit" :
SLEEP