This commit is contained in:
Stephane D'Alu 2016-06-28 22:31:24 +02:00
parent 3cdd1360d4
commit 7cb533cd20
2 changed files with 61 additions and 63 deletions

View File

@ -1,5 +1,5 @@
/* /*
ChibiOS - Copyright (C) 2006..2016 Martino Migliavacca ChibiOS - Copyright (C) 2016..2016 Stéphane D'Alu
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -15,8 +15,8 @@
*/ */
/** /**
* @file TIMv1/hal_qei_lld.c * @file NRF51/hal_qei_lld.c
* @brief STM32 QEI subsystem low level driver header. * @brief NRF51 QEI subsystem low level driver header.
* *
* @addtogroup QEI * @addtogroup QEI
* @{ * @{
@ -31,46 +31,14 @@
/* Driver local definitions. */ /* Driver local definitions. */
/*===========================================================================*/ /*===========================================================================*/
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/** /**
* @brief QEID1 driver identifier. * @brief Common IRQ handler.
*/
#if NRF51_QEI_USE_QDEC1 || defined(__DOXYGEN__)
QEIDriver QEID1;
#endif
/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
#if NRF51_QEI_USE_QDEC1 == TRUE
/**
* @brief Quadrature decoder vector (QDEC)
* *
* @isr * @param[in] qeip pointer to an QEIDriver
*/ */
OSAL_IRQ_HANDLER(Vector88) { static void serve_interrupt(QEIDriver *qeip) {
QEIDriver *qeip = &QEID1;
NRF_QDEC_Type *qdec = qeip->qdec; NRF_QDEC_Type *qdec = qeip->qdec;
OSAL_IRQ_PROLOGUE();
osalSysLockFromISR();
if (qdec->EVENTS_ACCOF) { if (qdec->EVENTS_ACCOF) {
qdec->EVENTS_ACCOF = 0; qdec->EVENTS_ACCOF = 0;
qeip->overflowed++; qeip->overflowed++;
@ -152,10 +120,43 @@ OSAL_IRQ_HANDLER(Vector88) {
if (overflowed && qeip->config->overflow_cb) if (overflowed && qeip->config->overflow_cb)
qeip->config->overflow_cb(qeip, delta); qeip->config->overflow_cb(qeip, delta);
} }
}
osalSysUnlockFromISR();
/*===========================================================================*/
/* Driver exported variables. */
/*===========================================================================*/
/**
* @brief QEID1 driver identifier.
*/
#if NRF51_QEI_USE_QDEC1 || defined(__DOXYGEN__)
QEIDriver QEID1;
#endif
/*===========================================================================*/
/* Driver local variables and types. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
/*===========================================================================*/
/* Driver interrupt handlers. */
/*===========================================================================*/
#if NRF51_QEI_USE_QDEC1 == TRUE
/**
* @brief Quadrature decoder vector (QDEC)
*
* @isr
*/
OSAL_IRQ_HANDLER(Vector88) {
OSAL_IRQ_PROLOGUE();
serve_interrupt(&QEID1);
OSAL_IRQ_EPILOGUE(); OSAL_IRQ_EPILOGUE();
} }
#endif #endif
@ -263,6 +264,13 @@ void qei_lld_stop(QEIDriver *qeip) {
#endif #endif
qdec->INTENCLR = QDEC_INTENSET_REPORTRDY_Msk | qdec->INTENCLR = QDEC_INTENSET_REPORTRDY_Msk |
QDEC_INTENSET_ACCOF_Msk; QDEC_INTENSET_ACCOF_Msk;
// Return pins to reset state
palSetLineMode(cfg->phase_a, PAL_MODE_RESET);
palSetLineMode(cfg->phase_b, PAL_MODE_RESET);
if (cfg->led != PAL_NOLINE) {
palSetLineMode(cfg->led, PAL_MODE_RESET);
}
} }
} }
@ -294,10 +302,6 @@ void qei_lld_disable(QEIDriver *qeip) {
} }
#endif /* HAL_USE_QEI */ #endif /* HAL_USE_QEI */
/** @} */ /** @} */

View File

