diff --git a/applications/nrf_desktop/configuration/nrf52820dongle_nrf52820/app.overlay b/applications/nrf_desktop/configuration/nrf52820dongle_nrf52820/app.overlay index d17e7249043b..c1584db08649 100644 --- a/applications/nrf_desktop/configuration/nrf52820dongle_nrf52820/app.overlay +++ b/applications/nrf_desktop/configuration/nrf52820dongle_nrf52820/app.overlay @@ -1,4 +1,20 @@ / { + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + gpioled1 { compatible = "gpio-leds"; status = "okay"; diff --git a/applications/nrf_desktop/configuration/nrf52833dk_nrf52820/app.overlay b/applications/nrf_desktop/configuration/nrf52833dk_nrf52820/app.overlay index c3305d1179f9..aa0259107423 100644 --- a/applications/nrf_desktop/configuration/nrf52833dk_nrf52820/app.overlay +++ b/applications/nrf_desktop/configuration/nrf52833dk_nrf52820/app.overlay @@ -1,4 +1,20 @@ / { + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + gpioled0 { compatible = "gpio-leds"; status = "okay"; diff --git a/applications/nrf_desktop/configuration/nrf52833dk_nrf52833/app.overlay b/applications/nrf_desktop/configuration/nrf52833dk_nrf52833/app.overlay index 22b33eb5458b..97d5c1d1212c 100644 --- a/applications/nrf_desktop/configuration/nrf52833dk_nrf52833/app.overlay +++ b/applications/nrf_desktop/configuration/nrf52833dk_nrf52833/app.overlay @@ -1,4 +1,20 @@ / { + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + pwmleds1 { compatible = "pwm-leds"; status = "okay"; diff --git a/applications/nrf_desktop/configuration/nrf52833dongle_nrf52833/app.overlay b/applications/nrf_desktop/configuration/nrf52833dongle_nrf52833/app.overlay index a7dcbd975b04..6a52f217e6cc 100644 --- a/applications/nrf_desktop/configuration/nrf52833dongle_nrf52833/app.overlay +++ b/applications/nrf_desktop/configuration/nrf52833dongle_nrf52833/app.overlay @@ -1,4 +1,20 @@ / { + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + pwmleds0 { compatible = "pwm-leds"; status = "okay"; diff --git a/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app.overlay b/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app.overlay index cebd48d9f7ae..83411087e746 100644 --- a/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app.overlay +++ b/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app.overlay @@ -10,6 +10,15 @@ zephyr,entropy = &rng; }; + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "mouse"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + pwmleds1 { compatible = "pwm-leds"; status = "okay"; diff --git a/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app_dongle.overlay b/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app_dongle.overlay new file mode 100644 index 000000000000..a364e24d76c2 --- /dev/null +++ b/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app_dongle.overlay @@ -0,0 +1,153 @@ +/ { + chosen { + /* + * In some default configurations within the nRF Connect SDK, + * e.g. on nRF52840 and nRF9160, the chosen zephyr,entropy node + * is &cryptocell. This devicetree overlay ensures that default + * is overridden wherever it is set, as this application uses + * the RNG node for entropy exclusively. + */ + zephyr,entropy = &rng; + }; + + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "keyboard"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "keyboard"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + + pwmleds1 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led1: led_pwm_1 { + status = "okay"; + pwms = <&pwm1 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED Conn State"; + }; + }; + + pwmleds2 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led2: led_pwm_2 { + status = "okay"; + pwms = <&pwm2 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED Num Lock"; + }; + }; + + pwmleds3 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led3: led_pwm_3 { + status = "okay"; + pwms = <&pwm3 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED Caps Lock"; + }; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default_alt>; + pinctrl-1 = <&pwm0_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default_alt>; + pinctrl-1 = <&pwm1_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm2 { + status = "okay"; + pinctrl-0 = <&pwm2_default_alt>; + pinctrl-1 = <&pwm2_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm3 { + status = "okay"; + pinctrl-0 = <&pwm3_default_alt>; + pinctrl-1 = <&pwm3_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm_led0 { + status = "okay"; + pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED System State"; +}; + +&pinctrl { + pwm0_default_alt: pwm0_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm0_sleep_alt: pwm0_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + + pwm1_default_alt: pwm1_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm1_sleep_alt: pwm1_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + + pwm2_default_alt: pwm2_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm2_sleep_alt: pwm2_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + + pwm3_default_alt: pwm3_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm3_sleep_alt: pwm3_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; +}; diff --git a/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app_keyboard.overlay b/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app_keyboard.overlay new file mode 100644 index 000000000000..bf54663a586f --- /dev/null +++ b/applications/nrf_desktop/configuration/nrf52840dk_nrf52840/app_keyboard.overlay @@ -0,0 +1,146 @@ +/ { + chosen { + /* + * In some default configurations within the nRF Connect SDK, + * e.g. on nRF52840 and nRF9160, the chosen zephyr,entropy node + * is &cryptocell. This devicetree overlay ensures that default + * is overridden wherever it is set, as this application uses + * the RNG node for entropy exclusively. + */ + zephyr,entropy = &rng; + }; + + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "keyboard"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + + pwmleds1 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led1: led_pwm_1 { + status = "okay"; + pwms = <&pwm1 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED Conn State"; + }; + }; + + pwmleds2 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led2: led_pwm_2 { + status = "okay"; + pwms = <&pwm2 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED Num Lock"; + }; + }; + + pwmleds3 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led3: led_pwm_3 { + status = "okay"; + pwms = <&pwm3 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED Caps Lock"; + }; + }; +}; + +&pwm0 { + status = "okay"; + pinctrl-0 = <&pwm0_default_alt>; + pinctrl-1 = <&pwm0_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default_alt>; + pinctrl-1 = <&pwm1_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm2 { + status = "okay"; + pinctrl-0 = <&pwm2_default_alt>; + pinctrl-1 = <&pwm2_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm3 { + status = "okay"; + pinctrl-0 = <&pwm3_default_alt>; + pinctrl-1 = <&pwm3_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pwm_led0 { + status = "okay"; + pwms = <&pwm0 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED System State"; +}; + +&pinctrl { + pwm0_default_alt: pwm0_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm0_sleep_alt: pwm0_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + + pwm1_default_alt: pwm1_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm1_sleep_alt: pwm1_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + + pwm2_default_alt: pwm2_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm2_sleep_alt: pwm2_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + + pwm3_default_alt: pwm3_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm3_sleep_alt: pwm3_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; +}; diff --git a/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app.overlay b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app.overlay index ca8b793bb20e..de4227ab818d 100644 --- a/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app.overlay +++ b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app.overlay @@ -10,6 +10,22 @@ zephyr,entropy = &rng; }; + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + pwmleds { red_pwm_led: pwm_led_0 { pwms = <&pwm0 0 PWM_MSEC(1) PWM_POLARITY_INVERTED>; diff --git a/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_3bleconn.overlay b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_3bleconn.overlay new file mode 100644 index 000000000000..52c6c7f3e086 --- /dev/null +++ b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_3bleconn.overlay @@ -0,0 +1,117 @@ +/ { + chosen { + /* + * In some default configurations within the nRF Connect SDK, + * e.g. on nRF52840 and nRF9160, the chosen zephyr,entropy node + * is &cryptocell. This devicetree overlay ensures that default + * is overridden wherever it is set, as this application uses + * the RNG node for entropy exclusively. + */ + zephyr,entropy = &rng; + }; + + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_2: hid_dev_2 { + compatible = "zephyr,hid-device"; + interface-name = "HID2"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_3: hid_dev_3 { + compatible = "zephyr,hid-device"; + interface-name = "HID3"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_4: hid_dev_4 { + compatible = "zephyr,hid-device"; + interface-name = "HID4"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_5: hid_dev_5 { + compatible = "zephyr,hid-device"; + interface-name = "HID5"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + + pwmleds { + red_pwm_led: pwm_led_0 { + pwms = <&pwm0 0 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + green_pwm_led: pwm_led_1 { + pwms = <&pwm0 1 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + blue_pwm_led: pwm_led_2 { + pwms = <&pwm0 2 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + }; + + pwmleds1 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led1: led_pwm_4 { + status = "okay"; + pwms = <&pwm1 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED System State"; + }; + }; +}; + +&usbd { + compatible = "nordic,nrf-usbd"; + status = "okay"; + num-bidir-endpoints = <0>; + num-in-endpoints = <7>; + num-out-endpoints = <2>; + num-isoin-endpoints = <0>; + num-isoout-endpoints = <0>; +}; + +&pwm0 { + status = "okay"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default_alt>; + pinctrl-1 = <&pwm1_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pinctrl { + pwm1_default_alt: pwm1_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm1_sleep_alt: pwm1_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + +}; diff --git a/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_4llpmconn.overlay b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_4llpmconn.overlay new file mode 100644 index 000000000000..52c6c7f3e086 --- /dev/null +++ b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_4llpmconn.overlay @@ -0,0 +1,117 @@ +/ { + chosen { + /* + * In some default configurations within the nRF Connect SDK, + * e.g. on nRF52840 and nRF9160, the chosen zephyr,entropy node + * is &cryptocell. This devicetree overlay ensures that default + * is overridden wherever it is set, as this application uses + * the RNG node for entropy exclusively. + */ + zephyr,entropy = &rng; + }; + + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_2: hid_dev_2 { + compatible = "zephyr,hid-device"; + interface-name = "HID2"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_3: hid_dev_3 { + compatible = "zephyr,hid-device"; + interface-name = "HID3"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_4: hid_dev_4 { + compatible = "zephyr,hid-device"; + interface-name = "HID4"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_5: hid_dev_5 { + compatible = "zephyr,hid-device"; + interface-name = "HID5"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + + pwmleds { + red_pwm_led: pwm_led_0 { + pwms = <&pwm0 0 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + green_pwm_led: pwm_led_1 { + pwms = <&pwm0 1 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + blue_pwm_led: pwm_led_2 { + pwms = <&pwm0 2 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + }; + + pwmleds1 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led1: led_pwm_4 { + status = "okay"; + pwms = <&pwm1 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED System State"; + }; + }; +}; + +&usbd { + compatible = "nordic,nrf-usbd"; + status = "okay"; + num-bidir-endpoints = <0>; + num-in-endpoints = <7>; + num-out-endpoints = <2>; + num-isoin-endpoints = <0>; + num-isoout-endpoints = <0>; +}; + +&pwm0 { + status = "okay"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default_alt>; + pinctrl-1 = <&pwm1_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pinctrl { + pwm1_default_alt: pwm1_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm1_sleep_alt: pwm1_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + +}; diff --git a/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_release_4llpmconn.overlay b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_release_4llpmconn.overlay new file mode 100644 index 000000000000..52c6c7f3e086 --- /dev/null +++ b/applications/nrf_desktop/configuration/nrf52840dongle_nrf52840/app_release_4llpmconn.overlay @@ -0,0 +1,117 @@ +/ { + chosen { + /* + * In some default configurations within the nRF Connect SDK, + * e.g. on nRF52840 and nRF9160, the chosen zephyr,entropy node + * is &cryptocell. This devicetree overlay ensures that default + * is overridden wherever it is set, as this application uses + * the RNG node for entropy exclusively. + */ + zephyr,entropy = &rng; + }; + + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_2: hid_dev_2 { + compatible = "zephyr,hid-device"; + interface-name = "HID2"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_3: hid_dev_3 { + compatible = "zephyr,hid-device"; + interface-name = "HID3"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_4: hid_dev_4 { + compatible = "zephyr,hid-device"; + interface-name = "HID4"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_5: hid_dev_5 { + compatible = "zephyr,hid-device"; + interface-name = "HID5"; + protocol-code = "none"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + + pwmleds { + red_pwm_led: pwm_led_0 { + pwms = <&pwm0 0 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + green_pwm_led: pwm_led_1 { + pwms = <&pwm0 1 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + blue_pwm_led: pwm_led_2 { + pwms = <&pwm0 2 PWM_MSEC(1) PWM_POLARITY_INVERTED>; + }; + }; + + pwmleds1 { + compatible = "pwm-leds"; + status = "okay"; + + pwm_led1: led_pwm_4 { + status = "okay"; + pwms = <&pwm1 0 PWM_MSEC(20) PWM_POLARITY_INVERTED>; + label = "LED System State"; + }; + }; +}; + +&usbd { + compatible = "nordic,nrf-usbd"; + status = "okay"; + num-bidir-endpoints = <0>; + num-in-endpoints = <7>; + num-out-endpoints = <2>; + num-isoin-endpoints = <0>; + num-isoout-endpoints = <0>; +}; + +&pwm0 { + status = "okay"; +}; + +&pwm1 { + status = "okay"; + pinctrl-0 = <&pwm1_default_alt>; + pinctrl-1 = <&pwm1_sleep_alt>; + pinctrl-names = "default", "sleep"; +}; + +&pinctrl { + pwm1_default_alt: pwm1_default_alt { + group1 { + psels = ; + nordic,invert; + }; + }; + + pwm1_sleep_alt: pwm1_sleep_alt { + group1 { + psels = ; + low-power-enable; + }; + }; + +}; diff --git a/applications/nrf_desktop/configuration/nrf52840gmouse_nrf52840/app.overlay b/applications/nrf_desktop/configuration/nrf52840gmouse_nrf52840/app.overlay index 9c5a6f5d7667..678c7a98a076 100644 --- a/applications/nrf_desktop/configuration/nrf52840gmouse_nrf52840/app.overlay +++ b/applications/nrf_desktop/configuration/nrf52840gmouse_nrf52840/app.overlay @@ -9,6 +9,14 @@ */ zephyr,entropy = &rng; }; + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "mouse"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; pwmleds0 { compatible = "pwm-leds"; diff --git a/applications/nrf_desktop/configuration/nrf5340dk_nrf5340_cpuapp/app.overlay b/applications/nrf_desktop/configuration/nrf5340dk_nrf5340_cpuapp/app.overlay index 7d33fc8475b1..efef4da7ddfe 100644 --- a/applications/nrf_desktop/configuration/nrf5340dk_nrf5340_cpuapp/app.overlay +++ b/applications/nrf_desktop/configuration/nrf5340dk_nrf5340_cpuapp/app.overlay @@ -1,4 +1,20 @@ / { + /* Configure DTS nodes used for USB next HID support. */ + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + protocol-code = "keyboard"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + hid_dev_1: hid_dev_1 { + compatible = "zephyr,hid-device"; + interface-name = "HID1"; + protocol-code = "keyboard"; + in-polling-rate = <1000>; + in-report-size = <64>; + }; + pwmleds1 { compatible = "pwm-leds"; status = "okay"; diff --git a/applications/nrf_desktop/sample.yaml b/applications/nrf_desktop/sample.yaml index a376c1786f76..6a5dd1348332 100644 --- a/applications/nrf_desktop/sample.yaml +++ b/applications/nrf_desktop/sample.yaml @@ -259,3 +259,35 @@ tests: - nrf54h20dk/nrf54h20/cpuapp tags: bluetooth ci_build sysbuild extra_args: FILE_SUFFIX=release + applications.nrf_desktop.zdebug.usb_next: + sysbuild: true + build_only: true + platform_allow: > + nrf52840dk/nrf52840 nrf52840gmouse/nrf52840 nrf52840dongle/nrf52840 + integration_platforms: + - nrf52840dk/nrf52840 + - nrf52840gmouse/nrf52840 + - nrf52840dongle/nrf52840 + tags: bluetooth ci_build sysbuild + extra_configs: + - CONFIG_DESKTOP_USB_STACK_NEXT=y + applications.nrf_desktop.zdebug_dongle.usb_next: + sysbuild: true + build_only: true + platform_allow: nrf52840dk/nrf52840 + integration_platforms: + - nrf52840dk/nrf52840 + tags: bluetooth ci_build sysbuild + extra_args: FILE_SUFFIX=dongle + extra_configs: + - CONFIG_DESKTOP_USB_STACK_NEXT=y + applications.nrf_desktop.zdebug_keyboard.usb_next: + sysbuild: true + build_only: true + platform_allow: nrf52840dk/nrf52840 + integration_platforms: + - nrf52840dk/nrf52840 + tags: bluetooth ci_build sysbuild + extra_args: FILE_SUFFIX=keyboard + extra_configs: + - CONFIG_DESKTOP_USB_STACK_NEXT=y diff --git a/applications/nrf_desktop/src/modules/Kconfig.usb_state b/applications/nrf_desktop/src/modules/Kconfig.usb_state index 145dc15a26c5..d8140003a8c0 100644 --- a/applications/nrf_desktop/src/modules/Kconfig.usb_state +++ b/applications/nrf_desktop/src/modules/Kconfig.usb_state @@ -56,9 +56,7 @@ config DESKTOP_USB_STACK_NEXT select EXPERIMENTAL select USB_DEVICE_STACK_NEXT help - Use experimental integration of USB next stack. The USB next API is - not yet integrated by the module's implementation. The option only - disables the legacy USB stack and builds with the USB next stack. + Use experimental integration of USB next stack. config DESKTOP_USB_STACK_LEGACY bool "USB legacy stack" @@ -143,6 +141,12 @@ endif # DESKTOP_USB_STACK_LEGACY if DESKTOP_USB_STACK_NEXT +config USBD_HID_IN_BUF_COUNT + default 1 + help + nRF Desktop queues HID reports at the source. There is no need to use + multiple buffers in the IN pool per HID instance. + choice USBD_LOG_LEVEL_CHOICE default USBD_LOG_LEVEL_WRN help diff --git a/applications/nrf_desktop/src/modules/usb_state.c b/applications/nrf_desktop/src/modules/usb_state.c index dc8f9c4c2dd7..717ee9992970 100644 --- a/applications/nrf_desktop/src/modules/usb_state.c +++ b/applications/nrf_desktop/src/modules/usb_state.c @@ -6,13 +6,19 @@ #include #include +#include +#include #include #include #include +#include +#include + #include #include #include +#include #define MODULE usb_state #include @@ -53,6 +59,7 @@ struct usb_hid_device { uint32_t report_bm; uint8_t hid_protocol; uint8_t sent_report_id; + uint32_t idle_duration[REPORT_ID_COUNT]; bool report_enabled[REPORT_ID_COUNT]; bool enabled; }; @@ -65,7 +72,16 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_DESKTOP_USB_STACK_NEXT) || "Unsupported USB stack"); #if CONFIG_DESKTOP_USB_STACK_NEXT -static struct usb_hid_device usb_hid_device[0]; +#define USB_NEXT_USB_HID_DEVICE_INIT(node_id) \ +{ \ + .dev = DEVICE_DT_GET(node_id), \ + .hid_protocol = HID_PROTOCOL_REPORT, \ + .sent_report_id = REPORT_ID_COUNT, \ +}, + +static struct usb_hid_device usb_hid_device[] = { + DT_FOREACH_STATUS_OKAY(zephyr_hid_device, USB_NEXT_USB_HID_DEVICE_INIT) +}; #else static struct usb_hid_device usb_hid_device[CONFIG_USB_HID_DEVICE_COUNT]; #endif @@ -77,6 +93,8 @@ BUILD_ASSERT(!IS_ENABLED(CONFIG_DESKTOP_HID_STATE_ENABLE) || IS_ENABLED(CONFIG_DESKTOP_USB_SELECTIVE_REPORT_SUBSCRIPTION) || (ARRAY_SIZE(usb_hid_device) <= 1)); +static struct usbd_contex *usbd_ctx; + static struct config_channel_transport cfg_chan_transport; @@ -213,11 +231,6 @@ static void report_sent(const struct device *dev, bool error) usb_hid->sent_report_id = REPORT_ID_COUNT; } -static void report_sent_cb(const struct device *dev) -{ - report_sent(dev, false); -} - static void send_hid_report(const struct hid_report_event *event) { struct usb_hid_device *usb_hid = NULL; @@ -281,7 +294,15 @@ static void send_hid_report(const struct hid_report_event *event) int err = 0; if (IS_ENABLED(CONFIG_DESKTOP_USB_STACK_NEXT)) { - LOG_WRN("send_hid_report not integrated for USB next"); + /* USB next stack expects buffer alignment. */ + if (IS_ALIGNED(report_buffer, sizeof(void *))) { + err = hid_device_submit_report(usb_hid->dev, report_size, report_buffer); + } else { + uint8_t temp[report_size] __aligned(sizeof(void *)); + + memcpy(temp, report_buffer, report_size); + err = hid_device_submit_report(usb_hid->dev, report_size, temp); + } } else { __ASSERT_NO_MSG(IS_ENABLED(CONFIG_DESKTOP_USB_STACK_LEGACY)); err = hid_int_ep_write(usb_hid->dev, report_buffer, report_size, NULL); @@ -293,11 +314,11 @@ static void send_hid_report(const struct hid_report_event *event) } } -static void broadcast_usb_state(void) +static void broadcast_usb_state(enum usb_state broadcast_state) { struct usb_state_event *event = new_usb_state_event(); - event->state = state; + event->state = broadcast_state; APP_EVENT_SUBMIT(event); } @@ -480,8 +501,8 @@ static void usb_wakeup(void) { int err = 0; - if (IS_ENABLED(CONFIG_DESKTOP_USB_STACK_NEXT)) { - LOG_WRN("usb_wakeup not integrated for USB next"); + if (IS_ENABLED(CONFIG_DESKTOP_USB_STACK_NEXT) && usbd_ctx) { + err = usbd_wakeup_request(usbd_ctx); } else { __ASSERT_NO_MSG(IS_ENABLED(CONFIG_DESKTOP_USB_STACK_LEGACY)); err = usb_wakeup_request(); @@ -626,6 +647,11 @@ static int set_report_legacy(const struct device *dev, struct usb_setup_packet * return err; } +static void report_sent_cb_legacy(const struct device *dev) +{ + report_sent(dev, false); +} + static int usb_init_legacy_hid_device_init(struct usb_hid_device *usb_hid_dev, const struct device *dev, uint32_t report_bm) @@ -633,7 +659,7 @@ static int usb_init_legacy_hid_device_init(struct usb_hid_device *usb_hid_dev, static const struct hid_ops hid_ops = { .get_report = get_report_legacy, .set_report = set_report_legacy, - .int_in_ready = report_sent_cb, + .int_in_ready = report_sent_cb_legacy, .protocol_change = protocol_change, }; @@ -747,7 +773,7 @@ static void usb_init_legacy_status_cb(enum usb_dc_status_code cb_status, const u /* Update state. */ state = new_state; - broadcast_usb_state(); + broadcast_usb_state(state); /* HID subscribe when entering active state. */ if (state == USB_STATE_ACTIVE) { @@ -804,6 +830,362 @@ static int usb_init_legacy(void) return 0; } +static bool is_usb_active_next(void) +{ + bool usb_active = false; + + for (size_t i = 0; i < ARRAY_SIZE(usb_hid_device); i++) { + if (usb_hid_device[i].enabled) { + usb_active = true; + break; + } + } + + return usb_active; +} + +static void iface_ready_next(const struct device *dev, const bool ready) +{ + struct usb_hid_device *usb_hid = dev_to_hid(dev); + bool was_usb_active = is_usb_active_next(); + + update_usb_hid(usb_hid, ready); + + bool is_usb_active = is_usb_active_next(); + + if (state == USB_STATE_SUSPENDED) { + /* USB state update is delayed if USB is suspended. */ + return; + } + + if (!was_usb_active && is_usb_active) { + broadcast_usb_state(USB_STATE_ACTIVE); + } else if (was_usb_active && !is_usb_active) { + broadcast_usb_state(state); + } +} + +static int get_report_next(const struct device *dev, const uint8_t type, const uint8_t id, + const uint16_t len, uint8_t *const buf) +{ + /* Omit the first byte - HID report ID. */ + buf[0] = id; + return get_report(dev, type, id, buf + 1, len - 1); +} + +static int set_report_next(const struct device *dev, const uint8_t type, const uint8_t id, + const uint16_t len, const uint8_t *const buf) +{ + /* Omit the first byte - HID report ID. */ + return set_report(dev, type, id, buf + 1, len - 1); +} + +static void set_idle_next(const struct device *dev, const uint8_t id, const uint32_t duration) +{ + struct usb_hid_device *usb_hid = dev_to_hid(dev); + + usb_hid->idle_duration[id] = duration; +} + +static uint32_t get_idle_next(const struct device *dev, const uint8_t id) +{ + struct usb_hid_device *usb_hid = dev_to_hid(dev); + + return usb_hid->idle_duration[id]; +} + +static void report_sent_cb_next(const struct device *dev) +{ + struct usb_hid_device *usb_hid = dev_to_hid(dev); + + /* USB next stack does not explicitly indicate failed transfers. */ + if (usb_hid->enabled) { + report_sent(dev, false); + } else { + report_sent(dev, true); + } +} + +static int usb_init_next_hid_device_init(struct usb_hid_device *usb_hid_dev, uint32_t report_bm) +{ + static const struct hid_device_ops hid_ops = { + .iface_ready = iface_ready_next, + .get_report = get_report_next, + .set_report = set_report_next, + .set_idle = set_idle_next, + .get_idle = get_idle_next, + .set_protocol = protocol_change, + .input_report_done = report_sent_cb_next, + }; + + usb_hid_dev->report_bm = report_bm; + + int err = hid_device_register(usb_hid_dev->dev, hid_report_desc, hid_report_desc_size, + &hid_ops); + + if (err) { + LOG_ERR("hid_device_register failed for %p (err: %d)", + (void *)usb_hid_dev->dev, err); + } + + return err; +} + +static int usb_init_next_hids_init(void) +{ + int err = 0; + + for (size_t i = 0; i < ARRAY_SIZE(usb_hid_device); i++) { + err = usb_init_next_hid_device_init(&usb_hid_device[i], get_report_bm(i)); + if (err) { + LOG_ERR("usb_init_next_hid_device_init failed (err: %d)", err); + break; + } + } + + return err; +} + +static void usb_init_next_status_cb(struct usbd_contex *const contex, + const struct usbd_msg *const msg) +{ + static enum usb_state before_suspend; + enum usb_state new_state = state; + + LOG_DBG("USBD msg: %s", usbd_msg_type_string(msg->type)); + + switch (msg->type) { + case USBD_MSG_VBUS_READY: + if (state != USB_STATE_DISCONNECTED) { + LOG_WRN("USBD_MSG_VBUS_READY while USB is not disconnected"); + } + new_state = USB_STATE_POWERED; + break; + + case USBD_MSG_VBUS_REMOVED: + new_state = USB_STATE_DISCONNECTED; + break; + + case USBD_MSG_RESUME: + if (state == USB_STATE_SUSPENDED) { + new_state = before_suspend; + } + break; + + case USBD_MSG_SUSPEND: + before_suspend = state; + new_state = USB_STATE_SUSPENDED; + break; + + case USBD_MSG_RESET: + if (state != USB_STATE_DISCONNECTED) { + new_state = USB_STATE_POWERED; + } else { + LOG_WRN("Reset while disconnected"); + } + break; + + case USBD_MSG_UDC_ERROR: + LOG_ERR("Non-correctable UDC error message"); + module_set_state(MODULE_STATE_ERROR); + break; + + case USBD_MSG_STACK_ERROR: + LOG_ERR("Unrecoverable USB device stack error"); + module_set_state(MODULE_STATE_ERROR); + break; + + case USBD_MSG_CDC_ACM_LINE_CODING: + case USBD_MSG_CDC_ACM_CONTROL_LINE_STATE: + /* Ignore */ + break; + + default: + LOG_ERR("Unexpected USB device message type: %d", msg->type); + break; + } + + if (new_state != state) { + if ((state == USB_STATE_SUSPENDED) && is_usb_active_next()) { + broadcast_usb_state(USB_STATE_ACTIVE); + } else { + broadcast_usb_state(new_state); + } + state = new_state; + } +} + +static int usb_init_next_register_fs_classes(struct usbd_contex *usbd) +{ + int err = 0; + + STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_fs, usbd_class_node, c_nd) { + err = usbd_register_class(usbd, c_nd->c_data->name, USBD_SPEED_FS, 1); + if (err) { + LOG_ERR("usbd_register_class failed for %s (err: %d)", + c_nd->c_data->name, err); + return err; + } + } + + return err; +} + +static int usb_init_next_register_hs_classes(struct usbd_contex *usbd) +{ + int err = 0; + + STRUCT_SECTION_FOREACH_ALTERNATE(usbd_class_hs, usbd_class_node, c_nd) { + err = usbd_register_class(usbd, c_nd->c_data->name, USBD_SPEED_HS, 1); + if (err) { + LOG_ERR("usbd_register_class failed for %s (err: %d)", + c_nd->c_data->name, err); + return err; + } + } + + return err; +} + +static int usb_init_next_add_configuration(struct usbd_contex *usbd, + const enum usbd_speed speed, + struct usbd_config_node *config) +{ + int err; + + err = usbd_add_configuration(usbd, speed, config); + if (err) { + LOG_ERR("usbd_add_configuration failed (err: %d)", err); + return err; + } + + if (speed == USBD_SPEED_FS) { + err = usb_init_next_register_fs_classes(usbd); + } else if (speed == USBD_SPEED_HS) { + err = usb_init_next_register_hs_classes(usbd); + } + + if (err) { + return err; + } + + /* Always use class code information from Interface Descriptors */ + if (IS_ENABLED(CONFIG_USBD_CDC_ACM_CLASS)) { + BUILD_ASSERT(!IS_ENABLED(CONFIG_USBD_CDC_ECM_CLASS)); + BUILD_ASSERT(!IS_ENABLED(CONFIG_USBD_AUDIO2_CLASS)); + /* + * Class with multiple interfaces have an Interface + * Association Descriptor available, use an appropriate triple + * to indicate it. + */ + usbd_device_set_code_triple(usbd, speed, USB_BCC_MISCELLANEOUS, 0x02, 0x01); + } else { + usbd_device_set_code_triple(usbd, speed, 0, 0, 0); + } + + return 0; +} + +static struct usbd_contex *usb_init_next_usbd_init(void) +{ + int err; + + USBD_DEVICE_DEFINE(usbd, DEVICE_DT_GET(DT_NODELABEL(usbd)), + CONFIG_DESKTOP_DEVICE_VID, CONFIG_DESKTOP_DEVICE_PID); + + USBD_DESC_LANG_DEFINE(lang); + USBD_DESC_MANUFACTURER_DEFINE(manufacturer, CONFIG_DESKTOP_DEVICE_MANUFACTURER); + USBD_DESC_PRODUCT_DEFINE(product, CONFIG_DESKTOP_DEVICE_PRODUCT); + USBD_DESC_SERIAL_NUMBER_DEFINE(serial_number); + + /* Maximum power consumption of a device: 250 * 2 mA = 500 mA. */ + static const uint8_t max_power = 250; + static const uint8_t attributes = IS_ENABLED(CONFIG_DESKTOP_USB_REMOTE_WAKEUP) ? + (USB_SCD_REMOTE_WAKEUP) : (0); + + USBD_CONFIGURATION_DEFINE(fs_config, attributes, max_power); + USBD_CONFIGURATION_DEFINE(hs_config, attributes, max_power); + + err = usbd_add_descriptor(&usbd, &lang); + if (err) { + LOG_ERR("usbd_add_descriptor(lang) failed (err: %d)", err); + return NULL; + } + + err = usbd_add_descriptor(&usbd, &manufacturer); + if (err) { + LOG_ERR("usbd_add_descriptor(manufacturer) failed (err: %d)", err); + return NULL; + } + + err = usbd_add_descriptor(&usbd, &product); + if (err) { + LOG_ERR("usbd_add_descriptor(product) failed (err: %d)", err); + return NULL; + } + + err = usbd_add_descriptor(&usbd, &serial_number); + if (err) { + LOG_ERR("usbd_add_descriptor(serial_number) failed (err: %d)", err); + return NULL; + } + + if (usbd_caps_speed(&usbd) == USBD_SPEED_HS) { + err = usb_init_next_add_configuration(&usbd, USBD_SPEED_HS, &hs_config); + if (err) { + LOG_ERR("usb_init_next_add_configuration failed (err: %d)", err); + return NULL; + } + } + + err = usb_init_next_add_configuration(&usbd, USBD_SPEED_FS, &fs_config); + if (err) { + LOG_ERR("usb_init_next_add_configuration failed (err: %d)", err); + return NULL; + } + + err = usbd_init(&usbd); + if (err) { + LOG_ERR("usbd_init (err: %d)", err); + return NULL; + } + + return &usbd; +} + +static int usb_init_next(void) +{ + int err = usb_init_next_hids_init(); + + if (err) { + LOG_ERR("usb_init_next_hids_init failed (err: %d)", err); + return err; + } + + struct usbd_contex *usbd = usb_init_next_usbd_init(); + + if (!usbd) { + LOG_ERR("usb_init_next_usbd_init failed"); + return -ENXIO; + } + + err = usbd_msg_register_cb(usbd, usb_init_next_status_cb); + if (err) { + LOG_ERR("usbd_msg_register_cb failed (err: %d)", err); + return err; + } + + err = usbd_enable(usbd); + if (err) { + LOG_ERR("usbd_enable failed (err: %d)", err); + return err; + } + + usbd_ctx = usbd; + + return 0; +} + static int usb_init(void) { int err = 0; @@ -815,7 +1197,7 @@ static int usb_init(void) } if (IS_ENABLED(CONFIG_DESKTOP_USB_STACK_NEXT)) { - LOG_WRN("USB next stack APIs are not yet in use"); + err = usb_init_next(); } else { __ASSERT_NO_MSG(IS_ENABLED(CONFIG_DESKTOP_USB_STACK_LEGACY)); err = usb_init_legacy(); diff --git a/boards/nordic/nrf52840gmouse/nrf52840gmouse_nrf52840_defconfig b/boards/nordic/nrf52840gmouse/nrf52840gmouse_nrf52840_defconfig index f9ec43c7c40b..69e328438fde 100644 --- a/boards/nordic/nrf52840gmouse/nrf52840gmouse_nrf52840_defconfig +++ b/boards/nordic/nrf52840gmouse/nrf52840gmouse_nrf52840_defconfig @@ -1,7 +1,4 @@ # Enable MPU CONFIG_ARM_MPU=y -# Enable USB -CONFIG_USB_DEVICE_STACK=y - CONFIG_PINCTRL=y