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
e6dc9db7
Unverified
Commit
e6dc9db7
authored
Aug 28, 2024
by
Me No Dev
Committed by
GitHub
Aug 28, 2024
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into release/v3.1.x
parents
0b842442
dd4a7d6c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
63 additions
and
3 deletions
+63
-3
cores/esp32/esp32-hal-ledc.c
cores/esp32/esp32-hal-ledc.c
+18
-3
cores/esp32/esp32-hal-ledc.h
cores/esp32/esp32-hal-ledc.h
+17
-0
docs/en/api/ledc.rst
docs/en/api/ledc.rst
+28
-0
No files found.
cores/esp32/esp32-hal-ledc.c
View file @
e6dc9db7
...
@@ -47,6 +47,21 @@ ledc_periph_t ledc_handle = {0};
...
@@ -47,6 +47,21 @@ ledc_periph_t ledc_handle = {0};
static
bool
fade_initialized
=
false
;
static
bool
fade_initialized
=
false
;
static
ledc_clk_cfg_t
clock_source
=
LEDC_DEFAULT_CLK
;
ledc_clk_cfg_t
ledcGetClockSource
(
void
)
{
return
clock_source
;
}
bool
ledcSetClockSource
(
ledc_clk_cfg_t
source
)
{
if
(
ledc_handle
.
used_channels
)
{
log_e
(
"Cannot change LEDC clock source! LEDC channels in use."
);
return
false
;
}
clock_source
=
source
;
return
true
;
}
static
bool
ledcDetachBus
(
void
*
bus
)
{
static
bool
ledcDetachBus
(
void
*
bus
)
{
ledc_channel_handle_t
*
handle
=
(
ledc_channel_handle_t
*
)
bus
;
ledc_channel_handle_t
*
handle
=
(
ledc_channel_handle_t
*
)
bus
;
bool
channel_found
=
false
;
bool
channel_found
=
false
;
...
@@ -111,7 +126,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
...
@@ -111,7 +126,7 @@ bool ledcAttachChannel(uint8_t pin, uint32_t freq, uint8_t resolution, uint8_t c
return
false
;
return
false
;
}
}
}
else
{
}
else
{
ledc_timer_config_t
ledc_timer
=
{.
speed_mode
=
group
,
.
timer_num
=
timer
,
.
duty_resolution
=
resolution
,
.
freq_hz
=
freq
,
.
clk_cfg
=
LEDC_DEFAULT_CLK
};
ledc_timer_config_t
ledc_timer
=
{.
speed_mode
=
group
,
.
timer_num
=
timer
,
.
duty_resolution
=
resolution
,
.
freq_hz
=
freq
,
.
clk_cfg
=
clock_source
};
if
(
ledc_timer_config
(
&
ledc_timer
)
!=
ESP_OK
)
{
if
(
ledc_timer_config
(
&
ledc_timer
)
!=
ESP_OK
)
{
log_e
(
"ledc setup failed!"
);
log_e
(
"ledc setup failed!"
);
return
false
;
return
false
;
...
@@ -241,7 +256,7 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) {
...
@@ -241,7 +256,7 @@ uint32_t ledcWriteTone(uint8_t pin, uint32_t freq) {
uint8_t
group
=
(
bus
->
channel
/
8
),
timer
=
((
bus
->
channel
/
2
)
%
4
);
uint8_t
group
=
(
bus
->
channel
/
8
),
timer
=
((
bus
->
channel
/
2
)
%
4
);
ledc_timer_config_t
ledc_timer
=
{.
speed_mode
=
group
,
.
timer_num
=
timer
,
.
duty_resolution
=
10
,
.
freq_hz
=
freq
,
.
clk_cfg
=
LEDC_DEFAULT_CLK
};
ledc_timer_config_t
ledc_timer
=
{.
speed_mode
=
group
,
.
timer_num
=
timer
,
.
duty_resolution
=
10
,
.
freq_hz
=
freq
,
.
clk_cfg
=
clock_source
};
if
(
ledc_timer_config
(
&
ledc_timer
)
!=
ESP_OK
)
{
if
(
ledc_timer_config
(
&
ledc_timer
)
!=
ESP_OK
)
{
log_e
(
"ledcWriteTone configuration failed!"
);
log_e
(
"ledcWriteTone configuration failed!"
);
...
@@ -292,7 +307,7 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) {
...
@@ -292,7 +307,7 @@ uint32_t ledcChangeFrequency(uint8_t pin, uint32_t freq, uint8_t resolution) {
}
}
uint8_t
group
=
(
bus
->
channel
/
8
),
timer
=
((
bus
->
channel
/
2
)
%
4
);
uint8_t
group
=
(
bus
->
channel
/
8
),
timer
=
((
bus
->
channel
/
2
)
%
4
);
ledc_timer_config_t
ledc_timer
=
{.
speed_mode
=
group
,
.
timer_num
=
timer
,
.
duty_resolution
=
resolution
,
.
freq_hz
=
freq
,
.
clk_cfg
=
LEDC_DEFAULT_CLK
};
ledc_timer_config_t
ledc_timer
=
{.
speed_mode
=
group
,
.
timer_num
=
timer
,
.
duty_resolution
=
resolution
,
.
freq_hz
=
freq
,
.
clk_cfg
=
clock_source
};
if
(
ledc_timer_config
(
&
ledc_timer
)
!=
ESP_OK
)
{
if
(
ledc_timer_config
(
&
ledc_timer
)
!=
ESP_OK
)
{
log_e
(
"ledcChangeFrequency failed!"
);
log_e
(
"ledcChangeFrequency failed!"
);
...
...
cores/esp32/esp32-hal-ledc.h
View file @
e6dc9db7
...
@@ -26,6 +26,7 @@ extern "C" {
...
@@ -26,6 +26,7 @@ extern "C" {
#include <stdbool.h>
#include <stdbool.h>
#include "freertos/FreeRTOS.h"
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/semphr.h"
#include "hal/ledc_types.h"
typedef
enum
{
typedef
enum
{
NOTE_C
,
NOTE_C
,
...
@@ -57,6 +58,22 @@ typedef struct {
...
@@ -57,6 +58,22 @@ typedef struct {
#endif
#endif
}
ledc_channel_handle_t
;
}
ledc_channel_handle_t
;
/**
* @brief Get the LEDC clock source.
*
* @return LEDC clock source.
*/
ledc_clk_cfg_t
ledcGetClockSource
(
void
);
/**
* @brief Set the LEDC clock source.
*
* @param source LEDC clock source to set.
*
* @return true if LEDC clock source was successfully set, false otherwise.
*/
bool
ledcSetClockSource
(
ledc_clk_cfg_t
source
);
/**
/**
* @brief Attach a pin to the LEDC driver, with a given frequency and resolution.
* @brief Attach a pin to the LEDC driver, with a given frequency and resolution.
* Channel is automatically assigned.
* Channel is automatically assigned.
...
...
docs/en/api/ledc.rst
View file @
e6dc9db7
...
@@ -23,6 +23,34 @@ ESP32-H2 6
...
@@ -23,6 +23,34 @@ ESP32-H2 6
Arduino-ESP32 LEDC API
Arduino-ESP32 LEDC API
----------------------
----------------------
ledcSetCLockSource
******************
This function is used to set the LEDC peripheral clock source. Must be called before any LEDC channel is used.
The default clock source is XTAL clock (``LEDC_USE_XTAL_CLK``) if supported by the SoC, otherwise it is AUTO clock (``LEDC_AUTO_CLK``).
.. code-block:: arduino
bool ledcSetClockSource(ledc_clk_cfg_t source);
* ``source`` select the clock source for LEDC peripheral.
* ``LEDC_APB_CLK`` - APB clock.
* ``LEDC_REF_CLK`` - REF clock.
This function will return ``true`` if setting the clock source is successful, otherwise it will return ``false``.
ledcGetClockSource
******************
This function is used to get the LEDC peripheral clock source.
.. code-block:: arduino
ledc_clk_cfg_t ledcGetClockSource(void);
This function will return the clock source for the LEDC peripheral.
ledcAttach
ledcAttach
**********
**********
...
...
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