Documentation ¶
Overview ¶
Package i2c implements a driver for NXP I2C controllers adopting the following reference specifications:
- IMX6ULLRM - i.MX 6ULL Applications Processor Reference Manual - Rev 1 2017/11
- IMX6FG - i.MX 6 Series Firmware Guide - Rev 0 2012/11
This package is only meant to be used with `GOOS=tamago GOARCH=arm` as supported by the TamaGo framework for bare metal Go on ARM SoCs, see https://github.com/usbarmory/tamago.
Index ¶
Constants ¶
const ( // The default IFDR value corresponds to a frequency divider of 768, // assuming 66 MHz for PERCLK_CLK_ROOT this results in a baud rate of // 85 kbps (p1464, 31.7.2 I2C Frequency Divider Register (I2Cx_IFDR), // IMX6ULLRM). I2C_DEFAULT_IFDR = 0x16 I2Cx_IADR = 0x0000 I2Cx_IFDR = 0x0004 I2Cx_I2CR = 0x0008 I2CR_IEN = 7 I2CR_MSTA = 5 I2CR_MTX = 4 I2CR_TXAK = 3 I2CR_RSTA = 2 I2Cx_I2SR = 0x000c I2SR_IBB = 5 I2SR_IIF = 1 I2SR_RXAK = 0 I2Cx_I2DR = 0x0010 )
I2C registers (p1462, 31.7 I2C Memory Map/Register Definition, IMX6ULLRM)
const ( // Timeout is the default timeout for I2C operations. Timeout = 100 * time.Millisecond )
Configuration constants
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type I2C ¶
type I2C struct { sync.Mutex // Controller index Index int // Base register Base uint32 // Clock gate register CCGR uint32 // Clock gate CG int // Timeout for I2C operations Timeout time.Duration // Div sets the frequency divider to control the I2C clock rate // (p1464, 31.7.2 I2C Frequency Divider Register (I2Cx_IFDR), IMX6ULLRM). Div uint16 // contains filtered or unexported fields }
I2C represents an I2C port instance.
func (*I2C) Init ¶
func (hw *I2C) Init()
Init initializes the I2C controller instance. At this time only master mode is supported by this driver.
func (*I2C) Read ¶
Read reads a sequence of bytes from a target device (p167, 16.4.2 Programming the I2C controller for I2C Read, IMX6FG).
The return data buffer always matches the requested size, otherwise an error is returned.
The address length (`alen`) parameter should be set greater then 0 for ordinary I2C reads (`SLAVE W|ADDR|SLAVE R|DATA`), equal to 0 when not sending a register address (`SLAVE W|SLAVE R|DATA`) and less than 0 only to send a target read (`SLAVE R|DATA`).
func (*I2C) Write ¶
Write writes a sequence of bytes to a target device (p170, 16.4.4 Programming the I2C controller for I2C Write, IMX6FG)
Set greater then 0 for ordinary I2C write (`SLAVE W|ADDR|DATA`), set equal then 0 to not send register address (`SLAVE W|DATA`), alen less then 0 is invalid.
The address length (`alen`) parameter should be set greater then 0 for ordinary I2C writes (`SLAVE W|ADDR|DATA`), equal to 0 when not sending a register address (`SLAVE W|DATA`), values less than 0 are not valid.