Skip to content

Commit

Permalink
cpu/kinetis_common: Use PORT driver for PWM pin handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Joakim Nohlgård committed Feb 14, 2016
1 parent 0782e36 commit 1b55b5f
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 95 deletions.
30 changes: 12 additions & 18 deletions boards/frdm-k64f/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,28 +160,22 @@ extern "C"
#define PWM_0_CLK CLOCK_CORECLOCK
#define PWM_0_CLKEN() (SIM->SCGC6 |= (SIM_SCGC6_FTM0_MASK))
#define PWM_0_CLKDIS() (SIM->SCGC6 &= ~(SIM_SCGC6_FTM0_MASK))
/* PWM 0 pin configuration */
#define PWM_0_PORT_CLKEN() (SIM->SCGC5 |= (SIM_SCGC5_PORTA_MASK | SIM_SCGC5_PORTC_MASK))
/* Arduino Connector D3 */
#define PWM_0_PORT_CH0 PORTA
#define PWM_0_PIN_CH0 1
#define PWM_0_FTMCHAN_CH0 6
#define PWM_0_PIN_AF_CH0 3
#define PWM_0_CH0_GPIO GPIO_PIN(PORT_A, 1)
#define PWM_0_CH0_FTMCHAN 6
#define PWM_0_CH0_AF 3
/* Arduino Connector D5 */
#define PWM_0_PORT_CH1 PORTA
#define PWM_0_PIN_CH1 2
#define PWM_0_FTMCHAN_CH1 7
#define PWM_0_PIN_AF_CH1 3
#define PWM_0_CH1_GPIO GPIO_PIN(PORT_A, 2)
#define PWM_0_CH1_FTMCHAN 7
#define PWM_0_CH1_AF 3
/* Arduino Connector D6 */
#define PWM_0_PORT_CH2 PORTC
#define PWM_0_PIN_CH2 2
#define PWM_0_FTMCHAN_CH2 1
#define PWM_0_PIN_AF_CH2 4
#define PWM_0_CH2_GPIO GPIO_PIN(PORT_C, 2)
#define PWM_0_CH2_FTMCHAN 1
#define PWM_0_CH2_AF 4
/* Arduino Connector D7 */
#define PWM_0_PORT_CH3 PORTC
#define PWM_0_PIN_CH3 3
#define PWM_0_FTMCHAN_CH3 2
#define PWM_0_PIN_AF_CH3 4
#define PWM_0_CH3_GPIO GPIO_PIN(PORT_C, 3)
#define PWM_0_CH3_FTMCHAN 2
#define PWM_0_CH3_AF 4
/** @} */


Expand Down
33 changes: 12 additions & 21 deletions boards/mulle/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,17 +236,13 @@ extern "C"
#define PWM_0_CLKDIS() (BITBAND_REG32(SIM->SCGC6, SIM_SCGC6_FTM0_SHIFT) = 0)

/* PWM 0 pin configuration */
#define PWM_0_PORT_CLKEN() (BITBAND_REG32(SIM->SCGC5, SIM_SCGC5_PORTC_SHIFT) = 1)
#define PWM_0_CH0_GPIO GPIO_PIN(PORT_C, 1)
#define PWM_0_CH0_FTMCHAN 0
#define PWM_0_CH0_AF 4

#define PWM_0_PIN_CH0 1
#define PWM_0_FTMCHAN_CH0 0
#define PWM_0_PORT_CH0 PORTC
#define PWM_0_PIN_AF_CH0 4

#define PWM_0_PIN_CH1 2
#define PWM_0_FTMCHAN_CH1 1
#define PWM_0_PORT_CH1 PORTC
#define PWM_0_PIN_AF_CH1 4
#define PWM_0_CH1_GPIO GPIO_PIN(PORT_C, 2)
#define PWM_0_CH1_FTMCHAN 1
#define PWM_0_CH1_AF 4

/* PWM 1 device configuration */
#define PWM_1_DEV FTM1
Expand All @@ -256,21 +252,16 @@ extern "C"
#define PWM_1_CLKDIS() (BITBAND_REG32(SIM->SCGC6, SIM_SCGC6_FTM1_SHIFT) = 0)

