Created
October 21, 2021 06:20
-
-
Save ChuckM/299434f3f3cbea17b8bba48122f87bf4 to your computer and use it in GitHub Desktop.
i2s clock generation and shifting loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# xmit_reg is a Signal(16) as are left_dr and right_dr | |
# | |
self.sync += [ | |
mclk.eq(~mclk), # running at 1/2 the clock rate (25MHz) | |
# @posedge of MCLK | |
If(mclk == 0, | |
If(sticks == 15, | |
sticks.eq(0), | |
sclk.eq(~sclk), | |
# @negedge of SCLK | |
If(sclk == 1, | |
shift_count.eq(shift_count + 1), | |
# generate LRCLK | |
If(shift_count == 15, | |
shift_count.eq(0), | |
lrclk.eq(~lrclk), | |
), | |
# shift out bits | |
If(shift_count == 0, | |
If(lrclk == 1, | |
xmit_reg.eq(left_dr), | |
).Else( | |
xmit_reg.eq(right_dr), | |
) | |
).Else( | |
xmit_reg.eq((xmit_reg[:-1] << 1) | xmit_reg[-1]), | |
), | |
), | |
).Else( sticks.eq(sticks + 1)), | |
) | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment