#ifndef __SI5351_H__
#define __SI5351_H__ __SI5351_H__

#include <stdint.h>

#include "twi.h"

static const uint8_t SI5351_ADDRESS = 96;

enum si5351_param_base {
    PLL_A = 26,
    PLL_B = 34,
    MULTISYNTH_0 = 42,
    MULTOSYNTH_1 = 50,
    MULTISYNTH_2 = 58
};

enum si5351_reg {
    CLK_ENABLE_CONTROL = 3,
    PLLX_SRC = 15,
    CLK0_CONTROL = 16,
    CLK1_CONTROL = 17,
    CLK2_CONTROL = 18,
    PLL_RESET = 177,
    XTAL_LOAD_CAP = 183
};



static inline uint8_t si5351_write8(uint8_t reg, uint8_t value) {
    uint8_t data[3] = {reg, value};
    return twi_write(SI5351_ADDRESS, data, 2);
}

void si5351_init(uint32_t freq_xtal, uint32_t freq_a, uint32_t freq_b);
void si5351_set_freq(enum si5351_param_base base, uint32_t freq);
uint8_t si5351_write_params(enum si5351_param_base base, uint32_t p1, uint32_t p2, uint32_t p3);



#endif
