Skip to content

board/teensy40: Add I2C support #1471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/machine/board_teensy40.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,3 +346,49 @@ const (
I2C3_SDA_PIN = D25
I2C3_SCL_PIN = D24
)

var (
I2C0 = I2C1 // I2C0 is an alias for I2C1 (LPI2C1)
I2C1 = &_I2C1
_I2C1 = I2C{
Bus: nxp.LPI2C1,
sda: I2C1_SDA_PIN, // D18 (PA17 [AD_B1_01])
scl: I2C1_SCL_PIN, // D19 (PA16 [AD_B1_00])
muxSDA: muxSelect{
mux: nxp.IOMUXC_LPI2C1_SDA_SELECT_INPUT_DAISY_GPIO_AD_B1_01_ALT3,
sel: &nxp.IOMUXC.LPI2C1_SDA_SELECT_INPUT,
},
muxSCL: muxSelect{
mux: nxp.IOMUXC_LPI2C1_SCL_SELECT_INPUT_DAISY_GPIO_AD_B1_00_ALT3,
sel: &nxp.IOMUXC.LPI2C1_SCL_SELECT_INPUT,
},
}
I2C2 = &_I2C2
_I2C2 = I2C{
Bus: nxp.LPI2C3,
sda: I2C2_SDA_PIN, // D17 (PA22 [AD_B1_06])
scl: I2C2_SCL_PIN, // D16 (PA23 [AD_B1_07])
muxSDA: muxSelect{
mux: nxp.IOMUXC_LPI2C3_SDA_SELECT_INPUT_DAISY_GPIO_AD_B1_06_ALT1,
sel: &nxp.IOMUXC.LPI2C3_SDA_SELECT_INPUT,
},
muxSCL: muxSelect{
mux: nxp.IOMUXC_LPI2C3_SCL_SELECT_INPUT_DAISY_GPIO_AD_B1_07_ALT1,
sel: &nxp.IOMUXC.LPI2C3_SCL_SELECT_INPUT,
},
}
I2C3 = &_I2C3
_I2C3 = I2C{
Bus: nxp.LPI2C4,
sda: I2C3_SDA_PIN, // D25 (PA13 [AD_B0_13])
scl: I2C3_SCL_PIN, // D24 (PA12 [AD_B0_12])
muxSDA: muxSelect{
mux: nxp.IOMUXC_LPI2C4_SDA_SELECT_INPUT_DAISY_GPIO_AD_B0_13_ALT0,
sel: &nxp.IOMUXC.LPI2C4_SDA_SELECT_INPUT,
},
muxSCL: muxSelect{
mux: nxp.IOMUXC_LPI2C4_SCL_SELECT_INPUT_DAISY_GPIO_AD_B0_12_ALT0,
sel: &nxp.IOMUXC.LPI2C4_SCL_SELECT_INPUT,
},
}
)
8 changes: 4 additions & 4 deletions src/machine/machine_mimxrt1062.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,10 @@ func (jt *pinJumpTable) dispatchInterrupt(interrupt.Interrupt) {
if status := gpio.ISR.Get() & gpio.IMR.Get(); status != 0 {
gpio.ISR.Set(status) // clear interrupt
for status != 0 {
p := Pin(bits.TrailingZeros32(status))
i := Pin(port + p)
jt.lut[i](i)
status &^= 1 << p
off := Pin(bits.TrailingZeros32(status)) // ctz
pin := Pin(port + off)
jt.lut[pin](pin)
status &^= 1 << off
}
}
}
Expand Down
Loading