Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy array of struct to memory and back #67

Open
sgjava opened this issue May 7, 2020 · 0 comments
Open

Copy array of struct to memory and back #67

sgjava opened this issue May 7, 2020 · 0 comments

Comments

@sgjava
Copy link

sgjava commented May 7, 2020

For I2C message you need to pass an array of structs:

struct i2c_msg {
	__u16 addr;
	__u16 flags;
#define I2C_M_TEN		0x0010
#define I2C_M_RD		0x0001
#define I2C_M_STOP		0x8000
#define I2C_M_NOSTART		0x4000
#define I2C_M_REV_DIR_ADDR	0x2000
#define I2C_M_IGNORE_NAK	0x1000
#define I2C_M_NO_RD_ACK		0x0800
#define I2C_M_RECV_LEN		0x0400
	__u16 len;
	__u8 *buf;
};

So I defined:

@JniClass(name = "i2c_msg", flags = {STRUCT})
public static class i2cMsg {

    static {
        LIBRARY.load();
        init();
    }

    @JniMethod(flags = {CONSTANT_INITIALIZER})
    private static native void init();
    @JniField(flags = {CONSTANT}, accessor = "sizeof(struct i2c_msg)")
    public static int SIZEOF;

    public short addr;
    public short flags;
    public short len;
    public byte[] buf;
}

And I need 2 messages for a I2C read operation:

@JniMethod(accessor = "memmove")
public static final native void i2cMsgToMem(
@JniArg(cast = "void *") long dest, @JniArg(cast = "const void *", flags = {NO_OUT, CRITICAL}) i2cMsg src, @JniArg(
cast = "size_t") long size);

The above doesn't work for i2cMsg[].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant