Accessing device pins from board overlay

Hi, I'm trying to write an app to capture images from a camera and was wondering how to monitor changes on specifc defined pins in the board overlay file. For example if(!pclk-gpios){ do something}

 &i2c0 {
	compatible = "nordic,nrf-twim";
	status = "okay";
	mycamera:ov7670@21 {
		compatible = "ovti,ov7670";
		label = "ov7670";
		reg = <0x21>;
		data-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
			  <&gpio0 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
			  <&gpio0 5 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
			  <&gpio0 6 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
			  <&gpio0 7 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
			  <&gpio0 8 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
			  <&gpio0 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>,
			  <&gpio0 10 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;       

		reset-gpios = < &gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH) >;

		vsync-gpios = < &gpio0 15 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;

   		hsync-gpios = < &gpio0 14 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;

   		pclk-gpios = < &gpio0 13 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;

   		xclk-gpios = < &gpio0 12 (GPIO_PULL_UP | GPIO_ACTIVE_LOW) >;
	};
};

  • Hi,

    That is not possible, the devicetree is a data structure used for hardware description, you can't execute code in it. You can read about how the devicetree functions here: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/guides/dts/intro.html

    But what are you trying to achieve? I will try to help you accomplish it another way.

  • Hi, I'm trying to write image acquisition code for the ov7670 camera. The example code I've seen for it monitors the vsync and hsync pins of the camera to determine when and frame and row has ended.

    void ov7670_readframe(void)
    { 
      // (1) locals;
      uint8_t byte_first, byte_second;
      //uint16_t r,g,b, value;
      //uint16_t this_color;
      
      // (2) resets of globals here;
      num_cols = 0;
      num_rows_read = 0;
      
      // (3) scan a frame and drive LCD display too;
      while (!ST_VSYNC); // wait for the old frame to end 
      while (ST_VSYNC); // wait for a new frame to start  
      while (!ST_VSYNC) { // while VSYNC is low during a whole frame
        while (!ST_VSYNC && !ST_HREF); // wait for a line to start 
        if (ST_VSYNC) break; // line didn't start, but frame ended 
        
        num_pixels_on_row = 0;
        while (ST_HREF) { // wait for a row/line to end 
     
          if (num_rows_read < 144) {
            // first byte 
            while (!ST_PCLK); // wait for clock to go high 
            // just grab P1.26,25,24,23  P0.5,4  P0.1,0 
            if (num_pixels_on_row < 176) { // neglect pixels beyond 320 column
              byte_first = // (1) locals;
      uint8_t byte_first, byte_second;
      //uint16_t r,g,b, value;
      //uint16_t this_color;
      
      // (2) resets of globals here;
      num_cols = 0;
      num_rows_read = 0;
      
      // (3) scan a frame and drive LCD display too;
      while (!ST_VSYNC); // wait for the old frame to end 
      while (ST_VSYNC); // wait for a new frame to start  
      while (!ST_VSYNC) { // while VSYNC is low during a whole frame
        while (!ST_VSYNC && !ST_HREF); // wait for a line to start 
        if (ST_VSYNC) break; // line didn't start, but frame ended 
        
        num_pixels_on_row = 0;
        while (ST_HREF) { // wait for a row/line to end 
     
          if (num_rows_read < 144) {
            // first byte 
            while (!ST_PCLK); // wait for clock to go high 
            // just grab P1.26,25,24,23  P0.5,4  P0.1,0 
            if (num_pixels_on_row < 176) { // neglect pixels beyond 320 column
              byte_first = 
                ((LPC_GPIO1->FIOPIN >> 19) & (0x000000F0)) | 
                ((LPC_GPIO0->FIOPIN >> 2) & (0x0000000C)) |          
                ((LPC_GPIO0->FIOPIN) & (0x00000003));  
            }
            while (ST_PCLK); // wait for clock to go back low 
            // second byte 
            while (!ST_PCLK); // wait for clock to go high    
            if (num_pixels_on_row < 176) { 
              byte_second = 
                ((LPC_GPIO1->FIOPIN >> 19) & (0x000000F0)) |
                ((LPC_GPIO0->FIOPIN >> 2) & (0x0000000C)) |          
                ((LPC_GPIO0->FIOPIN) & (0x00000003));
    
              //value = (byte_first << 8) | byte_second;    
              //r = (value & 0xF800);
              //g = (value & 0x07E0);
              //b = (value & 0x001F);   
              //this_color = r|g|b;           
              //LCD_SetPoint(num_rows_read, num_pixels_on_row, this_color);
              LCD_SetPoint(num_rows_read, num_pixels_on_row, ((byte_first << 8) | byte_second));                   
            }       
            while (ST_PCLK); // wait for clock to go back low 
            num_pixels_on_row ++;       
          } 
          else {
            while (!ST_PCLK); // wait for clock to go high 
            while (ST_PCLK); // wait for clock to go back low 
            while (!ST_PCLK); // wait for clock to go high      
            while (ST_PCLK); // wait for clock to go back low 
            num_pixels_on_row ++;      
          }
           
        } // wait for a row/line to end    
        num_rows_read ++;
        if (num_rows_read == 1) num_cols = num_pixels_on_row;
      }
                ((LPC_GPIO1->FIOPIN >> 19) & (0x000000F0)) | 
                ((LPC_GPIO0->FIOPIN >> 2) & (0x0000000C)) |          
                ((LPC_GPIO0->FIOPIN) & (0x00000003));  
            }
            while (ST_PCLK); // wait for clock to go back low 
            // second byte 
            while (!ST_PCLK); // wait for clock to go high    
            if (num_pixels_on_row < 176) { 
              byte_second = 
                ((LPC_GPIO1->FIOPIN >> 19) & (0x000000F0)) |
                ((LPC_GPIO0->FIOPIN >> 2) & (0x0000000C)) |          
                ((LPC_GPIO0->FIOPIN) & (0x00000003));
    
              //value = (byte_first << 8) | byte_second;    
              //r = (value & 0xF800);
              //g = (value & 0x07E0);
              //b = (value & 0x001F);   
              //this_color = r|g|b;           
              //LCD_SetPoint(num_rows_read, num_pixels_on_row, this_color);
              LCD_SetPoint(num_rows_read, num_pixels_on_row, ((byte_first << 8) | byte_second));                   
            }       
            while (ST_PCLK); // wait for clock to go back low 
            num_pixels_on_row ++;       
          } 
          else {
            while (!ST_PCLK); // wait for clock to go high 
            while (ST_PCLK); // wait for clock to go back low 
            while (!ST_PCLK); // wait for clock to go high      
            while (ST_PCLK); // wait for clock to go back low 
            num_pixels_on_row ++;      
          }
           
        } // wait for a row/line to end    
        num_rows_read ++;
        if (num_rows_read == 1) num_cols = num_pixels_on_row;
      }
    }

  • That function looks like it should be in the driver file. Take a look at zephyr/samples/basic/button, and how the button pin is monitored there. That should be a viable solution.

Related