-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathI2CFFM.java
More file actions
61 lines (47 loc) · 2.48 KB
/
Copy pathI2CFFM.java
File metadata and controls
61 lines (47 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package javaforce.ffm;
import java.lang.foreign.*;
import java.lang.invoke.*;
import static java.lang.foreign.ValueLayout.*;
import javaforce.*;
import javaforce.ffm.*;
import javaforce.api.*;
/** I2CAPI FFM implementation.
*
* Generated by GenFFM - DO NOT EDIT
*/
public class I2CFFM implements I2CAPI {
private FFM ffm;
private static I2CFFM instance;
public static synchronized I2CFFM getInstance() {
if (instance == null) {
instance = new I2CFFM();
if (!instance.ffm_init()) {
JFLog.log("I2CFFM init failed!");
instance = null;
}
}
return instance;
}
private MethodHandle i2cSetSlave;
public boolean i2cSetSlave(int a1) { try { boolean _ret_value_ = (boolean)i2cSetSlave.invokeExact(a1);return _ret_value_; } catch (Throwable t) { JFLog.log(t); return false;} }
private MethodHandle i2cSetup;
public boolean i2cSetup() { try { boolean _ret_value_ = (boolean)i2cSetup.invokeExact();return _ret_value_; } catch (Throwable t) { JFLog.log(t); return false;} }
private MethodHandle i2cWrite;
public boolean i2cWrite(byte[] a1,int a2) { try { Arena arena = Arena.ofAuto(); MemorySegment _array_a1 = FFM.toMemory(arena, a1);boolean _ret_value_ = (boolean)i2cWrite.invokeExact(_array_a1,a2);FFM.copyBack(_array_a1,a1);return _ret_value_; } catch (Throwable t) { JFLog.log(t); return false;} }
private MethodHandle i2cRead;
public int i2cRead(byte[] a1,int a2) { try { Arena arena = Arena.ofAuto(); MemorySegment _array_a1 = FFM.toMemory(arena, a1);int _ret_value_ = (int)i2cRead.invokeExact(_array_a1,a2);FFM.copyBack(_array_a1,a1);return _ret_value_; } catch (Throwable t) { JFLog.log(t); return -1;} }
private boolean ffm_init() {
if (FFM.debug) JFLog.log("I2CFFM init started");
MethodHandle init;
ffm = FFM.getInstance();
init = ffm.getFunction("I2CAPIinit", ffm.getFunctionDesciptor(ValueLayout.JAVA_BOOLEAN));
if (init == null) return false;
try {if (!(boolean)init.invokeExact()) return false;} catch (Throwable t) {JFLog.log(t); return false;}
i2cSetSlave = ffm.getFunctionPtr("_i2cSetSlave", ffm.getFunctionDesciptor(JAVA_BOOLEAN,JAVA_INT));
i2cSetup = ffm.getFunctionPtr("_i2cSetup", ffm.getFunctionDesciptor(JAVA_BOOLEAN));
i2cWrite = ffm.getFunctionPtr("_i2cWrite", ffm.getFunctionDesciptor(JAVA_BOOLEAN,ADDRESS,JAVA_INT));
i2cRead = ffm.getFunctionPtr("_i2cRead", ffm.getFunctionDesciptor(JAVA_INT,ADDRESS,JAVA_INT));
if (FFM.debug) JFLog.log("I2CFFM init complete");
return true;
}
}