How can I use ISR in pixhawk?

Hello Guys

I just want some information on how to use ISR in pixhawk ? From what I read , I can config the Aux pins a pwm input pins and I want to try something with ISR and pwm input pins.

Regards
Abin Ephrem

You can schedule an ISR with hrt_call_every, or with stm32_gpiosetevent in the case of an AUX pin. https://github.com/PX4/Firmware/blob/master/src/drivers/pwm_input/pwm_input.cpp#L311

Thanks…still got some doubts. Let me explain what I want to do.

I have a digital optical obstacle avoidance sensor ( HIGH in the normal state). Whenever there is an obstacle in front of the sensor it will give me a LOW state ( there will be a falling edge in the signal). I want to configure the AUX pin 5 (GPIO_GPIO4_INPUT) as input pin and whenever there is change in the state ( HIGH to LOW falling edge ) I want ISR to run a piece of code.

Couple of things I understood referring the forums !

	set FMU_MODE pwm4
	set AUX_MODE pwm4

this two lines in the rcs will configure first 4 Aux Pins as PWM output and rest two as GPIO’s.

px4_arch_configgpio(GPIO_GPIO4_INPUT) :- does it configure the Aux 5 pin as Input ?
px4_arch_gpioread(GPIO_GPIO4_INPUT) : this will read the current state of the pin right ?

px4_arch_gpiowrite(GPIO_GPIO4,HIGH);
irq_attach(GPIO_GPIO4_INPUT, pwmin_tim_isr,CHANGE);

Does the above two lines will do the trick ?

or should I use
stm32_configgpio(GPIO_GPIO4,INPUT);
stm32_gpiowrite(GPIO_GPIO4,HIGH);

I’m still struggling to get one particular pin working with ISR.

@dagar

I have a doubt regarding the pwm_input driver code. The driver code points to the device PWMIN0_DEVICE_PATH which is defined in the drv_pwm_input.h files as “/dev/pwmin0” . My confusion is which device/pin “/dev/pwmin0” corresponds too ?

PWMIN0_DEVICE_PATH is a “pwm input device” created by the driver. It’s a way for other parts of the system to interact with the driver. Does that make sense?