RCM — ESP32 Room Controller
WT32-ETH01 firmware
Loading...
Searching...
No Matches
pca9535.c File Reference

I2C-обмен с PCA9535, тест на светодиодах P0.3 и P0.4. More...

#include "pca9535.h"
#include "driver/i2c_master.h"
#include "esp_check.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"

Go to the source code of this file.

Macros

#define I2C_PORT   I2C_NUM_0
 
#define I2C_SCL_GPIO   14
 
#define I2C_SDA_GPIO   15
 
#define I2C_FREQ_HZ   400000
 
#define I2C_TIMEOUT_MS   1000
 
#define PCA9535_I2C_ADDR   0x20
 
#define PCA9535_REG_INPUT0   0x00
 
#define PCA9535_REG_INPUT1   0x01
 
#define PCA9535_REG_OUTPUT0   0x02
 
#define PCA9535_REG_OUTPUT1   0x03
 
#define PCA9535_REG_INVERT0   0x04
 
#define PCA9535_REG_INVERT1   0x05
 
#define PCA9535_REG_CONFIG0   0x06
 
#define PCA9535_REG_CONFIG1   0x07
 
#define LED_P03_BIT   (1U << 3)
 Светодиоды на порту 0, пины 3 и 4.
 
#define LED_P04_BIT   (1U << 4)
 
#define LED_MASK   (LED_P03_BIT | LED_P04_BIT)
 
#define PORT0_CONFIG_LEDS   0xE7
 Конфигурация: P0.3 и P0.4 — выходы, остальные — входы
 
#define TEST_BLINK_MS   400
 

Functions

static esp_err_t pca9535_write_reg (uint8_t reg, uint8_t value)
 
static esp_err_t pca9535_read_reg (uint8_t reg, uint8_t *value)
 
static esp_err_t pca9535_set_port0 (uint8_t value)
 
esp_err_t pca9535_init (void)
 Инициализирует шину I2C и PCA9535.
 
static void pca9535_test_task (void *arg)
 Тест: поочерённое включение P0.3 и P0.4.
 
esp_err_t pca9535_test_start (void)
 Запускает тестовую задачу: поочерённое мигание светодиодов P0.3 и P0.4.
 

Variables

static const char * TAG = "pca9535"
 
static i2c_master_bus_handle_t s_i2c_bus
 
static i2c_master_dev_handle_t s_pca9535_dev
 
static uint8_t s_output0
 
static bool s_initialized
 

Detailed Description

I2C-обмен с PCA9535, тест на светодиодах P0.3 и P0.4.

Адрес 0x20, I2C 400 кГц, SCL=GPIO14, SDA=GPIO15. Светодиоды к GND: HIGH — включён, LOW — выключен.

Definition in file pca9535.c.

Macro Definition Documentation

◆ I2C_FREQ_HZ

#define I2C_FREQ_HZ   400000

Definition at line 22 of file pca9535.c.

Referenced by pca9535_init().

◆ I2C_PORT

#define I2C_PORT   I2C_NUM_0

Definition at line 19 of file pca9535.c.

Referenced by pca9535_init().

◆ I2C_SCL_GPIO

#define I2C_SCL_GPIO   14

Definition at line 20 of file pca9535.c.

Referenced by pca9535_init().

◆ I2C_SDA_GPIO

#define I2C_SDA_GPIO   15

Definition at line 21 of file pca9535.c.

Referenced by pca9535_init().

◆ I2C_TIMEOUT_MS

#define I2C_TIMEOUT_MS   1000

Definition at line 23 of file pca9535.c.

Referenced by pca9535_read_reg(), and pca9535_write_reg().

◆ LED_MASK

#define LED_MASK   (LED_P03_BIT | LED_P04_BIT)

Definition at line 39 of file pca9535.c.

◆ LED_P03_BIT

#define LED_P03_BIT   (1U << 3)

Светодиоды на порту 0, пины 3 и 4.

Definition at line 37 of file pca9535.c.

Referenced by pca9535_test_task().

◆ LED_P04_BIT

#define LED_P04_BIT   (1U << 4)

Definition at line 38 of file pca9535.c.

Referenced by pca9535_test_task().

◆ PCA9535_I2C_ADDR

#define PCA9535_I2C_ADDR   0x20

Definition at line 25 of file pca9535.c.

