Hi,

Perhaps I am too late to the discussion and some of those stuffs were
already said but I use PCF8575 on a custom board so I think a can help a bit
with that.

> I'm trying to access the PCF8575 device from my application on NuttX to 
make it light up LEDs. I'm not really sure how to implement it, but this is
what I've got:

The easiest way if you want to use PCF8575 for LEDs is to register those as
GPIOs using CONFIG_GPIO_LOWER_HALF. First you have to initialize I2C and 
register the expander (you can do it in BSP layer).




struct pcf8575_config_s g_pcf8575_cfg =

{ 

  .address     = PCF8575_I2C_ADDRESS, 

  .frequency  = PCF8575_I2C_FREQ, 

};




struct i2c_master_s *i2c;
struct ioexpander_dev_s *ioe;


i2c = sam_i2cbus_initialize(TWIHS0_BUS);

ioe = pcf8575_initialize(i2c, &g_pcf8575_cfg);




Then you can register the pins.




IOEXP_SETDIRECTION(ioe, 0, IOEXPANDER_DIRECTION_OUT);

gpio_lower_half_byname(ioe, 0, GPIO_OUTPUT_PIN, "led_red");

IOEXP_WRITEPIN(ioe, 0, 1); 





etc.




The pin is registered as dev/led_red and you can access it from your
application using classic GPIO interface (take a look at examples/gpio). 
Writing multiple pins is a bit trickier, you can use IOEXP_MULTIWRITEPIN but
this requires ioexpander_dev_s structure to be available in application 
layer (which is possible, but you would have to do the whole

initialization in application layer and as someone already mentioned, this
might not be thread safe).




But accessing pins one by one should be straightforward with CONFIG_GPIO_
LOWER_HALF option. Hope this helps.




Best regards,

Michal Lenc

Reply via email to