Skip to content

Commit 4cf4643

Browse files
committed
Add I2C support for BCM
1 parent b972dd8 commit 4cf4643

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

src/hal/bcm.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
#include "cjson/cJSON.h"
1010
#endif
1111

12+
static unsigned char omni_addrs[] = {0x36, 0};
13+
14+
static sensor_addr_t my_possible_i2c_addrs[] = {{SENSOR_OMNIVISION, omni_addrs},
15+
{0, NULL}};
16+
1217
bool bcm_detect_cpu(char *chip_name) {
1318
char buf[256];
1419

@@ -40,7 +45,21 @@ static void chip_properties(cJSON *j_inner) {
4045
}
4146
#endif
4247

48+
static int i2c_change_plain_addr(int fd, unsigned char addr) {
49+
if (ioctl(fd, I2C_SLAVE_FORCE, addr) < 0) {
50+
return -1;
51+
}
52+
return 0;
53+
}
54+
55+
/* For using I2C functions make sure you have:
56+
* dtparam=i2c_arm=on
57+
* dtparam=i2c0=on
58+
* in your /boot/config.txt
59+
*/
4360
void bcm_setup_hal() {
61+
possible_i2c_addrs = my_possible_i2c_addrs;
62+
i2c_change_addr = i2c_change_plain_addr;
4463
#ifndef STANDALONE_LIBRARY
4564
hal_chip_properties = chip_properties;
4665
#endif

src/hal/hisi/hal_hisi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static unsigned char omni_addrs[] = {0x60, 0x6c, 0x42, 0};
2828
static unsigned char gc_addrs[] = {0x6e, 0x52, 0};
2929
static unsigned char superpix_addrs[] = {0x79, 0};
3030

31-
sensor_addr_t hisi_possible_i2c_addrs[] = {
31+
static sensor_addr_t my_possible_i2c_addrs[] = {
3232
{SENSOR_SONY, sony_addrs}, {SENSOR_SOI, soi_addrs},
3333
{SENSOR_ONSEMI, onsemi_addrs}, {SENSOR_SMARTSENS, ssens_addrs},
3434
{SENSOR_OMNIVISION, omni_addrs}, {SENSOR_GALAXYCORE, gc_addrs},
@@ -429,7 +429,7 @@ void setup_hal_hisi() {
429429
i2c_read_register = hisi_sensor_read_register;
430430
i2c_write_register = hisi_sensor_write_register;
431431
}
432-
possible_i2c_addrs = hisi_possible_i2c_addrs;
432+
possible_i2c_addrs = my_possible_i2c_addrs;
433433
hal_temperature = hisi_get_temp;
434434
#ifndef STANDALONE_LIBRARY
435435
hal_detect_ethernet = hisi_ethdetect;

src/hal/tegra.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static int tegra_open_sensor_fd() {
3434
return universal_open_sensor_fd("/dev/i2c-6");
3535
}
3636

37-
static int i2c_no_change_addr(int fd, unsigned char addr) {
37+
static int i2c_change_plain_addr(int fd, unsigned char addr) {
3838
if (ioctl(fd, I2C_SLAVE_FORCE, addr) < 0) {
3939
return -1;
4040
}
@@ -65,7 +65,7 @@ static void firmware_props(cJSON *j_inner) {
6565
void tegra_setup_hal() {
6666
open_i2c_sensor_fd = tegra_open_sensor_fd;
6767
possible_i2c_addrs = tegra_possible_i2c_addrs;
68-
i2c_change_addr = i2c_no_change_addr;
68+
i2c_change_addr = i2c_change_plain_addr;
6969
#ifndef STANDALONE_LIBRARY
7070
hal_chip_properties = chip_properties;
7171
hal_firmware_props = firmware_props;

src/sensors.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,16 +557,16 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd,
557557
res = prod_msb << 8 | prod_lsb;
558558

559559
switch (res) {
560-
case 0x4688:
561-
res = 0x4689;
562-
sprintf(ctx->sensor_id, "OV4689");
563-
return true;
564560
case 0x2710:
565561
case 0x2715:
566562
case 0x2718:
563+
case 0x5647:
567564
case 0x9732:
568565
sprintf(ctx->sensor_id, "OV%04x", res);
569566
return true;
567+
case 0x4688:
568+
sprintf(ctx->sensor_id, "OV4689");
569+
return true;
570570
case 0x5305:
571571
sprintf(ctx->sensor_id, "OS05A");
572572
return true;

0 commit comments

Comments
 (0)