PWM the R_EXT of the LED driver using FTM.
This commit is contained in:
@@ -595,13 +595,17 @@
|
|||||||
<configuration configurationName="Multiple configurations">
|
<configuration configurationName="Multiple configurations">
|
||||||
<resource resourceType="PROJECT" workspacePath="/FRDM-K64F_Demo"/>
|
<resource resourceType="PROJECT" workspacePath="/FRDM-K64F_Demo"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration configurationName="release-v7"/>
|
<configuration configurationName="v6-debug"/>
|
||||||
|
<configuration configurationName="v7-release"/>
|
||||||
<configuration configurationName="debug">
|
<configuration configurationName="debug">
|
||||||
<resource resourceType="PROJECT" workspacePath="/uhk-right"/>
|
<resource resourceType="PROJECT" workspacePath="/uhk-right"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration configurationName="release-v7"/>
|
||||||
<configuration configurationName="release">
|
<configuration configurationName="release">
|
||||||
<resource resourceType="PROJECT" workspacePath="/uhk-right"/>
|
<resource resourceType="PROJECT" workspacePath="/uhk-right"/>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<configuration configurationName="v6-release"/>
|
||||||
|
<configuration configurationName="v7-debug"/>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
<storageModule moduleId="org.eclipse.cdt.make.core.buildtargets"/>
|
||||||
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
|
||||||
|
|||||||
@@ -70,6 +70,16 @@
|
|||||||
<type>1</type>
|
<type>1</type>
|
||||||
<locationURI>$%7BPARENT-3-PROJECT_LOC%7D/lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_clock.h</locationURI>
|
<locationURI>$%7BPARENT-3-PROJECT_LOC%7D/lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_clock.h</locationURI>
|
||||||
</link>
|
</link>
|
||||||
|
<link>
|
||||||
|
<name>drivers/fsl_ftm.c</name>
|
||||||
|
<type>1</type>
|
||||||
|
<locationURI>$%7BPARENT-3-PROJECT_LOC%7D/lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_ftm.c</locationURI>
|
||||||
|
</link>
|
||||||
|
<link>
|
||||||
|
<name>drivers/fsl_ftm.h</name>
|
||||||
|
<type>1</type>
|
||||||
|
<locationURI>$%7BPARENT-3-PROJECT_LOC%7D/lib/KSDK_2.0_MK22FN512xxx12/devices/MK22F51212/drivers/fsl_ftm.h</locationURI>
|
||||||
|
</link>
|
||||||
<link>
|
<link>
|
||||||
<name>drivers/fsl_gpio.c</name>
|
<name>drivers/fsl_gpio.c</name>
|
||||||
<type>1</type>
|
<type>1</type>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "i2c.h"
|
#include "i2c.h"
|
||||||
#include "led_driver.h"
|
#include "led_driver.h"
|
||||||
#include "merge_sensor.h"
|
#include "merge_sensor.h"
|
||||||
|
#include "led_pwm.h"
|
||||||
|
|
||||||
void InitI2c() {
|
void InitI2c() {
|
||||||
port_pin_config_t pinConfig = {
|
port_pin_config_t pinConfig = {
|
||||||
@@ -49,4 +50,7 @@ void InitPeripherials(void)
|
|||||||
InitMergeSensor();
|
InitMergeSensor();
|
||||||
InitTestLed();
|
InitTestLed();
|
||||||
InitI2c();
|
InitI2c();
|
||||||
|
#if UHK_PCB_MAJOR_VERSION == 7
|
||||||
|
LedPwm_Init();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,6 @@ void LedDriver_InitAllLeds(char isEnabled)
|
|||||||
GPIO_PinInit(LED_DRIVER_SDB_GPIO, LED_DRIVER_SDB_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 0});
|
GPIO_PinInit(LED_DRIVER_SDB_GPIO, LED_DRIVER_SDB_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 0});
|
||||||
GPIO_WritePinOutput(LED_DRIVER_SDB_GPIO, LED_DRIVER_SDB_PIN, 1);
|
GPIO_WritePinOutput(LED_DRIVER_SDB_GPIO, LED_DRIVER_SDB_PIN, 1);
|
||||||
|
|
||||||
#if UHK_PCB_MAJOR_VERSION == 7
|
|
||||||
CLOCK_EnableClock(LED_DRIVER_PWM_CLOCK);
|
|
||||||
PORT_SetPinMux(LED_DRIVER_PWM_PORT, LED_DRIVER_PWM_PIN, kPORT_MuxAsGpio);
|
|
||||||
GPIO_PinInit(LED_DRIVER_PWM_GPIO, LED_DRIVER_PWM_PIN, &(gpio_pin_config_t){kGPIO_DigitalOutput, 0});
|
|
||||||
GPIO_WritePinOutput(LED_DRIVER_PWM_GPIO, LED_DRIVER_PWM_PIN, 1);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
LedDriver_SetAllLedsTo(isEnabled ? 0xFF : 0x00);
|
LedDriver_SetAllLedsTo(isEnabled ? 0xFF : 0x00);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +80,6 @@ void LedDriver_SetAllLedsTo(uint8_t val)
|
|||||||
I2cWrite(I2C_MAIN_BUS_BASEADDR, I2C_ADDRESS_LED_DRIVER_LEFT,
|
I2cWrite(I2C_MAIN_BUS_BASEADDR, I2C_ADDRESS_LED_DRIVER_LEFT,
|
||||||
ledControlBufferLeft, sizeof(ledControlBufferLeft));
|
ledControlBufferLeft, sizeof(ledControlBufferLeft));
|
||||||
|
|
||||||
|
|
||||||
for (i=FRAME_REGISTER_LED_CONTROL_FIRST; i<=FRAME_REGISTER_LED_CONTROL_LAST; i++) {
|
for (i=FRAME_REGISTER_LED_CONTROL_FIRST; i<=FRAME_REGISTER_LED_CONTROL_LAST; i++) {
|
||||||
LedDriver_WriteRegister(address, i, 0xff);
|
LedDriver_WriteRegister(address, i, 0xff);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,11 +16,6 @@
|
|||||||
#define LED_DRIVER_SDB_CLOCK kCLOCK_PortA
|
#define LED_DRIVER_SDB_CLOCK kCLOCK_PortA
|
||||||
#define LED_DRIVER_SDB_PIN 2
|
#define LED_DRIVER_SDB_PIN 2
|
||||||
|
|
||||||
#define LED_DRIVER_PWM_PORT PORTD
|
|
||||||
#define LED_DRIVER_PWM_GPIO GPIOD
|
|
||||||
#define LED_DRIVER_PWM_CLOCK kCLOCK_PortD
|
|
||||||
#define LED_DRIVER_PWM_PIN 6
|
|
||||||
|
|
||||||
#define LED_DRIVER_REGISTER_SHUTDOWN 0x0A
|
#define LED_DRIVER_REGISTER_SHUTDOWN 0x0A
|
||||||
#define LED_DRIVER_REGISTER_FRAME 0xFD
|
#define LED_DRIVER_REGISTER_FRAME 0xFD
|
||||||
|
|
||||||
|
|||||||
33
right/src/led_pwm.c
Normal file
33
right/src/led_pwm.c
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include "led_pwm.h"
|
||||||
|
#include "fsl_port.h"
|
||||||
|
|
||||||
|
void LedPwm_Init() {
|
||||||
|
ftm_config_t ftmInfo;
|
||||||
|
ftm_chnl_pwm_signal_param_t ftmParam[] = {{
|
||||||
|
.chnlNumber = LED_PWM_FTM_CHANNEL,
|
||||||
|
.level = kFTM_LowTrue,
|
||||||
|
.dutyCyclePercent = 00,
|
||||||
|
.firstEdgeDelayPercent = 0
|
||||||
|
}};
|
||||||
|
|
||||||
|
CLOCK_EnableClock(LED_PWM_CLOCK);
|
||||||
|
PORT_SetPinMux(LED_PWM_PORT, LED_PWM_PIN, kPORT_MuxAlt4);
|
||||||
|
|
||||||
|
ftmParam[0].chnlNumber = (ftm_chnl_t)LED_PWM_FTM_CHANNEL;
|
||||||
|
ftmParam[0].level = kFTM_LowTrue;
|
||||||
|
ftmParam[0].dutyCyclePercent = INITIAL_DUTY_CYCLE_PERCENT - 100;
|
||||||
|
ftmParam[0].firstEdgeDelayPercent = 0;
|
||||||
|
FTM_GetDefaultConfig(&ftmInfo);
|
||||||
|
|
||||||
|
// Initializes the FTM module.
|
||||||
|
FTM_Init(LED_PWM_FTM_BASEADDR, &ftmInfo);
|
||||||
|
FTM_SetupPwm(LED_PWM_FTM_BASEADDR, ftmParam, sizeof(ftmParam),
|
||||||
|
kFTM_EdgeAlignedPwm, FTM_PWM_FREQUENCY, FTM_SOURCE_CLOCK);
|
||||||
|
FTM_StartTimer(LED_PWM_FTM_BASEADDR, kFTM_SystemClock);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LedPwm_SetBrightness(uint8_t brightnessPercent)
|
||||||
|
{
|
||||||
|
FTM_UpdatePwmDutycycle(LED_PWM_FTM_BASEADDR, LED_PWM_FTM_CHANNEL, kFTM_EdgeAlignedPwm, brightnessPercent-100);
|
||||||
|
FTM_SetSoftwareTrigger(LED_PWM_FTM_BASEADDR, true); // Triggers register update.
|
||||||
|
}
|
||||||
27
right/src/led_pwm.h
Normal file
27
right/src/led_pwm.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef __LED_PWM_H__
|
||||||
|
#define __LED_PWM_H__
|
||||||
|
|
||||||
|
// Includes:
|
||||||
|
|
||||||
|
#include "fsl_ftm.h"
|
||||||
|
|
||||||
|
// Macros:
|
||||||
|
|
||||||
|
#define LED_PWM_PORT PORTD
|
||||||
|
#define LED_PWM_CLOCK kCLOCK_PortD
|
||||||
|
#define LED_PWM_PIN 6
|
||||||
|
|
||||||
|
#define LED_PWM_FTM_BASEADDR FTM0
|
||||||
|
#define LED_PWM_FTM_CHANNEL kFTM_Chnl_6
|
||||||
|
|
||||||
|
#define FTM_SOURCE_CLOCK CLOCK_GetFreq(kCLOCK_BusClk)
|
||||||
|
#define FTM_PWM_FREQUENCY 24000
|
||||||
|
|
||||||
|
#define INITIAL_DUTY_CYCLE_PERCENT 100
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
extern void LedPwm_Init();
|
||||||
|
void LedPwm_SetBrightness(uint8_t brightnessPercent);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
#include "merge_sensor.h"
|
#include "merge_sensor.h"
|
||||||
#include "deserialize.h"
|
#include "deserialize.h"
|
||||||
#include "config_buffer.h"
|
#include "config_buffer.h"
|
||||||
|
#include "led_pwm.h"
|
||||||
|
|
||||||
void setError(uint8_t error);
|
void setError(uint8_t error);
|
||||||
void setGenericError();
|
void setGenericError();
|
||||||
@@ -20,6 +21,7 @@ void readEeprom();
|
|||||||
void readMergeSensor();
|
void readMergeSensor();
|
||||||
void uploadConfig();
|
void uploadConfig();
|
||||||
void applyConfig();
|
void applyConfig();
|
||||||
|
void setLedPwm();
|
||||||
|
|
||||||
// Functions for setting error statuses
|
// Functions for setting error statuses
|
||||||
|
|
||||||
@@ -75,6 +77,9 @@ void usbProtocolHandler()
|
|||||||
case USB_COMMAND_APPLY_CONFIG:
|
case USB_COMMAND_APPLY_CONFIG:
|
||||||
applyConfig();
|
applyConfig();
|
||||||
break;
|
break;
|
||||||
|
case USB_COMMAND_SET_LED_PWM:
|
||||||
|
setLedPwm();
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -199,3 +204,11 @@ void applyConfig()
|
|||||||
{
|
{
|
||||||
deserialize_Layer(ConfigBuffer, 0);
|
deserialize_Layer(ConfigBuffer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setLedPwm()
|
||||||
|
{
|
||||||
|
uint8_t brightnessPercent = GenericHidInBuffer[1];
|
||||||
|
#if UHK_PCB_MAJOR_VERSION == 7
|
||||||
|
LedPwm_SetBrightness(brightnessPercent);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
#define USB_COMMAND_UPLOAD_CONFIG 8
|
#define USB_COMMAND_UPLOAD_CONFIG 8
|
||||||
#define UPLOAD_CONFIG_INVALID_PAYLOAD_SIZE 1
|
#define UPLOAD_CONFIG_INVALID_PAYLOAD_SIZE 1
|
||||||
#define USB_COMMAND_APPLY_CONFIG 9
|
#define USB_COMMAND_APPLY_CONFIG 9
|
||||||
|
#define USB_COMMAND_SET_LED_PWM 10
|
||||||
|
|
||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user