Skip to content

Commit

Permalink
machine/k210: implement i2c.SetBaudRate()
Browse files Browse the repository at this point in the history
Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Oct 13, 2023
1 parent 7d13f62 commit 35b5cfc
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/machine/machine_k210.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,16 +566,7 @@ func (i2c *I2C) Configure(config I2CConfig) error {
config.SCL.SetFPIOAFunction(FUNC_I2C2_SCLK)
}

div := CPUFrequency() / config.Frequency / 16

// Disable controller before setting the prescale register.
i2c.Bus.ENABLE.Set(0)

i2c.Bus.CON.Set(0x63)

// Set prescaler registers.
i2c.Bus.SS_SCL_HCNT.Set(uint32(div))
i2c.Bus.SS_SCL_LCNT.Set(uint32(div))
i2c.SetBaudRate(config.Frequency)

i2c.Bus.INTR_MASK.Set(0)
i2c.Bus.DMA_CR.Set(0x03)
Expand All @@ -587,7 +578,17 @@ func (i2c *I2C) Configure(config I2CConfig) error {

// SetBaudRate sets the communication speed for I2C.
func (i2c *I2C) SetBaudRate(br uint32) error {
// TODO: implement
div := CPUFrequency() / br / 16

// Disable controller before setting the prescale register.
i2c.Bus.ENABLE.Set(0)

i2c.Bus.CON.Set(0x63)

// Set prescaler registers.
i2c.Bus.SS_SCL_HCNT.Set(uint32(div))
i2c.Bus.SS_SCL_LCNT.Set(uint32(div))

return nil
}

Expand Down

0 comments on commit 35b5cfc

Please sign in to comment.