This commit is contained in:
2025-12-31 13:08:39 +03:00
parent 40163ad64b
commit c16dcc3a3c
8 changed files with 433 additions and 39 deletions

85
include/zh_mcp23s17.h Normal file → Executable file
View File

@@ -24,7 +24,6 @@
{ \
.task_priority = 1, \
.stack_size = configMINIMAL_STACK_SIZE, \
.expander_number = 0, \
.gpa0_gpio_work_mode = ZH_MCP23S17_GPIO_OUTPUT, \
.gpa1_gpio_work_mode = ZH_MCP23S17_GPIO_OUTPUT, \
.gpa2_gpio_work_mode = ZH_MCP23S17_GPIO_OUTPUT, \
@@ -41,6 +40,7 @@
.gpb5_gpio_work_mode = ZH_MCP23S17_GPIO_OUTPUT, \
.gpb6_gpio_work_mode = ZH_MCP23S17_GPIO_OUTPUT, \
.gpb7_gpio_work_mode = ZH_MCP23S17_GPIO_OUTPUT, \
.cs_gpio = GPIO_NUM_MAX, \
.interrupt_gpio = GPIO_NUM_MAX}
#ifdef __cplusplus
@@ -79,33 +79,40 @@ extern "C"
*/
typedef struct
{
uint8_t task_priority; /*!< Task priority for the MCP23S17 expander isr processing. @note Minimum value is 1. */
uint16_t stack_size; /*!< Stack size for task for the MCP23S17 expander isr processing processing. @note The minimum size is configMINIMAL_STACK_SIZE. */
uint8_t expander_number; /*!< Unique expander number. */
uint8_t cs_gpio; /*!< Unique CS GPIO. */
bool p0_gpio_work_mode; /*!< Expander GPIO PO work mode. */
bool p1_gpio_work_mode; /*!< Expander GPIO P1 work mode. */
bool p2_gpio_work_mode; /*!< Expander GPIO P2 work mode. */
bool p3_gpio_work_mode; /*!< Expander GPIO P3 work mode. */
bool p4_gpio_work_mode; /*!< Expander GPIO P4 work mode. */
bool p5_gpio_work_mode; /*!< Expander GPIO P5 work mode. */
bool p6_gpio_work_mode; /*!< Expander GPIO P6 work mode. */
bool p7_gpio_work_mode; /*!< Expander GPIO P7 work mode. */
uint8_t interrupt_gpio; /*!< Interrupt GPIO. @attention Must be same for all MCP23S17 expanders. */
spi_device_handle_t spi_handle; /*!< Unique SPI bus handle. @attention Must be same for all MCP23S17 expanders. */
uint8_t task_priority; /*!< Task priority for the MCP23S17 expander isr processing. @note Minimum value is 1. */
uint16_t stack_size; /*!< Stack size for task for the MCP23S17 expander isr processing processing. @note The minimum size is configMINIMAL_STACK_SIZE. */
uint8_t cs_gpio; /*!< CS GPIO. */
bool gpa0_gpio_work_mode; /*!< Expander GPIO GPAO work mode. */
bool gpa1_gpio_work_mode; /*!< Expander GPIO GPA1 work mode. */
bool gpa2_gpio_work_mode; /*!< Expander GPIO GPA2 work mode. */
bool gpa3_gpio_work_mode; /*!< Expander GPIO GPA3 work mode. */
bool gpa4_gpio_work_mode; /*!< Expander GPIO GPA4 work mode. */
bool gpa5_gpio_work_mode; /*!< Expander GPIO GPA5 work mode. */
bool gpa6_gpio_work_mode; /*!< Expander GPIO GPA6 work mode. */
bool gpa7_gpio_work_mode; /*!< Expander GPIO GPA7 work mode. */
bool gpb0_gpio_work_mode; /*!< Expander GPIO GPBO work mode. */
bool gpb1_gpio_work_mode; /*!< Expander GPIO GPB1 work mode. */
bool gpb2_gpio_work_mode; /*!< Expander GPIO GPB2 work mode. */
bool gpb3_gpio_work_mode; /*!< Expander GPIO GPB3 work mode. */
bool gpb4_gpio_work_mode; /*!< Expander GPIO GPB4 work mode. */
bool gpb5_gpio_work_mode; /*!< Expander GPIO GPB5 work mode. */
bool gpb6_gpio_work_mode; /*!< Expander GPIO GPB6 work mode. */
bool gpb7_gpio_work_mode; /*!< Expander GPIO GPB7 work mode. */
uint8_t interrupt_gpio; /*!< Interrupt GPIO. @attention Must be same for all MCP23S17 expanders. */
uint8_t spi_host; /*!< SPI host. @attention Must be same for all MCP23S17 expanders. */
} zh_mcp23s17_init_config_t;
/**
* @brief PCF8574 expander handle.
* @brief MCP23S17 expander handle.
*/
typedef struct
{
// uint8_t i2c_address; /*!< Expander I2C address. */
uint8_t gpio_work_mode; /*!< Expander GPIO's work mode. */
uint8_t gpio_status; /*!< Expander GPIO's status. */
bool is_initialized; /*!< Expander initialization flag. */
// i2c_master_dev_handle_t dev_handle; /*!< Unique I2C device handle. */
void *system; /*!< System pointer for use in another components. */
uint8_t cs_gpio; /*!< CS GPIO. */
uint16_t gpio_work_mode; /*!< Expander GPIO's work mode. */
uint16_t gpio_status; /*!< Expander GPIO's status. */
bool is_initialized; /*!< Expander initialization flag. */
spi_device_handle_t spi_handle; /*!< Unique SPI device handle. */
void *system; /*!< System pointer for use in another components. */
} zh_mcp23s17_handle_t;
/**
@@ -125,30 +132,30 @@ extern "C"
/**
* @brief Structure for sending data to the event handler when cause an interrupt.
*
* @note Should be used with ZH_PCF8574 event base.
* @note Should be used with ZH_MCP23S17 event base.
*/
typedef struct
{
// uint8_t i2c_address; /*!< The i2c address of PCF8574 expander that caused the interrupt. */
uint8_t cs_gpio; /*!< The CS GPIO of MCP23S17 expander that caused the interrupt. */
uint8_t gpio_number; /*!< The GPIO that caused the interrupt. */
bool gpio_level; /*!< The GPIO level that caused the interrupt. */
} zh_mcp23s17_event_on_isr_t;
// /**
// * @brief Initialize PCF8574 expander.
// *
// * @param[in] config Pointer to PCF8574 initialized configuration structure. Can point to a temporary variable.
// * @param[out] handle Pointer to unique PCF8574 handle.
// *
// * @attention I2C driver must be initialized first.
// *
// * @note Before initialize the expander recommend initialize zh_pcf8574_init_config_t structure with default values.
// *
// * @code zh_pcf8574_init_config_t config = ZH_PCF8574_INIT_CONFIG_DEFAULT() @endcode
// *
// * @return ESP_OK if success or an error code otherwise.
// */
// esp_err_t zh_pcf8574_init(const zh_mcp23s17_init_config_t *config, zh_pcf8574_handle_t *handle);
/**
* @brief Initialize MCP23S17 expander.
*
* @param[in] config Pointer to MCP23S17 initialized configuration structure. Can point to a temporary variable.
* @param[out] handle Pointer to unique MCP23S17 handle.
*
* @attention SPI driver must be initialized first.
*
* @note Before initialize the expander recommend initialize zh_mcp23s17_init_config_t structure with default values.
*
* @code zh_mcp23s17_init_config_t config = ZH_MCP23S17_INIT_CONFIG_DEFAULT() @endcode
*
* @return ESP_OK if success or an error code otherwise.
*/
esp_err_t zh_mcp23s17_init(const zh_mcp23s17_init_config_t *config, zh_mcp23s17_handle_t *handle);
// /**
// * @brief Deinitialize PCF8574 expander.