feat: initial
This commit is contained in:
		
							
								
								
									
										84
									
								
								include/zh_avr_ac_dimmer.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										84
									
								
								include/zh_avr_ac_dimmer.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,84 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "stdio.h" | ||||
| #include "avr_err.h" | ||||
| #include "avr_port.h" | ||||
| #include "stdbool.h" | ||||
| #include "avr/interrupt.h" | ||||
| #include "util/delay.h" | ||||
|  | ||||
| #define ZH_TRIAC_TIME 2 // Triac turn-on time (in microseconds). Depends on the type of triac. Tested on BTA16-600. | ||||
|  | ||||
| #define ZH_AVR_AC_DIMMER_INIT_CONFIG_DEFAULT() \ | ||||
|     {                                          \ | ||||
|         .ac_dimmer_frequency = ZH_50HZ,        \ | ||||
|         .zero_cross_gpio = 0xFF,               \ | ||||
|         .zero_cross_port = 0,                  \ | ||||
|         .triac_gpio = 0xFF,                    \ | ||||
|         .triac_port = 0} | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| extern "C" | ||||
| { | ||||
| #endif | ||||
|  | ||||
|     typedef enum | ||||
|     { | ||||
|         ZH_50HZ = 1, | ||||
|         ZH_60HZ = 2, | ||||
|         ZH_400HZ = 3 | ||||
|     } zh_avr_ac_dimmer_frequency_t; | ||||
|  | ||||
|     typedef struct // Structure for initial initialization of AC dimmer. | ||||
|     { | ||||
|         uint8_t ac_dimmer_frequency; // AC frequency. | ||||
|         uint8_t zero_cross_gpio;     // Zero cross GPIO. | ||||
|         uint8_t zero_cross_port;     // Zero cross port. | ||||
|         uint8_t triac_gpio;          // Triac GPIO. | ||||
|         uint8_t triac_port;          // Triac port. | ||||
|     } zh_avr_ac_dimmer_init_config_t; | ||||
|  | ||||
|     /** | ||||
|      * @brief Initialize AC dimmer. | ||||
|      * | ||||
|      * @param[in] config Pointer to AC dimmer initialized configuration structure. Can point to a temporary variable. | ||||
|      * | ||||
|      * @note Before initialize the AC dimmer recommend initialize zh_avr_ac_dimmer_init_config_t structure with default values. | ||||
|      * | ||||
|      * @code zh_avr_ac_dimmer_init_config_t config = ZH_AVR_AC_DIMMER_INIT_CONFIG_DEFAULT @endcode | ||||
|      * | ||||
|      * @return AVR_OK if success or an error code otherwise. | ||||
|      */ | ||||
|     avr_err_t zh_avr_ac_dimmer_init(const zh_avr_ac_dimmer_init_config_t *config); | ||||
|  | ||||
|     /** | ||||
|      * @brief Start AC dimmer. | ||||
|      * | ||||
|      * @return AVR_OK if success or an error code otherwise. | ||||
|      */ | ||||
|     avr_err_t zh_avr_ac_dimmer_start(void); | ||||
|  | ||||
|     /** | ||||
|      * @brief Stop AC dimmer. | ||||
|      * | ||||
|      * @return AVR_OK if success or an error code otherwise. | ||||
|      */ | ||||
|     avr_err_t zh_avr_ac_dimmer_stop(void); | ||||
|  | ||||
|     /** | ||||
|      * @brief Set AC dimmer dimming value. | ||||
|      * | ||||
|      * @param[in] value Dimming value (0 to 100). | ||||
|      * | ||||
|      * @return AVR_OK if success or an error code otherwise. | ||||
|      */ | ||||
|     avr_err_t zh_avr_ac_dimmer_set(uint8_t value); | ||||
|  | ||||
|     /** | ||||
|      * @brief AC dimmer ISR handler. | ||||
|      */ | ||||
|     void zh_avr_ac_dimmer_isr_handler(void); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user