Here's some questions related to the Switch and LED on the nRF9160 Feather. See my answers inline:

So, I generally understand that led_0 in the code is D7 because of the following entry in circuitdojo_feather_nrf9160_common.dts which I think is setting led0 to gpio pin P.0.03.

 leds {
compatible = "gpio-leds";
blue_led: led_0 {
gpios = <&gpio0 3 GPIO_ACTIVE_LOW>;
label = "Blue LED (D7)";

Why do you label it D7 on your feather? How are other gpios mapped to the feather pins? Am I missing where that documentation is?

D7 = Digital Input/Output 7. Similar concept to an Arduino whereas the LED is shared with D13 (from what I remember)

The pins that being with A are Analog pins that you can use the ADC with.

So the Switch 1 button is the Mode button. Is it attached to gpio P0.12 but no feather pins?

It's actually attached to the MD pin. In future versions the raw switch output will be connected to the MD pin (right now it's the digital 3.3V max version).

How do the following gpios map to the feather pins and what do the following mappings mean?

 /* Used for accessing other pins */
feather_header: feather_connector {
compatible = "adafruit-feather-header";
#gpio-cells = <2>;
gpio-map-mask = <0xffffffff 0xffffffc0>;
gpio-map-pass-thru = <0 0x3f>;
gpio-map = <12 0 &gpio0 26 0>,  /* SDA */
<13 0 &gpio0 27 0>,  /* SCL */
<14 0 &gpio0 29 0>,  /* PWM3 */
<15 0 &gpio0 30 0>,  /* PWM3 */
<16 0 &gpio0 0 0>,   /* PWM1 */
<17 0 &gpio0 1 0>,   /* PWM1 */
<18 0 &gpio0 2 0>,   /* PWM1 */
<19 0 &gpio0 3 0>,   /* PWM0 */
<20 0 &gpio0 4 0>,   /* PWM1 */
/* 11 not connected */
<10 0 &gpio0 24 0>,  /* TX */
<9 0 &gpio0 23 0>,   /* RX */
<8 0 &gpio0 22 0>,   /* MISO */
<7 0 &gpio0 21 0>,   /* MOSI */
<6 0 &gpio0 19 0>,   /* SCK */
<5 0 &gpio0 18 0>,   /* SS */
<4 0 &gpio0 17 0>,   /* ADC4 = AIN6 */
<3 0 &gpio0 16 0>,   /* ADC3 = AIN5 */
<2 0 &gpio0 15 0>,   /* ADC2 = AIN4 */
<1 0 &gpio0 14 0>,   /* ADC1 = AIN2 */
<0 0 &gpio0 13 0>;   /* ADC0 = AIN1 */

I've yet to utilize this definition. I saw it in the Zephyr library and thought it would be a good idea to implement it for other folks. It's a similar concept to the switch and LED though where it abstracts the PIN numbers to something more human friendly to interact with inside of code. More to come if more folks are interested. 🙃

    jaredwolff It's a similar concept to the switch and LED though where it abstracts the PIN numbers to something more human friendly to interact with inside of code.

    I'm still a little confused. How do I write code to blink another led, for example one connected to D2 or to an LED connected to D7 using an alias and not led0?

    We know from the leds section and the schematic that GPIO P0.03 is connected to D7 on the feather. The following in the feather-header mapping is an alias as you mention. What does the 19 refer to and how do you use it, Could it be changed to D7 and be more useful?
    <19 0 &gpio0 3 0>, /* PWM0 */

    From the schematic, we know that GPIO P0.29 is connected to pin D2. The corresponding line in the feather-header mapping above is the following. What does the 14 refer to and how do you use it, Could it be changed to D2 and be more useful?
    <14 0 &gpio0 29 0>, /* PWM3 */

      Tonyweil

      Here's a little snippet from the board.c in the Zephyr defs for the nRF9160 Feather:

      #define GPIO0 DT_LABEL(DT_NODELABEL(gpio0))
      #define POWER_LATCH_PIN 31
      
      static int board_circuitdojo_feather_nrf9160_init(struct device *dev)
      {
      	ARG_UNUSED(dev);
      
      	/* Get the device binding */
      	struct device *gpio = device_get_binding(GPIO0);
      	if (gpio == NULL) {
      		return -ENODEV;
      	}
      
      	/* Configure latch pin as output. */
      	gpio_pin_configure(gpio, POWER_LATCH_PIN, GPIO_OUTPUT_HIGH);
      
      	return 0;
      }

      Simply create a def and point it to the PIN number. In the example above I'm modifying P0.31.

        jaredwolff Here's a little snippet from the board.c in the Zephyr defs for the nRF9160 Feather:

        This is very helpful. One has to understand how to blink an arbitrary pin before you can do anything else. Using this information, here is a modified version of blinky that can blink an arbitrary gpio pin on the feather. It is actually much simpler than blinky.

        /*=======================================
        This program is similar to blinky. It is the bare minimum to blink an arbitrary feather pin every 100ms.
        This version blink D7, P0.03, which happens to be the Blue LED.
        
        circuitdojo_feather_nrf9160 pin and GPIO mappings:
        
        Feather Pin	nrf9160 gpio0
        D2		29    // P0.29
        D3		30    // P0.30
        D4	 	0     // P0.0    
        D5	 	1     // P0.1
        D6	 	2     // P0.2
        D7	 	3     // P0.3
        MD		12    // P0.12
        
         Copyright (c) 2016 Intel Corporation
         
         SPDX-License-Identifier: Apache-2.0
         */
        
        #include <zephyr.h>
        #include <device.h>
        #include <devicetree.h>
        #include <drivers/gpio.h>
        
        /* 1000 msec = 1 sec */
        #define SLEEP_TIME_MS   100
        
        #define GPIO0 DT_LABEL(DT_NODELABEL(gpio0))
        #define PIN 3 // Feather Pin D7 = Blue LED
        
        void main(void)
        {	
        	bool led_is_on = true;
        	
                // Get the device binding 
        	struct device *gpio = device_get_binding(GPIO0);
        	
        	// Configure latch pin as output. 
        	gpio_pin_configure(gpio, PIN, GPIO_OUTPUT_ACTIVE);
        	
                while (1) {
        		gpio_pin_set(gpio, PIN, (int)led_is_on);
        		led_is_on = !led_is_on;
        		k_msleep(SLEEP_TIME_MS);
        	}
        }

        jaredwolff board.c in the Zephyr defs for the nRF9160 Feather

        Where did board.c come from and why is it in this folder? Did you create it when you created the circuitdojo_feather_nrf9160 folder.

        I have noticed a lot of warnings when I compile blinky or this new blinky file, some referring to board.c. Not that I really need to understand at this point, but I wanted to mention it. I tried pasting it in here, but the formatting becomes a mess. Here is just the beginning of the warnings.

        [193/193] Linking C executable zephyr\zephyr.elf
        [15/156] Performing build step for 'mcuboot_subimage'
        [48/237] Building C object zephyr/boards/boards/arm/circui...s/boards__arm__circuitdojo_feather_nrf9160.dir/board.c.obj
        C:/ncs/zephyr/boards/arm/circuitdojo_feather_nrf9160/board.c: In function 'board_circuitdojo_feather_nrf9160_init':
        C:/ncs/zephyr/boards/arm/circuitdojo_feather_nrf9160/board.c:24:21: warning: passing argument 1 of 'gpio_pin_configure' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
           24 |  gpio_pin_configure(gpio, POWER_LATCH_PIN, GPIO_OUTPUT_HIGH);

          Tonyweil Where did board.c come from and why is it in this folder? Did you create it when you created the circuitdojo_feather_nrf9160 folder.

          It's part of the board definition. It's very important for keeping the 3.3V rail powered on battery operation. The next version of the board will have this pin brought out which gives folks the option to keep the board powered all the time on battery. I discussed this more in this thread https://community.jaredwolff.com/d/8-auto-power-on-with-battery-only/3

          Terms and Conditions | Privacy Policy