Skip to content

Commit

Permalink
oc cannot control the output because it cannot modify the mode
Browse files Browse the repository at this point in the history
  • Loading branch information
H-sw123 committed Oct 16, 2024
1 parent a85e263 commit 9e8adf4
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 206 deletions.
11 changes: 0 additions & 11 deletions src/ESP_IOExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ void ESP_IOExpander::digitalWrite(uint8_t pin, uint8_t val)
CHECK_ERROR_RETURN(esp_io_expander_set_level(handle, BIT64(pin), val));
}

void ESP_IOExpander::digital_od_Write(uint8_t pin, uint8_t val)
{
CHECK_FALSE_RETURN(IS_VALID_PIN(pin));
CHECK_ERROR_RETURN(esp_io_expander_set_od_level(handle, BIT64(pin), val));
}

int ESP_IOExpander::digitalRead(uint8_t pin)
{
uint32_t level = 0;
Expand All @@ -110,11 +104,6 @@ void ESP_IOExpander::multiDigitalWrite(uint32_t pin_mask, uint8_t value)
CHECK_ERROR_RETURN(esp_io_expander_set_level(handle, pin_mask, value));
}

void ESP_IOExpander::multiDigital_od_Write(uint32_t pin_mask, uint8_t value)
{
CHECK_ERROR_RETURN(esp_io_expander_set_od_level(handle, pin_mask, value));
}

uint32_t ESP_IOExpander::multiDigitalRead(uint32_t pin_mask)
{
uint32_t level = 0;
Expand Down
18 changes: 0 additions & 18 deletions src/ESP_IOExpander.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,6 @@ class ESP_IOExpander {
*/
void digitalWrite(uint8_t pin, uint8_t val);

/**
* @brief Set od pin level
*
* @note This function is same as Arduino's `digitalWrite()`.
*
* @param pin Pin number (0-1)
* @param val Pin level (HIGH/LOW)
*/
void digital_od_Write(uint8_t pin, uint8_t val);

/**
* @brief Read pin level
*
Expand All @@ -166,14 +156,6 @@ class ESP_IOExpander {
*/
void multiDigitalWrite(uint32_t pin_mask, uint8_t value);

/**
* @brief od Write to multiple pins
*
* @param pin_mask Pin mask (Bitwise OR of `IO_EXPANDER_PIN_NUM_*`)
* @param value Value to write (HIGH/LOW)
*/
void multiDigital_od_Write(uint32_t pin_mask, uint8_t value);

/**
* @brief Read multiple pin levels
*
Expand Down
37 changes: 0 additions & 37 deletions src/base/esp_io_expander.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
typedef enum {
REG_INPUT = 0,
REG_OUTPUT,
REG_OD_OUTPUT,
REG_DIRECTION,
} reg_type_t;

Expand Down Expand Up @@ -110,36 +109,6 @@ esp_err_t esp_io_expander_set_level(esp_io_expander_handle_t handle, uint32_t pi
return ESP_OK;
}

esp_err_t esp_io_expander_set_od_level(esp_io_expander_handle_t handle, uint32_t pin_num_mask, uint8_t level)
{
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "Invalid handle");
if (pin_num_mask >= BIT64(VALID_IO_COUNT(handle))) {
ESP_LOGW(TAG, "Pin num mask out of range, bit higher than %d won't work", VALID_IO_COUNT(handle) - 1);
}

uint32_t output_reg, temp;
/* Read the current output level */
ESP_RETURN_ON_ERROR(read_reg(handle, REG_OD_OUTPUT, &output_reg), TAG, "Read OD Output reg failed");
temp = output_reg;
/* Set expected output level */
if ((level && !handle->config.flags.output_high_bit_zero) || (!level && handle->config.flags.output_high_bit_zero)) {
/* 1. High level && Set 1 to output high */
/* 2. Low level && Set 1 to output low */
output_reg |= pin_num_mask;
} else {
/* 3. High level && Set 0 to output high */
/* 4. Low level && Set 0 to output low */
output_reg &= ~pin_num_mask;
}
/* Write to reg only when different */
if (output_reg != temp) {

ESP_RETURN_ON_ERROR(write_reg(handle, REG_OD_OUTPUT, output_reg), TAG, "Write Output reg failed");
}

return ESP_OK;
}

esp_err_t esp_io_expander_get_level(esp_io_expander_handle_t handle, uint32_t pin_num_mask, uint32_t *level_mask)
{
ESP_RETURN_ON_FALSE(handle, ESP_ERR_INVALID_ARG, TAG, "Invalid handle");
Expand Down Expand Up @@ -224,9 +193,6 @@ static esp_err_t write_reg(esp_io_expander_handle_t handle, reg_type_t reg, uint
case REG_OUTPUT:
ESP_RETURN_ON_FALSE(handle->write_output_reg, ESP_ERR_NOT_SUPPORTED, TAG, "write_output_reg isn't implemented");
return handle->write_output_reg(handle, value);
case REG_OD_OUTPUT:
ESP_RETURN_ON_FALSE(handle->write_od_output_reg, ESP_ERR_NOT_SUPPORTED, TAG, "write_output_reg isn't implemented");
return handle->write_od_output_reg(handle, value);
case REG_DIRECTION:
ESP_RETURN_ON_FALSE(handle->write_direction_reg, ESP_ERR_NOT_SUPPORTED, TAG, "write_direction_reg isn't implemented");
return handle->write_direction_reg(handle, value);
Expand Down Expand Up @@ -257,9 +223,6 @@ static esp_err_t read_reg(esp_io_expander_handle_t handle, reg_type_t reg, uint3
case REG_OUTPUT:
ESP_RETURN_ON_FALSE(handle->read_output_reg, ESP_ERR_NOT_SUPPORTED, TAG, "read_output_reg isn't implemented");
return handle->read_output_reg(handle, value);
case REG_OD_OUTPUT:
ESP_RETURN_ON_FALSE(handle->read_od_output_reg, ESP_ERR_NOT_SUPPORTED, TAG, "read_od_output_reg isn't implemented");
return handle->read_od_output_reg(handle, value);
case REG_DIRECTION:
ESP_RETURN_ON_FALSE(handle->read_direction_reg, ESP_ERR_NOT_SUPPORTED, TAG, "read_direction_reg isn't implemented");
return handle->read_direction_reg(handle, value);
Expand Down
53 changes: 0 additions & 53 deletions src/base/esp_io_expander.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ typedef enum {
IO_EXPANDER_PIN_NUM_31 = (1ULL << 31),
} esp_io_expander_pin_num_t;


typedef enum {
OD_IO_EXPANDER_PIN_NUM_0 = (1ULL << 0),
OD_IO_EXPANDER_PIN_NUM_1 = (1ULL << 1),
OD_IO_EXPANDER_PIN_NUM_2 = (1ULL << 2),
OD_IO_EXPANDER_PIN_NUM_3 = (1ULL << 3),
} esp_od_io_expander_pin_num_t;

/**
* @brief IO Expander Pin direction
*
Expand Down Expand Up @@ -124,20 +116,6 @@ struct esp_io_expander_s {
*/
esp_err_t (*write_output_reg)(esp_io_expander_handle_t handle, uint32_t value);

/**
* @brief Write value to od output register (mandatory)
*
* @note The value represents the output level to IO
* @note If there are multiple input registers in the device, their values should be spliced together in order to form the `value`.
*
* @param handle: IO Expander handle
* @param value: Register's value
*
* @return
* - ESP_OK: Success, otherwise returns ESP_ERR_xxx
*/
esp_err_t (*write_od_output_reg)(esp_io_expander_handle_t handle, uint32_t value);

/**
* @brief Read value from output register (mandatory)
*
Expand All @@ -153,22 +131,6 @@ struct esp_io_expander_s {
*/
esp_err_t (*read_output_reg)(esp_io_expander_handle_t handle, uint32_t *value);

/**
* @brief Read value from output register (mandatory)
*
* @note The value represents the expected output level to IO
* @note This function can be implemented by reading the physical output register, or simply by reading a variable that record the output value (more faster)
* @note If there are multiple input registers in the device, their values should be spliced together in order to form the `value`.
*
* @param handle: IO Expander handle
* @param value: Register's value
*
* @return
* - ESP_OK: Success, otherwise returns ESP_ERR_xxx
*/
esp_err_t (*read_od_output_reg)(esp_io_expander_handle_t handle, uint32_t *value);


/**
* @brief Write value to direction register (mandatory)
*
Expand Down Expand Up @@ -252,21 +214,6 @@ esp_err_t esp_io_expander_set_dir(esp_io_expander_handle_t handle, uint32_t pin_
*/
esp_err_t esp_io_expander_set_level(esp_io_expander_handle_t handle, uint32_t pin_num_mask, uint8_t level);

/**
* @brief Set the od output level of a set of target IOs
*
* @note All target IOs must be in output mode first, otherwise this function will return the error `ESP_ERR_INVALID_STATE`
*
* @param handle: IO Exapnder handle
* @param pin_num_mask: Bitwise OR of allowed pin num with type of `esp_io_expander_pin_num_t`
* @param level: 0 - Low level, 1 - High level
*
* @return
* - ESP_OK: Success, otherwise returns ESP_ERR_xxx
*/
esp_err_t esp_io_expander_set_od_level(esp_io_expander_handle_t handle, uint32_t pin_num_mask, uint8_t level);


/**
* @brief Get the intput level of a set of target IOs
*
Expand Down
Loading

0 comments on commit 9e8adf4

Please sign in to comment.