Skip to content

Commit a123ee4

Browse files
authored
doc(drv2605): Add missing docstrings (#457)
1 parent ea272e6 commit a123ee4

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

components/drv2605/include/drv2605.hpp

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class Drv2605 : public BasePeripheral<> {
2525
* @brief Convert LRA frequency to drive time.
2626
* @details The drive time is half the period of the LRA frequency, in ms.
2727
* The LRA frequency is in Hz, so we need to convert it to ms.
28-
* The formula is: drive_time = 1000 / (2 * lra_freq).
28+
* The formula is:
29+
* - drive_time_ms = 1000 / (2 * lra_freq).
30+
* - drive_time = (drive_time_ms - 0.5) / 0.1
2931
* @param lra_freq The frequency of the LRA in Hz.
3032
* @return The drive time in bits (0-31).
3133
*/
@@ -125,14 +127,15 @@ class Drv2605 : public BasePeripheral<> {
125127
cause the feedback to react at slower rate. */
126128
};
127129

128-
using ErmCalibrationSettings =
129-
BaseCalibrationSettings; /**< Calibration Routine Settings structure for ERM motors. */
130+
/**< Calibration Routine Settings structure for ERM motors. */
131+
using ErmCalibrationSettings = BaseCalibrationSettings;
130132

133+
/**< Calibration Routine Settings structure for LRA motors. */
131134
struct LraCalibrationSettings : BaseCalibrationSettings {
132135
uint8_t sample_time : 2 = 3; /**< Sample time, 0-3. */
133136
uint8_t blanking_time : 2 = 1; /**< Blanking time, 0-3. */
134137
uint8_t idiss_time : 2 = 1; /**< IDISS time, 0-3. */
135-
}; /**< Calibration Routine Settings structure for LRA motors. */
138+
};
136139

137140
/**
138141
* @brief Structure to hold the calibrated data for the DRV2605.
@@ -292,8 +295,6 @@ class Drv2605 : public BasePeripheral<> {
292295
* @note This is only valid when the RTP data format is set to unsigned
293296
* (requires set_rtp_data_format_unsigned(true)).
294297
* @param pwm_value The PWM value to set (0-255).
295-
* @note The value is interpreted as unsigned by default, but can be set to
296-
* signed by using the `set_rtp_pwm` method.
297298
* @param ec Error code to set if there is an error.
298299
* @return true if the PWM value was set successfully, false if there was an
299300
* error.
@@ -316,8 +317,6 @@ class Drv2605 : public BasePeripheral<> {
316317
* @note This is only valid when the RTP data format is set to signed
317318
* (default).
318319
* @param pwm_value The PWM value to set (-128 to 127).
319-
* @note The value is interpreted as signed by default, but can be set to
320-
* unsigned by using the `set_rtp_pwm_unsigned` method.
321320
* @param ec Error code to set if there is an error.
322321
* @return true if the PWM value was set successfully, false if there was an
323322
* error.
@@ -335,18 +334,19 @@ class Drv2605 : public BasePeripheral<> {
335334
}
336335

337336
/**
338-
* @brief Set the waveform slot at \p slot to \w.
337+
* @brief Set the waveform at slot.
339338
* @note When calling start() to play the configured waveform slots, the
340339
* driver will always start playing from slot 0 and will continue
341340
* until it reaches a slot that has been configured with the
342341
* Waveform::END.
343342
* @param slot The slot (0-8) to set.
344-
* @param w The Waveform to play in slot \p slot.
343+
* @param w The Waveform to play in slot.
345344
* @param ec Error code to set if there is an error.
346345
* @return true if the waveform was set successfully, false if there was an
347346
* error.
348347
*/
349348
bool set_waveform(uint8_t slot, Waveform w, std::error_code &ec) {
349+
std::lock_guard<std::recursive_mutex> lock(base_mutex_);
350350
logger_.info("Setting waveform {}", (uint8_t)w);
351351
write_u8_to_register((uint8_t)Register::WAVESEQ1 + slot, (uint8_t)w, ec);
352352
return !ec; // return true if no error
@@ -360,6 +360,7 @@ class Drv2605 : public BasePeripheral<> {
360360
* error.
361361
*/
362362
bool select_library(Library lib, std::error_code &ec) {
363+
std::lock_guard<std::recursive_mutex> lock(base_mutex_);
363364
logger_.info("Selecting library {}", lib);
364365
if (motor_type_ == MotorType::LRA && lib != Library::LRA) {
365366
logger_.warn("LRA motor selected, but library {} is not an LRA library", lib);
@@ -368,8 +369,22 @@ class Drv2605 : public BasePeripheral<> {
368369
return !ec; // return true if no error
369370
}
370371

372+
/**
373+
* @brief Calibrate the DRV2605 for an ERM motor.
374+
* @details This method performs the auto-calibration routine for the DRV2605.
375+
* It will put the DRV2605 into auto-calibration
376+
* mode, and then start the calibration process. The calibration
377+
* data will be stored in the `cal_data_out` parameter.
378+
* @param cal_conf The calibration settings to use.
379+
* @param cal_data_out The structure to store the calibration data.
380+
* @param ec Error code to set if there is an error.
381+
* @return true if the calibration was successful, false if there was an
382+
* error.
383+
*/
371384
bool calibrate(const ErmCalibrationSettings &cal_conf, CalibratedData &cal_data_out,
372385
std::error_code &ec) {
386+
std::lock_guard<std::recursive_mutex> lock(base_mutex_);
387+
373388
// if the motor type is not ERM, log a warning
374389
if (motor_type_ != MotorType::ERM) {
375390
logger_.warn("Calibrating ERM motor while the motor type is set to {}", motor_type_);
@@ -447,8 +462,22 @@ class Drv2605 : public BasePeripheral<> {
447462
return true; // return true if no error
448463
}
449464

465+
/**
466+
* @brief Calibrate the DRV2605 for an LRA motor.
467+
* @details This method performs the auto-calibration routine for the DRV2605.
468+
* It will put the DRV2605 into auto-calibration
469+
* mode, and then start the calibration process. The calibration
470+
* data will be stored in the `cal_data_out` parameter.
471+
* @param cal_conf The calibration settings to use.
472+
* @param cal_data_out The structure to store the calibration data.
473+
* @param ec Error code to set if there is an error.
474+
* @return true if the calibration was successful, false if there was an
475+
* error.
476+
*/
450477
bool calibrate(const LraCalibrationSettings &cal_conf, CalibratedData &cal_data_out,
451478
std::error_code &ec) {
479+
std::lock_guard<std::recursive_mutex> lock(base_mutex_);
480+
452481
// if the motor type is not LRA, log a warning
453482
if (motor_type_ != MotorType::LRA) {
454483
logger_.warn("Calibrating LRA motor while the motor type is set to {}", motor_type_);

0 commit comments

Comments
 (0)