31 #include "caplesenseconfig.h"
40 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0
53 1, 1, 1, 1, 1, 1, 1, 1,
55 1, 1, 1, 1, 1, 1, 1, 1
62 static const bool channelsInUse[LESENSE_CHANNELS] = LESENSE_CAPSENSE_CH_IN_USE;
149 .lowPowerReferenceEnabled =
false,
174 static bool init =
true;
177 static uint16_t capsenseCalibrateVals[4];
180 static const LESENSE_ChAll_TypeDef initChsSense = LESENSE_CAPSENSE_SCAN_CONF_SENSE;
182 static const LESENSE_ChAll_TypeDef initChsSleep = LESENSE_CAPSENSE_SCAN_CONF_SLEEP;
184 static const LESENSE_Init_TypeDef initLESENSE =
188 .scanStart = lesenseScanStartPeriodic,
189 .prsSel = lesensePRSCh0,
190 .scanConfSel = lesenseScanConfDirMap,
194 .storeScanRes =
false,
196 .bufTrigLevel = lesenseBufTrigHalf,
197 .wakeupOnDMA = lesenseDMAWakeUpDisable,
198 .biasMode = lesenseBiasModeDutyCycle,
209 .dacCh0Data = lesenseDACIfData,
210 .dacCh0ConvMode = lesenseDACConvModeDisable,
211 .dacCh0OutMode = lesenseDACOutModeDisable,
212 .dacCh1Data = lesenseDACIfData,
213 .dacCh1ConvMode = lesenseDACConvModeDisable,
214 .dacCh1OutMode = lesenseDACOutModeDisable,
216 .dacRef = lesenseDACRefBandGap,
217 .acmp0Mode = lesenseACMPModeMuxThres,
218 .acmp1Mode = lesenseACMPModeMuxThres,
219 .warmupMode = lesenseWarmupModeNormal
224 .decInput = lesenseDecInputSensorSt,
232 .prsChSel0 = lesensePRSCh0,
233 .prsChSel1 = lesensePRSCh1,
234 .prsChSel2 = lesensePRSCh2,
235 .prsChSel3 = lesensePRSCh3
243 LESENSE_Init(&initLESENSE,
true);
253 while (LESENSE_STATUS_SCANACTIVE & LESENSE_StatusGet()) ;
256 LESENSE_ResultBufferClear();
259 (void) LESENSE_ScanFreqSet(0U, 4U);
262 LESENSE_ClkDivSet(lesenseClkLF, lesenseClkDiv_1);
265 LESENSE_ChannelAllConfig(&initChsSleep);
268 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER0_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[0]);
269 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER1_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[1]);
270 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER2_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[2]);
271 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER3_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[3]);
274 LESENSE_IntDisable(LESENSE_IEN_SCANCOMPLETE);
282 while (LESENSE_STATUS_SCANACTIVE & LESENSE_StatusGet()) ;
285 LESENSE_IntClear(LESENSE_IEN_SCANCOMPLETE);
288 LESENSE_ResultBufferClear();
291 (void) LESENSE_ScanFreqSet(0U, 64U);
294 LESENSE_ClkDivSet(lesenseClkLF, lesenseClkDiv_8);
297 LESENSE_ChannelAllConfig(&initChsSense);
300 LESENSE_IntEnable(LESENSE_IEN_SCANCOMPLETE);
304 NVIC_EnableIRQ(LESENSE_IRQn);
317 while (!(LESENSE->STATUS & LESENSE_STATUS_BUFHALFFULL)) ;
320 for (i = 0U, j = 0U; j < LESENSE_CHANNELS; j++)
324 if (i < CAPLESENSE_NUMOF_SLIDERS)
326 capsenseCalibrateVals[i] = LESENSE_ScanResultDataBufferGet(j)
327 - CAPLESENSE_SENSITIVITY_OFFS;
334 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER0_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[0]);
335 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER1_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[1]);
336 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER2_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[2]);
337 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER3_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[3]);
363 if (LESENSE_IF_SCANCOMPLETE & LESENSE_IntGetEnabled())
365 LESENSE_IntClear(LESENSE_IF_SCANCOMPLETE);
377 count = LESENSE_ScanResultDataGet();
397 if (CAPLESENSE_CHANNEL_INT & LESENSE_IntGetEnabled())
400 LESENSE_IntClear(CAPLESENSE_CHANNEL_INT);
423 channel = SLIDER_PART0_CHANNEL;
426 channel = SLIDER_PART1_CHANNEL;
429 channel = SLIDER_PART2_CHANNEL;
432 channel = SLIDER_PART3_CHANNEL;
472 uint32_t minVal = 236;
476 uint32_t interpol[6] = { 255, 255, 255, 255, 255, 255 };
477 uint32_t channelPattern[] = { 0, SLIDER_PART0_CHANNEL + 1,
478 SLIDER_PART1_CHANNEL + 1,
479 SLIDER_PART2_CHANNEL + 1,
480 SLIDER_PART3_CHANNEL + 1 };
490 for (i = 1; i < CAPLESENSE_NUMOF_SLIDERS + 1; i++)
496 if (interpol[i] < minVal)
498 minVal = interpol[i];
508 position = (minPos - 1) << 4;
511 position -= ((256 - interpol[minPos - 1]) << 3)
512 / (256 - interpol[minPos]);
515 position += ((256 - interpol[minPos + 1]) << 3)
516 / (256 - interpol[minPos]);
Clock management unit (CMU) API.
void CMU_ClockSelectSet(CMU_Clock_TypeDef clock, CMU_Select_TypeDef ref)
Select reference clock/oscillator used for a clock branch.
uint32_t CAPLESENSE_getVal(uint8_t channel)
Get the current channelValue for a channel.
#define CORE_DECLARE_IRQ_STATE
Emlib peripheral API "assert" implementation.
void CAPLESENSE_Sleep(void)
Send the capacative sense system to sleep mode.
uint32_t CAPLESENSE_getNormalizedVal(uint8_t channel)
Get the current normalized channelValue for a channel.
static volatile uint8_t currentChannel
static __INLINE void SystemCoreClockUpdate(void)
Update CMSIS SystemCoreClock variable.
void EMU_EnterEM2(bool restore)
Enter energy mode 2 (EM2).
static void(* lesenseScanCb)(void)
static void(* lesenseChCb)(void)
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
void CAPLESENSE_setupCallbacks(void(*scanCb)(void), void(*chCb)(void))
LESENSE callback setup.
void LESENSE_IRQHandler(void)
LESENSE interrupt handler.
void CAPLESENSE_setupACMP(void)
Setup the ACMP.
void CAPLESENSE_setupGPIO(void)
Setup the GPIO.
#define CORE_ENTER_ATOMIC()
void GPIO_DriveModeSet(GPIO_Port_TypeDef port, GPIO_DriveMode_TypeDef mode)
Sets the drive mode for a GPIO port.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
void ACMP_CapsenseInit(ACMP_TypeDef *acmp, const ACMP_CapsenseInit_TypeDef *init)
Sets up the ACMP for use in capacative sense applications.
General Purpose IO (GPIO) peripheral API.
void CAPLESENSE_setupCMU(void)
Setup the CMU.
void CAPLESENSE_setupLESENSE(bool sleep)
Setup the LESENSE for capavitive sensing.
Core interrupt handling API.
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
#define CORE_EXIT_ATOMIC()
static const bool channelsInUse[LESENSE_CHANNELS]
A bit vector which represents the channels to iterate through.
int32_t CAPLESENSE_getSliderPosition(void)
Get the position of the slider.
Analog Comparator (ACMP) peripheral API.
Energy management unit (EMU) peripheral API.
static volatile uint32_t channelValues[LESENSE_CHANNELS]
This vector stores the latest read values from LESENSE.
Low Energy Sensor (LESENSE) peripheral API.
void CAPLESENSE_Init(bool sleep)
Initializes the capacative sense system without LESENSE.
static volatile uint32_t channelMaxValues[LESENSE_CHANNELS]
This stores the maximum values seen by a channel.
uint8_t CAPLESENSE_getSegmentChannel(uint8_t capSegment)
Get the channelValue for a sensor segment.
void ACMP_GPIOSetup(ACMP_TypeDef *acmp, uint32_t location, bool enable, bool invert)
Sets up GPIO output from the ACMP.
void CMU_ClockDivSet(CMU_Clock_TypeDef clock, CMU_ClkDiv_TypeDef div)
Set clock divisor/prescaler.