34 #include "caplesenseconfig.h"
43 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0
56 1, 1, 1, 1, 1, 1, 1, 1,
58 1, 1, 1, 1, 1, 1, 1, 1
65 static const bool channelsInUse[LESENSE_CHANNELS] = LESENSE_CAPSENSE_CH_IN_USE;
152 .lowPowerReferenceEnabled =
false,
177 static bool init =
true;
180 static uint16_t capsenseCalibrateVals[4];
183 static const LESENSE_ChAll_TypeDef initChsSense = LESENSE_CAPSENSE_SCAN_CONF_SENSE;
185 static const LESENSE_ChAll_TypeDef initChsSleep = LESENSE_CAPSENSE_SCAN_CONF_SLEEP;
187 static const LESENSE_Init_TypeDef initLESENSE =
191 .scanStart = lesenseScanStartPeriodic,
192 .prsSel = lesensePRSCh0,
193 .scanConfSel = lesenseScanConfDirMap,
197 .storeScanRes =
false,
199 .bufTrigLevel = lesenseBufTrigHalf,
200 .wakeupOnDMA = lesenseDMAWakeUpDisable,
201 .biasMode = lesenseBiasModeDutyCycle,
212 .dacCh0Data = lesenseDACIfData,
213 .dacCh0ConvMode = lesenseDACConvModeDisable,
214 .dacCh0OutMode = lesenseDACOutModeDisable,
215 .dacCh1Data = lesenseDACIfData,
216 .dacCh1ConvMode = lesenseDACConvModeDisable,
217 .dacCh1OutMode = lesenseDACOutModeDisable,
219 .dacRef = lesenseDACRefBandGap,
220 .acmp0Mode = lesenseACMPModeMuxThres,
221 .acmp1Mode = lesenseACMPModeMuxThres,
222 .warmupMode = lesenseWarmupModeNormal
227 .decInput = lesenseDecInputSensorSt,
235 .prsChSel0 = lesensePRSCh0,
236 .prsChSel1 = lesensePRSCh1,
237 .prsChSel2 = lesensePRSCh2,
238 .prsChSel3 = lesensePRSCh3
246 LESENSE_Init(&initLESENSE,
true);
256 while (LESENSE_STATUS_SCANACTIVE & LESENSE_StatusGet()) ;
259 LESENSE_ResultBufferClear();
262 (void) LESENSE_ScanFreqSet(0U, 4U);
265 LESENSE_ClkDivSet(lesenseClkLF, lesenseClkDiv_1);
268 LESENSE_ChannelAllConfig(&initChsSleep);
271 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER0_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[0]);
272 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER1_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[1]);
273 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER2_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[2]);
274 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER3_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[3]);
277 LESENSE_IntDisable(LESENSE_IEN_SCANCOMPLETE);
285 while (LESENSE_STATUS_SCANACTIVE & LESENSE_StatusGet()) ;
288 LESENSE_IntClear(LESENSE_IEN_SCANCOMPLETE);
291 LESENSE_ResultBufferClear();
294 (void) LESENSE_ScanFreqSet(0U, 64U);
297 LESENSE_ClkDivSet(lesenseClkLF, lesenseClkDiv_8);
300 LESENSE_ChannelAllConfig(&initChsSense);
303 LESENSE_IntEnable(LESENSE_IEN_SCANCOMPLETE);
307 NVIC_EnableIRQ(LESENSE_IRQn);
320 while (!(LESENSE->STATUS & LESENSE_STATUS_BUFHALFFULL)) ;
323 for (i = 0U; i < CAPLESENSE_NUMOF_SLIDERS; i++)
325 capsenseCalibrateVals[i] = LESENSE_ScanResultDataBufferGet(i) - CAPLESENSE_SENSITIVITY_OFFS;
329 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER0_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[0]);
330 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER1_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[1]);
331 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER2_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[2]);
332 LESENSE_ChannelThresSet(CAPLESENSE_SLIDER3_PIN, CAPLESENSE_ACMP_VDD_SCALE, capsenseCalibrateVals[3]);
358 if (LESENSE_IF_SCANCOMPLETE & LESENSE_IntGetEnabled())
360 LESENSE_IntClear(LESENSE_IF_SCANCOMPLETE);
372 count = LESENSE_ScanResultDataGet();
392 if (CAPLESENSE_CHANNEL_INT & LESENSE_IntGetEnabled())
395 LESENSE_IntClear(CAPLESENSE_CHANNEL_INT);
418 channel = SLIDER_PART0_CHANNEL;
421 channel = SLIDER_PART1_CHANNEL;
424 channel = SLIDER_PART2_CHANNEL;
427 channel = SLIDER_PART3_CHANNEL;
467 uint32_t minVal = 236;
471 uint32_t interpol[6] = { 255, 255, 255, 255, 255, 255 };
472 uint32_t channelPattern[] = { 0, SLIDER_PART0_CHANNEL + 1,
473 SLIDER_PART1_CHANNEL + 1,
474 SLIDER_PART2_CHANNEL + 1,
475 SLIDER_PART3_CHANNEL + 1 };
485 for (i = 1; i < CAPLESENSE_NUMOF_SLIDERS + 1; i++)
491 if (interpol[i] < minVal)
493 minVal = interpol[i];
503 position = (minPos - 1) << 4;
506 position -= ((256 - interpol[minPos - 1]) << 3)
507 / (256 - interpol[minPos]);
510 position += ((256 - interpol[minPos + 1]) << 3)
511 / (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.
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 uint32_t INT_Enable(void)
Enable interrupts.
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.
Interrupt enable/disable unit API.
void CAPLESENSE_setupGPIO(void)
Setup the GPIO.
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.
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
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.
static __INLINE void SystemCoreClockUpdate(void)
Update CMSIS SystemCoreClock variable.
__STATIC_INLINE uint32_t INT_Disable(void)
Disable interrupts.
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.