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

raw i2c I/O #353

Open
csboling opened this issue Jul 26, 2020 · 1 comment · May be fixed by #367
Open

raw i2c I/O #353

csboling opened this issue Jul 26, 2020 · 1 comment · May be fixed by #367

Comments

@csboling
Copy link
Contributor

@csboling csboling commented Jul 26, 2020

For debugging and developing other I2C devices, or general experimentation, it would be useful to expose a Lua API for handling raw bytes and arbitrary addresses. Seems fine if there's an 8 byte limit or whatever.

@trentgill
Copy link
Collaborator

@trentgill trentgill commented Aug 2, 2020

This is not difficult. Just requires duplicating a bunch of a hooks from Lua. The main issue is in ii_leader_enqueue https://github.com/monome/crow/blob/main/lib/ii.c#L121 where commands are looked up from the descriptors (ii_find_command and type_size), so those values will need to be passed through from lib/lualink.c. We do this normally so sending the wrong count of arguments fills in the zeroes, and so Lua floats get converted to the appropriate bit-representation per command - ie. so the user doesn't have to know if it's 8bit/16bit, MSB first whatever.

The easiest solution would be to force the user the send everything as a sequence of bytes (so they will have to do the bitshifting in lua if it's a 16bit destination).

The current lua interface (https://github.com/monome/crow/blob/main/lua/ii.lua#L34) has ii.get and ii.set which are used by the autogenerated lua files. These functions just call into C, but they will fail if the address and/or commands are unknown by the ii-descriptor system. Rather than overload these functions, should we add ii.get_raw and ii.set_raw? These are potentially confusing with lua's internal use of rawset and rawget.

When it comes to doing an ii get, I don't know how this would work? The current implementation is:

function ii_LeadRx_handler( addr, cmd, _arg, data )
    local name, ix = ii.is.lookup(addr)
    local rx_event = { name   = ii[name].e[cmd]
                     , device = ix or 1
                     , arg    = _arg
                     }
    ii[name].event(rx_event, data)  -- WHAT DO WE CALL FOR A RAW ACCESS?
end

We could just piggyback on this function by checking if ii[name] is not nil, then acting as normal, or forwarding to ii.event_raw(e, value) if the device doesn't exist?

////////////

So yeah. This is not difficult, just an afternoon of typing & testing if someone wants it.

@csboling csboling linked a pull request that will close this issue Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants