managed components purge
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
# The following four lines of boilerplate have to be in your project's CMakeLists
|
||||
# in this exact order for cmake to work correctly
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(example-tca95x5)
|
||||
@@ -0,0 +1,6 @@
|
||||
#V := 1
|
||||
PROJECT_NAME := example-tca95x5
|
||||
|
||||
|
||||
include $(IDF_PATH)/make/project.mk
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
## What the example does
|
||||
|
||||
* Initializes the driver
|
||||
* Configure a pin as input
|
||||
* Registers an interrupt that logs port value of the INT pin
|
||||
* Blinks, or toggles, P10 output
|
||||
|
||||
## Wiring
|
||||
|
||||
Connect an LED with an appropriate register to P10.
|
||||
|
||||
Connect a switch that toggle its voltage HIGH or LOW to INT GPIO. The INT GPIO
|
||||
can be set in `menuconfig`. See the defaults in `Kconfig.projbuild`.
|
||||
@@ -0,0 +1,2 @@
|
||||
idf_component_register(SRCS "main.c"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,21 @@
|
||||
menu "Example configuration"
|
||||
|
||||
config EXAMPLE_I2C_ADDR
|
||||
hex "I2C address of TCA9555"
|
||||
default 0x20
|
||||
help
|
||||
I2C address of TCA9555. The default is `TCA95X5_I2C_ADDR_BASE`, or
|
||||
0x20. See available options in datasheet.
|
||||
|
||||
config EXAMPLE_INT_GPIO
|
||||
int "INT GPIO Number"
|
||||
default 14 if IDF_TARGET_ESP8266
|
||||
default 7 if IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C5 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32C61
|
||||
default 5 if IDF_TARGET_ESP32H2
|
||||
default 5 if IDF_TARGET_ESP32P4
|
||||
default 5 if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
|
||||
help
|
||||
GPIO number connected to INT pin.
|
||||
|
||||
rsource "../../../Kconfig.i2c"
|
||||
endmenu
|
||||
@@ -0,0 +1 @@
|
||||
COMPONENT_ADD_INCLUDEDIRS = . include/
|
||||
@@ -0,0 +1,9 @@
|
||||
dependencies:
|
||||
esp-idf-lib/esp_idf_lib_helpers:
|
||||
version: '*'
|
||||
esp-idf-lib/i2cdev:
|
||||
version: '*'
|
||||
esp-idf-lib/tca95x5:
|
||||
version: '*'
|
||||
description: default
|
||||
version: 1.0.0
|
||||
@@ -0,0 +1,80 @@
|
||||
#include <stdio.h>
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/task.h>
|
||||
#include <freertos/queue.h>
|
||||
#include <tca95x5.h>
|
||||
#include <driver/gpio.h>
|
||||
#include <esp_log.h>
|
||||
|
||||
static i2c_dev_t tca9555 = { 0 };
|
||||
|
||||
static QueueHandle_t gpio_queue = NULL;
|
||||
|
||||
static const char *TAG = "tca95x5-example";
|
||||
|
||||
// Interrupt handler
|
||||
static void IRAM_ATTR intr_handler(void *arg)
|
||||
{
|
||||
gpio_num_t gpio = (gpio_num_t)arg;
|
||||
xQueueSendFromISR(gpio_queue, &gpio, NULL);
|
||||
}
|
||||
|
||||
// Interrupt event receiver
|
||||
static void gpio_recv_task(void *arg)
|
||||
{
|
||||
gpio_num_t gpio;
|
||||
while (1)
|
||||
{
|
||||
if (xQueueReceive(gpio_queue, &gpio, portMAX_DELAY))
|
||||
{
|
||||
ESP_LOGI(TAG, "GPIO interrupt on pin %d", gpio);
|
||||
if (gpio != CONFIG_EXAMPLE_INT_GPIO) continue;
|
||||
|
||||
uint16_t val;
|
||||
esp_err_t res = tca95x5_port_read(&tca9555, &val);
|
||||
if (res != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "Error reading TCA9555: %d (%s)", res, esp_err_to_name(res));
|
||||
continue;
|
||||
}
|
||||
|
||||
ESP_LOGI(TAG, "TCA9555 port value: 0x%04x", val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main_task(void *pvParameters)
|
||||
{
|
||||
// Init descriptor
|
||||
ESP_ERROR_CHECK(tca95x5_init_desc(&tca9555, CONFIG_EXAMPLE_I2C_ADDR, 0, CONFIG_EXAMPLE_I2C_MASTER_SDA, CONFIG_EXAMPLE_I2C_MASTER_SCL));
|
||||
|
||||
// Setup P00, P01 and P02 as input, others as output
|
||||
ESP_ERROR_CHECK(tca95x5_port_set_mode(&tca9555, 0x0007)); // 0b0000000000000111
|
||||
|
||||
// Create queue
|
||||
gpio_queue = xQueueCreate(5, sizeof(gpio_num_t));
|
||||
|
||||
// Run event receiver
|
||||
xTaskCreate(gpio_recv_task, "gpio_recv_task", 4096, NULL, 5, NULL);
|
||||
|
||||
// Setup GPIO interrupt
|
||||
gpio_set_direction(CONFIG_EXAMPLE_INT_GPIO, GPIO_MODE_INPUT);
|
||||
gpio_set_intr_type(CONFIG_EXAMPLE_INT_GPIO, GPIO_INTR_NEGEDGE);
|
||||
gpio_install_isr_service(0);
|
||||
gpio_isr_handler_add(CONFIG_EXAMPLE_INT_GPIO, intr_handler, (void *)CONFIG_EXAMPLE_INT_GPIO);
|
||||
|
||||
// blink on P10
|
||||
bool on = true;
|
||||
while (1)
|
||||
{
|
||||
ESP_ERROR_CHECK(tca95x5_set_level(&tca9555, 8, on));
|
||||
on = !on;
|
||||
vTaskDelay(pdMS_TO_TICKS(500));
|
||||
}
|
||||
}
|
||||
|
||||
void app_main()
|
||||
{
|
||||
ESP_ERROR_CHECK(i2cdev_init());
|
||||
xTaskCreate(main_task, "main_task", configMINIMAL_STACK_SIZE * 6, NULL, 5, NULL);
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 96 KiB |
Reference in New Issue
Block a user