Skip to content

Commit e1c9606

Browse files
authored
Changed type of LEDC frequency from double to uint32_t (#6570)
1 parent fb60efd commit e1c9606

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

Diff for: cores/esp32/esp32-hal-ledc.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
uint8_t channels_resolution[LEDC_CHANNELS] = {0};
5656

57-
double ledcSetup(uint8_t chan, double freq, uint8_t bit_num)
57+
uint32_t ledcSetup(uint8_t chan, uint32_t freq, uint8_t bit_num)
5858
{
5959
if(chan >= LEDC_CHANNELS || bit_num > LEDC_MAX_BIT_WIDTH){
6060
log_e("No more LEDC channels available! (maximum %u) or bit width too big (maximum %u)", LEDC_CHANNELS, LEDC_MAX_BIT_WIDTH);
@@ -106,7 +106,7 @@ uint32_t ledcRead(uint8_t chan)
106106
return ledc_get_duty(group,channel);
107107
}
108108

109-
double ledcReadFreq(uint8_t chan)
109+
uint32_t ledcReadFreq(uint8_t chan)
110110
{
111111
if(!ledcRead(chan)){
112112
return 0;
@@ -115,7 +115,7 @@ double ledcReadFreq(uint8_t chan)
115115
return ledc_get_freq(group,timer);
116116
}
117117

118-
double ledcWriteTone(uint8_t chan, double freq)
118+
uint32_t ledcWriteTone(uint8_t chan, uint32_t freq)
119119
{
120120
if(chan >= LEDC_CHANNELS){
121121
return 0;
@@ -142,12 +142,12 @@ double ledcWriteTone(uint8_t chan, double freq)
142142
}
143143
channels_resolution[chan] = 10;
144144

145-
double res_freq = ledc_get_freq(group,timer);
145+
uint32_t res_freq = ledc_get_freq(group,timer);
146146
ledcWrite(chan, 0x1FF);
147147
return res_freq;
148148
}
149149

150-
double ledcWriteNote(uint8_t chan, note_t note, uint8_t octave){
150+
uint32_t ledcWriteNote(uint8_t chan, note_t note, uint8_t octave){
151151
const uint16_t noteFrequencyBase[12] = {
152152
// C C# D Eb E F F# G G# A Bb B
153153
4186, 4435, 4699, 4978, 5274, 5588, 5920, 6272, 6645, 7040, 7459, 7902
@@ -156,7 +156,7 @@ double ledcWriteNote(uint8_t chan, note_t note, uint8_t octave){
156156
if(octave > 8 || note >= NOTE_MAX){
157157
return 0;
158158
}
159-
double noteFreq = (double)noteFrequencyBase[note] / (double)(1 << (8-octave));
159+
uint32_t noteFreq = (uint32_t)noteFrequencyBase[note] / (uint32_t)(1 << (8-octave));
160160
return ledcWriteTone(chan, noteFreq);
161161
}
162162

@@ -184,7 +184,7 @@ void ledcDetachPin(uint8_t pin)
184184
pinMatrixOutDetach(pin, false, false);
185185
}
186186

187-
double ledcChangeFrequency(uint8_t chan, double freq, uint8_t bit_num)
187+
uint32_t ledcChangeFrequency(uint8_t chan, uint32_t freq, uint8_t bit_num)
188188
{
189189
if(chan >= LEDC_CHANNELS || bit_num > LEDC_MAX_BIT_WIDTH){
190190
log_e("LEDC channel not available! (maximum %u) or bit width too big (maximum %u)", LEDC_CHANNELS, LEDC_MAX_BIT_WIDTH);

Diff for: cores/esp32/esp32-hal-ledc.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ typedef enum {
2727
} note_t;
2828

2929
//channel 0-15 resolution 1-16bits freq limits depend on resolution
30-
double ledcSetup(uint8_t channel, double freq, uint8_t resolution_bits);
30+
uint32_t ledcSetup(uint8_t channel, uint32_t freq, uint8_t resolution_bits);
3131
void ledcWrite(uint8_t channel, uint32_t duty);
32-
double ledcWriteTone(uint8_t channel, double freq);
33-
double ledcWriteNote(uint8_t channel, note_t note, uint8_t octave);
32+
uint32_t ledcWriteTone(uint8_t channel, uint32_t freq);
33+
uint32_t ledcWriteNote(uint8_t channel, note_t note, uint8_t octave);
3434
uint32_t ledcRead(uint8_t channel);
35-
double ledcReadFreq(uint8_t channel);
35+
uint32_t ledcReadFreq(uint8_t channel);
3636
void ledcAttachPin(uint8_t pin, uint8_t channel);
3737
void ledcDetachPin(uint8_t pin);
38-
double ledcChangeFrequency(uint8_t channel, double freq, uint8_t resolution_bits);
38+
uint32_t ledcChangeFrequency(uint8_t channel, uint32_t freq, uint8_t resolution_bits);
3939

4040

4141
#ifdef __cplusplus

0 commit comments

Comments
 (0)