1 /** 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 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 * Description: Provides pwm port \n 16 * 17 * History: \n 18 * 2022-09-16, Create file. \n 19 */ 20 21 #ifndef PWM_PORTING_H 22 #define PWM_PORTING_H 23 24 #include <stdint.h> 25 #include <stdbool.h> 26 #include "pwm.h" 27 28 29 #ifdef __cplusplus 30 #if __cplusplus 31 extern "C" { 32 #endif /* __cplusplus */ 33 #endif /* __cplusplus */ 34 35 /** 36 * @defgroup drivers_port_pwm PWM 37 * @ingroup drivers_port 38 * @{ 39 */ 40 uintptr_t pwm_porting_base_addr_get(void); 41 42 43 #define PWM_MAX_NUMBER 6 /* < Max number of PWM available */ 44 45 /** 46 * @brief PWM v150 channel ID. 47 */ 48 typedef enum { 49 PWM_0, /* < PWM Peripheral 0. */ 50 PWM_1, /* < PWM Peripheral 1. */ 51 PWM_2, /* < PWM Peripheral 2. */ 52 PWM_3, /* < PWM Peripheral 3. */ 53 PWM_4, /* < PWM Peripheral 4. */ 54 PWM_5, /* < PWM Peripheral 5. */ 55 PWM_6, /* < PWM Peripheral 6. */ 56 PWM_7, /* < PWM Peripheral 7. */ 57 PWM_8, /* < PWM Peripheral 8. */ 58 PWM_9, /* < PWM Peripheral 9. */ 59 PWM_10, /* < PWM Peripheral 10. */ 60 PWM_11, /* < PWM Peripheral 11. */ 61 PWM_12, /* < PWM Peripheral 12. */ 62 PWM_13, /* < PWM Peripheral 13. */ 63 PWM_14, /* < PWM Peripheral 14. */ 64 PWM_15, /* < PWM Peripheral 15. */ 65 PWM_NONE = PWM_MAX_NUMBER 66 } pwm_channel_t; 67 68 /** 69 * @brief PWM v150 group ID. 70 */ 71 typedef enum { 72 PWM_GROUP_0, 73 PWM_GROUP_1, 74 PWM_GROUP_2, 75 PWM_GROUP_3, 76 PWM_GROUP_4, 77 PWM_GROUP_5, 78 PWM_GROUP_6, 79 PWM_GROUP_7, 80 PWM_GROUP_8, 81 PWM_GROUP_9, 82 PWM_GROUP_10, 83 PWM_GROUP_11, 84 PWM_GROUP_12, 85 PWM_GROUP_13, 86 PWM_GROUP_14, 87 PWM_GROUP_15 88 } pwm_v151_group_t; 89 90 /** 91 * @brief Get the base address of a specified PWM. 92 * @return The base address of specified PWM. 93 */ 94 uintptr_t pwm_porting_base_addr_get(void); 95 96 /** 97 * @brief Register hal funcs objects into hal_pwm module. 98 */ 99 void pwm_port_register_hal_funcs(void); 100 101 /** 102 * @brief Unregister hal funcs objects from hal_pwm module. 103 */ 104 void pwm_port_unregister_hal_funcs(void); 105 106 /** 107 * @brief Register the interrupt of pwm. 108 * @param [in] channel PWM device 109 */ 110 void pwm_port_register_irq(pwm_channel_t channel); 111 112 /** 113 * @brief Unregister the interrupt of pwm. 114 * @param [in] channel PWM device 115 */ 116 void pwm_port_unregister_irq(pwm_channel_t channel); 117 118 /** 119 * @brief Set the divider number of the peripheral device clock. 120 * @param [in] on Enable or disable. 121 */ 122 void pwm_port_clock_enable(bool on); 123 124 /** 125 * @brief Lock of pwm interrupt. 126 * @param [in] channel The pwm channel. 127 */ 128 void pwm_irq_lock(uint8_t channel); 129 130 /** 131 * @brief Unlock of pwm interrupt. 132 * @param [in] channel The pwm channel. 133 */ 134 void pwm_irq_unlock(uint8_t channel); 135 136 /** 137 * @brief Get pwm clock value. 138 * @param [in] channel PWM device. 139 */ 140 uint32_t pwm_port_get_clock_value(pwm_channel_t channel); 141 142 errcode_t pwm_port_param_check(const pwm_config_t *cfg); 143 144 /** 145 * @} 146 */ 147 148 #ifdef __cplusplus 149 #if __cplusplus 150 } 151 #endif /* __cplusplus */ 152 #endif /* __cplusplus */ 153 154 #endif