Hello,
I am using the gpio_pca95cc.c driver on the zephyr for a nRF5340. I am a beginner at using zephyr OS
I am able to use one GPIO expander but when I add the second one, I can’t figure a way to access a specific device
In the myboard.dts file I configure the hardware with the following
&i2c0 {
compatible = "nordic,nrf-twim";
status = "okay";
pinctrl-0 = <&i2c0_default>;
pinctrl-1 = <&i2c0_sleep>;
pinctrl-names = "default", "sleep";
PCAL9535_0: pca95xx@20 {
compatible = "nxp,pca95xx";
#gpio-cells = <2>;
gpio-controller;
reg = <0x20 >;
ngpios = < 16 >;
interrupt-gpios = <&gpio0 9 (GPIO_ACTIVE_LOW)>;
has-interrupt-mask-reg;
};
PCAL9535_1: pca95xx@21 {
compatible = "nxp,pca95xx";
#gpio-cells = <2>;
gpio-controller;
reg = <0x21 >;
ngpios = < 16 >;
interrupt-gpios = <&gpio0 9 (GPIO_ACTIVE_LOW)>;
has-interrupt-mask-reg;
};
};
&PCAL9535_0 {
status = "okay";
};
&PCAL9535_1 {
status = "okay";
};
In the prj.conf:
# Enable I2C CONFIG_GPIO=y CONFIG_I2C=y CONFIG_GPIO_PCA95XX=y CONFIG_GPIO_PCA95XX_INTERRUPT=y
And in the main.c file to use the driver when I have only one I do this:
void main(void)
{
int err = 0;
const struct device *const gpio_pca0 = DEVICE_DT_GET_ANY(nxp_pca95xx);
if (!gpio_pca0) {
LOG_INF("Error initialization PCA");
return;
}
gpio_pin_configure(gpio_pca0, 12, GPIO_OUTPUT);
gpio_pin_set(gpio_pca0, 12, 1);
}
My problem is that I cannot choose which device is chosen by the function DEVICE_DT_GET_ANY(nxp_pca95xx);
Ideally I would like to create two struct device one that points at each IO expander so that I can use them separately:
const struct device *const gpio_pca0 = DEVICE_DT_GET_ANY(nxp_pca95xx);
const struct device *const gpio_pca1 = DEVICE_DT_GET_ANY(nxp_pca95xx);
I have tried with the function DEVICE_DT_GET to select a custom one but I could not find my way around the definitionsas I always have an error :
#define PCA1_NODE DT_ALIAS(PCAL9535_1)
#define PCA1_NAME DEVICE_DT_NAME_GET(PCA1_NODE)
void main(void)
{
int err = 0;
const struct device *const gpio_pca1 = DEVICE_DT_GET(PCA1_NAME);
…
}
Could you help me with this problem?
Thank you by advance
Regards
Augustin
