{"id":23517135,"url":"https://github.com/mnlipp/i2c-dev-sim","last_synced_at":"2025-07-12T07:05:05.079Z","repository":{"id":145192036,"uuid":"257108274","full_name":"mnlipp/i2c-dev-sim","owner":"mnlipp","description":"An I2C bus with only virtual devices for exercises with the I2C user space API","archived":false,"fork":false,"pushed_at":"2025-04-06T10:33:24.000Z","size":77,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-14T00:38:43.660Z","etag":null,"topics":["i2c","i2c-slave","kernel-driver","kernel-module"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mnlipp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-04-19T21:42:54.000Z","updated_at":"2025-04-22T07:15:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ddce5a3-48bc-40ba-9b07-e3bbfb436525","html_url":"https://github.com/mnlipp/i2c-dev-sim","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mnlipp/i2c-dev-sim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnlipp%2Fi2c-dev-sim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnlipp%2Fi2c-dev-sim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnlipp%2Fi2c-dev-sim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnlipp%2Fi2c-dev-sim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnlipp","download_url":"https://codeload.github.com/mnlipp/i2c-dev-sim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnlipp%2Fi2c-dev-sim/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264952368,"owners_count":23688062,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["i2c","i2c-slave","kernel-driver","kernel-module"],"created_at":"2024-12-25T15:16:35.984Z","updated_at":"2025-07-12T07:05:05.060Z","avatar_url":"https://github.com/mnlipp.png","language":"C","readme":"# I2C device simulation\n\nDuring the coronavirus pandemic the need for simulating I2C devices arose.\nStudents couldn't physically attend their laboratories and therefore I came\nup with the idea of making simulated (or virtual) I2C devices available.\nThis would allow the students to still exercise the usage of the API\nto interact with the (simulated) devices. Of course, there are no physical \neffects like blinking LEDs or alike, but ... better than nothing.\n\nThe kernel already provides something close to this as I2C slave devices,\nnotably the \n[i2c-eeprom-slave](https://github.com/torvalds/linux/blob/master/drivers/i2c/i2c-slave-eeprom.c). \nHowever, only a few I2C master device drivers support slaves and those\nrequire hardware to work.\n\nThe first approach was to write a single I2C driver that would both \nhave the slaves attached and be used to interact with them (i.e.\nwrite and read data as I2C transactions). As it turned out, having\na slave device at a given address prevents the usage of this address\nfor the simple I2C ioctl/read/write operations (at least for the\ni2c-eeprom-slave which I wanted to use as a sample device).\n\nThe i2c-virt-bus driver therefore creates two I2C busses. The first\n(\"`/dev/i2c-\u003cn\u003e`\") is a dummy that manages the slave devices. It exposes\nno other capabilities. Although there is no such thing with I2C busses,\nyou can think of it as a transparent hub to which all slave devices are \nattached.\n\nThe second (\"`/dev/i2c-\u003cn+1\u003e`\") I2C bus created when loading the module\nuses an I2C master driver that can be used to access the slave devices\nas if they were attached to its bus (see the setup-test target \n[here](test/Makefile)). You can think of this bus as your connection\nto the hub.\n\n## Future development\n\nNo. I'm making these sources available as is because they may be helpful\nin an educational context. I have no plans to clean them up\n(I'm not a kernel developer and I'm sure some things are horrible, e.g.\nI have no idea how much locking is done by the i2c-core layer and\nwhat I have missed here by not doing any locking at all) or maintain\nthem beyond my needs during the pandemic.\n\n## Eclipse settings for kernel modules\n\nOf course, real kernel developers use vi or emacs. But I have grown\naccustomed to using eclipse, its refactoring capabilities and the\nease of exploring unknown environments by hitting `F3`. I have no doubt\nthat something like this can be achieved with emacs (which I did use\nas my main tool during the 80s), but I didn't have time to explore this. \nI achieved to setup eclipse for kernel module development, following \n[these](https://wiki.eclipse.org/HowTo_use_the_CDT_to_navigate_Linux_kernel_source)\nhints. The setup is tied to the OS/compiler version I used when developing\nthese drivers (while `make all` should work anywhere). So you'll have\nto go through the setting if you want to use this in a different environment.","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnlipp%2Fi2c-dev-sim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnlipp%2Fi2c-dev-sim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnlipp%2Fi2c-dev-sim/lists"}