Skip to content

Commit

Permalink
Merge pull request #57 from xmos/release/v5.5.0
Browse files Browse the repository at this point in the history
Release/v5.5.0
  • Loading branch information
xhuw authored Feb 1, 2023
2 parents 85dad33 + 552aba5 commit ec76b55
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# VocalFusion Raspberry Pi Setup Change Log

## 5.5.0

* Add tool for setting arbitrary I2S clock

## 5.4.0

* Add support for XVF3800
Expand Down
5 changes: 4 additions & 1 deletion resources/clk_dac_setup/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
default: bclk mclk
default: bclk mclk setup_arbitrary_i2s_rate

bclk: setup_mclk_bclk.c
gcc -g -o setup_bclk setup_mclk_bclk.c

mclk: setup_mclk_bclk.c
gcc -g -DMCLK -o setup_mclk setup_mclk_bclk.c

setup_arbitrary_i2s_rate: setup_mclk_bclk.c
gcc -g -DARBITRARY_LRCLK -o setup_arbitrary_i2s_rate setup_mclk_bclk.c

clean:
rm -f setup_mclk
rm -f setup_bclk
37 changes: 37 additions & 0 deletions resources/clk_dac_setup/setup_mclk_bclk.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ void gpioSetMode(unsigned gpio, unsigned mode)
gpioReg[reg] = (gpioReg[reg] & ~(7<<shift)) | (mode<<shift);
}

struct clk_reg_t {
int i;
int f;
};

struct clk_reg_t calc_register_values(double input_khz, double output_khz) {
int i = input_khz/output_khz;
return (struct clk_reg_t) {
.i = i,
.f = ((input_khz/output_khz) - i) * 4096
};
}

unsigned getGpioHardwareRevision(void)
{
Expand Down Expand Up @@ -279,6 +291,31 @@ int main(int argc, char *argv[])
printf("MCLK at %.3fkHz: using %s (I=%-4d F=%-4d MASH=%d)\n",
(float)(source_clk_kHz / (clk_i + (float) clk_f/4096)),
clocks[clk_source], clk_i, clk_f, clk_mash);
#elif defined(ARBITRARY_LRCLK)
if(argc <= 1) {
return 1;
}

double desired = atof(argv[1]);
if(desired < 8000) {
printf("bad arg, expected valid clock rate in hz");
return 1;
}
printf("requested lrclk %f\n", desired);

int clk_index = 2;
int clk_source = 0;
int clk_mash = 1;
int clk_enable = 1;
double bclk_per_lrclk = 64;
struct clk_reg_t c = calc_register_values(source_clk_kHz, (desired*bclk_per_lrclk)/1000);
int clk_i = c.i;
int clk_f = c.f;

printf("BCLK at %.3fkHz: using %s (I=%-4d F=%-4d MASH=%d)\n",
(float)(source_clk_kHz / (clk_i + (float) clk_f/4096)),
clocks[clk_source], clk_i, clk_f, clk_mash);

#else
int i2s_16000 = 0;
if (argc > 1){
Expand Down

0 comments on commit ec76b55

Please sign in to comment.