From 38e55c392163c564121d344db6325e6d4780a406 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Tue, 19 Mar 2013 22:59:04 +0100 Subject: [PATCH 01/12] STMPE811 - not tested yet --- .../ginput/touch/STMPE811/ginput_lld_mouse.c | 97 ++++++++----------- .../ginput_lld_mouse_board_embest_dmstf4bb.h | 73 +++++++++----- drivers/ginput/touch/STMPE811/stmpe811.h | 6 +- 3 files changed, 95 insertions(+), 81 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index bacb1f1f..b2f7ba76 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -37,38 +37,16 @@ #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 uint16_t sampleBuf[7]; -static coord_t lastx, lasty; +static coord_t lastx, lasty, lastz; -/** - * @brief 7-point median filtering code for touch samples - * - * @note This is an internally used routine only. - * - * @notapi - */ -static void filter(void) { - uint16_t temp; - int i,j; - - for(i = 0; i < 4; i++) { - for(j = i; j < 7; j++) { - if(sampleBuf[i] > sampleBuf[j]) { - /* Swap the values */ - temp = sampleBuf[i]; - sampleBuf[i] = sampleBuf[j]; - sampleBuf[j] = temp; - } - } - } +/* 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) { + 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); + write_reg(STMPE811_REG_WDW_BL_Y, 2, bl_y); } /** @@ -78,6 +56,25 @@ static void filter(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, 0x04); // temp. sensor clock on, GPIO clock off, touch clock on, ADC clock on + write_reg(STMPE811_REG_INT_EN, 1, 0x03); //0x03 + write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x49); //ADC conversion time = 80 clock ticks, 12-bit ADC, internacl voltage refernce + + chThdSleepMicroseconds(1000); + + write_reg(STMPE811_REG_ADC_CTRL2, 1, 0x01); //ADC speed 3.25MHz + write_reg(STMPE811_REG_GPIO_AF, 1, 0x00); //GPIO alternate function - OFF + write_reg(STMPE811_REG_TSC_CFG, 1, 0xA3); //avaraging 4, Touch detect delay 1ms, Panel driver settling time 1ms + write_reg(STMPE811_REG_FIFO_TH, 1, 0x01); //FIFO trashold =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 + write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); //50mA touchscreen line current + write_reg(STMPE811_REG_TSC_CTRL, 1, 0x03); //X&Y only, TSC enable + write_reg(STMPE811_REG_INT_STA, 1, 0xFF); //clear all interrupts + write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); //level interrupt, enable intrrupts } /** @@ -95,44 +92,29 @@ void ginput_lld_mouse_init(void) { * @notapi */ void ginput_lld_mouse_get_reading(MouseReading *pt) { - uint16_t i; + uint16_t buf; - // If touch-off 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; pt->buttons = 0; return; } - - // Read the port to get the touch settings - aquire_bus(); - /* Get the X value - * Discard the first conversion - very noisy and keep the ADC on hereafter - * till we are done with the sampling. Note that PENIRQ is disabled while reading. - * Finally switch on PENIRQ once again - perform a dummy read. - * Once we have the readings, find the medium using our filter function - */ - read_value(0xD1); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_value(0xD1); - read_value(0xD0); - filter(); - lastx = (coord_t)sampleBuf[3]; + /* Get the X value */ + buf = read_reg(STMPE811_REG_TSC_DATA_X, 2); + lastx = (coord_t)(buf); - /* Get the Y value using the same process as above */ - read_value(0x91); - for(i = 0; i < 7; i++) - sampleBuf[i] = read_value(0x91); - read_value(0x90); - filter(); - lasty = (coord_t)sampleBuf[3]; + /* Get the Y value */ + buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2); + lasty = (coord_t)(buf); + + /* Get the Z value */ + buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1); + lastz = (buf & 0x00FF); - // Release the bus - release_bus(); - // Return the results pt->x = lastx; pt->y = lasty; @@ -142,3 +124,4 @@ void ginput_lld_mouse_get_reading(MouseReading *pt) { #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 fa43f4ac..490b8dca 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 @@ -30,7 +30,7 @@ #ifndef _GINPUT_LLD_MOUSE_BOARD_H #define _GINPUT_LLD_MOUSE_BOARD_H -static const I2CConfig i2ccfg2 = { +static const I2CConfig i2ccfg = { OPMODE_I2C, 400000, FAST_DUTY_CYCLE_2, @@ -41,12 +41,12 @@ static const I2CConfig i2ccfg2 = { * * @notapi */ -static inline void init_board(void) { - palSetPadMode(GPIOC, 13, PAL_MODE_INPUT); /* TP IRQ */ - palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(4)); /* I2C2 SCL */ - palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(4)); /* I2C2 SDA */ +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 */ - i2cStart(&I2CD2, &i2ccfg2); + i2cStart(&I2CD1, &i2ccfg); } /** @@ -60,34 +60,61 @@ static inline bool_t getpin_pressed(void) { } /** - * @brief Aquire the bus ready for readings + * @brief Write a value into a certain register + * + * @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 aquire_bus(void) { - i2cAcquireBus(&I2CD2); -} +static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { + uint8_t txbuf[1]; -/** - * @brief Release the bus after readings - * - * @notapi - */ -static inline void release_bus(void) { - i2cReleaseBus(&I2CD2); -} + 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 == 3) { + txbuf[0] = ((val & 0xFF00) >> 8); + txbuf[1] = (val & 0x00FF); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, NULL, 0, MS2ST(STMPE811_TIMEOUT)); + } + + i2cReleaseBus(&I2CD1); +} + /** - * @brief Read a value from touch controller - * @return The value read from the controller + * @brief Read the value of a certain register * - * params[in] port The controller port to read. + * @param[in] reg The register address + * @param[in] n The amount of bytes (one or two) * * @notapi */ -static inline uint16_t read_value(uint16_t port) { - #error "STMPE811: Implement this driver first!" +static uint16_t read_reg(uint8_t reg, uint8_t n) { + uint8_t txbuf[1], rxbuf[2]; + uint16_t ret; + + i2cAcquireBus(&I2CD1); + + txbuf[0] = reg; + i2cMasterTransmitTimeout(&I2CD1, 0x82 >> 1, txbuf, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); + + i2cReleaseBus(&I2CD1); + + if(n == 1) + ret = rxbuf[0]; + else if (n == 2) + ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); + + return ret; } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ /** @} */ + diff --git a/drivers/ginput/touch/STMPE811/stmpe811.h b/drivers/ginput/touch/STMPE811/stmpe811.h index 8396a844..9da8e1df 100644 --- a/drivers/ginput/touch/STMPE811/stmpe811.h +++ b/drivers/ginput/touch/STMPE811/stmpe811.h @@ -29,7 +29,11 @@ #ifndef _STMPE811_H #define _STMPE811_H -/* STMPE811 registers */ +// Slave address +#define STMPE811_ADDR (0x82 >> 1) + +// Maximum timeout +#define STMPE811_TIMEOUT 0x3000 // Identification registers #define STMPE811_REG_CHP_ID 0x00 // 16-bit From 5062603188f9d107ff460eb6485430c153126706 Mon Sep 17 00:00:00 2001 From: Mateusz Tomaszkiewicz Date: Wed, 20 Mar 2013 02:41:15 +0100 Subject: [PATCH 02/12] STMPE811: reading registers over I2C - Reading works. - Some other cleanups. Driver is not usable yet. --- .../ginput/touch/STMPE811/ginput_lld_mouse.c | 33 ++++++++++--------- .../ginput_lld_mouse_board_embest_dmstf4bb.h | 21 +++++++----- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index b2f7ba76..bdae310e 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -57,24 +57,25 @@ static void setActiveWindow(uint16_t bl_x, uint16_t bl_y, uint16_t tr_x, uint16_ 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, 0x04); // temp. sensor clock on, GPIO clock off, touch clock on, ADC clock on - write_reg(STMPE811_REG_INT_EN, 1, 0x03); //0x03 - write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x49); //ADC conversion time = 80 clock ticks, 12-bit ADC, internacl voltage refernce + 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 - chThdSleepMicroseconds(1000); + 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 - write_reg(STMPE811_REG_TSC_CFG, 1, 0xA3); //avaraging 4, Touch detect delay 1ms, Panel driver settling time 1ms - write_reg(STMPE811_REG_FIFO_TH, 1, 0x01); //FIFO trashold =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 - write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); //50mA touchscreen line current - write_reg(STMPE811_REG_TSC_CTRL, 1, 0x03); //X&Y only, TSC enable - write_reg(STMPE811_REG_INT_STA, 1, 0xFF); //clear all interrupts - write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); //level interrupt, enable intrrupts + 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_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 + write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); // 50mA touchscreen line current + write_reg(STMPE811_REG_TSC_CTRL, 1, 0x03); // X&Y only, TSC enable + write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts + write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts } /** 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 490b8dca..6808196d 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 @@ -69,7 +69,7 @@ static inline bool_t getpin_pressed(void) { * @notapi */ static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { - uint8_t txbuf[1]; + uint8_t txbuf[2]; i2cAcquireBus(&I2CD1); @@ -79,7 +79,7 @@ static void write_reg(uint8_t reg, uint8_t n, uint16_t val) { if(n == 1) { txbuf[0] = val; i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, NULL, 0, MS2ST(STMPE811_TIMEOUT)); - } else if(n == 3) { + } else if(n == 2) { txbuf[0] = ((val & 0xFF00) >> 8); txbuf[1] = (val & 0x00FF); i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 2, NULL, 0, MS2ST(STMPE811_TIMEOUT)); @@ -100,21 +100,26 @@ static uint16_t read_reg(uint8_t reg, uint8_t n) { uint8_t txbuf[1], rxbuf[2]; uint16_t ret; + rxbuf[0] = 0; + rxbuf[1] = 0; + i2cAcquireBus(&I2CD1); txbuf[0] = reg; - i2cMasterTransmitTimeout(&I2CD1, 0x82 >> 1, txbuf, 1, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); - - i2cReleaseBus(&I2CD1); + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, 0, MS2ST(STMPE811_TIMEOUT)); - if(n == 1) + if(n == 1) { + i2cMasterReceiveTimeout(&I2CD1, STMPE811_ADDR, rxbuf, 1, MS2ST(STMPE811_TIMEOUT)); ret = rxbuf[0]; - else if (n == 2) + } else if(n == 2) { + i2cMasterReceiveTimeout(&I2CD1, STMPE811_ADDR, rxbuf, 2, MS2ST(STMPE811_TIMEOUT)); ret = ((rxbuf[0] << 8) | (rxbuf[1] & 0xFF)); + } + + i2cReleaseBus(&I2CD1); return ret; } #endif /* _GINPUT_LLD_MOUSE_BOARD_H */ /** @} */ - From 15d76cb5fc61de83f5ff2e2d86911d18c6735507 Mon Sep 17 00:00:00 2001 From: Mateusz Tomaszkiewicz Date: Wed, 20 Mar 2013 22:15:18 +0100 Subject: [PATCH 03/12] SSD1289 SSD2119: fixed warning messages Few type castings in order to suppress warnings (-Wsign-compare): "comparison between signed and unsigned integer expressions" "signed and unsigned type in conditional expression" --- drivers/gdisp/SSD1289/gdisp_lld.c | 8 ++++---- drivers/gdisp/SSD2119/gdisp_lld.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/gdisp/SSD1289/gdisp_lld.c b/drivers/gdisp/SSD1289/gdisp_lld.c index e2dd79e0..f6531f2c 100644 --- a/drivers/gdisp/SSD1289/gdisp_lld.c +++ b/drivers/gdisp/SSD1289/gdisp_lld.c @@ -429,7 +429,7 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { abslines = lines < 0 ? -lines : lines; acquire_bus(); - if (abslines >= cy) { + if ((coord_t)abslines >= cy) { abslines = cy; gap = 0; } else { @@ -447,20 +447,20 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { set_viewport(x, row0, cx, 1); stream_start(); j = read_data(); // dummy read - for (j = 0; j < cx; j++) + for (j = 0; (coord_t)j < cx; j++) buf[j] = read_data(); stream_stop(); set_viewport(x, row1, cx, 1); stream_start(); - for (j = 0; j < cx; j++) + for (j = 0; (coord_t)j < cx; j++) write_data(buf[j]); stream_stop(); } } /* fill the remaining gap */ - set_viewport(x, lines > 0 ? (y+gap) : y, cx, abslines); + set_viewport(x, lines > 0 ? (y+(coord_t)gap) : y, cx, abslines); stream_start(); gap = cx*abslines; for(i = 0; i < gap; i++) write_data(bgcolor); diff --git a/drivers/gdisp/SSD2119/gdisp_lld.c b/drivers/gdisp/SSD2119/gdisp_lld.c index b8884e0f..a7ad7b1a 100644 --- a/drivers/gdisp/SSD2119/gdisp_lld.c +++ b/drivers/gdisp/SSD2119/gdisp_lld.c @@ -472,7 +472,7 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { abslines = lines < 0 ? -lines : lines; acquire_bus(); - if (abslines >= cy) { + if ((coord_t)abslines >= cy) { abslines = cy; gap = 0; } else { @@ -490,20 +490,20 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { set_viewport(x, row0, cx, 1); stream_start(); j = read_data(); // dummy read - for (j = 0; j < cx; j++) + for (j = 0; (coord_t)j < cx; j++) buf[j] = read_data(); stream_stop(); set_viewport(x, row1, cx, 1); stream_start(); - for (j = 0; j < cx; j++) + for (j = 0; (coord_t)j < cx; j++) write_data(buf[j]); stream_stop(); } } /* fill the remaining gap */ - set_viewport(x, lines > 0 ? (y+gap) : y, cx, abslines); + set_viewport(x, lines > 0 ? (y+(coord_t)gap) : y, cx, abslines); stream_start(); gap = cx*abslines; for(i = 0; i < gap; i++) write_data(bgcolor); From dd1eb6c63d12efb1896885eff7f0ac5d9809bff1 Mon Sep 17 00:00:00 2001 From: Mateusz Tomaszkiewicz Date: Mon, 25 Mar 2013 01:10:32 +0100 Subject: [PATCH 04/12] STMPE811: working reading, writing and interrupt - Slightly changed rading and writing routines. - Added delay after reset of STMPE811 in initialization code. - STMPE811 "interrupt service routine" - Comments, formatting etc. - Another commit with unfinished driver. --- .../ginput/touch/STMPE811/ginput_lld_mouse.c | 69 ++++++++++++------- .../ginput_lld_mouse_board_embest_dmstf4bb.h | 42 +++++------ .../STMPE811/ginput_lld_mouse_board_example.h | 46 ++++++------- .../touch/STMPE811/ginput_lld_mouse_config.h | 5 +- drivers/ginput/touch/STMPE811/stmpe811.h | 1 - 5 files changed, 90 insertions(+), 73 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); - /* Get the Y value */ - buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2); - lasty = (coord_t)(buf); + // If it is TOUCH interrupt, clear it and go on + if (int_status & 0x01) { + write_reg(STMPE811_REG_INT_STA, 1, 0x01); - /* Get the Z value */ - buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1); - lastz = (buf & 0x00FF); + /* Get the X value */ + buf = read_reg(STMPE811_REG_TSC_DATA_X, 2); + lastx = (coord_t)(buf); - // Return the results - pt->x = lastx; - pt->y = lasty; - pt->z = 100; - pt->buttons = GINPUT_TOUCH_PRESSED; + /* Get the Y value */ + buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2); + lasty = (coord_t)(buf); + + /* 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); + txbuf[0] = reg; + + 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 + * + * @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 aquire_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 aquire_bus for your board" + #error "ginputSTMPE811: You must supply a definition for write_reg for your board" } /** - * @brief Release the bus after readings + * @brief Read the value of a certain register + * + * @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 inline void release_bus(void) { +static uint16_t read_reg(uint8_t reg, uint8_t n) +{ /* Code here */ - #error "ginputSTMPE811: You must supply a definition for release_bus for your board" -} - -/** - * @brief Read a value from touch controller - * @return The value read from the controller - * - * params[in] port The controller port to read. - * - * @notapi - */ -static inline uint16_t read_value(uint16_t port) { - /* 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 */ /** @} */ - From 2f7b6fc80b89d4ccce19d919b8c2d4a793a3ce98 Mon Sep 17 00:00:00 2001 From: Mateusz Tomaszkiewicz Date: Fri, 29 Mar 2013 01:15:07 +0100 Subject: [PATCH 05/12] STMPE811: attempt to use FIFO Very early version of using FIFO threshold interrupt. --- .../ginput/touch/STMPE811/ginput_lld_mouse.c | 55 ++++++++++++------- .../ginput_lld_mouse_board_embest_dmstf4bb.h | 12 ++++ .../touch/STMPE811/ginput_lld_mouse_config.h | 4 +- drivers/ginput/touch/STMPE811/stmpe811.h | 1 + 4 files changed, 49 insertions(+), 23 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index bfdc964b..4f648a78 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -69,19 +69,19 @@ void ginput_lld_mouse_init(void) 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 + write_reg(STMPE811_REG_INT_EN, 1, 0x02); // 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, internal 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 - 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_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 write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); // 50mA touchscreen line current - write_reg(STMPE811_REG_TSC_CTRL, 1, 0x03); // X&Y only, TSC enable + write_reg(STMPE811_REG_TSC_CTRL, 1, 0x01); // X&Y&Z, TSC enable write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts } @@ -102,7 +102,7 @@ void ginput_lld_mouse_init(void) */ void ginput_lld_mouse_get_reading(MouseReading *pt) { - uint16_t buf; + //uint16_t buf; uint8_t int_status; // If not touched, return the previous results @@ -118,26 +118,39 @@ void ginput_lld_mouse_get_reading(MouseReading *pt) 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); + if (int_status & 0x02) { - /* Get the X value */ - buf = read_reg(STMPE811_REG_TSC_DATA_X, 2); - lastx = (coord_t)(buf); + uint8_t size = 0; + size = read_reg(STMPE811_REG_FIFO_SIZE, 1); - /* Get the Y value */ - buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2); - lasty = (coord_t)(buf); + if (size) { + uint8_t buffer[size * 4]; + read_reg_n(STMPE811_REG_TSC_DATA_AI, size * 4, buffer); - /* Get the Z value */ - buf = read_reg(STMPE811_REG_TSC_DATA_Z, 1); - lastz = (buf & 0x00FF); + lastx = (coord_t)((buffer[0] << 4) | (buffer[1] >> 4)); + lasty = (coord_t)(((buffer[1] & 0x0F) << 8) | buffer[2]); + lastz = (coord_t)buffer[3]; - // 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; + /* Get the X value */ + //buf = read_reg(STMPE811_REG_TSC_DATA_X, 2); + //lastx = (coord_t)(buf); + + /* Get the Y value */ + //buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2); + //lasty = (coord_t)(buf); + + /* 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 = 320 - lastx / 13; + pt->y = lasty / 17; + pt->z = lastz; + pt->buttons = GINPUT_TOUCH_PRESSED; + } + + write_reg(STMPE811_REG_INT_STA, 1, 0x02); } } 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 f14714f1..d7a360cd 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 @@ -123,5 +123,17 @@ static uint16_t read_reg(uint8_t reg, uint8_t n) return ret; } +static void read_reg_n(uint8_t reg, uint8_t n, uint8_t *rxbuf) +{ + uint8_t txbuf[1]; + + i2cAcquireBus(&I2CD1); + + txbuf[0] = reg; + i2cMasterTransmitTimeout(&I2CD1, STMPE811_ADDR, txbuf, 1, rxbuf, n, MS2ST(STMPE811_TIMEOUT)); + + i2cReleaseBus(&I2CD1); +} + #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 398fd7fb..b99b6f14 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 FALSE +#define GINPUT_MOUSE_NEED_CALIBRATION TRUE #define GINPUT_MOUSE_LLD_CALIBRATION_LOADSAVE FALSE #define GINPUT_MOUSE_MAX_CALIBRATION_ERROR 5 -#define GINPUT_MOUSE_READ_CYCLES 1//4 +#define GINPUT_MOUSE_READ_CYCLES 1 #define GINPUT_MOUSE_POLL_PERIOD 25 #define GINPUT_MOUSE_MAX_CLICK_JITTER 10 #define GINPUT_MOUSE_MAX_MOVE_JITTER 2 diff --git a/drivers/ginput/touch/STMPE811/stmpe811.h b/drivers/ginput/touch/STMPE811/stmpe811.h index 401734a4..36101cd4 100644 --- a/drivers/ginput/touch/STMPE811/stmpe811.h +++ b/drivers/ginput/touch/STMPE811/stmpe811.h @@ -92,6 +92,7 @@ #define STMPE811_REG_TSC_DATA_XYZ 0x52 // 32-bit #define STMPE811_REG_TSC_FRACT_XYZ 0x56 #define STMPE811_REG_TSC_DATA 0x57 +#define STMPE811_REG_TSC_DATA_AI 0xD7 #define STMPE811_REG_TSC_I_DRIVE 0x58 #define STMPE811_REG_TSC_SHIELD 0x59 From d6b75429b25bec5f83cd9eb1db21a8337454d5a6 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 29 Mar 2013 18:10:22 +0100 Subject: [PATCH 06/12] STMPE811 - initial --- drivers/gdisp/SSD2119/gdisp_lld.c | 8 - .../ginput/touch/STMPE811/ginput_lld_mouse.c | 341 ++++++++++-------- .../touch/STMPE811/ginput_lld_mouse_config.h | 2 + 3 files changed, 185 insertions(+), 166 deletions(-) diff --git a/drivers/gdisp/SSD2119/gdisp_lld.c b/drivers/gdisp/SSD2119/gdisp_lld.c index a7ad7b1a..9e6fdb4f 100644 --- a/drivers/gdisp/SSD2119/gdisp_lld.c +++ b/drivers/gdisp/SSD2119/gdisp_lld.c @@ -55,15 +55,7 @@ /* Driver local functions. */ /*===========================================================================*/ -#if defined(GDISP_USE_CUSTOM_BOARD) && GDISP_USE_CUSTOM_BOARD - /* Include the user supplied board definitions */ - #include "gdisp_lld_board.h" -#elif defined(BOARD_EMBEST_DMSTF4BB) #include "gdisp_lld_board_embest_dmstf4bb.h" -#else - /* Include the user supplied board definitions */ - #include "gdisp_lld_board.h" -#endif // Some common routines and macros #define write_reg(reg, data) { write_index(reg); write_data(data); } diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index 4f648a78..09360dbc 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -1,158 +1,183 @@ -/* - ChibiOS/GFX - Copyright (C) 2012, 2013 - Joel Bodenmann aka Tectu - - This file is part of ChibiOS/GFX. - - ChibiOS/GFX is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - ChibiOS/GFX is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -/** - * @file drivers/ginput/touch/STMPE811/ginput_lld_mouse.c - * @brief GINPUT Touch low level driver source for the STMPE811. - * - * @defgroup Mouse Mouse - * @ingroup GINPUT - * @{ - */ - -#include "ch.h" -#include "hal.h" -#include "gfx.h" - -#include "stmpe811.h" - -#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ - -#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) -{ - 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); - write_reg(STMPE811_REG_WDW_BL_Y, 2, bl_y); -} - -/** - * @brief Initialise the mouse/touch. - * - * @notapi - */ -void ginput_lld_mouse_init(void) -{ - init_board(); - - write_reg(STMPE811_REG_SYS_CTRL1, 1, 0x02); // Software chip reset - 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, 0x02); // 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, internal 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 - 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 - write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); // 50mA touchscreen line current - write_reg(STMPE811_REG_TSC_CTRL, 1, 0x01); // X&Y&Z, TSC enable - write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts - write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts -} - -/** - * @brief Read the mouse/touch position. - * - * @param[in] pt A pointer to the structure to fill - * - * @note For drivers that don't support returning a position - * when the touch is up (most touch devices), it should - * return the previous position with the new Z value. - * The z value is the pressure for those touch devices - * that support it (-100 to 100 where > 0 is touched) - * or, 0 or 100 for those drivers that don't. - * - * @notapi - */ -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()) { - pt->x = lastx; - pt->y = lasty; - pt->z = 0; - pt->buttons = 0; - return; - } - - // 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 & 0x02) { - - uint8_t size = 0; - size = read_reg(STMPE811_REG_FIFO_SIZE, 1); - - if (size) { - uint8_t buffer[size * 4]; - read_reg_n(STMPE811_REG_TSC_DATA_AI, size * 4, buffer); - - lastx = (coord_t)((buffer[0] << 4) | (buffer[1] >> 4)); - lasty = (coord_t)(((buffer[1] & 0x0F) << 8) | buffer[2]); - lastz = (coord_t)buffer[3]; - - /* Get the X value */ - //buf = read_reg(STMPE811_REG_TSC_DATA_X, 2); - //lastx = (coord_t)(buf); - - /* Get the Y value */ - //buf = read_reg(STMPE811_REG_TSC_DATA_Y, 2); - //lasty = (coord_t)(buf); - - /* 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 = 320 - lastx / 13; - pt->y = lasty / 17; - pt->z = lastz; - pt->buttons = GINPUT_TOUCH_PRESSED; - } - - write_reg(STMPE811_REG_INT_STA, 1, 0x02); - } -} - -#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ -/** @} */ +/* + ChibiOS/GFX - Copyright (C) 2012, 2013 + Joel Bodenmann aka Tectu + + This file is part of ChibiOS/GFX. + + ChibiOS/GFX is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + ChibiOS/GFX is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +/** + * @file drivers/ginput/touch/STMPE811/ginput_lld_mouse.c + * @brief GINPUT Touch low level driver source for the STMPE811. + * + * @defgroup Mouse Mouse + * @ingroup GINPUT + * @{ + */ + +#include "ch.h" +#include "hal.h" +#include "gfx.h" + +#include "stmpe811.h" + +#if (GFX_USE_GINPUT && GINPUT_NEED_MOUSE) /*|| defined(__DOXYGEN__)*/ + +#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_DMST4BB) + #include "ginput_lld_mouse_board_embest_dmstf4bb.h" +#else + #include "ginput_lld_mouse_board_example.h" +#endif + +#ifndef STMP811_NO_GPIO_IRQPIN + #define STMP811_NO_GPIO_IRQPIN FALSE +#endif +#ifndef STMP811_SLOW_CPU + #define STMP811_SLOW_CPU FALSE +#endif + +static coord_t x, y, z; +static uint8_t touched; + +/* 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) +{ + 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); + write_reg(STMPE811_REG_WDW_BL_Y, 2, bl_y); +} + +/** + * @brief Initialise the mouse/touch. + * + * @notapi + */ +void ginput_lld_mouse_init(void) +{ + init_board(); + + write_reg(STMPE811_REG_SYS_CTRL1, 1, 0x02); // Software chip reset + chThdSleepMilliseconds(10); + + write_reg(STMPE811_REG_SYS_CTRL2, 1, 0x0C); // Temperature sensor clock off, GPIO clock off, touch clock on, ADC clock on +#if STMP811_NO_GPIO_IRQPIN + write_reg(STMPE811_REG_INT_EN, 1, 0x00); // Interrupt on INT pin when touch is detected +#else + write_reg(STMPE811_REG_INT_EN, 1, 0x01); // Interrupt on INT pin when touch is detected +#endif + write_reg(STMPE811_REG_ADC_CTRL1, 1, 0x48); // ADC conversion time = 80 clock ticks, 12-bit ADC, internal 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 + 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, 0x40); // FIFO threshold = 64 + 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 + write_reg(STMPE811_REG_TSC_I_DRIVE, 1, 0x01); // 50mA touchscreen line current + write_reg(STMPE811_REG_TSC_CTRL, 1, 0x00); // X&Y&Z + write_reg(STMPE811_REG_TSC_CTRL, 1, 0x01); // X&Y&Z, TSC enable + write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // Clear all interrupts +#if !STMP811_NO_GPIO_IRQPIN + touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; +#endif + write_reg(STMPE811_REG_INT_CTRL, 1, 0x01); // Level interrupt, enable intrrupts +} + +/** + * @brief Read the mouse/touch position. + * + * @param[in] pt A pointer to the structure to fill + * + * @note For drivers that don't support returning a position + * when the touch is up (most touch devices), it should + * return the previous position with the new Z value. + * The z value is the pressure for those touch devices + * that support it (-100 to 100 where > 0 is touched) + * or, 0 or 100 for those drivers that don't. + * + * @notapi + */ +void ginput_lld_mouse_get_reading(MouseReading *pt) +{ + bool_t clearfifo; // Do we need to clear the FIFO + +#if STMP811_NO_GPIO_IRQPIN + // Poll to get the touched status + uint8_t last_touched; + + last_touched = touched; + touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; + clearfifo = (touched != last_touched); +#else + // Check if the touch controller IRQ pin has gone off + clearfifo = false; + if(getpin_pressed()) { // please rename this to getpin_irq + write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // clear all interrupts + touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; // set the new touched status + clearfifo = true; // only take the last FIFO reading + } +#endif + + // If not touched, return the previous results + if (!touched) { + pt->x = x; + pt->y = y; + pt->z = 0; + pt->buttons = 0; + return; + } + +#if !STMP811_SLOW_CPU + if (!clearfifo && (read_reg(STMPE811_REG_FIFO_STA, 1) & 0xD0)) +#endif + clearfifo = true; + + do { + /* Get the X, Y, Z values */ + /* This could be done in a single 4 byte read to STMPE811_REG_TSC_DATA_XYZ (incr or non-incr) */ + x = (coord_t)read_reg(STMPE811_REG_TSC_DATA_X, 2); + y = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Y, 2); + z = (coord_t)read_reg(STMPE811_REG_TSC_DATA_Z, 1); + } while(clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20)); + + // Rescale X,Y,Z - X & Y don't need scaling when you are using calibration! +#if !GINPUT_MOUSE_NEED_CALIBRATION + x = gdispGetWidth() - x / (4096/gdispGetWidth()); + y = y / (4096/gdispGetHeight()); +#endif + z = (((z&0xFF) * 100)>>8) + 1; + + // Return the results. ADC gives values from 0 to 2^12 (4096) + pt->x = x; + pt->y = y; + pt->z = z; + pt->buttons = GINPUT_TOUCH_PRESSED; + + /* Force another read if we have more results */ + if (!clearfifo && !(read_reg(STMPE811_REG_FIFO_STA, 1) & 0x20)) + ginputMouseWakeup(); + +} + +#endif /* GFX_USE_GINPUT && GINPUT_NEED_MOUSE */ +/** @} */ + diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h index b99b6f14..ca1612b6 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h @@ -39,6 +39,8 @@ #define GINPUT_MOUSE_MAX_CLICK_JITTER 10 #define GINPUT_MOUSE_MAX_MOVE_JITTER 2 #define GINPUT_MOUSE_CLICK_TIME 500 +#define STMP811_SLOWER_RESPONSE FALSE +#define STMP811_NO_GPIO_IRQPIN FALSE #endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ /** @} */ From 2510f3e75b44b84e6ef43275c0818cb90764af2f Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 29 Mar 2013 18:14:35 +0100 Subject: [PATCH 07/12] board file fix --- drivers/gdisp/SSD2119/gdisp_lld.c | 8 ++++++++ drivers/ginput/touch/STMPE811/ginput_lld_mouse.c | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gdisp/SSD2119/gdisp_lld.c b/drivers/gdisp/SSD2119/gdisp_lld.c index 9e6fdb4f..a7ad7b1a 100644 --- a/drivers/gdisp/SSD2119/gdisp_lld.c +++ b/drivers/gdisp/SSD2119/gdisp_lld.c @@ -55,7 +55,15 @@ /* Driver local functions. */ /*===========================================================================*/ +#if defined(GDISP_USE_CUSTOM_BOARD) && GDISP_USE_CUSTOM_BOARD + /* Include the user supplied board definitions */ + #include "gdisp_lld_board.h" +#elif defined(BOARD_EMBEST_DMSTF4BB) #include "gdisp_lld_board_embest_dmstf4bb.h" +#else + /* Include the user supplied board definitions */ + #include "gdisp_lld_board.h" +#endif // Some common routines and macros #define write_reg(reg, data) { write_index(reg); write_data(data); } diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index 09360dbc..782c5c06 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -39,7 +39,7 @@ #if defined(GINPUT_MOUSE_USE_CUSTOM_BOARD) && GINPUT_MOUSE_USE_CUSTOM_BOARD #include "ginput_lld_mouse_board.h" -#elif defined(BOARD_EMBEST_DMST4BB) +#elif defined(BOARD_EMBEST_DMSTF4BB) #include "ginput_lld_mouse_board_embest_dmstf4bb.h" #else #include "ginput_lld_mouse_board_example.h" From 4440c2c8874c7c94f05b3a04fea52aaa15240721 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 29 Mar 2013 18:17:24 +0100 Subject: [PATCH 08/12] STMPE811 getpin_pressed() -> getpin_irq() --- drivers/ginput/touch/STMPE811/ginput_lld_mouse.c | 2 +- .../touch/STMPE811/ginput_lld_mouse_board_embest_dmstf4bb.h | 2 +- .../ginput/touch/STMPE811/ginput_lld_mouse_board_example.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c index 782c5c06..696795cc 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse.c @@ -130,7 +130,7 @@ void ginput_lld_mouse_get_reading(MouseReading *pt) #else // Check if the touch controller IRQ pin has gone off clearfifo = false; - if(getpin_pressed()) { // please rename this to getpin_irq + if(getpin_irq()) { // please rename this to getpin_irq write_reg(STMPE811_REG_INT_STA, 1, 0xFF); // clear all interrupts touched = (uint8_t)read_reg(STMPE811_REG_TSC_CTRL, 1) & 0x80; // set the new touched status clearfifo = true; // only take the last FIFO reading 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 d7a360cd..a0d5a0de 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 @@ -56,7 +56,7 @@ static void init_board(void) * * @notapi */ -static inline bool_t getpin_pressed(void) { +static inline bool_t getpin_irq(void) { return (!(palReadPad(GPIOC, 13))); } 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 d2a62733..453924b0 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_example.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_board_example.h @@ -47,10 +47,10 @@ static void init_board(void) * * @notapi */ -static inline bool_t getpin_pressed(void) +static inline bool_t getpin_irq(void) { /* Code here */ - #error "ginputSTMPE811: You must supply a definition for getpin_pressed for your board" + #error "ginputSTMPE811: You must supply a definition for getpin_irq for your board" } /** From 6ed641c91d1f94137bbb85074e66cc3214558e75 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 29 Mar 2013 19:26:56 +0100 Subject: [PATCH 09/12] STMPE811 cleanup & readme --- .../touch/STMPE811/ginput_lld_mouse_config.h | 6 ++-- drivers/ginput/touch/STMPE811/readme.txt | 29 +++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h index ca1612b6..be19c5e0 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h @@ -39,8 +39,10 @@ #define GINPUT_MOUSE_MAX_CLICK_JITTER 10 #define GINPUT_MOUSE_MAX_MOVE_JITTER 2 #define GINPUT_MOUSE_CLICK_TIME 500 -#define STMP811_SLOWER_RESPONSE FALSE -#define STMP811_NO_GPIO_IRQPIN FALSE + +/* default values - over write these in your boad files */ +#define STMP811_SLOWER_RESPONSE FALSE +#define STMP811_NO_GPIO_IRQPIN FALSE #endif /* _LLD_GINPUT_MOUSE_CONFIG_H */ /** @} */ diff --git a/drivers/ginput/touch/STMPE811/readme.txt b/drivers/ginput/touch/STMPE811/readme.txt index 1d7a8b4f..065840d8 100644 --- a/drivers/ginput/touch/STMPE811/readme.txt +++ b/drivers/ginput/touch/STMPE811/readme.txt @@ -1,9 +1,20 @@ -To use this driver: - -1. Add in your halconf.h: - a) #define GFX_USE_GINPUT TRUE - b) #define GINPUT_NEED_MOUSE TRUE - -2. To your makefile add the following lines: - include $(GFXLIB)/drivers/ginput/touch/STMPE811/ginput_lld.mk - +The STMPE811 driver comes with two different #defines to perfectly fit +your application: + + +STMPE811_NO_GPIO_IRQPIN +This Macro is meant to be set in your board file. When you set this macro to +TRUE, the GINPUT module will not use the IRQ lane which might be connected +to a GPIO pin to recognize interrupts by the STMPE811 controller. This +costs a few more I2C calls. +When the interrupt IRQ pin is connected to a GPIO of your MCU, set this +macro to FALSE. + + +STMP811_SLOW_CPU +If you have a slow CPU and you need to take care of your resources, you can +set this macro TRUE. This will save some IRQs and therefore a few I2C calls. +The disadvantage is a little higher response time. +If you don't want to draw continious lines on your display, it's recommended +to set this to TRUE anyways. + From f938c720448b81f53310c9b0aaa8b29d0aee71e9 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Fri, 29 Mar 2013 20:19:35 +0100 Subject: [PATCH 10/12] STMPE811 tweaks --- drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h index be19c5e0..871a6c2e 100644 --- a/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h +++ b/drivers/ginput/touch/STMPE811/ginput_lld_mouse_config.h @@ -37,8 +37,8 @@ #define GINPUT_MOUSE_READ_CYCLES 1 #define GINPUT_MOUSE_POLL_PERIOD 25 #define GINPUT_MOUSE_MAX_CLICK_JITTER 10 -#define GINPUT_MOUSE_MAX_MOVE_JITTER 2 -#define GINPUT_MOUSE_CLICK_TIME 500 +#define GINPUT_MOUSE_MAX_MOVE_JITTER 5 +#define GINPUT_MOUSE_CLICK_TIME 450 /* default values - over write these in your boad files */ #define STMP811_SLOWER_RESPONSE FALSE From 674bcb52d2b981b7c3d0b0b313fe6f17b8e4ff1d Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sat, 30 Mar 2013 16:08:47 +0530 Subject: [PATCH 11/12] GPIO interface-related fixes Adding acquire_bus() and release_bus() so that orientation setting commands are not ignored. --- drivers/gdisp/ILI9320/gdisp_lld.c | 26 +++++++++++++++++++++++++- drivers/gdisp/ILI9325/gdisp_lld.c | 28 ++++++++++++++++++++++++++-- drivers/gdisp/S6D1121/gdisp_lld.c | 12 ++++++++++++ 3 files changed, 63 insertions(+), 3 deletions(-) diff --git a/drivers/gdisp/ILI9320/gdisp_lld.c b/drivers/gdisp/ILI9320/gdisp_lld.c index 0cb5542f..f4ff05d5 100644 --- a/drivers/gdisp/ILI9320/gdisp_lld.c +++ b/drivers/gdisp/ILI9320/gdisp_lld.c @@ -460,16 +460,20 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { return; switch((gdisp_powermode_t)value) { case powerOff: + acquire_bus(); lld_lcdWriteReg(0x0007, 0x0000); lld_lcdWriteReg(0x0010, 0x0000); lld_lcdWriteReg(0x0011, 0x0000); lld_lcdWriteReg(0x0012, 0x0000); lld_lcdWriteReg(0x0013, 0x0000); + release_bus(); + gdisp_lld_backlight(0); break; case powerOn: //*************Power On sequence ******************// + acquire_bus(); lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */ @@ -483,13 +487,16 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { lld_lcdWriteReg(0x0013, 0x0E00); /* VDV[4:0] for VCOM amplitude */ lld_lcdWriteReg(0x0029, 0x0009); /* VCM[4:0] for VCOMH */ lld_lcdDelay(500); - lld_lcdWriteReg(0x0007, 0x0173); /* 262K color and display ON */ + lld_lcdWriteReg(0x0007, 0x0173); /* 262K color and display ON */ + release_bus(); + gdisp_lld_backlight(GDISP.Backlight); if(GDISP.Powermode != powerSleep || GDISP.Powermode != powerDeepSleep) gdisp_lld_init(); break; case powerSleep: + acquire_bus(); lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */ lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ @@ -497,10 +504,13 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */ lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */ lld_lcdWriteReg(0x0010, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ + release_bus(); + gdisp_lld_backlight(0); break; case powerDeepSleep: + acquire_bus(); lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */ lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ @@ -508,6 +518,8 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */ lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */ lld_lcdWriteReg(0x0010, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ + release_bus(); + gdisp_lld_backlight(0); break; @@ -522,33 +534,45 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { return; switch((gdisp_orientation_t)value) { case GDISP_ROTATE_0: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0100); lld_lcdWriteReg(0x0003, 0x1038); lld_lcdWriteReg(0x0060, 0x2700); + release_bus(); + GDISP.Height = GDISP_SCREEN_HEIGHT; GDISP.Width = GDISP_SCREEN_WIDTH; break; case GDISP_ROTATE_90: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0100); lld_lcdWriteReg(0x0003, 0x1030); lld_lcdWriteReg(0x0060, 0x2700); + release_bus(); + GDISP.Height = GDISP_SCREEN_WIDTH; GDISP.Width = GDISP_SCREEN_HEIGHT; break; case GDISP_ROTATE_180: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0000); lld_lcdWriteReg(0x0003, 0x1030); lld_lcdWriteReg(0x0060, 0x2700); + release_bus(); + GDISP.Height = GDISP_SCREEN_HEIGHT; GDISP.Width = GDISP_SCREEN_WIDTH; break; case GDISP_ROTATE_270: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0000); lld_lcdWriteReg(0x0003, 0x1038); lld_lcdWriteReg(0x0060, 0xA700); + release_bus(); + GDISP.Height = GDISP_SCREEN_WIDTH; GDISP.Width = GDISP_SCREEN_HEIGHT; break; diff --git a/drivers/gdisp/ILI9325/gdisp_lld.c b/drivers/gdisp/ILI9325/gdisp_lld.c index 62508d87..88dd4ade 100644 --- a/drivers/gdisp/ILI9325/gdisp_lld.c +++ b/drivers/gdisp/ILI9325/gdisp_lld.c @@ -456,16 +456,20 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { return; switch((gdisp_powermode_t)value) { case powerOff: + acquire_bus(); lld_lcdWriteReg(0x0007, 0x0000); lld_lcdWriteReg(0x0010, 0x0000); lld_lcdWriteReg(0x0011, 0x0000); lld_lcdWriteReg(0x0012, 0x0000); lld_lcdWriteReg(0x0013, 0x0000); + release_bus(); + gdisp_lld_backlight(0); break; case powerOn: //*************Power On sequence ******************// + acquire_bus(); lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], AP, DSTB, SLP, STB */ lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */ @@ -479,24 +483,30 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { lld_lcdWriteReg(0x0013, 0x0E00); /* VDV[4:0] for VCOM amplitude */ lld_lcdWriteReg(0x0029, 0x0009); /* VCM[4:0] for VCOMH */ lld_lcdDelay(500); - lld_lcdWriteReg(0x0007, 0x0173); /* 262K color and display ON */ + lld_lcdWriteReg(0x0007, 0x0173); /* 262K color and display ON */ + release_bus(); + gdisp_lld_backlight(GDISP.Backlight); if(GDISP.Powermode != powerSleep || GDISP.Powermode != powerDeepSleep) gdisp_lld_init(); break; case powerSleep: + acquire_bus(); lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */ lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ lld_lcdWriteReg(0x0012, 0x0000); /* VREG1OUT voltage */ lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */ lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */ - lld_lcdWriteReg(0x0010, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ + lld_lcdWriteReg(0x0010, 0x0002); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ + release_bus(); + gdisp_lld_backlight(0); break; case powerDeepSleep: + acquire_bus(); lld_lcdWriteReg(0x0007, 0x0000); /* display OFF */ lld_lcdWriteReg(0x0010, 0x0000); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ lld_lcdWriteReg(0x0011, 0x0000); /* DC1[2:0], DC0[2:0], VC[2:0] */ @@ -504,6 +514,8 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { lld_lcdWriteReg(0x0013, 0x0000); /* VDV[4:0] for VCOM amplitude */ lld_lcdDelay(2000); /* Dis-charge capacitor power voltage */ lld_lcdWriteReg(0x0010, 0x0004); /* SAP, BT[3:0], APE, AP, DSTB, SLP */ + release_bus(); + gdisp_lld_backlight(0); break; @@ -518,33 +530,45 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { return; switch((gdisp_orientation_t)value) { case GDISP_ROTATE_0: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0100); lld_lcdWriteReg(0x0003, 0x1038); lld_lcdWriteReg(0x0060, 0x2700); + release_bus(); + GDISP.Height = GDISP_SCREEN_HEIGHT; GDISP.Width = GDISP_SCREEN_WIDTH; break; case GDISP_ROTATE_90: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0000); lld_lcdWriteReg(0x0003, 0x1030); lld_lcdWriteReg(0x0060, 0x2700); + release_bus(); + GDISP.Height = GDISP_SCREEN_WIDTH; GDISP.Width = GDISP_SCREEN_HEIGHT; break; case GDISP_ROTATE_180: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0000); lld_lcdWriteReg(0x0003, 0x1038); lld_lcdWriteReg(0x0060, 0xa700); + release_bus(); + GDISP.Height = GDISP_SCREEN_HEIGHT; GDISP.Width = GDISP_SCREEN_WIDTH; break; case GDISP_ROTATE_270: + acquire_bus(); lld_lcdWriteReg(0x0001, 0x0100); lld_lcdWriteReg(0x0003, 0x1030); lld_lcdWriteReg(0x0060, 0xA700); + release_bus(); + GDISP.Height = GDISP_SCREEN_WIDTH; GDISP.Width = GDISP_SCREEN_HEIGHT; break; diff --git a/drivers/gdisp/S6D1121/gdisp_lld.c b/drivers/gdisp/S6D1121/gdisp_lld.c index 982e788b..671b8f86 100644 --- a/drivers/gdisp/S6D1121/gdisp_lld.c +++ b/drivers/gdisp/S6D1121/gdisp_lld.c @@ -524,26 +524,38 @@ void gdisp_lld_draw_pixel(coord_t x, coord_t y, color_t color) { return; switch((gdisp_orientation_t)value) { case GDISP_ROTATE_0: + acquire_bus(); write_reg(0x0001,0x0127); write_reg(0x03, 0b0011); + release_bus(); + GDISP.Height = GDISP_SCREEN_HEIGHT; GDISP.Width = GDISP_SCREEN_WIDTH; break; case GDISP_ROTATE_90: + acquire_bus(); write_reg(0x0001,0x0027); write_reg(0x0003, 0b1011); + release_bus(); + GDISP.Height = GDISP_SCREEN_WIDTH; GDISP.Width = GDISP_SCREEN_HEIGHT; break; case GDISP_ROTATE_180: + acquire_bus(); write_reg(0x0001,0x0127); write_reg(0x0003, 0b0000); + release_bus(); + GDISP.Height = GDISP_SCREEN_HEIGHT; GDISP.Width = GDISP_SCREEN_WIDTH; break; case GDISP_ROTATE_270: + acquire_bus(); write_reg(0x0001,0x0027); write_reg(0x0003, 0b1000); + release_bus(); + GDISP.Height = GDISP_SCREEN_WIDTH; GDISP.Width = GDISP_SCREEN_HEIGHT; break; From 939ca6e1d2fbdb352f6d04fc19aa94c6cfbc4416 Mon Sep 17 00:00:00 2001 From: Joel Bodenmann Date: Sun, 31 Mar 2013 00:52:33 +0100 Subject: [PATCH 12/12] coding style --- include/gwin/button.h | 1 + src/gwin/button.c | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/include/gwin/button.h b/include/gwin/button.h index fb9a2b76..2df540da 100644 --- a/include/gwin/button.h +++ b/include/gwin/button.h @@ -251,3 +251,4 @@ void gwinButtonDraw_Square(GHandle gh, bool_t isdown, const char *txt, const GBu #endif /* _GWIN_BUTTON_H */ /** @} */ + diff --git a/src/gwin/button.c b/src/gwin/button.c index 519dd1fe..bec738b4 100644 --- a/src/gwin/button.c +++ b/src/gwin/button.c @@ -48,12 +48,13 @@ static const GButtonDrawStyle GButtonDefaultStyleUp = { HTML2COLOR(0x404040), // color_up_edge; HTML2COLOR(0xE0E0E0), // color_up_fill; HTML2COLOR(0x000000), // color_up_txt; - }; +}; + static const GButtonDrawStyle GButtonDefaultStyleDown = { HTML2COLOR(0x404040), // color_dn_edge; HTML2COLOR(0x808080), // color_dn_fill; HTML2COLOR(0x404040), // color_dn_txt; - }; +}; // Process an event callback static void gwinButtonCallback(void *param, GEvent *pe) {