Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,17 @@ static int detect_onsemi_sensor(sensor_ctx_t *ctx, int fd,
return sid;
}

// SC1135 holds no ID in 0x3107/0x3108; it is told by 0x3008 = 0x60 and
// 0x3005 = 0x22. That is the pair the Xiongmai XM510 isp daemon accepts as an
// SC1135 once 0x3107/0x3108 matched none of its IDs: a sweep of every 0x3005
// value with 0x3008 = 0x60 under emulation accepted 0x22 alone. The reads are
// 16-bit addressed, which an 8-bit device takes as a register write, so they
// are made only when 0x3107/0x3108 read empty.
static bool is_smartsens_sc1135(int fd, unsigned char i2c_addr) {
return i2c_read_register(fd, i2c_addr, 0x3008, 2, 1) == 0x60 &&
i2c_read_register(fd, i2c_addr, 0x3005, 2, 1) == 0x22;
Comment thread
qodo-free-for-open-source-projects[bot] marked this conversation as resolved.
Resolved
Comment thread
openipc-ai marked this conversation as resolved.
Resolved
}

static int detect_smartsens_sensor(sensor_ctx_t *ctx, int fd,
unsigned char i2c_addr) {
if (i2c_change_addr(fd, i2c_addr) < 0)
Expand All @@ -483,8 +494,6 @@ static int detect_smartsens_sensor(sensor_ctx_t *ctx, int fd,
if (lower == -1)
return false;

// check for SC1035, SC1145, SC1135 '0x3008' reg val is equal to 0x60

int res = high << 8 | lower;
switch (res) {
case 0x0010:
Expand Down Expand Up @@ -709,7 +718,11 @@ static int detect_smartsens_sensor(sensor_ctx_t *ctx, int fd,
return true;
case 0:
case 0xffff:
// SC1135 catches here
// SC1135 has no ID here; only then are two more registers read
if (is_smartsens_sc1135(fd, i2c_addr)) {
strcpy(ctx->sensor_id, "SC1135");
return true;
}
return false;
default:
SENSOR_ERR("SmartSens", res);
Expand Down
1 change: 1 addition & 0 deletions src/sensors_golden.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ smartsens da23 SC1345
smartsens da4d SC1346
smartsens dc42 SC4336
smartsens eb2c SC2355
smartsens-sc1135 6022 SC1135
soi 0500 JXK00
soi 0501 JXK01
soi 0502 JXK02
Expand Down
9 changes: 9 additions & 0 deletions src/sensors_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ static void sc_smartsens(uint32_t id) {
mock_set(0x3107, 2, 1, id >> 8);
mock_set(0x3108, 2, 1, id & 0xff);
}
/* SC1135 has no ID in 0x3107/0x3108: they read empty, and 0x3008/0x3005
* name it. */
static void sc_smartsens_sc1135(uint32_t id) {
mock_set(0x3107, 2, 1, 0x00);
mock_set(0x3108, 2, 1, 0x00);
mock_set(0x3008, 2, 1, id >> 8);
mock_set(0x3005, 2, 1, id & 0xff);
}
static void sc_soi(uint32_t id) {
mock_set(0x0a, 1, 1, id >> 8);
mock_set(0x0b, 1, 1, id & 0xff);
Expand Down Expand Up @@ -221,6 +229,7 @@ static void sc_techpoint(uint32_t id) {

static const struct scenario scenarios[] = {
{"smartsens", detect_smartsens_sensor, sc_smartsens},
{"smartsens-sc1135", detect_smartsens_sensor, sc_smartsens_sc1135},
{"soi", detect_soi_sensor, sc_soi},
{"onsemi", detect_onsemi_sensor, sc_onsemi},
{"omni", detect_omni_sensor, sc_omni},
Expand Down
Loading