microbit: modified constructor for DynamicPwm
Previously there would be the possibility of the period being reset each time a new DynamicPwm was instantiated. This has now been removed from the constructor, and the comments have been updated
This commit is contained in:
parent
6b1e020392
commit
68474c5e58
2 changed files with 5 additions and 9 deletions
|
@ -4,7 +4,6 @@
|
|||
#define MICROBIT_DYNAMIC_PWM_H
|
||||
|
||||
#define NO_PWMS 3
|
||||
#define MICROBIT_DISPLAY_PWM_PERIOD 1000
|
||||
|
||||
enum PwmPersistence
|
||||
{
|
||||
|
@ -31,9 +30,8 @@ class DynamicPwm : public PwmOut
|
|||
* @param pin the name of the pin for the pwm to target
|
||||
* @param persistance the level of persistence for this pin PWM_PERSISTENCE_PERSISTENT (can not be replaced until freed, should only be used for system services really.)
|
||||
* or PWM_PERSISTENCE_TRANSIENT (can be replaced at any point if a channel is required.)
|
||||
* @param period the frequency of the pwm channel in us.
|
||||
*/
|
||||
DynamicPwm(PinName pin, PwmPersistence persistence = PWM_PERSISTENCE_TRANSIENT, int period = MICROBIT_DISPLAY_PWM_PERIOD);
|
||||
DynamicPwm(PinName pin, PwmPersistence persistence = PWM_PERSISTENCE_TRANSIENT);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -62,7 +60,7 @@ class DynamicPwm : public PwmOut
|
|||
* DynamicPwm* pwm = DynamicPwm::allocate(PinName n);
|
||||
* @endcode
|
||||
*/
|
||||
static DynamicPwm* allocate(PinName pin, PwmPersistence persistence = PWM_PERSISTENCE_TRANSIENT, int period = MICROBIT_DISPLAY_PWM_PERIOD);
|
||||
static DynamicPwm* allocate(PinName pin, PwmPersistence persistence = PWM_PERSISTENCE_TRANSIENT);
|
||||
|
||||
/**
|
||||
* Frees this DynamicPwm instance if the pointer is valid.
|
||||
|
|
|
@ -48,10 +48,9 @@ void gpiote_reinit(PinName pin, PinName oldPin, uint8_t channel_number)
|
|||
* or PWM_PERSISTENCE_TRANSIENT (can be replaced at any point if a channel is required.)
|
||||
* @param period the frequency of the pwm channel in us.
|
||||
*/
|
||||
DynamicPwm::DynamicPwm(PinName pin, PwmPersistence persistence, int period) : PwmOut(pin)
|
||||
DynamicPwm::DynamicPwm(PinName pin, PwmPersistence persistence) : PwmOut(pin)
|
||||
{
|
||||
this->flags = persistence;
|
||||
this->setPeriodUs(period);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,14 +74,13 @@ void DynamicPwm::redirect(PinName pin)
|
|||
* @param pin the name of the pin for the pwm to target
|
||||
* @param persistance the level of persistence for this pin PWM_PERSISTENCE_PERSISTENT (can not be replaced until freed, should only be used for system services really.)
|
||||
* or PWM_PERSISTENCE_TRANSIENT (can be replaced at any point if a channel is required.)
|
||||
* @param period the frequency of the pwm channel in us.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* DynamicPwm* pwm = DynamicPwm::allocate(PinName n);
|
||||
* @endcode
|
||||
*/
|
||||
DynamicPwm* DynamicPwm::allocate(PinName pin, PwmPersistence persistence, int period)
|
||||
DynamicPwm* DynamicPwm::allocate(PinName pin, PwmPersistence persistence)
|
||||
{
|
||||
//try to find a blank spot first
|
||||
for(int i = 0; i < NO_PWMS; i++)
|
||||
|
@ -90,7 +88,7 @@ DynamicPwm* DynamicPwm::allocate(PinName pin, PwmPersistence persistence, int pe
|
|||
if(pwms[i] == NULL)
|
||||
{
|
||||
lastUsed = i;
|
||||
pwms[i] = new DynamicPwm(pin, persistence, period);
|
||||
pwms[i] = new DynamicPwm(pin, persistence);
|
||||
return pwms[i];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue