Files
Hodor/components/custom_io_expander_ch32v003/README.md
T

2.3 KiB

Custom IO Expander Chip CH34V003

Component Registry

Implementation of the Custom io expander chip (CH32V003) with esp_io_expander component.

Chip Communication interface Component name Link to datasheet
CH32V003 I2C custom_io_expander_ch32v003 datasheet

Add to project

Packages from this repository are uploaded to Espressif's component service. You can add them to your project via idf.py add-dependency, e.g.

    idf.py add-dependency custom_io_expander_ch32v003==1.0.0

Alternatively, you can create idf_component.yml. More is in Espressif's documentation.

Example use

Creation of the i2c bus.

    i2c_master_bus_handle_t i2c_handle = NULL;
    const i2c_master_bus_config_t bus_config = {
        .i2c_port = I2C_NUM_0,
        .sda_io_num = 8,
        .scl_io_num = 9,
        .clk_source = I2C_CLK_SRC_DEFAULT,
    };
    i2c_new_master_bus(&bus_config, &i2c_handle);

Creation of the component.

    esp_io_expander_handle_t custom_io_expander = NULL;
    custom_io_expander_new_i2c_ch32v003(i2c_handle, BSP_IO_EXPANDER_I2C_ADDRESS, &custom_io_expander);

Print all pins's status to the log:

    esp_io_expander_print_state(custom_io_expander);

Set pin 0 and pin 1 with output dircetion and low level:

    esp_io_expander_set_dir(custom_io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, IO_EXPANDER_OUTPUT);
    esp_io_expander_set_level(custom_io_expander, IO_EXPANDER_PIN_NUM_0 | IO_EXPANDER_PIN_NUM_1, 0);

Set pin 2 and pin 3 with input dircetion:

    uint32_t pin_levels = 0;
    esp_io_expander_set_dir(custom_io_expander, IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3, IO_EXPANDER_INPUT);
    esp_io_expander_get_level(custom_io_expander, IO_EXPANDER_PIN_NUM_2 | IO_EXPANDER_PIN_NUM_3, &pin_levels);