Skip to content

Commit b872760

Browse files
committed
IOIO: added latency arg to waitForConnect
1 parent a7b6de0 commit b872760

20 files changed

+297
-145
lines changed

ioio/README.md

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ see: https://github.com/ytai/ioio/wiki
44

55
## IOIO
66

7+
This interface provides control over all the IOIO board functions.
8+
79
| Name | Description |
810
|---------|---------------|
9-
| void ioio.beginBatch()|Start a batch of operations. This is strictly an optimization and will not change functionality|
10-
| void ioio.disconnect()|Closes the connection to the board, or aborts a connection process started with waitForConnect()|
11-
| void ioio.endBatch()|End a batch of operations.|
12-
| void ioio.hardReset()|Equivalent to disconnecting and reconnecting the board power supply.|
13-
| void ioio.softReset()|Resets the entire state (returning to initial state), without dropping the connection.|
14-
| void ioio.sync()|Sends a message to the IOIO and waits for an echo.|
15-
| void ioio.waitForConnect()|Establishes connection with the IOIO board.|
16-
| void ioio.waitForDisconnect()|Blocks until IOIO has been disconnected and all connection-related resources have been freed so that a new connection can be attempted.|
11+
|void beginBatch(void)|Start a batch of operations. This is strictly an optimization and will not change functionality.|
12+
|void disconnect(void)|Closes the connection to the board, or aborts a connection process started with waitForConnect().|
13+
|void endBatch(void)|End a batch of operations.|
14+
|void hardReset(void)|Equivalent to disconnecting and reconnecting the board power supply.|
15+
|void softReset(void)|Resets the entire state (returning to initial state), without dropping the connection.|
16+
|void sync(void)|Sends a message to the IOIO and waits for an echo.|
17+
|void waitForConnect(int)|Establishes connection with the IOIO board.|
18+
|void waitForDisconnect(void)|Blocks until IOIO has been disconnected and all connection-related resources have been freed, so that a new connection can be attempted.|
1719

1820
## AnalogInput
1921

@@ -96,3 +98,12 @@ A pin used for PWM (Pulse-Width Modulation) output. A PWM pin produces a logic-l
9698
|void setDutyCycle(float)|Sets the duty cycle of the PWM output. The duty cycle is defined to be the pulse width divided by the total cycle period. For absolute control of the pulse with, consider using setPulseWidth.|
9799
|void setPulseWidth(float)|Sets the pulse width of the PWM output. The pulse width is duration of the high-time within a single period of the signal. For relative control of the pulse with, consider using setDutyCycle.|
98100

101+
## TwiMaster
102+
103+
An interface for controlling a TWI module, in TWI bus-master mode, enabling communication with multiple TWI-enabled slave modules.
104+
105+
`io = ioio.openTwiMaster(pin)`
106+
107+
| Name | Description |
108+
|---------|---------------|
109+

ioio/api.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,51 @@
11
[
2+
{
3+
"name": "IOIO":
4+
"comment": "This interface provides control over all the IOIO board functions.",
5+
"methods": [
6+
{
7+
"name": "beginBatch"
8+
"rtn": "void",
9+
"arg": "void",
10+
"comment" : "Start a batch of operations. This is strictly an optimization and will not change functionality."
11+
},{
12+
"name": "disconnect"
13+
"rtn": "void",
14+
"arg": "void",
15+
"comment" : "Closes the connection to the board, or aborts a connection process started with waitForConnect()."
16+
},{
17+
"name": "endBatch"
18+
"rtn": "void",
19+
"arg": "void",
20+
"comment" : "End a batch of operations."
21+
},{
22+
"name": "hardReset"
23+
"rtn": "void",
24+
"arg": "void",
25+
"comment" : "Equivalent to disconnecting and reconnecting the board power supply."
26+
},{
27+
"name": "softReset"
28+
"rtn": "void",
29+
"arg": "void",
30+
"comment" : "Resets the entire state (returning to initial state), without dropping the connection."
31+
},{
32+
"name": "sync"
33+
"rtn": "void",
34+
"arg": "void",
35+
"comment" : "Sends a message to the IOIO and waits for an echo."
36+
},{
37+
"name": "waitForConnect"
38+
"rtn": "void",
39+
"arg": "int",
40+
"comment": "Establishes connection with the IOIO board."
41+
},{
42+
"name": "waitForDisconnect"
43+
"rtn": "void",
44+
"arg": "void",
45+
"comment" : "Blocks until IOIO has been disconnected and all connection-related resources have been freed, so that a new connection can be attempted."
46+
}
47+
]
48+
},
249
{
350
"name": "AnalogInput",
451
"comment": "This interface represents AnalogInput functionality, providing methods to obtain analog input readings and buffered samples.",
@@ -196,5 +243,10 @@
196243
"comment": "Sets the pulse width of the PWM output. The pulse width is duration of the high-time within a single period of the signal. For relative control of the pulse with, consider using setDutyCycle."
197244
}
198245
]
246+
},
247+
{
248+
"name": "TwiMaster":
249+
"comment": "An interface for controlling a TWI module, in TWI bus-master mode, enabling communication with multiple TWI-enabled slave modules.",
250+
"methods": []
199251
}
200252
]