@ -1,5 +1,5 @@
/* /*
ChibiOS - Copyright (C) 2006..2016 Martino Migliavacca ChibiOS - Copyright (C) 2016..2016 Stéphane D'Alu
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -15,8 +15,8 @@
*/ */
/** /**
* @file TIMv1/hal_qei_lld.h * @file NRF51/hal_qei_lld.h
* @brief STM32 QEI subsystem low level driver header. * @brief NRF51 QEI subsystem low level driver header.
* *
* @addtogroup QEI * @addtogroup QEI
* @{ * @{
@ -28,7 +28,6 @@
#if (HAL_USE_QEI == TRUE) || defined(__DOXYGEN__) #if (HAL_USE_QEI == TRUE) || defined(__DOXYGEN__)
/*===========================================================================*/ /*===========================================================================*/
/* Driver constants. */ /* Driver constants. */
/*===========================================================================*/ /*===========================================================================*/
@ -40,8 +39,6 @@
#define QEI_COUNT_MAX 65535 #define QEI_COUNT_MAX 65535
/*===========================================================================*/ /*===========================================================================*/
/* Driver pre-compile time settings. */ /* Driver pre-compile time settings. */
/*===========================================================================*/ /*===========================================================================*/
@ -104,7 +101,7 @@ typedef enum {
} qeiresolution_t; } qeiresolution_t;
/** /**
* * @brief Clusters of samples.
*/ */
typedef enum { typedef enum {
QEI_REPORT_10 = 0x00UL, /**< 10 samples per report. */ QEI_REPORT_10 = 0x00UL, /**< 10 samples per report. */
@ -117,9 +114,8 @@ typedef enum {
QEI_REPORT_280 = 0x07UL, /**< 280 samples per report. */ QEI_REPORT_280 = 0x07UL, /**< 280 samples per report. */
} qeireport_t; } qeireport_t;
/** /**
* @brief Handling of counter overflow/underflow * @brief Handling of counter overflow/underflow.
*/ */
typedef enum { typedef enum {
QEI_OVERFLOW_WRAP = 0, /**< Counter value will wrap around. */ QEI_OVERFLOW_WRAP = 0, /**< Counter value will wrap around. */
@ -167,11 +163,8 @@ typedef struct {
/** /**
* @brief Handling of counter overflow/underflow * @brief Handling of counter overflow/underflow
* *
* @details When overflow callback is called, the counter value * @details When overflow accours, the counter value is updated
* is not updated, the decision on how to update is left * according to:
* to the callback.
*
* Three implementation are provided
* - QEI_OVERFLOW_DISCARD: * - QEI_OVERFLOW_DISCARD:
* discard the update value, counter doesn't change * discard the update value, counter doesn't change
* - QEI_OVERFLOW_MINMAX * - QEI_OVERFLOW_MINMAX
@ -183,17 +176,19 @@ typedef struct {
/** /**
* @brief Min count value. * @brief Min count value.
* *
* @note If min == max, the QEI_COUNT_MIN is used as default * @note If min == max, then QEI_COUNT_MIN is used.
*/ */
qeicnt_t min; qeicnt_t min;
/** /**
* @brief Max count value. * @brief Max count value.
* *
* @note If min == max, the QEI_COUNT_MAX is used as default * @note If min == max, then QEI_COUNT_MAX is used.
*/ */
qeicnt_t max; qeicnt_t max;
/** /**
* @brief Notify of value change * @brief Notify of value change
*
* @note Called from ISR context.
*/ */
qeicallback_t notify_cb; qeicallback_t notify_cb;
/** /**
@ -201,6 +196,7 @@ typedef struct {
* *
* @note Overflow notification is performed after * @note Overflow notification is performed after
* value changed notification. * value changed notification.
* @note Called from ISR context.
*/ */
void (*overflow_cb)(QEIDriver *qeip, qeidelta_t delta); void (*overflow_cb)(QEIDriver *qeip, qeidelta_t delta);
/* End of the mandatory fields.*/ /* End of the mandatory fields.*/
@ -251,6 +247,7 @@ typedef struct {
* @brief Notify of internal accumulator overflowed * @brief Notify of internal accumulator overflowed
* *
* @note MCU has discarded some of the samples. * @note MCU has discarded some of the samples.
* @note Called from ISR context.
*/ */
qeicallback_t overflowed_cb; qeicallback_t overflowed_cb;
} QEIConfig; } QEIConfig;
@ -275,9 +272,6 @@ struct QEIDriver {
QEI_DRIVER_EXT_FIELDS QEI_DRIVER_EXT_FIELDS
#endif #endif
/* End of the mandatory fields.*/ /* End of the mandatory fields.*/
/**
*/
qeidelta_t delta;
/** /**
*/ */
qeicnt_t count; qeicnt_t count;