Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-esp32
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-esp32
Commits
96c184d2
Unverified
Commit
96c184d2
authored
Nov 09, 2021
by
Me No Dev
Committed by
GitHub
Nov 09, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic analogWrite support based on LEDC (#5861)
parent
da72bc90
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
cores/esp32/esp32-hal-ledc.c
cores/esp32/esp32-hal-ledc.c
+19
-0
cores/esp32/esp32-hal.h
cores/esp32/esp32-hal.h
+2
-0
No files found.
cores/esp32/esp32-hal-ledc.c
View file @
96c184d2
...
...
@@ -17,6 +17,7 @@
#include "freertos/task.h"
#include "freertos/semphr.h"
#include "esp32-hal-matrix.h"
#include "soc/soc_caps.h"
#include "soc/ledc_reg.h"
#include "soc/ledc_struct.h"
#include "driver/periph_ctrl.h"
...
...
@@ -331,3 +332,21 @@ double ledcChangeFrequency(uint8_t chan, double freq, uint8_t bit_num)
double
res_freq
=
_ledcSetupTimerFreq
(
chan
,
freq
,
bit_num
);
return
res_freq
;
}
static
int8_t
pin_to_channel
[
SOC_GPIO_PIN_COUNT
]
=
{
0
};
static
int
cnt_channel
=
SOC_LEDC_CHANNEL_NUM
;
void
analogWrite
(
uint8_t
pin
,
int
value
)
{
// Use ledc hardware for internal pins
if
(
pin
<
SOC_GPIO_PIN_COUNT
)
{
if
(
pin_to_channel
[
pin
]
==
0
)
{
if
(
!
cnt_channel
)
{
log_e
(
"No more analogWrite channels available! You can have maximum %u"
,
SOC_LEDC_CHANNEL_NUM
);
return
;
}
pin_to_channel
[
pin
]
=
cnt_channel
--
;
ledcAttachPin
(
pin
,
cnt_channel
);
ledcSetup
(
cnt_channel
,
1000
,
8
);
}
ledcWrite
(
pin_to_channel
[
pin
]
-
1
,
value
);
}
}
cores/esp32/esp32-hal.h
View file @
96c184d2
...
...
@@ -90,6 +90,8 @@ void yield(void);
#include "esp32-hal-psram.h"
#include "esp32-hal-cpu.h"
void
analogWrite
(
uint8_t
pin
,
int
value
);
//returns chip temperature in Celsius
float
temperatureRead
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment