The problem with the management of IO Expander PCA9534

Hi,

I need to control the LED using the PCA9534PW IO Extender. I found a library for this device, but unfortunately it does not compile. So I decided to try to control the expander without a library.

What should I do:

  1. Set 0 pin in output mode
  2. Set 0 pin to HIGH / LOW state

In the library I found the following:

  1. To set the pin to output mode:
  uint8_t pin = 0; // IO0
  uint8_t _port; // Port configuration status on Configuration register
  _port &= ~(1 << pin);
  Wire.beginTransmission(0x50);
  Wire.write(0x03); // PCA9534_CONF_REGISTER
  Wire.write(_port);
  Wire.endTransmission();
  1. HIGH level:
  uint8_t pin = 0; // IO0
  uint8_t _port; // Port configuration status on Configuration register
  _port |= (1 << pin); // HIGH Level
  Wire.beginTransmission(0x50);
  Wire.write(0x01); // PCA9534_OP_REGISTER
  Wire.write(_port);
  Wire.endTransmission();
  1. LOW level:
  uint8_t pin = 0; // IO0
  uint8_t _port; // Port configuration status on Configuration register
  _port &= ~(1 << pin); // LOW Level
  Wire.beginTransmission(0x50);
  Wire.write(0x01); // PCA9534_OP_REGISTER
  Wire.write(_port);
  Wire.endTransmission();

I do not understand how it works:
_port &= ~(1 << pin); // Output Mode
_port |= (1 << pin); // HIGH Level
_port &= ~(1 << pin); // LOW Level

And in general, how is this right?

Please, help!