Referenced by pca9535_init().

◆ PCA9535_REG_CONFIG0

#define PCA9535_REG_CONFIG0   0x06

Definition at line 33 of file pca9535.c.

Referenced by pca9535_init().

◆ PCA9535_REG_CONFIG1

#define PCA9535_REG_CONFIG1   0x07

Definition at line 34 of file pca9535.c.

Referenced by pca9535_init().

◆ PCA9535_REG_INPUT0

#define PCA9535_REG_INPUT0   0x00

Definition at line 27 of file pca9535.c.

◆ PCA9535_REG_INPUT1

#define PCA9535_REG_INPUT1   0x01

Definition at line 28 of file pca9535.c.

◆ PCA9535_REG_INVERT0

#define PCA9535_REG_INVERT0   0x04

Definition at line 31 of file pca9535.c.

Referenced by pca9535_init().

◆ PCA9535_REG_INVERT1

#define PCA9535_REG_INVERT1   0x05

Definition at line 32 of file pca9535.c.

Referenced by pca9535_init().

◆ PCA9535_REG_OUTPUT0

#define PCA9535_REG_OUTPUT0   0x02

Definition at line 29 of file pca9535.c.

Referenced by pca9535_set_port0().

◆ PCA9535_REG_OUTPUT1

#define PCA9535_REG_OUTPUT1   0x03

Definition at line 30 of file pca9535.c.

◆ PORT0_CONFIG_LEDS

#define PORT0_CONFIG_LEDS   0xE7

Конфигурация: P0.3 и P0.4 — выходы, остальные — входы

Definition at line 42 of file pca9535.c.

Referenced by pca9535_init().

◆ TEST_BLINK_MS

#define TEST_BLINK_MS   400

Definition at line 44 of file pca9535.c.

Referenced by pca9535_test_task().

Function Documentation

◆ pca9535_init()

◆ pca9535_read_reg()

static esp_err_t pca9535_read_reg ( uint8_t reg,
uint8_t * value )
static

Definition at line 57 of file pca9535.c.

References I2C_TIMEOUT_MS, and s_pca9535_dev.

Referenced by pca9535_init().

◆ pca9535_set_port0()

static esp_err_t pca9535_set_port0 ( uint8_t value)
static

Definition at line 62 of file pca9535.c.

References PCA9535_REG_OUTPUT0, pca9535_write_reg(), s_output0, and TAG.

Referenced by pca9535_init(), and pca9535_test_task().

◆ pca9535_test_start()

esp_err_t pca9535_test_start ( void )

Запускает тестовую задачу: поочерённое мигание светодиодов P0.3 и P0.4.

Definition at line 128 of file pca9535.c.

References pca9535_test_task(), s_initialized, and TAG.

◆ pca9535_test_task()

static void pca9535_test_task ( void * arg)
static

Тест: поочерённое включение P0.3 и P0.4.

Definition at line 112 of file pca9535.c.

References LED_P03_BIT, LED_P04_BIT, pca9535_set_port0(), TAG, and TEST_BLINK_MS.

Referenced by pca9535_test_start().

◆ pca9535_write_reg()

static esp_err_t pca9535_write_reg ( uint8_t reg,
uint8_t value )
static

Definition at line 51 of file pca9535.c.

References I2C_TIMEOUT_MS, and s_pca9535_dev.

Referenced by pca9535_init(), and pca9535_set_port0().

Variable Documentation

◆ s_i2c_bus

i2c_master_bus_handle_t s_i2c_bus
static

Definition at line 46 of file pca9535.c.

Referenced by pca9535_init().

◆ s_initialized

bool s_initialized
static

Definition at line 49 of file pca9535.c.

Referenced by pca9535_init(), and pca9535_test_start().

◆ s_output0

uint8_t s_output0
static

Definition at line 48 of file pca9535.c.

Referenced by pca9535_set_port0().

◆ s_pca9535_dev

i2c_master_dev_handle_t s_pca9535_dev
static

Definition at line 47 of file pca9535.c.

Referenced by pca9535_init(), pca9535_read_reg(), and pca9535_write_reg().

◆ TAG

const char* TAG = "pca9535"
static

Definition at line 17 of file pca9535.c.

Referenced by pca9535_init(), pca9535_set_port0(), pca9535_test_start(), and pca9535_test_task().