wip:
This commit is contained in:
@@ -1,62 +1,76 @@
|
||||
#pragma once
|
||||
|
||||
// #include "FreeRTOS.h"
|
||||
// #include "semphr.h"
|
||||
#include "stdio.h"
|
||||
#include "avr_err.h"
|
||||
#include "avr_port.h"
|
||||
#include "stdbool.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "avr/pgmspace.h"
|
||||
// #include "avr/pgmspace.h"
|
||||
|
||||
#define ZH_AVR_AC_DIMMER_INIT_CONFIG_DEFAULT() \
|
||||
{ \
|
||||
.task_priority = configMAX_PRIORITIES, \
|
||||
.stack_size = 124, \
|
||||
.queue_size = 1, \
|
||||
.a_gpio_number = 0, \
|
||||
.b_gpio_number = 0, \
|
||||
.pullup = false, \
|
||||
.encoder_min_value = -100, \
|
||||
.encoder_max_value = 100, \
|
||||
.encoder_step = 1, \
|
||||
.encoder_number = 0}
|
||||
.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,
|
||||
ZH_400HZ
|
||||
} zh_avr_ac_dimmer_frequency_t;
|
||||
|
||||
typedef struct // Structure for initial initialization of AC dimmer.
|
||||
{
|
||||
uint8_t task_priority; // Task priority for the PCF8574 expander isr processing. @note It is not recommended to set a value less than configMAX_PRIORITIES.
|
||||
uint8_t stack_size; // Stack size for task for the PCF8574 expander isr processing processing. @note The minimum size is 124 byte.
|
||||
uint8_t i2c_address; // Expander I2C address.
|
||||
bool p0_gpio_work_mode; // Expander GPIO PO work mode. True for input, false for output.
|
||||
bool p1_gpio_work_mode; // Expander GPIO P1 work mode. True for input, false for output.
|
||||
bool p2_gpio_work_mode; // Expander GPIO P2 work mode. True for input, false for output.
|
||||
bool p3_gpio_work_mode; // Expander GPIO P3 work mode. True for input, false for output.
|
||||
bool p4_gpio_work_mode; // Expander GPIO P4 work mode. True for input, false for output.
|
||||
bool p5_gpio_work_mode; // Expander GPIO P5 work mode. True for input, false for output.
|
||||
bool p6_gpio_work_mode; // Expander GPIO P6 work mode. True for input, false for output.
|
||||
bool p7_gpio_work_mode; // Expander GPIO P7 work mode. True for input, false for output.
|
||||
uint8_t interrupt_gpio; // Interrupt GPIO. @attention Must be same for all PCF8574 expanders.
|
||||
uint8_t interrupt_port; // Interrupt port.
|
||||
} zh_avr_pcf8574_init_config_t;
|
||||
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 PCF8574 expander.
|
||||
* @brief Initialize AC dimmer.
|
||||
*
|
||||
* @param[in] config Pointer to PCF8574 initialized configuration structure. Can point to a temporary variable.
|
||||
* @param[out] handle Pointer to unique PCF8574 handle.
|
||||
* @param[in] config Pointer to AC dimmer initialized configuration structure. Can point to a temporary variable.
|
||||
*
|
||||
* @attention I2C driver must be initialized first.
|
||||
* @note Before initialize the expander recommend initialize zh_avr_ac_dimmer_init_config_t structure with default values.
|
||||
*
|
||||
* @note Before initialize the expander recommend initialize zh_avr_pcf8574_init_config_t structure with default values.
|
||||
*
|
||||
* @code zh_avr_pcf8574_init_config_t config = ZH_AVR_PCF8574_INIT_CONFIG_DEFAULT() @endcode
|
||||
* @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_pcf8574_init(const zh_avr_pcf8574_init_config_t *config, zh_avr_pcf8574_handle_t *handle);
|
||||
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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Reference in New Issue
Block a user