/* PWM 1 pin configuration */
#define PWM_1_PORT_CLKEN() (BITBAND_REG32(SIM->SCGC5, SIM_SCGC5_PORTA_SHIFT) = 1)

#define PWM_1_PIN_CH0 12
#define PWM_1_FTMCHAN_CH0 0
#define PWM_1_PORT_CH0 PORTA
#define PWM_1_PIN_AF_CH0 3
#define PWM_1_CH0_GPIO GPIO_PIN(PORT_A, 12)
#define PWM_1_CH0_FTMCHAN 0
#define PWM_1_CH0_AF 3

#define PWM_1_PIN_CH1 13
#define PWM_1_FTMCHAN_CH1 1
#define PWM_1_PORT_CH1 PORTA
#define PWM_1_PIN_AF_CH1 3
#define PWM_1_CH1_GPIO GPIO_PIN(PORT_A, 13)
#define PWM_1_CH1_FTMCHAN 1
#define PWM_1_CH1_AF 3

/** @} */


/**
* @name SPI configuration
* @{
Expand Down
37 changes: 16 additions & 21 deletions boards/pba-d-01-kw2x/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,27 +180,22 @@ extern "C"
#define PWM_0_CLKEN() (SIM->SCGC6 |= (SIM_SCGC6_FTM0_MASK))
#define PWM_0_CLKDIS() (SIM->SCGC6 &= ~(SIM_SCGC6_FTM0_MASK))
/* PWM 0 pin configuration */
#define PWM_0_PORT_CLKEN() (SIM->SCGC5 |= (SIM_SCGC5_PORTD_MASK | SIM_SCGC5_PORTA_MASK))

#define PWM_0_PIN_CH0 4
#define PWM_0_FTMCHAN_CH0 1
#define PWM_0_PORT_CH0 PORTA
#define PWM_0_PIN_AF_CH0 3

#define PWM_0_PIN_CH1 4
#define PWM_0_FTMCHAN_CH1 4
#define PWM_0_PORT_CH1 PORTD
#define PWM_0_PIN_AF_CH1 4

#define PWM_0_PIN_CH2 6
#define PWM_0_FTMCHAN_CH2 6
#define PWM_0_PORT_CH2 PORTD
#define PWM_0_PIN_AF_CH2 4

#define PWM_0_PIN_CH3 1
#define PWM_0_FTMCHAN_CH3 1
#define PWM_0_PORT_CH3 PORTA
#define PWM_0_PIN_AF_CH3 3

#define PWM_0_CH0_GPIO GPIO_PIN(PORT_A, 4)
#define PWM_0_CH0_FTMCHAN 1
#define PWM_0_CH0_AF 3

#define PWM_0_CH1_GPIO GPIO_PIN(PORT_D, 4)
#define PWM_0_CH1_FTMCHAN 4
#define PWM_0_CH1_AF 4

#define PWM_0_CH2_GPIO GPIO_PIN(PORT_D, 6)
#define PWM_0_CH2_FTMCHAN 6
#define PWM_0_CH2_AF 4

#define PWM_0_CH3_GPIO GPIO_PIN(PORT_A, 1)
#define PWM_0_CH3_FTMCHAN 1
#define PWM_0_CH3_AF 3
/** @} */


Expand Down
69 changes: 34 additions & 35 deletions cpu/kinetis_common/periph/pwm.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
* Copyright (C) 2014 PHYTEC Messtechnik GmbH
* Copyright (C) 2015 Eistec AB
* Copyright (C) 2015-2016 Eistec AB
*
* 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
Expand Down Expand Up @@ -30,61 +30,62 @@
#include "cpu.h"
#include "periph/pwm.h"
#include "periph_conf.h"
#include "port.h"

