if (timer_clock() - start > ms_to_ticks(CONFIG_I2C_START_TIMEOUT)) \
{ \
LOG_ERR("Timeout SI assert\n"); \
+ LOG_ERR("[%08lx]\n", HWREG(i2c->hw->base + I2C_STAT_OFF)); \
break; \
} \
} \
.pclk_mask = I2C0_PCLK_MASK,
.pclk_div = I2C0_PCLK_DIV8,
},
+ { /* I2C1 */
+ .base = I2C1_BASE_ADDR,
+ .pconp = BV(PCONP_PCI2C1),
+ .pinsel_port = PINSEL0_OFF,
+ .pinsel = I2C1_PINSEL,
+ .pinsel_mask = I2C1_PINSEL_MASK,
+ .pclksel = PCLKSEL1_OFF,
+ .pclk_mask = I2C1_PCLK_MASK,
+ .pclk_div = I2C1_PCLK_DIV8,
+ },
+ { /* I2C2 */
+ .base = I2C2_BASE_ADDR,
+ .pconp = BV(PCONP_PCI2C2),
+ .pinsel_port = PINSEL0_OFF,
+ .pinsel = I2C2_PINSEL,
+ .pinsel_mask = I2C2_PINSEL_MASK,
+ .pclksel = PCLKSEL1_OFF,
+ .pclk_mask = I2C2_PCLK_MASK,
+ .pclk_div = I2C2_PCLK_DIV8,
+ },
};
/**
i2c->hw = &i2c_lpc2_hw[dev];
i2c->vt = &i2c_lpc_vt;
-
/* Enable I2C clock */
PCONP |= i2c->hw->pconp;
ASSERT(HWREG(i2c->hw->base + I2C_SCLH_OFF) > 4);
ASSERT(HWREG(i2c->hw->base + I2C_SCLL_OFF) > 4);
- /* Assign pins to SCL and SDA (P0_27, P0_28) */
+ /* Assign pins to SCL and SDA */
HWREG(PINSEL_BASE_ADDR + i2c->hw->pinsel_port) &= ~i2c->hw->pinsel_mask;
HWREG(PINSEL_BASE_ADDR + i2c->hw->pinsel_port) |= i2c->hw->pinsel;
-
// Enable I2C
HWREG(i2c->hw->base + I2C_CONSET_OFF) = BV(I2CON_I2EN);
/* Pin Connect Block */
-#define PINSEL_BASE_ADDR 0xE002C000
+#define PINSEL_BASE_ADDR 0xE002C000
#define PINSEL0 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x00))
#define PINSEL1 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x04))
#define PINSEL2 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x08))
#define PINSEL9 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x24))
#define PINSEL10 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x28))
+#define PINSEL0_OFF 0x00
+#define PINSEL1_OFF 0x04
+#define PINSEL2_OFF 0x08
+#define PINSEL3_OFF 0x0C
+#define PINSEL4_OFF 0x10
+#define PINSEL5_OFF 0x14
+#define PINSEL6_OFF 0x18
+#define PINSEL7_OFF 0x1C
+#define PINSEL8_OFF 0x20
+#define PINSEL9_OFF 0x24
+#define PINSEL10_OFF 0x28
+
#define PINMODE0 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x40))
#define PINMODE1 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x44))
#define PINMODE2 (*(reg32_t *)(PINSEL_BASE_ADDR + 0x48))
#define PCLKSEL0 (*(reg32_t *)(SCB_BASE_ADDR + 0x1A8))
#define PCLKSEL1 (*(reg32_t *)(SCB_BASE_ADDR + 0x1AC))
+#define CCLKCFG_OFF 0x104
+#define USBCLKCFG_OFF 0x108
+#define CLKSRCSEL_OFF 0x10C
+#define PCLKSEL0_OFF 0x1A8
+#define PCLKSEL1_OFF 0x1AC
+
+
/* External Interrupts */
#define EXTINT (*(reg32_t *)(SCB_BASE_ADDR + 0x140))
#define INTWAKE (*(reg32_t *)(SCB_BASE_ADDR + 0x144))
#define U3TER (*(reg32_t *)(UART3_BASE_ADDR + 0x30))
/* I2C Interface 0 */
-#define I2C0_BASE_ADDR 0xE001C000
+#define I2C0_BASE_ADDR 0xE001C000
#define I20CONSET (*(reg32_t *)(I2C0_BASE_ADDR + 0x00))
#define I20STAT (*(reg32_t *)(I2C0_BASE_ADDR + 0x04))
#define I20DAT (*(reg32_t *)(I2C0_BASE_ADDR + 0x08))
#define I20CONCLR (*(reg32_t *)(I2C0_BASE_ADDR + 0x18))
/* I2C Interface 1 */
-#define I2C1_BASE_ADDR 0xE005C000
+#define I2C1_BASE_ADDR 0xE005C000
#define I21CONSET (*(reg32_t *)(I2C1_BASE_ADDR + 0x00))
#define I21STAT (*(reg32_t *)(I2C1_BASE_ADDR + 0x04))
#define I21DAT (*(reg32_t *)(I2C1_BASE_ADDR + 0x08))
#define I21CONCLR (*(reg32_t *)(I2C1_BASE_ADDR + 0x18))
/* I2C Interface 2 */
-#define I2C2_BASE_ADDR 0xE0080000
+#define I2C2_BASE_ADDR 0xE0080000
#define I22CONSET (*(reg32_t *)(I2C2_BASE_ADDR + 0x00))
#define I22STAT (*(reg32_t *)(I2C2_BASE_ADDR + 0x04))
#define I22DAT (*(reg32_t *)(I2C2_BASE_ADDR + 0x08))
#define I22SCLL (*(reg32_t *)(I2C2_BASE_ADDR + 0x14))
#define I22CONCLR (*(reg32_t *)(I2C2_BASE_ADDR + 0x18))
+/* I2C offesets */
+#define I2C_CONSET_OFF 0x00
+#define I2C_STAT_OFF 0x04
+#define I2C_DAT_OFF 0x08
+#define I2C_ADR_OFF 0x0C
+#define I2C_SCLH_OFF 0x10
+#define I2C_SCLL_OFF 0x14
+#define I2C_CONCLR_OFF 0x18
/* I2C register definition Clear */
#define I2CON_I2ENC 6 // I2C interface Disable bit
#define I2C0_PCLK_MASK 0xC000
#define I2C0_PCLK_DIV8 0xC000
#define I2C0_PCLK_DIV4 0x4000
-#define I2C0_PCLK_OFFSET 14
-
+#define I2C1_PCLK_MASK 0x00C0
+#define I2C1_PCLK_DIV8 0x00C0
+#define I2C1_PCLK_DIV4 0x0040
+#define I2C2_PCLK_MASK 0x300000
+#define I2C2_PCLK_DIV8 0x300000
+#define I2C2_PCLK_DIV4 0x100000
/* I2C pins defines */
#define I2C0_PINSEL_MASK 0x3C00000
#define I2C0_PINSEL 0x1400000
+#define I2C1_PINSEL_MASK 0x000000F
+#define I2C1_PINSEL 0x000000F
+#define I2C2_PINSEL_MASK 0x0F00000
+#define I2C2_PINSEL 0x0A00000
/* SPI0 (Serial Peripheral Interface 0) */
#define SPI0_BASE_ADDR 0xE0020000