Git Product home page Git Product logo

i2c-dev-sim's Introduction

I2C device simulation

During the coronavirus pandemic the need for simulating I2C devices arose. Students couldn't physically attend their laboratories and therefore I came up with the idea of making simulated (or virtual) I2C devices available. This would allow the students to still exercise the usage of the API to interact with the (simulated) devices. Of course, there are no physical effects like blinking LEDs or alike, but ... better than nothing.

The kernel already provides something close to this as I2C slave devices, notably the i2c-eeprom-slave. However, only a few I2C master device drivers support slaves and those require hardware to work.

The first approach was to write a single I2C driver that would both have the slaves attached and be used to interact with them (i.e. write and read data as I2C transactions). As it turned out, having a slave device at a given address prevents the usage of this address for the simple I2C ioctl/read/write operations (at least for the i2c-eeprom-slave which I wanted to use as a sample device).

The i2c-virt-bus driver therefore creates two I2C busses. The first ("/dev/i2c-<n>") is a dummy that manages the slave devices. It exposes no other capabilities. Although there is no such thing with I2C busses, you can think of it as a transparent hub to which all slave devices are attached.

The second ("/dev/i2c-<n+1>") I2C bus created when loading the module uses an I2C master driver that can be used to access the slave devices as if they were attached to its bus (see the setup-test target here). You can think of this bus as your connection to the hub.

Future development

No. I'm making these sources available as is because they may be helpful in an educational context. I have no plans to clean them up (I'm not a kernel developer and I'm sure some things are horrible, e.g. I have no idea how much locking is done by the i2c-core layer and what I have missed here by not doing any locking at all) or maintain them beyond my needs during the pandemic.

Eclipse settings for kernel modules

Of course, real kernel developers use vi or emacs. But I have grown accustomed to using eclipse, its refactoring capabilities and the ease of exploring unknown environments by hitting F3. I have no doubt that something like this can be achieved with emacs (which I did use as my main tool during the 80s), but I didn't have time to explore this. I achieved to setup eclipse for kernel module development, following these hints. The setup is tied to the OS/compiler version I used when developing these drivers (while make all should work anywhere). So you'll have to go through the setting if you want to use this in a different environment.

i2c-dev-sim's People

Contributors

mnlipp avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

seokbeomkim

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.