2012-05-06 18:28:43 +02:00
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* drivers/input/stmpe811_temp.c
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* 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
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
2021-03-04 07:10:42 +01:00
|
|
|
* 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.
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-03-04 07:10:42 +01:00
|
|
|
/* References:
|
2022-09-27 14:14:07 +02:00
|
|
|
* "STMPE811 S-Touch® advanced resistive touchscreen controller with 8-bit
|
2021-03-04 07:10:42 +01:00
|
|
|
* GPIO expander," Doc ID 14489 Rev 6, CD00186725, STMicroelectronics"
|
|
|
|
*/
|
|
|
|
|
2012-05-06 18:28:43 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#include <nuttx/input/stmpe811.h>
|
2017-03-30 15:38:37 +02:00
|
|
|
#include <nuttx/random.h>
|
2012-05-06 18:28:43 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#include "stmpe811.h"
|
2012-05-06 18:28:43 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#if defined(CONFIG_INPUT) && defined(CONFIG_INPUT_STMPE811) && !defined(CONFIG_STMPE811_TEMP_DISABLE)
|
2012-05-06 18:28:43 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_tempinitialize
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the temperature sensor.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2012-05-29 03:43:51 +02:00
|
|
|
* handle - The handle previously returned by stmpe811_instantiate
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success. Otherwise, a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
int stmpe811_tempinitialize(STMPE811_HANDLE handle)
|
2012-05-06 18:28:43 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
FAR struct stmpe811_dev_s *priv = (FAR struct stmpe811_dev_s *)handle;
|
2012-05-06 18:28:43 +02:00
|
|
|
uint8_t regval;
|
|
|
|
|
|
|
|
/* Enable clocking for ADC and the temperature sensor */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
regval = stmpe811_getreg8(priv, STMPE811_SYS_CTRL2);
|
2012-05-06 18:28:43 +02:00
|
|
|
regval &= ~(SYS_CTRL2_TS_OFF | SYS_CTRL2_ADC_OFF);
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_SYS_CTRL2, regval);
|
2012-05-06 18:28:43 +02:00
|
|
|
|
|
|
|
/* Enable the temperature sensor */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_TEMP_CTRL, TEMP_CTRL_ENABLE);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2020-02-22 19:31:14 +01:00
|
|
|
/* Acquire data enable */
|
2012-05-06 18:28:43 +02:00
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_TEMP_CTRL,
|
|
|
|
(TEMP_CTRL_ACQ | TEMP_CTRL_ENABLE));
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-05-06 18:28:43 +02:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_tempread
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the temperature sensor.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2012-05-29 03:43:51 +02:00
|
|
|
* handle - The handle previously returned by stmpe811_instantiate
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success. Otherwise, a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
uint16_t stmpe811_tempread(STMPE811_HANDLE handle)
|
2012-05-06 18:28:43 +02:00
|
|
|
{
|
2012-05-29 03:43:51 +02:00
|
|
|
FAR struct stmpe811_dev_s *priv = (FAR struct stmpe811_dev_s *)handle;
|
2014-04-13 22:32:20 +02:00
|
|
|
uint32_t temp = 0;
|
2012-05-06 18:28:43 +02:00
|
|
|
uint8_t temp1;
|
|
|
|
uint8_t temp2;
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-05-06 18:28:43 +02:00
|
|
|
/* Acquire data enable */
|
|
|
|
|
2015-10-10 18:41:00 +02:00
|
|
|
stmpe811_putreg8(priv, STMPE811_TEMP_CTRL,
|
|
|
|
(TEMP_CTRL_ACQ | TEMP_CTRL_ENABLE));
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-05-07 03:40:39 +02:00
|
|
|
/* Read the temperature */
|
2012-05-06 18:28:43 +02:00
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
temp1 = stmpe811_getreg8(priv, STMPE811_SYS_CTRL2);
|
2021-03-04 08:02:21 +01:00
|
|
|
temp2 = stmpe811_getreg8(priv, STMPE811_SYS_CTRL2 + 1);
|
2012-05-06 18:28:43 +02:00
|
|
|
|
2017-03-30 15:38:37 +02:00
|
|
|
add_sensor_randomness((temp1 << 8) | temp2);
|
|
|
|
|
2012-05-07 03:40:39 +02:00
|
|
|
/* Scale the temperature (where Vio is assumed to be .33) */
|
2012-05-06 18:28:43 +02:00
|
|
|
|
|
|
|
temp = ((uint32_t)(temp1 & 3) << 8) | temp2;
|
|
|
|
temp = (uint32_t)((33 * temp * 100) / 751);
|
|
|
|
temp = (uint32_t)((temp + 5) / 10);
|
|
|
|
|
|
|
|
return (uint16_t)temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2012-05-29 03:43:51 +02:00
|
|
|
* Name: stmpe811_tempinterrupt
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Configure the temperature sensor to sample the temperature periodically.
|
|
|
|
* Set the temperature threshold to generate an interrupt and notify
|
|
|
|
* to the client using the provide callback function pointer.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2012-05-29 03:43:51 +02:00
|
|
|
* handle - The handle previously returned by stmpe811_instantiate
|
2012-05-06 18:28:43 +02:00
|
|
|
* threshold - The threshold temperature value
|
|
|
|
* direction - True: Generate an interrupt if the temperate exceeds the
|
|
|
|
* threshold value; False: Generate an interrupt if the
|
|
|
|
* temperature falls below the threshold value.
|
|
|
|
* callback - The client callback function that will be called when
|
2020-02-23 09:50:23 +01:00
|
|
|
* the temperature crosses the threshold.
|
2012-05-06 18:28:43 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero is returned on success. Otherwise, a negated errno value is
|
|
|
|
* returned to indicate the nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2021-03-04 08:02:21 +01:00
|
|
|
|
2012-05-06 18:28:43 +02:00
|
|
|
/* Not implemented */
|
|
|
|
|
2012-05-29 03:43:51 +02:00
|
|
|
#endif /* CONFIG_INPUT && CONFIG_INPUT_STMPE811 && !CONFIG_STMPE811_TEMP_DISABLE */
|