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;
124 GPIO_DriveModeSet(CAPLESENSE_SLIDER_PORT0, gpioDriveModeStandard);
146 .warmTime = acmpWarmTime512,
149 .lowPowerReferenceEnabled =
false,
174 static bool init =
true;
177 static uint16_t capsenseCalibrateVals[4];
194 .storeScanRes =
false,
210 .dacCh0ConvMode = lesenseDACConvModeDisable,
211 .dacCh0OutMode = lesenseDACOutModeDisable,
213 .dacCh1ConvMode = lesenseDACConvModeDisable,
214 .dacCh1OutMode = lesenseDACOutModeDisable,
216 .dacRef = lesenseDACRefBandGap,
320 for (i = 0U, j = 0U; j < LESENSE_CHANNELS; j++)
324 if (i < CAPLESENSE_NUMOF_SLIDERS)
327 - CAPLESENSE_SENSITIVITY_OFFS;
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.
__STATIC_INLINE uint32_t LESENSE_IntGetEnabled(void)
Get enabled and pending LESENSE interrupt flags.
void CMU_ClockSelectSet(CMU_Clock_TypeDef clock, CMU_Select_TypeDef ref)
Select reference clock/oscillator used for a clock branch.
__STATIC_INLINE void LESENSE_IntClear(uint32_t flags)
Clear one or more pending LESENSE interrupts.
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 LESENSE_Init(const LESENSE_Init_TypeDef *init, bool reqReset)
Initialize the LESENSE module.
void EMU_EnterEM2(bool restore)
Enter energy mode 2 (EM2).
#define LESENSE_STATUS_SCANACTIVE
static void(* lesenseScanCb)(void)
static void(* lesenseChCb)(void)
void LESENSE_ResultBufferClear(void)
Clear result buffer.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
void LESENSE_ChannelThresSet(uint8_t chIdx, uint16_t acmpThres, uint16_t cntThres)
Set LESENSE channel threshold parameters.
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.
#define LESENSE_STATUS_BUFHALFFULL
void CAPLESENSE_setupGPIO(void)
Setup the GPIO.
#define CORE_ENTER_ATOMIC()
uint32_t LESENSE_ScanFreqSet(uint32_t refFreq, uint32_t scanFreq)
Set scan frequency for periodic scanning.
__STATIC_INLINE void LESENSE_IntDisable(uint32_t flags)
Disable one or more LESENSE interrupts.
void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out)
Set the mode for a GPIO pin.
__STATIC_INLINE uint32_t LESENSE_ScanResultDataBufferGet(uint32_t idx)
Get data from the result data buffer.
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.
__STATIC_INLINE uint32_t LESENSE_StatusGet(void)
Get the current status of LESENSE.
void LESENSE_ClkDivSet(LESENSE_ChClk_TypeDef clk, LESENSE_ClkPresc_TypeDef clkDiv)
Set clock division for LESENSE timers.
void CAPLESENSE_setupCMU(void)
Setup the CMU.
void CAPLESENSE_setupLESENSE(bool sleep)
Setup the LESENSE for capavitive sensing.
Core interrupt handling API.
void LESENSE_ChannelAllConfig(const LESENSE_ChAll_TypeDef *confChAll)
Configure all (16) LESENSE sensor channels.
void CMU_ClockEnable(CMU_Clock_TypeDef clock, bool enable)
Enable/disable a clock.
#define LESENSE_IF_SCANCOMPLETE
#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.
LESENSE_CoreCtrlDesc_TypeDef coreCtrl
LESENSE_ScanMode_TypeDef scanStart
__STATIC_INLINE uint32_t LESENSE_ScanResultDataGet(void)
Get the oldest unread data from the result buffer.
#define LESENSE_IEN_SCANCOMPLETE
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.
void LESENSE_ScanStart(void)
Start scanning of sensors.
void LESENSE_ScanStop(void)
Stop scanning of sensors.
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.
__STATIC_INLINE void LESENSE_IntEnable(uint32_t flags)
Enable one or more LESENSE interrupts.
void CMU_ClockDivSet(CMU_Clock_TypeDef clock, CMU_ClkDiv_TypeDef div)
Set clock divisor/prescaler.