FastPWM clone

Revision:
31:10e2e171f430
Parent:
14:b30038fbba51
Child:
33:2ca2e47f9650
--- a/Device/FastPWM_KSDK.cpp	Mon Mar 14 20:41:49 2016 +0000
+++ b/Device/FastPWM_KSDK.cpp	Tue Sep 06 20:17:21 2016 +0000
@@ -1,7 +1,7 @@
 #if defined(TARGET_KPSDK_MCUS)
 
 #include "FastPWM.h"
-#include "fsl_clock_manager.h"
+#include "fsl_ftm.h"
 
 
 #define PWM_CNV              (*(((fastpwm_struct*)fast_obj)->CnV))  
@@ -15,18 +15,16 @@
 } fastpwm_struct;
 
 static uint32_t pwm_prescaler;
+static FTM_Type *const ftm_addrs[] = FTM_BASE_PTRS;
 
 void FastPWM::initFastPWM( void ) {
     fast_obj = new fastpwm_struct;
     bits = 16;
-    
-    uint32_t pwm_base_clock;
-    CLOCK_SYS_GetFreq(kBusClock, &pwm_base_clock);
-    pwm_prescaler = SystemCoreClock / pwm_base_clock;
+
+    pwm_prescaler = SystemCoreClock / CLOCK_GetFreq(kCLOCK_BusClk);;
 
-    uint32_t ftms[] = FTM_BASE_ADDRS;
-    unsigned int ch_n = (_pwm.pwm_name & 0xFF);
-    FTM_Type *ftm = (FTM_Type *)ftms[_pwm.pwm_name >> TPM_SHIFT];
+    unsigned int ch_n = (_pwm.pwm_name & 0xF);
+    FTM_Type *ftm = ftm_addrs[_pwm.pwm_name >> TPM_SHIFT];
     
     ((fastpwm_struct*)fast_obj)->CnV = &ftm->CONTROLS[ch_n].CnV;
     ((fastpwm_struct*)fast_obj)->MOD = &ftm->MOD;
@@ -35,6 +33,10 @@
 
 void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
     PWM_CNV = ticks;
+    
+    //Temporary work around until I figure out which settings mbed screwed up in this update
+    FTM_Type *ftm = ftm_addrs[_pwm.pwm_name >> TPM_SHIFT];
+    FTM_SetSoftwareTrigger(ftm, true);
 }
 
 void FastPWM::period_ticks( uint32_t ticks ) {