mirror of
https://github.com/apache/nuttx.git
synced 2026-06-07 17:33:08 +08:00
arch/arm/src/lpc54xx: Complete coding of the I2C driver. It is not yet functional and has not yet been seriously tested. config/lpcxpresso-lpc54628: Add support for I2C2 and for the I2C tool to the nsh configuration.
This commit is contained in:
@@ -313,6 +313,8 @@
|
||||
#define I2C_SLAVE_STATE_RXAVAIL (1) /* Received data is available (Slave Receiver mode) */
|
||||
#define I2C_SLAVE_STATE_TXOK (2) /* Data can be transmitted (Slave Transmitter mode) */
|
||||
|
||||
/* Interrupt status, set and read, and clear registers */
|
||||
|
||||
#define I2C_INT_MSTPENDING (1 << 0) /* Bit 0 Master Pending interrupt */
|
||||
#define I2C_STAT_MSTSTATE_SHIFT (1) /* Bits 1-3: Master State code (status only) */
|
||||
#define I2C_STAT_MSTSTATE_MASK (7 << I2C_STAT_MSTSTATE_SHIFT)
|
||||
@@ -345,7 +347,7 @@
|
||||
#define I2C_INT_EVENTTIMEOUT (1 << 24) /* Bit 24: Event time-out interrupt */
|
||||
#define I2C_INT_SCLTIMEOUT (1 << 25) /* Bit 25: SCL time-out interrupt */
|
||||
|
||||
#define I2C_INT_MSTPENDING (1 << 0) /* Bit 0 Master Pending interrupt */
|
||||
#define I2C_INT_MSTPENDING (1 << 0) /* Bit 0 Master Pending interrupt */
|
||||
#define I2C_INT_MSTARBLOSS (1 << 4) /* Bit 4: Master Arbitration Loss interrupt */
|
||||
#define I2C_INT_MSTSTSTPERR (1 << 6) /* Bit 6: Master Start/Stop Error interrupt */
|
||||
#define I2C_INT_SLVPENDING (1 << 8) /* Bit 8: Slave Pending interrupt */
|
||||
@@ -360,7 +362,11 @@
|
||||
#define I2C_INT_ALL 0x030b8951
|
||||
|
||||
/* Time-out value */
|
||||
#define I2C_TIMEOUT_
|
||||
|
||||
#define I2C_TIMEOUT_SHIFT (0) /* Bits 0-15: Time out value
|
||||
* Bits 0-3 hardwired to 0xff */
|
||||
#define I2C_TIMEOUT_MASK (0xffff << I2C_TIMEOUT_SHIFT)
|
||||
# define I2C_TIMEOUT(n) ((uint32_t)((n)-1) << I2C_TIMEOUT_SHIFT)
|
||||
|
||||
/* Clock pre-divider for the entire I2C interface */
|
||||
|
||||
@@ -368,9 +374,6 @@
|
||||
#define I2C_CLKDIV_MASK (0xffff << I2C_CLKDIV_SHIFT)
|
||||
# define I2C_CLKDIV(n) ((uint32_t)((n)-1) << I2C_CLKDIV_SHIFT)
|
||||
|
||||
/* Interrupt status register for shared functions */
|
||||
#define I2C_INTSTAT_
|
||||
|
||||
/* Master control */
|
||||
|
||||
#define I2C_MSTCTL_MSTCONTINUE (1 << 0) /* Bit 0: Master Continue */
|
||||
@@ -388,7 +391,11 @@
|
||||
# define I2C_MSTTIME_SCLHIGH(n) ((uint32_t)((n)-2) << I2C_MSTTIME_SCLHIGH_SHIFT)
|
||||
|
||||
/* Combined Master receiver and transmitter data */
|
||||
#define I2C_MSTDAT_
|
||||
|
||||
#define I2C_MSTDAT_SHIFT (0) /* Bits 0-7: Master function data */
|
||||
#define I2C_MSTDAT_MASK (0xff << I2C_MSTDAT_SHIFT)
|
||||
# define I2C_MSTDAT(n) ((uint32_t)(n) << I2C_MSTDAT_SHIFT)
|
||||
|
||||
/* Slave control */
|
||||
#define I2C_SLVCTL_
|
||||
/* Combined Slave receiver and transmitter data */
|
||||
|
||||
@@ -184,11 +184,11 @@
|
||||
#undef HAVE_I2C_MASTER_DEVICE
|
||||
|
||||
#if defined(CONFIG_LPC54_I2C0_MASTER) || defined(CONFIG_LPC54_I2C1_MASTER) || \
|
||||
defined(CONFIG_LPC54_I2C1_MASTER) || defined(CONFIG_LPC54_I2C3_MASTER) || \
|
||||
defined(CONFIG_LPC54_I2C_MASTER4) || defined(CONFIG_LPC54_I2C5_MASTER) || \
|
||||
defined(CONFIG_LPC54_I2C2_MASTER) || defined(CONFIG_LPC54_I2C3_MASTER) || \
|
||||
defined(CONFIG_LPC54_I2C4_MASTER) || defined(CONFIG_LPC54_I2C5_MASTER) || \
|
||||
defined(CONFIG_LPC54_I2C6_MASTER) || defined(CONFIG_LPC54_I2C7_MASTER) || \
|
||||
defined(CONFIG_LPC54_I2C8_MASTER) || defined(CONFIG_LPC54_I2C9_MASTER)
|
||||
# define HAVE_MASTER_I2C_MASTER_DEVICE 1
|
||||
# define HAVE_I2C_MASTER_DEVICE 1
|
||||
#endif
|
||||
|
||||
/* Check if we have an SPI device */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -46,6 +46,23 @@ STATUS
|
||||
horizontal elongation.
|
||||
2017-12-14: Corrected a misconception about how the video data lines
|
||||
were configured. Now the LCD appears to be fully functional.
|
||||
2017-12-15: Added an I2C driver. This is the first step on the road
|
||||
to getting support for the capacitive touchscreen on the TFT panel.
|
||||
Not yet functional:
|
||||
|
||||
nsh> i2c dev -b 2 3 77
|
||||
0 1 2 3 4 5 6 7 8 9 a b c d e f
|
||||
00: -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
|
||||
70: -- -- -- -- -- -- -- --
|
||||
|
||||
I believe that the on-board Accelerometer, Audio Codec, and touch panel controller should have been detected (but perhaps that are not properly
|
||||
powered in this configuration?)
|
||||
|
||||
Configurations
|
||||
==============
|
||||
@@ -118,7 +135,7 @@ Configurations
|
||||
as NSH built-in applications.
|
||||
|
||||
NOTES:
|
||||
1, This configuration enables SDRAM to hold the LCD framebuffer and
|
||||
1. This configuration enables SDRAM to hold the LCD framebuffer and
|
||||
enables the LPC54xx LCD driver in order to support the LPCXpresso's
|
||||
TFT panel. In this configuration, the framebuffer resides in the
|
||||
the lower half megabyte of SDRAM beginning at address 0xa0000000
|
||||
@@ -179,3 +196,20 @@ Configurations
|
||||
RAMTest: Pattern test: a0000000 16777216 33333333 cccccccc
|
||||
RAMTest: Address-in-address test: a0000000 16777216
|
||||
nsh>
|
||||
|
||||
3. I2C2 is enabled (will be used with the capacitive touchscreen). In
|
||||
order to verify I2C functionality, the I2C tool at apps/system/i2ctool
|
||||
is enabled in this configuration.
|
||||
|
||||
nsh> i2c bus
|
||||
BUS EXISTS?
|
||||
Bus 0: NO
|
||||
Bus 1: NO
|
||||
Bus 2: YES
|
||||
Bus 3: NO
|
||||
Bus 4: NO
|
||||
Bus 5: NO
|
||||
Bus 6: NO
|
||||
Bus 7: NO
|
||||
Bus 8: NO
|
||||
Bus 9: NO
|
||||
|
||||
@@ -173,11 +173,16 @@
|
||||
# define BOARD_SYSTICK_CLOCK (BOARD_AHB_FREQUENCY / BOARD_SYSTICKCLKDIV)
|
||||
#endif
|
||||
|
||||
/* Flexcomm0: REVIST */
|
||||
/* Flexcomm0: USART0 (REVIST) */
|
||||
|
||||
#define BOARD_FLEXCOMM0_CLKSEL SYSCON_FCLKSEL_FRO12M
|
||||
#define BOARD_FLEXCOMM0_FCLK LPC54_FRO_12MHZ
|
||||
|
||||
/* Flexcomm2: I2C2 (REVIST) */
|
||||
|
||||
#define BOARD_FLEXCOMM2_CLKSEL SYSCON_FCLKSEL_FRO12M
|
||||
#define BOARD_FLEXCOMM2_FCLK LPC54_FRO_12MHZ
|
||||
|
||||
/* EMC */
|
||||
|
||||
#ifdef BOARD_220MHz
|
||||
@@ -273,6 +278,41 @@
|
||||
#define GPIO_USART0_RXD (GPIO_FC0_RXD_SDA_MOSI_2 | GPIO_FILTER_OFF)
|
||||
#define GPIO_USART0_TXD (GPIO_FC0_TXD_SCL_MISO_2 | GPIO_FILTER_OFF)
|
||||
|
||||
/* Flexomm2/I2C
|
||||
*
|
||||
* For I2C:
|
||||
* Type A & D pins need:
|
||||
* GPIO_OPENDRAIN + GPIO_FILTER_OFF
|
||||
* Type I pins need for Standard mode I2C need:
|
||||
* GPIO_FILTER_OFF + GPIO_I2C_FILTER_ON + GPIO_I2CDRIVE_LOW
|
||||
* Type I pins need for fast speed I2C need:
|
||||
* GPIO_FILTER_OFF + GPIO_I2C_FILTER_ON or OFF +
|
||||
* GPIO_I2CDRIVE_LOW or HIGH
|
||||
* Type I pins need for high speed I2C need:
|
||||
* GPIO_FILTER_OFF + GPIO_I2C_FILTER_OFF + GPIO_I2CDRIVE_HIGH
|
||||
*
|
||||
* The touchscreen controller is on I2C2: SCL P3.24, SDA P3.23. These are
|
||||
* both Type D/I pins.
|
||||
*/
|
||||
|
||||
#if defined(CONFIG_LPC54_I2C_FAST)
|
||||
# define _I2CFILTER GPIO_I2C_FILTER_OFF
|
||||
# define _I2CDRIVE GPIO_I2CDRIVE_HIGH
|
||||
#elif defined(CONFIG_LPC54_I2C_HIGH)
|
||||
# define _I2CFILTER GPIO_I2C_FILTER_OFF
|
||||
# define _I2CDRIVE GPIO_I2CDRIVE_HIGH
|
||||
#else
|
||||
# define _I2CFILTER GPIO_I2C_FILTER_ON
|
||||
# define _I2CDRIVE GPIO_I2CDRIVE_LOW
|
||||
#endif
|
||||
|
||||
#define GPIO_I2C2_SCL (GPIO_FC2_RTS_SCL_SSEL1_2 | \
|
||||
GPIO_FILTER_OFF | _I2CFILTER | \
|
||||
_I2CDRIVE)
|
||||
#define GPIO_I2C2_SDA (GPIO_FC2_CTS_SDA_SSEL0_2 | \
|
||||
GPIO_FILTER_OFF | _I2CFILTER | \
|
||||
_I2CDRIVE)
|
||||
|
||||
/* LCD
|
||||
*
|
||||
* There are no alternatives for LCD pins except for the VD0-VD3 pins.
|
||||
|
||||
@@ -13,8 +13,11 @@ CONFIG_FAT_LCNAMES=y
|
||||
CONFIG_FAT_LFN=y
|
||||
CONFIG_FS_FAT=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_I2C=y
|
||||
CONFIG_I2CTOOL_MAXBUS=9
|
||||
CONFIG_LPC54_EMC_DYNAMIC_CS0=y
|
||||
CONFIG_LPC54_EMC=y
|
||||
CONFIG_LPC54_I2C2_MASTER=y
|
||||
CONFIG_LPC54_USART0=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MAX_WDOGPARMS=2
|
||||
@@ -38,6 +41,7 @@ CONFIG_SDCLONE_DISABLE=y
|
||||
CONFIG_START_DAY=2
|
||||
CONFIG_START_MONTH=12
|
||||
CONFIG_SYMTAB_ORDEREDBYNAME=y
|
||||
CONFIG_SYSTEM_I2CTOOL=y
|
||||
CONFIG_SYSTEM_RAMTEST=y
|
||||
CONFIG_TASK_NAME_SIZE=0
|
||||
CONFIG_USART0_SERIAL_CONSOLE=y
|
||||
|
||||
@@ -44,9 +44,94 @@
|
||||
#include <syslog.h>
|
||||
|
||||
#include <nuttx/video/fb.h>
|
||||
#include <nuttx/i2c/i2c_master.h>
|
||||
|
||||
#include "lpc54_config.h"
|
||||
#include "lpc54_i2c_master.h"
|
||||
#include "lpcxpresso-lpc54628.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc54_i2c_register
|
||||
*
|
||||
* Description:
|
||||
* Register one I2C drivers for the I2C tool.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_I2CTOOL
|
||||
static void lpc54_i2c_register(int bus)
|
||||
{
|
||||
FAR struct i2c_master_s *i2c;
|
||||
int ret;
|
||||
|
||||
i2c = lpc54_i2cbus_initialize(bus);
|
||||
if (i2c == NULL)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to get I2C%d interface\n", bus);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = i2c_register(i2c, bus);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to register I2C%d driver: %d\n",
|
||||
bus, ret);
|
||||
lpc54_i2cbus_uninitialize(i2c);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: lpc54_i2ctool
|
||||
*
|
||||
* Description:
|
||||
* Register I2C drivers for the I2C tool.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_I2CTOOL
|
||||
static void lpc54_i2ctool(void)
|
||||
{
|
||||
#ifdef CONFIG_LPC54_I2C0_MASTER
|
||||
lpc54_i2c_register(0);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C1_MASTER
|
||||
lpc54_i2c_register(1);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C2_MASTER
|
||||
lpc54_i2c_register(2);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C3_MASTER
|
||||
lpc54_i2c_register(3);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C4_MASTER
|
||||
lpc54_i2c_register(4);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C5_MASTER
|
||||
lpc54_i2c_register(5);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C6_MASTER
|
||||
lpc54_i2c_register(6);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C7_MASTER
|
||||
lpc54_i2c_register(7);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C8_MASTER
|
||||
lpc54_i2c_register(8);
|
||||
#endif
|
||||
#ifdef CONFIG_LPC54_I2C9_MASTER
|
||||
lpc54_i2c_register(9);
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
# define lpc54_i2ctool()
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -79,6 +164,10 @@ int lpc54_bringup(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Register I2C drivers on behalf of the I2C tool */
|
||||
|
||||
lpc54_i2ctool();
|
||||
|
||||
#ifdef CONFIG_VIDEO_FB
|
||||
/* Initialize and register the framebuffer driver */
|
||||
|
||||
|
||||
@@ -43,10 +43,21 @@
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/compiler.h>
|
||||
|
||||
#include "lpc54_config.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define HAVE_I2CTOOL 1
|
||||
|
||||
/* Do we need to register I2C drivers on behalf of the I2C tool? */
|
||||
|
||||
#if !defined(CONFIG_SYSTEM_I2CTOOL) || !defined(CONFIG_I2C_DRIVER) || \
|
||||
!defined(HAVE_I2C_MASTER_DEVICE)
|
||||
# undef HAVE_I2CTOOL
|
||||
#endif
|
||||
|
||||
/* LED definitions **********************************************************/
|
||||
/* The LPCXpress-LPC54628 has three user LEDs: D9, D11, and D12. These
|
||||
* LEDs are for application use. They are illuminated when the driving
|
||||
|
||||
Reference in New Issue
Block a user