/* FTM channel look up tables */
#if PWM_0_EN
static const uint8_t ftm0chan[] = {
#if PWM_0_CHANNELS > 0
PWM_0_FTMCHAN_CH0,
PWM_0_CH0_FTMCHAN,
#endif
#if PWM_0_CHANNELS > 1
PWM_0_FTMCHAN_CH1,
PWM_0_CH1_FTMCHAN,
#endif
#if PWM_0_CHANNELS > 2
PWM_0_FTMCHAN_CH2,
PWM_0_CH2_FTMCHAN,
#endif
#if PWM_0_CHANNELS > 3
PWM_0_FTMCHAN_CH3,
PWM_0_CH3_FTMCHAN,
#endif
#if PWM_0_CHANNELS > 4
PWM_0_FTMCHAN_CH4,
PWM_0_CH4_FTMCHAN,
#endif
#if PWM_0_CHANNELS > 5
PWM_0_FTMCHAN_CH5,
PWM_0_CH5_FTMCHAN,
#endif
#if PWM_0_CHANNELS > 6
PWM_0_FTMCHAN_CH6,
PWM_0_CH6_FTMCHAN,
#endif
#if PWM_0_CHANNELS > 7
PWM_0_FTMCHAN_CH7,
PWM_0_CH7_FTMCHAN,
#endif
};
#endif
#if PWM_1_EN
static const uint8_t ftm1chan[] = {
#if PWM_1_CHANNELS > 0
PWM_1_FTMCHAN_CH0,
PWM_1_CH0_FTMCHAN,
#endif
#if PWM_1_CHANNELS > 1
PWM_1_FTMCHAN_CH1,
PWM_1_CH1_FTMCHAN,
#endif
#if PWM_1_CHANNELS > 2
PWM_1_FTMCHAN_CH2,
PWM_1_CH2_FTMCHAN,
#endif
#if PWM_1_CHANNELS > 3
PWM_1_FTMCHAN_CH3,
PWM_1_CH3_FTMCHAN,
#endif
#if PWM_1_CHANNELS > 4
PWM_1_FTMCHAN_CH4,
PWM_1_CH4_FTMCHAN,
#endif
#if PWM_1_CHANNELS > 5
PWM_1_FTMCHAN_CH5,
PWM_1_CH5_FTMCHAN,
#endif
#if PWM_1_CHANNELS > 6
PWM_1_FTMCHAN_CH6,
PWM_1_CH6_FTMCHAN,
#endif
#if PWM_1_CHANNELS > 7
PWM_1_FTMCHAN_CH7,
PWM_1_CH7_FTMCHAN,
#endif
};
#endif
Expand Down Expand Up @@ -158,60 +159,58 @@ uint32_t pwm_init(pwm_t dev, pwm_mode_t mode, uint32_t freq, uint16_t res)
#if PWM_0_EN

case PWM_0:
PWM_0_PORT_CLKEN();
#if PWM_0_CHANNELS > 0
PWM_0_PORT_CH0->PCR[PWM_0_PIN_CH0] = PORT_PCR_MUX(PWM_0_PIN_AF_CH0);
port_init(PWM_0_CH0_GPIO, GPIO_NOPULL, PWM_0_CH0_AF);
#endif
#if PWM_0_CHANNELS > 1
PWM_0_PORT_CH1->PCR[PWM_0_PIN_CH1] = PORT_PCR_MUX(PWM_0_PIN_AF_CH1);
port_init(PWM_0_CH1_GPIO, GPIO_NOPULL, PWM_0_CH1_AF);
#endif
#if PWM_0_CHANNELS > 2
PWM_0_PORT_CH2->PCR[PWM_0_PIN_CH2] = PORT_PCR_MUX(PWM_0_PIN_AF_CH2);
port_init(PWM_0_CH2_GPIO, GPIO_NOPULL, PWM_0_CH2_AF);
#endif
#if PWM_0_CHANNELS > 3
PWM_0_PORT_CH3->PCR[PWM_0_PIN_CH3] = PORT_PCR_MUX(PWM_0_PIN_AF_CH3);
port_init(PWM_0_CH3_GPIO, GPIO_NOPULL, PWM_0_CH3_AF);
#endif
#if PWM_0_CHANNELS > 4
PWM_0_PORT_CH4->PCR[PWM_0_PIN_CH4] = PORT_PCR_MUX(PWM_0_PIN_AF_CH4);
port_init(PWM_0_CH4_GPIO, GPIO_NOPULL, PWM_0_CH4_AF);
#endif
#if PWM_0_CHANNELS > 5
PWM_0_PORT_CH5->PCR[PWM_0_PIN_CH5] = PORT_PCR_MUX(PWM_0_PIN_AF_CH5);
port_init(PWM_0_CH5_GPIO, GPIO_NOPULL, PWM_0_CH5_AF);
#endif
#if PWM_0_CHANNELS > 6
PWM_0_PORT_CH6->PCR[PWM_0_PIN_CH6] = PORT_PCR_MUX(PWM_0_PIN_AF_CH6);
port_init(PWM_0_CH6_GPIO, GPIO_NOPULL, PWM_0_CH6_AF);
#endif
#if PWM_0_CHANNELS > 7
PWM_0_PORT_CH7->PCR[PWM_0_PIN_CH7] = PORT_PCR_MUX(PWM_0_PIN_AF_CH7);
port_init(PWM_0_CH7_GPIO, GPIO_NOPULL, PWM_0_CH7_AF);
#endif
break;
#endif
#if PWM_1_EN

