Skip to content

Commit 2cdb1f3

Browse files
committed
altos: Add generic LED driver.
This driver uses the generic GPIO functions and allows per-LED port and pin configuration. It supports up to 32 LEDs. Rename SoC-specific LED drivers. Remove enabled parameter to ao_led_init Signed-off-by: Keith Packard <[email protected]>
1 parent cdaa0d7 commit 2cdb1f3

File tree

85 files changed

+843
-336
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+843
-336
lines changed

src/attiny/ao_arch.h

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#define AO_PORT_TYPE uint8_t
3636

37+
#define AO_LED_TYPE uint8_t
38+
3739
/* Various definitions to make GCC look more like SDCC */
3840

3941
#define ao_arch_naked_declare __attribute__((naked))

src/attiny/ao_led.c src/attiny/ao_led_tiny.c

+8-11
Original file line numberDiff line numberDiff line change
@@ -18,47 +18,44 @@
1818

1919
#include "ao.h"
2020

21-
uint8_t ao_led_enable;
22-
2321
#define LED_PORT PORTB
2422
#define LED_DDR DDRB
2523

2624
void
2725
ao_led_on(uint8_t colors)
2826
{
29-
LED_PORT |= (colors & ao_led_enable);
27+
LED_PORT |= colors;
3028
}
3129

3230
void
3331
ao_led_off(uint8_t colors)
3432
{
35-
LED_PORT &= ~(colors & ao_led_enable);
33+
LED_PORT &= ~colors;
3634
}
3735

3836
void
3937
ao_led_set(uint8_t colors)
4038
{
41-
LED_PORT = (LED_PORT & ~(ao_led_enable)) | (colors & ao_led_enable);
39+
LED_PORT = (LED_PORT & ~LEDS_AVAILABLE) | (colors & LEDS_AVAILABLE);
4240
}
4341

4442
void
4543
ao_led_toggle(uint8_t colors)
4644
{
47-
LED_PORT ^= (colors & ao_led_enable);
45+
LED_PORT ^= (colors & LEDS_AVAILABLE);
4846
}
4947

5048
void
51-
ao_led_for(uint8_t colors, uint16_t ticks)
49+
ao_led_for(uint8_t colors, AO_TICK_TYPE ticks)
5250
{
5351
ao_led_on(colors);
5452
ao_delay(ticks);
5553
ao_led_off(colors);
5654
}
5755

5856
void
59-
ao_led_init(uint8_t enable)
57+
ao_led_init(void)
6058
{
61-
ao_led_enable = enable;
62-
LED_PORT &= ~enable;
63-
LED_DDR |= enable;
59+
LED_PORT &= ~LEDS_AVAILABLE;
60+
LED_DDR |= LEDS_AVAILABLE;
6461
}

src/avr-demo/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ ALTOS_SRC = \
3838
ao_stdio.c \
3939
ao_task.c \
4040
ao_timer.c \
41-
ao_led.c \
41+
ao_led_avr.c \
4242
ao_usb_avr.c \
4343
ao_lcd.c
4444

File renamed without changes.

src/chaoskey-v0.1/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ ALTOS_SRC = \
2828
ao_adc_fast.c \
2929
ao_crc_stm.c \
3030
ao_stdio.c \
31-
ao_led.c \
31+
ao_led_stmf0.c \
3232
ao_romconfig.c \
3333
ao_boot_chain.c \
3434
ao_usb_stm.c \

src/chaoskey-v1.0/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ALTOS_SRC = \
3030
ao_adc_fast.c \
3131
ao_crc_stm.c \
3232
ao_stdio.c \
33-
ao_led.c \
33+
ao_led_stmf0.c \
3434
ao_romconfig.c \
3535
ao_boot_chain.c \
3636
ao_usb_stm.c \

