Skip to content

Commit

Permalink
Merge branch 'master' into feat-implement-qmp6988
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleRus committed Feb 3, 2024
2 parents e04b261 + d798bd4 commit d9888fe
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ or [GitLab examples](https://gitlab.com/UncleRus/esp-idf-lib/tree/master/example
|--------------------------|----------------------------------------------------------------------------------|---------|--------------------|---------------|
| **mcp23008** | Driver for 8-bit I2C GPIO expander MCP23008 | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
| **mcp23x17** | Driver for I2C/SPI 16 bit GPIO expanders MCP23017/MCP23S17 | BSD-3-Clause | esp32, esp32s2, esp32c3 | yes |
| **pca9557** | Driver for PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
| **pca9557** | Driver for PCA9536/PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
| **pcf8574** | Driver for PCF8574 remote 8-bit I/O expander for I2C-bus | MIT | esp32, esp8266, esp32s2, esp32c3 | yes |
| **pcf8575** | Driver for PCF8575 remote 16-bit I/O expander for I2C-bus | MIT | esp32, esp8266, esp32s2, esp32c3 | yes |
| **tca6424a** | Driver for TCA6424A low-voltage 24-bit I2C I/O expander | BSD-3-Clause | esp32, esp8266, esp32s2, esp32c3 | yes |
Expand Down
2 changes: 1 addition & 1 deletion components/pca9557/.eil.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pca9557
description: Driver for PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus
description: Driver for PCA9536/PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus
version: 1.0.0
groups:
- gpio
Expand Down
4 changes: 2 additions & 2 deletions components/pca9557/pca9557.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* @file pca9557.c
*
* ESP-IDF driver for PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus
* ESP-IDF driver for PCA9536/PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus
*
* Copyright (c) 2021 Ruslan V. Uss <[email protected]>
*
Expand Down Expand Up @@ -103,7 +103,7 @@ esp_err_t pca9557_init_desc(i2c_dev_t *dev, uint8_t addr, i2c_port_t port, gpio_
CHECK_ARG(dev && (
(addr & PCA9557_I2C_ADDR_BASE) == PCA9557_I2C_ADDR_BASE ||
(addr & TCA9534_I2C_ADDR_BASE) == TCA9534_I2C_ADDR_BASE ||
addr == PCA9537_I2C_ADDR));
addr == PCA9537_I2C_ADDR || addr == PCA9536_I2C_ADDR));

