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 #error LED_PER_LED support is in ao_led.c now
26 ao_led_on(AO_LED_TYPE colors)
29 LED_PORT->bsrr = (colors & LEDS_AVAILABLE);
32 LED_PORT_0->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
35 LED_PORT_1->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
38 LED_PORT_2->bsrr = ((colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << LED_PORT_2_SHIFT;
44 ao_led_off(AO_LED_TYPE colors)
47 LED_PORT->bsrr = (uint32_t) (colors & LEDS_AVAILABLE) << 16;
50 LED_PORT_0->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16);
53 LED_PORT_1->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16);
56 LED_PORT_2->bsrr = ((uint32_t) (colors & LEDS_AVAILABLE) & LED_PORT_2_MASK) << (LED_PORT_2_SHIFT + 16);
62 ao_led_set(AO_LED_TYPE colors)
64 AO_LED_TYPE on = colors & LEDS_AVAILABLE;
65 AO_LED_TYPE off = ~colors & LEDS_AVAILABLE;
72 ao_led_for(AO_LED_TYPE colors, AO_TICK_TYPE ticks)
79 #define init_led_pin(port, bit) do { \
80 stm_moder_set(port, bit, STM_MODER_OUTPUT); \
81 stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \
90 stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE);
91 LED_PORT->odr &= ~LEDS_AVAILABLE;
94 stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE);
95 LED_PORT_0->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
98 stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE);
99 LED_PORT_1->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
102 stm_rcc.ahbenr |= (1 << LED_PORT_2_ENABLE);
103 LED_PORT_2->odr &= (uint32_t) ~(LEDS_AVAILABLE & LED_PORT_2_MASK) << LED_PORT_2_SHIFT;
106 for (bit = 0; bit < sizeof (AO_LED_TYPE) * 8; bit++) {
107 if (LEDS_AVAILABLE & (1 << bit)) {
109 init_led_pin(LED_PORT, bit);
112 if (LED_PORT_0_MASK & (1 << bit))
113 init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT);
116 if (LED_PORT_1_MASK & (1 << bit))
117 init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT);
120 if (LED_PORT_2_MASK & (1 << bit))
121 init_led_pin(LED_PORT_2, bit + LED_PORT_2_SHIFT);