Merged in JordanMacIntyre/nuttx/PWM_driver (pull request #106)
Pwm_driver
This commit is contained in:
commit
250b9d5597
@ -58,7 +58,7 @@
|
|||||||
#include "chip.h"
|
#include "chip.h"
|
||||||
|
|
||||||
#include "kinetis.h"
|
#include "kinetis.h"
|
||||||
#include "chip/kinetis_pwm.h"
|
#include "kinetis_pwm.h"
|
||||||
#include "chip/kinetis_gpio.h"
|
#include "chip/kinetis_gpio.h"
|
||||||
#include "chip/kinetis_ftm.h"
|
#include "chip/kinetis_ftm.h"
|
||||||
#include "chip/kinetis_sim.h"
|
#include "chip/kinetis_sim.h"
|
||||||
|
@ -90,13 +90,13 @@
|
|||||||
# elif CONFIG_KL_TPM0_CHANNEL == 1
|
# elif CONFIG_KL_TPM0_CHANNEL == 1
|
||||||
# define PWM_TPM0_PINCFG GPIO_TPM0_CH1OUT
|
# define PWM_TPM0_PINCFG GPIO_TPM0_CH1OUT
|
||||||
# elif CONFIG_KL_TPM0_CHANNEL == 2
|
# elif CONFIG_KL_TPM0_CHANNEL == 2
|
||||||
# define PWM_TPM0_PINCFG GPIO_TPM1_CH2OUT
|
# define PWM_TPM0_PINCFG GPIO_TPM0_CH2OUT
|
||||||
# elif CONFIG_KL_TPM0_CHANNEL == 3
|
# elif CONFIG_KL_TPM0_CHANNEL == 3
|
||||||
# define PWM_TPM0_PINCFG GPIO_TPM1_CH3OUT
|
# define PWM_TPM0_PINCFG GPIO_TPM0_CH3OUT
|
||||||
# elif CONFIG_KL_TPM0_CHANNEL == 4
|
# elif CONFIG_KL_TPM0_CHANNEL == 4
|
||||||
# define PWM_TPM0_PINCFG GPIO_TPM1_CH4OUT
|
# define PWM_TPM0_PINCFG GPIO_TPM0_CH4OUT
|
||||||
# elif CONFIG_KL_TPM0_CHANNEL == 5
|
# elif CONFIG_KL_TPM0_CHANNEL == 5
|
||||||
# define PWM_TPM0_PINCFG GPIO_TPM1_CH5OUT
|
# define PWM_TPM0_PINCFG GPIO_TPM0_CH5OUT
|
||||||
# else
|
# else
|
||||||
# error "Unsupported value of CONFIG_KL_TPM1_CHANNEL"
|
# error "Unsupported value of CONFIG_KL_TPM1_CHANNEL"
|
||||||
# endif
|
# endif
|
||||||
|
@ -134,6 +134,19 @@
|
|||||||
# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3)
|
# define BOARD_SDHC_SD4MODE_DIVISOR SDHC_SYSCTL_DVS_DIV(3)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* PWM Configuration */
|
||||||
|
/* FTM0 Channels */
|
||||||
|
/* Channels can be modified using kinetis_k64pinmux.h */
|
||||||
|
|
||||||
|
#define GPIO_FTM0_CH0OUT PIN_FTM0_CH0_1
|
||||||
|
#define GPIO_FTM0_CH1OUT PIN_FTM0_CH1_1
|
||||||
|
#define GPIO_FTM0_CH2OUT PIN_FTM0_CH2_2
|
||||||
|
#define GPIO_FTM0_CH3OUT PIN_FTM0_CH3_1
|
||||||
|
#define GPIO_FTM0_CH4OUT PIN_FTM0_CH4_1
|
||||||
|
#define GPIO_FTM0_CH5OUT PIN_FTM0_CH5_1
|
||||||
|
|
||||||
|
|
||||||
/* LED definitions ******************************************************************/
|
/* LED definitions ******************************************************************/
|
||||||
/* The Freedom K64F has a single RGB LED driven by the K64F as follows:
|
/* The Freedom K64F has a single RGB LED driven by the K64F as follows:
|
||||||
*
|
*
|
||||||
|
@ -8,12 +8,12 @@
|
|||||||
#
|
#
|
||||||
# CONFIG_EXPERIMENTAL is not set
|
# CONFIG_EXPERIMENTAL is not set
|
||||||
# CONFIG_DEFAULT_SMALL is not set
|
# CONFIG_DEFAULT_SMALL is not set
|
||||||
# CONFIG_HOST_LINUX is not set
|
CONFIG_HOST_LINUX=y
|
||||||
# CONFIG_HOST_OSX is not set
|
# CONFIG_HOST_OSX is not set
|
||||||
CONFIG_HOST_WINDOWS=y
|
# CONFIG_HOST_WINDOWS is not set
|
||||||
# CONFIG_HOST_OTHER is not set
|
# CONFIG_HOST_OTHER is not set
|
||||||
# CONFIG_WINDOWS_NATIVE is not set
|
# CONFIG_WINDOWS_NATIVE is not set
|
||||||
CONFIG_WINDOWS_CYGWIN=y
|
# CONFIG_WINDOWS_CYGWIN is not set
|
||||||
# CONFIG_WINDOWS_MSYS is not set
|
# CONFIG_WINDOWS_MSYS is not set
|
||||||
# CONFIG_WINDOWS_OTHER is not set
|
# CONFIG_WINDOWS_OTHER is not set
|
||||||
|
|
||||||
@ -216,7 +216,7 @@ CONFIG_KINETIS_UART0=y
|
|||||||
# CONFIG_KINETIS_CMP is not set
|
# CONFIG_KINETIS_CMP is not set
|
||||||
# CONFIG_KINETIS_VREF is not set
|
# CONFIG_KINETIS_VREF is not set
|
||||||
CONFIG_KINETIS_SDHC=y
|
CONFIG_KINETIS_SDHC=y
|
||||||
# CONFIG_KINETIS_FTM0 is not set
|
CONFIG_KINETIS_FTM0=y
|
||||||
# CONFIG_KINETIS_FTM1 is not set
|
# CONFIG_KINETIS_FTM1 is not set
|
||||||
# CONFIG_KINETIS_FTM2 is not set
|
# CONFIG_KINETIS_FTM2 is not set
|
||||||
# CONFIG_KINETIS_LPTIMER is not set
|
# CONFIG_KINETIS_LPTIMER is not set
|
||||||
@ -232,6 +232,8 @@ CONFIG_KINETIS_SDHC=y
|
|||||||
# CONFIG_KINETIS_CRC is not set
|
# CONFIG_KINETIS_CRC is not set
|
||||||
# CONFIG_KINETIS_PDB is not set
|
# CONFIG_KINETIS_PDB is not set
|
||||||
# CONFIG_KINETIS_PIT is not set
|
# CONFIG_KINETIS_PIT is not set
|
||||||
|
CONFIG_KINETIS_FTM0_PWM=y
|
||||||
|
CONFIG_KINETIS_FTM0_CHANNEL=2
|
||||||
|
|
||||||
#
|
#
|
||||||
# Kinetis GPIO Interrupt Configuration
|
# Kinetis GPIO Interrupt Configuration
|
||||||
@ -339,7 +341,7 @@ CONFIG_LIB_BOARDCTL=y
|
|||||||
# CONFIG_BOARDCTL_UNIQUEID is not set
|
# CONFIG_BOARDCTL_UNIQUEID is not set
|
||||||
# CONFIG_BOARDCTL_TSCTEST is not set
|
# CONFIG_BOARDCTL_TSCTEST is not set
|
||||||
# CONFIG_BOARDCTL_ADCTEST is not set
|
# CONFIG_BOARDCTL_ADCTEST is not set
|
||||||
# CONFIG_BOARDCTL_PWMTEST is not set
|
CONFIG_BOARDCTL_PWMTEST=y
|
||||||
# CONFIG_BOARDCTL_GRAPHICS is not set
|
# CONFIG_BOARDCTL_GRAPHICS is not set
|
||||||
# CONFIG_BOARDCTL_IOCTL is not set
|
# CONFIG_BOARDCTL_IOCTL is not set
|
||||||
|
|
||||||
@ -347,11 +349,11 @@ CONFIG_LIB_BOARDCTL=y
|
|||||||
# RTOS Features
|
# RTOS Features
|
||||||
#
|
#
|
||||||
CONFIG_DISABLE_OS_API=y
|
CONFIG_DISABLE_OS_API=y
|
||||||
# CONFIG_DISABLE_POSIX_TIMERS is not set
|
CONFIG_DISABLE_POSIX_TIMERS=y
|
||||||
# CONFIG_DISABLE_PTHREAD is not set
|
# CONFIG_DISABLE_PTHREAD is not set
|
||||||
# CONFIG_DISABLE_SIGNALS is not set
|
# CONFIG_DISABLE_SIGNALS is not set
|
||||||
# CONFIG_DISABLE_MQUEUE is not set
|
CONFIG_DISABLE_MQUEUE=y
|
||||||
# CONFIG_DISABLE_ENVIRON is not set
|
CONFIG_DISABLE_ENVIRON=y
|
||||||
|
|
||||||
#
|
#
|
||||||
# Clocks and Timers
|
# Clocks and Timers
|
||||||
@ -468,7 +470,7 @@ CONFIG_DEV_NULL=y
|
|||||||
# CONFIG_CAN is not set
|
# CONFIG_CAN is not set
|
||||||
# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
|
# CONFIG_ARCH_HAVE_PWM_PULSECOUNT is not set
|
||||||
# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
|
# CONFIG_ARCH_HAVE_PWM_MULTICHAN is not set
|
||||||
# CONFIG_PWM is not set
|
CONFIG_PWM=y
|
||||||
# CONFIG_ARCH_HAVE_I2CRESET is not set
|
# CONFIG_ARCH_HAVE_I2CRESET is not set
|
||||||
# CONFIG_I2C is not set
|
# CONFIG_I2C is not set
|
||||||
# CONFIG_SPI is not set
|
# CONFIG_SPI is not set
|
||||||
@ -777,6 +779,11 @@ CONFIG_EXAMPLES_NSH=y
|
|||||||
# CONFIG_EXAMPLES_PCA9635 is not set
|
# CONFIG_EXAMPLES_PCA9635 is not set
|
||||||
# CONFIG_EXAMPLES_POSIXSPAWN is not set
|
# CONFIG_EXAMPLES_POSIXSPAWN is not set
|
||||||
# CONFIG_EXAMPLES_PPPD is not set
|
# CONFIG_EXAMPLES_PPPD is not set
|
||||||
|
CONFIG_EXAMPLES_PWM=y
|
||||||
|
CONFIG_EXAMPLES_PWM_DEVPATH="/dev/pwm0"
|
||||||
|
CONFIG_EXAMPLES_PWM_FREQUENCY=100
|
||||||
|
CONFIG_EXAMPLES_PWM_DURATION=5
|
||||||
|
CONFIG_EXAMPLES_PWM_DUTYPCT=50
|
||||||
# CONFIG_EXAMPLES_RGBLED is not set
|
# CONFIG_EXAMPLES_RGBLED is not set
|
||||||
# CONFIG_EXAMPLES_RGMP is not set
|
# CONFIG_EXAMPLES_RGMP is not set
|
||||||
# CONFIG_EXAMPLES_SENDMAIL is not set
|
# CONFIG_EXAMPLES_SENDMAIL is not set
|
||||||
|
@ -69,4 +69,8 @@ ifeq ($(CONFIG_USBMSC),y)
|
|||||||
CSRCS += k64_usbmsc.c
|
CSRCS += k64_usbmsc.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_PWM),y)
|
||||||
|
CSRCS += k64_pwm.c
|
||||||
|
endif
|
||||||
|
|
||||||
include $(TOPDIR)/configs/Board.mk
|
include $(TOPDIR)/configs/Board.mk
|
||||||
|
122
configs/freedom-k64f/src/k64_pwm.c
Normal file
122
configs/freedom-k64f/src/k64_pwm.c
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
/************************************************************************************
|
||||||
|
* configs/freedom-k64f/src/k64_pwm.c
|
||||||
|
*
|
||||||
|
* Copyright (C) 2013, 2015, 2016 Gregory Nutt. All rights reserved.
|
||||||
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
|
* Jordan MacIntyre <jordanroymax@gmail.com>
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||||
|
* used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||||
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||||
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||||
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||||
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||||
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||||
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
* POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Included Files
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/board.h>
|
||||||
|
#include <nuttx/pwm.h>
|
||||||
|
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
#include "chip.h"
|
||||||
|
#include "up_arch.h"
|
||||||
|
#include "kinetis_pwm.h"
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
************************************************************************************/
|
||||||
|
/* Configuration *******************************************************************/
|
||||||
|
/* PWM
|
||||||
|
*
|
||||||
|
* The Kinetis Freedom board provides a LED on GPIO.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef CONFIG_PWM
|
||||||
|
|
||||||
|
extern struct pwm_lowerhalf_s *kinetis_pwminitialize(int timer);
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Name: board_pwm_setup
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* All Kinetis K architectures must provide the following interface to work with
|
||||||
|
* examples/pwm.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
int board_pwm_setup(void)
|
||||||
|
{
|
||||||
|
static bool initialized = false;
|
||||||
|
struct pwm_lowerhalf_s *pwm;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Have we already initialized? */
|
||||||
|
|
||||||
|
if (!initialized)
|
||||||
|
{
|
||||||
|
/* Call k64_pwminitialize() to get an instance of the PWM interface */
|
||||||
|
|
||||||
|
pwm = kinetis_pwminitialize(0);
|
||||||
|
if (!pwm)
|
||||||
|
{
|
||||||
|
aerr("ERROR: Failed to get the K64 PWM lower half\n");
|
||||||
|
return -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Register the PWM driver at "/dev/pwm0" */
|
||||||
|
|
||||||
|
ret = pwm_register("/dev/pwm0", pwm);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
aerr("ERROR: pwm_register failed: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now we are initialized */
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_PWM */
|
@ -186,7 +186,7 @@ CONFIG_KL_TPM0=y
|
|||||||
CONFIG_KL_SYSTICK_CORECLK=y
|
CONFIG_KL_SYSTICK_CORECLK=y
|
||||||
# CONFIG_KL_SYSTICK_CORECLK_DIV16 is not set
|
# CONFIG_KL_SYSTICK_CORECLK_DIV16 is not set
|
||||||
CONFIG_KL_TPM0_PWM=y
|
CONFIG_KL_TPM0_PWM=y
|
||||||
CONFIG_KL_TPM0_CHANNEL=0
|
CONFIG_KL_TPM0_CHANNEL=2
|
||||||
|
|
||||||
#
|
#
|
||||||
# Kinetis GPIO Interrupt Configuration
|
# Kinetis GPIO Interrupt Configuration
|
||||||
|
Loading…
Reference in New Issue
Block a user