diff options
| author | Tectu <joel@unormal.org> | 2013-03-24 22:22:15 -0700 | 
|---|---|---|
| committer | Tectu <joel@unormal.org> | 2013-03-24 22:22:15 -0700 | 
| commit | 2a00dd667df1fec0692d21ca2ef1001dbf9589ef (patch) | |
| tree | a2e06c70b4988c4b4317c3c8857c71742a5dd726 | |
| parent | a309a1d19f4e16d1c646b9750a7c9d754ddcf1e8 (diff) | |
| parent | dd1eb6c63d12efb1896885eff7f0ac5d9809bff1 (diff) | |
| download | uGFX-2a00dd667df1fec0692d21ca2ef1001dbf9589ef.tar.gz uGFX-2a00dd667df1fec0692d21ca2ef1001dbf9589ef.tar.bz2 uGFX-2a00dd667df1fec0692d21ca2ef1001dbf9589ef.zip | |
Merge pull request #48 from resset/master
STMPE811: working reading, writing and interrupt
5 files changed, 88 insertions, 71 deletions
| diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index bdae310e..bfdc964b 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -37,12 +37,19 @@  #include "ginput/lld/mouse.h"
 +#if defined(GINPUT_MOUSE_USE_CUSTOM_BOARD) && GINPUT_MOUSE_USE_CUSTOM_BOARD
 +	#include "ginput_lld_mouse_board.h"
 +#elif defined(BOARD_EMBEST_DMSTF4BB)
  	#include "ginput_lld_mouse_board_embest_dmstf4bb.h"
 +#else
 +	#include "ginput_lld_mouse_board_example.h"
 +#endif
  static coord_t lastx, lasty, lastz;
  /* set the active window of the stmpe811. bl is bottom left, tr is top right */
 -static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_t tr_y) {
 +static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_t tr_y)
 +{
  	write_reg(STMPE811_REG_WDW_TR_X, 2, tr_x);
  	write_reg(STMPE811_REG_WDW_TR_Y, 2, tr_y);
  	write_reg(STMPE811_REG_WDW_BL_X, 2, bl_x);
 @@ -54,21 +61,22 @@ static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_   *
   * @notapi
   */
 -void ginput_lld_mouse_init(void) {
 +void ginput_lld_mouse_init(void)
 +{
  	init_board();
  	write_reg(STMPE811_REG_SYS_CTRL1,		1, 0x02);	// Software chip reset
 -	write_reg(STMPE811_REG_SYS_CTRL2,		1, 0x0C);	// Temp. sensor clock off, GPIO clock off, touch clock on, ADC clock on
 -	write_reg(STMPE811_REG_INT_EN,			1, 0x03);	// Interrupt on INT pin when FIFO is equal or above threshold value OR touch is detected
 -	write_reg(STMPE811_REG_ADC_CTRL1,		1, 0x48);	// ADC conversion time = 80 clock ticks, 12-bit ADC, internaal voltage refernce
 +	chThdSleepMilliseconds(10);
 +	write_reg(STMPE811_REG_SYS_CTRL2,		1, 0x0C);	// Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on
 +	write_reg(STMPE811_REG_INT_EN,			1, 0x01);	// Interrupt on INT pin when FIFO is equal or above threshold value OR touch is detected
 +	write_reg(STMPE811_REG_ADC_CTRL1,		1, 0x48);	// ADC conversion time = 80 clock ticks, 12-bit ADC, internaal voltage refernce
  	chThdSleepMilliseconds(2);
  	write_reg(STMPE811_REG_ADC_CTRL2,		1, 0x01);	// ADC speed 3.25MHz
  	write_reg(STMPE811_REG_GPIO_AF,			1, 0x00);	// GPIO alternate function - OFF
 -	// @TODO: decide which value should STMPE811_REG_TSC_CFG have - either 0x9A or from comment;)
 -	write_reg(STMPE811_REG_TSC_CFG,			1, 0x9A);	// Averaging 4, Touch detect delay 1ms, Panel driver settling time 1ms
 -	write_reg(STMPE811_REG_FIFO_TH,			1, 0x01);	// FIFO threshold =1
 +	write_reg(STMPE811_REG_TSC_CFG,			1, 0x9A);	// Averaging 4, Touch detect delay 500 us, Panel driver settling time 500 us
 +	write_reg(STMPE811_REG_FIFO_TH,			1, 0x01);	// FIFO threshold = 1
  	write_reg(STMPE811_REG_FIFO_STA,		1, 0x01);	// FIFO reset enable
  	write_reg(STMPE811_REG_FIFO_STA,		1, 0x00);	// FIFO reset disable
  	write_reg(STMPE811_REG_TSC_FRACT_XYZ,	1, 0x07);	// Z axis data format
 @@ -92,11 +100,13 @@ void ginput_lld_mouse_init(void) {   *
   * @notapi
   */
 -void ginput_lld_mouse_get_reading(MouseReading *pt) {
 +void ginput_lld_mouse_get_reading(MouseReading *pt)
 +{
  	uint16_t buf;
 +	uint8_t int_status;
 -	// if not touched, return the previous results
 -	if(!getpin_pressed()) {
 +	// If not touched, return the previous results
 +	if (!getpin_pressed()) {
  		pt->x = lastx;
  		pt->y = lasty;
  		pt->z = 0;
 @@ -104,25 +114,32 @@ void ginput_lld_mouse_get_reading(MouseReading *pt) {  		return;
  	}
 -	/* Get the X value */
 -	buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
 -	lastx = (coord_t)(buf);
 +	// Find out what caused an interrupt
 +	int_status = read_reg(STMPE811_REG_INT_STA, 1);
 +
 +	// If it is TOUCH interrupt, clear it and go on
 +	if (int_status & 0x01) {
 +	   write_reg(STMPE811_REG_INT_STA, 1, 0x01);
 -	/* Get the Y value */
 -	buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2);
 -	lasty = (coord_t)(buf);
 +		/* Get the X value */
 +		buf = read_reg(STMPE811_REG_TSC_DATA_X, 2);
 +		lastx = (coord_t)(buf);
 -	/* Get the Z value */
 -	buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1);
 -	lastz = (buf & 0x00FF);
 +		/* Get the Y value */
 +		buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2);
 +		lasty = (coord_t)(buf);
 -	// Return the results
 -	pt->x = lastx;
 -	pt->y = lasty;
 -	pt->z = 100;
 -	pt->buttons = GINPUT_TOUCH_PRESSED;
 +		/* Get the Z value */
 +		buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1);
 +		lastz = (buf & 0x00FF);
 +
 +		// Return the results. ADC gives values from 0 to 2^12
 +		pt->x = lastx / 13;
 +		pt->y = lasty / 17;
 +		pt->z = 100;
 +		pt->buttons = GINPUT_TOUCH_PRESSED;
 +	}
  }
  #endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */
  /** @} */
 -
 diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h index 6808196d..f14714f1 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h @@ -41,7 +41,8 @@ static const I2CConfig i2ccfg = {   *
   * @notapi
   */
 -static void init_board(void) {
 +static void init_board(void)
 +{
  	palSetPadMode(GPIOC, 13, PAL_MODE_INPUT | PAL_STM32_PUDR_FLOATING);			/* TP IRQ */
  	palSetPadMode(GPIOB, 8, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);	/* SCL */
  	palSetPadMode(GPIOB, 9, PAL_MODE_ALTERNATE(4) | PAL_STM32_OTYPE_OPENDRAIN);	/* SDA */
 @@ -50,8 +51,8 @@ static void init_board(void) {  }
  /**
 - * @brief   Check whether the surface is currently touched
 - * @return	TRUE if the surface is currently touched
 + * @brief   Check whether an interrupt is raised
 + * @return	TRUE if there is an interrupt signal present
   *
   * @notapi
   */
 @@ -68,21 +69,21 @@ static inline bool_t getpin_pressed(void) {   *
   * @notapi
   */
 -static void write_reg(uint8_t reg, uint8_t n, uint16_t val) {
 -	uint8_t txbuf[2];
 +static void write_reg(uint8_t reg, uint8_t n, uint16_t val)
 +{
 +	uint8_t txbuf[3];
  	i2cAcquireBus(&I2CD1);
 -	
 +
  	txbuf[0] = reg;
 -	i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, NULL, 0, MS2ST(STMPE811_TIMEOUT));
 -
 -	if(n == 1) {
 -		txbuf[0] = val;
 -		i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, NULL, 0, MS2ST(STMPE811_TIMEOUT));
 -	} else if(n == 2) {
 -		txbuf[0] = ((val & 0xFF00) >> 8);
 -		txbuf[1] = (val & 0x00FF);
 +
 +	if (n == 1) {
 +		txbuf[1] = val;
  		i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, NULL, 0, MS2ST(STMPE811_TIMEOUT));
 +	} else if (n == 2) {
 +		txbuf[1] = ((val & 0xFF00) >> 8);
 +		txbuf[2] = (val & 0x00FF);
 +		i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 3, NULL, 0, MS2ST(STMPE811_TIMEOUT));
  	}
  	i2cReleaseBus(&I2CD1);
 @@ -94,9 +95,12 @@ static void write_reg(uint8_t reg, uint8_t n, uint16_t val) {   * @param[in] reg	The register address
   * @param[in] n		The amount of bytes (one or two)
   *
 + * @return Data read from device (one byte or two depending on n param)
 + *
   * @notapi
   */
 -static uint16_t read_reg(uint8_t reg, uint8_t n) {
 +static uint16_t read_reg(uint8_t reg, uint8_t n)
 +{
  	uint8_t txbuf[1], rxbuf[2];
  	uint16_t ret;
 @@ -106,13 +110,11 @@ static uint16_t read_reg(uint8_t reg, uint8_t n) {  	i2cAcquireBus(&I2CD1);
  	txbuf[0] = reg;
 -	i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, 0, MS2ST(STMPE811_TIMEOUT));
 +	i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT));
 -	if(n == 1) {
 -		i2cMasterReceiveTimeout(&I2CD1, STMPE811_ADDR, rxbuf, 1, MS2ST(STMPE811_TIMEOUT));
 +	if (n == 1) {
  		ret = rxbuf[0];
 -	} else if(n == 2) {
 -		i2cMasterReceiveTimeout(&I2CD1, STMPE811_ADDR, rxbuf, 2, MS2ST(STMPE811_TIMEOUT));
 +	} else if (n == 2) {
  		ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF));
  	}
 diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_example.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_example.h index fbedcb60..d2a62733 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_example.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_example.h @@ -35,53 +35,53 @@   *
   * @notapi
   */
 -static inline void init_board(void) {
 +static void init_board(void)
 +{
  	/* Code here */
  	#error "ginputSTMPE811: You must supply a definition for init_board for your board"
  }
  /**
 - * @brief   Check whether the surface is currently touched
 - * @return	TRUE if the surface is currently touched
 + * @brief   Check whether an interrupt is raised
 + * @return	TRUE if there is an interrupt signal present
   *
   * @notapi
   */
 -static inline bool_t getpin_pressed(void) {
 +static inline bool_t getpin_pressed(void)
 +{
  	/* Code here */
  	#error "ginputSTMPE811: You must supply a definition for getpin_pressed for your board"
  }
  /**
 - * @brief   Aquire the bus ready for readings
 + * @brief	Write a value into a certain register
   *
 - * @notapi
 - */
 -static inline void aquire_bus(void) {
 -	/* Code here */
 -	#error "ginputSTMPE811: You must supply a definition for aquire_bus for your board"
 -}
 -
 -/**
 - * @brief   Release the bus after readings
 + * @param[in] reg	The register address
 + * @param[in] n		The amount of bytes (one or two)
 + * @param[in] val	The value
   *
   * @notapi
   */
 -static inline void release_bus(void) {
 +static void write_reg(uint8_t reg, uint8_t n, uint16_t val)
 +{
  	/* Code here */
 -	#error "ginputSTMPE811: You must supply a definition for release_bus for your board"
 +	#error "ginputSTMPE811: You must supply a definition for write_reg for your board"
  }
  /**
 - * @brief   Read a value from touch controller
 - * @return	The value read from the controller
 + * @brief	Read the value of a certain register
 + *
 + * @param[in] reg	The register address
 + * @param[in] n		The amount of bytes (one or two)
   *
 - * params[in] port	The controller port to read.
 + * @return Data read from device (one byte or two depending on n param)
   *
   * @notapi
   */
 -static inline uint16_t read_value(uint16_t port) {
 +static uint16_t read_reg(uint8_t reg, uint8_t n)
 +{
  	/* Code here */
 -	#error "ginputSTMPE811: You must supply a definition for read_value for your board"
 +	#error "ginputSTMPE811: You must supply a definition for read_reg for your board"
  }
  #endif /* _GINPUT_LLD_MOUSE_BOARD_H */
 diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h index 76224198..398fd7fb 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h @@ -31,10 +31,10 @@  #define _LLD_GINPUT_MOUSE_CONFIG_H
  #define GINPUT_MOUSE_EVENT_TYPE					GEVENT_TOUCH
 -#define GINPUT_MOUSE_NEED_CALIBRATION			TRUE
 +#define GINPUT_MOUSE_NEED_CALIBRATION			FALSE
  #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE	FALSE
  #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR		5
 -#define GINPUT_MOUSE_READ_CYCLES				4
 +#define GINPUT_MOUSE_READ_CYCLES				1//4
  #define GINPUT_MOUSE_POLL_PERIOD				25
  #define GINPUT_MOUSE_MAX_CLICK_JITTER			10
  #define GINPUT_MOUSE_MAX_MOVE_JITTER			2
 @@ -42,4 +42,3 @@  #endif /* _LLD_GINPUT_MOUSE_CONFIG_H */
  /** @} */
 -
 diff --git a/drivers/ginput/touch/STMPE811/stmpe811.h b/drivers/ginput/touch/STMPE811/stmpe811.h index 9da8e1df..401734a4 100644 --- a/drivers/ginput/touch/STMPE811/stmpe811.h +++ b/drivers/ginput/touch/STMPE811/stmpe811.h @@ -102,4 +102,3 @@  #endif /* _STMPE811_H */  /** @} */ - | 
