Adding a 3x3 Shield button board to nRF5340 DK

I have acquired a basic 3x3 matrix scanning type button board that drops onto the Shield interface of the nRF5340.  I am running the "peripheral_hids_keyboard" sample project with Zephyr.  The button board is the "Ibridge lite 3×3 keypad shield" from https://www.electrokit.com/en/product/ibridge-lite-3x3-keypad-shield-with-lcd-interface/.

What would be the recommend way to add a scanning keyboard driver to this sample project?  I am just getting familiar with this environment and would like to avoid wasting time by re-inventing the wheel if i can avoid it.

I did enable the CONFIG_KSCAN option in the .config file but I don't know how to go any further at this moment.

Thanks!

  • It looks to me like the Fujitsu keyboard stuff in the example is there just to show you how keyboard mapping is done, so you can replace it with your own layout.

    These GPIO mappings you're talking about is exactly what's missing from the devicetree. In the datasheet of the shield you linked to you can see what pins on your shield are the different keyboard scan pins, and you'll have to map these to the GPIO pins on your DK that they are connected to.

    If you have a look at the overlay example code here, I believe your overlay should look very similar to this, but without the zmk bits, and for DT_ALIAS to work you'll have to add something like this:

    aliases {
        kscan0 = &kscan0;
    };

    Hope that helps!

    -Einar

  • I seem to be getting a little further along with this "overlay" concept but I am not all the way there.

    I have modified my CMakeLists.txt as follows:

    # SPDX-License-Identifier: Apache-2.0
    
    set(DTC_OVERLAY_FILE nrf5340_audio_dk_nrf5340_cpuapp_ns.overlay;iBridges-Lite_3x3_keypad.overlay)
    
    cmake_minimum_required(VERSION 3.20.0)
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(kscan)
    
    FILE(GLOB app_sources src/*.c)
    target_sources(app PRIVATE ${app_sources})

    Note the first set() command.  If I want to use my own custom overlay do I have to manually declare the defacto project overlay and then my custom overlay?  Does using a single custom overlay force me to do this and ditch the automatic finding of overlays or can I just let the automatic system do it's thing and declare a custom overlay after?

    Here is my custom overlay "\kscan\iBridges-Lite_3x3_keypad.overlay":

    / {
        chosen {
            kscan = &kscan0;
        };
    
        kscan0: kscan_0 {
            compatible = "kscan-gpio-matrix";
            label = "KSCAN";
            diode-direction = "col2row";
    
            col-gpios
                = <&gpio0 16 GPIO_ACTIVE_HIGH>
                , <&gpio0 17 GPIO_ACTIVE_HIGH>
                , <&gpio0 18 GPIO_ACTIVE_HIGH>
                ;
    
            row-gpios
                = <&gpio0 13 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                , <&gpio0 14 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                , <&gpio0 15 (GPIO_ACTIVE_HIGH | GPIO_PULL_DOWN)>
                ;
        };
    
        aliases {
            kscan0 = &kscan0;
        };
    };

    Now my build is still failing at the following:

    FAILED: zephyr/zephyr_pre0.elf zephyr/zephyr_pre0.map
    cmd.exe /C "cd . && C:\Users\PeterTomich\ncs\toolchains\v2.0.0\opt\zephyr-sdk\arm-zephyr-eabi\bin\arm-zephyr-eabi-gcc.exe zephyr/CMakeFiles/zephyr_pre0.dir/misc/empty_file.c.obj -o zephyr\zephyr_pre0.elf -Wl,-T zephyr/linker_zephyr_pre0.cmd -Wl,-Map=C:/Nordic/Scanning_Keyboard/kscan/build/zephyr/zephyr_pre0.map -Wl,--whole-archive app/libapp.a zephyr/libzephyr.a zephyr/arch/common/libarch__common.a zephyr/arch/arch/arm/core/aarch32/libarch__arm__core__aarch32.a zephyr/arch/arch/arm/core/aarch32/cortex_m/libarch__arm__core__aarch32__cortex_m.a zephyr/arch/arch/arm/core/aarch32/cortex_m/cmse/libarch__arm__core__aarch32__cortex_m__cmse.a zephyr/arch/arch/arm/core/aarch32/mpu/libarch__arm__core__aarch32__mpu.a zephyr/lib/libc/minimal/liblib__libc__minimal.a zephyr/lib/posix/liblib__posix.a zephyr/soc/arm/common/cortex_m/libsoc__arm__common__cortex_m.a zephyr/subsys/random/libsubsys__random.a zephyr/drivers/clock_control/libdrivers__clock_control.a zephyr/drivers/gpio/libdrivers__gpio.a zephyr/drivers/entropy/libdrivers__entropy.a zephyr/drivers/timer/libdrivers__timer.a zephyr/drivers/pinctrl/libdrivers__pinctrl.a modules/nrf/lib/fatal_error/lib..__nrf__lib__fatal_error.a modules/trusted-firmware-m/libtfm_api.a modules/hal_nordic/nrfx/libmodules__hal_nordic__nrfx.a modules/nrfxlib/nrfxlib/nrf_security/src/zephyr/libmbedtls_zephyr.a -Wl,--no-whole-archive zephyr/kernel/libkernel.a zephyr/CMakeFiles/offsets.dir/./arch/arm/core/offsets/offsets.c.obj -L"c:/users/petertomich/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/thumb/v8-m.main/nofp" -LC:/Nordic/Scanning_Keyboard/kscan/build/zephyr -lgcc zephyr/arch/common/libisr_tables.a tfm/platform/libplatform_ns.a tfm/app/libtfm_api_ns.a tfm/secure_fw/s_veneers.o -no-pie -Wl,--gc-sections -Wl,--build-id=none -Wl,--sort-common=descending -Wl,--sort-section=alignment -Wl,-u,_OffsetAbsSyms -Wl,-u,_ConfigAbsSyms -nostdlib -static -Wl,-X -Wl,-N -Wl,--orphan-handling=warn modules/nrfxlib/nrfxlib/nrf_security/src/libmbedcrypto.a C:/Users/PeterTomich/ncs/v2.0.0/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_mbedtls_3.0.11.a modules/nrfxlib/nrfxlib/nrf_security/src/libmbedcrypto_base.a -mcpu=cortex-m33 -mthumb -mabi=aapcs -mfp16-format=ieee C:/Users/PeterTomich/ncs/v2.0.0/nrfxlib/crypto/nrf_oberon/lib/cortex-m33/soft-float/liboberon_3.0.11.a && cmd.exe /C "cd /D C:\Nordic\Scanning_Keyboard\kscan\build\zephyr && C:\Users\PeterTomich\ncs\toolchains\v2.0.0\opt\bin\cmake.exe -E echo ""
    c:/users/petertomich/ncs/toolchains/v2.0.0/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/10.3.0/../../../../arm-zephyr-eabi/bin/ld.exe: app/libapp.a(main.c.obj):C:\Nordic\Scanning_Keyboard\kscan\src\main.c:20: undefined reference to `__device_dts_ord_5'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'c:\Users\PeterTomich\ncs\toolchains\v2.0.0\opt\bin\cmake.EXE' --build 'c:\Nordic\Scanning_Keyboard\kscan\build'

    * The terminal process terminated with exit code: 1.
    * Terminal will be reused by tasks, press any key to close it.

    The problem appears to be this: undefined reference to `__device_dts_ord_5'

    Thanks for your help on this!

  • I opened a private Case ID: 293251 with our app attached.  I need direct support on that case to integrate the ZMK driver.  Thanks.

  • Hi,

    Was this ever resolved, having the same issue here and am at the undefined reference to '__device_dts_ord_xx' step 

    Thanks.

  • Hi

    This error comes from the linker, and usually means something in your devicetree is ill-defined.

    If you're still having this issue, please open a new ticket and explain the full context of your problem there.

    -Einar

Related