-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsi5351.h
88 lines (67 loc) · 1.83 KB
/
si5351.h
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/**************************************************************************/
/*!
@file si5351.h
@author Przemek Sadowski SQ9NJE
@license BSD (see license.txt)
@section HISTORY
v1.0 - First release
*/
/**************************************************************************/
#ifndef __SI5351_H__
#define __SI5351_H__
#include <utility/twi.h>
#include <Wire.h>
//#define SI5351_ADDR 0x63 // I2C address of the Mouser batch of ICs
#define SI5351_ADDR 0x60 // normal I2C address
#define PLL_A 26
#define PLL_B 34
#define MS_0 42
#define CLK0_PHOFF 165
#define CLK0_CFG 0x10
#define CLK_EN 0x03
#define CLK0 0
#define CLK1 1
#define CLK2 2
#define FBx_INT 6
#define CLKx_PDN 7
#define MSx_INT 6
#define MSx_SRC 5
#define CLKx_INV 4
#define CLKx_SRC 2
#define CLKx_IDRV 0
#define IDRV_8 3
#define IDRV_6 2
#define IDRV_4 1
#define IDRV_2 0
#define SRC_A 0
#define SRC_B 1
#define SRC_XTAL 0
#define SRC_CLKIN 1
#define SRC_PLL 3
#define FAREY_N 1048575
class si5351
{
private:
uint8_t _mult_a, _mult_b;
uint8_t _clk_src;
uint8_t _addr;
uint32_t _xtal;
int _ppm;
void farey(float alpha, uint32_t &x, uint32_t &y);
public:
si5351(uint8_t addr = SI5351_ADDR) { _addr = addr;}
void write_register(uint8_t addr, uint8_t value);
void write_block(uint8_t addr, uint8_t* value, uint8_t len);
uint8_t read_register(uint8_t addr);
void begin();
void set_xtal(uint32_t xtal);
void set_xtal(uint32_t xtal, int ppm);
void pll_integer_config(uint8_t pll, uint8_t multiplier);
void clk_config(uint8_t clk, uint8_t config);
void clk_disable(uint8_t clk);
void clk_enable(uint8_t clk);
void set_phase(uint8_t clk, uint8_t phase);
void set_frequency(uint8_t clk, uint32_t freq);
void simple_set_frequency(uint8_t clk, uint32_t freq);
};
#endif /* __SI5351_H__ */