コード例 #1
0
void LcdDisplayInitPwm(void)
{
    PioSetMode(PIO_LED, pio_mode_user);
    PioSetDir(PIO_LED, TRUE); /* Output */
    PioSet(PIO_LED, FALSE);

    PioSetMode(PIO_LED, pio_mode_pwm0); /* PIO is controlled by PWM. */

    LcdDisplayBacklight(10, 10);        /* Start with dim light. */
    
    PioEnablePWM(PWM_ID_LED, TRUE);
} /* LcdDisplayInitPwm */
コード例 #2
0
void LcdDisplayInitRst(void)
{
    /* Set up the PIOs for the RST pin on the LCD display. */
    PioSetPullModes((1UL << PIO_RST), pio_mode_no_pulls);
    PioSetMode(PIO_RST, pio_mode_user);
    PioSetDir(PIO_RST, TRUE); /* Output */
    PioSet(PIO_RST, TRUE);
} /* LcdDisplayInitRst */
コード例 #3
0
ファイル: beacon.c プロジェクト: arm11a/pirWithBLE
void AppInit(sleep_state last_sleep_state)
{
    /* set all PIOs to inputs and pull them down */
    PioSetModes(0xFFFFFFFFUL, pio_mode_user);
    PioSetDirs(0xFFFFFFFFUL, FALSE);
    PioSetPullModes(0xFFFFFFFFUL, pio_mode_strong_pull_down);
    
    /* Set LED0 and LED1 to be controlled directly via PioSet */
    PioSetModes((1UL << PIO_LED0), pio_mode_user);

    /* Configure LED0 and LED1 to be outputs */
    PioSetDir(PIO_LED0, PIO_DIR_OUTPUT);

    /* Set the LED0 and LED1 to have strong internal pull ups */
    PioSetPullModes((1UL << PIO_LED0),
                    pio_mode_strong_pull_up);

    /* Configure button to be controlled directly */
    PioSetMode(PIR_SIGNAL, pio_mode_user);

    /* Configure button to be input */
    PioSetDir(PIR_SIGNAL, PIO_DIR_INPUT);

    /* Set weak pull up on button PIO, in order not to draw too much current
     * while button is pressed
     */
    PioSetPullModes((1UL << PIR_SIGNAL), pio_mode_weak_pull_down);

    /* Set the button to generate sys_event_pio_changed when pressed as well
     * as released
     */
    PioSetEventMask((1UL << PIR_SIGNAL), pio_event_mode_rising);


    /* disable wake up on UART RX */
    SleepWakeOnUartRX(FALSE);
    
    /* pull down the I2C lines */
    PioSetI2CPullMode(pio_i2c_pull_mode_strong_pull_down);

    /* Reset LED sequence */
    restartLedSeq();

	SleepModeChange(sleep_mode_deep);


    TimerInit(MAX_APP_TIMERS, (void*)app_timers);

    BeaconInit();

    pirStatusServiceInit();
}
コード例 #4
0
ファイル: main.c プロジェクト: NemProjects/CSR1010-MMA9550
/*----------------------------------------------------------------------------*
 *  NAME
 *      AppInit
 *
 *  DESCRIPTION
 *      This user application function is called after a power-on reset
 *      (including after a firmware panic), after a wakeup from Hibernate or
 *      Dormant sleep states, or after an HCI Reset has been requested.
 *
 *      NOTE: In the case of a power-on reset, this function is called
 *      after AppPowerOnReset().
 *
 * PARAMETERS
 *      last_sleep_state [in]   Last sleep state
 *
 * RETURNS
 *      Nothing
 *----------------------------------------------------------------------------*/
void AppInit(sleep_state last_sleep_state)
{
    /* Initialise UART communications */
    DebugInit(1, NULL, NULL);

    DebugWriteString("Configuring PWM Modes\r\n");

    /* Configure the output PIO on which the slow flashing LED signal is
     * generated */
    PioSetDir(PIO_LED, PIO_DIR_OUTPUT);

    /* SLOW FLASHING WITH PWM:
     * Configure PWM 0 to have the following characteristics
     * DULL LED Light is generated by having pulses of 0ms ON and
     *      6ms OFF (~0% duty cycle)
     * BRIGHT LED Light is generated by having pulses of 6ms ON and
     *      0ms OFF (~100% duty cycle)
     * Dullest and Brightest level are held for ~1s
     *
     * The brightness level ramps for ~1s when going from dullest to
     * brightest and vice-versa */
    if (PioConfigPWM(0, pio_pwm_mode_push_pull,
                     /* Pulse timings for the dullest part of the sequence:
                      * dullest part of the sequence has the pulse off for the whole
                      * period, in effect the line stays low for the duration for which
                      * the dullest part of the sequence lasts. */
                     0,          /* ON time for the pulse is 0us */
                     255,        /* OFF time for the pulse is (255 * 30)us */
                     62,         /* Dullest part of the sequence lasts for
                            ( 62 * 16 )ms before ramping up to the brightest
                            part of the sequence */

                     /* Pulse timings for the brightest part of the sequence:
                      * brightest part of the sequence has the pulse ON for the whole
                      * period, in effect the line stays high for the duration for which
                      * the brightest part of the sequence lasts. */
                     255,        /* ON time for the pulse is (255 * 30)us */
                     0,          /* OFF time for the pulse is 0us */
                     62,         /* Brightest part of the sequence lasts for
                            ( 62 * 16 )ms before ramping down to the dullest
                            part of the sequence */

                     /* Ramping between dullest and brightest parts of the sequence
                      * This parameter determines the duration for which the ramping
                      * lasts when going from dullest to the brightest (and vice-versa).
                      *
                      * The total duration for which the ramping lasts is determined by
                      * multiplying this value with one less than the difference between
                      * the on_time or off_time of the two states, whichever is bigger;
                      * in the units of 30us
                      * */
                     132         /* Ramping lasts for ((255-1) * 132 * 30)us */
                    ))
    {
        DebugWriteString("PWM0 was set to ramp between brightest and dullest "
                         "levels\r\n");

        /* Connect PWM0 output to LED */
        PioSetMode(PIO_LED, pio_mode_pwm0);

        /* Enable the PWM0 */
        PioEnablePWM(0, TRUE);
    }
    else
    {
        DebugWriteString("PWM0 couldn't be configured\r\n");
    }

    /* Set both outputs to have strong internal pull ups */
    PioSetPullModes((1UL << PIO_MOTOR) | (1UL << PIO_LED),
                    pio_mode_strong_pull_up);

    /* Configure motor PIO to be output */
    PioSetDir(PIO_MOTOR, PIO_DIR_OUTPUT);

    /* Connect PWM1 output to motor PIO */
    PioSetMode(PIO_MOTOR, pio_mode_pwm1);

    /* Initialise timers */
    TimerInit(MAX_APP_TIMERS, app_timers);

    /* Call the function (with a dummy timer ID to start with) to configure
     * the PWM1 with initial duty cycle and start a timer. When the timer
     * expires the same function gets called again and the duty cycle for
     * PWM1 gets updated. It takes care of restarting the timer and ensuring
     * that duty cycle alternates between 0% and 100% back and forth. */
    dutyCycleTask(TIMER_INVALID);

    /* Enable the PWM1 */
    PioEnablePWM(1, TRUE);
}