@@ -25,7 +25,9 @@ class Drv2605 : public BasePeripheral<> {
25
25
* @brief Convert LRA frequency to drive time.
26
26
* @details The drive time is half the period of the LRA frequency, in ms.
27
27
* 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
29
31
* @param lra_freq The frequency of the LRA in Hz.
30
32
* @return The drive time in bits (0-31).
31
33
*/
@@ -125,14 +127,15 @@ class Drv2605 : public BasePeripheral<> {
125
127
cause the feedback to react at slower rate. */
126
128
};
127
129
128
- using ErmCalibrationSettings =
129
- BaseCalibrationSettings; /* *< Calibration Routine Settings structure for ERM motors. */
130
+ /* *< Calibration Routine Settings structure for ERM motors. */
131
+ using ErmCalibrationSettings = BaseCalibrationSettings;
130
132
133
+ /* *< Calibration Routine Settings structure for LRA motors. */
131
134
struct LraCalibrationSettings : BaseCalibrationSettings {
132
135
uint8_t sample_time : 2 = 3 ; /* *< Sample time, 0-3. */
133
136
uint8_t blanking_time : 2 = 1 ; /* *< Blanking time, 0-3. */
134
137
uint8_t idiss_time : 2 = 1 ; /* *< IDISS time, 0-3. */
135
- }; /* *< Calibration Routine Settings structure for LRA motors. */
138
+ };
136
139
137
140
/* *
138
141
* @brief Structure to hold the calibrated data for the DRV2605.
@@ -292,8 +295,6 @@ class Drv2605 : public BasePeripheral<> {
292
295
* @note This is only valid when the RTP data format is set to unsigned
293
296
* (requires set_rtp_data_format_unsigned(true)).
294
297
* @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.
297
298
* @param ec Error code to set if there is an error.
298
299
* @return true if the PWM value was set successfully, false if there was an
299
300
* error.
@@ -316,8 +317,6 @@ class Drv2605 : public BasePeripheral<> {
316
317
* @note This is only valid when the RTP data format is set to signed
317
318
* (default).
318
319
* @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.
321
320
* @param ec Error code to set if there is an error.
322
321
* @return true if the PWM value was set successfully, false if there was an
323
322
* error.
@@ -335,18 +334,19 @@ class Drv2605 : public BasePeripheral<> {
335
334
}
336
335
337
336
/* *
338
- * @brief Set the waveform slot at \p slot to \w .
337
+ * @brief Set the waveform at slot.
339
338
* @note When calling start() to play the configured waveform slots, the
340
339
* driver will always start playing from slot 0 and will continue
341
340
* until it reaches a slot that has been configured with the
342
341
* Waveform::END.
343
342
* @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.
345
344
* @param ec Error code to set if there is an error.
346
345
* @return true if the waveform was set successfully, false if there was an
347
346
* error.
348
347
*/
349
348
bool set_waveform (uint8_t slot, Waveform w, std::error_code &ec) {
349
+ std::lock_guard<std::recursive_mutex> lock (base_mutex_);
350
350
logger_.info (" Setting waveform {}" , (uint8_t )w);
351
351
write_u8_to_register ((uint8_t )Register::WAVESEQ1 + slot, (uint8_t )w, ec);
352
352
return !ec; // return true if no error
@@ -360,6 +360,7 @@ class Drv2605 : public BasePeripheral<> {
360
360
* error.
361
361
*/
362
362
bool select_library (Library lib, std::error_code &ec) {
363
+ std::lock_guard<std::recursive_mutex> lock (base_mutex_);
363
364
logger_.info (" Selecting library {}" , lib);
364
365
if (motor_type_ == MotorType::LRA && lib != Library::LRA) {
365
366
logger_.warn (" LRA motor selected, but library {} is not an LRA library" , lib);
@@ -368,8 +369,22 @@ class Drv2605 : public BasePeripheral<> {
368
369
return !ec; // return true if no error
369
370
}
370
371
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
+ */
371
384
bool calibrate (const ErmCalibrationSettings &cal_conf, CalibratedData &cal_data_out,
372
385
std::error_code &ec) {
386
+ std::lock_guard<std::recursive_mutex> lock (base_mutex_);
387
+
373
388
// if the motor type is not ERM, log a warning
374
389
if (motor_type_ != MotorType::ERM) {
375
390
logger_.warn (" Calibrating ERM motor while the motor type is set to {}" , motor_type_);
@@ -447,8 +462,22 @@ class Drv2605 : public BasePeripheral<> {
447
462
return true ; // return true if no error
448
463
}
449
464
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
+ */
450
477
bool calibrate (const LraCalibrationSettings &cal_conf, CalibratedData &cal_data_out,
451
478
std::error_code &ec) {
479
+ std::lock_guard<std::recursive_mutex> lock (base_mutex_);
480
+
452
481
// if the motor type is not LRA, log a warning
453
482
if (motor_type_ != MotorType::LRA) {
454
483
logger_.warn (" Calibrating LRA motor while the motor type is set to {}" , motor_type_);
0 commit comments