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.
21 __pdata uint16_t ao_led_enable;
24 ao_led_on(uint16_t colors)
27 LED_PORT->bsrr = (colors & ao_led_enable);
30 LED_PORT_0->bsrr = ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
33 LED_PORT_1->bsrr = ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
39 ao_led_off(uint16_t colors)
42 LED_PORT->bsrr = (uint32_t) (colors & ao_led_enable) << 16;
45 LED_PORT_0->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16);
48 LED_PORT_1->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16);
54 ao_led_set(uint16_t colors)
56 uint16_t on = colors & ao_led_enable;
57 uint16_t off = ~colors & ao_led_enable;
64 ao_led_toggle(uint16_t colors)
67 LED_PORT->odr ^= (colors & ao_led_enable);
70 LED_PORT_0->odr ^= ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
73 LED_PORT_1->odr ^= ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
79 ao_led_for(uint16_t colors, uint16_t ticks) __reentrant
86 #define init_led_pin(port, bit) do { \
87 stm_moder_set(port, bit, STM_MODER_OUTPUT); \
88 stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \
92 ao_led_init(uint16_t enable)
96 ao_led_enable = enable;
98 stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE);
99 LED_PORT->odr &= ~enable;
102 stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE);
103 LED_PORT_0->odr &= ~((enable & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
106 stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE);
107 LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
110 for (bit = 0; bit < 16; bit++) {
111 if (enable & (1 << bit)) {
113 init_led_pin(LED_PORT, bit);
116 if (LED_PORT_0_MASK & (1 << bit))
117 init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT);
120 if (LED_PORT_1_MASK & (1 << bit))
121 init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT);