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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 /******************************************************************************* 16 * NOTICE 17 * The hal is not public api, don't use in application code. 18 * See readme.md in hal/include/hal/readme.md 19 ******************************************************************************/ 20 21 // The HAL layer for SIGMADELTA. 22 // There is no parameter check in the hal layer, so the caller must ensure the correctness of the parameters. 23 24 #pragma once 25 26 #include "soc/sigmadelta_periph.h" 27 #include "hal/sigmadelta_types.h" 28 #include "hal/sigmadelta_ll.h" 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /** 35 * Context that should be maintained by both the driver and the HAL 36 */ 37 38 typedef struct { 39 gpio_sd_dev_t *dev; 40 } sigmadelta_hal_context_t; 41 42 /** 43 * @brief Set Sigma-delta channel duty. 44 * 45 * @param hal Context of the HAL layer 46 * @param channel Sigma-delta channel number 47 * @param duty Sigma-delta duty of one channel, the value ranges from -128 to 127, recommended range is -90 ~ 90. 48 * The waveform is more like a random one in this range. 49 */ 50 #define sigmadelta_hal_set_duty(hal, channel, duty) sigmadelta_ll_set_duty((hal)->dev, channel, duty) 51 52 /** 53 * @brief Set Sigma-delta channel's clock pre-scale value. 54 * 55 * @param hal Context of the HAL layer 56 * @param channel Sigma-delta channel number 57 * @param prescale The divider of source clock, ranges from 0 to 255 58 */ 59 #define sigmadelta_hal_set_prescale(hal, channel, prescale) sigmadelta_ll_set_prescale((hal)->dev, channel, prescale) 60 61 /** 62 * @brief Init the SIGMADELTA hal and set the SIGMADELTA to the default configuration. This function should be called first before other hal layer function is called 63 * 64 * @param hal Context of the HAL layer 65 * @param sigmadelta_num The uart port number, the max port number is (SIGMADELTA_NUM_MAX -1) 66 */ 67 void sigmadelta_hal_init(sigmadelta_hal_context_t *hal, int sigmadelta_num); 68 69 #ifdef __cplusplus 70 } 71 #endif 72