diff options
Diffstat (limited to 'os/hal/src/hal_qei.c')
| -rw-r--r-- | os/hal/src/hal_qei.c | 48 | 
1 files changed, 43 insertions, 5 deletions
| diff --git a/os/hal/src/hal_qei.c b/os/hal/src/hal_qei.c index abecdf8..eb6223e 100644 --- a/os/hal/src/hal_qei.c +++ b/os/hal/src/hal_qei.c @@ -42,10 +42,6 @@  /* Driver local functions.                                                   */
  /*===========================================================================*/
 -/*===========================================================================*/
 -/* Driver exported functions.                                                */
 -/*===========================================================================*/
 -
  /**
   * @brief   Helper for correclty handling overflow/underflow
   *
 @@ -66,6 +62,7 @@   *                was due to occur
   *
   */
 +static inline
  bool qei_adjust_count(qeicnt_t *count, qeidelta_t *delta,
  		      qeicnt_t min, qeicnt_t max, qeioverflow_t mode) {
    /* For information on signed integer overflow see:
 @@ -131,6 +128,10 @@ bool qei_adjust_count(qeicnt_t *count, qeidelta_t *delta,    }
  }
 +/*===========================================================================*/
 +/* Driver exported functions.                                                */
 +/*===========================================================================*/
 +
  /**
   * @brief   QEI Driver initialization.
   * @note    This function is implicitly invoked by @p halInit(), there is
 @@ -284,13 +285,50 @@ qeidelta_t qeiAdjust(QEIDriver *qeip, qeidelta_t delta) {    osalDbgAssert((qeip->state == QEI_ACTIVE), "invalid state");
    osalSysLock();
 -  delta = qei_lld_adjust_count(qeip, delta);
 +  delta = qeiAdjustI(qeip, delta);
    osalSysUnlock();
    return delta;
  }
  /**
 + * @brief   Adjust the counter by delta.
 + *
 + * @param[in] qeip      pointer to the @p QEIDriver object.
 + * @param[in] delta     the adjustement value.
 + * @return              the remaining delta (can occur during overflow).
 + *
 + * @api
 + */
 +qeidelta_t qeiAdjustI(QEIDriver *qeip, qeidelta_t delta) {
 +  /* Get boundaries */
 +  qeicnt_t min = QEI_COUNT_MIN;
 +  qeicnt_t max = QEI_COUNT_MAX;
 +  if (qeip->config->min != qeip->config->max) {
 +    min = qeip->config->min;
 +    max = qeip->config->max;
 +  }
 +
 +  /* Get counter */
 +  qeicnt_t count = qei_lld_get_count(qeip);
 +  
 +  /* Adjust counter value */
 +  bool overflowed = qei_adjust_count(&count, &delta,
 +				     min, max, qeip->config->overflow);
 +
 +  /* Notify for value change */
 +  qei_lld_set_count(qeip, count);
 +
 +  /* Notify for overflow (passing the remaining delta) */
 +  if (overflowed && qeip->config->overflow_cb)
 +    qeip->config->overflow_cb(qeip, delta);
 +
 +  /* Remaining delta */
 +  return delta;
 +}
 +
 +
 +/**
   * @brief   Returns the counter delta from last reading.
   *
   * @param[in] qeip      pointer to the @p QEIDriver object
 | 
