Skip to content

Commit 730a1f6

Browse files
pyhyskartben
authored andcommitted
boards: Add Waveshare RP2040-Keyboard-3 development board
Tested with the commands mentioned in the index.rst page. Signed-off-by: Jonas Berg <[email protected]>
1 parent fbdd3bb commit 730a1f6

File tree

10 files changed

+375
-0
lines changed

10 files changed

+375
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2025 Jonas Berg
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config BOARD_RP2040_KEYBOARD_3
5+
select RP2_FLASH_W25Q080
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2022 Peter Johanson
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
if BOARD_RP2040_KEYBOARD_3
5+
6+
if I2C_DW
7+
8+
config I2C_DW_CLOCK_SPEED
9+
default 125
10+
11+
endif # I2C_DW
12+
13+
config USB_SELF_POWERED
14+
default n
15+
16+
source "boards/common/usb/Kconfig.cdc_acm_serial.defconfig"
17+
18+
endif # BOARD_RP2040_KEYBOARD_3
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright (c) 2025 Jonas Berg
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config BOARD_RP2040_KEYBOARD_3
5+
select SOC_RP2040
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2023 TOKITA Hiroshi
3+
4+
board_runner_args(uf2 "--board-id=RPI-RP2")
5+
6+
include(${ZEPHYR_BASE}/boards/common/uf2.board.cmake)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
board:
2+
name: rp2040_keyboard_3
3+
full_name: RP2040-Keyboard-3
4+
vendor: waveshare
5+
socs:
6+
- name: rp2040
5.86 KB
Loading
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
.. zephyr:board:: rp2040_keyboard_3
2+
3+
Overview
4+
********
5+
6+
The `Waveshare 3-Key Shortcut Keyboard Development Board`_ is based on the RP2040 microcontroller
7+
from Raspberry Pi Ltd. It has three keys with the default values "CTRL", "C" and "V". The board
8+
is equipped with two USB type C connectors. There are two versions of the keyboard, where the
9+
diffence is in the housing (plastic or metal). This board definition can be used with both versions.
10+
11+
12+
Hardware
13+
********
14+
15+
- Microcontroller Raspberry Pi RP2040, with a max frequency of 133 MHz
16+
- Dual ARM Cortex M0+ cores
17+
- 264 kByte SRAM
18+
- 2 Mbyte QSPI flash
19+
- 3 user keys
20+
- 3 RGB LEDs (Neopixels); one in each user key
21+
- Dual USB type C connectors (use one at a time)
22+
- RESET and BOOT buttons
23+
24+
The RESET and BOOT buttons are located on the back side of the board, on separate long edges
25+
of the board. The BOOT button is located at the long edge with a USB connector, and the RESET
26+
is located at the other long edge of the board.
27+
28+
29+
Default Zephyr Peripheral Mapping
30+
=================================
31+
32+
.. rst-class:: rst-columns
33+
34+
- Button CTRL (left) : GPIO14
35+
- Button C (center) : GPIO13
36+
- Button V (right) : GPIO12
37+
- RGB LEDs: GPIO18
38+
39+
Note that no serial port pins (RX or TX) are exposed. By default this board uses USB for
40+
terminal output.
41+
42+
See also `Waveshare P2040-Keyboard-3 wiki`_ and `schematic`_.
43+
44+
45+
Supported Features
46+
==================
47+
48+
.. zephyr:board-supported-hw::
49+
50+
51+
Programming and Debugging
52+
*************************
53+
54+
.. zephyr:board-supported-runners::
55+
56+
The board does not expose the SWDIO and SWCLK pins, so programming must be done via the USB port.
57+
Press and hold the BOOT button, and then press the RESET button, and the device will appear as
58+
a USB mass storage unit. Building your application will result in a :file:`build/zephyr/zephyr.uf2`
59+
file. Drag and drop the file to the USB mass storage unit, and the board will be reprogrammed.
60+
61+
For more details on programming RP2040-based boards, see :zephyr:board:`rpi_pico` and especially
62+
:ref:`rpi_pico_programming_and_debugging`.
63+
64+
65+
Flashing
66+
========
67+
68+
To run the :zephyr:code-sample:`led-strip` sample:
69+
70+
.. zephyr-app-commands::
71+
:zephyr-app: samples/drivers/led/led_strip/
72+
:board: rp2040_keyboard_3
73+
:goals: build flash
74+
75+
Try also the :zephyr:code-sample:`dining-philosophers`, :zephyr:code-sample:`input-dump` and
76+
:zephyr:code-sample:`button` samples.
77+
78+
Samples where text is printed only just at startup, for example :zephyr:code-sample:`hello_world`,
79+
are difficult to use as the text is already printed once you connect to the newly created
80+
USB console endpoint.
81+
82+
To run a program that acts as a keyboard (with the keys CTRL, C and V), use the
83+
:zephyr:code-sample:`usb-hid-keyboard` sample with some modifications. First remove the line
84+
``source "boards/common/usb/Kconfig.cdc_acm_serial.defconfig"`` from the
85+
:zephyr_file:`boards/waveshare/rp2040_keyboard_3/Kconfig.defconfig` file. Then do the
86+
modifications below to the :zephyr_file:`samples/subsys/usb/hid-keyboard/src/main.c` file.
87+
88+
Change:
89+
90+
.. code-block:: c
91+
92+
case INPUT_KEY_0:
93+
if (kb_evt.value) {
94+
report[KB_KEY_CODE1] = HID_KEY_NUMLOCK;
95+
} else {
96+
report[KB_KEY_CODE1] = 0;
97+
}
98+
99+
break;
100+
case INPUT_KEY_1:
101+
if (kb_evt.value) {
102+
report[KB_KEY_CODE2] = HID_KEY_CAPSLOCK;
103+
} else {
104+
report[KB_KEY_CODE2] = 0;
105+
}
106+
107+
break;
108+
case INPUT_KEY_2:
109+
if (kb_evt.value) {
110+
report[KB_KEY_CODE3] = HID_KEY_SCROLLLOCK;
111+
} else {
112+
report[KB_KEY_CODE3] = 0;
113+
}
114+
115+
break;
116+
117+
to:
118+
119+
.. code-block:: c
120+
121+
case INPUT_KEY_LEFTCTRL:
122+
if (kb_evt.value) {
123+
report[KB_MOD_KEY] = HID_KBD_MODIFIER_LEFT_CTRL;
124+
} else {
125+
report[KB_MOD_KEY] = 0;
126+
}
127+
128+
break;
129+
case INPUT_KEY_C:
130+
if (kb_evt.value) {
131+
report[KB_KEY_CODE1] = HID_KEY_C;
132+
} else {
133+
report[KB_KEY_CODE1] = 0;
134+
}
135+
136+
break;
137+
case INPUT_KEY_V:
138+
if (kb_evt.value) {
139+
report[KB_KEY_CODE1] = HID_KEY_V;
140+
} else {
141+
report[KB_KEY_CODE1] = 0;
142+
}
143+
144+
break;
145+
146+
147+
References
148+
**********
149+
150+
.. target-notes::
151+
152+
.. _Waveshare 3-Key Shortcut Keyboard Development Board:
153+
https://www.waveshare.com/rp2040-keyboard-3.htm
154+
155+
.. _Waveshare P2040-Keyboard-3 wiki:
156+
https://www.waveshare.com/wiki/RP2040-Keyboard-3
157+
158+
.. _schematic:
159+
https://files.waveshare.com/wiki/RP2040-Keyboard-3/RP2040-Keyboard-3-Schematic.pdf
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*
2+
* Copyright (c) 2021 Yonatan Schachter
3+
* Copyright (c) 2022 Peter Johanson
4+
* Copyright (c) 2025 Jonas Berg
5+
*
6+
* SPDX-License-Identifier: Apache-2.0
7+
*/
8+
9+
/dts-v1/;
10+
11+
#include <raspberrypi/rpi_pico/rp2040.dtsi>
12+
#include <dt-bindings/pinctrl/rpi-pico-rp2040-pinctrl.h>
13+
#include <zephyr/dt-bindings/input/input-event-codes.h>
14+
#include <zephyr/dt-bindings/led/led.h>
15+
16+
/ {
17+
model = "Waveshare RP2040 Keyboard 3";
18+
compatible = "waveshare,rp2040-keyboard-3";
19+
20+
chosen {
21+
zephyr,sram = &sram0;
22+
zephyr,flash = &flash0;
23+
zephyr,flash-controller = &ssi;
24+
zephyr,code-partition = &code_partition;
25+
};
26+
27+
aliases {
28+
watchdog0 = &wdt0;
29+
led-strip = &ws2812;
30+
sw0 = &button_ctrl;
31+
};
32+
33+
gpio_keys {
34+
compatible = "gpio-keys";
35+
36+
button_ctrl: button_ctrl {
37+
label = "CTRL";
38+
gpios = <&gpio0 14 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
39+
zephyr,code = <INPUT_KEY_LEFTCTRL>;
40+
};
41+
42+
button_c: button_c {
43+
label = "C";
44+
gpios = <&gpio0 13 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
45+
zephyr,code = <INPUT_KEY_C>;
46+
};
47+
48+
button_v: button_v {
49+
label = "V";
50+
gpios = <&gpio0 12 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
51+
zephyr,code = <INPUT_KEY_V>;
52+
};
53+
};
54+
};
55+
56+
&pinctrl {
57+
ws2812_pio0_default: ws2812_pio0_default {
58+
ws2812 {
59+
pinmux = <PIO0_P18>;
60+
};
61+
};
62+
};
63+
64+
&flash0 {
65+
reg = <0x10000000 DT_SIZE_M(2)>;
66+
67+
partitions {
68+
compatible = "fixed-partitions";
69+
#address-cells = <1>;
70+
#size-cells = <1>;
71+
72+
/* Reserved memory for the second stage bootloader */
73+
second_stage_bootloader: partition@0 {
74+
label = "second_stage_bootloader";
75+
reg = <0x00000000 0x100>;
76+
read-only;
77+
};
78+
79+
/*
80+
* Usable flash. Starts at 0x100, after the bootloader. The partition
81+
* size is 2 MB minus the 0x100 bytes taken by the bootloader.
82+
*/
83+
code_partition: partition@100 {
84+
label = "code-partition";
85+
reg = <0x100 (DT_SIZE_M(2) - 0x100)>;
86+
read-only;
87+
};
88+
};
89+
};
90+
91+
&gpio0 {
92+
status = "okay";
93+
};
94+
95+
&adc {
96+
status = "okay";
97+
#address-cells = <1>;
98+
#size-cells = <0>;
99+
};
100+
101+
&timer {
102+
status = "okay";
103+
};
104+
105+
&wdt0 {
106+
status = "okay";
107+
};
108+
109+
&pio0 {
110+
status = "okay";
111+
112+
pio-ws2812 {
113+
compatible = "worldsemi,ws2812-rpi_pico-pio";
114+
status = "okay";
115+
pinctrl-0 = <&ws2812_pio0_default>;
116+
pinctrl-names = "default";
117+
bit-waveform = <3>, <3>, <4>;
118+
119+
ws2812: ws2812 {
120+
status = "okay";
121+
gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;
122+
chain-length = <3>;
123+
color-mapping = <LED_COLOR_ID_GREEN
124+
LED_COLOR_ID_RED
125+
LED_COLOR_ID_BLUE>;
126+
reset-delay = <280>;
127+
frequency = <800000>;
128+
};
129+
};
130+
};
131+
132+
zephyr_udc0: &usbd {
133+
status = "okay";
134+
};
135+
136+
&die_temp {
137+
status = "okay";
138+
};
139+
140+
&vreg {
141+
regulator-always-on;
142+
regulator-allowed-modes = <REGULATOR_RPI_PICO_MODE_NORMAL>;
143+
};
144+
145+
&xosc {
146+
startup-delay-multiplier = <64>;
147+
};
148+
149+
#include <../boards/common/usb/cdc_acm_serial.dtsi>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
identifier: rp2040_keyboard_3
2+
name: Waveshare RP2040-Keyboard-3
3+
type: mcu
4+
arch: arm
5+
flash: 2048
6+
ram: 264
7+
toolchain:
8+
- zephyr
9+
- gnuarmemb
10+
supported:
11+
- clock
12+
- counter
13+
- dma
14+
- flash
15+
- gpio
16+
- hwinfo
17+
- usb
18+
- watchdog
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Jonas Berg
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_BUILD_OUTPUT_UF2=y
5+
CONFIG_CLOCK_CONTROL=y
6+
CONFIG_GPIO=y
7+
CONFIG_PIO_RPI_PICO=y
8+
CONFIG_RESET=y
9+
CONFIG_USE_DT_CODE_PARTITION=y

0 commit comments

Comments
 (0)