src/chaoskey-v1.0/ao_chaoskey.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
void main(void)
2626
{
27-
ao_led_init(LEDS_AVAILABLE);
27+
ao_led_init();
2828
ao_clock_init();
2929
ao_task_init();
3030
ao_timer_init();

src/detherm/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ALTOS_SRC = \
2727
ao_spi_stm.c \
2828
ao_exti_stm.c \
2929
ao_stdio.c \
30-
ao_led.c \
30+
ao_led_stmf0.c \
3131
ao_log.c \
3232
ao_log_mini.c \
3333
ao_sample.c \
+54-96
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright © 2012 Keith Packard <[email protected]>
2+
* Copyright © 2018 Keith Packard <[email protected]>
33
*
44
* This program is free software; you can redistribute it and/or modify
55
* it under the terms of the GNU General Public License as published by
@@ -18,7 +18,6 @@
1818

1919
#include "ao.h"
2020

21-
#if LED_PER_LED
2221
static const struct {
2322
struct stm_gpio *port;
2423
uint16_t pin;
@@ -71,146 +70,105 @@ static const struct {
7170
#ifdef LED_15_PORT
7271
[15] { LED_15_PORT, LED_15_PIN },
7372
#endif
73+
#ifdef LED_16_PORT
74+
[16] { LED_16_PORT, LED_16_PIN },
75+
#endif
76+
#ifdef LED_17_PORT
77+
[17] { LED_17_PORT, LED_17_PIN },
78+
#endif
79+
#ifdef LED_18_PORT
80+
[18] { LED_18_PORT, LED_18_PIN },
81+
#endif
82+
#ifdef LED_19_PORT
83+
[19] { LED_19_PORT, LED_19_PIN },
84+
#endif
85+
#ifdef LED_20_PORT
86+
[20] { LED_20_PORT, LED_20_PIN },
87+
#endif
88+
#ifdef LED_21_PORT
89+
[21] { LED_21_PORT, LED_21_PIN },
90+
#endif
91+
#ifdef LED_22_PORT
92+
[22] { LED_22_PORT, LED_22_PIN },
93+
#endif
94+
#ifdef LED_23_PORT
95+
[23] { LED_23_PORT, LED_23_PIN },
96+
#endif
97+
#ifdef LED_24_PORT
98+
[24] { LED_24_PORT, LED_24_PIN },
99+
#endif
100+
#ifdef LED_25_PORT
101+
[25] { LED_25_PORT, LED_25_PIN },
102+
#endif
103+
#ifdef LED_26_PORT
104+
[26] { LED_26_PORT, LED_26_PIN },
105+
#endif
106+
#ifdef LED_27_PORT
107+
[27] { LED_27_PORT, LED_27_PIN },
108+
#endif
109+
#ifdef LED_28_PORT
110+
[28] { LED_28_PORT, LED_28_PIN },
111+
#endif
112+
#ifdef LED_29_PORT
113+
[29] { LED_29_PORT, LED_29_PIN },
114+
#endif
115+
#ifdef LED_30_PORT
116+
[30] { LED_30_PORT, LED_30_PIN },
117+
#endif
118+
#ifdef LED_31_PORT
119+
[31] { LED_31_PORT, LED_31_PIN },
120+
#endif
74121
};
75122
#define N_LED (sizeof (ao_leds)/sizeof(ao_leds[0]))
76-
#endif
77-
static AO_LED_TYPE ao_led_enable;
78123

79124
void
80125
ao_led_on(AO_LED_TYPE colors)
81126
{
82-
#ifdef LED_PER_LED
83127
AO_LED_TYPE i;
84128
for (i = 0; i < N_LED; i++)
85129
if (colors & (1 << i))
86130
ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, 1);
87-
#else
88-
#ifdef LED_PORT
89-
LED_PORT->bsrr = (colors & ao_led_enable);
90-
#else
91-
#ifdef LED_PORT_0
92-
LED_PORT_0->bsrr = ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
93-
#endif
94-
#ifdef LED_PORT_1
95-
LED_PORT_1->bsrr = ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
96-
#endif
97-
#endif
98-
#endif
99131
}
100132

101133
void
102134
ao_led_off(AO_LED_TYPE colors)
103135
{
104-
#ifdef LED_PER_LED
105136
AO_LED_TYPE i;
106137
for (i = 0; i < N_LED; i++)
107138
if (colors & (1 << i))
108139
ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, 0);
109-
#else
110-
#ifdef LED_PORT
111-
LED_PORT->bsrr = (uint32_t) (colors & ao_led_enable) << 16;
112-
#else
113-
#ifdef LED_PORT_0
114-
LED_PORT_0->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_0_MASK) << (LED_PORT_0_SHIFT + 16);
115-
#endif
116-
#ifdef LED_PORT_1
117-
LED_PORT_1->bsrr = ((uint32_t) (colors & ao_led_enable) & LED_PORT_1_MASK) << (LED_PORT_1_SHIFT + 16);
118-
#endif
119-
#endif
120-
#endif
121140
}
122141

123142
void
124143
ao_led_set(AO_LED_TYPE colors)
125144
{
126-
AO_LED_TYPE on = colors & ao_led_enable;
127-
AO_LED_TYPE off = ~colors & ao_led_enable;
128-
129-
ao_led_off(off);
130-
ao_led_on(on);
145+
AO_LED_TYPE i;
146+
for (i = 0; i < N_LED; i++)
147+
ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, (colors >> i) & 1);
131148
}
132149

