pojiro
Do we need to write Linux i2c bus atomic operation by ourselves?
I think this is the basic question. I don’t know the I2C protocol details.
I would like to know the linux case.
Do we need to write the atomic operation for i2c bus in Elixir?
Or if we just use cicuits_i2c, it is done by the library or Linux driver?
Thank you
Marked As Solved
fhunleth
You can open as many I2C bus references as you’d like. There won’t be any issues. It’s common to call Circuits.I2C.open/2 for each I2C device that you’re using from Elixir. What you’re describing with two GenServers is the normal way, and that’s how most Elixir libraries that use I2C are written.
Trying to pass around I2C bus references to reduce calls to Circuits.I2C.open/2 is unnecessary. I probably would only do that if it were really convenient.
The Linux kernel ensures that each read and write completes before the next transfer starts. The low level I2C hardware controller can only issue one at a time anyway.
Yes, there’s a file handle behind each I2C bus reference.
Also Liked
fhunleth
I might need more information on what you’re trying to achieve.
Linux schedules messages to devices in the order that they’re requested. If multiple OS or Erlang processes send messages on an I2C bus, they’ll be interleaved. Circuits.I2C directly uses the Linux APIs so it behaves identically.
There’s a way tell Linux to make more than one I2C bus transaction at a time using the I2C_RDWR ioctl. The Circuits.I2C.write_read/5 function uses this ioctl. The main reason is to do an I2C repeated start which is often expected by I2C devices. It also ensures that the write and read operations are issued back-to-back.
The I2C_RDWR lets you string together more I2C bus operations and this might be what you’re looking for with your question.
A PR that adds a Circuits.I2C.transfer/4 that takes a list of I2C operations would be interesting. But before going down that route, it would be good to confirm that this is the right thing to do. Every time I’ve thought I’ve needed to implement this, I’ve found that making multiple Circuits.I2C calls is sufficient. Also take a look at the error semantics as described in i2c-core-base.c.
Hope this helps.
pojiro
I appreciate your answer!!
Thank you
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









