change token from const var to enum

This commit is contained in:
hathach committed 2020-08-27 15:45:16 +07:00
1 parent 13a01fe7a8
commit 786ceae1f1
3 files changed
+20 -13

No files matched your search

+4 -4
View File
@@ -48,7 +48,7 @@ static HardwarePWM * const _HwPWM = HwPWMx[2];
// Defined a struct, to simplify validation testing ... also provides context when debugging
class TonePwmConfig {
private:
const uint32_t toneToken = 0x656e6f54; //< 'T' 'o' 'n' 'e'
enum { TONE_TOKEN = 0x656e6f54 }; //< 'T' 'o' 'n' 'e'
uint64_t pulse_count; //< total number of PWM pulses
uint32_t seq0_refresh; //< count of pulses for each SEQ0 iteration
uint32_t seq1_refresh; //< count of pulses for each SEQ1 iteration
@@ -198,7 +198,7 @@ void noTone(uint8_t pin)
}
bool TonePwmConfig::ensurePwmPeripheralOwnership(void) {
if (!_HwPWM->isOwner(TonePwmConfig::toneToken) && !_HwPWM->takeOwnership(TonePwmConfig::toneToken)) {
if (!_HwPWM->isOwner(TonePwmConfig::TONE_TOKEN) && !_HwPWM->takeOwnership(TonePwmConfig::TONE_TOKEN)) {
LOG_LV1("Tone", "unable to allocate PWM2 to Tone");
return false;
}
@@ -364,7 +364,7 @@ bool TonePwmConfig::startPlayback(void) {
bool TonePwmConfig::stopPlayback(bool releaseOwnership) {
if (!_HwPWM->isOwner(TonePwmConfig::toneToken)) {
if (!_HwPWM->isOwner(TonePwmConfig::TONE_TOKEN)) {
LOG_LV2("Tone", "Attempt to set noTone when not the owner of the PWM peripheral. Ignoring call....");
return false;
}
@@ -376,7 +376,7 @@ bool TonePwmConfig::stopPlayback(bool releaseOwnership) {
}
if (releaseOwnership) {
_HwPWM->releaseOwnership(TonePwmConfig::toneToken);
_HwPWM->releaseOwnership(TonePwmConfig::TONE_TOKEN);
}
return true;
+9 -5
View File
@@ -46,8 +46,12 @@
extern "C"
{
enum
{
ANALOG_TOKEN = 0x676f6c41 // 'A' 'l' 'o' 'g'
};
static uint8_t _analogResolution = 8; // default is 256 levels
static uint32_t _analogToken = 0x676f6c41; // 'A' 'l' 'o' 'g'
/**
* This will apply to all PWM Hardware currently used by analogWrite(),
@@ -59,7 +63,7 @@ void analogWriteResolution( uint8_t res )
_analogResolution = res;
for (int i = 0; i<HWPWM_MODULE_NUM; i++)
{
if (HwPWMx[i]->isOwner(_analogToken))
if (HwPWMx[i]->isOwner(ANALOG_TOKEN))
{
HwPWMx[i]->setResolution(res);
}
@@ -78,7 +82,7 @@ void analogWrite( uint32_t pin, uint32_t value )
// first, handle the case where the pin is already in use by analogWrite()
for(int i=0; i<HWPWM_MODULE_NUM; i++)
{
if (HwPWMx[i]->isOwner(_analogToken))
if (HwPWMx[i]->isOwner(ANALOG_TOKEN))
{
int const ch = HwPWMx[i]->pin2channel(pin);
if (ch >= 0)
@@ -92,7 +96,7 @@ void analogWrite( uint32_t pin, uint32_t value )
// Next, handle the case where can add the pin to a PWM instance already owned by analogWrite()
for(int i=0; i<HWPWM_MODULE_NUM; i++)
{
if ( HwPWMx[i]->isOwner(_analogToken) && HwPWMx[i]->addPin(pin) )
if ( HwPWMx[i]->isOwner(ANALOG_TOKEN) && HwPWMx[i]->addPin(pin) )
{
// successfully added the pin, so write the value also
HwPWMx[i]->writePin(pin, value);
@@ -106,7 +110,7 @@ void analogWrite( uint32_t pin, uint32_t value )
// 2. it currently has no pins in use.
for(int i=0; i<HWPWM_MODULE_NUM; i++)
{
if (HwPWMx[i]->takeOwnership(_analogToken))
if (HwPWMx[i]->takeOwnership(ANALOG_TOKEN))
{
// apply the cached analog resolution to newly owned instances
HwPWMx[i]->setResolution(_analogResolution);
+7 -4
View File
@@ -21,7 +21,10 @@
#include <Arduino.h>
#include <Servo.h>
static uint32_t _servoToken = 0x76726553; // 'S' 'e' 'r' 'v'
enum
{
SERVO_TOKEN = 0x76726553 // 'S' 'e' 'r' 'v'
};
static servo_t servos[MAX_SERVOS]; // static array of servo structures
uint8_t ServoCount = 0; // the total number of attached servos
@@ -71,7 +74,7 @@ uint8_t Servo::attach(int pin, int min, int max)
// first, use existing HWPWM modules (already owned by Servo)
for ( int i = 0; i < HWPWM_MODULE_NUM; i++ )
{
if ( HwPWMx[i]->isOwner(_servoToken) && HwPWMx[i]->addPin(pin) )
if ( HwPWMx[i]->isOwner(SERVO_TOKEN) && HwPWMx[i]->addPin(pin) )
{
this->pwm = HwPWMx[i];
succeeded = true;
@@ -84,7 +87,7 @@ uint8_t Servo::attach(int pin, int min, int max)
{
for ( int i = 0; i < HWPWM_MODULE_NUM; i++ )
{
if ( HwPWMx[i]->takeOwnership(_servoToken) && HwPWMx[i]->addPin(pin) )
if ( HwPWMx[i]->takeOwnership(SERVO_TOKEN) && HwPWMx[i]->addPin(pin) )
{
this->pwm = HwPWMx[i];
succeeded = true;
@@ -124,7 +127,7 @@ void Servo::detach()
pwm->removePin(pin);
if (pwm->usedChannelCount() == 0) {
pwm->stop(); // disables peripheral so can release ownership
pwm->releaseOwnership(_servoToken);
pwm->releaseOwnership(SERVO_TOKEN);
}
}