pojiro

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

fhunleth

Co-author of Nerves

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

fhunleth

Co-author of Nerves

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

pojiro

I appreciate your answer!!

Thank you

Where Next?

Popular in Questions Top

New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 43622 214
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
marick
I had some trouble figuring out how to make many-to-many associations work. Once I got it working, I wrote a blog post. Because I’m a nov...
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement