-
Notifications
You must be signed in to change notification settings - Fork 0
/
pll.c
52 lines (42 loc) · 931 Bytes
/
pll.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
#include "pll.h"
#include "i2csw.h"
uint8_t pll_update_divider(pll_settings *p)
{
uint8_t ack = 1;
i2cStart();
ack &= i2cPutbyte(p->addr);
ack &= i2cPutbyte((p->div >> 8) & 0x7F);
ack &= i2cPutbyte(p->div & 0xFF);
i2cStop();
return ack;
}
uint8_t pll_update_ctrl(pll_settings *p)
{
uint8_t ack = 1;
i2cStart();
ack &= i2cPutbyte(p->addr);
ack &= i2cPutbyte(p->c1 | (1<<PLL_C11) | (1<<PLL_C12));
ack &= i2cPutbyte(p->c2);
i2cStop();
return ack;
}
uint8_t pll_update_all(pll_settings *p)
{
uint8_t ack = 1;
i2cStart();
ack &= i2cPutbyte(p->addr);
ack &= i2cPutbyte((p->div >> 8) & 0x7F); // must not be set
ack &= i2cPutbyte(p->div & 0xFF);
ack &= i2cPutbyte(p->c1 | (1<<PLL_C11) | (1<<PLL_C12));
ack &= i2cPutbyte(p->c2);
i2cStop();
return ack;
}
void pll_init(pll_settings *p, uint8_t addr, uint16_t div)
{
p->c1 = PLL_C1_DEFAULT;
p->c2 = 0;
p->div = div;
p->addr = addr;
pll_update_all(p);
}