ioio/main.cpp

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ int nextId = 1;
2929
#define CLASS_PULSEINPUT "net/sourceforge/smallbasic/ioio/PulseInputImpl"
3030
#define CLASS_PWMOUTPUT "net/sourceforge/smallbasic/ioio/PwmOutputImpl"
3131
#define CLASS_CAPSENSE "net/sourceforge/smallbasic/ioio/CapsenseImpl"
32+
#define CLASS_TWIMASTER "net/sourceforge/smallbasic/ioio/TwiMasterImpl"
3233
#define CLASS_IOIO "net/sourceforge/smallbasic/ioio/IOIOImpl"
3334
#define CLASS_IOTASK_ID 1
3435

@@ -216,6 +217,21 @@ static int get_io_class_id(var_s *map, var_s *retval) {
216217
return result;
217218
}
218219

220+
static int cmd_twimaster_writeread(var_s *self, int argc, slib_par_t *arg, var_s *retval) {
221+
int result = 0;
222+
if (argc != 0) {
223+
error(retval, "writeRead", 0);
224+
} else {
225+
// TODO
226+
//result = ioioTask->invokeVoidVoid("waitForDisconnect", retval);
227+
}
228+
return result;
229+
}
230+
231+
static void create_twimaster(var_t *map) {
232+
v_create_callback(map, "writeRead", cmd_twimaster_writeread);
233+
}
234+
219235
#include "api.h"
220236