case PWM_1:
PWM_1_PORT_CLKEN();
#if PWM_1_CHANNELS > 0
PWM_1_PORT_CH0->PCR[PWM_1_PIN_CH0] = PORT_PCR_MUX(PWM_1_PIN_AF_CH0);
port_init(PWM_1_CH0_GPIO, GPIO_NOPULL, PWM_1_CH0_AF);
#endif
#if PWM_1_CHANNELS > 1
PWM_1_PORT_CH1->PCR[PWM_1_PIN_CH1] = PORT_PCR_MUX(PWM_1_PIN_AF_CH1);
port_init(PWM_1_CH1_GPIO, GPIO_NOPULL, PWM_1_CH1_AF);
#endif
#if PWM_1_CHANNELS > 2
PWM_1_PORT_CH2->PCR[PWM_1_PIN_CH2] = PORT_PCR_MUX(PWM_1_PIN_AF_CH2);
port_init(PWM_1_CH2_GPIO, GPIO_NOPULL, PWM_1_CH2_AF);
#endif
#if PWM_1_CHANNELS > 3
PWM_1_PORT_CH3->PCR[PWM_1_PIN_CH3] = PORT_PCR_MUX(PWM_1_PIN_AF_CH3);
port_init(PWM_1_CH3_GPIO, GPIO_NOPULL, PWM_1_CH3_AF);
#endif
#if PWM_1_CHANNELS > 4
PWM_1_PORT_CH4->PCR[PWM_1_PIN_CH4] = PORT_PCR_MUX(PWM_1_PIN_AF_CH4);
port_init(PWM_1_CH4_GPIO, GPIO_NOPULL, PWM_1_CH4_AF);
#endif
#if PWM_1_CHANNELS > 5
PWM_1_PORT_CH5->PCR[PWM_1_PIN_CH5] = PORT_PCR_MUX(PWM_1_PIN_AF_CH5);
port_init(PWM_1_CH5_GPIO, GPIO_NOPULL, PWM_1_CH5_AF);
#endif
#if PWM_1_CHANNELS > 6
PWM_1_PORT_CH6->PCR[PWM_1_PIN_CH6] = PORT_PCR_MUX(PWM_1_PIN_AF_CH6);
port_init(PWM_1_CH6_GPIO, GPIO_NOPULL, PWM_1_CH6_AF);
#endif
#if PWM_1_CHANNELS > 7
PWM_1_PORT_CH7->PCR[PWM_1_PIN_CH7] = PORT_PCR_MUX(PWM_1_PIN_AF_CH7);
port_init(PWM_1_CH7_GPIO, GPIO_NOPULL, PWM_1_CH7_AF);
#endif
break;
#endif
Expand Down

0 comments on commit 1b55b5f

Please sign in to comment.