Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
F
fwatch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
8
Issues
8
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
fwatch
Commits
515e5834
Commit
515e5834
authored
Aug 31, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backlight: Driver, basic functions.
parent
a3d6a733
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
184 additions
and
9 deletions
+184
-9
backlight.c
sw/common/drivers/backlight.c
+123
-0
backlight.h
sw/common/drivers/backlight.h
+49
-0
Makefile
sw/freertos/Makefile
+1
-0
example_app.c
sw/freertos/src/apps/example_app.c
+9
-6
main.c
sw/freertos/src/main.c
+2
-3
No files found.
sw/common/drivers/backlight.c
0 → 100644
View file @
515e5834
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
* @author Matthieu Cattin <matthieu.cattin@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Backlight control.
*/
#include "backlight.h"
#include <em_cmu.h>
#include <em_gpio.h>
#include <em_timer.h>
static
int
backlight_level
;
void
backlight_init
(
void
)
{
CMU_ClockEnable
(
cmuClock_TIMER1
,
true
);
// Configure backlight LED pins as outputs
GPIO_PinModeSet
(
gpioPortE
,
11
,
gpioModePushPull
,
0
);
GPIO_PinModeSet
(
gpioPortE
,
12
,
gpioModePushPull
,
0
);
// Select CC channel parameters
TIMER_InitCC_TypeDef
timerCCInit
=
{
.
eventCtrl
=
timerEventEveryEdge
,
.
edge
=
timerEdgeBoth
,
.
prsSel
=
timerPRSSELCh1
,
.
cufoa
=
timerOutputActionNone
,
.
cofoa
=
timerOutputActionNone
,
.
cmoa
=
timerOutputActionToggle
,
.
mode
=
timerCCModePWM
,
.
filter
=
false
,
.
prsInput
=
false
,
.
coist
=
false
,
.
outInvert
=
false
,
};
// Configure CC channel 1 & 2
TIMER_InitCC
(
TIMER1
,
1
,
&
timerCCInit
);
TIMER_InitCC
(
TIMER1
,
2
,
&
timerCCInit
);
// Route CC1 to location 1 (PE11) and enable pin
TIMER1
->
ROUTE
|=
(
TIMER_ROUTE_CC1PEN
|
TIMER_ROUTE_LOCATION_LOC1
);
// Route CC2 to location 1 (PE12) and enable pin
TIMER1
->
ROUTE
|=
(
TIMER_ROUTE_CC2PEN
|
TIMER_ROUTE_LOCATION_LOC1
);
// Select timer parameters
TIMER_Init_TypeDef
timerInit
=
{
.
enable
=
true
,
.
debugRun
=
true
,
.
prescale
=
timerPrescale64
,
.
clkSel
=
timerClkSelHFPerClk
,
.
fallAction
=
timerInputActionNone
,
.
riseAction
=
timerInputActionNone
,
.
mode
=
timerModeUp
,
.
dmaClrAct
=
false
,
.
quadModeX4
=
false
,
.
oneShot
=
false
,
.
sync
=
false
,
};
// Set Top Value (determines PWM frequency)
// TODO the top value may need adjustments if HFPER changes
// TIMER_TopSet(TIMER1, CMU_ClockFreqGet(cmuClock_HFPER) / 100000));
TIMER_TopSet
(
TIMER1
,
100
);
backlight_set_level
(
0
);
// Configure timer
TIMER_Init
(
TIMER1
,
&
timerInit
);
}
void
backlight_set_level
(
int
level
)
{
const
int
BL_MAX_LEVEL
=
100
;
if
(
level
<=
0
)
{
TIMER_Enable
(
TIMER1
,
false
);
level
=
0
;
// in case level is negative
}
else
{
// Reenable the timer, if it was turned off previously
if
(
backlight_level
==
0
)
TIMER_Enable
(
TIMER1
,
true
);
if
(
level
>
BL_MAX_LEVEL
)
level
=
BL_MAX_LEVEL
;
TIMER_CompareBufSet
(
TIMER1
,
1
,
level
);
TIMER_CompareBufSet
(
TIMER1
,
2
,
level
);
}
backlight_level
=
level
;
}
unsigned
int
backlight_get_level
(
void
)
{
return
backlight_level
;
}
sw/common/drivers/backlight.h
0 → 100644
View file @
515e5834
/*
* Copyright (C) 2014 Julian Lewis
* @author Maciej Suminski <maciej.suminski@cern.ch>
* @author Matthieu Cattin <matthieu.cattin@cern.ch>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @brief Backlight control.
*/
#ifndef BACKLIGHT_H
#define BACKLIGHT_H
/**
* @brief Initialize backlight control.
*/
void
backlight_init
(
void
);
/**
* @brief Sets the backlight brightness.
* @param level is the brightness level to be set. Valid values are in the
* 0-100 range. 0 stands for completely turned off, 100 is full brightness.
*/
void
backlight_set_level
(
int
level
);
/**
* @brief Returns the current level of backlight.
*/
unsigned
int
backlight_get_level
(
void
);
#endif
/* BACKLIGHT_H */
sw/freertos/Makefile
View file @
515e5834
...
...
@@ -139,6 +139,7 @@ C_SRC += \
../common/emlib/src/em_usart.c
\
../common/emdrv/sleep/src/sleep.c
\
../common/drivers/lcd.c
\
../common/drivers/backlight.c
\
../common/drivers/buttons.c
\
../common/drivers/buzzer.c
\
../common/drivers/rtc.c
\
...
...
sw/freertos/src/apps/example_app.c
View file @
515e5834
...
...
@@ -26,6 +26,7 @@
#include "application.h"
#include "widgets/status_bar.h"
#include "drivers/backlight.h"
#include "drivers/buzzer.h"
#include "drivers/vibra.h"
...
...
@@ -47,16 +48,18 @@ static void widget_event(struct ui_widget *w, const struct event *evt)
switch
(
evt
->
type
)
{
case
BUTTON_PRESSED
:
switch
(
evt
->
data
.
button
)
{
case
BUT_TR
:
strcpy
(
message
,
"top right"
);
case
BUT_TR
:
// top right button
backlight_set_level
(
backlight_get_level
()
+
10
);
sprintf
(
message
,
"top right (bl: %d)"
,
backlight_get_level
());
break
;
case
BUT_BR
:
strcpy
(
message
,
"bottom right"
);
case
BUT_BR
:
// bottom right button
backlight_set_level
(
backlight_get_level
()
-
10
);
sprintf
(
message
,
"bot right (bl: %d)"
,
backlight_get_level
());
break
;
case
BUT_BL
:
strcpy
(
message
,
"bot
tom
left"
);
case
BUT_BL
:
// bottom left button
strcpy
(
message
,
"bot left"
);
break
;
case
BUT_TL
:
// this should not happen, it is handled
...
...
sw/freertos/src/main.c
View file @
515e5834
...
...
@@ -30,6 +30,7 @@
#include <sleep.h>
#include <apps/app_list.h>
#include <drivers/backlight.h>
#include <drivers/buttons.h>
#include <drivers/buzzer.h>
#include <drivers/lcd.h>
...
...
@@ -46,6 +47,7 @@ int main(void)
CMU_ClockEnable
(
cmuClock_HFPER
,
true
);
CMU_ClockEnable
(
cmuClock_GPIO
,
true
);
backlight_init
();
buttons_init
();
buzzer_init
();
vibra_init
();
...
...
@@ -53,9 +55,6 @@ int main(void)
lcd_init
();
ui_init
();
GPIO_PinModeSet
(
gpioPortE
,
11
,
gpioModePushPull
,
0
);
GPIO_PinModeSet
(
gpioPortE
,
12
,
gpioModePushPull
,
0
);
// Initialize SLEEP driver, no callbacks are used
SLEEP_Init
(
NULL
,
NULL
);
#if (configSLEEP_MODE < 3)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment