Added pin descriptions for NUCLEO-F303RE. Tested

Fork of FastPWM by Erik -

Files at this revision

API Documentation at this revision

Comitter:
Sissors
Date:
Sun Jul 20 12:49:21 2014 +0000
Parent:
11:e0a8f0fcb1c9
Child:
13:cdefd9d75b64
Commit message:
Preparation for Nucleo devices: Added option to have a device specific container with variables (such as pointer to match registers, since nucleo pwmout class lacks those).
; And practised on the LPC11u24 to implement it.

Changed in this revision

Device/FastPWM_LPC11U24.cpp Show annotated file Show diff for this revision Revisions of this file
FastPWM.h Show annotated file Show diff for this revision Revisions of this file
FastPWM_common.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Device/FastPWM_LPC11U24.cpp	Wed Jul 16 15:44:21 2014 +0000
+++ b/Device/FastPWM_LPC11U24.cpp	Sun Jul 20 12:49:21 2014 +0000
@@ -2,13 +2,18 @@
 
 #include "FastPWM.h"
 
+#define PWM_MR              (*(((fastpwm_struct*)fast_obj)->MR))   
+#define PWM_TIMER           (((fastpwm_struct*)fast_obj)->timer)      
+
+typedef struct  {
+    __IO uint32_t *MR;
+    LPC_CTxxBx_Type *timer;
+} fastpwm_struct;
+
 typedef struct {
     uint8_t timer;
     uint8_t mr;
 } timer_mr;
-
-LPC_CTxxBx_Type *pwm_obj;
-timer_mr tid;
  
 static timer_mr pwm_timer_map[11] = {
     {0, 0}, {0, 1}, {0, 2},
@@ -24,8 +29,10 @@
 
 
 void FastPWM::initFastPWM( void ) {
-    tid = pwm_timer_map[_pwm.pwm];
-    pwm_obj = Timers[tid.timer];
+    fast_obj = new fastpwm_struct;
+    timer_mr tid = pwm_timer_map[_pwm.pwm];
+    PWM_TIMER = Timers[tid.timer];
+    (((fastpwm_struct*)fast_obj)->MR) = &PWM_TIMER->MR[tid.mr];
     
     if (tid.timer < 2)
         //16-bit timer
@@ -36,35 +43,23 @@
 }
 
 void FastPWM::pulsewidth_ticks( uint32_t ticks ) {
-    tid = pwm_timer_map[_pwm.pwm];
-    pwm_obj = Timers[tid.timer];
-    
     if (ticks)
-        pwm_obj->MR[tid.mr] = pwm_obj->MR3 - ticks;  //They inverted PWM on the 11u24
+        PWM_MR = PWM_TIMER->MR3 - ticks;  //They inverted PWM on the 11u24
     else
-        pwm_obj->MR[tid.mr] = 0xFFFFFFFF;           //If MR3 = ticks 1 clock cycle wide errors appear, this prevents that (unless MR3 = max).
+        PWM_MR = 0xFFFFFFFF;           //If MR3 = ticks 1 clock cycle wide errors appear, this prevents that (unless MR3 = max).
 }
 
-void FastPWM::period_ticks( uint32_t ticks ) {
-    tid = pwm_timer_map[_pwm.pwm];
-    pwm_obj = Timers[tid.timer];
-    
-    pwm_obj->TCR = 0x02;
-    pwm_obj->MR3 = ticks;
-    pwm_obj->TCR = 0x01;   
+void FastPWM::period_ticks( uint32_t ticks ) {  
+    PWM_TIMER->TCR = 0x02;
+    PWM_TIMER->MR3 = ticks;
+    PWM_TIMER->TCR = 0x01;   
 }
 
 uint32_t FastPWM::getPeriod( void ) {
-    tid = pwm_timer_map[_pwm.pwm];
-    pwm_obj = Timers[tid.timer];
-    
-    return pwm_obj->MR3;
+    return PWM_TIMER->MR3;
 }
 
 uint32_t FastPWM::setPrescaler(uint32_t reqScale) {
-    tid = pwm_timer_map[_pwm.pwm];
-    pwm_obj = Timers[tid.timer];
-    
     //If 32-bit, disable auto-scaling, return 1
     if (bits == 32) {
         dynamicPrescaler = false;
@@ -74,11 +69,11 @@
     //Else 16-bit timer:
     if (reqScale == 0)
         //Return prescaler
-        return pwm_obj->PR + 1;
+        return PWM_TIMER->PR + 1;
     if (reqScale > (uint32_t)(1<<16))
         reqScale = 1<<16;
     //Else set prescaler, we have to substract one from reqScale since a 0 in PCVAL is prescaler of 1
-    pwm_obj->PR = reqScale - 1;
+    PWM_TIMER->PR = reqScale - 1;
 
     return reqScale;
 }
--- a/FastPWM.h	Wed Jul 16 15:44:21 2014 +0000
+++ b/FastPWM.h	Sun Jul 20 12:49:21 2014 +0000
@@ -36,6 +36,7 @@
     * @param prescaler - Clock prescaler, -1 is dynamic (default), 0 is bit random, everything else normal
     */
     FastPWM(PinName pin, int prescaler = -1);
+    ~FastPWM(); 
     
     /**
     * Set the PWM period, specified in seconds (double), keeping the pulsewidth the same.
@@ -144,6 +145,6 @@
     
     bool dynamicPrescaler;
     
-
+    void *fast_obj;
 };
 #endif
\ No newline at end of file
--- a/FastPWM_common.cpp	Wed Jul 16 15:44:21 2014 +0000
+++ b/FastPWM_common.cpp	Sun Jul 20 12:49:21 2014 +0000
@@ -1,6 +1,7 @@
 #include "FastPWM.h"
 
 FastPWM::FastPWM(PinName pin, int prescaler) : PwmOut(pin) {
+    fast_obj = NULL;
     initFastPWM();
     this->prescaler(prescaler);
     
@@ -11,6 +12,11 @@
 
 }
 
+FastPWM::~FastPWM( void ) {
+    if (fast_obj != NULL)
+        delete(fast_obj);
+} 
+
 void FastPWM::period(double seconds) {
     if (dynamicPrescaler)
         calcPrescaler((uint64_t)(seconds * (double) SystemCoreClock));