Skip to content

Commit 2c8dfe9

Browse files
committed
IOIO: updated spiMaster handling.
1 parent 22e136e commit 2c8dfe9

File tree

5 files changed

+28
-64
lines changed

5 files changed

+28
-64
lines changed

ioio/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ void sblib_close(void) {
367367
fprintf(stderr, "IOTask leak detected\n");
368368
_ioTaskMap.clear();
369369
}
370-
jvm->DetachCurrentThread();
370+
if (jvm) {
371+
jvm->DetachCurrentThread();
372+
}
371373
// calling this hangs
372374
//jvm->DestroyJavaVM();
373375
env = nullptr;

ioio/samples/duino-1088AS.bas

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,27 @@
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-
451
import ioio
462

47-
const dinPin = 2
3+
const mosiPin = 2
4+
const misoPin = 6
485
const csPin = 3
496
const clkPin = 4
507

51-
din = ioio.openDigitalOutput(dinPin)
8+
spi = ioio.openSpiMaster(misoPin, mosiPin, sckPin, csPin)
529
cs = ioio.openDigitalOutput(csPin)
53-
clk = ioio.openDigitalOutput(clkPin)
5410

5511
ioio.waitForConnect(10)
5612

57-
while 1
58-
shiftOut(0x55)
59-
delay 10000
60-
wend
13+
rem true sets the initial state to high (deasserted)
14+
cs.write(true)
6115

62-
sub shiftOut(_data)
63-
cs.write(false); ' Enable the chip
64-
for i = 7 to 0 step -1
65-
clk.write(false) ' Start clock pulse
66-
din.write((_data band (1 lshift i)) != 0) ' Send bit
67-
clk.write(true) ' End clock pulse
16+
spi.write(0x09, 0x00) ' Decode mode: no decode for digits 0-7
17+
spi.write(0x0A, 0x07) ' Intensity: maximum intensity 0x0 -> 0x0F
18+
spi.write(0x0B, 0x07) ' Scan limit: all digits
19+
spi.write(0x0C, 0x01) ' Shutdown: normal operation
20+
21+
while 1
22+
for i = 1 to 8
23+
spi.write(0x55)
6824
next
69-
cs.write(true) ' Disable the chip
70-
end
25+
delay 1000
26+
wend
27+
'

ioio/src/main/java/net/sourceforge/smallbasic/ioio/DigitalInputImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public void loop() throws InterruptedException, ConnectionLostException {
3131

3232
@Override
3333
public boolean read() {
34+
handleError();
3435
return value.get();
3536
}
3637

ioio/src/main/java/net/sourceforge/smallbasic/ioio/DigitalOutputImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void loop() throws ConnectionLostException {
2929

3030
@Override
3131
public void setup(IOIO ioio) throws ConnectionLostException {
32-
Log.i(TAG, "setup entered");
32+
Log.i(TAG, "setup entered: " + pin);
3333
output = ioio.openDigitalOutput(pin);
3434
}
3535

ioio/src/main/java/net/sourceforge/smallbasic/ioio/SpiMasterImpl.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package net.sourceforge.smallbasic.ioio;
22

3+
import java.io.IOException;
4+
35
import ioio.lib.api.IOIO;
46
import ioio.lib.api.SpiMaster;
57
import ioio.lib.api.exception.ConnectionLostException;
68
import ioio.lib.spi.Log;
79

810
public class SpiMasterImpl extends IOTask {
9-
private static final String TAG = "TwiMasterImpl";
11+
private static final String TAG = "SpiMasterImpl";
1012
private final IOLock<SpiMaster> lock = new IOLock<>();
1113
private SpiMaster spiMaster = null;
1214
private int miso;
@@ -19,14 +21,16 @@ public SpiMasterImpl() {
1921
Log.i(TAG, "created");
2022
}
2123

22-
public void open(int miso, int mosi, int clk, int slaveSelect) {
24+
public void open(int miso, int mosi, int clk, int slaveSelect) throws IOException {
25+
super.open(miso);
2326
this.miso = miso;
2427
this.mosi = mosi;
2528
this.clk = clk;
2629
this.slaveSelect = slaveSelect;
2730
}
2831

2932
public void write(int address, int data) {
33+
handleError();
3034
lock.invoke((i) -> {
3135
byte[] buffer = {(byte) address, (byte) data};
3236
spiMaster.writeRead(buffer, buffer.length, buffer.length, null, 0);
@@ -40,7 +44,7 @@ void loop() throws ConnectionLostException, InterruptedException {
4044

4145
@Override
4246
void setup(IOIO ioio) throws ConnectionLostException {
43-
Log.i(TAG, "setup entered");
47+
Log.i(TAG, "setup entered: " + miso + " " + mosi + " " + clk + " " + slaveSelect);
4448
spiMaster = ioio.openSpiMaster(miso, mosi, clk, slaveSelect, SpiMaster.Rate.RATE_1M);
4549
}
4650
}

0 commit comments

Comments
 (0)