SAMA5: Framework for an touchscreen driver (incomplete)

This commit is contained in:
Gregory Nutt
2013-09-30 09:04:21 -06:00
parent ecd7502c34
commit 744f3776b7
6 changed files with 1252 additions and 30 deletions
+3
View File
@@ -5675,4 +5675,7 @@
* arch/arm/src/sama5/sam_adc.c and .h: Framework for an ADC
driver to come (just empty "skeleton" files on initial commit)
(2013-9-30).
* arch/arm/src/sama5/sam_touchscreen.h and .h: Framework for a
touchscreen driver (also an empty "skeleton" file on the initial
commit) (2013-9-30).
+3
View File
@@ -48,6 +48,9 @@
/****************************************************************************************
* Pre-processor Definitions
****************************************************************************************/
/* General definitions ******************************************************************/
#define SAM_ADC_NCHANNELS 12 /* 12 ADC Channels */
/* ADC register offsets ****************************************************************/
+157 -27
View File
@@ -74,23 +74,42 @@
struct sam_adc_s
{
/* Debug stuff */
#ifdef CONFIG_SAMA5_ADC_REGDEBUG
bool wrlast; /* Last was a write */
uintptr_t addrlast; /* Last address */
uint32_t vallast; /* Last value */
int ntimes; /* Number of times */
#endif
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/* Register operations ******************************************************/
#if defined(CONFIG_SAMA5_ADC_REGDEBUG) && defined(CONFIG_DEBUG)
static bool sam_adc_checkreg(struct sam_gmac_s *priv, bool wr,
uint32_t regval, uintptr_t address);
static uint32_t sam_adc_getreg(struct sam_gmac_s *priv, uintptr_t addr);
static void sam_adc_putreg(struct sam_gmac_s *priv, uintptr_t addr, uint32_t val);
#else
# define sam_adc_getreg(priv,addr) getreg32(addr)
# define sam_adc_putreg(priv,addr,val) putreg32(val,addr)
#endif
/* ADC interrupt handling */
static int adc_interrupt(int irq, void *context);
static int sam_adc_interrupt(int irq, void *context);
/* ADC methods */
static void adc_reset(FAR struct adc_dev_s *dev);
static int adc_setup(FAR struct adc_dev_s *dev);
static void adc_shutdown(FAR struct adc_dev_s *dev);
static void adc_rxint(FAR struct adc_dev_s *dev, bool enable);
static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg);
static void sam_adc_reset(FAR struct adc_dev_s *dev);
static int sam_adc_setup(FAR struct adc_dev_s *dev);
static void sam_adc_shutdown(FAR struct adc_dev_s *dev);
static void sam_adc_rxint(FAR struct adc_dev_s *dev, bool enable);
static int sam_adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg);
/****************************************************************************
* Private Data
@@ -100,11 +119,11 @@ static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg);
static const struct adc_ops_s g_adcops =
{
.ao_reset = adc_reset,
.ao_setup = adc_setup,
.ao_shutdown = adc_shutdown,
.ao_rxint = adc_rxint,
.ao_ioctl = adc_ioctl,
.ao_reset = sam_adc_reset,
.ao_setup = sam_adc_setup,
.ao_shutdown = sam_adc_shutdown,
.ao_rxint = sam_adc_rxint,
.ao_ioctl = sam_adc_ioctl,
};
/* ADC internal state */
@@ -126,15 +145,112 @@ static struct adc_dev_s g_adcdev =
****************************************************************************/
/****************************************************************************
* Name: adc_reset
* Name: sam_adc_checkreg
*
* Description:
* Reset the ADC device. Called early to initialize the hardware. This
* is called, before adc_setup() and on error conditions.
* Check if the current register access is a duplicate of the preceding.
*
* Input Parameters:
* regval - The value to be written
* address - The address of the register to write to
*
* Returned Value:
* true: This is the first register access of this type.
* flase: This is the same as the preceding register access.
*
****************************************************************************/
static void adc_reset(FAR struct adc_dev_s *dev)
#ifdef CONFIG_SAMA5_ADC_REGDEBUG
static bool sam_adc_checkreg(struct sam_gmac_s *priv, bool wr,
uint32_t regval, uintptr_t address)
{
if (wr == priv->wrlast && /* Same kind of access? */
regval == priv->vallast && /* Same value? */
address == priv->addrlast) /* Same address? */
{
/* Yes, then just keep a count of the number of times we did this. */
priv->ntimes++;
return false;
}
else
{
/* Did we do the previous operation more than once? */
if (priv->ntimes > 0)
{
/* Yes... show how many times we did it */
lldbg("...[Repeats %d times]...\n", priv->ntimes);
}
/* Save information about the new access */
priv->wrlast = wr;
priv->vallast = regval;
priv->addrlast = address;
priv->ntimes = 0;
}
/* Return true if this is the first time that we have done this operation */
return true;
}
#endif
/****************************************************************************
* Name: sam_adc_getreg
*
* Description:
* Read any 32-bit register using an absolute address.
*
****************************************************************************/
#ifdef CONFIG_SAMA5_ADC_REGDEBUG
static uint32_t sam_adc_getreg(struct sam_gmac_s *priv, uintptr_t address)
{
uint32_t regval = getreg32(address);
if (sam_adc_checkreg(priv, false, regval, address))
{
lldbg("%08x->%08x\n", address, regval);
}
return regval;
}
#endif
/****************************************************************************
* Name: sam_adc_putreg
*
* Description:
* Write to any 32-bit register using an absolute address.
*
****************************************************************************/
#ifdef CONFIG_SAMA5_ADC_REGDEBUG
static void sam_adc_putreg(struct sam_gmac_s *priv, uintptr_t address,
uint32_t regval)
{
if (sam_adc_checkreg(priv, true, regval, address))
{
lldbg("%08x<-%08x\n", address, regval);
}
putreg32(regval, address);
}
#endif
/****************************************************************************
* Name: sam_adc_reset
*
* Description:
* Reset the ADC device. Called early to initialize the hardware. This
* is called, before sam_adc_setup() and on error conditions.
*
****************************************************************************/
static void sam_adc_reset(FAR struct adc_dev_s *dev)
{
FAR struct sam_adc_s *priv = (FAR struct sam_adc_s *)dev->ad_priv;
irqstate_t flags;
@@ -147,7 +263,7 @@ static void adc_reset(FAR struct adc_dev_s *dev)
}
/****************************************************************************
* Name: adc_setup
* Name: sam_adc_setup
*
* Description:
* Configure the ADC. This method is called the first time that the ADC
@@ -157,14 +273,14 @@ static void adc_reset(FAR struct adc_dev_s *dev)
*
****************************************************************************/
static int adc_setup(FAR struct adc_dev_s *dev)
static int sam_adc_setup(FAR struct adc_dev_s *dev)
{
FAR struct sam_adc_s *priv = (FAR struct sam_adc_s *)dev->ad_priv;
int ret;
/* Attach the ADC interrupt */
ret = irq_attach(SAM_IRQ_ADC, adc_interrupt);
ret = irq_attach(SAM_IRQ_ADC, sam_adc_interrupt);
if (ret < 0)
{
adbg("ERROR: Failed to attach IRQ %d: %d\n", SAM_IRQ_ADC, ret);
@@ -178,7 +294,7 @@ static int adc_setup(FAR struct adc_dev_s *dev)
}
/****************************************************************************
* Name: adc_shutdown
* Name: sam_adc_shutdown
*
* Description:
* Disable the ADC. This method is called when the ADC device is closed.
@@ -186,7 +302,7 @@ static int adc_setup(FAR struct adc_dev_s *dev)
*
****************************************************************************/
static void adc_shutdown(FAR struct adc_dev_s *dev)
static void sam_adc_shutdown(FAR struct adc_dev_s *dev)
{
FAR struct sam_adc_s *priv = (FAR struct sam_adc_s *)dev->ad_priv;
@@ -203,14 +319,14 @@ static void adc_shutdown(FAR struct adc_dev_s *dev)
}
/****************************************************************************
* Name: adc_rxint
* Name: sam_adc_rxint
*
* Description:
* Call to enable or disable RX interrupts
*
****************************************************************************/
static void adc_rxint(FAR struct adc_dev_s *dev, bool enable)
static void sam_adc_rxint(FAR struct adc_dev_s *dev, bool enable)
{
FAR struct sam_adc_s *priv = (FAR struct sam_adc_s *)dev->ad_priv;
@@ -226,14 +342,14 @@ static void adc_rxint(FAR struct adc_dev_s *dev, bool enable)
}
/****************************************************************************
* Name: adc_ioctl
* Name: sam_adc_ioctl
*
* Description:
* All ioctl calls will be routed through this method
*
****************************************************************************/
static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
static int sam_adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
{
/* No ioctl commands supported */
@@ -241,14 +357,14 @@ static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
}
/****************************************************************************
* Name: adc_interrupt
* Name: sam_adc_interrupt
*
* Description:
* ADC interrupt handler
*
****************************************************************************/
static int adc_interrupt(int irq, void *context)
static int sam_adc_interrupt(int irq, void *context)
{
FAR struct sam_adc_s *priv = (FAR struct sam_adc_s *)g_adcdev.ad_priv;
uint32_t regval;
@@ -273,8 +389,22 @@ static int adc_interrupt(int irq, void *context)
*
****************************************************************************/
FAR struct adc_dev_s *sam_adcinitialize(void)
FAR struct adc_dev_s *sam_adc_initialize(void)
{
/* Enable the ADC peripheral clock*/
sam_adc_enableclk();
/* Reset the ADC controller */
sam_adc_putreg(priv, SAM_ADC_CR, ADC_CR_SWRST);
/* Reset Mode Register */
sam_adc_putreg(priv, SAM_ADC_MR, 0);
/* Return a pointer to the device structure */
return &g_adcdev;
}
+7 -3
View File
@@ -1,7 +1,6 @@
/****************************************************************************
* arch/arm/src/sama5/sam_adc.h
*
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
@@ -44,6 +43,8 @@
#include <nuttx/config.h>
#include "chip/sam_adc.h"
#ifdef CONFIG_SAMA5_ADC
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@@ -81,13 +82,16 @@ extern "C"
*
****************************************************************************/
#ifdef CONFIG_LPC17_ADC
FAR struct adc_dev_s *sam_adcinitialize(void);
#endif
/****************************************************************************
* Interfaces exported from the ADC to the touchscreen driver
****************************************************************************/
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_SAMA5_ADC */
#endif /* __ARCH_ARM_SRC_SAMA5_SAM_ADC_H */
File diff suppressed because it is too large Load Diff
+117
View File
@@ -0,0 +1,117 @@
/****************************************************************************
* arch/arm/src/sama5/sam_adc.h
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __ARCH_ARM_SRC_SAMA5_SAM_ADC_H
#define __ARCH_ARM_SRC_SAMA5_SAM_ADC_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "chip/sam_adc.h"
#if defined(CONFIG_SAMA5_ADC) && defined(CONFIG_SAMA5_TOUCHSCREEN)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sam_tsd_register
*
* Description:
* Configure the SAMA5 touchscreen. This will register the driver as
* /dev/inputN where N is the minor device number
*
* Input Parameters:
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
int sam_tsd_register(int minor);
/****************************************************************************
* Interfaces exported from the touchscreen to the ADC driver
****************************************************************************/
/****************************************************************************
* Name: sam_tsd_interrupt
*
* Description:
* Handles ADC interrupts associated with touchscreen channels
*
* Input parmeters:
* None
*
* Returned Value:
* None
*
****************************************************************************/
void sam_tsd_interrupt(void);
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_SAMA5_ADC && CONFIG_SAMA5_TOUCHSCREEN */
#endif /* __ARCH_ARM_SRC_SAMA5_SAM_ADC_H */