6#ifndef ZEPHYR_INCLUDE_DRIVERS_HAPTICS_CS40L5X_H_
7#define ZEPHYR_INCLUDE_DRIVERS_HAPTICS_CS40L5X_H_
190typedef struct device *(*cs40l5x_io_bus_get_device)(
const struct device *
const dev);
241#if CONFIG_HAPTICS_CS40L5X_I2C
248#if CONFIG_HAPTICS_CS40L5X_SPI
262#if CONFIG_HAPTICS_CS40L5X_I2C
266#if CONFIG_HAPTICS_CS40L5X_SPI
429 void (*error_callback)(
const struct device *
const haptic_dev,
Main header file for GPIO driver API.
Main header file for I2C (Inter-Integrated Circuit) driver API.
Main header file for SPI (Serial Peripheral Interface) driver API.
struct device *(* cs40l5x_io_bus_get_device)(const struct device *const dev)
Return pointer to control port instance.
Definition cs40l5x.h:190
int cs40l5x_logger_get(const struct device *const dev, enum cs40l5x_logger_source source, enum cs40l5x_logger_source_type type, uint32_t *const value)
Get runtime haptics logging data for the specified logger source.
int cs40l5x_select_output(const struct device *const dev, const enum cs40l5x_bank bank, const uint8_t index)
Select haptic effect triggered via haptics_start_output().
int cs40l5x_calibrate(const struct device *const dev)
Run calibration to derive ReDC and F0 values and apply results for click compensation.
cs40l5x_error_type
Types of fatal CS40L5x hardware errors.
Definition cs40l5x.h:85
int(* cs40l5x_io_bus_write)(const struct device *const dev, uint32_t *const tx, const uint32_t len)
Function wrapper for i2c_write_dt() or spi_read_dt().
Definition cs40l5x.h:224
cs40l5x_bank
Wavetable sources for haptic effects.
Definition cs40l5x.h:49
cs40l5x_logger
Options for runtime haptics logging.
Definition cs40l5x.h:99
int cs40l5x_set_gain(const struct device *const dev, const uint8_t gain)
Configure gain for haptic effects triggered via haptics_start_output().
cs40l5x_attenuation
Attenuation options for GPIO-triggered haptic effects.
Definition cs40l5x.h:33
cs40l5x_logger_source_type
Type specification for runtime haptics logging sources.
Definition cs40l5x.h:121
int cs40l5x_configure_trigger(const struct device *const dev, const struct gpio_dt_spec *const gpio, const enum cs40l5x_bank bank, const uint8_t index, const enum cs40l5x_attenuation attenuation, const enum cs40l5x_trigger_edge edge)
Configure edge-triggered haptic effect.
int cs40l5x_upload_pcm(const struct device *const dev, const enum cs40l5x_custom_index index, const uint16_t redc, const uint16_t f0, const int8_t *const samples, const uint16_t num_samples)
Upload PCM effect to the specified index.
cs40l5x_trigger_edge
Options for edge-triggered haptics effects.
Definition cs40l5x.h:148
cs40l5x_logger_source
Options for runtime haptics logging sources.
Definition cs40l5x.h:110
cs40l5x_custom_index
Custom haptics source indices (0 or 1).
Definition cs40l5x.h:74
void cs40l5x_register_error_callback(const struct device *dev, void(*error_callback)(const struct device *const haptic_dev, const uint32_t errors))
Register an application callback to handle fatal hardware errors.
int cs40l5x_configure_buzz(const struct device *const dev, const uint32_t frequency, const uint8_t level, const uint32_t duration)
Configure ROM buzz for haptic playback.
int(* cs40l5x_io_bus_read)(const struct device *const dev, const uint32_t addr, uint32_t *const rx, const uint32_t len)
Function wrapper for i2c_write_read_dt() or spi_read_dt().
Definition cs40l5x.h:212
bool(* cs40l5x_io_bus_is_ready)(const struct device *const dev)
Function wrapper for i2c_is_ready_dt() or spi_is_ready_dt().
Definition cs40l5x.h:200
int cs40l5x_upload_pwle(const struct device *const dev, const enum cs40l5x_custom_index index, const struct cs40l5x_pwle_section *const sections, const uint8_t num_sections)
Upload PWLE effect to the specified index.
@ CS40L5X_ERROR_INDUCTOR_SHORT
Inductor short detected.
Definition cs40l5x.h:89
@ CS40L5X_ERROR_OVERCURRENT
Overcurrent condition detected.
Definition cs40l5x.h:90
@ CS40L5X_ERROR_AMPLIFIER_SHORT
Amplifier short detected.
Definition cs40l5x.h:86
@ CS40L5X_ERROR_OVERTEMPERATURE
Overtemperature detected.
Definition cs40l5x.h:87
@ CS40L5X_ERROR_UNDERVOLTAGE
Undervoltage detected.
Definition cs40l5x.h:88
@ CS40L5X_ERROR_BATTERY_UNDERVOLTAGE
Vdd_batt undervoltage detected.
Definition cs40l5x.h:91
@ CS40L5X_NO_BANK
Reserved for driver error handling.
Definition cs40l5x.h:53
@ CS40L5X_ROM_BANK
Playback from the pre-programmed ROM library.
Definition cs40l5x.h:50
@ CS40L5X_CUSTOM_BANK
Playback from custom haptics source programmed at runtime.
Definition cs40l5x.h:51
@ CS40L5X_BUZ_BANK
Playback from buzz source programmed at runtime.
Definition cs40l5x.h:52
@ CS40L5X_LOGGER_NO_CHANGE
Use to retrieve haptics logging status without updating.
Definition cs40l5x.h:102
@ CS40L5X_LOGGER_ENABLE
Enable runtime logging for the device.
Definition cs40l5x.h:101
@ CS40L5X_LOGGER_DISABLE
Disable runtime logging for the device.
Definition cs40l5x.h:100
@ CS40L5X_ATTENUATION_2DB
Configure haptic effect with 2 dB attenuation.
Definition cs40l5x.h:39
@ CS40L5X_ATTENUATION_6DB
Configure haptic effect with 6 dB attenuation.
Definition cs40l5x.h:35
@ CS40L5X_ATTENUATION_5DB
Configure haptic effect with 5 dB attenuation.
Definition cs40l5x.h:36
@ CS40L5X_ATTENUATION_4DB
Configure haptic effect with 4 dB attenuation.
Definition cs40l5x.h:37
@ CS40L5X_ATTENUATION_7DB
Configure haptic effect with 7 dB attenuation.
Definition cs40l5x.h:34
@ CS40L5X_ATTENUATION_1DB
Configure haptic effect with 1 dB attenuation.
Definition cs40l5x.h:40
@ CS40L5X_ATTENUATION_0DB
Configure haptic effect with no attenuation.
Definition cs40l5x.h:41
@ CS40L5X_ATTENUATION_3DB
Configure haptic effect with 3 dB attenuation.
Definition cs40l5x.h:38
@ CS40L5X_LOGGER_MAX
Maximum value sampled for a logger source.
Definition cs40l5x.h:123
@ CS40L5X_LOGGER_MEAN
Mean value sampled for a logger source.
Definition cs40l5x.h:124
@ CS40L5X_LOGGER_MIN
Minimum value sampled for a logger source.
Definition cs40l5x.h:122
@ CS40L5X_RISING_EDGE
Configure a rising-edge haptic effect.
Definition cs40l5x.h:149
@ CS40L5X_FALLING_EDGE
Configure a falling-edge haptic effect.
Definition cs40l5x.h:150
@ CS40L5X_LOGGER_BEMF
Back EMF (SVC) in signed Q0.23 format (full scale is 24 V).
Definition cs40l5x.h:111
@ CS40L5X_LOGGER_VMON
Output voltage in signed Q0.23 format (full scale is 24 V).
Definition cs40l5x.h:113
@ CS40L5X_LOGGER_VBST
Boost voltage in unsigned Q0.24 format (full scale is 14 V).
Definition cs40l5x.h:112
@ CS40L5X_CUSTOM_0
Custom haptics source at index 0.
Definition cs40l5x.h:75
@ CS40L5X_CUSTOM_1
Custom haptics source at index 1.
Definition cs40l5x.h:76
@ CS40L5X_NUM_CUSTOM_EFFECTS
Maximum number of custom haptics effects.
Definition cs40l5x.h:77
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
Main header file for haptics driver API.
__INTPTR_TYPE__ off_t
Definition types.h:36
#define bool
Definition stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT8_TYPE__ int8_t
Definition stdint.h:72
Control port I/O functions.
Definition cs40l5x.h:230
cs40l5x_io_bus_get_device get_device
< Get control device instance for PM runtime usage
Definition cs40l5x.h:232
cs40l5x_io_bus_is_ready is_ready
Read from the device.
Definition cs40l5x.h:234
cs40l5x_io_bus_read read
Write to the device.
Definition cs40l5x.h:236
cs40l5x_io_bus_write write
Definition cs40l5x.h:238
Structure to store control port devices.
Definition cs40l5x.h:261
Calibration data for click compensation.
Definition cs40l5x.h:61
uint32_t f0
Definition cs40l5x.h:65
uint32_t redc
< Coil DC resistance in signed Q6.17 format (Ohms * (24 / 2.9))
Definition cs40l5x.h:63
CS40L5x configuration structure for a device instance.
Definition cs40l5x.h:275
const struct device *const dev
< Pointer to CS40L5x device instance
Definition cs40l5x.h:277
const struct device * flash
Optional flash register offset, configurable via devicetree property 'flash-offset'.
Definition cs40l5x.h:293
struct cs40l5x_data *const data
Logger configuration for instance-based logging.
Definition cs40l5x.h:279
struct gpio_dt_spec reset_gpio
Optional GPIO for hardware and DSP interrupts.
Definition cs40l5x.h:287
struct gpio_dt_spec interrupt_gpio
Optional GPIOs for edge-triggered haptic effects.
Definition cs40l5x.h:289
const off_t flash_offset
Boost setting, configurable via devicetree property 'external-boost'.
Definition cs40l5x.h:295
const struct cs40l5x_bus bus
Control port I/O functions.
Definition cs40l5x.h:283
struct cs40l5x_trigger_gpios trigger_gpios
Optional flash storage, configurable via devicetree property 'flash-storage'.
Definition cs40l5x.h:291
const struct cs40l5x_bus_io *const bus_io
Required GPIO for hardware resets.
Definition cs40l5x.h:285
const struct device *const external_boost
Definition cs40l5x.h:297
LOG_INSTANCE_PTR_DECLARE(log)
Control port devices.
CS40L5x data structure for a device instance.
Definition cs40l5x.h:303
struct k_sem calibration_semaphore
F0 and ReDC data derived from calibration.
Definition cs40l5x.h:323
struct k_work_delayable interrupt_worker
Callback handler for trigger logging.
Definition cs40l5x.h:317
struct gpio_callback interrupt_callback
Worker for debounced interrupt processing.
Definition cs40l5x.h:315
uint8_t buf_trigger_history[CONFIG_HAPTICS_CS40L5X_METADATA_CACHE_LEN]
Upload status for custom effects at indices 0 and 1.
Definition cs40l5x.h:335
struct gpio_callback trigger_callback
Application-provided callback to recover from fatal hardware errors.
Definition cs40l5x.h:319
struct cs40l5x_calibration calibration
Playback command for mailbox-triggered haptic effects.
Definition cs40l5x.h:325
struct ring_buf rb_mailbox_history
Ring buffer to cache trigger playback history.
Definition cs40l5x.h:329
const struct device *const dev
< Pointer to CS40L5x device instance
Definition cs40l5x.h:305
int effects_in_flight
Definition cs40l5x.h:339
uint8_t buf_mailbox_history[CONFIG_HAPTICS_CS40L5X_METADATA_CACHE_LEN]
Ring buffer storage for cached trigger playback history.
Definition cs40l5x.h:333
uint8_t rev_id
Callback handler for interrupt processing.
Definition cs40l5x.h:313
uint32_t dev_id
Revision ID corresponding to the silicon variant.
Definition cs40l5x.h:311
uint32_t output
Ring buffer to cache mailbox playback history.
Definition cs40l5x.h:327
void(* error_callback)(const struct device *const haptic_dev, const uint32_t errors)
Semaphore used to sequence the calibration routine.
Definition cs40l5x.h:321
bool custom_effects[CS40L5X_NUM_CUSTOM_EFFECTS]
Number of haptic effects playing or suspended.
Definition cs40l5x.h:337
struct ring_buf rb_trigger_history
Ring buffer storage for cached mailbox playback history.
Definition cs40l5x.h:331
struct k_mutex lock
Device ID corresponding to the part number.
Definition cs40l5x.h:309
const struct cs40l5x_config *const config
Lock to deconflict haptic playback, device calibration, and configuration changes.
Definition cs40l5x.h:307
PWLE section definition.
Definition cs40l5x.h:132
uint16_t frequency
Section level in unsigned Q0.11 format.
Definition cs40l5x.h:136
uint8_t flags
Definition cs40l5x.h:140
uint16_t level
Section flags in unsigned Q4.0 format.
Definition cs40l5x.h:138
uint16_t duration
< Section duration in unsigned Q14.2 format (time) or Q16.0 format (half-cycles)
Definition cs40l5x.h:134
Structure to store GPIO trigger configurations.
Definition cs40l5x.h:156
uint8_t address
Definition cs40l5x.h:164
uint8_t index
Attenuation to be applied to haptic effect.
Definition cs40l5x.h:160
int attenuation
Offset register address that stores the GPIO trigger configuration.
Definition cs40l5x.h:162
enum cs40l5x_bank bank
< Wavetable source for desired haptic effect
Definition cs40l5x.h:158
Structure to store and handle trigger GPIOs.
Definition cs40l5x.h:170
struct cs40l5x_trigger_config * rising_edge
Trigger configurations for falling-edge events.
Definition cs40l5x.h:176
bool * ready
Definition cs40l5x.h:180
const uint8_t num_gpio
Trigger configurations for rising-edge events.
Definition cs40l5x.h:174
struct gpio_dt_spec * gpio
< Array of GPIOs provided via devicetree property 'trigger-gpios'
Definition cs40l5x.h:172
struct cs40l5x_trigger_config * falling_edge
GPIO statuses.
Definition cs40l5x.h:178
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
GPIO callback structure.
Definition gpio.h:748
Container for GPIO pin information specified in devicetree.
Definition gpio.h:296
Complete I2C DT information.
Definition i2c.h:78
Mutex Structure.
Definition kernel.h:3336
Semaphore structure.
Definition kernel.h:3541
A structure used to submit work after a delay.
Definition kernel.h:4465
A structure to represent a ring buffer.
Definition ring_buffer.h:50
Complete SPI DT information.
Definition spi.h:541