90 lines
2.0 KiB
C
90 lines
2.0 KiB
C
/*
|
|
* si5351_driver.c
|
|
*
|
|
* Created on: 16. aug. 2024
|
|
* Author: Christian L. V. Madsen (OZ1CM)
|
|
*/
|
|
#include "include/si5351_driver.h"
|
|
|
|
enum{
|
|
SI5351_I2C_GET = 0,
|
|
SI5351_I2C_SET = 1,
|
|
|
|
};
|
|
|
|
static int readRegister(si5351_driver *inst,uint8_t data_addr, uint8_t *data, uint32_t len){
|
|
|
|
// Write what kind of addr we would like to read from:
|
|
inst->i2c_transfer_evt(inst->i2c_transfer_inst,&data_addr,1, SI5351_I2C_SET);
|
|
|
|
// Read data:
|
|
inst->i2c_transfer_evt(inst->i2c_transfer_inst,data,len, SI5351_I2C_GET);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int writeRegister(si5351_driver *inst,uint8_t data_addr, uint8_t *data, uint32_t len){
|
|
|
|
// Write what kind of addr we would like to read from:
|
|
inst->i2c_transfer_evt(inst->i2c_transfer_inst,&data_addr,1, SI5351_I2C_SET);
|
|
|
|
// Write data:
|
|
inst->i2c_transfer_evt(inst->i2c_transfer_inst,data,len, SI5351_I2C_SET);
|
|
|
|
return 0;
|
|
}
|
|
|
|
int cm_setInputSource(si5351_driver *inst, si5351_ClkSource clk_source){
|
|
|
|
switch(clk_source){
|
|
|
|
case SI5351_CLK_SOURCE_XTAL:
|
|
inst->device_data.pllInputSource.PLLA_SRC = 1;
|
|
break;
|
|
|
|
case SI5351_CLK_SOURCE_CLOCKSOURCE:
|
|
inst->device_data.pllInputSource.PLLA_SRC = 0;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
// Write to register:
|
|
writeRegister(inst,SI5351_REG_PLL_INPUT_SOURCE, (uint8_t*) &inst->device_data.pllInputSource, sizeof(si5351_PLLInputSource_t));
|
|
|
|
return 0;
|
|
}
|
|
|
|
uint8_t cm_si5351_getRevisionNumber(si5351_driver *inst){
|
|
|
|
// Read Device Status register:
|
|
readRegister(inst,0x00, (uint8_t *) &inst->device_data.deviceStatus, sizeof(si5351_deviceStat_t));
|
|
|
|
return inst->device_data.deviceStatus.REVID;
|
|
}
|
|
|
|
int cm_si5351_init(si5351_driver *inst, void *i2c_transfer_inst, setGet_I2C_Event_fpt i2c_transfer_evt){
|
|
|
|
if(inst == NULL)return -1;
|
|
if(i2c_transfer_inst == NULL)return -1;
|
|
if(i2c_transfer_evt == NULL)return -1;
|
|
|
|
inst->i2c_transfer_inst = i2c_transfer_inst;
|
|
inst->i2c_transfer_evt = i2c_transfer_evt;
|
|
|
|
int ret = 0;
|
|
|
|
// SW Reset device.
|
|
//ret = cm_ltr390_SWreset(inst);
|
|
|
|
// ret = ltr390_readAllReg(inst);
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|