Reading a GPIO bus

Hi, I'm trying to reading the data pins of a camera and store it in variable. I'm able to read single pins using

static const struct gpio_dt_spec vsync = GPIO_DT_SPEC_GET_OR(ST_VSYNC, gpios, {0});
	gpio_pin_configure_dt(&vsync, GPIO_INPUT);
	
if (gpio_pin_get_dt(&vsync) == 1)
	{
		printk("Frame Complete!");
	}
 

How would I read 8 data pins simultaneously. This is my overlay file

/{
	aliases {
		sw0 = &button;
		vsync = &vsync;
		hsync = &hsync;
		pclk = &pclk;
	};

	gpios {
		compatible = "gpio-keys";
		button: button {
			gpios = < &gpio0 29 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
			label = "User button";
		};
		camdata: camdata {
			gpios = <&gpio0 4 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
				<&gpio0 3 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
				<&gpio0 20 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
				<&gpio0 21 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
				<&gpio0 22 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
				<&gpio0 23 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
				<&gpio0 28 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
				<&gpio1 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;  
				label="camdata";
		};		
			//reset-gpios = < &gpio0 2 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH) >;
		vsync: vsync {
			gpios = < &gpio1 10 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;
			label="vsync";
		};
		hsync: hsync {
			gpios = < &gpio1 11 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;
			label = "hsync";
		};
		pclk: pclk {
			gpios = < &gpio1 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;
			label = "pclk";
		};
			//xclk-gpios = < &gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;
	};
};

  • You can synchronously read all 32 bits of the input port P0 simultaneously with a single instruction. Using a bit mask and shifts enables cuddling up the data bits if that is required. An advantage of using a single 32-bit read returns not just the data bits but also the sync etc bits. Since the input port sampling clock is 16MHz the race hazard/uncertainty between fast changing input pins can be estimated.

     volatile uint32_t inputPinSnapshot = NRFP0->IN & pinsDefinedAsInputsMask;

Related