@@ -45,20 +45,150 @@ typedef struct {
4545#endif
4646} ledc_channel_handle_t ;
4747
48- //channel 0-15 resolution 1-16bits freq limits depend on resolution
49- bool ledcAttach (uint8_t pin , uint32_t freq , uint8_t resolution );
50- bool ledcAttachChannel (uint8_t pin , uint32_t freq , uint8_t resolution , uint8_t channel );
51- bool ledcWrite (uint8_t pin , uint32_t duty );
52- uint32_t ledcWriteTone (uint8_t pin , uint32_t freq );
53- uint32_t ledcWriteNote (uint8_t pin , note_t note , uint8_t octave );
54- uint32_t ledcRead (uint8_t pin );
55- uint32_t ledcReadFreq (uint8_t pin );
56- bool ledcDetach (uint8_t pin );
57- uint32_t ledcChangeFrequency (uint8_t pin , uint32_t freq , uint8_t resolution );
48+ /**
49+ * @brief Attach a pin to the LEDC driver, with a given frequency and resolution.
50+ * Channel is automatically assigned.
51+ *
52+ * @param pin GPIO pin
53+ * @param freq frequency of PWM signal
54+ * @param resolution resolution for LEDC pin
55+ *
56+ * @return true if configuration is successful and pin was successfully attached, false otherwise.
57+ */
58+ bool ledcAttach (uint8_t pin , uint32_t freq , uint8_t resolution );
59+
60+ /**
61+ * @brief Attach a pin to the LEDC driver, with a given frequency, resolution and channel.
62+ *
63+ * @param pin GPIO pin
64+ * @param freq frequency of PWM signal
65+ * @param resolution resolution for LEDC pin
66+ * @param channel LEDC channel to attach to
67+ *
68+ * @return true if configuration is successful and pin was successfully attached, false otherwise.
69+ */
70+ bool ledcAttachChannel (uint8_t pin , uint32_t freq , uint8_t resolution , uint8_t channel );
71+
72+ /**
73+ * @brief Set the duty cycle of a given pin.
74+ *
75+ * @param pin GPIO pin
76+ * @param duty duty cycle to set
77+ *
78+ * @return true if duty cycle was successfully set, false otherwise.
79+ */
80+ bool ledcWrite (uint8_t pin , uint32_t duty );
81+
82+ /**
83+ * @brief Sets the duty to 50 % PWM tone on selected frequency.
84+ *
85+ * @param pin GPIO pin
86+ * @param freq select frequency of pwm signal. If frequency is 0, duty will be set to 0.
87+ *
88+ * @return frequency if tone was successfully set.
89+ * If ``0`` is returned, error occurs and LEDC pin was not configured.
90+ */
91+ uint32_t ledcWriteTone (uint8_t pin , uint32_t freq );
92+
93+ /**
94+ * @brief Sets the LEDC pin to specific note.
95+ *
96+ * @param pin GPIO pin
97+ * @param note select note to be set (NOTE_C, NOTE_Cs, NOTE_D, NOTE_Eb, NOTE_E, NOTE_F, NOTE_Fs, NOTE_G, NOTE_Gs, NOTE_A, NOTE_Bb, NOTE_B).
98+ * @param octave select octave for note.
99+ *
100+ * @return frequency if note was successfully set.
101+ * If ``0`` is returned, error occurs and LEDC pin was not configured.
102+ */
103+ uint32_t ledcWriteNote (uint8_t pin , note_t note , uint8_t octave );
104+
105+ /**
106+ * @brief Read the duty cycle of a given LEDC pin.
107+ *
108+ * @param pin GPIO pin
109+ *
110+ * @return duty cycle of selected LEDC pin.
111+ */
112+ uint32_t ledcRead (uint8_t pin );
113+
114+ /**
115+ * @brief Read the frequency of a given LEDC pin.
116+ *
117+ * @param pin GPIO pin
118+ *
119+ * @return frequency of selected LEDC pin.
120+ */
121+ uint32_t ledcReadFreq (uint8_t pin );
122+
123+ /**
124+ * @brief Detach a pin from the LEDC driver.
125+ *
126+ * @param pin GPIO pin
127+ *
128+ * @return true if pin was successfully detached, false otherwise.
129+ */
130+ bool ledcDetach (uint8_t pin );
131+
132+ /**
133+ * @brief Change the frequency and resolution of a given LEDC pin.
134+ *
135+ * @param pin GPIO pin
136+ * @param freq frequency of PWM signal
137+ * @param resolution resolution for LEDC pin
138+ *
139+ * @return frequency configured for the LEDC channel.
140+ * If ``0`` is returned, error occurs and LEDC pin was not configured.
141+ */
142+ uint32_t ledcChangeFrequency (uint8_t pin , uint32_t freq , uint8_t resolution );
143+
144+ /**
145+ * @brief Sets inverting of the output signal for a given LEDC pin.
146+ *
147+ * @param pin GPIO pin
148+ * @param out_invert select, if output should be inverted (true = inverting output).
149+ *
150+ * @return true if output inverting was successfully set, false otherwise.
151+ */
152+ bool ledcOutputInvert (uint8_t pin , bool out_invert );
58153
59154//Fade functions
155+ /**
156+ * @brief Setup and start a fade on a given LEDC pin.
157+ *
158+ * @param pin GPIO pin
159+ * @param start_duty initial duty cycle of the fade
160+ * @param target_duty target duty cycle of the fade
161+ * @param max_fade_time_ms maximum fade time in milliseconds
162+ *
163+ * @return true if fade was successfully set and started, false otherwise.
164+ */
60165bool ledcFade (uint8_t pin , uint32_t start_duty , uint32_t target_duty , int max_fade_time_ms );
166+
167+ /**
168+ * @brief Setup and start a fade on a given LEDC pin with a callback function.
169+ *
170+ * @param pin GPIO pin
171+ * @param start_duty initial duty cycle of the fade
172+ * @param target_duty target duty cycle of the fade
173+ * @param max_fade_time_ms maximum fade time in milliseconds
174+ * @param userFunc callback function to be called after fade is finished
175+ *
176+ * @return true if fade was successfully set and started, false otherwise.
177+ */
61178bool ledcFadeWithInterrupt (uint8_t pin , uint32_t start_duty , uint32_t target_duty , int max_fade_time_ms , void (* userFunc )(void ));
179+
180+ /**
181+ * @brief Setup and start a fade on a given LEDC pin with a callback function and argument.
182+ *
183+ * @param pin GPIO pin
184+ * @param start_duty initial duty cycle of the fade
185+ * @param target_duty target duty cycle of the fade
186+ * @param max_fade_time_ms maximum fade time in milliseconds
187+ * @param userFunc callback function to be called after fade is finished
188+ * @param arg argument to be passed to the callback function
189+ *
190+ * @return true if fade was successfully set and started, false otherwise.
191+ */
62192bool ledcFadeWithInterruptArg (uint8_t pin , uint32_t start_duty , uint32_t target_duty , int max_fade_time_ms , void (* userFunc )(void * ), void * arg );
63193
64194#ifdef __cplusplus
0 commit comments