Skip to content

Commit 786ceae

Browse files
committed
change token from const var to enum
1 parent 13a01fe commit 786ceae

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

cores/nRF5/Tone.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static HardwarePWM * const _HwPWM = HwPWMx[2];
4848
// Defined a struct, to simplify validation testing ... also provides context when debugging
4949
class TonePwmConfig {
5050
private:
51-
const uint32_t toneToken = 0x656e6f54; //< 'T' 'o' 'n' 'e'
51+
enum { TONE_TOKEN = 0x656e6f54 }; //< 'T' 'o' 'n' 'e'
5252
uint64_t pulse_count; //< total number of PWM pulses
5353
uint32_t seq0_refresh; //< count of pulses for each SEQ0 iteration
5454
uint32_t seq1_refresh; //< count of pulses for each SEQ1 iteration
@@ -198,7 +198,7 @@ void noTone(uint8_t pin)
198198
}
199199

200200
bool TonePwmConfig::ensurePwmPeripheralOwnership(void) {
201-
if (!_HwPWM->isOwner(TonePwmConfig::toneToken) && !_HwPWM->takeOwnership(TonePwmConfig::toneToken)) {
201+
if (!_HwPWM->isOwner(TonePwmConfig::TONE_TOKEN) && !_HwPWM->takeOwnership(TonePwmConfig::TONE_TOKEN)) {
202202
LOG_LV1("Tone", "unable to allocate PWM2 to Tone");
203203
return false;
204204
}
@@ -364,7 +364,7 @@ bool TonePwmConfig::startPlayback(void) {
364364

365365
bool TonePwmConfig::stopPlayback(bool releaseOwnership) {
366366

367-
if (!_HwPWM->isOwner(TonePwmConfig::toneToken)) {
367+
if (!_HwPWM->isOwner(TonePwmConfig::TONE_TOKEN)) {
368368
LOG_LV2("Tone", "Attempt to set noTone when not the owner of the PWM peripheral. Ignoring call....");
369369
return false;
370370
}
@@ -376,7 +376,7 @@ bool TonePwmConfig::stopPlayback(bool releaseOwnership) {
376376
}
377377

378378
if (releaseOwnership) {
379-
_HwPWM->releaseOwnership(TonePwmConfig::toneToken);
379+
_HwPWM->releaseOwnership(TonePwmConfig::TONE_TOKEN);
380380
}
381381

382382
return true;

cores/nRF5/wiring_analog.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@
4646
extern "C"
4747
{
4848

49+
enum
50+
{
51+
ANALOG_TOKEN = 0x676f6c41 // 'A' 'l' 'o' 'g'
52+
};
53+
4954
static uint8_t _analogResolution = 8; // default is 256 levels
50-
static uint32_t _analogToken = 0x676f6c41; // 'A' 'l' 'o' 'g'
5155

5256
/**
5357
* This will apply to all PWM Hardware currently used by analogWrite(),
@@ -59,7 +63,7 @@ void analogWriteResolution( uint8_t res )
5963
_analogResolution = res;
6064
for (int i = 0; i<HWPWM_MODULE_NUM; i++)
6165
{
62-
if (HwPWMx[i]->isOwner(_analogToken))
66+
if (HwPWMx[i]->isOwner(ANALOG_TOKEN))
6367
{
6468
HwPWMx[i]->setResolution(res);
6569
}
@@ -78,7 +82,7 @@ void analogWrite( uint32_t pin, uint32_t value )
7882
// first, handle the case where the pin is already in use by analogWrite()
7983
for(int i=0; i<HWPWM_MODULE_NUM; i++)
8084
{
81-
if (HwPWMx[i]->isOwner(_analogToken))
85+
if (HwPWMx[i]->isOwner(ANALOG_TOKEN))
8286
{
8387
int const ch = HwPWMx[i]->pin2channel(pin);
8488
if (ch >= 0)
@@ -92,7 +96,7 @@ void analogWrite( uint32_t pin, uint32_t value )
9296
// Next, handle the case where can add the pin to a PWM instance already owned by analogWrite()
9397
for(int i=0; i<HWPWM_MODULE_NUM; i++)
9498
{
95-
if ( HwPWMx[i]->isOwner(_analogToken) && HwPWMx[i]->addPin(pin) )
99+
if ( HwPWMx[i]->isOwner(ANALOG_TOKEN) && HwPWMx[i]->addPin(pin) )
96100
{
97101
// successfully added the pin, so write the value also
98102
HwPWMx[i]->writePin(pin, value);
@@ -106,7 +110,7 @@ void analogWrite( uint32_t pin, uint32_t value )
106110
// 2. it currently has no pins in use.
107111
for(int i=0; i<HWPWM_MODULE_NUM; i++)
108112
{
109-
if (HwPWMx[i]->takeOwnership(_analogToken))
113+
if (HwPWMx[i]->takeOwnership(ANALOG_TOKEN))
110114
{
111115
// apply the cached analog resolution to newly owned instances
112116
HwPWMx[i]->setResolution(_analogResolution);

libraries/Servo/src/nrf52/Servo.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
#include <Arduino.h>
2222
#include <Servo.h>
2323

24-
static uint32_t _servoToken = 0x76726553; // 'S' 'e' 'r' 'v'
24+
enum
25+
{
26+
SERVO_TOKEN = 0x76726553 // 'S' 'e' 'r' 'v'
27+
};
2528

2629
static servo_t servos[MAX_SERVOS]; // static array of servo structures
2730
uint8_t ServoCount = 0; // the total number of attached servos
@@ -71,7 +74,7 @@ uint8_t Servo::attach(int pin, int min, int max)
7174
// first, use existing HWPWM modules (already owned by Servo)
7275
for ( int i = 0; i < HWPWM_MODULE_NUM; i++ )
7376
{
74-
if ( HwPWMx[i]->isOwner(_servoToken) && HwPWMx[i]->addPin(pin) )
77+
if ( HwPWMx[i]->isOwner(SERVO_TOKEN) && HwPWMx[i]->addPin(pin) )
7578
{
7679
this->pwm = HwPWMx[i];
7780
succeeded = true;
@@ -84,7 +87,7 @@ uint8_t Servo::attach(int pin, int min, int max)
8487
{
8588
for ( int i = 0; i < HWPWM_MODULE_NUM; i++ )
8689
{
87-
if ( HwPWMx[i]->takeOwnership(_servoToken) && HwPWMx[i]->addPin(pin) )
90+
if ( HwPWMx[i]->takeOwnership(SERVO_TOKEN) && HwPWMx[i]->addPin(pin) )
8891
{
8992
this->pwm = HwPWMx[i];
9093
succeeded = true;
@@ -124,7 +127,7 @@ void Servo::detach()
124127
pwm->removePin(pin);
125128
if (pwm->usedChannelCount() == 0) {
126129
pwm->stop(); // disables peripheral so can release ownership
127-
pwm->releaseOwnership(_servoToken);
130+
pwm->releaseOwnership(SERVO_TOKEN);
128131
}
129132
}
130133

0 commit comments

Comments
 (0)