Ejemplo n.º 1
0
/*
 * \brief Configures Glitch or Debouncing filter for input.
 *
 * \param pPin       Pointer to a Pin instance describing one or more pins.
 * \param dwCutOff  Cut off frequency for debounce filter.
 */
extern void PIO_PinSetDebounceFilter( const Pin* pPin, uint32_t dwCutOff )
{
    Pio* pPio = pPin->pio ;

    pPio->PIO_DIFSR = pPin->mask; /* set Debouncing, 0 bit field no effect */
    pPio->PIO_SCDR = PIO_SCDR_DIV( (32678/(dwCutOff << 1)) - 1 ) ;
}
/**
 * \brief Configure Glitch or Debouncing filter for the specified input(s).
 *
 * \param p_pio Pointer to a PIO instance.
 * \param ul_mask Bitmask of one or more pin(s) to configure.
 * \param ul_cut_off Cuts off frequency for debouncing filter.
 */
void pio_set_debounce_filter(Pio *p_pio, const uint32_t ul_mask,
		const uint32_t ul_cut_off)
{
#if (SAM3S || SAM3N || SAM4S)
	/* Set Debouncing, 0 bit field no effect */
	p_pio->PIO_IFSCER = ul_mask;
#elif (SAM3XA || SAM3U)
	/* Set Debouncing, 0 bit field no effect */
	p_pio->PIO_DIFSR = ul_mask;
#else
#error "Unsupported device"
#endif

	/* The debouncing filter can filter a pulse of less than 1/2 Period of a
	   programmable Divided Slow Clock:
	   Tdiv_slclk = ((DIV+1)*2).Tslow_clock */
	p_pio->PIO_SCDR = PIO_SCDR_DIV((FREQ_SLOW_CLOCK_EXT /
					(2 * (ul_cut_off))) - 1);
}