Giter Site home page Giter Site logo

Comments (10)

shaggygi avatar shaggygi commented on June 17, 2024 1

I was tinkering with this for a little bit and was able to get the Restart bit to occur between write/read buffers. I'm just not so sure on the best solution as devices can required different sequences of this. For example, You might have to write a few bytes for addressing, followed by a Restart bit, write another for a command and then remaining data can be clocked in to read buffer. One question is how can this be structured to allow multiple types of bits in specific locations of command? 🤔

I'm putting these notes here to ponder later.

Added to I2cDevice.cs:
public abstract void WriteRead(Span<byte> writeBuffer, Span<byte> readBuffer);

Added to UnixI2cDevice.Linux.cs:

public override unsafe void WriteRead(Span<byte> writeBuffer, Span<byte> readBuffer)
{
  Initialize();

  fixed (byte* writeBufferPointer = writeBuffer)
  {
    fixed (byte* readBufferPointer = readBuffer)
    {
      Transfer(writeBufferPointer, readBufferPointer, writeBuffer.Length, readBuffer.Length);
    }
  }
}

from iot.

joperezr avatar joperezr commented on June 17, 2024

I think we can add the WriteRead method, but individual device bindings should still have to think about the specific protocol they require (meaining the Restart bit that you mention above) since that can't really be generalized. I would expect each binding to have all of that logic in their source code, and then call either Write(), Read() or WriteRead() methods as appropriate.

from iot.

joperezr avatar joperezr commented on June 17, 2024

Next steps for this: We would need a formal Api proposal for this in order to consider adding it to the library, so feel free to submit one.

from iot.

shaggygi avatar shaggygi commented on June 17, 2024

Just to note, all the bindings I've worked with appear to work by setting register pointer using a Write first and then follow up with the Reads. So it hasn't hindered me so far. Most of the device datasheets have diagrams on the steps to perform where a few had some more complex steps to do things like sequential writes/reads (and for more than one cycle of Writes/Reads within one command).

I also came across a note in a random blog that stated they had devices that would only work using the Reset condition and extra steps to configure the RPi. They were not using .NET IoT, didn't provide the device names, so I couldn't confirm their accuracy.

I was able to produce the Reset condition with above code, but needs to be thought through more. I'm okay with keeping this issue open for a period to allow others to chime in and keep record on possible devices that require this scenario. Investigate further if popular or close if not.

Thx

from iot.

ZhangGaoxing avatar ZhangGaoxing commented on June 17, 2024

Hope to be implemented in the master branch as soon as possible.
I have encountered problems in adding KT0803L binding recently. This is not the only one. When I used the old version System.Devices.Gpio package, it contained ReadWrite(), and MLX90614 worked well. However, Write()Read() mode does not work correctly when using the current System.Device.Gpio package.
@shaggygi @joperezr @krwq

from iot.

joperezr avatar joperezr commented on June 17, 2024

Adding WriteRead sounds reasonable to me. @ZhangGaoxing do you want to put up a PR for it?

from iot.

ZhangGaoxing avatar ZhangGaoxing commented on June 17, 2024

@joperezr Let you do it. I'm not familiar with Linux drivers.😀

from iot.

krwq avatar krwq commented on June 17, 2024

@ZhangGaoxing @shaggygi - @joperezr is currently on vacation so won't be able to help for couple of weeks. I think this just uses just some linux APIs I can help with linux implementation if it's not too much work although I'm not familiar with that piece of code - I don't think I currently have any devices which require Restart/Repeat so will be hard to test if it is working - perhaps one of you could start WIP PR and ask questions if you're not sure about something - or alternatively please point me to PRs which are broken because of lack of that and I can try to fix but you will need to tell me if it work...

add two work incorrectly sequence diagrams

not sure what that means 😄

Do you know of any cheap devices which would require Restart/Repeat we could get for testing? You have mentioned KT0803L, do you perhaps know any other?

Perhaps @JeremyKuhne knows or has some devices like that

from iot.

krwq avatar krwq commented on June 17, 2024

Marking as 3.0 since this is potentially blocking adding new devices

from iot.

ZhangGaoxing avatar ZhangGaoxing commented on June 17, 2024

I think we should try to solve this problem as soon as possible. I found that the SMBus protocol devices I tried to bind were not working properly (I can't guarantee all the devices), like MLX90614 (this sensor adafruit is on sale). I don't know if the latest version of the Raspberry Pi driver supports I2C Repeated Start, I refered this post to back the I2C driver, then I realized that our lib didn't provide WriteRead() method...

I remember that a long time ago version of System.Devices.Gpio provided this method.🤔

from iot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.