Exemple #1
0
/*----------------------------------------------------------------------------*
 *  NAME
 *      InitHardware
 *
 *  DESCRIPTION
 *      This function is called to initialise the application hardware.
 *
 *  PARAMETERS
 *      None
 *
 *  RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
extern void InitHardware(void)
{
    /* Setup PIOs
     * PIO11 - Button
     */
    /* Set the button PIO to user mode */
    PioSetModes(BUTTON_PIO_MASK, pio_mode_user);

    /* Set the PIO direction as input */
    PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT);

    /* Pull up the PIO */
    PioSetPullModes(BUTTON_PIO_MASK, pio_mode_strong_pull_up);

    /* Initialise buzzer hardware */
    BuzzerInitHardware();
    
    /* Initialise LED hardware */
    LedInitHardware();

    /* Request an event when the button PIO changes state */
    PioSetEventMask(BUTTON_PIO_MASK, pio_event_mode_both);

    /* Save power by changing the I2C pull mode to pull down.*/
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);
}
extern void WeightInitHardware(void)
{
    /* Set up PIOs
     * PIO11 - Button
     */
    /* Set the button PIO to user mode */
    PioSetModes(BUTTON_PIO_MASK, pio_mode_user);

    /* Set the PIO direction as input. */
    PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT);

    /* Pull up the PIO. */
    PioSetPullModes(BUTTON_PIO_MASK, pio_mode_strong_pull_up);

    /* Initialise Buzzer Hardware */
    BuzzerInitHardware();

    /* Set up button on PIO11 */
    PioSetEventMask(BUTTON_PIO_MASK, pio_event_mode_both);

    /* Save power by changing the I2C pull mode to pull down */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);

#ifdef ENABLE_LEDBLINK
    /* PIO 4 is being used for LED glowing. */
    PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_user); /* user mode set */
    PioSetDir(LED_PIO, PIO_DIRECTION_OUTPUT);   /* output */
    PioSet(LED_PIO, FALSE);     /* set low */
#endif /* ENABLE_LEDBLINK */

}
/*----------------------------------------------------------------------------*
 *  NAME
 *      InitTimeClientHardware-initialize application hardware
 *
 *  DESCRIPTION
 *      This function is called upon a power reset to initialize the PIOs
 *      and configure their initial states.
 *
 *  RETURNS
 *      Nothing.
 *
 *----------------------------------------------------------------------------*/
extern void InitTimeClientHardware(void)
{
    /* Setup PIOs
     * PIO3 - Buzzer - BUZZER_PIO
     * PIO4 - LED 1 - LED_PIO
     * PIO11 - Button - BUTTON_PIO
     */

    PioSetModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_user);
    PioSetDir(BUTTON_PIO, PIO_DIRECTION_INPUT); /* input */
    PioSetPullModes(PIO_BIT_MASK(BUTTON_PIO), pio_mode_strong_pull_up); 
    /* Setup button on PIO11 */
    PioSetEventMask(PIO_BIT_MASK(BUTTON_PIO), pio_event_mode_both);

    /* Initialize Buzzer Hardware */
    BuzzerInitHardware();

#ifdef ENABLE_LEDBLINK
    /* PWM is being used for LED glowing.*/
    PioSetModes(PIO_BIT_MASK(LED_PIO), pio_mode_pwm1);

    /* Advertising parameters are being configured for PWM right now. When
     * application moves to connection state, we change PWM parameters to
     * the ones for connection
     */

    PioConfigPWM(LED_PWM_INDEX_1, pio_pwm_mode_push_pull, DULL_LED_ON_TIME_ADV,
         DULL_LED_OFF_TIME_ADV, DULL_LED_HOLD_TIME_ADV, BRIGHT_LED_OFF_TIME_ADV,
         BRIGHT_LED_ON_TIME_ADV, BRIGHT_LED_HOLD_TIME_ADV, LED_RAMP_RATE);

    PioEnablePWM(LED_PWM_INDEX_1, FALSE);
#endif /* ENABLE_LEDBLINK */

    /* Set the I2C pins to pull down */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);
}