{"id":30222885,"url":"https://github.com/maximilianfeldthusen/i2c-sensor-driver","last_synced_at":"2026-06-23T13:32:14.228Z","repository":{"id":309655826,"uuid":"1037081536","full_name":"maximilianfeldthusen/i2c-sensor-driver","owner":"maximilianfeldthusen","description":"i2c-sensor-driver","archived":false,"fork":false,"pushed_at":"2025-08-13T03:41:33.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"TFD","last_synced_at":"2025-09-06T17:46:09.971Z","etag":null,"topics":["c","driver","i2c","linux","linux-kernel","sensor","spdx"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maximilianfeldthusen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2025-08-13T03:29:51.000Z","updated_at":"2025-08-13T03:46:48.000Z","dependencies_parsed_at":"2025-08-13T19:01:05.060Z","dependency_job_id":null,"html_url":"https://github.com/maximilianfeldthusen/i2c-sensor-driver","commit_stats":null,"previous_names":["maximilianfeldthusen/i2c-sensor-driver"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maximilianfeldthusen/i2c-sensor-driver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2Fi2c-sensor-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2Fi2c-sensor-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2Fi2c-sensor-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2Fi2c-sensor-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximilianfeldthusen","download_url":"https://codeload.github.com/maximilianfeldthusen/i2c-sensor-driver/tar.gz/refs/heads/TFD","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2Fi2c-sensor-driver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34691770,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-23T02:00:07.161Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["c","driver","i2c","linux","linux-kernel","sensor","spdx"],"created_at":"2025-08-14T11:18:05.891Z","updated_at":"2026-06-23T13:32:14.208Z","avatar_url":"https://github.com/maximilianfeldthusen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# i2c-sensor-driver\n\n##  License Declaration\n\n```c\n// SPDX-License-Identifier: MIT\n```\n- Declares the license using the SPDX identifier.\n- Required for kernel contributions; this one uses **MIT**.\n\n---\n\n##  Header Inclusions\n\n```c\n#include \u003clinux/module.h\u003e\n#include \u003clinux/i2c.h\u003e\n#include \u003clinux/hwmon.h\u003e\n#include \u003clinux/hwmon-sysfs.h\u003e\n#include \u003clinux/slab.h\u003e\n```\n- `module.h`: For kernel module infrastructure.\n- `i2c.h`: For I²C device and driver APIs.\n- `hwmon.h` and `hwmon-sysfs.h`: For integrating with the hwmon subsystem.\n- `slab.h`: For memory allocation (`kzalloc`).\n\n---\n\n## Register Definition\n\n```c\n#define ACME_REG_TEMP 0x00\n```\n- Defines the register address where the sensor stores temperature data.\n\n---\n\n## Driver Data Structure\n\n```c\nstruct acme_data {\n    struct i2c_client *client;\n};\n```\n- Holds per-device data.\n- `i2c_client` represents the I²C device instance.\n\n---\n\n##  Temperature Read Function\n\n```c\nstatic int acme_read_temp(struct acme_data *data, long *val)\n```\n- Reads a 16-bit word from the temperature register.\n- Converts it from **big-endian** to host-endian.\n- Stores the result in `val` (assumed to be in milli-Celsius).\n- Returns 0 on success or a negative error code.\n\n---\n\n##  hwmon Read Callback\n\n```c\nstatic int acme_hwmon_read(...)\n```\n- Called by the hwmon subsystem when userspace reads `temp1_input`.\n- Verifies the sensor type and attribute.\n- Delegates to `acme_read_temp()`.\n\n---\n\n##  hwmon Operations\n\n```c\nstatic const struct hwmon_ops acme_hwmon_ops = {\n    .read = acme_hwmon_read,\n};\n```\n- Defines the read callback for hwmon.\n\n---\n\n## hwmon Channel Info\n\n```c\nstatic const struct hwmon_channel_info *acme_info[] = {\n    HWMON_CHANNEL_INFO(temp, HWMON_T_INPUT),\n    NULL\n};\n```\n- Declares that this driver exposes one temperature input.\n\n---\n\n## hwmon Chip Info\n\n```c\nstatic const struct hwmon_chip_info acme_chip_info = {\n    .ops = \u0026acme_hwmon_ops,\n    .info = acme_info,\n};\n```\n- Combines the ops and channel info into a single structure.\n\n---\n\n## Probe Function\n\n```c\nstatic int acme_probe(struct i2c_client *client, ...)\n```\n- Called when the kernel matches this driver to a device.\n- Allocates memory for `acme_data`.\n- Stores the `i2c_client` pointer.\n- Registers the device with hwmon using `devm_hwmon_device_register_with_info()`.\n- Returns 0 on success or an error code.\n\n---\n\n## Device Matching Tables\n\n```c\nstatic const struct i2c_device_id acme_id[] = { ... };\nstatic const struct of_device_id acme_of_match[] = { ... };\n```\n- Allow matching via legacy board files (`i2c_device_id`) or Device Tree (`of_device_id`).\n\n---\n\n## Driver Registration\n\n```c\nstatic struct i2c_driver acme_driver = { ... };\nmodule_i2c_driver(acme_driver);\n```\n- Defines the driver and registers it with the kernel.\n- `module_i2c_driver()` sets up init/exit functions automatically.\n\n---\n\n## Module Metadata\n\n```c\nMODULE_AUTHOR(\"Your Name\");\nMODULE_DESCRIPTION(\"ACME Temperature Sensor Driver (hwmon)\");\nMODULE_LICENSE(\"MIT\");\n```\n- Provides metadata for tools like `modinfo`.\n\n---\n\n##  What This Driver Does\n\n- Talks to a simple I²C temperature sensor.\n- Reads temperature from a register.\n- Exposes it via the standard hwmon interface (`/sys/class/hwmon/.../temp1_input`).\n- Compatible with tools like `sensors`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianfeldthusen%2Fi2c-sensor-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximilianfeldthusen%2Fi2c-sensor-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianfeldthusen%2Fi2c-sensor-driver/lists"}