summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/soc/trap_entry.S
diff options
context:
space:
mode:
authorUros Majstorovic <majstor@majstor.org>2024-09-12 15:48:59 +0200
committerUros Majstorovic <majstor@majstor.org>2024-09-12 15:48:59 +0200
commitfbef02e7d13e85ddfc9b22c7f06cbfad9f0fd9d3 (patch)
tree86c02358c6e0fece9d9f1066ceafb52cba9f0d49 /fw/fe310/eos/soc/trap_entry.S
parentf454f5238c0af89dcadfc572478dcd96efc74d98 (diff)
fixed i2s driver
Diffstat (limited to 'fw/fe310/eos/soc/trap_entry.S')
-rw-r--r--fw/fe310/eos/soc/trap_entry.S45
1 files changed, 26 insertions, 19 deletions
diff --git a/fw/fe310/eos/soc/trap_entry.S b/fw/fe310/eos/soc/trap_entry.S
index 1d3d1c2..98f9267 100644
--- a/fw/fe310/eos/soc/trap_entry.S
+++ b/fw/fe310/eos/soc/trap_entry.S
@@ -136,7 +136,7 @@ i2s_abuf_pop:
1:
sh x18, I2S_ABUF_OFF_IDXR(x9)
- # check for correct channel if mode is stereo
+ # check if buf data is for correct channel if mode is stereo
lw x21, I2S_MODE(x27)
bnez x21, 2f
andi x22, x22, 1
@@ -209,11 +209,16 @@ i2s_sd_xchg:
li x21, (1 << I2S_PIN_SR_CK)
lw x22, GPIO_OUTPUT_VAL(x18)
+ # disable intpu, enable output for I2S_PIN_SD_OUT (pin is low)
lw x9, GPIO_OUTPUT_EN(x18)
or x9, x9, x20
sw x9, GPIO_OUTPUT_EN(x18)
-
not x20, x20
+ lw x9, GPIO_INPUT_EN(x18)
+ and x9, x9, x20
+ sw x9, GPIO_INPUT_EN(x18)
+
+ # I2S_PIN_SR_CK bit low (was high)
xor x22, x22, x21
li x23, 16
@@ -230,55 +235,57 @@ i2s_sd_xchg:
and x22, x22, x20
or x22, x22, x9
-#if I2S_IDLE1_CYCLES
- # idle
- li x9, I2S_IDLE1_CYCLES
-1:
- addi x9, x9, -1
- bnez x9, 1b
-#endif
-
# read bit
lw x9, GPIO_INPUT_VAL(x18)
and x9, x9, x19
srli x9, x9, I2S_PIN_SD_IN
or x8, x8, x9
- # 74HC595 ck low (I2S_PIN_SR_CK high)
+ # I2S_PIN_SR_CK pin high (74HC595 ck low)
xor x22, x22, x21
sw x22, GPIO_OUTPUT_VAL(x18)
+#if I2S_IDLE1_CYCLES
# idle
- li x9, I2S_IDLE2_CYCLES
+ li x9, I2S_IDLE1_CYCLES
1:
addi x9, x9, -1
bnez x9, 1b
+#endif
- # 74HC595 ck high (I2S_PIN_SR_CK low)
+ # I2S_PIN_SR_CK pin low (74HC595 ck high)
xor x22, x22, x21
sw x22, GPIO_OUTPUT_VAL(x18)
- addi x23, x23, -1
- bnez x23, 0b
-
+#if I2S_IDLE2_CYCLES
# idle
li x9, I2S_IDLE2_CYCLES
1:
addi x9, x9, -1
bnez x9, 1b
+#endif
+
+ addi x23, x23, -1
+ bnez x23, 0b
- # 74HC595 ck low (I2S_PIN_SR_CK high)
+ # I2S_PIN_SD_OUT pin low (has pull-dn)
+ and x22, x22, x20
+ # I2S_PIN_SR_CK pin high (74HC595 ck low)
xor x22, x22, x21
sw x22, GPIO_OUTPUT_VAL(x18)
+ # disable output, enable input for I2S_PIN_SD_OUT
lw x9, GPIO_OUTPUT_EN(x18)
- and x9, x9, x20
+ xor x9, x9, x20
sw x9, GPIO_OUTPUT_EN(x18)
+ lw x9, GPIO_INPUT_EN(x18)
+ xor x9, x9, x20
+ sw x9, GPIO_INPUT_EN(x18)
slli x8, x8, 16
srai x8, x8, 16
- # skip right channel
+ # skip right mic channel
bnez x25, i2s_sd_complete
i2s_encode: