summaryrefslogtreecommitdiff
path: root/code/fe310/eos/i2s.c
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2018-03-17 01:56:21 +0100
committerUros Majstorovic <majstor@majstor.org>2018-03-17 01:56:21 +0100
commit723b3db6942c8b3f51a819870df6e523008c2ed0 (patch)
tree6053da05f47b4031745e7e69af051a4b658861d1 /code/fe310/eos/i2s.c
parentb623f680f6a7aa53de6a1d949d857b37f391c80d (diff)
pwm scaling for i2s sck line added
Diffstat (limited to 'code/fe310/eos/i2s.c')
-rw-r--r--code/fe310/eos/i2s.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/code/fe310/eos/i2s.c b/code/fe310/eos/i2s.c
index 3b1772c..47be820 100644
--- a/code/fe310/eos/i2s.c
+++ b/code/fe310/eos/i2s.c
@@ -10,7 +10,7 @@
#include "i2s.h"
#include "i2s_def.h"
-#define I2S_PWM_REG_CK PWM1_REG
+#define I2S_PWM_REG_CK PWM0_REG
#define I2S_PWM_REG_WS PWM2_REG
#define EOS_ABUF_IDX_MASK(IDX, SIZE) ((IDX) & ((SIZE) - 1))
@@ -90,6 +90,7 @@ void eos_i2s_init(void) {
unsigned long f = get_cpu_freq();
_eos_i2s_ck_period = 512;
+ uint32_t _ck_period_scaled = _eos_i2s_ck_period >> I2S_PWM_SCALE_CK;
GPIO_REG(GPIO_INPUT_EN) &= ~(1 << I2S_PIN_LR);
GPIO_REG(GPIO_OUTPUT_EN) |= (1 << I2S_PIN_LR);
GPIO_REG(GPIO_OUTPUT_XOR) &= ~(1 << I2S_PIN_LR);
@@ -110,15 +111,15 @@ void eos_i2s_init(void) {
I2S_PWM_REG_CK(PWM_CFG) = 0;
I2S_PWM_REG_CK(PWM_COUNT) = 0;
- I2S_PWM_REG_CK(PWM_CMP0) = _eos_i2s_ck_period - 1;
- I2S_PWM_REG_CK(PWM_CMP1) = I2S_PWM_REG_CK(PWM_CMP0) / 2;
- I2S_PWM_REG_CK(PWM_CMP2) = I2S_PWM_REG_CK(PWM_CMP0) / 8;
+ I2S_PWM_REG_CK(PWM_CMP0) = _ck_period_scaled;
+ I2S_PWM_REG_CK(PWM_CMP1) = _ck_period_scaled / 2;
+ I2S_PWM_REG_CK(PWM_CMP2) = _ck_period_scaled / 4;
I2S_PWM_REG_WS(PWM_CFG) = 0;
I2S_PWM_REG_WS(PWM_COUNT) = 0;
- I2S_PWM_REG_WS(PWM_CMP0) = _eos_i2s_ck_period * 64 - 1;
- I2S_PWM_REG_WS(PWM_CMP1) = I2S_PWM_REG_WS(PWM_CMP0) / 2;
- I2S_PWM_REG_WS(PWM_CMP2) = I2S_PWM_REG_WS(PWM_CMP0) - _eos_i2s_ck_period;
+ I2S_PWM_REG_WS(PWM_CMP0) = (_eos_i2s_ck_period + 1) * 64 - 1;
+ I2S_PWM_REG_WS(PWM_CMP1) = (_eos_i2s_ck_period + 1) * 32;
+ I2S_PWM_REG_WS(PWM_CMP2) = (_eos_i2s_ck_period + 1) * 62;
eos_intr_set(I2S_IRQ_SD_ID, I2S_IRQ_SD_PRIORITY, NULL);
eos_intr_set(I2S_IRQ_CK_ID, I2S_IRQ_CK_PRIORITY, NULL);
@@ -147,7 +148,7 @@ void eos_i2s_start(void) {
I2S_PWM_REG_CK(PWM_COUNT) = 0;
I2S_PWM_REG_WS(PWM_COUNT) = 0;
- I2S_PWM_REG_CK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP;
+ I2S_PWM_REG_CK(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP | I2S_PWM_SCALE_CK;
I2S_PWM_REG_WS(PWM_CFG) = PWM_CFG_ENALWAYS | PWM_CFG_ZEROCMP;
GPIO_REG(GPIO_IOF_SEL) |= (1 << I2S_PIN_CK);