221237
FUNC_SIG lib_func[] = {
@@ -225,17 +241,18 @@ FUNC_SIG lib_func[] = {
225241
{1, 2, "OPENDIGITALOUTPUT", cmd_opendigitaloutput},
226242
{1, 2, "OPENPULSEINPUT", cmd_openpulseinput},
227243
{1, 2, "OPENPWMOUTPUT", cmd_openpwmoutput},
244+
{1, 2, "OPENTWIMASTER", cmd_opentwimaster},
228245
};
229246

230247
FUNC_SIG lib_proc[] = {
231-
{0, 0, "BEGINBATCH", cmd_beginbatch},
232-
{0, 0, "DISCONNECT", cmd_disconnect},
233-
{0, 0, "ENDBATCH", cmd_endbatch},
234-
{0, 0, "HARDRESET", cmd_hardreset},
235-
{0, 0, "SOFTRESET", cmd_softreset},
236-
{0, 0, "SYNC", cmd_sync},
237-
{0, 0, "WAITFORCONNECT", cmd_waitforconnect},
238-
{0, 0, "WAITFORDISCONNECT", cmd_waitfordisconnect},
248+
{0, 0, "BEGINBATCH", cmd_ioio_beginbatch},
249+
{0, 0, "DISCONNECT", cmd_ioio_disconnect},
250+
{0, 0, "ENDBATCH", cmd_ioio_endbatch},
251+
{0, 0, "HARDRESET", cmd_ioio_hardreset},
252+
{0, 0, "SOFTRESET", cmd_ioio_softreset},
253+
{0, 0, "SYNC", cmd_ioio_sync},
254+
{0, 0, "WAITFORCONNECT", cmd_ioio_waitforconnect},
255+
{0, 0, "WAITFORDISCONNECT", cmd_ioio_waitfordisconnect},
239256
};
240257

241258
SBLIB_API int sblib_proc_count() {

ioio/mkapi.bas

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ rem
55
tload "api.json", s, 1
66
api = array(s)
77

8-
ioioApi = ["beginBatch", "disconnect", "endBatch", "hardReset", "softReset", "sync", "waitForConnect", "waitForDisconnect"]
9-
108
func get_method_name(method)
119
local result
1210

@@ -22,7 +20,7 @@ func get_method_name(method)
2220

2321
if (method.arg == "void") then
2422
result += "Void"
25-
else if (method.arg == method.arg == "int") then
23+
else if (method.arg == "int") then
2624
result += "Int"
2725
else if (method.arg == "boolean") then
2826
result += "Bool"
@@ -47,44 +45,46 @@ sub generate_command(objName, method)
4745
err_name = method.name
4846
endif
4947

50-
print "static int cmd_" + cmd_name + "(var_s *self, int argc, slib_par_t *arg, var_s *retval) {"
48+
if (objName == "IOIO") then
49+
print "static int cmd_" + cmd_name + "(int argc, slib_par_t *arg, var_s *retval) {"
50+
else
51+
print "static int cmd_" + cmd_name + "(var_s *self, int argc, slib_par_t *arg, var_s *retval) {"
52+
endif
5153
print " int result = 0;"
5254
print " if (argc != " + param_count + ") {"
5355
print " error(retval, \"" + err_name + "\", " + param_count + ");"
5456
print " } else {"
55-
print " int id = get_io_class_id(self, retval);"
56-
print " if (id != -1) {"
57+
58+
local getter, indent
59+
if (objName == "IOIO") then
60+
getter = "ioioTask->"
61+
indent = " "
62+
else
63+
getter = "_ioTaskMap.at(id)."
64+
indent = " "
65+
print " int id = get_io_class_id(self, retval);"
66+
print " if (id != -1) {"
67+
endif
5768

5869
local argument = ""
5970
if (method.arg == "boolean" || method.arg == "int") then
60-
print " auto value = get_param_int(argc, arg, 0, 0);"
71+
print indent + "auto value = get_param_int(argc, arg, 0, 0);"
6172
argument = ", value"
6273
else if (method.arg == "float") then
63-
print " auto value = get_param_num(argc, arg, 0, 0);"
74+
print indent + "auto value = get_param_num(argc, arg, 0, 0);"
6475
argument = ", value"
6576
endif
6677

6778
if (method.rtn == "void") then
68-
print " result = _ioTaskMap.at(id)." + invoke + "(\"" + method.name + "\"" + argument + ", retval);"
79+
print indent + "result = " + getter + invoke + "(\"" + method.name + "\"" + argument + ", retval);"
6980
else if (method.rtn == "boolean" || method.rtn == "int") then
70-
print " result = _ioTaskMap.at(id)." + invoke + "(\"" + method.name + "\"" + argument + ", retval);"
81+
print indent + "result = " + getter + invoke + "(\"" + method.name + "\"" + argument + ", retval);"
7182
else if (method.rtn == "float") then
72-
print " result = _ioTaskMap.at(id)." + invoke + "(\"" + method.name + "\"" + argument + ", retval);"
83+
print indent + "result = " + getter + invoke + "(\"" + method.name + "\"" + argument + ", retval);"
84+
endif
85+
if (objName != "IOIO") then
86+
print " }"
7387
endif
74-
print " }"
75-
print " }"
76-
print " return result;"
77-
print "}"
78-
print
79-
end
80-
81-
sub generate_ioio_command(name)
82-
print "static int cmd_" + lower(name) + "(int argc, slib_par_t *arg, var_s *retval) {"
83-
print " int result = 0;"
84-
print " if (argc != 0) {"
85-
print " error(retval, \"" + name + "\", 0);"
86-
print " } else {"
87-
print " result = ioioTask->invokeVoidVoid(\"" + name + "\", retval);"
8888
print " }"
8989
print " return result;"
9090
print "}"
@@ -128,15 +128,15 @@ for obj in api
128128
next
129129
next
130130

131-
for s in ioioApi
132-
generate_ioio_command(s)
133-
next
134-
135131
for obj in api
136-
generate_constructor(obj)
132+
if (len(obj.methods) > 0 && obj.name != "IOIO") then
133+
generate_constructor(obj)
134+
endif
137135
next
138136

139137
for obj in api
140-
generate_open_function(obj)
138+
if (obj.name != "IOIO") then
139+
generate_open_function(obj)
140+
endif
141141
next
142142

ioio/mkdoc.bas

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,6 @@ rem
44

55
tload "api.json", s, 1
66
api = array(s)
7-
ioioApi = [{
8-
"name": "beginBatch"
9-
"comment": "Start a batch of operations. This is strictly an optimization and will not change functionality"
10-
},{
11-
"name": "disconnect",
12-
"comment": "Closes the connection to the board, or aborts a connection process started with waitForConnect()"
13-
},{
14-
"name": "endBatch",
15-
"comment": "End a batch of operations."
16-
},{
17-
"name": "hardReset",
18-
"comment": "Equivalent to disconnecting and reconnecting the board power supply."
19-
},{
20-
"name": "softReset",
21-
"comment": "Resets the entire state (returning to initial state), without dropping the connection."
22-
},{
23-
"name": "sync",
24-
"comment": "Sends a message to the IOIO and waits for an echo."
25-
},{
26-
"name": "waitForConnect",
27-
"comment": "Establishes connection with the IOIO board."
28-
},{
29-
"name": "waitForDisconnect",
30-
"comment": "Blocks until IOIO has been disconnected and all connection-related resources have been freed so that a new connection can be attempted."
31-
}]
327

338
func get_signature(method)
349
local result
@@ -61,21 +36,14 @@ print
6136
print "see: https://github.com/ytai/ioio/wiki"
6237
print
6338

64-
print "## IOIO"
65-
print
66-
print "| Name | Description |"
67-
print "|---------|---------------|"
68-
for obj in ioioApi
69-
print "| void ioio." + obj.name + "()|" + obj.comment + "|"
70-
next s
71-
print
72-
7339
for obj in api
7440
print "## " + obj.name
7541
print
7642
print obj.comment
77-
print
78-
print "`io = ioio.open" + obj.name + "(pin)`"
43+
if (obj.name != "IOIO") then
44+
print
45+
print "`io = ioio.open" + obj.name + "(pin)`"
46+
endif
7947
print ""
8048
print "| Name | Description |"
8149
print "|---------|---------------|"

ioio/samples/duino-1088AS.bas

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
rem
2+
rem Hardware Setup:
3+
rem Power Supply: Connect VCC of the 1088AS to a suitable power supply voltage (usually 5V).
4+
rem Ground Connection: Connect GND of the 1088AS to the ground (GND) of the IOIO-OTG board.
5+
rem Data Connections:
6+
rem Connect the DIN pin of the 1088AS to a digital output pin on the IOIO-OTG board.
7+
rem Connect the CS pin of the 1088AS to another digital output pin on the IOIO-OTG board.
8+
rem Connect the CLK pin of the 1088AS to yet another digital output pin on the IOIO-OTG board.
9+
rem
10+
rem In the context of an LED matrix display like the 8x8 Duinotech 1088AS,
11+
rem writing to the DIN (Data Input) pin is not directly addressing a
12+
rem particular LED. Instead, it's part of a process to send data to the
13+
rem display to control which LEDs are lit up.
14+
rem
15+
rem Here's a simplified overview of how it works:
16+
rem
17+
rem Data Shifted In: You send a stream of data serially to the
18+
rem display. Each bit of data represents whether a corresponding LED
19+
rem should be on or off.
20+
rem
21+
rem Data Shifted Out to LEDs: As the data is shifted into the display
22+
rem through the DIN pin, it is internally stored in shift registers. When
23+
rem enough data is received (for example, 8 bits for an 8x8 LED matrix),
24+
rem the display will update the LEDs accordingly.
25+
rem
26+
rem Control Signals: Alongside the data, you typically send control
27+
rem signals like clock pulses (CLK) to synchronize the shifting of data
28+
rem and chip select (CS) to indicate when the data is valid.
29+
rem
30+
rem Matrix Multiplexing: The LED matrix is typically arranged in rows and
31+
rem columns. By controlling the state of each row and column (using
32+
rem additional control pins or internally within the display), you can
33+
rem select individual LEDs or groups of LEDs to turn on or off.
34+
rem
35+
rem Updating Display: After sending the necessary data and control
36+
rem signals, the display refreshes itself to reflect the new state of the
37+
rem LEDs based on the received data.
38+
rem
39+
rem So, when you write to the DIN pin, you're not directly addressing a
40+
rem particular LED. Instead, you're sending data to the display to update
41+
rem the entire matrix, and by controlling the row and column pins, you
42+
rem indirectly address specific LEDs or groups of LEDs within the matrix.
43+
rem
44+
45+
import ioio
46+
47+
const dinPin = 2
48+
const csPin = 3
49+
const clkPin = 4
50+
51+
ioio.waitForConnect(10)
52+
53+
din = ioio.openDigitalOutput(dinPin)
54+
cs = ioio.openDigitalOutput(csPin)
55+
clk = ioio.openDigitalOutput(clkPin)
56+
57+
while 1
58+
shiftOut(0x55)
59+
wend
60+
61+
sub shiftOut(_data)
62+
cs.write(false); ' Enable the chip
63+
for i = 7 to 0
64+
clk.write(false) ' Start clock pulse
65+
din.write((_data band (1 lshift i)) != 0) ' Send bit
66+
clk.write(true) ' End clock pulse
67+
next
68+
cs.write(true) ' Disable the chip
69+
end

0 commit comments

Comments
 (0)