summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/led-imx233.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2017-01-11 16:58:30 +0100
committerGerrit Rockbox <gerrit@rockbox.org>2017-01-16 20:08:13 +0100
commitb23b7088cbba364bd37a7ec5e6572f1ecf234e7a (patch)
tree38fd3014f7f667e0893245d3069e4ee41a9f18a4 /firmware/target/arm/imx233/led-imx233.c
parent759a78e5dff134f2632875f61aae60815eea6f5b (diff)
downloadrockbox-b23b7088cbba364bd37a7ec5e6572f1ecf234e7a.tar.gz
rockbox-b23b7088cbba364bd37a7ec5e6572f1ecf234e7a.zip
imx233: add small framework for LED
It handles GPIO and PWM based LEDs, possibly with several channels (red-green LED for example). The debug allows one to play with the setting. Currently the code supports the ZEN, ZEN X-Fi, and ZEN Mozaic. Change-Id: I8c3b66e6ba21778acdb123daabb724280a7d1a4f
Diffstat (limited to 'firmware/target/arm/imx233/led-imx233.c')
-rw-r--r--firmware/target/arm/imx233/led-imx233.c100
1 files changed, 100 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/led-imx233.c b/firmware/target/arm/imx233/led-imx233.c
new file mode 100644
index 0000000000..88c2b7e054
--- /dev/null
+++ b/firmware/target/arm/imx233/led-imx233.c
@@ -0,0 +1,100 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2017 by Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include "led-imx233.h"
22#include "pwm-imx233.h"
23#include "pinctrl-imx233.h"
24
25/** Target specific tables */
26#if defined(CREATIVE_ZENXFI) || defined(CREATIVE_ZENMOZAIC)
27/* ZEN X-Fi/Mozaic have a Red-Green LED */
28static struct imx233_led_chan_t zenxfi_led_chans[] =
29{
30 { true, LED_RED, 2, 2, 2 }, /* red channel on B20P2 (pwm 2) */
31 { true, LED_GREEN, 2, 4, 4 }, /* green channel on B20P4 (pwm 4) */
32};
33static struct imx233_led_t leds[] = {{2, zenxfi_led_chans}};
34#elif defined(CREATIVE_ZEN)
35/* ZEN has a blue LED */
36static struct imx233_led_chan_t zen_led_chans[] =
37{
38 { true, LED_BLUE, 2, 3, 3 }, /* blue channel on B20P3 (pwm 3) */
39};
40static struct imx233_led_t leds[] = {{1, zen_led_chans}};
41#else
42#define NO_LEDS
43#endif
44
45#ifndef NO_LEDS
46int imx233_led_get_count(void)
47{
48 return sizeof(leds) / sizeof(leds[0]);
49}
50
51struct imx233_led_t *imx233_led_get_info(void)
52{
53 return leds;
54}
55#else
56int imx233_led_get_count(void)
57{
58 return 0;
59}
60
61struct imx233_led_t * imx233_led_get_info(void)
62{
63 return NULL;
64}
65#endif
66
67void imx233_led_init(void)
68{
69 struct imx233_led_t *leds = imx233_led_get_info();
70 /* turn off all channels */
71 for(int led = 0; led < imx233_led_get_count(); led++)
72 for(int chan = 0; chan < leds[led].nr_chan; chan++)
73 imx233_led_set(led, chan, false);
74}
75
76void imx233_led_set(int led, int chan, bool on)
77{
78 struct imx233_led_chan_t *c = &imx233_led_get_info()[led].chan[chan];
79 /* if LED has a PWM, handle it using the PWM */
80 if(c->has_pwm)
81 {
82 /* toogle at 1KHz */
83 return imx233_led_set_pwm(led, chan, 1000, on ? 100 : 0);
84 }
85 /* make sure pin is configured as a GPIO */
86 imx233_pinctrl_setup_vpin(
87 VPIN_PACK(c->gpio_bank, c->gpio_pin, GPIO), "led",
88 PINCTRL_DRIVE_4mA, false);
89 imx233_pinctrl_enable_gpio(c->gpio_bank, c->gpio_pin, true);
90 imx233_pinctrl_set_gpio(c->gpio_bank, c->gpio_pin, on);
91}
92
93void imx233_led_set_pwm(int led, int chan, int freq, int duty)
94{
95 struct imx233_led_chan_t *c = &imx233_led_get_info()[led].chan[chan];
96 if(!c->has_pwm)
97 panicf("led %d chan %d cannot do pwm", led, chan);
98 imx233_pwm_setup_simple(c->pwm_chan, freq, duty);
99 imx233_pwm_enable(c->pwm_chan, true);
100}