Fix nxstyle issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2020-04-29 15:08:16 +08:00 committed by patacongo
parent 304ecb2552
commit c82b446fa9
2 changed files with 107 additions and 68 deletions

View File

@ -1,4 +1,25 @@
unsigned char romfs_img[] = { /****************************************************************************
* nuttx/boards/arm/stm32/mikroe-stm32f4/include/nsh_romfsimg.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
unsigned char romfs_img[] =
{
0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x01, 0x80, 0x2d, 0x72, 0x6f, 0x6d, 0x31, 0x66, 0x73, 0x2d, 0x00, 0x00, 0x01, 0x80,
0x42, 0x56, 0x48, 0x93, 0x4e, 0x53, 0x48, 0x49, 0x6e, 0x69, 0x74, 0x56, 0x42, 0x56, 0x48, 0x93, 0x4e, 0x53, 0x48, 0x49, 0x6e, 0x69, 0x74, 0x56,
0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49, 0x6f, 0x6c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x49,

View File

@ -70,8 +70,11 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration ********************************************************************/
/* Reference counting is partially implemented, but not needed in the current design. /* Configuration ************************************************************/
/* Reference counting is partially implemented, but not needed in the current
* design.
*/ */
#define CONFIG_TOUCHSCREEN_REFCNT #define CONFIG_TOUCHSCREEN_REFCNT
@ -79,8 +82,9 @@
#undef CONFIG_TOUCHSCREEN_RESAMPLE #undef CONFIG_TOUCHSCREEN_RESAMPLE
/* TP uses ADC Channel #2 in a dedicated mode. Ensure ADC2 not selected for general /* TP uses ADC Channel #2 in a dedicated mode. Ensure ADC2 not selected for
* use via the menuconfig */ * general use via the menuconfig
*/
#ifndef CONFIG_STM32_ADC2 #ifndef CONFIG_STM32_ADC2
# error Touchpanel Input (CONFIG_INPUT=y) requires enablinga ADC2 (CONFIG_STM32_ADC2=y) # error Touchpanel Input (CONFIG_INPUT=y) requires enablinga ADC2 (CONFIG_STM32_ADC2=y)
@ -96,8 +100,8 @@
* Touchscreen data comes in a a very high rate. New touch positions * Touchscreen data comes in a a very high rate. New touch positions
* will only be reported when the X or Y data changes by these thresholds. * will only be reported when the X or Y data changes by these thresholds.
* This trades reduces data rate for some loss in dragging accuracy. The * This trades reduces data rate for some loss in dragging accuracy. The
* touchscreen is configure for 12-bit values so the raw ranges are 0-4096. So * touchscreen is configure for 12-bit values so the raw ranges are 0-4096.
* for example, if your display is 320x240, then THRESHX=3 and THRESHY=4 * So for example, if your display is 320x240, then THRESHX=3 and THRESHY=4
* would correspond to one pixel. Default: 4 * would correspond to one pixel. Default: 4
*/ */
@ -117,17 +121,18 @@
# define CONFIG_TOUCHSCREEN_NPOLLWAITERS 2 # define CONFIG_TOUCHSCREEN_NPOLLWAITERS 2
#endif #endif
/* Driver support *******************************************************************/ /* Driver support ***********************************************************/
/* This format is used to construct the /dev/input[n] device driver path. It is
* defined here so that it will be used consistently in all places. /* This format is used to construct the /dev/input[n] device driver path. It
* is defined here so that it will be used consistently in all places.
*/ */
#define DEV_FORMAT "/dev/input%d" #define DEV_FORMAT "/dev/input%d"
#define DEV_NAMELEN 16 #define DEV_NAMELEN 16
/* Mikroe-STM32M4 Touchscreen Hardware Definitions ********************************* /* Mikroe-STM32M4 Touchscreen Hardware Definitions **************************
* PIN CONFIGURATIONS SIGNAL NAME ON-BOARD CONNECTIONS * PIN CONFIGURATIONS SIGNAL NAME ON-BOARD CONNECTIONS
* --- ---------------------------------- -------------------- ------------------------ * --- ---------------------------------- -------------------- --------------
* 35 PB0 LCD-YD YD Analog input * 35 PB0 LCD-YD YD Analog input
* 36 PB1 LCD-XL XL Analog input * 36 PB1 LCD-XL XL Analog input
* 95 PB8 DRIVEA Drives XR, XL and YU * 95 PB8 DRIVEA Drives XR, XL and YU
@ -150,7 +155,7 @@
#define TC_ADC_BASE STM32_ADC2_BASE /* ADC Channel base for TP */ #define TC_ADC_BASE STM32_ADC2_BASE /* ADC Channel base for TP */
#define ADC_CR1_ALLINTS (ADC_CR1_AWDIE | ADC_CR1_EOCIE | ADC_CR1_JEOCIE) #define ADC_CR1_ALLINTS (ADC_CR1_AWDIE | ADC_CR1_EOCIE | ADC_CR1_JEOCIE)
/* Conversions are performed as 10-bit samples represented as 16-bit unsigned integers: */ /* Conversions are performed as 10-bit samples represented as 16-bit */
#define MAX_ADC (4096) #define MAX_ADC (4096)
@ -159,7 +164,8 @@
#define UPPER_THRESHOLD (MAX_ADC-1) #define UPPER_THRESHOLD (MAX_ADC-1)
#define LOWER_THRESHOLD (362) #define LOWER_THRESHOLD (362)
/* Delays ***************************************************************************/ /* Delays *******************************************************************/
/* All values will be increased by one system timer tick (probably 10MS). */ /* All values will be increased by one system timer tick (probably 10MS). */
#define TC_PENUP_POLL_TICKS MSEC2TICK(70) /* IDLE polling rate: 70 MSec */ #define TC_PENUP_POLL_TICKS MSEC2TICK(70) /* IDLE polling rate: 70 MSec */
@ -172,6 +178,7 @@
/**************************************************************************** /****************************************************************************
* Private Types * Private Types
****************************************************************************/ ****************************************************************************/
/* This enumeration describes the state of touchscreen state machine */ /* This enumeration describes the state of touchscreen state machine */
enum tc_state_e enum tc_state_e
@ -182,7 +189,7 @@ enum tc_state_e
TC_DEBOUNCE, /* Allowing a debounce time for the first sample */ TC_DEBOUNCE, /* Allowing a debounce time for the first sample */
TC_RESAMPLE, /* Restart sampling on a bad measurement */ TC_RESAMPLE, /* Restart sampling on a bad measurement */
TC_YSAMPLE, /* Allowing time for the Y sampling */ TC_YSAMPLE, /* Allowing time for the Y sampling */
TC_XSETTLE, /* Allowing time for the X to settle after changing DRIVE*/ TC_XSETTLE, /* Allowing time for the X to settle after changing DRIVE */
TC_XSAMPLE, /* Allowing time for the X sampling */ TC_XSAMPLE, /* Allowing time for the X sampling */
TC_XRESAMPLE, /* Allow time to resample X */ TC_XRESAMPLE, /* Allow time to resample X */
TC_PENDOWN, /* Conversion is complete -- pen down */ TC_PENDOWN, /* Conversion is complete -- pen down */
@ -293,6 +300,7 @@ static bool g_touchinitdone = false;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: tc_adc_getreg * Name: tc_adc_getreg
* *
@ -334,8 +342,9 @@ static inline void tc_adc_putreg(int offset, uint32_t value)
* Name: tc_adc_init * Name: tc_adc_init
* *
* Description: * Description:
* Initialize ADC Channel #2 for use with the touch panel. The touch panel uses * Initialize ADC Channel #2 for use with the touch panel. The touch panel
* Channels 8 and 9 (PB0 and PB1) to read the X and Y axis touch positions. * uses Channels 8 and 9 (PB0 and PB1) to read the X and Y axis touch
* positions.
* *
****************************************************************************/ ****************************************************************************/
@ -399,7 +408,7 @@ static void tc_adc_init(void)
/* Enable interrupt flags */ /* Enable interrupt flags */
//regval |= ADC_CR1_ALLINTS; /* regval |= ADC_CR1_ALLINTS; */
/* Disable Overrun interrupt */ /* Disable Overrun interrupt */
@ -416,7 +425,8 @@ static void tc_adc_init(void)
regval = tc_adc_getreg(STM32_ADC_CR2_OFFSET); regval = tc_adc_getreg(STM32_ADC_CR2_OFFSET);
/* Clear CONT, continuous mode disable. We will perform single /* Clear CONT, continuous mode disable. We will perform single
* sampling on one channel at a time. */ * sampling on one channel at a time.
*/
regval &= ~ADC_CR2_CONT; regval &= ~ADC_CR2_CONT;
@ -445,9 +455,11 @@ static void tc_adc_init(void)
/* ADC CCR configuration */ /* ADC CCR configuration */
regval = getreg32(STM32_ADC_CCR); regval = getreg32(STM32_ADC_CCR);
regval &= ~(ADC_CCR_MULTI_MASK | ADC_CCR_DELAY_MASK | ADC_CCR_DDS | ADC_CCR_DMA_MASK | regval &= ~(ADC_CCR_MULTI_MASK | ADC_CCR_DELAY_MASK | ADC_CCR_DDS |
ADC_CCR_ADCPRE_MASK | ADC_CCR_VBATEN | ADC_CCR_TSVREFE); ADC_CCR_DMA_MASK | ADC_CCR_ADCPRE_MASK | ADC_CCR_VBATEN |
regval |= (ADC_CCR_MULTI_NONE | ADC_CCR_DMA_DISABLED | ADC_CCR_ADCPRE_DIV2); ADC_CCR_TSVREFE);
regval |= (ADC_CCR_MULTI_NONE | ADC_CCR_DMA_DISABLED |
ADC_CCR_ADCPRE_DIV2);
putreg32(regval, STM32_ADC_CCR); putreg32(regval, STM32_ADC_CCR);
/* Set ADON to wake up the ADC from Power Down state. */ /* Set ADON to wake up the ADC from Power Down state. */
@ -465,8 +477,8 @@ static void tc_adc_init(void)
* Name: tc_adc_start_sample * Name: tc_adc_start_sample
* *
* Description: * Description:
* Perform A/D sampling. Time must be allowed between the start of sampling * Perform A/D sampling. Time must be allowed between the start of
* and conversion (approx. 100Ms). * sampling and conversion (approx. 100Ms).
* *
****************************************************************************/ ****************************************************************************/
@ -497,8 +509,8 @@ static void tc_adc_start_sample(int channel)
* Name: tc_adc_read_sample * Name: tc_adc_read_sample
* *
* Description: * Description:
* Begin A/D conversion. Time must be allowed between the start of sampling * Begin A/D conversion. Time must be allowed between the start of
* and conversion (approx. 100Ms). * sampling and conversion (approx. 100Ms).
* *
* Assumptions: * Assumptions:
* 1) All output pins configured as outputs: * 1) All output pins configured as outputs:
@ -599,17 +611,17 @@ static void tc_notify(FAR struct tc_dev_s *priv)
if (priv->nwaiters > 0) if (priv->nwaiters > 0)
{ {
/* After posting this semaphore, we need to exit because the touchscreen /* After posting this semaphore, we need to exit because the
* is no longer available. * touchscreen is no longer available.
*/ */
nxsem_post(&priv->waitsem); nxsem_post(&priv->waitsem);
} }
/* If there are threads waiting on poll() for touchscreen data to become available, /* If there are threads waiting on poll() for touchscreen data to become
* then wake them up now. NOTE: we wake up all waiting threads because we * available, then wake them up now. NOTE: we wake up all waiting threads
* do not know that they are going to do. If they all try to read the data, * because we do not know that they are going to do. If they all try to
* then some make end up blocking after all. * read the data, then some make end up blocking after all.
*/ */
for (i = 0; i < CONFIG_TOUCHSCREEN_NPOLLWAITERS; i++) for (i = 0; i < CONFIG_TOUCHSCREEN_NPOLLWAITERS; i++)
@ -644,7 +656,7 @@ static int tc_sample(FAR struct tc_dev_s *priv,
* sampled data. * sampled data.
*/ */
memcpy(sample, &priv->sample, sizeof(struct tc_sample_s )); memcpy(sample, &priv->sample, sizeof(struct tc_sample_s));
/* Now manage state transitions */ /* Now manage state transitions */
@ -708,13 +720,13 @@ static int tc_waitsample(FAR struct tc_dev_s *priv,
if (ret < 0) if (ret < 0)
{ {
goto errout; goto errout;
} }
} }
/* Re-acquire the semaphore that manages mutually exclusive access to /* Re-acquire the semaphore that manages mutually exclusive access to
* the device structure. We may have to wait here. But we have our sample. * the device structure. We may have to wait here. But we have our
* Interrupts and pre-emption will be re-enabled while we wait. * sample. Interrupts and pre-emption will be re-enabled while we wait.
*/ */
ret = nxsem_wait(&priv->devsem); ret = nxsem_wait(&priv->devsem);
@ -755,9 +767,9 @@ static void tc_worker(FAR void *arg)
{ {
/* Select DRIVE for Y sampling */ /* Select DRIVE for Y sampling */
/* Configure XL, XR with drive voltages and disable YU drive. Note that /* Configure XL, XR with drive voltages and disable YU drive. Note
* this is configuring the DRIVEA and DRIVEB outputs to enable the on-board * that this is configuring the DRIVEA and DRIVEB outputs to enable
* transistor drive logic to energize the touch panel. * the on-board transistor drive logic to energize the touch panel.
*/ */
*((uint32_t *) LCD_TP_PORT_SETRESET) = LCD_SAMPY_BITS; *((uint32_t *) LCD_TP_PORT_SETRESET) = LCD_SAMPY_BITS;
@ -821,9 +833,9 @@ static void tc_worker(FAR void *arg)
{ {
/* Select DRIVE for Y sampling */ /* Select DRIVE for Y sampling */
/* Configure XL, XR with drive voltages and disable YU drive. Note that /* Configure XL, XR with drive voltages and disable YU drive. Note
* this is configuring the DRIVEA and DRIVEB outputs to enable the on-board * that this is configuring the DRIVEA and DRIVEB outputs to enable
* transistor drive logic to energize the touch panel. * the on-board transistor drive logic to energize the touch panel.
*/ */
*((uint32_t *) LCD_TP_PORT_SETRESET) = LCD_SAMPY_BITS; *((uint32_t *) LCD_TP_PORT_SETRESET) = LCD_SAMPY_BITS;
@ -858,9 +870,9 @@ static void tc_worker(FAR void *arg)
value = tc_adc_read_sample(); value = tc_adc_read_sample();
/* A converted value at the minimum would mean that we lost the contact /* A converted value at the minimum would mean that we lost the
* before all of the conversions were completed. At converted value at * contact before all of the conversions were completed. At
* the maximum value is probably bad too. * converted value at the maximum value is probably bad too.
*/ */
if (!tc_valid_sample(value)) if (!tc_valid_sample(value))
@ -888,9 +900,10 @@ static void tc_worker(FAR void *arg)
priv->sampcount = 0; priv->sampcount = 0;
iinfo("Y=%d\n", priv->newy); iinfo("Y=%d\n", priv->newy);
/* Configure YU and YD with drive voltages and disable XR drive. Note that /* Configure YU and YD with drive voltages and disable XR drive.
* this is configuring the DRIVEA and DRIVEB outputs to enable the on-board * Note that this is configuring the DRIVEA and DRIVEB outputs
* transistor drive logic to energize the touch panel. * to enable the on-board transistor drive logic to energize the
* touch panel.
*/ */
*((uint32_t *) LCD_TP_PORT_SETRESET) = LCD_SAMPX_BITS; *((uint32_t *) LCD_TP_PORT_SETRESET) = LCD_SAMPX_BITS;
@ -935,9 +948,9 @@ static void tc_worker(FAR void *arg)
value = tc_adc_read_sample(); value = tc_adc_read_sample();
/* A converted value at the minimum would mean that we lost the contact /* A converted value at the minimum would mean that we lost the
* before all of the conversions were completed. At converted value at * contact before all of the conversions were completed. At
* the maximum value is probably bad too. * converted value at the maximum value is probably bad too.
*/ */
if (!tc_valid_sample(value)) if (!tc_valid_sample(value))
@ -955,7 +968,6 @@ static void tc_worker(FAR void *arg)
{ {
/* Calculate the X axis position */ /* Calculate the X axis position */
//value = MAX_ADC - value;
priv->value += value; priv->value += value;
if (++priv->sampcount < CONFIG_TOUCHSCREEN_AVG_SAMPLES) if (++priv->sampcount < CONFIG_TOUCHSCREEN_AVG_SAMPLES)
{ {
@ -983,8 +995,8 @@ static void tc_worker(FAR void *arg)
if (priv->state == TC_PENUP) if (priv->state == TC_PENUP)
{ {
/* Ignore if the pen was already down (CONTACT_NONE == pen up and already /* Ignore if the pen was already down (CONTACT_NONE == pen up and
* reported. CONTACT_UP == pen up, but not reported) * already reported. CONTACT_UP == pen up, but not reported)
*/ */
if (priv->sample.contact != CONTACT_NONE && if (priv->sample.contact != CONTACT_NONE &&
@ -1020,15 +1032,16 @@ static void tc_worker(FAR void *arg)
else if (priv->state == TC_PENDOWN) else if (priv->state == TC_PENDOWN)
{ {
/* It is a pen down event. If the last loss-of-contact event has not been /* It is a pen down event. If the last loss-of-contact event has not
* processed yet, then we have to ignore the pen down event (or else it will * been processed yet, then we have to ignore the pen down event (or
* look like a drag event) * else it will look like a drag event)
*/ */
if (priv->sample.contact != CONTACT_UP) if (priv->sample.contact != CONTACT_UP)
{ {
/* Perform a thresholding operation so that the results will be more stable. /* Perform a thresholding operation so that the results will be
* If the difference from the last sample is small, then ignore the event. * more stable. If the difference from the last sample is small,
* then ignore the event.
*/ */
xdiff = (int16_t)priv->sample.x - (int16_t)newx; xdiff = (int16_t)priv->sample.x - (int16_t)newx;
@ -1046,7 +1059,9 @@ static void tc_worker(FAR void *arg)
if (xdiff >= CONFIG_TOUCHSCREEN_THRESHX || if (xdiff >= CONFIG_TOUCHSCREEN_THRESHX ||
ydiff >= CONFIG_TOUCHSCREEN_THRESHY) ydiff >= CONFIG_TOUCHSCREEN_THRESHY)
{ {
/* There is some change above the threshold... Report the change. */ /* There is some change above the threshold...
* Report the change.
*/
#ifdef CONFIG_LCD_LANDSCAPE #ifdef CONFIG_LCD_LANDSCAPE
priv->sample.x = MAX_ADC - priv->newy; priv->sample.x = MAX_ADC - priv->newy;
@ -1057,9 +1072,10 @@ static void tc_worker(FAR void *arg)
#endif #endif
priv->sample.valid = true; priv->sample.valid = true;
/* If this is the first (acknowledged) penddown report, then report /* If this is the first (acknowledged) penddown report, then
* this as the first contact. If contact == CONTACT_DOWN, it will be * report this as the 1st contact. If contact == CONTACT_DOWN,
* set to set to CONTACT_MOVE after the contact is first sampled. * it will be set to set to CONTACT_MOVE after the contact is
* first sampled.
*/ */
if (priv->sample.contact != CONTACT_MOVE) if (priv->sample.contact != CONTACT_MOVE)
@ -1239,7 +1255,7 @@ static ssize_t tc_read(FAR struct file *filep, FAR char *buffer, size_t len)
{ {
ret = -EAGAIN; ret = -EAGAIN;
goto errout; goto errout;
} }
/* Wait for sample data */ /* Wait for sample data */
@ -1267,8 +1283,8 @@ static ssize_t tc_read(FAR struct file *filep, FAR char *buffer, size_t len)
if (sample.contact == CONTACT_UP) if (sample.contact == CONTACT_UP)
{ {
/* Pen is now up. Is the positional data valid? This is important to /* Pen is now up. Is the positional data valid? This is important to
* know because the release will be sent to the window based on its * know because the release will be sent to the window based on its
* last positional data. * last positional data.
*/ */
@ -1288,13 +1304,15 @@ static ssize_t tc_read(FAR struct file *filep, FAR char *buffer, size_t len)
{ {
/* First contact */ /* First contact */
report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID | TOUCH_POS_VALID; report->point[0].flags = TOUCH_DOWN | TOUCH_ID_VALID |
TOUCH_POS_VALID;
} }
else /* if (sample->contact == CONTACT_MOVE) */ else /* if (sample->contact == CONTACT_MOVE) */
{ {
/* Movement of the same contact */ /* Movement of the same contact */
report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID | TOUCH_POS_VALID; report->point[0].flags = TOUCH_MOVE | TOUCH_ID_VALID |
TOUCH_POS_VALID;
} }
} }