PebbleOS v4.47.0-512-g5285d4236
Loading...
Searching...
No Matches
Vibration motor

Vibration motor class. More...

Modules

 AW86225
 Awinic AW86225 Vibration motor driver.
 
 AW8623X
 Awinic AW8623X Vibration motor driver, driving an LRA in continuous mode.
 
 DRV2604
 TI DRV2604 Vibration motor driver, driving an LRA in real-time playback mode.
 
 Simulator
 Simulated vibration motor, reporting its strength to an observer.
 

Data Structures

struct  pbl_vibe_ops
 Vibration motor driver operations, called with the device lock held. More...
 
struct  pbl_vibe_state
 Vibration motor runtime state. More...
 
struct  pbl_vibe
 Vibration motor. More...
 

Macros

#define VIBE_STRENGTH_MAX   100
 Full power.
 
#define VIBE_STRENGTH_MIN   -100
 Full reverse, for drivers that can brake.
 
#define VIBE_STRENGTH_OFF   0
 Stopped.
 
#define PBL_VIBE_CALIBRATION_NONE   0xFFU
 Calibration value of a driver that keeps nothing to persist.
 
#define PBL_VIBE_STATE_DEFINE(sym)
 Define the class state of a vibration motor.
 
#define PBL_VIBE_INIT(sym, _name, _parent, _ops, _braking_strength)
 Initialize a struct pbl_vibe.
 

Functions

int pbl_vibe_start (const struct pbl_vibe *vibe, int8_t strength)
 Drive the motor, starting it if stopped.
 
int pbl_vibe_stop (const struct pbl_vibe *vibe)
 Stop the motor.
 
int8_t pbl_vibe_get_braking_strength (const struct pbl_vibe *vibe)
 Get the strength that brakes the motor to a stop.
 
int pbl_vibe_calibrate (const struct pbl_vibe *vibe, uint8_t *cali)
 Calibrate the motor driver.
 
int pbl_vibe_set_calibration (const struct pbl_vibe *vibe, uint8_t cali)
 Apply a calibration value returned by pbl_vibe_calibrate().
 

Variables

const struct pbl_vibe *const VIBE
 The board's vibration motor.
 

Detailed Description

Vibration motor class.

A vibration motor is a struct pbl_vibe device. Every call into the driver runs with the device lock held, a recursive mutex.

// ...
#define VIBE_STRENGTH_MAX
Full power.
Definition vibe.h:28
int pbl_vibe_start(const struct pbl_vibe *vibe, int8_t strength)
Drive the motor, starting it if stopped.
const struct pbl_vibe *const VIBE
The board's vibration motor.
int pbl_vibe_stop(const struct pbl_vibe *vibe)
Stop the motor.

Data Structure Documentation

◆ pbl_vibe_state

struct pbl_vibe_state

Vibration motor runtime state.

Data Fields
struct pbl_mutex lock Device lock.

◆ pbl_vibe

struct pbl_vibe

Vibration motor.

Data Fields
int8_t braking_strength Strength that brakes the motor, VIBE_STRENGTH_OFF if the driver cannot brake.
struct pbl_device dev Device.
const struct pbl_vibe_ops * ops Driver operations.
struct pbl_vibe_state * state Runtime state.

Macro Definition Documentation

◆ PBL_VIBE_CALIBRATION_NONE

#define PBL_VIBE_CALIBRATION_NONE   0xFFU

Calibration value of a driver that keeps nothing to persist.

◆ PBL_VIBE_INIT

#define PBL_VIBE_INIT (   sym,
  _name,
  _parent,
  _ops,
  _braking_strength 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_vibe_dev_init, _parent, &pbl_vibe_class), \
.ops = (_ops), \
.state = &sym##_vibe_state, \
.braking_strength = (_braking_strength), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:153

Initialize a struct pbl_vibe.

Parameters
symSymbol of the instance, as passed to PBL_VIBE_STATE_DEFINE().
_nameDevice name.
_parentParent device.
_opsDriver operations.
_braking_strengthStrength that brakes the motor, or VIBE_STRENGTH_OFF.

◆ PBL_VIBE_STATE_DEFINE

#define PBL_VIBE_STATE_DEFINE (   sym)
Value:
static struct pbl_vibe_state sym##_vibe_state = {.lock = PBL_MUTEX_INITIALIZER}
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:132
struct pbl_mutex lock
Device lock.
Definition vibe.h:56
Vibration motor runtime state.
Definition vibe.h:54
#define PBL_MUTEX_INITIALIZER
Static initializer for an unlocked mutex.
Definition mutex.h:50

Define the class state of a vibration motor.

Parameters
symSymbol of the instance.

◆ VIBE_STRENGTH_MAX

#define VIBE_STRENGTH_MAX   100

Full power.

◆ VIBE_STRENGTH_MIN

#define VIBE_STRENGTH_MIN   -100

Full reverse, for drivers that can brake.

◆ VIBE_STRENGTH_OFF

#define VIBE_STRENGTH_OFF   0

Stopped.

Function Documentation

◆ pbl_vibe_calibrate()

int pbl_vibe_calibrate ( const struct pbl_vibe *  vibe,
uint8_t *  cali 
)

Calibrate the motor driver.

Parameters
vibeVibration motor.
[out]caliValue to persist and later pass to pbl_vibe_set_calibration(), or PBL_VIBE_CALIBRATION_NONE.
Returns
0, -ENOTSUP if the driver cannot calibrate, -ENODEV if the motor is not ready, or a negative errno.

◆ pbl_vibe_get_braking_strength()

int8_t pbl_vibe_get_braking_strength ( const struct pbl_vibe *  vibe)

Get the strength that brakes the motor to a stop.

Parameters
vibeVibration motor.
Returns
Braking strength, VIBE_STRENGTH_OFF if the driver does not brake this way.

◆ pbl_vibe_set_calibration()

int pbl_vibe_set_calibration ( const struct pbl_vibe *  vibe,
uint8_t  cali 
)

Apply a calibration value returned by pbl_vibe_calibrate().

Parameters
vibeVibration motor.
caliCalibration value.
Returns
0, -ENOTSUP if the driver cannot calibrate, -ENODEV if the motor is not ready, or a negative errno.

◆ pbl_vibe_start()

int pbl_vibe_start ( const struct pbl_vibe *  vibe,
int8_t  strength 
)

Drive the motor, starting it if stopped.

Drivers without reverse drive use the absolute value of strength.

Parameters
vibeVibration motor.
strengthStrength from VIBE_STRENGTH_MIN to VIBE_STRENGTH_MAX.
Returns
0, -ENODEV if the motor is not ready, or a negative errno.

◆ pbl_vibe_stop()

int pbl_vibe_stop ( const struct pbl_vibe *  vibe)

Stop the motor.

Parameters
vibeVibration motor.
Returns
0, -ENODEV if the motor is not ready, or a negative errno.

Variable Documentation

◆ VIBE

const struct pbl_vibe* const VIBE
extern

The board's vibration motor.