Пример #1
0
/**
 * Initalize the GPIO unit for the leds
 */
void initLeds(void)
{
    GPIO_init(&g_gpio0, COREGPIO_IN_BASE_ADDR, GPIO_APB_32_BITS_BUS);

    // DIP Switches
    GPIO_config(&g_gpio0, GPIO_0, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_1, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_2, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_3, GPIO_INPUT_MODE);

    // Buttons
    GPIO_config(&g_gpio0, GPIO_4, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_5, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_6, GPIO_INPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_7, GPIO_INPUT_MODE);

    // LEDs
    GPIO_config(&g_gpio0, GPIO_8, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_9, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_10, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_11, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_12, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_13, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_14, GPIO_OUTPUT_MODE);
    GPIO_config(&g_gpio0, GPIO_15, GPIO_OUTPUT_MODE);

    GPIO_set_outputs(&g_gpio0, 0xFF00);
    led_state = 0;
}
Пример #2
0
/*------------------------------------------------------------------------------
 * Count the number of elapsed milliseconds (SysTick_Handler is called every
 * 10mS so the resolution will be 10ms). Rolls over every 49 days or so...
 *
 * Should be safe to read g_10ms_count from elsewhere.
 */
void SysTick_Handler( void )
{
    uint32_t gpio_pattern;
    static uint8_t count;
    /*
     * Toggle GPIO output pattern by doing an exclusive OR of all
     * pattern bits with ones.
     */
    if(count++>=50)
    {
        gpio_pattern = GPIO_get_outputs( &g_gpio );
        gpio_pattern ^= 0x00000002;
        GPIO_set_outputs( &g_gpio, gpio_pattern );
        count=0;
    }

    g_10ms_count += 10;

     /*
      * For neatness, if we roll over, reset cleanly back to 0 so the count
      * always goes up in proper 10s.
      */
    if(g_10ms_count < 10)
        g_10ms_count = 0;
}
Пример #3
0
/**
 * Set the led state of all leds at once. The state is committed to the GPIO
 * directly.
 *
 * @param 	state	the value to write to the leds
 * @param	mask	the mask value is one for each IO that is not effected by the
 * 					write operation. The value will always be masked with the led
 * 					so that the operation will only effect the leds.
 */
void setLeds(int state, int mask)
{
    mask = mask | LED_MASK;

    /* TODO: should be atomic, so create a mutex or so */
    uint32_t outputs = GPIO_get_outputs(&g_gpio0);
    outputs = (outputs & mask) | (state & ~mask);
    GPIO_set_outputs(&g_gpio0, outputs);
    /* end of critical section */
}
Пример #4
0
void writeGpio(uint32_t value)
{
    GPIO_set_outputs(&g_gpio0, value);
    uint32_t result = GPIO_get_outputs(&g_gpio0);
    dbprintf("[GPIO] write 0x%08x, read 0x%08x\n", value, result);
}