diff --git a/arch/arm/src/sama5/Kconfig b/arch/arm/src/sama5/Kconfig index 960f1f80a2..4cf74c3dd5 100644 --- a/arch/arm/src/sama5/Kconfig +++ b/arch/arm/src/sama5/Kconfig @@ -1778,7 +1778,7 @@ config SAMA5_SPI_REGDEBUG endmenu # SPI device driver options endif # SAMA5_SPI0 || SAMA5_SPI1 -if SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 +if SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 || SAMA5_TWI3 menu "TWI device driver options" @@ -1797,6 +1797,11 @@ config SAMA5_TWI2_FREQUENCY default 100000 depends on SAMA5_TWI2 +config SAMA5_TWI3_FREQUENCY + int "TWI3 Frequency" + default 100000 + depends on SAMA5_TWI3 + config SAMA5_TWI_REGDEBUG bool "TWI register level debug" depends on DEBUG @@ -1806,7 +1811,7 @@ config SAMA5_TWI_REGDEBUG Very invasive! Requires also DEBUG. endmenu # TWI device driver options -endif # SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 +endif # SAMA5_TWI0 || SAMA5_TWI1 || SAMA5_TWI2 || SAMA5_TWI3 if SAMA5_SSC0 || SAMA5_SSC1 menu "SSC Configuration" diff --git a/arch/arm/src/sama5/sam_twi.c b/arch/arm/src/sama5/sam_twi.c index 1cde9bdb63..a2899729a7 100644 --- a/arch/arm/src/sama5/sam_twi.c +++ b/arch/arm/src/sama5/sam_twi.c @@ -70,7 +70,8 @@ #include "sam_pio.h" #include "sam_twi.h" -#if defined(CONFIG_SAMA5_TWI0) || defined(CONFIG_SAMA5_TWI1) || defined(CONFIG_SAMA5_TWI2) +#if defined(CONFIG_SAMA5_TWI0) || defined(CONFIG_SAMA5_TWI1) || \ + defined(CONFIG_SAMA5_TWI2) || defined(CONFIG_SAMA5_TWI3) /******************************************************************************* * Pre-processor Definitions @@ -89,6 +90,10 @@ #define CONFIG_SAMA5_TWI2_FREQUENCY 100000 #endif +#ifndef CONFIG_SAMA5_TWI3_FREQUENCY + #define CONFIG_SAMA5_TWI3_FREQUENCY 100000 +#endif + /* Driver internal definitions *************************************************/ #define TWI_TIMEOUT ((20 * CLK_TCK) / 1000) /* 20 mS */ @@ -186,6 +191,9 @@ static int twi1_interrupt(int irq, FAR void *context); #ifdef CONFIG_SAMA5_TWI2 static int twi2_interrupt(int irq, FAR void *context); #endif +#ifdef CONFIG_SAMA5_TWI3 +static int twi3_interrupt(int irq, FAR void *context); +#endif static void twi_timeout(int argc, uint32_t arg, ...); static void twi_startread(struct twi_dev_s *priv, struct i2c_msg_s *msg); @@ -237,6 +245,10 @@ static struct twi_dev_s g_twi1; static struct twi_dev_s g_twi2; #endif +#ifdef CONFIG_SAMA5_TWI3 +static struct twi_dev_s g_twi3; +#endif + struct i2c_ops_s g_twiops = { .setfrequency = twi_setfrequency, @@ -620,6 +632,13 @@ static int twi2_interrupt(int irq, FAR void *context) } #endif +#ifdef CONFIG_SAMA5_TWI3 +static int twi3_interrupt(int irq, FAR void *context) +{ + return twi_interrupt(&g_twi3); +} +#endif + /******************************************************************************* * Name: twi_timeout * @@ -1208,7 +1227,7 @@ struct i2c_dev_s *up_i2cinitialize(int bus) #ifdef CONFIG_SAMA5_TWI0 if (bus == 0) { - /* Set up TWI2 register base address and IRQ number */ + /* Set up TWI0 register base address and IRQ number */ priv = &g_twi0; priv->base = SAM_TWI0_VBASE; @@ -1285,6 +1304,33 @@ struct i2c_dev_s *up_i2cinitialize(int bus) pid = SAM_PID_TWI2; } else +#endif +#ifdef CONFIG_SAMA5_TWI3 + if (bus == 3) + { + /* Set up TWI3 register base address and IRQ number */ + + priv = &g_twi3; + priv->base = SAM_TWI3_VBASE; + priv->irq = SAM_IRQ_TWI3; + priv->twi = 3; + + /* Configure PIO pins */ + + sam_configpio(PIO_TWI3_CK); + sam_configpio(PIO_TWI3_D); + + /* Enable peripheral clocking */ + + sam_twi3_enableclk(); + + /* Select the interrupt handler, TWI frequency, and peripheral ID */ + + handler = twi3_interrupt; + frequency = CONFIG_SAMA5_TWI3_FREQUENCY; + pid = SAM_PID_TWI3; + } + else #endif { irqrestore(flags);