conditionally include support for LED

This commit is contained in:
Stephane D'Alu 2016-06-29 12:26:22 +02:00
parent dde47ff1ab
commit 5fee893778
2 changed files with 22 additions and 2 deletions

View File

@ -199,9 +199,11 @@ void qei_lld_start(QEIDriver *qeip) {
// Set Pins
palSetLineMode(cfg->phase_a, PAL_MODE_INPUT);
palSetLineMode(cfg->phase_b, PAL_MODE_INPUT);
#if NRF51_QEI_USE_LED == TRUE
if (cfg->led != PAL_NOLINE) {
palSetLineMode(cfg->led, PAL_MODE_INPUT);
}
#endif
// Set interrupt masks and enable interrupt
qdec->INTENSET = QDEC_INTENSET_REPORTRDY_Msk |
@ -217,13 +219,17 @@ void qei_lld_start(QEIDriver *qeip) {
qdec->PSELB = PAL_PAD(cfg->phase_b);
// Select (optional) pin for LED, and configure it
#if NRF51_QEI_USE_LED == TRUE
qdec->PSELLED = PAL_PAD(cfg->led);
qdec->LEDPOL = ((cfg->led_polarity == QEI_LED_POLARITY_LOW)
? QDEC_LEDPOL_LEDPOL_ActiveLow
: QDEC_LEDPOL_LEDPOL_ActiveHigh)
<< QDEC_LEDPOL_LEDPOL_Pos;
qdec->LEDPRE = cfg->led_warming;
#else
qdec->PSELLED = (uint32_t)-1;
#endif
// Set sampling resolution and debouncing
qdec->SAMPLEPER = cfg->resolution;
qdec->DBFEN = (cfg->debouncing ? QDEC_DBFEN_DBFEN_Enabled
@ -272,9 +278,11 @@ void qei_lld_stop(QEIDriver *qeip) {
// Return pins to reset state
palSetLineMode(cfg->phase_a, PAL_MODE_RESET);
palSetLineMode(cfg->phase_b, PAL_MODE_RESET);
#if NRF51_QEI_USE_LED == TRUE
if (cfg->led != PAL_NOLINE) {
palSetLineMode(cfg->led, PAL_MODE_RESET);
}
#endif
}
}

View File

@ -51,6 +51,16 @@
* @name Configuration options
* @{
*/
/**
* @brief LED control enable switch.
* @details If set to @p TRUE the support for LED control
* is included.
* @note The default is @p FALSE.
*/
#if !defined(NRF51_QEI_USE_LED) || defined(__DOXYGEN__)
#define NRF51_QEI_USE_LED FALSE
#endif
/**
* @brief QEID1 driver enable switch.
* @details If set to @p TRUE the support for QEID1 is included.
@ -217,8 +227,9 @@ typedef struct {
* @brief Line for reading Phase B
*/
ioline_t phase_b;
#if (NRF51_QEI_USE_LED == TRUE) || defined(__DOXYGEN__)
/**
* @brief Line to use to control LED
* @brief Line used to control LED
*
* @note If LED is not controlled by MCU, you need to use the
* PAL_NOLINE value.
@ -239,6 +250,7 @@ typedef struct {
* @brief LED polarity to used (when LED is controlled by MCU)
*/
uint8_t led_polarity;
#endif
/**
* @brief Activate debouncing filter
*