From 5f5a3def6eafa91432bd83edbff02a8cce2d08e4 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sun, 8 Sep 2024 14:15:59 +0100 Subject: [PATCH] fw: add ploopy_mouse_nrf --- .github/workflows/build.yml | 1 + .../balto/ploopy_mouse_nrf/CMakeLists.txt | 3 + .../balto/ploopy_mouse_nrf/Kconfig.defconfig | 6 + .../ploopy_mouse_nrf/Kconfig.ploopy_mouse_nrf | 2 + .../boards/balto/ploopy_mouse_nrf/board.c | 28 ++ .../boards/balto/ploopy_mouse_nrf/board.cmake | 6 + .../boards/balto/ploopy_mouse_nrf/board.yml | 5 + .../ploopy_mouse_nrf-pinctrl.dtsi | 33 +++ .../ploopy_mouse_nrf/ploopy_mouse_nrf.dts | 243 ++++++++++++++++++ .../ploopy_mouse_nrf_defconfig | 5 + .../boards/balto/ploopy_mouse_nrf/pmw_power.c | 36 +++ .../balto/ploopy_mouse_nrf/pre_dt_board.cmake | 1 + firmware/boards/ploopy_mouse_nrf.conf | 11 + 13 files changed, 380 insertions(+) create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/CMakeLists.txt create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/Kconfig.defconfig create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/Kconfig.ploopy_mouse_nrf create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/board.c create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/board.cmake create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/board.yml create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf-pinctrl.dtsi create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf.dts create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf_defconfig create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/pmw_power.c create mode 100644 firmware/boards/balto/ploopy_mouse_nrf/pre_dt_board.cmake create mode 100644 firmware/boards/ploopy_mouse_nrf.conf diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2d16398..a145886 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,6 +28,7 @@ jobs: - nrf52dk/nrf52832 - paw_pogo - paw_testboard + - ploopy_mouse_nrf - pmw_testboard - zalpakka diff --git a/firmware/boards/balto/ploopy_mouse_nrf/CMakeLists.txt b/firmware/boards/balto/ploopy_mouse_nrf/CMakeLists.txt new file mode 100644 index 0000000..6ef62d1 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/CMakeLists.txt @@ -0,0 +1,3 @@ +zephyr_library() +zephyr_library_sources(pmw_power.c) +zephyr_library_sources(board.c) diff --git a/firmware/boards/balto/ploopy_mouse_nrf/Kconfig.defconfig b/firmware/boards/balto/ploopy_mouse_nrf/Kconfig.defconfig new file mode 100644 index 0000000..4258db1 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/Kconfig.defconfig @@ -0,0 +1,6 @@ +if BOARD_PLOOPY_MOUSE_NRF + +config BT_CTLR + default BT + +endif diff --git a/firmware/boards/balto/ploopy_mouse_nrf/Kconfig.ploopy_mouse_nrf b/firmware/boards/balto/ploopy_mouse_nrf/Kconfig.ploopy_mouse_nrf new file mode 100644 index 0000000..7d46ade --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/Kconfig.ploopy_mouse_nrf @@ -0,0 +1,2 @@ +config BOARD_PLOOPY_MOUSE_NRF + select SOC_NRF52833_QDAA diff --git a/firmware/boards/balto/ploopy_mouse_nrf/board.c b/firmware/boards/balto/ploopy_mouse_nrf/board.c new file mode 100644 index 0000000..6dda8a6 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/board.c @@ -0,0 +1,28 @@ +#include +#include + +static int board_regulator_init(void) +{ + if ((nrf_power_mainregstatus_get(NRF_POWER) == NRF_POWER_MAINREGSTATUS_HIGH) && + (NRF_UICR->REGOUT0 & UICR_REGOUT0_VOUT_Msk) == (UICR_REGOUT0_VOUT_DEFAULT << UICR_REGOUT0_VOUT_Pos)) { + + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { + ; + } + + NRF_UICR->REGOUT0 = (NRF_UICR->REGOUT0 & ~((uint32_t)UICR_REGOUT0_VOUT_Msk)) | + (UICR_REGOUT0_VOUT_3V3 << UICR_REGOUT0_VOUT_Pos); + + NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos; + while (NRF_NVMC->READY == NVMC_READY_READY_Busy) { + ; + } + + NVIC_SystemReset(); + } + + return 0; +} + +SYS_INIT(board_regulator_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); diff --git a/firmware/boards/balto/ploopy_mouse_nrf/board.cmake b/firmware/boards/balto/ploopy_mouse_nrf/board.cmake new file mode 100644 index 0000000..bde54dd --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/board.cmake @@ -0,0 +1,6 @@ +board_runner_args(nrfjprog "--softreset") +board_runner_args(jlink "--device=nRF52833_xxAA" "--speed=4000") + +include(${ZEPHYR_BASE}/boards/common/nrfjprog.board.cmake) +include(${ZEPHYR_BASE}/boards/common/nrfutil.board.cmake) +include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) diff --git a/firmware/boards/balto/ploopy_mouse_nrf/board.yml b/firmware/boards/balto/ploopy_mouse_nrf/board.yml new file mode 100644 index 0000000..9becaa2 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/board.yml @@ -0,0 +1,5 @@ +board: + name: ploopy_mouse_nrf + vendor: balto + socs: + - name: nrf52833 diff --git a/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf-pinctrl.dtsi b/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf-pinctrl.dtsi new file mode 100644 index 0000000..a6594f5 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf-pinctrl.dtsi @@ -0,0 +1,33 @@ +&pinctrl { + i2c0_default: i2c0_default { + group1 { + psels = , + ; + }; + }; + + i2c0_sleep: i2c0_sleep { + group1 { + psels = , + ; + low-power-enable; + }; + }; + + spi1_default: spi1_default { + group1 { + psels = , + , + ; + }; + }; + + spi1_sleep: spi1_sleep { + group1 { + psels = , + , + ; + low-power-enable; + }; + }; +}; diff --git a/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf.dts b/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf.dts new file mode 100644 index 0000000..bbe98a5 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf.dts @@ -0,0 +1,243 @@ +/dts-v1/; +#include +#include "ploopy_mouse_nrf-pinctrl.dtsi" +#include +#include +#include + +/ { + model = "Ploopy Mouse nRF"; + compatible = "balto,ploopy-mouse-nrf"; + + chosen { + zephyr,sram = &sram0; + zephyr,flash = &flash0; + zephyr,code-partition = &slot0_partition; + }; + + leds { + compatible = "gpio-leds"; + led_status: led_a { + gpios = <&pcal6408a 3 GPIO_ACTIVE_HIGH>; + }; + led_input_activity: led_b { + gpios = <&pcal6408a 2 GPIO_ACTIVE_HIGH>; + }; + }; + + buttons: buttons { + compatible = "gpio-keys"; + debounce-interval-ms = <3>; + + sw_0 { + gpios = <&pcal6408a 7 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + sw_1 { + gpios = <&pcal6408a 6 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + sw_2 { + gpios = <&gpio0 31 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + sw_3 { + gpios = <&pcal6408a 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + sw_4 { + gpios = <&gpio0 18 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + sw_5 { + gpios = <&pcal6408a 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + sw_6 { + gpios = <&pcal6408a 4 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + sw_7 { + gpios = <&pcal6408a 5 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + zephyr,code = ; + }; + }; + + gpio_qdec: qdec { + compatible = "gpio-qdec"; + gpios = <&gpio0 17 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>, + <&gpio0 20 (GPIO_PULL_UP | GPIO_ACTIVE_HIGH)>; + steps-per-period = <2>; + zephyr,axis = ; + sample-time-us = <2000>; + idle-timeout-ms = <200>; + }; + + + vbatt: vbatt { + compatible = "voltage-divider"; + io-channels = <&adc 0>; + output-ohms = <(560 * 1000)>; + full-ohms = <(560 * 1000 * 2)>; + }; + + fuel_gauge: fuel_gauge_composite { + compatible = "zephyr,fuel-gauge-composite"; + battery-voltage = <&vbatt>; + device-chemistry = "lithium-ion-polymer"; + ocv-capacity-table-0 = ; + }; + + reg_1v8: reg_1v8{ + compatible = "regulator-fixed"; + regulator-name = "reg_1v8"; + enable-gpios = <&gpio0 10 GPIO_ACTIVE_HIGH>; + regulator-boot-on; + }; + + hid { + compatible = "hid"; + input { + hid-mouse { + compatible = "hid-mouse"; + input = <&pmw &gpio_qdec &buttons>; + input-id = <1>; + report = ; + }; + }; + output { + hid-hog { + compatible = "hid-hog"; + }; + usb-hid { + compatible = "usb-hid"; + usb-hid-dev = <&hid_dev_0>; + }; + }; + }; + + hid_dev_0: hid_dev_0 { + compatible = "zephyr,hid-device"; + interface-name = "HID0"; + in-report-size = <16>; + in-polling-period-us = <1000>; + }; + + ble-unpair { + input = <&buttons>; + compatible = "ble-unpair"; + key-a = ; + key-b = ; + }; +}; + +&uicr { + nfct-pins-as-gpios; +}; + +®1 { + regulator-initial-mode = ; +}; + +&adc { + status = "okay"; + #address-cells = <1>; + #size-cells = <0>; + + channel@0 { + reg = <0>; + zephyr,gain = "ADC_GAIN_1_6"; + zephyr,reference = "ADC_REF_INTERNAL"; + zephyr,acquisition-time = ; + zephyr,input-positive = ; + zephyr,resolution = <10>; + }; +}; + +&gpiote { + status = "okay"; +}; + +&gpio0 { + status = "okay"; +}; + +&gpio1 { + status = "okay"; +}; + +&i2c0 { + compatible = "nordic,nrf-twi"; + status = "okay"; + pinctrl-0 = <&i2c0_default>; + pinctrl-1 = <&i2c0_sleep>; + pinctrl-names = "default", "sleep"; + + pcal6408a: pcal6408a@20 { + compatible = "nxp,pcal6408a"; + status = "okay"; + reg = <0x20>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <8>; + reset-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>; + int-gpios = <&gpio1 9 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; + }; + + charger: bq25180@6a { + compatible = "ti,bq25180"; + reg = <0x6a>; + constant-charge-current-max-microamp = <500000>; + }; +}; + +&spi1 { + compatible = "nordic,nrf-spi"; + status = "okay"; + pinctrl-0 = <&spi1_default>; + pinctrl-1 = <&spi1_sleep>; + pinctrl-names = "default", "sleep"; + + cs-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>; + + sensor: pmw: pmw3610@0 { + compatible = "pixart,pmw3610"; + reg = <0>; + spi-max-frequency = ; + motion-gpios = <&gpio0 3 GPIO_ACTIVE_LOW>; + zephyr,axis-x = ; + zephyr,axis-y = ; + res-cpi = <800>; + invert-y; + }; +}; + +&flash0 { + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + boot_partition: partition@0 { + label = "mcuboot"; + reg = <0x00000000 0xC000>; + }; + slot0_partition: partition@c000 { + label = "image-0"; + reg = <0x0000C000 0x37000>; + }; + slot1_partition: partition@43000 { + label = "image-1"; + reg = <0x00043000 0x37000>; + }; + storage_partition: partition@7a000 { + label = "storage"; + reg = <0x0007A000 0x00006000>; + }; + }; +}; + +zephyr_udc0: &usbd { + compatible = "nordic,nrf-usbd"; + status = "okay"; +}; diff --git a/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf_defconfig b/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf_defconfig new file mode 100644 index 0000000..dd9c7f0 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/ploopy_mouse_nrf_defconfig @@ -0,0 +1,5 @@ +CONFIG_ARM_MPU=y +CONFIG_HW_STACK_PROTECTION=y +CONFIG_USE_SEGGER_RTT=y +CONFIG_GPIO=y +CONFIG_CONSOLE=y diff --git a/firmware/boards/balto/ploopy_mouse_nrf/pmw_power.c b/firmware/boards/balto/ploopy_mouse_nrf/pmw_power.c new file mode 100644 index 0000000..a78d7f4 --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/pmw_power.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +LOG_MODULE_REGISTER(pmw_power, LOG_LEVEL_INF); + +#define PMW_NODE DT_NODELABEL(pmw) + +#define FORCE_AWAKE_TIMEOUT_S 30 + +static const struct device *const pmw = DEVICE_DT_GET(PMW_NODE); + +static bool force_awake; + +static void sleep_handler(struct k_work *work) +{ + pmw3610_force_awake(pmw, false); + force_awake = false; + + LOG_DBG("sleep"); +} + +K_WORK_DELAYABLE_DEFINE(sleep_dwork, sleep_handler); + +static void pmw_cb(struct input_event *evt, void *user_data) +{ + if (!force_awake) { + pmw3610_force_awake(pmw, true); + force_awake = true; + LOG_DBG("awake"); + } + + k_work_reschedule(&sleep_dwork, K_SECONDS(FORCE_AWAKE_TIMEOUT_S)); +} +INPUT_CALLBACK_DEFINE(pmw, pmw_cb, NULL); diff --git a/firmware/boards/balto/ploopy_mouse_nrf/pre_dt_board.cmake b/firmware/boards/balto/ploopy_mouse_nrf/pre_dt_board.cmake new file mode 100644 index 0000000..aaa56af --- /dev/null +++ b/firmware/boards/balto/ploopy_mouse_nrf/pre_dt_board.cmake @@ -0,0 +1 @@ +list(APPEND EXTRA_DTC_FLAGS "-Wno-unique_unit_address_if_enabled") diff --git a/firmware/boards/ploopy_mouse_nrf.conf b/firmware/boards/ploopy_mouse_nrf.conf new file mode 100644 index 0000000..97847fc --- /dev/null +++ b/firmware/boards/ploopy_mouse_nrf.conf @@ -0,0 +1,11 @@ +CONFIG_SHELL_BACKEND_RTT=y +CONFIG_SHELL_TAB=y +CONFIG_SHELL_VT100_COMMANDS=y +CONFIG_CONSOLE=y +CONFIG_REGULATOR=y + +CONFIG_APP_DEVICE_NAME="Ploopy Mouse nRF" + +CONFIG_BT=y +CONFIG_USB_DEVICE_STACK=n +CONFIG_USB_DEVICE_STACK_NEXT=y