Commit 119ec0d2 authored by Felix Wittenfeld's avatar Felix Wittenfeld
Browse files

- fixed address calculation

- added reset-function
parent 5e585131
......@@ -243,6 +243,9 @@ extern "C" {
apalExitStatus_t at42qt1050_lld_read_keyssignal(const AT42QT1050Driver* at42qt1050d, const uint8_t key, uint16_t* signal, const apalTime_t timeout);
apalExitStatus_t at42qt1050_lld_read_referencedata(const AT42QT1050Driver* at42qt1050d, const uint8_t key, uint16_t* refdata, const apalTime_t timeout);
apalExitStatus_t at42qt1050_lld_reset_safe(const AT42QT1050Driver* at42qt1050d, const bool wait4wakeup, const apalTime_t timeout);
apalExitStatus_t at42qt1050_lld_reset(const AT42QT1050Driver* at42qt1050d, const apalTime_t timeout, const bool wait4wakeup);
uint16_t at42qt1050_lld_pulse2samples(const uint8_t pulse);
float at42qt1050_lld_samples2pulse(const uint16_t samples);
uint16_t at42qt1050_lld_scale2scaling(const uint8_t scale);
......
......@@ -33,6 +33,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
/******************************************************************************/
/* LOCAL DEFINITIONS */
/******************************************************************************/
#define AT42QT1050_LLD_WATCHDOGTIME_MAX 125000
#define AT42QT1050_LLD_INITIALIZATION_TIME_MAX 30000
/******************************************************************************/
/* EXPORTED VARIABLES */
......@@ -107,7 +109,7 @@ apalExitStatus_t at42qt1050_lld_read_keyssignal(const AT42QT1050Driver* at42qt10
apalDbgAssert(key < AT42QT1050_LLD_NUM_KEYS);
apalDbgAssert(signal != NULL);
const uint8_t txbuf = AT42QT1050_LLD_REG_KEYSIGNAL_0 + (2*key) + ((key > 1) ? 1 : 0);
const uint8_t txbuf = AT42QT1050_LLD_REG_KEYSIGNAL_0 + (2*key) + ((key > 1) ? 2 : 0);
uint8_t rxbuf[2];
const apalExitStatus_t status = apalI2CMasterTransmit(at42qt1050d->i2cd, at42qt1050d->addr, &txbuf, 1, rxbuf, 2, timeout);
*signal = (rxbuf[0] << 8) | rxbuf[1];
......@@ -130,13 +132,48 @@ apalExitStatus_t at42qt1050_lld_read_referencedata(const AT42QT1050Driver* at42q
apalDbgAssert(key < AT42QT1050_LLD_NUM_KEYS);
apalDbgAssert(refdata != NULL);
const uint8_t txbuf = AT42QT1050_LLD_REG_REFERENCEDATA_0 + (2*key) + ((key > 1) ? 1 : 0);
const uint8_t txbuf = AT42QT1050_LLD_REG_REFERENCEDATA_0 + (2*key) + ((key > 1) ? 2 : 0);
uint8_t rxbuf[2];
const apalExitStatus_t status = apalI2CMasterTransmit(at42qt1050d->i2cd, at42qt1050d->addr, &txbuf, 1, rxbuf, 2, timeout);
*refdata = (rxbuf[0] << 8) | rxbuf[1];
return status;
}
/**
* @brief Soft Reset of the device
*
* @param[in] at42qt1050d The AT42QT1050 driver to use.
* @param[in] timeout Timeout for the function to return (in microseconds).
* @param[in] wait4wakeup Wait for device wakeup (timeout must be > 155 ms)
*
* @return Indicator whether the function call was successful or a timeout occurred.
*/
inline apalExitStatus_t at42qt1050_lld_reset_safe(const AT42QT1050Driver* at42qt1050d, const bool wait4wakeup, const apalTime_t timeout) {
if(wait4wakeup)
apalDbgAssert(timeout >= AT42QT1050_LLD_WATCHDOGTIME_MAX+AT42QT1050_LLD_INITIALIZATION_TIME_MAX);
return at42qt1050_lld_reset(at42qt1050d, timeout-(AT42QT1050_LLD_WATCHDOGTIME_MAX+AT42QT1050_LLD_INITIALIZATION_TIME_MAX), wait4wakeup);
}
/**
* @brief Soft Reset of the device
*
* @param[in] at42qt1050d The AT42QT1050 driver to use.
* @param[in] timeout Timeout for the i2c call (in microseconds).
* @param[in] wait4wakeup Wait for device wakeup (155 ms)
*
* @return Indicator whether the function call was successful or a timeout occurred.
*/
inline apalExitStatus_t at42qt1050_lld_reset(const AT42QT1050Driver* at42qt1050d, const apalTime_t timeout, const bool wait4wakeup) {
apalDbgAssert(at42qt1050d != NULL && at42qt1050d->i2cd != NULL);
const apalExitStatus_t status = at42qt1050_lld_write_reg(
at42qt1050d, AT42QT1050_LLD_RESETCALIBRATE_RESET, AT42QT1050_LLD_RESETCALIBRATE_RESET, timeout);
if(wait4wakeup)
usleep(AT42QT1050_LLD_WATCHDOGTIME_MAX+AT42QT1050_LLD_INITIALIZATION_TIME_MAX); // watchdog timer+initialization -> datasheet
return status;
}
/**
* @brief Convert a 4 bit pulse value to the representing number of samples.
* @details Calculation: <#samples> = 2^(<pulse value>)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment