Files
zh_ac_dimmer/include/zh_ac_dimmer.h
2025-10-14 15:58:53 +03:00

85 lines
2.3 KiB
C

#pragma once
// #include "stdio.h"
// #include "avr_err.h"
// #include "avr_port.h"
// #include "stdbool.h"
// #include "avr/interrupt.h"
// #include "util/delay.h"
#include "esp_log.h"
#include "driver/gpio.h"
// #define ZH_TRIAC_TIME 1 // Triac turn-on time (in microseconds). Depends on the type of triac. Tested on BTA16-600.
#define ZH_AC_DIMMER_INIT_CONFIG_DEFAULT() \
{ \
.ac_dimmer_frequency = ZH_50HZ, \
.zero_cross_gpio = GPIO_NUM_MAX, \
.triac_gpio = GPIO_NUM_MAX, \
.triac_time = 1}
#ifdef __cplusplus
extern "C"
{
#endif
typedef enum
{
ZH_50HZ = 1,
ZH_60HZ = 2,
ZH_400HZ = 3
} zh_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 triac_gpio; // Triac GPIO.
uint8_t triac_time; // Triac turn-on time (in microseconds). Depends on the type of triac. Tested on BTA16-600.
} zh_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_ac_dimmer_init_config_t structure with default values.
*
* @code zh_ac_dimmer_init_config_t config = ZH_AC_DIMMER_INIT_CONFIG_DEFAULT @endcode
*
* @return ESP_OK if success or an error code otherwise.
*/
esp_err_t zh_ac_dimmer_init(const zh_ac_dimmer_init_config_t *config);
/**
* @brief Start AC dimmer.
*
* @return ESP_OK if success or an error code otherwise.
*/
esp_err_t zh_ac_dimmer_start(void);
/**
* @brief Stop AC dimmer.
*
* @return ESP_OK if success or an error code otherwise.
*/
esp_err_t zh_ac_dimmer_stop(void);
/**
* @brief Set AC dimmer dimming value.
*
* @param[in] value Dimming value (0 to 100).
*
* @return ESP_OK if success or an error code otherwise.
*/
esp_err_t zh_ac_dimmer_set(uint8_t value);
// /**
// * @brief AC dimmer ISR handler.
// */
// void zh_ac_dimmer_isr_handler(void);
#ifdef __cplusplus
}
#endif