dev->port = port;
dev->addr = addr;
Expand Down
15 changes: 8 additions & 7 deletions components/pca9557/pca9557.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @defgroup pca9557 pca9557
* @{
*
* ESP-IDF driver for PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus
* ESP-IDF driver for PCA9536/PCA9537/PCA9557/TCA9534 remote 4/8-bit I/O expanders for I2C-bus
*
* Copyright (c) 2021 Ruslan V. Uss <[email protected]>
*
Expand All @@ -47,6 +47,7 @@
extern "C" {
#endif

#define PCA9536_I2C_ADDR 0x41 ///< I2C address for PCA9536
#define PCA9537_I2C_ADDR 0x49 ///< I2C address for PCA9537
#define PCA9557_I2C_ADDR_BASE 0x18 ///< Base I2C address for PCA9557
#define TCA9534_I2C_ADDR_BASE 0x20 ///< Base I2C address for TCA9534
Expand Down Expand Up @@ -129,7 +130,7 @@ esp_err_t pca9557_port_set_polarity(i2c_dev_t *dev, uint8_t pol);
* @brief Read I/O port value
*
* @param dev Pointer to I2C device descriptor
* @param[out] val 8-bit GPIO port value for PCA9557 or 4-bit port value for PCA9537
* @param[out] val 8-bit GPIO port value for PCA9557 or 4-bit port value for PCA9536/PCA9537
* @return `ESP_OK` on success
*/
esp_err_t pca9557_port_read(i2c_dev_t *dev, uint8_t *val);
Expand All @@ -138,7 +139,7 @@ esp_err_t pca9557_port_read(i2c_dev_t *dev, uint8_t *val);
* @brief Write value to I/O port
*
* @param dev Pointer to I2C device descriptor
* @param val 8-bit GPIO port value for PCA9557 or 4-bit port value for PCA9537
* @param val 8-bit GPIO port value for PCA9557 or 4-bit port value for PCA9536/PCA9537
* @return ESP_OK on success
*/
esp_err_t pca9557_port_write(i2c_dev_t *dev, uint8_t val);
Expand All @@ -147,7 +148,7 @@ esp_err_t pca9557_port_write(i2c_dev_t *dev, uint8_t val);
* @brief Read I/O pin mode
*
* @param dev Pointer to device descriptor
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PC9537
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PCA9536/PC9537
* @param[out] mode Pin mode
* @return `ESP_OK` on success
*/
Expand All @@ -157,7 +158,7 @@ esp_err_t pca9557_get_mode(i2c_dev_t *dev, uint8_t pin, pca9557_mode_t *mode);
* @brief Set I/O pin mode
*
* @param dev Pointer to device descriptor
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PC9537
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PCA9536/PC9537
* @param mode Pin mode
* @return `ESP_OK` on success
*/
Expand All @@ -167,7 +168,7 @@ esp_err_t pca9557_set_mode(i2c_dev_t *dev, uint8_t pin, pca9557_mode_t mode);
* @brief Read I/O pin level
*
* @param dev Pointer to device descriptor
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PC9537
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PCA9536/PC9537
* @param[out] val 1 if pin currently in high state, 0 otherwise
* @return `ESP_OK` on success
*/
Expand All @@ -179,7 +180,7 @@ esp_err_t pca9557_get_level(i2c_dev_t *dev, uint8_t pin, uint32_t *val);
* Pin must be set up as output
*
* @param dev Pointer to device descriptor
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PC9537
* @param pin Pin number, 0..7 for PCA9557, 0..3 for PCA9536/PC9537
* @param val Pin level. 1 - high, 0 - low
* @return `ESP_OK` on success
*/
Expand Down
36 changes: 30 additions & 6 deletions examples/mcp23x17/mcp23017/main/main.c
Original file line number Diff line number Diff line change
@@ -1,19 +1,40 @@
#include <stdio.h>
#include <esp_log.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <freertos/event_groups.h>
#include <mcp23x17.h>
#include <driver/gpio.h>
#include <string.h>

static const char *TAG = "mcp23017_example";

static EventGroupHandle_t eg = NULL;
static mcp23x17_t dev = { 0 };

#define BIT_BUTTON_CHANGED BIT(0)

static void IRAM_ATTR intr_handler(void *arg)
{
printf("Interrupt!\n");
// On interrupt set bit in event group
BaseType_t hp_task;
if (xEventGroupSetBitsFromISR(eg, BIT_BUTTON_CHANGED, &hp_task) != pdFAIL)
portYIELD_FROM_ISR(hp_task);
}

void button_handler(void *pvParameters)
{
while (1)
{
// wait for BIT_BUTTON_CHANGED, clear it on exit
if (xEventGroupWaitBits(eg, BIT_BUTTON_CHANGED, pdTRUE, pdTRUE, portMAX_DELAY) != BIT_BUTTON_CHANGED)
continue;
// OK, we got this bit set
ESP_LOGI(TAG, "Button was pressed!");
}
}

void test(void *pvParameters)
{
mcp23x17_t dev;
memset(&dev, 0, sizeof(mcp23x17_t));
eg = xEventGroupCreate();

ESP_ERROR_CHECK(mcp23x17_init_desc(&dev, CONFIG_EXAMPLE_I2C_ADDR, 0, CONFIG_EXAMPLE_I2C_MASTER_SDA, CONFIG_EXAMPLE_I2C_MASTER_SCL));

Expand All @@ -22,6 +43,10 @@ void test(void *pvParameters)
// Setup interrupt on it
mcp23x17_set_interrupt(&dev, 0, MCP23X17_INT_ANY_EDGE);

// Run button handler
xTaskCreate(button_handler, "button_handler", 4096, NULL, 5, NULL);

// Setup GPIO interrupt
gpio_set_direction(CONFIG_EXAMPLE_INTA_GPIO, GPIO_MODE_INPUT);
gpio_set_intr_type(CONFIG_EXAMPLE_INTA_GPIO, GPIO_INTR_ANYEDGE);
gpio_install_isr_service(0);
Expand All @@ -44,4 +69,3 @@ void app_main()
ESP_ERROR_CHECK(i2cdev_init());
xTaskCreate(test, "test", configMINIMAL_STACK_SIZE * 6, NULL, 5, NULL);
}

0 comments on commit d9888fe

Please sign in to comment.