133150
void
134151
ao_led_toggle(AO_LED_TYPE colors)
135152
{
136-
#ifdef LED_PER_LED
137153
AO_LED_TYPE i;
138154
for (i = 0; i < N_LED; i++)
139155
if (colors & (1 << i))
140156
ao_gpio_set(ao_leds[i].port, ao_leds[i].pin, ~ao_gpio_get(ao_leds[i].port, ao_leds[i].pin));
141-
#else
142-
#ifdef LED_PORT
143-
LED_PORT->odr ^= (colors & ao_led_enable);
144-
#else
145-
#ifdef LED_PORT_0
146-
LED_PORT_0->odr ^= ((colors & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
147-
#endif
148-
#ifdef LED_PORT_1
149-
LED_PORT_1->odr ^= ((colors & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
150-
#endif
151-
#endif
152-
#endif
153157
}
154158

155159
void
156-
ao_led_for(AO_LED_TYPE colors, AO_LED_TYPE ticks)
160+
ao_led_for(AO_LED_TYPE colors, AO_TICK_TYPE ticks)
157161
{
158162
ao_led_on(colors);
159163
ao_delay(ticks);
160164
ao_led_off(colors);
161165
}
162166

163-
#define init_led_pin(port, bit) do { \
164-
stm_moder_set(port, bit, STM_MODER_OUTPUT); \
165-
stm_otyper_set(port, bit, STM_OTYPER_PUSH_PULL); \
166-
} while (0)
167-
168167
void
169-
ao_led_init(AO_LED_TYPE enable)
168+
ao_led_init(void)
170169
{
171170
AO_LED_TYPE bit;
172171

173-
ao_led_enable = enable;
174-
#if LED_PER_LED
175172
for (bit = 0; bit < N_LED; bit++)
176173
ao_enable_output(ao_leds[bit].port, ao_leds[bit].pin, 0);
177-
#else
178-
#ifdef LED_PORT
179-
stm_rcc.ahbenr |= (1 << LED_PORT_ENABLE);
180-
LED_PORT->odr &= ~enable;
181-
#else
182-
#ifdef LED_PORT_0
183-
stm_rcc.ahbenr |= (1 << LED_PORT_0_ENABLE);
184-
LED_PORT_0->odr &= ~((enable & ao_led_enable) & LED_PORT_0_MASK) << LED_PORT_0_SHIFT;
185-
#endif
186-
#ifdef LED_PORT_1
187-
stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE);
188-
LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
189-
#endif
190-
#ifdef LED_PORT_2
191-
stm_rcc.ahbenr |= (1 << LED_PORT_1_ENABLE);
192-
LED_PORT_1->odr &= ~((enable & ao_led_enable) & LED_PORT_1_MASK) << LED_PORT_1_SHIFT;
193-
#endif
194-
#endif
195-
for (bit = 0; bit < 16; bit++) {
196-
if (enable & (1 << bit)) {
197-
#ifdef LED_PORT
198-
init_led_pin(LED_PORT, bit);
199-
#else
200-
#ifdef LED_PORT_0
201-
if (LED_PORT_0_MASK & (1 << bit))
202-
init_led_pin(LED_PORT_0, bit + LED_PORT_0_SHIFT);
203-
#endif
204-
#ifdef LED_PORT_1
205-
if (LED_PORT_1_MASK & (1 << bit))
206-
init_led_pin(LED_PORT_1, bit + LED_PORT_1_SHIFT);
207-
#endif
208-
#ifdef LED_PORT_2
209-
if (LED_PORT_2_MASK & (1 << bit))
210-
init_led_pin(LED_PORT_2, bit + LED_PORT_2_SHIFT);
211-
#endif
212-
#endif
213-
}
214-
}
215-
#endif
216174
}

src/easymega-v1.0/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ ALTOS_SRC = \
5353
ao_cmd.c \
5454
ao_config.c \
5555
ao_task.c \
56-
ao_led.c \
56+
ao_led_stm.c \
5757
ao_stdio.c \
5858
ao_panic.c \
5959
ao_timer.c \

src/easymega-v1.0/ao_easymega.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ main(void)
4343
#endif
4444

4545
ao_task_init();
46-
ao_led_init(LEDS_AVAILABLE);
46+
ao_led_init();
4747
ao_led_on(LEDS_AVAILABLE);
4848
ao_timer_init();
4949

src/fox1ihu/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ALTOS_SRC = \
3737
ao_romconfig.c \
3838
ao_cmd.c \
3939
ao_task.c \
40-
ao_led.c \
40+
ao_led_stm.c \
4141
ao_stdio.c \
4242
ao_panic.c \
4343
ao_timer.c \

src/fox1ihu/ao_fox1ihu.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ main(void)
3131
#endif
3232

3333
ao_task_init();
34-
ao_led_init(LEDS_AVAILABLE);
34+
ao_led_init();
3535
ao_led_on(AO_LED_RED|AO_LED_GREEN|AO_LED_RED_2|AO_LED_GREEN_2);
3636
ao_timer_init();
3737

src/kernel/ao.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ ao_cmd_filter(void);
230230
#include <ao_beep.h>
231231
#endif
232232

233-
#if LEDS_AVAILABLE
233+
#if LEDS_AVAILABLE || HAS_LED
234234
#include <ao_led.h>
235235
#endif
236236

0 commit comments

Comments
 (0)