mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 02:36:11 +08:00
More TSC2007 driver updates
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3830 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -62,6 +62,10 @@
|
||||
* - Be ready for IPMI
|
||||
**/
|
||||
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/irq.h>
|
||||
@@ -84,7 +88,6 @@
|
||||
#include "stm32_i2c.h"
|
||||
#include "stm32_waste.h"
|
||||
|
||||
|
||||
#if defined(CONFIG_STM32_I2C1) || defined(CONFIG_STM32_I2C2)
|
||||
|
||||
/************************************************************************************
|
||||
@@ -108,7 +111,6 @@ struct stm32_i2c_priv_s {
|
||||
uint32_t status;
|
||||
};
|
||||
|
||||
|
||||
/** I2C Device, Instance
|
||||
*/
|
||||
struct stm32_i2c_inst_s {
|
||||
@@ -120,7 +122,6 @@ struct stm32_i2c_inst_s {
|
||||
uint16_t flags;
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Private Data
|
||||
************************************************************************************/
|
||||
@@ -139,7 +140,6 @@ struct stm32_i2c_priv_s stm32_i2c2_priv = {
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Private Functions
|
||||
************************************************************************************/
|
||||
@@ -150,21 +150,18 @@ static inline uint16_t stm32_i2c_getreg(FAR struct stm32_i2c_priv_s *priv, uint8
|
||||
return getreg16(priv->base + offset);
|
||||
}
|
||||
|
||||
|
||||
/** Put register value by offset */
|
||||
static inline void stm32_i2c_putreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset, uint16_t value)
|
||||
{
|
||||
putreg16(value, priv->base + offset);
|
||||
}
|
||||
|
||||
|
||||
/** Modify register value by offset */
|
||||
static inline void stm32_i2c_modifyreg(FAR struct stm32_i2c_priv_s *priv, uint8_t offset, uint16_t clearbits, uint16_t setbits)
|
||||
{
|
||||
modifyreg16(priv->base + offset, clearbits, setbits);
|
||||
}
|
||||
|
||||
|
||||
void inline stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev)
|
||||
{
|
||||
while( sem_wait( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl ) != 0 ) {
|
||||
@@ -172,7 +169,6 @@ void inline stm32_i2c_sem_wait(FAR struct i2c_dev_s *dev)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int inline stm32_i2c_sem_waitisr(FAR struct i2c_dev_s *dev)
|
||||
{
|
||||
while( sem_wait( &((struct stm32_i2c_inst_s *)dev)->priv->sem_isr ) != 0 ) {
|
||||
@@ -181,27 +177,23 @@ int inline stm32_i2c_sem_waitisr(FAR struct i2c_dev_s *dev)
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void inline stm32_i2c_sem_post(FAR struct i2c_dev_s *dev)
|
||||
{
|
||||
sem_post( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl );
|
||||
}
|
||||
|
||||
|
||||
void inline stm32_i2c_sem_init(FAR struct i2c_dev_s *dev)
|
||||
{
|
||||
sem_init( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl, 0, 1);
|
||||
sem_init( &((struct stm32_i2c_inst_s *)dev)->priv->sem_isr, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
void inline stm32_i2c_sem_destroy(FAR struct i2c_dev_s *dev)
|
||||
{
|
||||
sem_destroy( &((struct stm32_i2c_inst_s *)dev)->priv->sem_excl );
|
||||
sem_destroy( &((struct stm32_i2c_inst_s *)dev)->priv->sem_isr );
|
||||
}
|
||||
|
||||
|
||||
static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequency)
|
||||
{
|
||||
/* Disable Peripheral if rising time is to be changed,
|
||||
@@ -238,20 +230,17 @@ static void stm32_i2c_setclock(FAR struct stm32_i2c_priv_s *priv, uint32_t frequ
|
||||
stm32_i2c_putreg(priv, STM32_I2C_CR1_OFFSET, cr1);
|
||||
}
|
||||
|
||||
|
||||
static inline void stm32_i2c_sendstart(FAR struct stm32_i2c_priv_s *priv)
|
||||
{
|
||||
/* Disable ACK on receive by default and generate START */
|
||||
stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, I2C_CR1_START);
|
||||
}
|
||||
|
||||
|
||||
static inline void stm32_i2c_sendstop(FAR struct stm32_i2c_priv_s *priv)
|
||||
{
|
||||
stm32_i2c_modifyreg(priv, STM32_I2C_CR1_OFFSET, I2C_CR1_ACK, I2C_CR1_STOP);
|
||||
}
|
||||
|
||||
|
||||
static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv)
|
||||
{
|
||||
uint32_t status = stm32_i2c_getreg(priv, STM32_I2C_SR1_OFFSET);
|
||||
@@ -259,7 +248,6 @@ static inline uint32_t stm32_i2c_getstatus(FAR struct stm32_i2c_priv_s *priv)
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Interrupt Service Routines
|
||||
************************************************************************************/
|
||||
@@ -425,8 +413,6 @@ static int stm32_i2c_isr(struct stm32_i2c_priv_s * priv)
|
||||
priv->status = status;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Decode ***************************************************************************/
|
||||
|
||||
@@ -444,7 +430,6 @@ static int stm32_i2c2_isr(int irq, void *context)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Private Initialization and Deinitialization
|
||||
************************************************************************************/
|
||||
@@ -511,7 +496,6 @@ static int stm32_i2c_init(FAR struct stm32_i2c_priv_s *priv)
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
/** Shutdown the I2C hardware */
|
||||
static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv)
|
||||
{
|
||||
@@ -555,7 +539,6 @@ static int stm32_i2c_deinit(FAR struct stm32_i2c_priv_s *priv)
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Device Driver OPS - Blocking Type
|
||||
************************************************************************************/
|
||||
@@ -574,7 +557,6 @@ uint32_t stm32_i2c_setfrequency(FAR struct i2c_dev_s *dev, uint32_t frequency)
|
||||
return ((struct stm32_i2c_inst_s *)dev)->frequency;
|
||||
}
|
||||
|
||||
|
||||
int stm32_i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev);
|
||||
@@ -586,7 +568,6 @@ int stm32_i2c_setaddress(FAR struct i2c_dev_s *dev, int addr, int nbits)
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int count)
|
||||
{
|
||||
struct stm32_i2c_inst_s *inst = (struct stm32_i2c_inst_s *)dev;
|
||||
@@ -666,7 +647,6 @@ int stm32_i2c_process(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int
|
||||
return -status_errno;
|
||||
}
|
||||
|
||||
|
||||
int stm32_i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
@@ -681,7 +661,6 @@ int stm32_i2c_write(FAR struct i2c_dev_s *dev, const uint8_t *buffer, int buflen
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
|
||||
int stm32_i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen)
|
||||
{
|
||||
stm32_i2c_sem_wait(dev); /* ensure that address or flags don't change meanwhile */
|
||||
@@ -696,7 +675,6 @@ int stm32_i2c_read(FAR struct i2c_dev_s *dev, uint8_t *buffer, int buflen)
|
||||
return stm32_i2c_process(dev, &msgv, 1);
|
||||
}
|
||||
|
||||
|
||||
#ifdef CONFIG_I2C_WRITEREAD
|
||||
int stm32_i2c_writeread(FAR struct i2c_dev_s *dev, const uint8_t *wbuffer, int wbuflen,
|
||||
uint8_t *buffer, int buflen)
|
||||
@@ -722,7 +700,6 @@ int stm32_i2c_writeread(FAR struct i2c_dev_s *dev, const uint8_t *wbuffer, int w
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef CONFIG_I2C_TRANSFER
|
||||
int stm32_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, int count)
|
||||
{
|
||||
@@ -731,7 +708,6 @@ int stm32_i2c_transfer(FAR struct i2c_dev_s *dev, FAR struct i2c_msg_s *msgs, in
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Device Structures, Instantiation
|
||||
************************************************************************************/
|
||||
@@ -740,9 +716,9 @@ struct i2c_ops_s stm32_i2c_ops = {
|
||||
.setfrequency = stm32_i2c_setfrequency,
|
||||
.setaddress = stm32_i2c_setaddress,
|
||||
.write = stm32_i2c_write,
|
||||
.read = stm32_i2c_read,
|
||||
.read = stm32_i2c_read
|
||||
#ifdef CONFIG_I2C_WRITEREAD
|
||||
.writeread = stm32_i2c_writeread
|
||||
, .writeread = stm32_i2c_writeread
|
||||
#endif
|
||||
#ifdef CONFIG_I2C_TRANSFER
|
||||
, .transfer = stm32_i2c_transfer
|
||||
@@ -753,7 +729,6 @@ struct i2c_ops_s stm32_i2c_ops = {
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
/************************************************************************************
|
||||
* Public Function - Initialization
|
||||
************************************************************************************/
|
||||
|
||||
@@ -496,7 +496,7 @@ int sif_init(void)
|
||||
* Provides direct access to the sensor connector, readings, and diagnostic.
|
||||
**/
|
||||
|
||||
extern int cc1101_eventcb(int irq, FAR void *context)
|
||||
extern int cc1101_eventcb(int irq, FAR void *context);
|
||||
|
||||
int sif_main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
+464
-86
File diff suppressed because it is too large
Load Diff
+5
-10
@@ -38,6 +38,11 @@
|
||||
*
|
||||
********************************************************************************************/
|
||||
|
||||
/* The TSC2007 is an analog interface circuit for a human interface touch screen device.
|
||||
* All peripheral functions are controlled through the command byte and onboard state
|
||||
* machines.
|
||||
*/
|
||||
|
||||
#ifndef __DRIVERS_INPUT_TSC2007_H
|
||||
#define __DRIVERS_INPUT_TSC2007_H
|
||||
|
||||
@@ -96,16 +101,6 @@
|
||||
* Public Types
|
||||
********************************************************************************************/
|
||||
|
||||
/* This structure describes the sampled TSC2007 data */
|
||||
|
||||
struct tsc2007_sample_s
|
||||
{
|
||||
uint16_t x; /* X position */
|
||||
uint16_t y; /* Y position */
|
||||
uint16_t z1; /* Z1 position */
|
||||
uint16_t z2; /* Z2 position */
|
||||
};
|
||||
|
||||
/********************************************************************************************
|
||||
* Public Function Prototypes
|
||||
********************************************************************************************/
|
||||
|
||||
@@ -452,7 +452,8 @@ volatile int cc1101_interrupt = 0;
|
||||
|
||||
int cc1101_eventcb(int irq, FAR void *context)
|
||||
{
|
||||
cc1101_interrupt++;
|
||||
cc1101_interrupt++;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
+14
-15
@@ -87,7 +87,7 @@
|
||||
* i2c_dev_s instance and will be used with all transfers. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* dev - Device-specific state data
|
||||
* frequency - The I2C frequency requested
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -105,9 +105,9 @@
|
||||
* i2c_dev_s instance and will be used with all transfers. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* dev - Device-specific state data
|
||||
* address - The I2C slave address
|
||||
* nbits - The number of address bits provided (7 or 10)
|
||||
* nbits - The number of address bits provided (7 or 10)
|
||||
*
|
||||
* Returned Value:
|
||||
* Returns OK on success; a negated errno on failure.
|
||||
@@ -129,10 +129,10 @@
|
||||
* to handle reads and writes from a master.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* dev - Device-specific state data
|
||||
* address - Our own slave address; If it is 0x00, then the device driver
|
||||
* listens to general call
|
||||
* nbits - The number of address bits provided (7 or 10)
|
||||
* nbits - The number of address bits provided (7 or 10)
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on valid address and if the same address has not been assigned
|
||||
@@ -152,7 +152,7 @@
|
||||
* and pend until this write completes. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to the read-only buffer of data to be written to device
|
||||
* buflen - The number of bytes to send from the buffer
|
||||
*
|
||||
@@ -173,7 +173,7 @@
|
||||
* and pend until this read completes. Required.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* dev - Device-specific state data
|
||||
* buffer - A pointer to a buffer of data to receive the data from the device
|
||||
* buflen - The requested number of bytes to be read
|
||||
*
|
||||
@@ -193,7 +193,7 @@
|
||||
* It provides a convenient wrapper to the transfer function.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* dev - Device-specific state data
|
||||
* wbuffer - A pointer to the read-only buffer of data to be written to device
|
||||
* wbuflen - The number of bytes to send from the buffer
|
||||
* rbuffer - A pointer to a buffer of data to receive the data from the device
|
||||
@@ -216,8 +216,8 @@
|
||||
* will be serialized and pend until this read completes. Optional.
|
||||
*
|
||||
* Input Parameters:
|
||||
* dev - Device-specific state data
|
||||
* msgs - A pointer to a set of message descriptors
|
||||
* dev - Device-specific state data
|
||||
* msgs - A pointer to a set of message descriptors
|
||||
* msgcount - The number of transfers to perform
|
||||
*
|
||||
* Returned Value:
|
||||
@@ -261,10 +261,10 @@ struct i2c_ops_s
|
||||
|
||||
struct i2c_msg_s
|
||||
{
|
||||
uint16_t addr; /* Slave address */
|
||||
uint16_t flags; /* See I2C_M_* definitions */
|
||||
uint8_t *buffer;
|
||||
int length;
|
||||
uint16_t addr; /* Slave address */
|
||||
uint16_t flags; /* See I2C_M_* definitions */
|
||||
uint8_t *buffer;
|
||||
int length;
|
||||
};
|
||||
|
||||
/* I2C private data. This structure only defines the initial fields of the
|
||||
@@ -308,7 +308,6 @@ extern "C" {
|
||||
|
||||
EXTERN FAR struct i2c_dev_s *up_i2cinitialize(int port);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Name: up_i2cuninitialize
|
||||
*
|
||||
|
||||
@@ -38,6 +38,11 @@
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/* The TSC2007 is an analog interface circuit for a human interface touch
|
||||
* screen device. All peripheral functions are controlled through the command
|
||||
* byte and onboard state machines.
|
||||
*/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_INPUT_TSC2007_H
|
||||
#define __INCLUDE_NUTTX_INPUT_TSC2007_H
|
||||
|
||||
@@ -85,7 +90,9 @@
|
||||
* of the TSB2007 and provides some board-specific hooks.
|
||||
*
|
||||
* Memory for this structure is provided by the caller. It is not copied
|
||||
* by the driver and is presumed to persist while the driver is active.
|
||||
* by the driver and is presumed to persist while the driver is active. The
|
||||
* memory must be writable because, under certain circumstances, the driver
|
||||
* may modify frequency or X plate resistance values.
|
||||
*/
|
||||
|
||||
struct tsc2007_config_s
|
||||
@@ -93,15 +100,31 @@ struct tsc2007_config_s
|
||||
/* Device characterization */
|
||||
|
||||
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
|
||||
uint16_t caldata; /* Calibrated X plate resistance data */
|
||||
uint16_t rxplate; /* Calibrated X plate resistance */
|
||||
uint32_t frequency; /* I2C frequency */
|
||||
|
||||
/* IRQ/GPIO access callbacks */
|
||||
/* If multiple TSC2007 devices are supported, then an IRQ number must
|
||||
* be provided for each so that their interrupts can be distinguished.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_TSC2007_MULTIPLE
|
||||
int irq; /* IRQ number received by interrupt handler. */
|
||||
#endif
|
||||
|
||||
/* IRQ/GPIO access callbacks. These operations all hidden behind
|
||||
* callbacks to isolate the TSC2007 driver from differences in GPIO
|
||||
* interrupt handling by varying boards and MCUs.
|
||||
*
|
||||
* attach - Attach the TSC2007 interrupt handler to the GPIO interrupt
|
||||
* enable - Enable or disable the GPIO interrupt
|
||||
* clear - Acknowledge/clear any pending GPIO interrupt
|
||||
* pendown - Return the state of the pen down GPIO input
|
||||
*/
|
||||
|
||||
int (*attach)(FAR struct tsc2007_config_s *state, xcpt_t isr);
|
||||
int (*enable)(FAR struct tsc2007_config_s *state, bool enable);
|
||||
int (*clear)(FAR struct tsc2007_config_s *state);
|
||||
int (*pendown)(FAR struct tsc2007_config_s *state);
|
||||
void (*enable)(FAR struct tsc2007_config_s *state, bool enable);
|
||||
void (*clear)(FAR struct tsc2007_config_s *state);
|
||||
bool (*pendown)(FAR struct tsc2007_config_s *state);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/wqueue.h
|
||||
*
|
||||
* Copyright (C) 2009 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
Reference in New Issue
Block a user