1 // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 /*******************************************************************************
15 * NOTICE
16 * The hal is not public api, don't use in application code.
17 * See readme.md in hal/include/hal/readme.md
18 ******************************************************************************/
19
20 // The LL layer for ESP32 SIGMADELTA register operations
21
22 #pragma once
23
24 #include <stdbool.h>
25 #include "soc/sigmadelta_periph.h"
26 #include "hal/sigmadelta_types.h"
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 // Get SIGMADELTA hardware instance with giving sigmadelta num
33 #define SIGMADELTA_LL_GET_HW(num) (((num) == 0) ? (&SIGMADELTA) : NULL)
34
35 /**
36 * @brief Set Sigma-delta enable
37 *
38 * @param hw Peripheral SIGMADELTA hardware instance address.
39 * @param en Sigma-delta enable value
40 */
sigmadelta_ll_set_en(gpio_sd_dev_t * hw,bool en)41 static inline void sigmadelta_ll_set_en(gpio_sd_dev_t *hw, bool en)
42 {
43 // The clk enable register does not exist on ESP32.
44 }
45
46 /**
47 * @brief Set Sigma-delta channel duty.
48 *
49 * @param hw Peripheral SIGMADELTA hardware instance address.
50 * @param channel Sigma-delta channel number
51 * @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90.
52 * The waveform is more like a random one in this range.
53 */
sigmadelta_ll_set_duty(gpio_sd_dev_t * hw,sigmadelta_channel_t channel,int8_t duty)54 static inline void sigmadelta_ll_set_duty(gpio_sd_dev_t *hw, sigmadelta_channel_t channel, int8_t duty)
55 {
56 hw->channel[channel].duty = duty;
57 }
58
59 /**
60 * @brief Set Sigma-delta channel's clock pre-scale value.
61 *
62 * @param hw Peripheral SIGMADELTA hardware instance address.
63 * @param channel Sigma-delta channel number
64 * @param val The divider of source clock, ranges from 0 to 255
65 */
sigmadelta_ll_set_prescale(gpio_sd_dev_t * hw,sigmadelta_channel_t channel,uint8_t prescale)66 static inline void sigmadelta_ll_set_prescale(gpio_sd_dev_t *hw, sigmadelta_channel_t channel, uint8_t prescale)
67 {
68 hw->channel[channel].prescale = prescale;
69 }
70
71 #ifdef __cplusplus
72 }
73 #endif
74