Пример #1
0
/**
 * \brief Configures a list of Pin instances, each of which can either hold a single
 * pin or a group of pins, depending on the mask value; all pins are configured
 * by this function. The size of the array must also be provided and is easily
 * computed using PIO_LISTSIZE whenever its length is not known in advance.
 *
 * \param list  Pointer to a list of Pin instances.
 * \param size  Size of the Pin list (calculated using PIO_LISTSIZE).
 *
 * \return 1 if the pins have been configured properly; otherwise 0.
 */
uint8_t PIO_Configure( const Pin *list, uint32_t size )
{
    /* Configure pins */
    while ( size > 0 )
    {
        switch ( list->type )
        {

            case PIO_PERIPH_A:
                PIO_SetPeripheralA(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            case PIO_PERIPH_B:
                PIO_SetPeripheralB(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            case PIO_PERIPH_C:
                PIO_SetPeripheralC(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            case PIO_PERIPH_D:
                PIO_SetPeripheralD(list->pio,
                        list->mask,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
            case PIO_INPUT:
#ifndef __FPGA
                PMC_EnablePeripheral(list->id);
#endif
                PIO_SetInput(list->pio,
                        list->mask,
                        list->attribute);
                break;

            case PIO_OUTPUT_0:
            case PIO_OUTPUT_1:
                PIO_SetOutput(list->pio,
                        list->mask,
                        (list->type == PIO_OUTPUT_1),
                        (list->attribute & PIO_OPENDRAIN) ? 1 : 0,
                        (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;

            default: return 0;
        }

        list++;
        size--;
    }

    return 1;
}
Пример #2
0
//------------------------------------------------------------------------------
/// Configures a list of Pin instances, each of which can either hold a single
/// pin or a group of pins, depending on the mask value; all pins are configured
/// by this function. The size of the array must also be provided and is easily
/// computed using PIO_LISTSIZE whenever its length is not known in advance.
/// \param list  Pointer to a list of Pin instances.
/// \param size  Size of the Pin list (calculated using PIO_LISTSIZE).
/// \return 1 if the pins have been configured properly; otherwise 0.
//------------------------------------------------------------------------------
unsigned char PIO_Configure(const Pin *list, unsigned int size)
{
    // Configure pins
    while (size > 0) {
    
        switch (list->type) {
    
            case PIO_PERIPH_A:
                PIO_SetPeripheralA(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_PERIPH_B:
                PIO_SetPeripheralB(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_INPUT:
                AT91C_BASE_PMC->PMC_PCER = 1 << list->id;
                PIO_SetInput(list->pio,
                             list->mask,
                             (list->attribute & PIO_PULLUP) ? 1 : 0,
                             (list->attribute & PIO_DEGLITCH)? 1 : 0);

                #if defined(AT91C_PIOA_IFDGSR) //PIO3 with Glitch or Debouncing selection
                //if glitch input filter enabled, set it
                if(list->attribute & PIO_DEGLITCH)//Glitch input filter enabled
                    PIO_SetFilter(list->pio,
                        list->inFilter.filterSel,
                        list->inFilter.clkDivider);
                #endif
                break;
    
            case PIO_OUTPUT_0:
            case PIO_OUTPUT_1:
                PIO_SetOutput(list->pio,
                              list->mask,
                              (list->type == PIO_OUTPUT_1),
                              (list->attribute & PIO_OPENDRAIN) ? 1 : 0,
                              (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            default: return 0;
        }

        list++;
        size--;
    }

    return 1;
}
Пример #3
0
//------------------------------------------------------------------------------
//         Exported functions
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
/// Configures a list of Pin instances, which can either hold a single pin or a 
/// group of pins, depending on the mask value; all pins are configured by this 
/// function.
/// Returns 1 if the configuration has been performed successfully; otherwise 0.
/// \param list  Pointer to a list of Pin instances.
/// \param size  Size of the Pin list (see <PIO_LISTSIZE>).
//------------------------------------------------------------------------------
unsigned char PIO_Configure(const Pin *list, unsigned int size)
{
    // Configure pins
    while (size > 0) {
    
        switch (list->type) {
    
            case PIO_PERIPH_A:
                PIO_SetPeripheralA(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_PERIPH_B:
                PIO_SetPeripheralB(list->pio,
                                   list->mask,
                                   (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            case PIO_INPUT:
                AT91C_BASE_PMC->PMC_PCER = 1 << list->id;
                PIO_SetInput(list->pio,
                             list->mask,
                             (list->attribute & PIO_PULLUP) ? 1 : 0,
                             (list->attribute & PIO_DEGLITCH)? 1 : 0);
                break;
    
            case PIO_OUTPUT_0:
            case PIO_OUTPUT_1:
                PIO_SetOutput(list->pio,
                              list->mask,
                              (list->type == PIO_OUTPUT_1),
                              (list->attribute & PIO_OPENDRAIN) ? 1 : 0,
                              (list->attribute & PIO_PULLUP) ? 1 : 0);
                break;
    
            default: return 0;
        }

        list++;
        size--;
    }

    return 1;
}
Пример #4
0
/**
 * \brief Configures a list of Pin instances, each of which can either hold a single
 * pin or a group of pins, depending on the mask value; all pins are configured
 * by this function. The size of the array must also be provided and is easily
 * computed using PIO_LISTSIZE whenever its length is not known in advance.
 *
 * \param list  Pointer to a list of Pin instances.
 * \param size  Size of the Pin list (calculated using PIO_LISTSIZE).
 *
 * \return 1 if the pins have been configured properly; otherwise 0.
 */
extern uint32_t PIO_PinConfigure( const Pin* pPins, uint32_t dwSize )
{
    uint32_t dwOptions=0 ;

    /* Configure pins */
    while ( dwSize > 0 )
    {
        switch ( pPins->type )
        {
            case PIO_PERIPH_A :
                if ( pPins->attribute & PIO_PULLUP )
                {
                    dwOptions=PIO_PULLUP ;
                }

                PIO_SetPeripheralA( pPins->pio, pPins->mask, dwOptions ) ;
            break ;

            case PIO_PERIPH_B :
                if ( pPins->attribute & PIO_PULLUP )
                {
                    dwOptions=PIO_PULLUP ;
                }

                PIO_SetPeripheralB( pPins->pio, pPins->mask, dwOptions ) ;
            break ;

            case PIO_INPUT :
                PMC_EnablePeripheral( pPins->id ) ;
                PIO_SetInput( pPins->pio, pPins->mask, pPins->attribute ) ;
            break ;

            case PIO_OUTPUT_0 :
            case PIO_OUTPUT_1 :
                if ( pPins->type == PIO_OUTPUT_1 )
                {
                    dwOptions|=PIO_OUTPUT_HIGH ;
                }

                if ( pPins->attribute & PIO_OPENDRAIN )
                {
                    dwOptions|=PIO_OPENDRAIN ;
                }

                if ( pPins->attribute & PIO_PULLUP )
                {
                    dwOptions|=PIO_PULLUP ;
                }

                PIO_SetOutput( pPins->pio, pPins->mask, dwOptions ) ;
            break ;

            default :
                return 0 ;
        }

        pPins++ ;
        dwSize-- ;
    }

    return 1 ;
}