2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 ao_led_on(AO_LED_TYPE colors)
25 LED_PORT->bsrr = (colors & LEDS_AVAILABLE);
28 LED_PORT_0->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
31 LED_PORT_1->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
37 ao_led_off(AO_LED_TYPE colors)
40 LED_PORT->bsrr = (uint32_t) (colors & LEDS_AVAILABLE) << 16;
43 LED_PORT_0->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16);
46 LED_PORT_1->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16);
52 ao_led_set(AO_LED_TYPE colors)
54 AO_LED_TYPE on = colors & LEDS_AVAILABLE;
55 AO_LED_TYPE off = ~colors & LEDS_AVAILABLE;
62 ao_led_for(AO_LED_TYPE colors, AO_TICK_TYPE ticks)
69 #define init_led_pin(port, bit) do { \
70 stm_moder_set(port, bit, STM_MODER_OUTPUT); \
71 stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \
80 stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE);
81 LED_PORT->odr &= ~LEDS_AVAILABLE;
84 stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE);
85 LED_PORT_0->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
88 stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE);
89 LED_PORT_1->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
92 for (bit = 0; bit < 16; bit++) {
93 if (LEDS_AVAILABLE & (1 << bit)) {
95 init_led_pin(LED_PORT, bit);
98 if (LED_PORT_0_MASK & (1 << bit))
99 init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT);
102 if (LED_PORT_1_MASK & (1 << bit))
103 init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT);