Skip to content

Commit

Permalink
will not touch gpio direction when create a gpio pin
Browse files Browse the repository at this point in the history
Signed-off-by: Clark Wang <[email protected]>
  • Loading branch information
wangxiaoningnxp committed Sep 2, 2020
1 parent 121fc90 commit bc72950
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 3 additions & 1 deletion bcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,9 @@ static void get_boot_mode(struct options_setting* setting)
if (status)
printf("get_boot_mode failed, error = 0x%x\n", status);
else
printf("get_boot_mode: %s\n", get_boot_mode_name_from_hex(board, read_buf));
printf("get_boot_mode: %s\n", get_boot_mode_name_from_hex(board, read_buf) == NULL ?
"Cannot find the boot mode!" :
get_boot_mode_name_from_hex(board, read_buf));

free_gpio(gpio);
}
Expand Down
17 changes: 11 additions & 6 deletions chip.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,20 +814,19 @@ void* pca6416a_create(char* chip_specification, void* parent)
pca->addr = extract_parameter_value(chip_specification, "addr");
pca->port = extract_parameter_value(chip_specification, "port");

if (pca->gpio_device.opendrain <= 0)
pca6416a_set_direction(pca, ~pca->gpio_device.pin_bitmask);
else
pca6416a_set_output(pca, ~pca->gpio_device.pin_bitmask);

return pca;
}

int pca6416a_write(void* pca6416a, unsigned char bit_value)
{
struct pca6416a* pca = pca6416a;
if (pca->gpio_device.opendrain > 0)

if (pca->gpio_device.opendrain > 0) {
pca6416a_set_output(pca, ~pca->gpio_device.pin_bitmask);
return pca6416a_set_direction(pca, bit_value);
}

pca6416a_set_direction(pca, ~pca->gpio_device.pin_bitmask);
return pca6416a_set_output(pca, bit_value);
}
int pca6416a_set_output(struct pca6416a* pca6416a, unsigned char bit_value)
Expand Down Expand Up @@ -897,6 +896,9 @@ int pca6416a_get_direction(void* pca6416a, unsigned char* bit_value_buffer)
bSucceed = parent->i2c_stop(parent);
if (bSucceed) return bSucceed;

if (pca->gpio_device.opendrain <= 0)
(*bit_value_buffer) = ~(*bit_value_buffer);

//mask away unwanted value;
*bit_value_buffer = (*bit_value_buffer) & (pca->gpio_device.pin_bitmask);
return 0;
Expand Down Expand Up @@ -979,6 +981,9 @@ int pca6416a_toggle(void* pca6416a)
{
struct pca6416a* pca = pca6416a;
struct i2c_device* parent = (void*)pca->gpio_device.device.parent;

//TODO: NEED SET DIRECTIONS FOR THE PINS FIRST HERE

unsigned char addr_plus_write = (pca->addr << 1) + 0;
unsigned char addr_plus_read = (pca->addr << 1) + 1;

Expand Down

0 comments on commit bc72950

Please sign in to comment.