Exemplo n.º 1
0
void port_dir(port_t *obj, PinDirection dir)
{
    uint32_t i;
    // The mode is set per pin: reuse gpio logic
    for (i=0; i<32; i++) {
        if (obj->mask & (1<<i)) {
            pin_dir(port_pin(obj->port, i), dir);
        }
    }
}
Exemplo n.º 2
0
/*
    Sets up the TCC module to send PWM output to the PWR LED
*/
void init_breathing_animation() {
    // Setup the pin to be used as a TCC output
    pin_mux(PIN_LED);
    pin_dir(PIN_LED, true);

    // Disable the TCC
    tcc(PWR_LED_TCC_CHAN)->CTRLA.reg = 0;

    // Reset the TCC
    tcc(PWR_LED_TCC_CHAN)->CTRLA.reg = TCC_CTRLA_SWRST;

    // Enable the timer
    timer_clock_enable(PWR_LED_TCC_CHAN);

    /* Set the prescalar setting to the highest division so we have more time
        in between interrupts to complete the math
    */
    tcc(PWR_LED_TCC_CHAN)->CTRLA.bit.PRESCALER = TCC_CTRLA_PRESCALER_DIV1024_Val;

    // Set the waveform generator to generate a PWM signal
    // It uses polarity setting of 1 (switches from DIR to ~DIR)
    tcc(PWR_LED_TCC_CHAN)->WAVE.reg = TCC_WAVE_WAVEGEN_NPWM | TCC_WAVE_POL0;

    // Set the top count value (when a match will be hit and the waveform output flipped)
    tcc(PWR_LED_TCC_CHAN)->PER.reg = MAX_COUNTER;

    // Set the counter number, starting at 0% duty cycle
    tcc(PWR_LED_TCC_CHAN)->CC[PWR_LED_CC_CHAN].reg = counter;

    // Set the second CCB value value be dark for simplicity
    tcc(PWR_LED_TCC_CHAN)->CCB[PWR_LED_CC_CHAN].bit.CCB = counter;

    // Enable IRQ's in the NVIC
    NVIC_EnableIRQ(TCC1_IRQn);
    // Set the priority to low
    NVIC_SetPriority(TCC1_IRQn, 0xff);
    // Enable interrupts so we can modify the counter value (creates breathing effect)
    tcc(PWR_LED_TCC_CHAN)->INTENSET.reg = TC_INTENSET_OVF;

    // Wait for all the changes to finish loading?
    while (tcc(PWR_LED_TCC_CHAN)->SYNCBUSY.reg > 0);

    // Enable the TCC
    tcc(PWR_LED_TCC_CHAN)->CTRLA.reg = TCC_CTRLA_ENABLE;
}
Exemplo n.º 3
0
void port_init(port_t *obj, PortName port, int mask, PinDirection dir)
{
    obj->port = port;
    obj->mask = mask;
    obj->reg_out = &MXC_GPIO->out_val[port];
    obj->reg_in  = &MXC_GPIO->in_val[port];

    /* Ensure that the GPIO clock is enabled */
	MXC_CLKMAN->sys_clk_ctrl_6_gpio = MXC_S_CLKMAN_CLK_SCALE_DIV_1;

    uint32_t i;
    // The function is set per pin: reuse gpio logic
    for (i=0; i<32; i++) {
        if (obj->mask & (1<<i)) {
            gpio_set(port_pin(obj->port, i));
            pin_dir(port_pin(obj->port, i), dir);
        }
    }
}