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
cb02bd4e
Commit
cb02bd4e
authored
Aug 30, 2014
by
Projects
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
buzzer: Driver, basic routines. Updated the example application.
parent
31dd2d10
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
175 additions
and
2 deletions
+175
-2
buzzer.c
sw/common/drivers/buzzer.c
+111
-0
buzzer.h
sw/common/drivers/buzzer.h
+53
-0
Makefile
sw/freertos/Makefile
+1
-0
example_app.c
sw/freertos/src/apps/example_app.c
+8
-2
main.c
sw/freertos/src/main.c
+2
-0
No files found.
sw/common/drivers/buzzer.c
0 → 100644
View file @
cb02bd4e
/*
* 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 Buzzer control.
*/
#include "buzzer.h"
#include <em_cmu.h>
#include <em_gpio.h>
#include <em_timer.h>
#define BUZZER_PWM_FREQ 10000
void
buzzer_init
(
void
)
{
// Configure buzzer pin as push/pull output
GPIO_PinModeSet
(
gpioPortA
,
9
,
gpioModePushPull
,
0
);
// Enable clock for TIMER2 module
CMU_ClockEnable
(
cmuClock_TIMER2
,
true
);
// Select CC channel parameters
TIMER_InitCC_TypeDef
timerCCInit
=
{
.
cufoa
=
timerOutputActionNone
,
.
cofoa
=
timerOutputActionToggle
,
.
cmoa
=
timerOutputActionNone
,
.
mode
=
timerCCModeCompare
,
.
filter
=
false
,
.
prsInput
=
false
,
.
coist
=
false
,
.
outInvert
=
false
,
};
// Configure CC channel 1
TIMER_InitCC
(
TIMER2
,
1
,
&
timerCCInit
);
// Route CC1 to location 0 (PA9) and enable pin
TIMER2
->
ROUTE
|=
(
TIMER_ROUTE_CC1PEN
|
TIMER_ROUTE_LOCATION_LOC0
);
// Select timer parameter
TIMER_Init_TypeDef
timerInit
=
{
.
enable
=
false
,
.
debugRun
=
true
,
.
prescale
=
timerPrescale64
,
.
clkSel
=
timerClkSelHFPerClk
,
.
fallAction
=
timerInputActionNone
,
.
riseAction
=
timerInputActionNone
,
.
mode
=
timerModeUp
,
.
dmaClrAct
=
false
,
.
quadModeX4
=
false
,
.
oneShot
=
false
,
.
sync
=
false
,
};
// Configure timer
TIMER_Init
(
TIMER2
,
&
timerInit
);
buzzer_set_freq
(
5500
);
}
void
buzzer_enable
(
void
)
{
TIMER_Enable
(
TIMER2
,
true
);
}
void
buzzer_disable
(
void
)
{
TIMER_Enable
(
TIMER2
,
false
);
}
void
buzzer_set_freq
(
int
frequency
)
{
const
int
MIN_AUDIBLE
=
6
;
const
int
MAX_AUDIBLE
=
5000
;
// For timer, lower TOP values mean higher frequency
frequency
=
MAX_AUDIBLE
+
MIN_AUDIBLE
-
frequency
;
if
(
frequency
<
MIN_AUDIBLE
)
frequency
=
MIN_AUDIBLE
;
else
if
(
frequency
>
MAX_AUDIBLE
)
frequency
=
MAX_AUDIBLE
;
// TODO add a formula to convert frequency to TIMER top value
TIMER_TopSet
(
TIMER2
,
frequency
);
}
sw/common/drivers/buzzer.h
0 → 100644
View file @
cb02bd4e
/*
* 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 Buzzer control.
*/
#ifndef BUZZER_H
#define BUZZER_H
/**
* @brief Initialize buzzer.
*/
void
buzzer_init
(
void
);
/**
* @brief Turns on the buzzer.
*/
void
buzzer_enable
(
void
);
/**
* @brief Turns off the buzzer.
*/
void
buzzer_disable
(
void
);
/**
* @brief Sets the frequency of buzzer sound.
* @param frequency is the frequency to be set.
*/
void
buzzer_set_freq
(
int
frequency
);
#endif
/* BUZZER_H */
sw/freertos/Makefile
View file @
cb02bd4e
...
...
@@ -140,6 +140,7 @@ C_SRC += \
../common/emdrv/sleep/src/sleep.c
\
../common/drivers/lcd.c
\
../common/drivers/buttons.c
\
../common/drivers/buzzer.c
\
../common/drivers/rtc.c
\
../common/gfx/font_helv11.c
\
../common/gfx/font_helv17.c
\
...
...
sw/freertos/src/apps/example_app.c
View file @
cb02bd4e
...
...
@@ -26,6 +26,7 @@
#include "application.h"
#include "widgets/status_bar.h"
#include "drivers/buzzer.h"
#include <string.h> // for strcpy
...
...
@@ -60,10 +61,15 @@ static void widget_event(struct ui_widget *w, const struct event *evt)
case
BUT_TL
:
// this should not happen, it is handled
break
;
// in the main loop
}
break
;
case
RTC_TICK
:
// commented out, because it interferes with other messages
//strcpy(message, "tick-tock");
// tick-tock with a buzzer
buzzer_enable
();
vTaskDelay
(
100
);
buzzer_disable
();
// ok, we do not need redrawing
w
->
flags
&=
~
WF_DIRTY
;
break
;
default:
// suppress warnings
...
...
sw/freertos/src/main.c
View file @
cb02bd4e
...
...
@@ -31,6 +31,7 @@
#include <apps/app_list.h>
#include <drivers/buttons.h>
#include <drivers/buzzer.h>
#include <drivers/lcd.h>
#include <drivers/rtc.h>
#include <gfx/ui.h>
...
...
@@ -45,6 +46,7 @@ int main(void)
CMU_ClockEnable
(
cmuClock_GPIO
,
true
);
buttons_init
();
buzzer_init
();
rtc_init
();
lcd_init
();
ui_init
();
...
...
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