Revision 9e45662e
| Makefile | ||
|---|---|---|
| 35 | 35 |
# C sources |
| 36 | 36 |
AMIROLLD_CSRC = $(AMIROLLD_SRCDIR)/alld_a3906.c \ |
| 37 | 37 |
$(AMIROLLD_SRCDIR)/alld_at24c01bn-sh-b.c \ |
| 38 |
$(AMIROLLD_SRCDIR)/alld_at42qt1050.c \ |
|
| 38 | 39 |
$(AMIROLLD_SRCDIR)/alld_bq24103a.c \ |
| 39 | 40 |
$(AMIROLLD_SRCDIR)/alld_bq27500.c \ |
| 40 | 41 |
$(AMIROLLD_SRCDIR)/alld_hmc5883l.c \ |
| include/alld_at42qt1050.h | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2019 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU Lesser General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU Lesser General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU Lesser General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
/** |
|
| 20 |
* @file alld_at42qt1050.h |
|
| 21 |
* @brief Touch sensor macros and structures. |
|
| 22 |
* |
|
| 23 |
* @addtogroup lld_touch |
|
| 24 |
* @{
|
|
| 25 |
*/ |
|
| 26 |
|
|
| 27 |
#ifndef _AMIROLLD_AT42QT1050_H_ |
|
| 28 |
#define _AMIROLLD_AT42QT1050_H_ |
|
| 29 |
|
|
| 30 |
#include <amiro-lld.h> |
|
| 31 |
|
|
| 32 |
#if defined(AMIROLLD_CFG_USE_AT42QT1050) || defined(__DOXYGEN__) |
|
| 33 |
|
|
| 34 |
/** |
|
| 35 |
* @brief Maximum I2C frequency. |
|
| 36 |
*/ |
|
| 37 |
#define AT42QT1050_LLD_I2C_MAXFREQUENCY 400000 |
|
| 38 |
|
|
| 39 |
/** |
|
| 40 |
* @brief A falling edge indicats an interrupt. |
|
| 41 |
*/ |
|
| 42 |
#define AT42QT1050_LLD_INT_EDGE APAL_GPIO_EDGE_FALLING |
|
| 43 |
|
|
| 44 |
/** |
|
| 45 |
* @brief Number of touch keys supported by AT42QT1050. |
|
| 46 |
*/ |
|
| 47 |
#define AT42QT1050_LLD_NUM_KEYS 5 |
|
| 48 |
|
|
| 49 |
/** |
|
| 50 |
* @brief Maximum time (in microseconds) to acquire all key signals before the overflow bit of the detection status register is set. |
|
| 51 |
*/ |
|
| 52 |
#define AT42QT1050_LLD_MAX_KEY_ACQUIRATION_TIME 8000 |
|
| 53 |
|
|
| 54 |
/** |
|
| 55 |
* @brief The AT42QT1050Driver sruct. |
|
| 56 |
*/ |
|
| 57 |
typedef struct {
|
|
| 58 |
apalI2CDriver_t* i2cd; |
|
| 59 |
apalI2Caddr_t addr; |
|
| 60 |
} AT42QT1050Driver; |
|
| 61 |
|
|
| 62 |
/** |
|
| 63 |
* @brief Possible I2C address configurations. |
|
| 64 |
*/ |
|
| 65 |
enum {
|
|
| 66 |
AT42QT1050_LLD_I2C_ADDRSEL_LOW = 0x0041u, /**< ADDR_SEL pin is pulled low. */ |
|
| 67 |
AT42QT1050_LLD_I2C_ADDRSEL_HIGH = 0x0046u, /**< ADDR_SEL pin is pulled high. */ |
|
| 68 |
}; |
|
| 69 |
|
|
| 70 |
/** |
|
| 71 |
* @brief Available register addresses of the AT42Q1050. |
|
| 72 |
*/ |
|
| 73 |
typedef enum {
|
|
| 74 |
AT42QT1050_LLD_REG_CHIPID = 0x00u, /**< read only */ |
|
| 75 |
AT42QT1050_LLD_REG_FIRMWAREVERSION = 0x01u, /**< read only */ |
|
| 76 |
AT42QT1050_LLD_REG_DETECTIONSTATUS = 0x02u, /**< read only */ |
|
| 77 |
AT42QT1050_LLD_REG_KEYSTATUS = 0x03u, /**< read only */ |
|
| 78 |
AT42QT1050_LLD_REG_KEYSIGNAL_0 = 0x06u, /**< read only */ |
|
| 79 |
AT42QT1050_LLD_REG_KEYSIGNAL_1 = 0x08u, /**< read only */ |
|
| 80 |
AT42QT1050_LLD_REG_KEYSIGNAL_2 = 0x0Du, /**< read only */ |
|
| 81 |
AT42QT1050_LLD_REG_KEYSIGNAL_3 = 0x0Fu, /**< read only */ |
|
| 82 |
AT42QT1050_LLD_REG_KEYSIGNAL_4 = 0x11u, /**< read only */ |
|
| 83 |
AT42QT1050_LLD_REG_REFERENCEDATA_0 = 0x14u, /**< read only */ |
|
| 84 |
AT42QT1050_LLD_REG_REFERENCEDATA_1 = 0x16u, /**< read only */ |
|
| 85 |
AT42QT1050_LLD_REG_REFERENCEDATA_2 = 0x1Au, /**< read only */ |
|
| 86 |
AT42QT1050_LLD_REG_REFERENCEDATA_3 = 0x1Cu, /**< read only */ |
|
| 87 |
AT42QT1050_LLD_REG_REFERENCEDATA_4 = 0x1Eu, /**< read only */ |
|
| 88 |
AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_0 = 0x21u, /**< read/write */ |
|
| 89 |
AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_1 = 0x22u, /**< read/write */ |
|
| 90 |
AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_2 = 0x24u, /**< read/write */ |
|
| 91 |
AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_3 = 0x25u, /**< read/write */ |
|
| 92 |
AT42QT1050_LLD_REG_NEGATIVETHRESHOLD_4 = 0x26u, /**< read/write */ |
|
| 93 |
AT42QT1050_LLD_REG_PULSE_SCALE_0 = 0x28u, /**< read/write */ |
|
| 94 |
AT42QT1050_LLD_REG_PULSE_SCALE_1 = 0x29u, /**< read/write */ |
|
| 95 |
AT42QT1050_LLD_REG_PULSE_SCALE_2 = 0x2Bu, /**< read/write */ |
|
| 96 |
AT42QT1050_LLD_REG_PULSE_SCALE_3 = 0x2Cu, /**< read/write */ |
|
| 97 |
AT42QT1050_LLD_REG_PULSE_SCALE_4 = 0x2Du, /**< read/write */ |
|
| 98 |
AT42QT1050_LLD_REG_INTEGRATOR_AKS_0 = 0x2Fu, /**< read/write */ |
|
| 99 |
AT42QT1050_LLD_REG_INTEGRATOR_AKS_1 = 0x30u, /**< read/write */ |
|
| 100 |
AT42QT1050_LLD_REG_INTEGRATOR_AKS_2 = 0x32u, /**< read/write */ |
|
| 101 |
AT42QT1050_LLD_REG_INTEGRATOR_AKS_3 = 0x33u, /**< read/write */ |
|
| 102 |
AT42QT1050_LLD_REG_INTEGRATOR_AKS_4 = 0x34u, /**< read/write */ |
|
| 103 |
AT42QT1050_LLD_REG_CHARGESHAREDELAY_0 = 0x36u, /**< read/write */ |
|
| 104 |
AT42QT1050_LLD_REG_CHARGESHAREDELAY_1 = 0x37u, /**< read/write */ |
|
| 105 |
AT42QT1050_LLD_REG_CHARGESHAREDELAY_2 = 0x39u, /**< read/write */ |
|
| 106 |
AT42QT1050_LLD_REG_CHARGESHAREDELAY_3 = 0x3Au, /**< read/write */ |
|
| 107 |
AT42QT1050_LLD_REG_CHARGESHAREDELAY_4 = 0x3Bu, /**< read/write */ |
|
| 108 |
AT42QT1050_LLD_REG_FINFOUTMAXCALGUARD = 0x3Cu, /**< read/write */ |
|
| 109 |
AT42QT1050_LLD_REG_LOWPOWERMODE = 0x3Du, /**< read/write */ |
|
| 110 |
AT42QT1050_LLD_REG_MAXONDURATION = 0x3Eu, /**< read/write */ |
|
| 111 |
AT42QT1050_LLD_REG_RESET_CALIBRATE = 0x3Fu, /**< read/write */ |
|
| 112 |
} at42qt1050_lld_register_t; |
|
| 113 |
|
|
| 114 |
/** |
|
| 115 |
* @brief The chip ID as can be read from the according register (constant). |
|
| 116 |
*/ |
|
| 117 |
#define AT42QT1050_LLD_CHIPID 0x46 |
|
| 118 |
|
|
| 119 |
/** |
|
| 120 |
* @brief Firmware version register structure. |
|
| 121 |
*/ |
|
| 122 |
typedef union {
|
|
| 123 |
uint8_t raw; |
|
| 124 |
struct {
|
|
| 125 |
uint8_t minor : 4; |
|
| 126 |
uint8_t major : 4; |
|
| 127 |
}; |
|
| 128 |
} at42qt1050_lld_firmwarereg_t; |
|
| 129 |
|
|
| 130 |
|
|
| 131 |
/** |
|
| 132 |
* @brief Relevant bits of the detection status register. |
|
| 133 |
*/ |
|
| 134 |
typedef enum {
|
|
| 135 |
AT42QT1050_LLD_DETECTIONSTATUS_TOUCH = 0x01u, /**< Set if any keys are in detect. */ |
|
| 136 |
AT42QT1050_LLD_DETECTIONSTATUS_OVERFLOW = 0x40u, /**< Set if the time to acquire all key signals exceeds 8ms. */ |
|
| 137 |
AT42QT1050_LLD_DETECTIONSTATUS_CALIBRATE = 0x80u, /**< Set during calibration sequence. */ |
|
| 138 |
} at42q1050_lld_detectionstatusreg_t; |
|
| 139 |
|
|
| 140 |
/** |
|
| 141 |
* @brief Key status register masks. |
|
| 142 |
*/ |
|
| 143 |
typedef enum {
|
|
| 144 |
AT42QT1050_LLD_KEYSTATUS_KEY0 = 0x02u, |
|
| 145 |
AT42QT1050_LLD_KEYSTATUS_KEY1 = 0x04u, |
|
| 146 |
AT42QT1050_LLD_KEYSTATUS_KEY2 = 0x10u, |
|
| 147 |
AT42QT1050_LLD_KEYSTATUS_KEY3 = 0x20u, |
|
| 148 |
AT42QT1050_LLD_KEYSTATUS_KEY4 = 0x40u, |
|
| 149 |
} at42qt1050_lld_keystatusreg_t; |
|
| 150 |
|
|
| 151 |
/** |
|
| 152 |
* @brief Pulse/Scale register structure. |
|
| 153 |
*/ |
|
| 154 |
typedef union {
|
|
| 155 |
uint8_t raw; |
|
| 156 |
struct {
|
|
| 157 |
uint8_t scale : 4; |
|
| 158 |
uint8_t pulse : 4; |
|
| 159 |
}; |
|
| 160 |
} at42qt1050_lld_pulsescalereg_t; |
|
| 161 |
|
|
| 162 |
/** |
|
| 163 |
* @brief Detection Integrator (DI) / AKS register structure. |
|
| 164 |
*/ |
|
| 165 |
typedef union {
|
|
| 166 |
uint8_t raw; |
|
| 167 |
struct {
|
|
| 168 |
uint8_t aks : 2; |
|
| 169 |
uint8_t detection_integrator : 6; |
|
| 170 |
}; |
|
| 171 |
} at42qt1050_lld_detectionintegratoraksreg_t; |
|
| 172 |
|
|
| 173 |
/** |
|
| 174 |
* @brief Charge share delay constant sclaing factor. |
|
| 175 |
* @details Values in the charge share delay registers are multiplied by this factor. |
|
| 176 |
* Unit is microseconds (µs). |
|
| 177 |
*/ |
|
| 178 |
#define AT42QT1050_LLD_CHARGESHAREDELAY_FACTOR 2.5f |
|
| 179 |
|
|
| 180 |
/** |
|
| 181 |
* @brief FastIn / FastOutDI / Max Cal / Guard Channel register masks. |
|
| 182 |
*/ |
|
| 183 |
typedef enum {
|
|
| 184 |
AT42QT1050_LLD_FINFOUTMAXCALGUARD_GUARD = 0x0Fu, |
|
| 185 |
AT42QT1050_LLD_FINFOUTMAXCALGUARD_MAXCAL = 0x10u, |
|
| 186 |
AT42QT1050_LLD_FINFOUTMAXCALGUARD_FO = 0x20u, |
|
| 187 |
AT42QT1050_LLD_FINFOUTMAXCALGUARD_FI = 0x40u, |
|
| 188 |
} at42qt1050_lld_finfoutmaxcalguardreg_t; |
|
| 189 |
|
|
| 190 |
/** |
|
| 191 |
* @brief Low power mode constant scaling factor. |
|
| 192 |
* @details The values in the low poer mode register is multiplied by this factor. |
|
| 193 |
* Unit is microseconds (µs). |
|
| 194 |
* @note Setting the power mode scaling register value to zero makes the AT42QT1050 enter deep-sleep mode. |
|
| 195 |
*/ |
|
| 196 |
#define AT42QT1050_LLD_LOWPOWER_FACTOR 8000 |
|
| 197 |
|
|
| 198 |
/** |
|
| 199 |
* @brief Man on duration constant scaling factor. |
|
| 200 |
* @details The value in the max on duration register is multiplied by this factor. |
|
| 201 |
* Unit is microseconds (µs). |
|
| 202 |
*/ |
|
| 203 |
#define AT42QT1050_LLD_MAXONDURATION_FACTOR 160000 |
|
| 204 |
|
|
| 205 |
/** |
|
| 206 |
* @brief RESET / Calibrate register masks. |
|
| 207 |
*/ |
|
| 208 |
typedef enum {
|
|
| 209 |
AT42QT1050_LLD_RESETCALIBRATE_CALIBRATE = 0x7Fu, |
|
| 210 |
AT42QT1050_LLD_RESETCALIBRATE_RESET = 0x80u, |
|
| 211 |
} at42qt1050_lld_resetcalibratereg_t; |
|
| 212 |
|
|
| 213 |
#ifdef __cplusplus |
|
| 214 |
extern "C" {
|
|
| 215 |
#endif |
|
| 216 |
apalExitStatus_t at42qt1050_lld_read_reg(const AT42QT1050Driver* at42qt1050d, const at42qt1050_lld_register_t reg, uint8_t* const data, const apalTime_t timeout); |
|
| 217 |
apalExitStatus_t at42qt1050_lld_write_reg(const AT42QT1050Driver* at42qt1050d, const at42qt1050_lld_register_t reg, const uint8_t data, const apalTime_t timeout); |
|
| 218 |
|
|
| 219 |
apalExitStatus_t at42qt1050_lld_read_keyssignal(const AT42QT1050Driver* at42qt1050d, const uint8_t key, uint16_t* signal, const apalTime_t timeout); |
|
| 220 |
apalExitStatus_t at42qt1050_lld_read_referencedata(const AT42QT1050Driver* at42qt1050d, const uint8_t key, uint16_t* refdata, const apalTime_t timeout); |
|
| 221 |
|
|
| 222 |
uint16_t at42qt1050_lld_pulse2samples(const uint8_t pulse); |
|
| 223 |
float at42qt1050_lld_samples2pulse(const uint16_t samples); |
|
| 224 |
uint16_t at42qt1050_lld_scale2scaling(const uint8_t scale); |
|
| 225 |
float at42qt1050_lld_scaling2scale(const uint16_t factor); |
|
| 226 |
#ifdef __cplusplus |
|
| 227 |
} |
|
| 228 |
#endif |
|
| 229 |
|
|
| 230 |
#endif /* defined(AMIROLLD_CFG_USE_AT42QT1050) */ |
|
| 231 |
|
|
| 232 |
#endif /* _AMIROLLD_AT42QT1050_H_ */ |
|
| 233 |
|
|
| 234 |
/** @} */ |
|
| source/alld_at42qt1050.c | ||
|---|---|---|
| 1 |
/* |
|
| 2 |
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform. |
|
| 3 |
Copyright (C) 2016..2019 Thomas Schöpping et al. |
|
| 4 |
|
|
| 5 |
This program is free software: you can redistribute it and/or modify |
|
| 6 |
it under the terms of the GNU Lesser General Public License as published by |
|
| 7 |
the Free Software Foundation, either version 3 of the License, or |
|
| 8 |
(at your option) any later version. |
|
| 9 |
|
|
| 10 |
This program is distributed in the hope that it will be useful, |
|
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
GNU Lesser General Public License for more details. |
|
| 14 |
|
|
| 15 |
You should have received a copy of the GNU Lesser General Public License |
|
| 16 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
| 17 |
*/ |
|
| 18 |
|
|
| 19 |
/** |
|
| 20 |
* @file alld_at42qt1050.c |
|
| 21 |
* @brief Touch sensor function implementations. |
|
| 22 |
* |
|
| 23 |
* @addtogroup lld_touch |
|
| 24 |
* @{
|
|
| 25 |
*/ |
|
| 26 |
|
|
| 27 |
#include <alld_at42qt1050.h> |
|
| 28 |
|
|
| 29 |
#if defined(AMIROLLD_CFG_USE_AT42QT1050) || defined(__DOXYGEN__) |
|
| 30 |
|
|
| 31 |
#include <math.h> |
|
| 32 |
|
|
| 33 |
/** |
|
| 34 |
* @brief Read 8bit data from any register. |
|
| 35 |
* |
|
| 36 |
* @param[in] at42qt1050d The AT42QT1050 driver to use. |
|
| 37 |
* @param[in] reg Register address to read from. |
|
| 38 |
* @param[out] data Pointer to store the register data to. |
|
| 39 |
* @param[in] timeout Timeout for the function to return (in microseconds). |
|
| 40 |
* |
|
| 41 |
* @return Indicator whether the function call was successful or a timeout occurred. |
|
| 42 |
*/ |
|
| 43 |
inline apalExitStatus_t |
|
| 44 |
at42qt1050_lld_read_reg(const AT42QT1050Driver* at42qt1050d, const at42qt1050_lld_register_t reg, uint8_t* const data, const apalTime_t timeout) |
|
| 45 |
{
|
|
| 46 |
apalDbgAssert(at42qt1050d != NULL && at42qt1050d->i2cd != NULL); |
|
| 47 |
apalDbgAssert(data != NULL); |
|
| 48 |
|
|
| 49 |
const uint8_t txbuf = (uint8_t)reg; |
|
| 50 |
return apalI2CMasterTransmit(at42qt1050d->i2cd, at42qt1050d->addr, &txbuf, 1, data, 1, timeout); |
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
/** |
|
| 54 |
* @brief Write 8bit data to any (writable) register. |
|
| 55 |
* |
|
| 56 |
* @param[in] at42qt1050d The AT42QT1050 driver to use. |
|
| 57 |
* @param[in] reg Register address to write to. |
|
| 58 |
* @param[in] data Data to transmit. |
|
| 59 |
* @param[in] timeout Timeout for the function to return (in microseconds). |
|
| 60 |
* |
|
| 61 |
* @return Indicator whether the function call was successful or a timeout occurred. |
|
| 62 |
*/ |
|
| 63 |
inline apalExitStatus_t |
|
| 64 |
at42qt1050_lld_write_reg(const AT42QT1050Driver* at42qt1050d, const at42qt1050_lld_register_t reg, const uint8_t data, const apalTime_t timeout) |
|
| 65 |
{
|
|
| 66 |
apalDbgAssert(at42qt1050d != NULL && at42qt1050d->i2cd != NULL); |
|
| 67 |
|
|
| 68 |
const uint8_t txbuf[2] = { (uint8_t)reg, data };
|
|
| 69 |
return apalI2CMasterTransmit(at42qt1050d->i2cd, at42qt1050d->addr, txbuf, 2, NULL, 0, timeout); |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
/** |
|
| 73 |
* @brief Read signal information of a key. |
|
| 74 |
* |
|
| 75 |
* @param[in] at42qt1050d The AT42QT1050 driver to use. |
|
| 76 |
* @param[in] key Key to read the signal information of. |
|
| 77 |
* @param[out] signal Pointer to store the data to. |
|
| 78 |
* @param[in] timeout Timeout for the function to return (in microseconds). |
|
| 79 |
* |
|
| 80 |
* @return Indicator whether the function call was successful or a timeout occurred. |
|
| 81 |
*/ |
|
| 82 |
inline apalExitStatus_t |
|
| 83 |
at42qt1050_lld_read_keyssignal(const AT42QT1050Driver* at42qt1050d, const uint8_t key, uint16_t* signal, const apalTime_t timeout) |
|
| 84 |
{
|
|
| 85 |
apalDbgAssert(at42qt1050d != NULL && at42qt1050d->i2cd != NULL); |
|
| 86 |
apalDbgAssert(key < AT42QT1050_LLD_NUM_KEYS); |
|
| 87 |
apalDbgAssert(signal != NULL); |
|
| 88 |
|
|
| 89 |
const uint8_t txbuf = AT42QT1050_LLD_REG_KEYSIGNAL_0 + (2*key) + ((key > 1) ? 1 : 0); |
|
| 90 |
uint8_t rxbuf[2]; |
|
| 91 |
const apalExitStatus_t status = apalI2CMasterTransmit(at42qt1050d->i2cd, at42qt1050d->addr, &txbuf, 1, rxbuf, 2, timeout); |
|
| 92 |
*signal = (rxbuf[0] << 8) | rxbuf[1]; |
|
| 93 |
return status; |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
/** |
|
| 97 |
* @brief Read reference data of a key. |
|
| 98 |
* |
|
| 99 |
* @param[in] at42qt1050d The AT42QT1050 driver to use. |
|
| 100 |
* @param[in] key Key to read the signal information of. |
|
| 101 |
* @param[out] refdata Pointer to store the data to. |
|
| 102 |
* @param[in] timeout Timeout for the function to return (in microseconds). |
|
| 103 |
* |
|
| 104 |
* @return Indicator whether the function call was successful or a timeout occurred. |
|
| 105 |
*/ |
|
| 106 |
inline apalExitStatus_t |
|
| 107 |
at42qt1050_lld_read_referencedata(const AT42QT1050Driver* at42qt1050d, const uint8_t key, uint16_t* refdata, const apalTime_t timeout) |
|
| 108 |
{
|
|
| 109 |
apalDbgAssert(at42qt1050d != NULL && at42qt1050d->i2cd != NULL); |
|
| 110 |
apalDbgAssert(key < AT42QT1050_LLD_NUM_KEYS); |
|
| 111 |
apalDbgAssert(refdata != NULL); |
|
| 112 |
|
|
| 113 |
const uint8_t txbuf = AT42QT1050_LLD_REG_REFERENCEDATA_0 + (2*key) + ((key > 1) ? 1 : 0); |
|
| 114 |
uint8_t rxbuf[2]; |
|
| 115 |
const apalExitStatus_t status = apalI2CMasterTransmit(at42qt1050d->i2cd, at42qt1050d->addr, &txbuf, 1, rxbuf, 2, timeout); |
|
| 116 |
*refdata = (rxbuf[0] << 8) | rxbuf[1]; |
|
| 117 |
return status; |
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
/** |
|
| 121 |
* @brief Convert a 4 bit pulse value to the representing number of samples. |
|
| 122 |
* @details Calculation: <#samples> = 2^(<pulse value>) |
|
| 123 |
* |
|
| 124 |
* @param[in] pulse Pulse value. |
|
| 125 |
* |
|
| 126 |
* @return Resulting sample count. |
|
| 127 |
*/ |
|
| 128 |
inline uint16_t |
|
| 129 |
at42qt1050_lld_pulse2samples(const uint8_t pulse) |
|
| 130 |
{
|
|
| 131 |
apalDbgAssert(pulse <= 0x0Fu); |
|
| 132 |
|
|
| 133 |
return (1 << pulse); |
|
| 134 |
} |
|
| 135 |
|
|
| 136 |
/** |
|
| 137 |
* @brief Convert a desired number of samples to the according (theoretical) pulse value. |
|
| 138 |
* @details Calculation: <pulse value> = log2(<#samples>) |
|
| 139 |
* |
|
| 140 |
* @param[in] samples Desired number of samples. |
|
| 141 |
* |
|
| 142 |
* @return The (theoretical) value to set to the pulse register. |
|
| 143 |
*/ |
|
| 144 |
inline float |
|
| 145 |
at42qt1050_lld_samples2pulse(const uint16_t samples) |
|
| 146 |
{
|
|
| 147 |
return log2f(samples); |
|
| 148 |
} |
|
| 149 |
|
|
| 150 |
/** |
|
| 151 |
* @brief Convert a 4 bit scale value to the accoring scaling factor. |
|
| 152 |
* @details Calculation: <scaling factor> = 2^(<scale value>) |
|
| 153 |
* |
|
| 154 |
* @param[in] scale Scale value. |
|
| 155 |
* |
|
| 156 |
* @return Resulting scaling factor. |
|
| 157 |
*/ |
|
| 158 |
inline uint16_t |
|
| 159 |
at42qt1050_lld_scale2scaling(const uint8_t scale) |
|
| 160 |
{
|
|
| 161 |
apalDbgAssert(scale <= 0x0Fu); |
|
| 162 |
|
|
| 163 |
return (1 << scale); |
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
/** |
|
| 167 |
* @brief Convert a desired scaling factor to the according (theoretical) scale value. |
|
| 168 |
* @details Calculation: <scale value> = log2(<scaling factor> |
|
| 169 |
* ) |
|
| 170 |
* @param[in] factor Desired scaling factor. |
|
| 171 |
* |
|
| 172 |
* @return The (theoretcial) value to set to the scale register. |
|
| 173 |
*/ |
|
| 174 |
inline float |
|
| 175 |
at42qt1050_lld_scaling2scale(const uint16_t factor) |
|
| 176 |
{
|
|
| 177 |
return log2f(factor); |
|
| 178 |
} |
|
| 179 |
|
|
| 180 |
#endif /* defined(AMIROLLD_CFG_USE_AT42QT1050) */ |
|
| 181 |
|
|
| 182 |
/** @} */ |
|
Also available in: Unified diff