Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
26f6ef50
Commit
26f6ef50
authored
8 years ago
by
Peter Kietzmann
Committed by
GitHub
8 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #6208 from haukepetersen/opt_lpc2387_pwm
cpu/lpc2387: cleanup PWM driver
parents
b24be6a6
718c8a5f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
boards/avsextrem/include/periph_conf.h
+0
-20
0 additions, 20 deletions
boards/avsextrem/include/periph_conf.h
boards/msba2/include/periph_conf.h
+19
-14
19 additions, 14 deletions
boards/msba2/include/periph_conf.h
cpu/lpc2387/periph/pwm.c
+69
-104
69 additions, 104 deletions
cpu/lpc2387/periph/pwm.c
with
88 additions
and
138 deletions
boards/avsextrem/include/periph_conf.h
+
0
−
20
View file @
26f6ef50
...
...
@@ -41,26 +41,6 @@ extern "C" {
#define TIMER_NUMOF (1U)
/** @} */
/**
* @brief PWM device and pinout configuration
*/
#define PWM_NUMOF (0)
/* disable PWM for now as no pins are specified */
#define PWM_0_EN (0)
/* PWM_0 device configuration */
#define PWM_0_CH0 (3)
/* TODO: adjust pins for avsextrem */
#define PWM_0_CH0_MR PWM1MR3
#define PWM_0_CH1 (4)
#define PWM_0_CH1_MR PWM1MR4
#define PWM_0_CH2 (5)
#define PWM_0_CH2_MR PWM1MR5
/* PWM_0 pin configuration */
#define PWM_0_PORT PINSEL4
#define PWM_0_CH0_PIN (2)
#define PWM_0_CH1_PIN (3)
#define PWM_0_CH2_PIN (4)
#define PWM_0_FUNC (1)
/**
* @brief Real Time Clock configuration
*/
...
...
This diff is collapsed.
Click to expand it.
boards/msba2/include/periph_conf.h
+
19
−
14
View file @
26f6ef50
...
...
@@ -42,25 +42,30 @@ extern "C" {
/** @} */
/**
* @brief PWM device and pinout configuration
* @brief PWM device and pinout configuration
*
* Currently, we only support a single device and 3 channels, the implementation
* is fixed on PWM1.
*
* @{
*/
#define PWM_NUMOF (1U)
#define PWM_0_EN (1)
/* PWM_0 device configuration */
#define PWM_
0_
CHANNELS (3)
#define PWM_
0_
CH0 (3)
#define PWM_
0_
CH0_MR PWM1MR3
#define PWM_
0_
CH1 (4)
#define PWM_
0_
CH1_MR PWM1MR4
#define PWM_
0_
CH2 (5)
#define PWM_
0_
CH2_MR PWM1MR5
#define PWM_CHANNELS (3)
#define PWM_CH0 (3)
#define PWM_CH0_MR PWM1MR3
#define PWM_CH1 (4)
#define PWM_CH1_MR PWM1MR4
#define PWM_CH2 (5)
#define PWM_CH2_MR PWM1MR5
/* PWM_0 pin configuration */
#define PWM_0_PORT PINSEL4
#define PWM_0_CH0_PIN (2)
#define PWM_0_CH1_PIN (3)
#define PWM_0_CH2_PIN (4)
#define PWM_0_FUNC (1)
#define PWM_PORT PINSEL4
#define PWM_CH0_PIN (2)
#define PWM_CH1_PIN (3)
#define PWM_CH2_PIN (4)
#define PWM_FUNC (1)
/** @} */
/**
* @brief Real Time Clock configuration
...
...
This diff is collapsed.
Click to expand it.
cpu/lpc2387/periph/pwm.c
+
69
−
104
View file @
26f6ef50
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014
-2016
Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
General
* Public License v2.1. See the file LICENSE in the top level
directory for more
* details.
* This file is subject to the terms and conditions of the GNU Lesser
*
General
Public License v2.1. See the file LICENSE in the top level
*
directory for more
details.
*/
/**
* @ingroup lpc2387
* @ingroup
cpu_
lpc2387
* @{
*
* @file
* @brief CPU specific low-level PWM driver implementation for the LPC2387
*
* The current implementation is somewhat limited: it supports only a single
* hardware PWM device (fixed to PWM1) and it is fixed on supporting 3 channels.
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include
"cpu.h"
#include
"assert.h"
#include
"bitarithm.h"
#include
"lpc2387.h"
#include
"periph_conf.h"
#include
"periph/pwm.h"
/* guard file in case no PWM device is defined */
#if (PWM_0_EN || PWM_1_EN)
/* pull the PWM header inside the guards for now. Guards will be removed on
* adapting this driver implementation... */
#include
"periph/pwm.h"
#ifdef PWM_NUMOF
/**
* @note The PWM is always initialized with left-aligned mode.
...
...
@@ -36,135 +36,100 @@
*/
uint32_t
pwm_init
(
pwm_t
dev
,
pwm_mode_t
mode
,
uint32_t
freq
,
uint16_t
res
)
{
(
void
)
mode
;
/* unused */
if
((
dev
!=
PWM_DEV
(
0
))
&&
(
mode
!=
PWM_LEFT
))
{
return
0
;
}
switch
(
dev
)
{
#if PWM_0_EN
case
PWM_0
:
/* select function PWM[3] for pins */
PWM_0_PORT
&=
~
((
3
<<
PWM_0_CH0_PIN
*
2
)
|
(
3
<<
PWM_0_CH1_PIN
*
2
)
|
(
3
<<
PWM_0_CH2_PIN
*
2
));
PWM_0_PORT
|=
(
PWM_0_FUNC
<<
PWM_0_CH0_PIN
*
2
)
|
(
PWM_0_FUNC
<<
PWM_0_CH1_PIN
*
2
)
|
(
PWM_0_FUNC
<<
PWM_0_CH2_PIN
*
2
);
/* select function PWM[3] for pins */
PWM_PORT
&=
~
((
3
<<
PWM_CH0_PIN
*
2
)
|
(
3
<<
PWM_CH1_PIN
*
2
)
|
(
3
<<
PWM_CH2_PIN
*
2
));
PWM_PORT
|=
(
PWM_FUNC
<<
PWM_CH0_PIN
*
2
)
|
(
PWM_FUNC
<<
PWM_CH1_PIN
*
2
)
|
(
PWM_FUNC
<<
PWM_CH2_PIN
*
2
);
/* power on PWM1 */
pwm_poweron
(
dev
);
/* power on PWM1 */
pwm_poweron
(
dev
);
/* select PWM1 clock */
PCLKSEL0
&=
~
(
BIT13
);
PCLKSEL0
|=
(
BIT12
);
/* select PWM1 clock */
PCLKSEL0
&=
~
(
BIT13
);
PCLKSEL0
|=
(
BIT12
);
/* reset PWM1s counter */
PWM1TCR
=
BIT1
;
/* reset PWM1s counter */
PWM1TCR
=
BIT1
;
/* set prescaler */
PWM1PR
=
(
CLOCK_CORECLOCK
/
(
freq
*
res
))
-
1
;
/* set prescaler */
PWM1PR
=
(
CLOCK_CORECLOCK
/
(
freq
*
res
))
-
1
;
/* set match register */
PWM1MR0
=
res
;
PWM_
0_
CH0_MR
=
0
;
PWM_
0_
CH1_MR
=
0
;
PWM_
0_
CH2_MR
=
0
;
/* set match register */
PWM1MR0
=
res
;
PWM_CH0_MR
=
0
;
PWM_CH1_MR
=
0
;
PWM_CH2_MR
=
0
;
/* reset timer counter on MR0 match */
PWM1MCR
=
BIT1
;
/* reset timer counter on MR0 match */
PWM1MCR
=
BIT1
;
/* enable PWM1 channel 3, 4 and 5 */
PWM1PCR
=
(
1
<<
(
8
+
PWM_
0_
CH0
))
|
(
1
<<
(
8
+
PWM_
0_
CH1
))
|
(
1
<<
(
8
+
PWM_
0_
CH2
));
/* enable PWM1 channel 3, 4 and 5 */
PWM1PCR
=
(
1
<<
(
8
+
PWM_CH0
))
|
(
1
<<
(
8
+
PWM_CH1
))
|
(
1
<<
(
8
+
PWM_CH2
));
/* enable PWM1 timer in PWM mode */
PWM1TCR
=
BIT0
+
BIT3
;
/* enable PWM1 timer in PWM mode */
PWM1TCR
=
BIT0
+
BIT3
;
/* update match registers */
PWM1LER
=
BIT0
|
(
1
<<
PWM_0_CH0
)
|
(
1
<<
PWM_0_CH1
)
|
(
1
<<
PWM_0_CH2
);
break
;
#endif
default:
return
0
;
}
/* update match registers */
PWM1LER
=
BIT0
|
(
1
<<
PWM_CH0
)
|
(
1
<<
PWM_CH1
)
|
(
1
<<
PWM_CH2
);
return
freq
;
}
uint8_t
pwm_channels
(
pwm_t
dev
)
{
if
(
dev
==
PWM_0
)
{
return
PWM_0_CHANNELS
;
}
return
0
;
assert
(
dev
==
PWM_DEV
(
0
));
return
PWM_CHANNELS
;
}
void
pwm_set
(
pwm_t
dev
,
uint8_t
channel
,
uint16_t
value
)
{
switch
(
dev
)
{
#if PWM_0_EN
case
PWM_0
:
switch
(
channel
)
{
case
0
:
PWM_0_CH0_MR
=
value
;
PWM1LER
|=
(
1
<<
PWM_0_CH0
);
break
;
case
1
:
PWM_0_CH1_MR
=
value
;
PWM1LER
|=
(
1
<<
PWM_0_CH1
);
break
;
case
2
:
PWM_0_CH2_MR
=
value
;
PWM1LER
|=
(
1
<<
PWM_0_CH2
);
break
;
default:
return
;
break
;
}
assert
((
dev
==
PWM_DEV
(
0
))
&&
(
channel
<
3
));
switch
(
channel
)
{
case
0
:
PWM_CH0_MR
=
value
;
PWM1LER
|=
(
1
<<
PWM_CH0
);
break
;
case
1
:
PWM_CH1_MR
=
value
;
PWM1LER
|=
(
1
<<
PWM_CH1
);
break
;
case
2
:
PWM_CH2_MR
=
value
;
PWM1LER
|=
(
1
<<
PWM_CH2
);
break
;
#endif
}
}
void
pwm_start
(
pwm_t
dev
)
{
switch
(
dev
)
{
#if PWM_0_EN
case
PWM_0
:
PWM1TCR
|=
BIT0
;
break
;
#endif
}
assert
(
dev
==
PWM_DEV
(
0
));
PWM1TCR
|=
BIT0
;
}
void
pwm_stop
(
pwm_t
dev
)
{
switch
(
dev
)
{
#if PWM_0_EN
case
PWM_0
:
PWM1TCR
&=
~
(
BIT0
);
break
;
#endif
}
assert
(
dev
==
PWM_DEV
(
0
));
PWM1TCR
&=
~
(
BIT0
);
}
void
pwm_poweron
(
pwm_t
dev
)
{
switch
(
dev
)
{
#if PWM_0_EN
case
PWM_0
:
PCONP
|=
PCPWM1
;
break
;
#endif
}
assert
(
dev
==
PWM_DEV
(
0
));
PCONP
|=
PCPWM1
;
}
void
pwm_poweroff
(
pwm_t
dev
)
{
switch
(
dev
)
{
#if PWM_0_EN
case
PWM_0
:
PCONP
&=
~
(
PCPWM1
);
break
;
#endif
}
assert
(
dev
==
PWM_DEV
(
0
));
PCONP
&=
~
(
PCPWM1
);
}
#endif
/*
(
PWM_
0_EN || PWM_1_EN)
*/
#endif
/* PWM_
NUMOF
*/
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment