git.haldean.org d / e24ef72
move firmware into firmware directory Haldean Brown 3 years ago
6 changed file(s) with 128 addition(s) and 128 deletion(s). Raw diff Collapse all Expand all
+0
-2
Makefile less more
0 libal: main.c
1 gcc -o $@ $<
0 libal: main.c
1 gcc -o $@ $<
0 /*
1 * lidar-lite.h: definitions for interacting with Garmin's Lidar-Lite v3
2 * Copyright (C) 2016, Haldean Brown
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stdint.h>
20
21 typedef uint8_t i2c_register;
22
23 const i2c_register CMD = 0x00;
24 const uint8_t CMD_RESET = 0x00;
25 const uint8_t CMD_CAPTURE_FAST = 0x03;
26 const uint8_t CMD_CAPTURE = 0x04;
27
28 const i2c_register STATUS = 0x01;
29 const uint8_t STATUS_PROC_ERR = 0x40;
30 const uint8_t STATUS_HEALTH_ERR = 0x20;
31 const uint8_t STATUS_SECONDARY_RETURN = 0x10;
32 const uint8_t STATUS_INVALID_SIGNAL = 0x08;
33 const uint8_t STATUS_SIGNAL_OVERFLOW = 0x04;
34 const uint8_t STATUS_REF_OVERFLOW = 0x02;
35 const uint8_t STATUS_BUSY = 0x01;
36
37 const i2c_register SIG_COUNT_VAL = 0x02;
38
39 const i2c_register CONFIG = 0x04;
40 const uint8_t CONFIG_REF_DISABLE = 0x40;
41 const uint8_t CONFIG_OVERRIDE_BURST = 0x20;
42 const uint8_t CONFIG_REF_FILTER = 0x10;
43 const uint8_t CONFIG_QUICK_TERM = 0x08;
44 const uint8_t CONFIG_OVERRIDE_REF_NUM = 0x04;
45
46 const i2c_register DISTANCE_H = 0x0F;
47 const i2c_register DISTANCE_L = 0x10;
0 /*
1 * main.c: main libal runner
2 * Copyright (C) 2016, Haldean Brown
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <linux/i2c-dev.h>
20 #include <fcntl.h>
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stropts.h>
25 #include <time.h>
26 #include <unistd.h>
27
28 #include "lidar-lite.h"
29
30 static const int addr = 0x63;
31
32 static bool
33 register_write(int i2c, uint8_t *cmd, size_t len)
34 {
35 struct timespec ts;
36
37 if (write(i2c, cmd, len) != len)
38 {
39 fprintf(stderr, "failed to send write to %02X register\n",
40 cmd[0]);
41 return false;
42 }
43
44 // clock_nanosleep(
45 return true;
46 }
47
48 int main(int argc, char *argv[])
49 {
50 int i2c;
51 uint8_t buf[4];
52
53 i2c = open("/dev/i2c-0", O_RDWR);
54 if (i2c < 0)
55 {
56 perror("couldn't open I2C interface");
57 return 1;
58 }
59
60 if (ioctl(i2c, I2C_SLAVE, addr) < 0)
61 {
62 perror("couldnt set I2C address");
63 return 1;
64 }
65
66 bzero(buf, sizeof(buf));
67 buf[0] = SIG_COUNT_VAL;;
68 buf[1] = 0xFF;
69 if (!register_write(i2c, buf, 2))
70 return 1;
71
72 bzero(buf, sizeof(buf));
73 buf[0] = CONFIG;
74 buf[1] = CONFIG_REF_FILTER | CONFIG_QUICK_TERM;
75 if (!register_write(i2c, buf, 2))
76 return 1;
77 }
+0
-48
lidar-lite.h less more
0 /*
1 * lidar-lite.h: definitions for interacting with Garmin's Lidar-Lite v3
2 * Copyright (C) 2016, Haldean Brown
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stdint.h>
20
21 typedef uint8_t i2c_register;
22
23 const i2c_register CMD = 0x00;
24 const uint8_t CMD_RESET = 0x00;
25 const uint8_t CMD_CAPTURE_FAST = 0x03;
26 const uint8_t CMD_CAPTURE = 0x04;
27
28 const i2c_register STATUS = 0x01;
29 const uint8_t STATUS_PROC_ERR = 0x40;
30 const uint8_t STATUS_HEALTH_ERR = 0x20;
31 const uint8_t STATUS_SECONDARY_RETURN = 0x10;
32 const uint8_t STATUS_INVALID_SIGNAL = 0x08;
33 const uint8_t STATUS_SIGNAL_OVERFLOW = 0x04;
34 const uint8_t STATUS_REF_OVERFLOW = 0x02;
35 const uint8_t STATUS_BUSY = 0x01;
36
37 const i2c_register SIG_COUNT_VAL = 0x02;
38
39 const i2c_register CONFIG = 0x04;
40 const uint8_t CONFIG_REF_DISABLE = 0x40;
41 const uint8_t CONFIG_OVERRIDE_BURST = 0x20;
42 const uint8_t CONFIG_REF_FILTER = 0x10;
43 const uint8_t CONFIG_QUICK_TERM = 0x08;
44 const uint8_t CONFIG_OVERRIDE_REF_NUM = 0x04;
45
46 const i2c_register DISTANCE_H = 0x0F;
47 const i2c_register DISTANCE_L = 0x10;
+0
-78
main.c less more
0 /*
1 * main.c: main libal runner
2 * Copyright (C) 2016, Haldean Brown
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <linux/i2c-dev.h>
20 #include <fcntl.h>
21 #include <stdbool.h>
22 #include <stdio.h>
23 #include <string.h>
24 #include <stropts.h>
25 #include <time.h>
26 #include <unistd.h>
27
28 #include "lidar-lite.h"
29
30 static const int addr = 0x63;
31
32 static bool
33 register_write(int i2c, uint8_t *cmd, size_t len)
34 {
35 struct timespec ts;
36
37 if (write(i2c, cmd, len) != len)
38 {
39 fprintf(stderr, "failed to send write to %02X register\n",
40 cmd[0]);
41 return false;
42 }
43
44 // clock_nanosleep(
45 return true;
46 }
47
48 int main(int argc, char *argv[])
49 {
50 int i2c;
51 uint8_t buf[4];
52
53 i2c = open("/dev/i2c-0", O_RDWR);
54 if (i2c < 0)
55 {
56 perror("couldn't open I2C interface");
57 return 1;
58 }
59
60 if (ioctl(i2c, I2C_SLAVE, addr) < 0)
61 {
62 perror("couldnt set I2C address");
63 return 1;
64 }
65
66 bzero(buf, sizeof(buf));
67 buf[0] = SIG_COUNT_VAL;;
68 buf[1] = 0xFF;
69 if (!register_write(i2c, buf, 2))
70 return 1;
71
72 bzero(buf, sizeof(buf));
73 buf[0] = CONFIG;
74 buf[1] = CONFIG_REF_FILTER | CONFIG_QUICK_TERM;
75 if (!register_write(i2c, buf, 2))
76 return 1;
77 }