-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample_for_terminal.c
69 lines (62 loc) · 1.2 KB
/
example_for_terminal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "universal_i2c/universal_i2c.h"
#include "stdio.h"
#include "string.h"
void setScl(int level)
{
//print red -/_ to show the level
if (level)
printf("\033[33m-");
else
printf("\033[33m_");
}
void setSda(int level)
{
//print yello -/_ to show the level
if (level)
printf("\033[32m-");
else
printf("\033[32m_");
}
void setSdaDir(int dir)
{
}
void setSclDir(int dir)
{
}
int getSda()
{
return 0;
}
void delayUs(int us)
{
}
struct UniversalI2cAdapter i2c0Adapter = {
.setScl = setScl,
.setSda = setSda,
.setSdaDir = setSdaDir,
.setSclDir = setSclDir,
.getSda = getSda,
.delayUs = delayUs
};
struct UniversalI2c i2c0 = {
.id = 0,
.freq = 1000,
.adapter = &i2c0Adapter
};
int main(int argc, char **argv)
{
unsigned int devAddr, regAddr, data;
if (argc == 1) {
printf("help\n");
return 0;
}
sscanf(argv[1], "0x%x", &devAddr);
sscanf(argv[2], "0x%x", ®Addr);
sscanf(argv[3], "0x%x", &data);
printf("devAddr=0x%x regAddr=0x%x data=0x%x\n", devAddr, regAddr, data);
printf("universal i2c example:\n"
"\033[33myello -/_ refer to the scl line \033[32mgreen -/_ refer to the sda line\n");
UniversalI2c_init(&i2c0);
UniversalI2c_writeByte(&i2c0, devAddr, regAddr, data);
return 0;
}