LESENSE - Low Energy Sensor Interface#
Low Energy Sensor Interface (LESENSE) Peripheral API.
This module contains functions to control the LESENSE peripheral of Silicon Labs 32-bit MCUs and SoCs. LESENSE is a low energy sensor interface which utilizes on-chip peripherals to perform measurement of a configurable set of sensors
Example#
This example demonstrates initialization, basic configuration, and usage of the LESENSE peripheral. It shows how to:
Initialize the LESENSE with default settings to sample a single channel. LESENSE uses ACMP to sample input state of a button 0 and will trigger an interrupt to toggle LED0.
#include "sl_hal_lesense.h"
#include "sl_hal_acmp.h"
#include "sl_hal_gpio.h"
#include "sl_clock_manager.h"
sl_gpio_t led0 = {LED0_PORT, LED0_PIN};
void init_gpio(void)
{
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_GPIO);
sl_hal_gpio_set_pin_mode(&led0, SL_GPIO_MODE_PUSH_PULL, 0);
}
void init_ACMP(void)
{
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_ACMP0);
sl_hal_acmp_init_t amcp_init = SL_HAL_ACMP_INIT_DEFAULT;
sl_hal_acmp_init(ACMP0, &amcp_init);
if (BTN0_PIN % 2 == 0) {
GPIO->BBUSALLOC_SET = GPIO_BBUSALLOC_BEVEN0_ACMP0;
} else {
GPIO->BBUSALLOC_SET = GPIO_BBUSALLOC_BODD0_ACMP0;
}
sl_hal_acmp_enable(ACMP0);
// Set 1.25V internal as reference voltage for ACMP negative input and port B external interface override.
sl_hal_acmp_set_input(ACMP0, SL_HAL_ACMP_INPUT_VREFDIV1V25, SL_HAL_ACMP_INPUT_EXTPB);
// Wait for warm-up.
while (!(ACMP0->STATUS & ACMP_IF_ACMPRDY));
}
void lesense_acmp_example(void)
{
init_gpio();
init_ACMP();
// Initialize configuration structure with default settings
sl_hal_lesense_init_t init = SL_HAL_LESENSE_INIT_DEFAULT;
sl_hal_lesense_channel_descriptor_t lesense_channel = SL_HAL_LESENSE_CHANNEL_CONFIG_DEFAULT;
uint32_t reference_freq;
// Enable clock.
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_LFRCO);
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_LESENSE);
sl_clock_manager_enable_bus_clock(SL_BUS_CLOCK_PRS);
// Get the frequency of LFRCO for LESENSE reference.
sl_clock_manager_get_oscillator_frequency(SL_OSCILLATOR_LFRCO, &reference_freq);
// Do not store scan result and invert ACMP0 to accommodate PB0 pull-up.
init.core_control.store_scanres = false;
init.core_control.invert_acmp0 = true;
// Enable LESENSE control of ACMP0 positive input mux.
init.per_control.acmp0_mode = SL_HAL_LESENSE_ACMP_MODE_MUX;
// Config lesense channel.
lesense_channel.enable_scan = true;
lesense_channel.enable_interrupt = true;
lesense_channel.sample_mode = SL_HAL_LESENSE_SAMPLE_MODE_ACMP;
lesense_channel.interrupt_mode = SL_HAL_LESENSE_SET_INTERRUPT_POSITIVE_EDGE;
lesense_channel.offset = PB0_PIN; // push button pin number.
// Initialize and enable LESENSE with default settings.
sl_hal_lesense_init(&init);
// Config channel 0.
sl_hal_lesense_channel_config(&lesense_channel, 0);
// Get 32 samples per second.
sl_hal_lesense_disable();
sl_hal_lesense_set_scan_frequency(reference_freq, 32);
// Start LESENSE scanning.
sl_hal_lesense_enable();
sl_hal_lesense_start_scan();
// Enable interrupt in NVIC.
NVIC_ClearPendingIRQ(LESENSE_IRQn);
NVIC_EnableIRQ(LESENSE_IRQn);
}
void LESENSE_IRQHandler(void)
{
// Clear all LESENSE interrupt flag
uint32_t flags = sl_hal_lesense_get_pending_interrupts();
sl_hal_lesense_clear_interrupts(flags);
// Toggle LED0.
if (flags & LESENSE_IF_CH0) {
sl_hal_gpio_toggle_pin(&led0);
}
}
Modules#
sl_hal_lesense_core_descriptor_t
sl_hal_lesense_timing_descriptor_t
sl_hal_lesense_peripheral_descriptor_t
sl_hal_lesense_decoder_descriptor_t
sl_hal_lesense_channel_descriptor_t
sl_hal_lesense_channel_alternate_excitation_t
sl_hal_lesense_transition_arc_t
sl_hal_lesense_all_transition_arcs_t
Enumerations#
Clock divisors for controlling the prescaling factor of the period counter.
Scan modes.
PRS sources.
Scan configuration.
DAC CHx data control configuration.
ACMPx control configuration.
Compare source selection for sensor sampling.
Interrupt generation setup for CHx interrupt flag.
Channel pin mode for the excitation phase of the scan sequence.
Channel pin mode for the idle phase of scan sequence.
Clock used for excitation and sample delay timing.
Compare modes for counter comparison.
Mode of Storing of Sensor Sample in Result Buffer.
Sensor evaluation modes.
Transition action modes.
Functions#
Initialize the LESENSE module.
Set the scan frequency for periodic scanning.
Set the clock division for LESENSE timers.
Configure all (16) LESENSE sensor channels.
Configure a single LESENSE sensor channel.
Enable/disable LESENSE scan channel and the pin assigned to it.
Enable/disable LESENSE scan channel and the pin assigned to it.
Set LESENSE channel threshold parameters.
Configure a Sliding Window evaluation mode for a specific channel.
Configure the step detection evaluation mode for a specific channel.
Configure the LESENSE alternate excitation modes.
Configure all LESENSE transition ARCs.
Enable the LESENSE module.
Wait for ongoing sync of register(s) to complete before writing to any other register.
Wait for disabling to finish.
Disable the LESENSE module.
Start the LESENSE decoder.
Stop LESENSE decoder.
Set scan mode of the LESENSE channels.
Start scanning sensors.
Stop scanning sensors.
Set the start delay of the sensor interaction on each channel.
Set the window size for all LESENSE channels.
Set the step size for all LESENSE channels.
Configure a single LESENSE transition ARC.
Enable the PRS output from the LESENSE decoder.
Disable the PRS output from the LESENSE decoder.
Get the current status of LESENSE.
Set LESENSE channel timing parameters.
Wait until status of LESENSE is equal to what was requested.
Get the currently active channel index.
Get the latest scan comparison result (1 bit / channel).
Get the oldest unread data from the result buffer.
Clear the result buffer.
Get the current state of the LESENSE decoder.
Get the current state of the LESENSE sensor.
Reset the LESENSE module.
Clear one or more pending LESENSE interrupts.
Enable one or more LESENSE interrupts.
Disable one or more LESENSE interrupts.
Set one or more pending LESENSE interrupts from SW.
Get pending LESENSE interrupt flags.
Get enabled and pending LESENSE interrupt flags.
Macros#
Number of ARCs supported by current device. Number of ARCS is the number of states times 2.
Number of LESENSE channels.
Default value for the FIFO trigger level.
Default configuration for sl_hal_lesense_core_descriptor_t structure.
Default configuration for sl_hal_lesense_peripheral_descriptor_t structure.
Default configuration for sl_hal_lesense_timing_descriptor_t structure.
Default configuration for sl_hal_lesense_decoder_descriptor_t structure.
Default configuration for sl_hal_lesense_init_t structure.
Default configuration for the scan channel.
Default configuration for all the sensor channels.
Default configuration for all the alternate excitation channels.
Default configuration for the decoder state condition.
Default configuration for all decoder states.
Enumeration Documentation#
sl_hal_lesense_clock_prescale_t#
sl_hal_lesense_clock_prescale_t
Clock divisors for controlling the prescaling factor of the period counter.
Note
These enumeration values are used for different clock division related configuration parameters.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_CLOCK_DIV1 | Divide clock by 1. |
| SL_HAL_LESENSE_CLOCK_DIV2 | Divide clock by 2. |
| SL_HAL_LESENSE_CLOCK_DIV4 | Divide clock by 4. |
| SL_HAL_LESENSE_CLOCK_DIV8 | Divide clock by 8. |
| SL_HAL_LESENSE_CLOCK_DIV16 | Divide clock by 16. |
| SL_HAL_LESENSE_CLOCK_DIV32 | Divide clock by 32. |
| SL_HAL_LESENSE_CLOCK_DIV64 | Divide clock by 64. |
| SL_HAL_LESENSE_CLOCK_DIV128 | Divide clock by 128. |
sl_hal_lesense_scan_mode_t#
sl_hal_lesense_scan_mode_t
Scan modes.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_SCAN_START_PERIODIC | New scan is started each time the period counter overflows. |
| SL_HAL_LESENSE_SCAN_START_ONESHOT | Single scan is performed when sl_hal_lesense_start_scan() is called. |
| SL_HAL_LESENSE_SCAN_START_PRS | New scan is triggered by pulse on PRS channel. |
sl_hal_lesense_prs_source_t#
sl_hal_lesense_prs_source_t
PRS sources.
Note
These enumeration values are being used for different PRS related. configuration parameters.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_PRS_CHANNEL_0 | PRS channel 0. |
| SL_HAL_LESENSE_PRS_CHANNEL_1 | PRS channel 1. |
| SL_HAL_LESENSE_PRS_CHANNEL_2 | PRS channel 2. |
| SL_HAL_LESENSE_PRS_CHANNEL_3 | PRS channel 3. |
| SL_HAL_LESENSE_PRS_CHANNEL_4 | PRS channel 4. |
| SL_HAL_LESENSE_PRS_CHANNEL_5 | PRS channel 5. |
| SL_HAL_LESENSE_PRS_CHANNEL_6 | PRS channel 6. |
| SL_HAL_LESENSE_PRS_CHANNEL_7 | PRS channel 7. |
| SL_HAL_LESENSE_PRS_CHANNEL_8 | PRS channel 8. |
| SL_HAL_LESENSE_PRS_CHANNEL_9 | PRS channel 9. |
| SL_HAL_LESENSE_PRS_CHANNEL_10 | PRS channel 10. |
| SL_HAL_LESENSE_PRS_CHANNEL_11 | PRS channel 11. |
sl_hal_lesense_scan_config_t#
sl_hal_lesense_scan_config_t
Scan configuration.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_SCAN_CONFIG_DIRECTLY_MAP | Channel configuration registers (CHx_CONF) used are directly mapped to the channel number. |
| SL_HAL_LESENSE_SCAN_CONFIG_INV_MAP | Channel configuration registers used are CHx+8_CONF for channels 0-7 and CHx-8_CONF for channels 8-15. |
| SL_HAL_LESENSE_SCAN_CONFIG_TOGGLE | Channel configuration registers used toggles between CHX_SCANCONF and CHX+8_SCANCONF when channel x triggers. |
| SL_HAL_LESENSE_SCAN_CONFIG_DECODER_DEFINES | Decoder state defines the channel configuration register (CHx_CONF) to be used. |
sl_hal_lesense_control_dac_data_t#
sl_hal_lesense_control_dac_data_t
DAC CHx data control configuration.
Note
This value could be used for both DAC Ch0 and Ch1.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_DAC_CH_DATA | DAC channel x data is defined by the DAC_CH0DATA register. |
| SL_HAL_LESENSE_DAC_THRES | DAC channel x data is defined by the THRES in LESENSE_CHx_INTERACT. |
sl_hal_lesense_control_acmp_t#
sl_hal_lesense_control_acmp_t
ACMPx control configuration.
Note
This value could be used for both ACMP0 and ACMP1.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_ACMP_MODE_MUX | ACMPx is controlled by LESENSE input mux. |
| SL_HAL_LESENSE_ACMP_MODE_MUXTHRES | ACMPx is controlled by LESENSE input mux and threshold value. |
sl_hal_lesense_channel_sample_t#
sl_hal_lesense_channel_sample_t
Compare source selection for sensor sampling.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_SAMPLE_MODE_ACMP_COUNT | ACMP Counter output will be used in comparison. |
| SL_HAL_LESENSE_SAMPLE_MODE_ACMP | ACMP output will be used in comparison. |
| SL_HAL_LESENSE_SAMPLE_MODE_ADC | ADC output will be used in comparison. |
| SL_HAL_LESENSE_SAMPLE_MODE_ADC_DIFF | Differential ADC output will be used in comparison. |
sl_hal_lesense_channel_interrupt_t#
sl_hal_lesense_channel_interrupt_t
Interrupt generation setup for CHx interrupt flag.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_SET_INTERRUPT_NONE | No interrupt is generated. |
| SL_HAL_LESENSE_SET_INTERRUPT_LEVEL | Set interrupt flag if the sensor triggers. |
| SL_HAL_LESENSE_SET_INTERRUPT_POSITIVE_EDGE | Set interrupt flag on positive edge of the sensor state. |
| SL_HAL_LESENSE_SET_INTERRUPT_NEGATIVE_EDGE | Set interrupt flag on negative edge of the sensor state. |
| SL_HAL_LESENSE_SET_INTERRUPT_BOTH_EDGE | Set interrupt flag on both edges of the sensor state. |
sl_hal_lesense_pin_excitation_phase_t#
sl_hal_lesense_pin_excitation_phase_t
Channel pin mode for the excitation phase of the scan sequence.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_CHANNEL_PIN_EXCITATION_DISABLE | Channel pin is disabled. |
| SL_HAL_LESENSE_CHANNEL_PIN_EXCITATION_HIGH | Channel pin is configured as push-pull, driven HIGH. |
| SL_HAL_LESENSE_CHANNEL_PIN_EXCITATION_LOW | Channel pin is configured as push-pull, driven LOW. |
| SL_HAL_LESENSE_CHANNEL_PIN_EXCITATION_DAC_OUTPUT | DAC output (only available on channel 0, 1, 2, 3, 12, 13, 14 and 15). |
sl_hal_lesense_pin_idle_mode_t#
sl_hal_lesense_pin_idle_mode_t
Channel pin mode for the idle phase of scan sequence.
Note
This value could be used for all channels.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_CHANNEL_PIN_IDLE_DISABLE | Channel pin is disabled in idle phase. |
| SL_HAL_LESENSE_CHANNEL_PIN_IDLE_HIGH | Channel pin is configured as push-pull, driven HIGH in idle phase. |
| SL_HAL_LESENSE_CHANNEL_PIN_IDLE_LOW | Channel pin is configured as push-pull, driven LOW in idle phase. |
| SL_HAL_LESENSE_CHANNEL_PIN_IDLE_DAC | Channel pin is connected to DAC output in idle phase. |
sl_hal_lesense_excitation_clock_t#
sl_hal_lesense_excitation_clock_t
Clock used for excitation and sample delay timing.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_EXCITATION_TIMING_LFACLK | LFACLK (LF clock) is used. |
| SL_HAL_LESENSE_EXCITATION_TIMING_AUXHFRCO | AUXHFRCO (HF clock) is used. |
sl_hal_lesense_compare_counter_t#
sl_hal_lesense_compare_counter_t
Compare modes for counter comparison.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_COMPARE_MODE_LESS | Evaluates to 1 if sensor data is less than counter threshold, or if ACMP output is 0. |
| SL_HAL_LESENSE_COMPARE_MODE_GREATER_OR_EQUAL | Evaluates to 1 if sensor data is greater than, or equal to counter threshold, or if the ACMP output is 1. |
sl_hal_lesense_store_sample_data_t#
sl_hal_lesense_store_sample_data_t
Mode of Storing of Sensor Sample in Result Buffer.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_STORE_SAMPLE_DISABLE | Nothing will be stored in the result buffer. |
| SL_HAL_LESENSE_STORE_SAMPLE_DATA | The sensor sample data will be stored in the result buffer. |
| SL_HAL_LESENSE_STORE_SAMPLE_DATA_SOURCE | The data source (i.e. the channel) will be stored alongside the sensor sample data. |
sl_hal_lesense_sensor_evaluation_t#
sl_hal_lesense_sensor_evaluation_t
Sensor evaluation modes.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_EVALUATION_MODE_THRESHOLD | Threshold comparison evaluation mode. |
| SL_HAL_LESENSE_EVALUATION_MODE_SLIDING_WINDOW | Sliding window evaluation mode. |
| SL_HAL_LESENSE_EVALUATION_MODE_STEP_DETECTION | Step detection evaluation mode. |
sl_hal_lesense_transition_action_t#
sl_hal_lesense_transition_action_t
Transition action modes.
| Enumerator | |
|---|---|
| SL_HAL_LESENSE_TRANSITION_ACTION_NONE | No PRS pulses generated (if PRSCOUNT == 0). Do not count (if PRSCOUNT == 1). |
| SL_HAL_LESENSE_TRANSITION_ACTION_PRS0 | Generate pulse on LESPRS0 (if PRSCOUNT == 0). |
| SL_HAL_LESENSE_TRANSITION_ACTION_PRS1 | Generate pulse on LESPRS1 (if PRSCOUNT == 0). |
| SL_HAL_LESENSE_TRANSITION_ACTION_PRS01 | Generate pulse on LESPRS0 and LESPRS1 (if PRSCOUNT == 0). |
| SL_HAL_LESENSE_TRANSITION_ACTION_PRS2 | Generate pulse on LESPRS2 (for both PRSCOUNT == 0 and PRSCOUNT == 1). |
| SL_HAL_LESENSE_TRANSITION_ACTION_PRS02 | Generate pulse on LESPRS0 and LESPRS2 (if PRSCOUNT == 0). |
| SL_HAL_LESENSE_TRANSITION_ACTION_PRS12 | Generate pulse on LESPRS1 and LESPRS2 (if PRSCOUNT == 0). |
| SL_HAL_LESENSE_TRANSITION_ACTION_PRS012 | Generate pulse on LESPRS0, LESPRS1, and LESPRS2 (if PRSCOUNT == 0). |
| SL_HAL_LESENSE_TRANSITION_ACTION_COUNT_UP | Count up (if PRSCOUNT == 1). |
| SL_HAL_LESENSE_TRANSITION_ACTION_COUNT_DOWN | Count down (if PRSCOUNT == 1). |
| SL_HAL_LESENSE_TRANSITION_ACTION_COUNT_UP_PRS2 | Count up and generate pulse on LESPRS2 (if PRSCOUNT == 1). |
| SL_HAL_LESENSE_TRANSITION_ACTION_COUNT_DOWN_PRS2 | Count down and generate pulse on LESPRS2 (if PRSCOUNT == 1). |
Function Documentation#
sl_hal_lesense_init#
void sl_hal_lesense_init (const sl_hal_lesense_init_t * init)
Initialize the LESENSE module.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| const sl_hal_lesense_init_t * | [in] | init | The LESENSE initialization structure. |
This function configures the main parameters of the LESENSE interface. See the initialization parameter type definition (sl_hal_lesense_init_t) for more details.
Note
Function sl_hal_lesense_init() is designed to initialize LESENSE once in an operation cycle. Be aware of the effects of reconfiguration if using this function from multiple sources in your code. This function has not been designed to be re-entrant. Notice that GPIO pins used by the LESENSE module must be properly configured by the user explicitly for the LESENSE to work as intended. (When configuring pins, one should remember to consider the sequence of configuration to avoid unintended pulses/glitches on output pins.) LESENSE needs to be disabled before configuring any register.
sl_hal_lesense_set_scan_frequency#
uint32_t sl_hal_lesense_set_scan_frequency (uint32_t reference_frequency, uint32_t scan_frequency)
Set the scan frequency for periodic scanning.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | reference_frequency | Select reference LFACLK clock frequency in Hz. |
| uint32_t | [in] | scan_frequency | Set the desired scan frequency in Hz. |
This function only applies to LESENSE if a period counter is used as a trigger for scan start. The calculation is based on the following formula: Fscan = LFACLKles / ((1+PCTOP)*2^PCPRESC)
Note
Note that the calculation does not necessarily result in the requested scan frequency due to integer division. Check the return value for the resulted scan frequency. LESENSE needs to be disabled before configuring any register.
Returns
Frequency in Hz calculated and set by this function. Users can use this to compare the requested and set values.
sl_hal_lesense_set_clock_division#
void sl_hal_lesense_set_clock_division (sl_hal_lesense_excitation_clock_t clock, sl_hal_lesense_clock_prescale_t clock_divisor)
Set the clock division for LESENSE timers.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_hal_lesense_excitation_clock_t | [in] | clock | Select the clock to prescale. |
| sl_hal_lesense_clock_prescale_t | [in] | clock_divisor | The clock divisor value. A valid range depends on the |
Use this function to configure the clock division for the LESENSE timers used for excitation timing. The division setting is global but the clock source can be selected for each channel using sl_hal_lesense_channel_config() function. See documentation for more details.
Note
If AUXHFRCO is used for excitation timing, LFACLK can't exceed 500 kHz. LFACLK can't exceed 50 kHz if the ACMP threshold level (ACMPTHRES) is not equal for all channels. LESENSE needs to be disabled before configuring any register.
SL_HAL_LESENSE_EXCITATION_TIMING_AUXHFRCO - set AUXHFRCO clock divisor for HF timer.
SL_HAL_LESENSE_EXCITATION_TIMING_LFACLK - set LFACLKles clock divisor for LF timer.
sl_hal_lesense_channel_config_all#
void sl_hal_lesense_channel_config_all (const sl_hal_lesense_channel_all_t * config_all_channel)
Configure all (16) LESENSE sensor channels.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| const sl_hal_lesense_channel_all_t * | [in] | config_all_channel | A configuration structure for all (16) LESENSE sensor channels. |
This function configures all sensor channels of the LESENSE interface. See the configuration parameter type definition (sl_hal_lesense_channel_all_t) for more details.
Note
Channels can be configured individually using sl_hal_lesense_channel_config() function. Notice that pins used by the LESENSE module must be properly configured by the user explicitly for LESENSE to work as intended. (When configuring pins, consider the sequence of the configuration to avoid unintended pulses/glitches on output pins.)
sl_hal_lesense_channel_config#
void sl_hal_lesense_channel_config (const sl_hal_lesense_channel_descriptor_t * config_channel, uint32_t channel_index)
Configure a single LESENSE sensor channel.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| const sl_hal_lesense_channel_descriptor_t * | [in] | config_channel | A configuration structure for a single LESENSE sensor channel. |
| uint32_t | [in] | channel_index | A channel index to configure (0-15). |
This function configures a single sensor channel of the LESENSE interface. See the configuration parameter type definition (sl_hal_lesense_channel_descriptor_t) for more details.
Note
This function has been designed to minimize the effects of sensor channel reconfiguration while LESENSE is in operation. However, be aware of these effects and the right timing to call this function. Parameter
pin_alternate_excitemust be true in the channel configuration to use alternate excitation pins. LESENSE needs to be disabled before configuring any register.
sl_hal_lesense_channel_enable#
void sl_hal_lesense_channel_enable (uint8_t channel_index, bool enable_scan_channel, bool enable_pin)
Enable/disable LESENSE scan channel and the pin assigned to it.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint8_t | [in] | channel_index | An identifier of the scan channel. A valid range: 0-15. |
| bool | [in] | enable_scan_channel | Enable/disable the selected scan channel by setting this parameter to true/false respectively. |
| bool | [in] | enable_pin | Enable/disable the pin assigned to the channel selected by |
Use this function to enable/disable a selected LESENSE scan channel and the pin assigned to it.
Note
Users can enable/disable scan channels and the channel pin with the sl_hal_lesense_channel_config() function, but only with a significant overhead. This simple function controls these parameters after the channel has been configured.
sl_hal_lesense_channel_enable_mask#
void sl_hal_lesense_channel_enable_mask (uint16_t channel_mask, uint16_t pin_mask)
Enable/disable LESENSE scan channel and the pin assigned to it.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint16_t | [in] | channel_mask | Set the corresponding bit to 1 to enable, 0 to disable the selected scan channel. |
| uint16_t | [in] | pin_mask | Set the corresponding bit to 1 to enable, 0 to disable the pin on selected channel. |
Use this function to enable/disable LESENSE scan channels and the pins assigned to them using a mask.
Note
Users can enable/disable scan channels and channel pins by using the sl_hal_lesense_channel_config_all() function, but only with a significant overhead. This function controls these parameters after the channel has been configured.
sl_hal_lesense_channel_set_threshold#
void sl_hal_lesense_channel_set_threshold (uint8_t channel_index, uint16_t acmp_threshold, uint16_t count_threshold)
Set LESENSE channel threshold parameters.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint8_t | [in] | channel_index | A decision threshold for counter comparison. A valid range is 0-65535 (16 bits). |
| uint16_t | [in] | acmp_threshold | ACMP threshold. |
| uint16_t | N/A | count_threshold |
Use this function to set threshold parameters on a selected LESENSE channel.
Note
Users can configure the channel threshold parameters with the sl_hal_lesense_channel_config() function, but only with a significant overhead. This function serves controls these parameters after the channel has been configured. LESENSE needs to be disabled before configuring INTERACT register and needs to be enabled when configuring EVALTHRES register.
If per_control.dac_channel0_data is set to SL_HAL_LESENSE_DAC_CH_DATA, acmp_threshold defines the 12-bit DAC data in the corresponding data register of the DAC interface (DACn_CH0DATA and DACn_CH1DATA). In this case, the valid range is 0-4095 (12 bits).
sl_hal_lesense_channel_config_sliding_window#
void sl_hal_lesense_channel_config_sliding_window (uint8_t channel_index, uint32_t window_size, uint32_t init_value)
Configure a Sliding Window evaluation mode for a specific channel.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint8_t | [in] | channel_index | An identifier of the scan channel. A valid range is 0-15. |
| uint32_t | [in] | window_size | A window size to be used on all channels. |
| uint32_t | [in] | init_value | The initial sensor value for the channel. |
This function will configure the evaluation mode, the initial sensor measurement (COMPTHRES), and the window size. For other channel-related configuration, see the sl_hal_lesense_channel_config() function.
Note
LESENSE needs to be disabled before configuring EVALCFG register and needs to be enabled when configuring EVALTHRES register.
Warnings
Note that the step size and window size configuration are global to all LESENSE channels and use the same register field in the hardware. This means that any window_size configuration passed to this function will apply for all channels and override all other step_size/window_size configurations.
sl_hal_lesense_channel_config_step_detection#
void sl_hal_lesense_channel_config_step_detection (uint8_t channel_index, uint32_t step_size, uint32_t init_value)
Configure the step detection evaluation mode for a specific channel.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint8_t | [in] | channel_index | An identifier of the scan channel. A valid range is 0-15. |
| uint32_t | [in] | step_size | A step size to be used on all channels. |
| uint32_t | [in] | init_value | The initial sensor value for the channel. |
This function will configure the evaluation mode, the initial sensor measurement (COMPTHRES) and the window size. For other channel-related configuration, see the sl_hal_lesense_channel_config() function.
Warnings
Note that the step size and window size configuration are global to all LESENSE channels and use the same register field in the hardware. This means that any step_size configuration passed to this function will apply for all channels and override all other step_size/window_size configurations. LESENSE needs to be disabled before configuring EVALCFG register and needs to be enabled when configuring EVALTHRES register.
sl_hal_lesense_config_alternate_excitation#
void sl_hal_lesense_config_alternate_excitation (const sl_hal_lesense_channel_alternate_excitation_t * config_alternate_excitation)
Configure the LESENSE alternate excitation modes.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| const sl_hal_lesense_channel_alternate_excitation_t * | [in] | config_alternate_excitation | A configuration structure for LESENSE alternate excitation pins. |
This function enable/disable the alternate excitation channels of the LESENSE interface. See the configuration parameter type definition (sl_hal_lesense_channel_alternate_excitation_t) for more details.
Note
The
config_alternate_excitationparameter must be true in the channel configuration structure (sl_hal_lesense_channel_descriptor_t) to use alternate excitation pins on the channel.
sl_hal_lesense_decoder_config_all_arcs#
void sl_hal_lesense_decoder_config_all_arcs (const sl_hal_lesense_all_transition_arcs_t * config_all_arcs)
Configure all LESENSE transition ARCs.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| const sl_hal_lesense_all_transition_arcs_t * | [in] | config_all_arcs | A configuration structure for all 64 LESENSE decoder arcs. |
This function configures all the transition ARC of the LESENSE interface. See the configuration parameter type definition (sl_hal_lesense_all_transition_arcs_t) for more details.
sl_hal_lesense_enable#
void sl_hal_lesense_enable (void )
Enable the LESENSE module.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_hal_lesense_wait_sync#
void sl_hal_lesense_wait_sync (void )
Wait for ongoing sync of register(s) to complete before writing to any other register.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_hal_lesense_wait_ready#
void sl_hal_lesense_wait_ready (void )
Wait for disabling to finish.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_hal_lesense_disable#
void sl_hal_lesense_disable (void )
Disable the LESENSE module.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_hal_lesense_decoder_start#
void sl_hal_lesense_decoder_start (void )
Start the LESENSE decoder.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Note
This function will wait for any pending previous write operation to the CMD register to complete before accessing the CMD register. It will also wait for the write operation to the CMD register to complete before returning. Each write operation to the CMD register may take up to 3 LF clock cycles, so expect some delay. The user may implement a separate function to write multiple command bits in the CMD register in one single operation to optimize an application.
sl_hal_lesense_decoder_stop#
void sl_hal_lesense_decoder_stop (void )
Stop LESENSE decoder.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Disables LESENSE decoder by setting the command to LESENSE_DECCTRL register.
sl_hal_lesense_set_scan_mode#
void sl_hal_lesense_set_scan_mode (sl_hal_lesense_scan_mode_t scan_mode)
Set scan mode of the LESENSE channels.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| sl_hal_lesense_scan_mode_t | [in] | scan_mode | Select the location to map LESENSE alternate excitation channels. |
This function configures how the scan start is triggered. It can be used for re-configuring the scan mode while running the application but it is also used by sl_hal_lesense_init() for initialization.
Note
Users can configure the scan mode by sl_hal_lesense_init() function, but only with a significant overhead. This simple function serves the purpose of controlling this parameter after the channel has been configured. Be aware of the effects of the non-atomic Read-Modify-Write cycle. LESENSE needs to be disabled before configuring any register.
SL_HAL_LESENSE_SCAN_START_PERIODIC - A new scan is started each time the period counter overflows.
SL_HAL_LESENSE_SCAN_START_ONESHOT - A single scan is performed when sl_hal_lesense_start_scan() function is called.
SL_HAL_LESENSE_SCAN_START_PRS - A new scan is triggered by pulse on the PRS channel.
sl_hal_lesense_start_scan#
void sl_hal_lesense_start_scan (void )
Start scanning sensors.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Note
This function will wait for any pending previous write operation to the CMD register to complete before accessing the CMD register. It will also wait for the write operation to the CMD register to complete before returning. Each write operation to the CMD register may take up to 3 LF clock cycles, so expect some delay. The user may implement a separate function to write multiple command bits in the CMD register in one single operation to optimize an application.
sl_hal_lesense_stop_scan#
void sl_hal_lesense_stop_scan (void )
Stop scanning sensors.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Note
This function will wait for any pending previous write operation to the CMD register to complete before accessing the CMD register. It will also wait for the write operation to the CMD register to complete before returning. Each write operation to the CMD register may take up to 3 LF clock cycles, so the user should expect some delay. The user may implement a separate function to write multiple command bits in the CMD register in one single operation in order to optimize an application. If issued during a scan, the command takes effect after scan completion.
sl_hal_lesense_set_start_delay#
void sl_hal_lesense_set_start_delay (uint8_t start_delay)
Set the start delay of the sensor interaction on each channel.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint8_t | [in] | start_delay | A number of LFACLK cycles to delay. A valid range: 0-3 (2 bit). |
This function sets the start delay of the sensor interaction on each channel. It can be used for adjusting the start delay while running the application but it is also used by sl_hal_lesense_init() for initialization.
Note
Users can configure the start delay by sl_hal_lesense_init() function, but only with a significant overhead. This simple function serves the purpose of controlling this parameter after the channel has been configured. Be aware of the effects of the non-atomic Read-Modify-Write cycle. LESENSE needs to be disabled before configuring any register.
sl_hal_lesense_set_window_size#
void sl_hal_lesense_set_window_size (uint32_t window_size)
Set the window size for all LESENSE channels.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | window_size | The window size to use for all channels. |
The window size is used by all channels that are configured as SL_HAL_LESENSE_EVALUATION_MODE_SLIDING_WINDOW.
Note
LESENSE needs to be disabled before configuring EVALCTRL register.
Warnings
The window size configuration is using the same register field as the step detection size. As a result, the window size configuration will have an effect on channels configured with the SL_HAL_LESENSE_EVALUATION_MODE_STEP_DETECTION evaluation mode as well.
sl_hal_lesense_set_step_size#
void sl_hal_lesense_set_step_size (uint32_t step_size)
Set the step size for all LESENSE channels.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | step_size | The step size to use for all channels. |
The step size is configured using the same register field as used to configure window size. Therefore, calling this function will overwrite any previously configured window size as done by the sl_hal_lesense_set_window_size() function.
sl_hal_lesense_decoder_config_arc#
void sl_hal_lesense_decoder_config_arc (const sl_hal_lesense_transition_arc_t * config_arc, uint32_t arc_index)
Configure a single LESENSE transition ARC.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| const sl_hal_lesense_transition_arc_t * | [in] | config_arc | A configuration structure for a single LESENSE transition ARC. |
| uint32_t | [in] | arc_index | An ARC index to configure. |
This function configures a transition ARC of the LESENSE interface. See the configuration parameter type definition sl_hal_lesense_transition_arc_t for more details.
Note
LESENSE needs to be disabled before configuring STx_ARC register.
sl_hal_lesense_decoder_enable_prs_output#
void sl_hal_lesense_decoder_enable_prs_output (uint32_t decoder_mask, uint32_t decoder_compare)
Enable the PRS output from the LESENSE decoder.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | decoder_mask | A decoder state compare value mask. |
| uint32_t | [in] | decoder_compare | A decoder state comparison value. |
sl_hal_lesense_decoder_disable_prs_output#
void sl_hal_lesense_decoder_disable_prs_output (void )
Disable the PRS output from the LESENSE decoder.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
sl_hal_lesense_get_status#
uint32_t sl_hal_lesense_get_status (void )
Get the current status of LESENSE.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Returns the value of the LESENSE_STATUS register that contains the OR combination of the following status bits for EFR series 2:
LESENSE_STATUS_RESFIFOV - Result Fifo valid. Set when data is available in result Fifo. Cleared when Fifo is empty.
LESENSE_STATUS_RESFIFOFULL - Result Fifo full. Set when result Fifo is full.
LESENSE_STATUS_RUNNING - LESENSE is active.
LESENSE_STATUS_SCANACTIVE - LESENSE is currently interfacing sensors.
LESENSE_STATUS_FLUSHING - Fifo flushing
LESENSE_STATUS_READBUSY - Fifo Read busy
sl_hal_lesense_channel_set_timing#
void sl_hal_lesense_channel_set_timing (uint8_t channel_index, uint8_t excitation_time, uint8_t sample_delay, uint16_t measure_delay)
Set LESENSE channel timing parameters.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint8_t | [in] | channel_index | An identifier of the scan channel. A valid range is 0-15. |
| uint8_t | [in] | excitation_time | An excitation time on channel_index. The excitation will last excitation_time+1 excitation clock cycles. A valid range is 0-63 (6 bits). |
| uint8_t | [in] | sample_delay | Sample delay on channel_index. Sampling will occur after sample_delay+1 sample clock cycles. A valid range is 0-127 (7 bits). |
| uint16_t | [in] | measure_delay | A measure delay on channel_index. Sensor measuring is delayed for measure_delay+1 excitation clock cycles. A valid range is 0-127 (7 bits). |
Use this function to set timing parameters on a selected LESENSE channel.
Note
Users can configure the channel timing parameters with the sl_hal_lesense_channel_config() function, but only with a significant overhead. This function controls these parameters after the channel has been configured. LESENSE needs to be disabled before configuring any register.
sl_hal_lesense_wait_status#
void sl_hal_lesense_wait_status (uint32_t flag)
Wait until status of LESENSE is equal to what was requested.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flag | The OR combination of the following status bits for EFR series 2:
|
Polls LESENSE_STATUS register and waits until requested combination of flags are set.
sl_hal_lesense_channel_get_active#
uint32_t sl_hal_lesense_channel_get_active (void )
Get the currently active channel index.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Returns the value of the LESENSE_CHINDEX register that contains the index of currently active channel (0-15).
sl_hal_lesense_get_scan_result#
uint32_t sl_hal_lesense_get_scan_result (void )
Get the latest scan comparison result (1 bit / channel).
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Returns the value of the LESENSE_SCANRES register that contains the comparison result of last scan on all channels. Bit x is set if a comparison triggered on channel x, which means that LESENSE counter met the comparison criteria set in LESENSE_CHx_EVAL by COMPMODE and CNTTHRES.
sl_hal_lesense_get_scan_result_data#
uint32_t sl_hal_lesense_get_scan_result_data (void )
Get the oldest unread data from the result buffer.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Note
Make sure that the STORERES bit is set in LESENSE_CHx_EVAL, or the STRSCANRES bit is set in LESENSE_CTRL; otherwise, returns the undefined value.
Returns
Returns the value of LESENSE_RESDATA register that contains the oldest unread counter result from result buffer.
sl_hal_lesense_clear_result_buffer#
void sl_hal_lesense_clear_result_buffer (void )
Clear the result buffer.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Note
This function will wait for any pending previous write operation to the CMD register to complete before accessing the CMD register. It will also wait for the write operation to the CMD register to complete before returning. Each write operation to the CMD register may take up to 3 LF clock cycles, so expect some delay. The user may implement a separate function to write multiple command bits in the CMD register in one single operation to optimize an application.
sl_hal_lesense_decoder_get_state#
uint32_t sl_hal_lesense_decoder_get_state (void )
Get the current state of the LESENSE decoder.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
This function returns the value of the LESENSE_DECSTATE register that represents the current state of the LESENSE decoder.
sl_hal_lesense_get_sensor_state#
uint32_t sl_hal_lesense_get_sensor_state (void )
Get the current state of the LESENSE sensor.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Returns
Returns the value of LESENSE_SENSORSTATE register that represents the current state of the LESENSE sensor.
sl_hal_lesense_reset#
void sl_hal_lesense_reset (void )
Reset the LESENSE module.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Use this function to reset LESENSE registers.
Note
Resetting LESENSE registers is required in each reset or power-on cycle to configure the default values of the RAM mapped LESENSE registers. sl_hal_lesense_reset() can be called on initialization by setting the
req_resetparameter to true in sl_hal_lesense_init(). Starting from Series 2 Config 3 (xG23 and higher), this function leaves LESENSE in the disabled state.
sl_hal_lesense_clear_interrupts#
void sl_hal_lesense_clear_interrupts (uint32_t flags)
Clear one or more pending LESENSE interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | Pending LESENSE interrupt sources to clear. Use a set of interrupt flags OR-ed together to clear multiple interrupt sources of LESENSE module (LESENSE_IF_nnn). |
sl_hal_lesense_enable_interrupts#
void sl_hal_lesense_enable_interrupts (uint32_t flags)
Enable one or more LESENSE interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | LESENSE interrupt sources to enable. Use a set of interrupt flags OR-ed together to enable multiple interrupt sources of LESENSE module (LESENSE_IF_nnn). |
sl_hal_lesense_disable_interrupts#
void sl_hal_lesense_disable_interrupts (uint32_t flags)
Disable one or more LESENSE interrupts.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | LESENSE interrupt sources to disable. Use a set of interrupt flags OR-ed together to disable multiple interrupt sources of LESENSE module (LESENSE_IF_nnn). |
sl_hal_lesense_set_interrupts#
void sl_hal_lesense_set_interrupts (uint32_t flags)
Set one or more pending LESENSE interrupts from SW.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| uint32_t | [in] | flags | LESENSE interrupt sources to set to pending. Use a set of interrupt flags OR-ed together to set multiple interrupt sources of LESENSE module (LESENSE_IFS_nnn). |
sl_hal_lesense_get_pending_interrupts#
uint32_t sl_hal_lesense_get_pending_interrupts (void )
Get pending LESENSE interrupt flags.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Note
Event bits are not cleared by the use of this function.
Returns
Pending LESENSE interrupt sources. The OR combination of valid interrupt flags of the LESENSE module (LESENSE_IF_nnn).
sl_hal_lesense_get_enabled_pending_interrupts#
uint32_t sl_hal_lesense_get_enabled_pending_interrupts (void )
Get enabled and pending LESENSE interrupt flags.
| Type | Direction | Argument Name | Description |
|---|---|---|---|
| void | N/A |
Useful for handling more interrupt sources in the same interrupt handler.
Note
Event bits are not cleared by the use of this function.
Returns
Pending and enabled LESENSE interrupt sources. Return value is the bitwise AND combination of
the OR combination of enabled interrupt sources in LESENSE_IEN_nnn register (LESENSE_IEN_nnn).
the OR combination of valid interrupt flags of LESENSE module (LESENSE_IF_nnn).