From 861b3fc0daa86ba29e6b9826640e9104969c9f46 Mon Sep 17 00:00:00 2001 From: zzhujf <1240893074@qq.com> Date: Sat, 25 May 2024 21:51:01 +0800 Subject: [PATCH 01/16] Remove function --- keyboards/nuphy/air75_v2/ansi/ansi.c | 2 -- lib/chibios-contrib | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/ansi.c b/keyboards/nuphy/air75_v2/ansi/ansi.c index 33cdcb4de3d0..f8c8333a0a45 100644 --- a/keyboards/nuphy/air75_v2/ansi/ansi.c +++ b/keyboards/nuphy/air75_v2/ansi/ansi.c @@ -271,6 +271,4 @@ void housekeeping_task_kb(void) { side_led_show(); sleep_handle(); - - housekeeping_task_user(); } diff --git a/lib/chibios-contrib b/lib/chibios-contrib index 9d7a7f904ed1..da78eb3759b8 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit 9d7a7f904ed135e3459cf6d602db56a26872df6b +Subproject commit da78eb3759b8d1779b237657c7667baa4aa95ca1 From f9df7f4ac0efe9049432324a78a6faa98a77886e Mon Sep 17 00:00:00 2001 From: nuphy-scr Date: Sun, 26 May 2024 14:10:56 +0800 Subject: [PATCH 02/16] update PID --- keyboards/nuphy/air75_v2/ansi/info.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keyboards/nuphy/air75_v2/ansi/info.json b/keyboards/nuphy/air75_v2/ansi/info.json index 5626507cc884..ac90d7ba5f14 100644 --- a/keyboards/nuphy/air75_v2/ansi/info.json +++ b/keyboards/nuphy/air75_v2/ansi/info.json @@ -3,7 +3,7 @@ "manufacturer": "NuPhy", "usb":{ "vid": "0x19F5", - "pid": "0x3245", + "pid": "0x3246", "device_version": "0.0.1", "no_startup_check": true }, From 3dfbeb1b718f5a7775c5ac448022e6349f5e00cf Mon Sep 17 00:00:00 2001 From: nuphy-scr Date: Sun, 26 May 2024 15:28:21 +0800 Subject: [PATCH 03/16] Rename user_kb.c to kb_util.c --- keyboards/nuphy/air75_v2/ansi/ansi.c | 2 +- keyboards/nuphy/air75_v2/ansi/{user_kb.c => kb_util.c} | 2 +- keyboards/nuphy/air75_v2/ansi/{user_kb.h => kb_util.h} | 0 keyboards/nuphy/air75_v2/ansi/rf.c | 2 +- keyboards/nuphy/air75_v2/ansi/rf_driver.c | 2 +- keyboards/nuphy/air75_v2/ansi/rules.mk | 2 +- keyboards/nuphy/air75_v2/ansi/side.c | 2 +- keyboards/nuphy/air75_v2/ansi/sleep.c | 2 +- 8 files changed, 7 insertions(+), 7 deletions(-) rename keyboards/nuphy/air75_v2/ansi/{user_kb.c => kb_util.c} (99%) rename keyboards/nuphy/air75_v2/ansi/{user_kb.h => kb_util.h} (100%) diff --git a/keyboards/nuphy/air75_v2/ansi/ansi.c b/keyboards/nuphy/air75_v2/ansi/ansi.c index f8c8333a0a45..16fd2cb4b856 100644 --- a/keyboards/nuphy/air75_v2/ansi/ansi.c +++ b/keyboards/nuphy/air75_v2/ansi/ansi.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "user_kb.h" +#include "kb_util.h" #include "ansi.h" #include "usb_main.h" diff --git a/keyboards/nuphy/air75_v2/ansi/user_kb.c b/keyboards/nuphy/air75_v2/ansi/kb_util.c similarity index 99% rename from keyboards/nuphy/air75_v2/ansi/user_kb.c rename to keyboards/nuphy/air75_v2/ansi/kb_util.c index d8341721a1ed..b84d4b541837 100644 --- a/keyboards/nuphy/air75_v2/ansi/user_kb.c +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "user_kb.h" +#include "kb_util.h" #include "ansi.h" #include "usb_main.h" #include "rf_driver.h" diff --git a/keyboards/nuphy/air75_v2/ansi/user_kb.h b/keyboards/nuphy/air75_v2/ansi/kb_util.h similarity index 100% rename from keyboards/nuphy/air75_v2/ansi/user_kb.h rename to keyboards/nuphy/air75_v2/ansi/kb_util.h diff --git a/keyboards/nuphy/air75_v2/ansi/rf.c b/keyboards/nuphy/air75_v2/ansi/rf.c index baf42c8b5ff0..31369c40cb3a 100644 --- a/keyboards/nuphy/air75_v2/ansi/rf.c +++ b/keyboards/nuphy/air75_v2/ansi/rf.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "user_kb.h" +#include "kb_util.h" #include "uart.h" // qmk uart.h #include "ansi.h" #include "rf_driver.h" diff --git a/keyboards/nuphy/air75_v2/ansi/rf_driver.c b/keyboards/nuphy/air75_v2/ansi/rf_driver.c index f5b766521313..65db72c6deff 100644 --- a/keyboards/nuphy/air75_v2/ansi/rf_driver.c +++ b/keyboards/nuphy/air75_v2/ansi/rf_driver.c @@ -18,7 +18,7 @@ along with this program. If not, see . #include "host_driver.h" #include "rf_driver.h" #include "host.h" -#include "user_kb.h" +#include "kb_util.h" /* Variable declaration */ extern DEV_INFO_STRUCT dev_info; diff --git a/keyboards/nuphy/air75_v2/ansi/rules.mk b/keyboards/nuphy/air75_v2/ansi/rules.mk index 824c6891edf3..31ccc14d28fe 100644 --- a/keyboards/nuphy/air75_v2/ansi/rules.mk +++ b/keyboards/nuphy/air75_v2/ansi/rules.mk @@ -1,3 +1,3 @@ -SRC += side.c rf.c sleep.c rf_driver.c user_kb.c side_driver.c +SRC += side.c rf.c sleep.c rf_driver.c kb_util.c side_driver.c UART_DRIVER_REQUIRED = yes diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index 461f6b0195d4..3debd1d92d7a 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "user_kb.h" +#include "kb_util.h" #include "ansi.h" #include "side_table.h" #include "ws2812.h" diff --git a/keyboards/nuphy/air75_v2/ansi/sleep.c b/keyboards/nuphy/air75_v2/ansi/sleep.c index 4a86a99bf240..61bf545ba844 100644 --- a/keyboards/nuphy/air75_v2/ansi/sleep.c +++ b/keyboards/nuphy/air75_v2/ansi/sleep.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include "user_kb.h" +#include "kb_util.h" #include "ansi.h" #include "hal_usb.h" #include "usb_main.h" From e91d3dfee3e933782579ee224e1d61324c967962 Mon Sep 17 00:00:00 2001 From: nuphy-scr Date: Sun, 26 May 2024 17:33:14 +0800 Subject: [PATCH 04/16] Update macro names --- keyboards/nuphy/air75_v2/ansi/kb_util.c | 48 ++++++++++----------- keyboards/nuphy/air75_v2/ansi/rf.c | 8 ++-- keyboards/nuphy/air75_v2/ansi/side.c | 20 ++++----- keyboards/nuphy/air75_v2/ansi/side_driver.c | 8 ++-- keyboards/nuphy/air75_v2/ansi/sleep.c | 18 ++++---- 5 files changed, 51 insertions(+), 51 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/kb_util.c b/keyboards/nuphy/air75_v2/ansi/kb_util.c index b84d4b541837..bb18df1105c0 100644 --- a/keyboards/nuphy/air75_v2/ansi/kb_util.c +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.c @@ -63,28 +63,28 @@ extern uint8_t side_colour; */ void gpio_init(void) { /* enable led power driver */ - setPinOutput(DRIVER_LED_CS_PIN); - setPinOutput(DRIVER_SIDE_CS_PIN); - writePinLow(DRIVER_LED_CS_PIN); - writePinLow(DRIVER_SIDE_CS_PIN); + gpio_set_pin_output_push_pull(DRIVER_LED_CS_PIN); + gpio_set_pin_output_push_pull(DRIVER_SIDE_CS_PIN); + gpio_write_pin_low(DRIVER_LED_CS_PIN); + gpio_write_pin_low(DRIVER_SIDE_CS_PIN); /* set side led pin output low */ - setPinOutput(DRIVER_SIDE_PIN); - writePinLow(DRIVER_SIDE_PIN); + gpio_set_pin_output_push_pull(DRIVER_SIDE_PIN); + gpio_write_pin_low(DRIVER_SIDE_PIN); /* config RF module pin */ - setPinOutput(NRF_WAKEUP_PIN); - writePinHigh(NRF_WAKEUP_PIN); - setPinInputHigh(NRF_TEST_PIN); + gpio_set_pin_output_push_pull(NRF_WAKEUP_PIN); + gpio_write_pin_high(NRF_WAKEUP_PIN); + gpio_set_pin_input_high(NRF_TEST_PIN); /* reset RF module */ - setPinOutput(NRF_RESET_PIN); - writePinLow(NRF_RESET_PIN); + gpio_set_pin_output_push_pull(NRF_RESET_PIN); + gpio_write_pin_low(NRF_RESET_PIN); wait_ms(50); - writePinHigh(NRF_RESET_PIN); + gpio_write_pin_high(NRF_RESET_PIN); /* config dial switch pin */ - setPinInputHigh(DEV_MODE_PIN); - setPinInputHigh(SYS_MODE_PIN); + gpio_set_pin_input_high(DEV_MODE_PIN); + gpio_set_pin_input_high(SYS_MODE_PIN); /* open led DC driver */ - setPinOutput(DC_BOOST_PIN); - writePinHigh(DC_BOOST_PIN); + gpio_set_pin_output_push_pull(DC_BOOST_PIN); + gpio_write_pin_high(DC_BOOST_PIN); } /** @@ -246,11 +246,11 @@ void dial_sw_scan(void) { } dial_scan_timer = timer_read32(); - setPinInputHigh(DEV_MODE_PIN); - setPinInputHigh(SYS_MODE_PIN); + gpio_set_pin_input_high(DEV_MODE_PIN); + gpio_set_pin_input_high(SYS_MODE_PIN); - if (readPin(DEV_MODE_PIN)) dial_scan |= 0X01; - if (readPin(SYS_MODE_PIN)) dial_scan |= 0X02; + if (gpio_read_pin(DEV_MODE_PIN)) dial_scan |= 0X01; + if (gpio_read_pin(SYS_MODE_PIN)) dial_scan |= 0X02; if (dial_save != dial_scan) { break_all_key(); @@ -316,16 +316,16 @@ void dial_sw_fast_scan(void) { uint8_t dial_check_sys = 0; uint8_t debounce = 0; - setPinInputHigh(DEV_MODE_PIN); - setPinInputHigh(SYS_MODE_PIN); + gpio_set_pin_input_high(DEV_MODE_PIN); + gpio_set_pin_input_high(SYS_MODE_PIN); // Debounce to get a stable state for(debounce=0; debounce<10; debounce++) { dial_scan_dev = 0; dial_scan_sys = 0; - if (readPin(DEV_MODE_PIN)) dial_scan_dev = 0x01; + if (gpio_read_pin(DEV_MODE_PIN)) dial_scan_dev = 0x01; else dial_scan_dev = 0; - if (readPin(SYS_MODE_PIN)) dial_scan_sys = 0x01; + if (gpio_read_pin(SYS_MODE_PIN)) dial_scan_sys = 0x01; else dial_scan_sys = 0; if((dial_scan_dev != dial_check_dev)||(dial_scan_sys != dial_check_sys)) { diff --git a/keyboards/nuphy/air75_v2/ansi/rf.c b/keyboards/nuphy/air75_v2/ansi/rf.c index 31369c40cb3a..9efd372e4261 100644 --- a/keyboards/nuphy/air75_v2/ansi/rf.c +++ b/keyboards/nuphy/air75_v2/ansi/rf.c @@ -447,9 +447,9 @@ void dev_sts_sync(void) { if (f_rf_reset) { f_rf_reset = 0; wait_ms(100); - writePinLow(NRF_RESET_PIN); + gpio_write_pin_low(NRF_RESET_PIN); wait_ms(50); - writePinHigh(NRF_RESET_PIN); + gpio_write_pin_high(NRF_RESET_PIN); wait_ms(50); } else if (f_send_channel) { @@ -509,13 +509,13 @@ void dev_sts_sync(void) { * @param Length data lenght */ void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length) { - writePinLow(NRF_WAKEUP_PIN); + gpio_write_pin_low(NRF_WAKEUP_PIN); wait_us(50); uart_transmit(Buffer, Length); wait_us(50 + Length * 30); - writePinHigh(NRF_WAKEUP_PIN); + gpio_write_pin_high(NRF_WAKEUP_PIN); } /** diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index 3debd1d92d7a..38d46aa65a64 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -718,11 +718,11 @@ void bat_led_show(void) { */ void device_reset_show(void) { - writePinHigh(DC_BOOST_PIN); - setPinOutput(DRIVER_SIDE_CS_PIN); - setPinOutput(DRIVER_LED_CS_PIN); - writePinLow(DRIVER_SIDE_CS_PIN); - writePinLow(DRIVER_LED_CS_PIN); + gpio_write_pin_high(DC_BOOST_PIN); + gpio_set_pin_output_push_pull(DRIVER_SIDE_CS_PIN); + gpio_set_pin_output_push_pull(DRIVER_LED_CS_PIN); + gpio_write_pin_low(DRIVER_SIDE_CS_PIN); + gpio_write_pin_low(DRIVER_LED_CS_PIN); for (int blink_cnt = 0; blink_cnt < 3; blink_cnt++) { rgb_matrix_set_color_all(0x10, 0x10, 0x10); @@ -778,11 +778,11 @@ void device_reset_init(void) { void rgb_test_show(void) { // open power control - writePinHigh(DC_BOOST_PIN); - setPinOutput(DRIVER_LED_CS_PIN); - writePinLow(DRIVER_LED_CS_PIN); - setPinOutput(DRIVER_SIDE_CS_PIN); - writePinLow(DRIVER_SIDE_CS_PIN); + gpio_write_pin_high(DC_BOOST_PIN); + gpio_set_pin_output_push_pull(DRIVER_LED_CS_PIN); + gpio_write_pin_low(DRIVER_LED_CS_PIN); + gpio_set_pin_output_push_pull(DRIVER_SIDE_CS_PIN); + gpio_write_pin_low(DRIVER_SIDE_CS_PIN); // set test color rgb_matrix_set_color_all(0xFF, 0x00, 0x00); diff --git a/keyboards/nuphy/air75_v2/ansi/side_driver.c b/keyboards/nuphy/air75_v2/ansi/side_driver.c index 5f20a33c18d5..7ecdc52db5b8 100644 --- a/keyboards/nuphy/air75_v2/ansi/side_driver.c +++ b/keyboards/nuphy/air75_v2/ansi/side_driver.c @@ -73,15 +73,15 @@ void side_sendByte(uint8_t byte) // using something like wait_ns(is_one ? T1L : T0L) here throws off timings if (is_one) { // 1 - writePinHigh(DRIVER_SIDE_PIN); + gpio_write_pin_high(DRIVER_SIDE_PIN); wait_ns(WS2812_T1H); - writePinLow(DRIVER_SIDE_PIN); + gpio_write_pin_low(DRIVER_SIDE_PIN); wait_ns(WS2812_T1L); } else { // 0 - writePinHigh(DRIVER_SIDE_PIN); + gpio_write_pin_high(DRIVER_SIDE_PIN); wait_ns(WS2812_T0H); - writePinLow(DRIVER_SIDE_PIN); + gpio_write_pin_low(DRIVER_SIDE_PIN); wait_ns(WS2812_T0L); } } diff --git a/keyboards/nuphy/air75_v2/ansi/sleep.c b/keyboards/nuphy/air75_v2/ansi/sleep.c index 61bf545ba844..e553262f9c67 100644 --- a/keyboards/nuphy/air75_v2/ansi/sleep.c +++ b/keyboards/nuphy/air75_v2/ansi/sleep.c @@ -52,11 +52,11 @@ void sleep_handle(void) { uart_send_cmd(CMD_SLEEP, 5, 5); // power off led - setPinOutput(DC_BOOST_PIN); - writePinLow(DC_BOOST_PIN); + gpio_set_pin_output_push_pull(DC_BOOST_PIN); + gpio_write_pin_low(DC_BOOST_PIN); - setPinInput(DRIVER_LED_CS_PIN); - setPinInput(DRIVER_SIDE_CS_PIN); + gpio_set_pin_input(DRIVER_LED_CS_PIN); + gpio_set_pin_input(DRIVER_SIDE_CS_PIN); } f_wakeup_prepare = 1; @@ -66,12 +66,12 @@ void sleep_handle(void) { if (f_wakeup_prepare && (no_act_time < 10)) { f_wakeup_prepare = 0; - writePinHigh(DC_BOOST_PIN); + gpio_write_pin_high(DC_BOOST_PIN); - setPinOutput(DRIVER_LED_CS_PIN); - writePinLow(DRIVER_LED_CS_PIN); - setPinOutput(DRIVER_SIDE_CS_PIN); - writePinLow(DRIVER_SIDE_CS_PIN); + gpio_set_pin_output_push_pull(DRIVER_LED_CS_PIN); + gpio_write_pin_low(DRIVER_LED_CS_PIN); + gpio_set_pin_output_push_pull(DRIVER_SIDE_CS_PIN); + gpio_write_pin_low(DRIVER_SIDE_CS_PIN); uart_send_cmd(CMD_HAND, 0, 1); From 1be7573fd45f6207ce17ebfb4273ea3627fdc3c3 Mon Sep 17 00:00:00 2001 From: nuphy-scr Date: Sun, 26 May 2024 18:27:44 +0800 Subject: [PATCH 05/16] Update submodule to latest version --- lib/chibios | 2 +- lib/chibios-contrib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chibios b/lib/chibios index 11edb1610980..0062927e3058 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit 11edb1610980f213b9f83161e1715a46fb7e4c51 +Subproject commit 0062927e3058a8b5ef587234bbd98d42fb4e595e diff --git a/lib/chibios-contrib b/lib/chibios-contrib index da78eb3759b8..a224be155ae1 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit da78eb3759b8d1779b237657c7667baa4aa95ca1 +Subproject commit a224be155ae18d38deccf33a6c1d259b9a5ad8d3 From c9ba22d93983db37b7ec9be4324b601a93b735af Mon Sep 17 00:00:00 2001 From: nuphy-scr Date: Sun, 26 May 2024 22:49:41 +0800 Subject: [PATCH 06/16] revert lib/chibios-contrib --- lib/chibios-contrib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chibios-contrib b/lib/chibios-contrib index a224be155ae1..99f32d13c6f7 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit a224be155ae18d38deccf33a6c1d259b9a5ad8d3 +Subproject commit 99f32d13c6f75c43e7ce4b53389fd284983eecb6 From 77b1d30edacc35f4e04f16f9f673c939a2bfcd37 Mon Sep 17 00:00:00 2001 From: nuphy-src Date: Mon, 27 May 2024 11:43:53 +0800 Subject: [PATCH 07/16] Update submodule --- lib/chibios | 2 +- lib/chibios-contrib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chibios b/lib/chibios index 0062927e3058..11edb1610980 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit 0062927e3058a8b5ef587234bbd98d42fb4e595e +Subproject commit 11edb1610980f213b9f83161e1715a46fb7e4c51 diff --git a/lib/chibios-contrib b/lib/chibios-contrib index 99f32d13c6f7..9d7a7f904ed1 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit 99f32d13c6f75c43e7ce4b53389fd284983eecb6 +Subproject commit 9d7a7f904ed135e3459cf6d602db56a26872df6b From 232002e713007bd390adef1835b8c56d55710865 Mon Sep 17 00:00:00 2001 From: nuphy-src Date: Sun, 2 Jun 2024 13:34:20 +0800 Subject: [PATCH 08/16] update --- lib/chibios | 2 +- lib/chibios-contrib | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chibios b/lib/chibios index 11edb1610980..0062927e3058 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit 11edb1610980f213b9f83161e1715a46fb7e4c51 +Subproject commit 0062927e3058a8b5ef587234bbd98d42fb4e595e diff --git a/lib/chibios-contrib b/lib/chibios-contrib index 9d7a7f904ed1..77cb0a4f7589 160000 --- a/lib/chibios-contrib +++ b/lib/chibios-contrib @@ -1 +1 @@ -Subproject commit 9d7a7f904ed135e3459cf6d602db56a26872df6b +Subproject commit 77cb0a4f7589f89e724f5e6ecb1d76d514dd1212 From 0d292806270a257ec49a7f4aa6ea61bb422f1f62 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sun, 16 Jun 2024 05:50:58 +1000 Subject: [PATCH 09/16] Fix chibios submodule version by setting to upstream commit ref Reverting the commits that modified this would be preferable, but merge commits make that an ugly process --- lib/chibios | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chibios b/lib/chibios index a29eefa36b33..be44b3305f9a 160000 --- a/lib/chibios +++ b/lib/chibios @@ -1 +1 @@ -Subproject commit a29eefa36b3378b03be509d09c530cb86ffc049f +Subproject commit be44b3305f9a9fe5f2f49a4e7b978db322dc463e From 3f9a91260923eea6f176d5ec848404778346ec4a Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sun, 16 Jun 2024 06:08:04 +1000 Subject: [PATCH 10/16] Fix spelling --- keyboards/nuphy/air75_v2/ansi/ansi.c | 8 ++++---- keyboards/nuphy/air75_v2/ansi/kb_util.c | 2 +- keyboards/nuphy/air75_v2/ansi/kb_util.h | 8 ++++---- keyboards/nuphy/air75_v2/ansi/rf.c | 14 +++++++------- keyboards/nuphy/air75_v2/ansi/side.c | 14 +++++++------- keyboards/nuphy/air75_v2/ansi/side_driver.c | 2 +- keyboards/nuphy/air75_v2/ansi/sleep.c | 2 +- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/ansi.c b/keyboards/nuphy/air75_v2/ansi/ansi.c index 16fd2cb4b856..2154656713cc 100644 --- a/keyboards/nuphy/air75_v2/ansi/ansi.c +++ b/keyboards/nuphy/air75_v2/ansi/ansi.c @@ -152,13 +152,13 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { case SIDE_VAI: if (record->event.pressed) { - side_light_contol(1); + side_light_control(1); } return false; case SIDE_VAD: if (record->event.pressed) { - side_light_contol(0); + side_light_control(0); } return false; @@ -176,13 +176,13 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { case SIDE_SPI: if (record->event.pressed) { - side_speed_contol(1); + side_speed_control(1); } return false; case SIDE_SPD: if (record->event.pressed) { - side_speed_contol(0); + side_speed_control(0); } return false; diff --git a/keyboards/nuphy/air75_v2/ansi/kb_util.c b/keyboards/nuphy/air75_v2/ansi/kb_util.c index bb18df1105c0..3f927de406d3 100644 --- a/keyboards/nuphy/air75_v2/ansi/kb_util.c +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.c @@ -22,7 +22,7 @@ along with this program. If not, see . kb_config_t kb_config; DEV_INFO_STRUCT dev_info = { - .rf_baterry = 100, + .rf_battery = 100, .link_mode = LINK_USB, .rf_state = RF_IDLE, }; diff --git a/keyboards/nuphy/air75_v2/ansi/kb_util.h b/keyboards/nuphy/air75_v2/ansi/kb_util.h index 47ef18e8f493..2e5049914573 100644 --- a/keyboards/nuphy/air75_v2/ansi/kb_util.h +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.h @@ -47,7 +47,7 @@ typedef enum { #define RF_DISCONNECT 4 #define RF_SLEEP 5 #define RF_SNIF 6 -#define RF_INVAILD 0XFE +#define RF_INVALID 0XFE #define RF_ERR_STATE 0XFF #define CMD_POWER_UP 0XF0 @@ -124,7 +124,7 @@ typedef struct uint8_t rf_state; uint8_t rf_charge; uint8_t rf_led; - uint8_t rf_baterry; + uint8_t rf_battery; uint8_t sys_sw_state; } DEV_INFO_STRUCT; @@ -147,8 +147,8 @@ void rf_device_init(void); void uart_send_report_repeat(void); void uart_receive_pro(void); void uart_send_report(uint8_t report_type, uint8_t *report_buf, uint8_t report_size); -void side_speed_contol(uint8_t dir); -void side_light_contol(uint8_t dir); +void side_speed_control(uint8_t dir); +void side_light_control(uint8_t dir); void side_colour_control(uint8_t dir); void side_mode_control(uint8_t dir); void side_led_show(void); diff --git a/keyboards/nuphy/air75_v2/ansi/rf.c b/keyboards/nuphy/air75_v2/ansi/rf.c index 9efd372e4261..f01dcb6c8904 100644 --- a/keyboards/nuphy/air75_v2/ansi/rf.c +++ b/keyboards/nuphy/air75_v2/ansi/rf.c @@ -146,7 +146,7 @@ void uart_send_report_repeat(void) wait_us(200); if(f_bit_kb_act) - uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16); + uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16); } else { f_bit_kb_act = 0; @@ -256,11 +256,11 @@ void RF_Protocol_Receive(void) { dev_info.rf_charge = Usart_Mgr.RXDBuf[7]; - if (Usart_Mgr.RXDBuf[8] <= 100) dev_info.rf_baterry = Usart_Mgr.RXDBuf[8]; - if (dev_info.rf_charge & 0x01) dev_info.rf_baterry = 100; + if (Usart_Mgr.RXDBuf[8] <= 100) dev_info.rf_battery = Usart_Mgr.RXDBuf[8]; + if (dev_info.rf_charge & 0x01) dev_info.rf_battery = 100; } else { - if (dev_info.rf_state != RF_INVAILD) { + if (dev_info.rf_state != RF_INVALID) { if (error_cnt >= 5) { error_cnt = 0; f_send_channel = 1; @@ -506,7 +506,7 @@ void dev_sts_sync(void) { /** * @brief Uart send bytes. * @param Buffer data buf - * @param Length data lenght + * @param Length data length */ void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length) { gpio_write_pin_low(NRF_WAKEUP_PIN); @@ -521,7 +521,7 @@ void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length) { /** * @brief get checksum. * @param buf data buf - * @param len data lenght + * @param len data length */ uint8_t get_checksum(uint8_t *buf, uint8_t len) { uint8_t i; @@ -560,7 +560,7 @@ void uart_send_report(uint8_t report_type, uint8_t *report_buf, uint8_t report_s } /** - * @brief Uart receives data and processes it after completion,. + * @brief Uart receives data and processes it after completion. */ void uart_receive_pro(void) { static bool rcv_start = false; diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index 38d46aa65a64..7e5ed0b5c89e 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -111,7 +111,7 @@ void side_rgb_refresh(void) { * @param dir: 0 - decrease, 1 - increase. * @note save to eeprom. */ -void side_light_contol(uint8_t dir) { +void side_light_control(uint8_t dir) { if (dir) { if (side_light > SIDE_BRIGHT_MAX) { return; @@ -132,7 +132,7 @@ void side_light_contol(uint8_t dir) { * @param dir: 0 - decrease, 1 - increase. * @note save to eeprom. */ -void side_speed_contol(uint8_t dir) { +void side_speed_control(uint8_t dir) { if ((side_speed) > SIDE_SPEED_MAX) (side_speed) = SIDE_SPEED_MAX / 2; if (dir) { @@ -588,7 +588,7 @@ void bat_num_led(uint8_t bat_percent) void num_led_show(void) { static uint8_t num_bat_temp = 0; - num_bat_temp = dev_info.rf_baterry; + num_bat_temp = dev_info.rf_battery; bat_num_led(num_bat_temp); } @@ -659,7 +659,7 @@ void bat_led_show(void) { f_init = 0; bat_show_time = timer_read32(); charge_state = dev_info.rf_charge; - bat_percent = dev_info.rf_baterry; + bat_percent = dev_info.rf_battery; } if (charge_state != dev_info.rf_charge) { @@ -680,13 +680,13 @@ void bat_led_show(void) { if (charge_state == 0x03) { bat_show_breath = true; } else if (charge_state & 0x01) { - dev_info.rf_baterry = 100; + dev_info.rf_battery = 100; } } - if (bat_percent != dev_info.rf_baterry) { + if (bat_percent != dev_info.rf_battery) { if (timer_elapsed32(bat_per_debounce) > 1000) { - bat_percent = dev_info.rf_baterry; + bat_percent = dev_info.rf_battery; } } else { bat_per_debounce = timer_read32(); diff --git a/keyboards/nuphy/air75_v2/ansi/side_driver.c b/keyboards/nuphy/air75_v2/ansi/side_driver.c index 7ecdc52db5b8..00b4c2712783 100644 --- a/keyboards/nuphy/air75_v2/ansi/side_driver.c +++ b/keyboards/nuphy/air75_v2/ansi/side_driver.c @@ -28,7 +28,7 @@ along with this program. If not, see . #define NOP_FUDGE 0.4 #else #error("NOP_FUDGE configuration required") -#define NOP_FUDGE 1 // this just pleases the compile so the above error is easier to spot +#define NOP_FUDGE 1 // this just pleases the compiler so the above error is easier to spot #endif #endif diff --git a/keyboards/nuphy/air75_v2/ansi/sleep.c b/keyboards/nuphy/air75_v2/ansi/sleep.c index e553262f9c67..df12b04f907d 100644 --- a/keyboards/nuphy/air75_v2/ansi/sleep.c +++ b/keyboards/nuphy/air75_v2/ansi/sleep.c @@ -51,7 +51,7 @@ void sleep_handle(void) { else uart_send_cmd(CMD_SLEEP, 5, 5); - // power off led + // power off LED gpio_set_pin_output_push_pull(DC_BOOST_PIN); gpio_write_pin_low(DC_BOOST_PIN); From 7d4a464f00b552a8f8cfc08bd42bb06e9a205973 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sun, 16 Jun 2024 06:19:08 +1000 Subject: [PATCH 11/16] Move all side tables to side_table.h Also rename all tables to `_tab` for consistency --- keyboards/nuphy/air75_v2/ansi/side.c | 74 ++++------------------ keyboards/nuphy/air75_v2/ansi/side.h | 35 ++++++++++ keyboards/nuphy/air75_v2/ansi/side_table.h | 28 ++++++++ 3 files changed, 77 insertions(+), 60 deletions(-) create mode 100644 keyboards/nuphy/air75_v2/ansi/side.h diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index 7e5ed0b5c89e..7fd784154576 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -20,26 +20,6 @@ along with this program. If not, see . #include "side_table.h" #include "ws2812.h" -#define SIDE_BRIGHT_MAX 4 -#define SIDE_SPEED_MAX 4 -#define SIDE_COLOUR_MAX 8 - -#define SIDE_LINE 6 -#define SIDE_LED_NUM 12 - -#define RF_LED_LINK_PERIOD 500 -#define RF_LED_PAIR_PERIOD 250 - - -/* side rgb mode */ -enum { - SIDE_WAVE = 0, - SIDE_MIX, - SIDE_STATIC, - SIDE_BREATH, - SIDE_OFF, -}; - uint8_t side_mode = 0; uint8_t side_light = 3; uint8_t side_speed = 2; @@ -51,32 +31,6 @@ uint32_t side_play_timer = 0; uint8_t r_temp, g_temp, b_temp; rgb_led_t side_leds[SIDE_LED_NUM] = {0}; -const uint8_t side_speed_table[5][5] = { - [SIDE_WAVE] = {10, 14, 20, 28, 38}, // - [SIDE_MIX] = {10, 14, 20, 28, 38}, // - [SIDE_STATIC] = {50, 50, 50, 50, 50}, // - [SIDE_BREATH] = {10, 14, 20, 28, 38}, // - [SIDE_OFF] = {50, 50, 50, 50, 50}, // -}; - -const uint8_t side_light_table[6] = { - 0, // - 22, // - 34, // - 55, // - 79, // - 106, // -}; - -const uint8_t side_led_index_tab[SIDE_LINE][2] = { - {5, 6}, // - {4, 7}, // - {3, 8}, // - {2, 9}, // - {1, 10}, // - {0, 11}, // -}; - extern DEV_INFO_STRUCT dev_info; extern kb_config_t kb_config; extern uint8_t rf_blink_cnt; @@ -350,10 +304,10 @@ static void count_rgb_light(uint8_t light_temp) { static void side_wave_mode_show(void) { uint8_t play_index; - if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) return; else - side_play_cnt -= side_speed_table[side_mode][side_speed]; + side_play_cnt -= side_speed_tab[side_mode][side_speed]; if (side_play_cnt > 20) side_play_cnt = 0; if (side_rgb) @@ -378,7 +332,7 @@ static void side_wave_mode_show(void) { count_rgb_light(wave_data_tab[play_index]); } - count_rgb_light(side_light_table[side_light]); + count_rgb_light(side_light_tab[side_light]); for (int j = 0; j < 2; j++) { side_rgb_set_color(side_led_index_tab[i][j], r_temp >> 2, g_temp >> 2, b_temp >> 2); @@ -390,10 +344,10 @@ static void side_wave_mode_show(void) { * @brief side_spectrum_mode_show. */ static void side_spectrum_mode_show(void) { - if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) return; else - side_play_cnt -= side_speed_table[side_mode][side_speed]; + side_play_cnt -= side_speed_tab[side_mode][side_speed]; if (side_play_cnt > 20) side_play_cnt = 0; light_point_playing(1, 1, FLOW_COLOUR_TAB_LEN, &side_play_point); @@ -402,7 +356,7 @@ static void side_spectrum_mode_show(void) { g_temp = flow_rainbow_colour_tab[side_play_point][1]; b_temp = flow_rainbow_colour_tab[side_play_point][2]; - count_rgb_light(side_light_table[side_light]); + count_rgb_light(side_light_tab[side_light]); for (int i = 0; i < SIDE_LINE; i++) { for (int j = 0; j < 2; j++) { @@ -417,10 +371,10 @@ static void side_spectrum_mode_show(void) { static void side_breathe_mode_show(void) { static uint8_t play_point = 0; - if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) return; else - side_play_cnt -= side_speed_table[side_mode][side_speed]; + side_play_cnt -= side_speed_tab[side_mode][side_speed]; if (side_play_cnt > 20) side_play_cnt = 0; light_point_playing(0, 1, BREATHE_TAB_LEN, &play_point); @@ -440,7 +394,7 @@ static void side_breathe_mode_show(void) { } count_rgb_light(breathe_data_tab[play_point]); - count_rgb_light(side_light_table[side_light]); + count_rgb_light(side_light_tab[side_light]); for (int i = 0; i < SIDE_LINE; i++) { for (int j = 0; j < 2; j++) { @@ -455,10 +409,10 @@ static void side_breathe_mode_show(void) { static void side_static_mode_show(void) { uint8_t play_index; - if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) return; else - side_play_cnt -= side_speed_table[side_mode][side_speed]; + side_play_cnt -= side_speed_tab[side_mode][side_speed]; if (side_play_cnt > 20) side_play_cnt = 0; if (side_play_point >= SIDE_COLOUR_MAX) side_play_point = 0; @@ -475,7 +429,7 @@ static void side_static_mode_show(void) { b_temp = colour_lib[side_colour][2]; } - count_rgb_light(side_light_table[side_light]); + count_rgb_light(side_light_tab[side_light]); for (int j = 0; j < 2; j++) { side_rgb_set_color(side_led_index_tab[i][j], r_temp >> 2, g_temp >> 2, b_temp >> 2); @@ -487,10 +441,10 @@ static void side_static_mode_show(void) { * @brief side_off_mode_show. */ static void side_off_mode_show(void) { - if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) return; else - side_play_cnt -= side_speed_table[side_mode][side_speed]; + side_play_cnt -= side_speed_tab[side_mode][side_speed]; if (side_play_cnt > 20) side_play_cnt = 0; r_temp = 0x00; diff --git a/keyboards/nuphy/air75_v2/ansi/side.h b/keyboards/nuphy/air75_v2/ansi/side.h new file mode 100644 index 000000000000..578b2818ac97 --- /dev/null +++ b/keyboards/nuphy/air75_v2/ansi/side.h @@ -0,0 +1,35 @@ +/* +Copyright 2023 @ Nuphy + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#define SIDE_BRIGHT_MAX 4 +#define SIDE_SPEED_MAX 4 +#define SIDE_COLOUR_MAX 8 + +#define SIDE_LINE 6 +#define SIDE_LED_NUM 12 + +#define RF_LED_LINK_PERIOD 500 +#define RF_LED_PAIR_PERIOD 250 + +/* side rgb mode */ +enum { + SIDE_WAVE = 0, + SIDE_MIX, + SIDE_STATIC, + SIDE_BREATH, + SIDE_OFF, +}; diff --git a/keyboards/nuphy/air75_v2/ansi/side_table.h b/keyboards/nuphy/air75_v2/ansi/side_table.h index 65a4d393d89c..d3440edee6a9 100644 --- a/keyboards/nuphy/air75_v2/ansi/side_table.h +++ b/keyboards/nuphy/air75_v2/ansi/side_table.h @@ -17,6 +17,8 @@ along with this program. If not, see . #pragma once +#include "side.h" + #define LIGHT_TAB_LEN 101 #define WAVE_TAB_LEN 112 #define BREATHE_TAB_LEN 128 @@ -573,3 +575,29 @@ const uint8_t colour_lib[9][3] = {0xc0, 0xc0, 0xff}, {0x00, 0x00, 0x00}, }; + +const uint8_t side_speed_tab[5][5] = { + [SIDE_WAVE] = {10, 14, 20, 28, 38}, // + [SIDE_MIX] = {10, 14, 20, 28, 38}, // + [SIDE_STATIC] = {50, 50, 50, 50, 50}, // + [SIDE_BREATH] = {10, 14, 20, 28, 38}, // + [SIDE_OFF] = {50, 50, 50, 50, 50}, // +}; + +const uint8_t side_light_tab[6] = { + 0, // + 22, // + 34, // + 55, // + 79, // + 106, // +}; + +const uint8_t side_led_index_tab[SIDE_LINE][2] = { + {5, 6}, // + {4, 7}, // + {3, 8}, // + {2, 9}, // + {1, 10}, // + {0, 11}, // +}; From 23404735289e739cede69a001855ddb9eee5d3b6 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sun, 16 Jun 2024 06:20:57 +1000 Subject: [PATCH 12/16] Rename count_rgb_light to side_rgb_brightness to match its usage --- keyboards/nuphy/air75_v2/ansi/side.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index 7fd784154576..dcd53c6b0108 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -282,10 +282,10 @@ static void light_point_playing(uint8_t trend, uint8_t step, uint8_t len, uint8_ } /** - * @brief count_rgb_light. + * @brief side_rgb_brightness. * @param light_temp: */ -static void count_rgb_light(uint8_t light_temp) { +static void side_rgb_brightness(uint8_t light_temp) { uint16_t temp; temp = (light_temp)*r_temp + r_temp; @@ -329,10 +329,10 @@ static void side_wave_mode_show(void) { b_temp = colour_lib[side_colour][2]; light_point_playing(1, 12, WAVE_TAB_LEN, &play_index); - count_rgb_light(wave_data_tab[play_index]); + side_rgb_brightness(wave_data_tab[play_index]); } - count_rgb_light(side_light_tab[side_light]); + side_rgb_brightness(side_light_tab[side_light]); for (int j = 0; j < 2; j++) { side_rgb_set_color(side_led_index_tab[i][j], r_temp >> 2, g_temp >> 2, b_temp >> 2); @@ -356,7 +356,7 @@ static void side_spectrum_mode_show(void) { g_temp = flow_rainbow_colour_tab[side_play_point][1]; b_temp = flow_rainbow_colour_tab[side_play_point][2]; - count_rgb_light(side_light_tab[side_light]); + side_rgb_brightness(side_light_tab[side_light]); for (int i = 0; i < SIDE_LINE; i++) { for (int j = 0; j < 2; j++) { @@ -393,8 +393,8 @@ static void side_breathe_mode_show(void) { b_temp = colour_lib[side_colour][2]; } - count_rgb_light(breathe_data_tab[play_point]); - count_rgb_light(side_light_tab[side_light]); + side_rgb_brightness(breathe_data_tab[play_point]); + side_rgb_brightness(side_light_tab[side_light]); for (int i = 0; i < SIDE_LINE; i++) { for (int j = 0; j < 2; j++) { @@ -429,7 +429,7 @@ static void side_static_mode_show(void) { b_temp = colour_lib[side_colour][2]; } - count_rgb_light(side_light_tab[side_light]); + side_rgb_brightness(side_light_tab[side_light]); for (int j = 0; j < 2; j++) { side_rgb_set_color(side_led_index_tab[i][j], r_temp >> 2, g_temp >> 2, b_temp >> 2); @@ -659,7 +659,7 @@ void bat_led_show(void) { r_temp = 0x80; g_temp = 0x40; b_temp = 0x00; - count_rgb_light(breathe_data_tab[play_point]); + side_rgb_brightness(breathe_data_tab[play_point]); set_right_rgb(r_temp, g_temp, b_temp); } else { bat_percent_led(bat_percent); From 94a484d4109f487d2938c32c55f34e60222c78e0 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sun, 16 Jun 2024 06:50:03 +1000 Subject: [PATCH 13/16] Move battery color to table and simplify light calculation --- keyboards/nuphy/air75_v2/ansi/side.c | 65 +++++----------------- keyboards/nuphy/air75_v2/ansi/side_table.h | 9 +++ 2 files changed, 24 insertions(+), 50 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index dcd53c6b0108..52e95e0ec3b9 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -511,32 +511,17 @@ void rf_led_show(void) { void bat_num_led(uint8_t bat_percent) { uint8_t r, g, b; + uint8_t bat_idx = bat_percent / 17; + uint8_t bat_lvl = 1 + ((bat_percent - 1) / 10); - // set color - if (bat_percent <= 15) { - r = 0xff; g = 0x00; b = 0x00; - } - else if (bat_percent <= 50) { - r = 0xff; g = 0x40; b = 0x00; - } - else if (bat_percent <= 80) { - r = 0xff; g = 0xff; b = 0x00; - } - else { - r = 0x00; g = 0xff; b = 0x00; - } + r = bat_percent_tab[bat_idx][0]; + g = bat_percent_tab[bat_idx][1]; + b = bat_percent_tab[bat_idx][2]; // set percent - if (bat_percent >= 1) rgb_matrix_set_color(29, r, g, b); - if (bat_percent > 10) rgb_matrix_set_color(28, r, g, b); - if (bat_percent > 20) rgb_matrix_set_color(27, r, g, b); - if (bat_percent > 30) rgb_matrix_set_color(26, r, g, b); - if (bat_percent > 40) rgb_matrix_set_color(25, r, g, b); - if (bat_percent > 50) rgb_matrix_set_color(24, r, g, b); - if (bat_percent > 60) rgb_matrix_set_color(23, r, g, b); - if (bat_percent > 70) rgb_matrix_set_color(22, r, g, b); - if (bat_percent > 80) rgb_matrix_set_color(21, r, g, b); - if (bat_percent > 90) rgb_matrix_set_color(20, r, g, b); + for (uint8_t i = 0; i < bat_lvl ; i++) { + rgb_matrix_set_color(29 - i, r, g, b); + } } void num_led_show(void) @@ -558,35 +543,15 @@ void bat_led_close(void) * @brief bat_percent_led. */ void bat_percent_led(uint8_t bat_percent) { - uint8_t bat_end_led = 0; - uint8_t bat_r, bat_g, bat_b; - - if (bat_percent <= 15) { - bat_end_led = 0; - bat_r = 0x80, bat_g = 0, bat_b = 0; - } else if (bat_percent <= 20) { - bat_end_led = 1; - bat_r = 0x80, bat_g = 0x40, bat_b = 0; - } else if (bat_percent <= 40) { - bat_end_led = 2; - bat_r = 0x80, bat_g = 0x40, bat_b = 0; - } else if (bat_percent <= 60) { - bat_end_led = 3; - bat_r = 0x80, bat_g = 0x40, bat_b = 0; - } else if (bat_percent <= 80) { - bat_end_led = 4; - bat_r = 0x80, bat_g = 0x40, bat_b = 0; - } else if (bat_percent <= 95) { - bat_end_led = 5; - bat_r = 0x80, bat_g = 0x40, bat_b = 0; - } else { - bat_end_led = 5; - bat_r = 0, bat_g = 0x80, bat_b = 0; - } + uint8_t bat_idx = bat_percent / 17; + + r_temp = bat_percent_tab[bat_idx][0]; + g_temp = bat_percent_tab[bat_idx][1]; + b_temp = bat_percent_tab[bat_idx][2]; uint8_t i = 0; - for (; i <= bat_end_led; i++) - side_rgb_set_color(11 - i, bat_r >> 2, bat_g >> 2, bat_b >> 2); + for (; i <= bat_idx; i++) + side_rgb_set_color(11 - i, r_temp >> 2, g_temp >> 2, b_temp >> 2); for (; i < 6; i++) side_rgb_set_color(11 - i, 0, 0, 0); diff --git a/keyboards/nuphy/air75_v2/ansi/side_table.h b/keyboards/nuphy/air75_v2/ansi/side_table.h index d3440edee6a9..3bd38513c32f 100644 --- a/keyboards/nuphy/air75_v2/ansi/side_table.h +++ b/keyboards/nuphy/air75_v2/ansi/side_table.h @@ -601,3 +601,12 @@ const uint8_t side_led_index_tab[SIDE_LINE][2] = { {1, 10}, // {0, 11}, // }; + +const uint8_t bat_percent_tab[6][3] = { + {0xff, 0x00, 0x00}, + {0xff, 0x66, 0x00}, + {0xff, 0xcc, 0x00}, + {0xcc, 0xff, 0x00}, + {0x66, 0xff, 0x00}, + {0x00, 0xff, 0x00}, +}; From b89e321707044db722ae09000114439046f15361 Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sun, 16 Jun 2024 16:50:10 +1000 Subject: [PATCH 14/16] Respect side light level for battery/system indicators (minimum level 1) --- keyboards/nuphy/air75_v2/ansi/side.c | 125 +++++++++++++++++---------- 1 file changed, 78 insertions(+), 47 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index 52e95e0ec3b9..be35313ce2ca 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -161,22 +161,65 @@ void side_mode_control(uint8_t dir) { eeconfig_update_kb_datablock(&kb_config); } +/** + * @brief side_rgb_brightness. + * @param light_temp: + */ +static void side_rgb_brightness(uint8_t light_temp) { + uint16_t temp; + + temp = (light_temp)*r_temp + r_temp; + r_temp = temp >> 8; + + temp = (light_temp)*g_temp + g_temp; + g_temp = temp >> 8; + + temp = (light_temp)*b_temp + b_temp; + b_temp = temp >> 8; +} + /** * @brief set left side leds. * @param ... */ -void set_left_rgb(uint8_t r, uint8_t g, uint8_t b) { +void set_left_rgb(uint8_t r, uint8_t g, uint8_t b, bool system) { + uint8_t bright = side_light; + if (bright == 0) { + if (system) { + bright = 1; + } else { + return; + } + } + r_temp = r; + g_temp = g; + b_temp = b; + side_rgb_brightness(side_light_tab[bright]); + for (int i = 0; i < 6; i++) - side_rgb_set_color(i, r >> 2, g >> 2, b >> 2); + side_rgb_set_color(i, r_temp >> 2, g_temp >> 2, b_temp >> 2); } /** * @brief set right side leds. * @param ... */ -void set_right_rgb(uint8_t r, uint8_t g, uint8_t b) { +void set_right_rgb(uint8_t r, uint8_t g, uint8_t b, bool system) { + uint8_t bright = side_light; + if (bright == 0) { + if (system) { + bright = 1; + } else { + return; + } + } + r_temp = r; + g_temp = g; + b_temp = b; + side_rgb_brightness(side_light_tab[bright]); + for (int i = 6; i < 12; i++) - side_rgb_set_color(i, r >> 2, g >> 2, b >> 2); + side_rgb_set_color(i, r_temp >> 2, g_temp >> 2, b_temp >> 2); } /** @@ -203,9 +246,9 @@ void sys_sw_led_show(void) { b_temp = 0x80; } if ((timer_elapsed32(sys_show_timer) / 500) % 2 == 0) { - set_right_rgb(r_temp, g_temp, b_temp); + set_right_rgb(r_temp, g_temp, b_temp, true); } else { - set_right_rgb(0x00, 0x00, 0x00); + set_right_rgb(0x00, 0x00, 0x00, false); } if (timer_elapsed32(sys_show_timer) >= 3000) { sys_show_flag = false; @@ -237,9 +280,9 @@ void sleep_sw_led_show(void) { b_temp = 0x00; } if ((timer_elapsed32(sleep_show_timer) / 500) % 2 == 0) { - set_right_rgb(r_temp, g_temp, b_temp); + set_right_rgb(r_temp, g_temp, b_temp, true); } else { - set_right_rgb(0x00, 0x00, 0x00); + set_right_rgb(0x00, 0x00, 0x00, false); } if (timer_elapsed32(sleep_show_timer) >= 3000) { sleep_show_flag = false; @@ -253,13 +296,13 @@ void sleep_sw_led_show(void) { void sys_led_show(void) { if (dev_info.link_mode == LINK_USB) { if (host_keyboard_led_state().caps_lock) { - set_left_rgb(0X00, 0x80, 0x80); + set_left_rgb(0X00, 0x80, 0x80, true); } } else { if (dev_info.rf_led & 0x02) { - set_left_rgb(0X00, 0x80, 0x80); + set_left_rgb(0X00, 0x80, 0x80, true); } } } @@ -281,23 +324,6 @@ static void light_point_playing(uint8_t trend, uint8_t step, uint8_t len, uint8_ } } -/** - * @brief side_rgb_brightness. - * @param light_temp: - */ -static void side_rgb_brightness(uint8_t light_temp) { - uint16_t temp; - - temp = (light_temp)*r_temp + r_temp; - r_temp = temp >> 8; - - temp = (light_temp)*g_temp + g_temp; - g_temp = temp >> 8; - - temp = (light_temp)*b_temp + b_temp; - b_temp = temp >> 8; -} - /** * @brief side_wave_mode_show. */ @@ -502,7 +528,7 @@ void rf_led_show(void) { } } - set_left_rgb(r_temp, g_temp, b_temp); + set_left_rgb(r_temp, g_temp, b_temp, true); } /** @@ -544,10 +570,15 @@ void bat_led_close(void) */ void bat_percent_led(uint8_t bat_percent) { uint8_t bat_idx = bat_percent / 17; + uint8_t bright = side_light; + if (bright < 1) { + bright = 1; + } r_temp = bat_percent_tab[bat_idx][0]; g_temp = bat_percent_tab[bat_idx][1]; b_temp = bat_percent_tab[bat_idx][2]; + side_rgb_brightness(side_light_tab[bright]); uint8_t i = 0; for (; i <= bat_idx; i++) @@ -625,7 +656,7 @@ void bat_led_show(void) { g_temp = 0x40; b_temp = 0x00; side_rgb_brightness(breathe_data_tab[play_point]); - set_right_rgb(r_temp, g_temp, b_temp); + set_right_rgb(r_temp, g_temp, b_temp, true); } else { bat_percent_led(bat_percent); } @@ -645,15 +676,15 @@ void device_reset_show(void) { for (int blink_cnt = 0; blink_cnt < 3; blink_cnt++) { rgb_matrix_set_color_all(0x10, 0x10, 0x10); - set_left_rgb(0x40, 0x40, 0x40); - set_right_rgb(0x40, 0x40, 0x40); + set_left_rgb(0x40, 0x40, 0x40, true); + set_right_rgb(0x40, 0x40, 0x40, true); rgb_matrix_update_pwm_buffers(); side_rgb_refresh(); wait_ms(200); rgb_matrix_set_color_all(0x00, 0x00, 0x00); - set_left_rgb(0x00, 0x00, 0x00); - set_right_rgb(0x00, 0x00, 0x00); + set_left_rgb(0x00, 0x00, 0x00, true); + set_right_rgb(0x00, 0x00, 0x00, true); rgb_matrix_update_pwm_buffers(); side_rgb_refresh(); wait_ms(200); @@ -706,50 +737,50 @@ void rgb_test_show(void) // set test color rgb_matrix_set_color_all(0xFF, 0x00, 0x00); rgb_matrix_update_pwm_buffers(); - set_left_rgb(0xff, 0x00, 0x00); - set_right_rgb(0xff, 0x00, 0x00); + set_left_rgb(0xff, 0x00, 0x00, true); + set_right_rgb(0xff, 0x00, 0x00, true); side_rgb_refresh(); wait_ms(500); rgb_matrix_set_color_all(0x00, 0xFF, 0x00); rgb_matrix_update_pwm_buffers(); - set_left_rgb(0x00, 0xFF, 0x00); - set_right_rgb(0x00, 0xFF, 0x00); + set_left_rgb(0x00, 0xFF, 0x00, true); + set_right_rgb(0x00, 0xFF, 0x00, true); side_rgb_refresh(); wait_ms(500); rgb_matrix_set_color_all(0x00, 0x00, 0xFF); rgb_matrix_update_pwm_buffers(); - set_left_rgb(0x00, 0x00, 0xFF); - set_right_rgb(0x00, 0x00, 0xFF); + set_left_rgb(0x00, 0x00, 0xFF, true); + set_right_rgb(0x00, 0x00, 0xFF, true); side_rgb_refresh(); wait_ms(500); rgb_matrix_set_color_all(0x80, 0x80, 0x80); rgb_matrix_update_pwm_buffers(); - set_left_rgb(0x80, 0x80, 0x80); - set_right_rgb(0x80, 0x80, 0x80); + set_left_rgb(0x80, 0x80, 0x80, true); + set_right_rgb(0x80, 0x80, 0x80, true); side_rgb_refresh(); wait_ms(500); rgb_matrix_set_color_all(0x80, 0x80, 0x00); rgb_matrix_update_pwm_buffers(); - set_left_rgb(0x80, 0x80, 0x00); - set_right_rgb(0x80, 0x80, 0x00); + set_left_rgb(0x80, 0x80, 0x00, true); + set_right_rgb(0x80, 0x80, 0x00, true); side_rgb_refresh(); wait_ms(500); rgb_matrix_set_color_all(0x80, 0x00, 0x80); rgb_matrix_update_pwm_buffers(); - set_left_rgb(0x80, 0x00, 0x80); - set_right_rgb(0x80, 0x00, 0x80); + set_left_rgb(0x80, 0x00, 0x80, true); + set_right_rgb(0x80, 0x00, 0x80, true); side_rgb_refresh(); wait_ms(500); rgb_matrix_set_color_all(0x00, 0x80, 0x80); rgb_matrix_update_pwm_buffers(); - set_left_rgb(0x00, 0x80, 0x80); - set_right_rgb(0x00, 0x80, 0x80); + set_left_rgb(0x00, 0x80, 0x80, true); + set_right_rgb(0x00, 0x80, 0x80, true); side_rgb_refresh(); wait_ms(500); } From 2dd6efcb699b9ecae0693b2654b1fa2e8bb0fcdd Mon Sep 17 00:00:00 2001 From: Peter Fern Date: Sun, 16 Jun 2024 18:48:16 +1000 Subject: [PATCH 15/16] Fix style (optional braces and clang-format) Conform with the QMK C coding conventions: https://docs.qmk.fm/coding_conventions_c --- keyboards/nuphy/air75_v2/ansi/ansi.c | 52 +++--- keyboards/nuphy/air75_v2/ansi/ansi.h | 8 +- keyboards/nuphy/air75_v2/ansi/config.h | 30 ++-- keyboards/nuphy/air75_v2/ansi/kb_util.c | 172 +++++++++++--------- keyboards/nuphy/air75_v2/ansi/kb_util.h | 140 ++++++++-------- keyboards/nuphy/air75_v2/ansi/rf.c | 101 +++++++----- keyboards/nuphy/air75_v2/ansi/side.c | 131 +++++++++------ keyboards/nuphy/air75_v2/ansi/side.h | 14 +- keyboards/nuphy/air75_v2/ansi/side_driver.c | 45 +++-- keyboards/nuphy/air75_v2/ansi/sleep.c | 20 ++- 10 files changed, 385 insertions(+), 328 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/ansi.c b/keyboards/nuphy/air75_v2/ansi/ansi.c index 2154656713cc..4fea648a86ab 100644 --- a/keyboards/nuphy/air75_v2/ansi/ansi.c +++ b/keyboards/nuphy/air75_v2/ansi/ansi.c @@ -19,32 +19,33 @@ along with this program. If not, see . #include "ansi.h" #include "usb_main.h" -extern bool f_rf_sw_press; -extern bool f_sleep_show; -extern bool f_dev_reset_press; -extern bool f_bat_num_show; -extern bool f_rgb_test_press; -extern bool f_bat_hold; -extern uint16_t no_act_time; -extern uint8_t rf_sw_temp; -extern uint16_t rf_sw_press_delay; -extern uint16_t rf_linking_time; -extern kb_config_t kb_config; +extern bool f_rf_sw_press; +extern bool f_sleep_show; +extern bool f_dev_reset_press; +extern bool f_bat_num_show; +extern bool f_rgb_test_press; +extern bool f_bat_hold; +extern uint16_t no_act_time; +extern uint8_t rf_sw_temp; +extern uint16_t rf_sw_press_delay; +extern uint16_t rf_linking_time; +extern kb_config_t kb_config; extern DEV_INFO_STRUCT dev_info; - /* qmk process record */ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { - if(!process_record_user(keycode, record)){ + if (!process_record_user(keycode, record)) { return false; } - no_act_time = 0; + no_act_time = 0; rf_linking_time = 0; switch (keycode) { case RF_DFU: if (record->event.pressed) { - if (dev_info.link_mode != LINK_USB) return false; + if (dev_info.link_mode != LINK_USB) { + return false; + } uart_send_cmd(CMD_RF_DFU, 10, 20); } return false; @@ -197,9 +198,12 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { case SLEEP_MODE: if (record->event.pressed) { - if(kb_config.sleep_enable) kb_config.sleep_enable = false; - else kb_config.sleep_enable = true; - f_sleep_show = 1; + if (kb_config.sleep_enable) { + kb_config.sleep_enable = false; + } else { + kb_config.sleep_enable = true; + } + f_sleep_show = 1; eeconfig_update_kb_datablock(&kb_config); } return false; @@ -224,24 +228,21 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { return true; } - -bool rgb_matrix_indicators_kb(void) -{ - if(!rgb_matrix_indicators_user()){ +bool rgb_matrix_indicators_kb(void) { + if (!rgb_matrix_indicators_user()) { return false; } - if(f_bat_num_show) { + if (f_bat_num_show) { num_led_show(); } // fix power-on brightness is abnormal - rgb_matrix_set_color(RGB_MATRIX_LED_COUNT-1, 0, 0, 0); + rgb_matrix_set_color(RGB_MATRIX_LED_COUNT - 1, 0, 0, 0); return true; } /* qmk keyboard post init */ void keyboard_post_init_kb(void) { - gpio_init(); rf_uart_init(); wait_ms(500); @@ -255,7 +256,6 @@ void keyboard_post_init_kb(void) { /* qmk housekeeping task */ void housekeeping_task_kb(void) { - timer_pro(); uart_receive_pro(); diff --git a/keyboards/nuphy/air75_v2/ansi/ansi.h b/keyboards/nuphy/air75_v2/ansi/ansi.h index 82f9875f77f0..4a79db0e2d7d 100644 --- a/keyboards/nuphy/air75_v2/ansi/ansi.h +++ b/keyboards/nuphy/air75_v2/ansi/ansi.h @@ -44,7 +44,7 @@ enum custom_keycodes { RGB_TEST }; -#define SYS_PRT G(S(KC_3)) -#define MAC_PRTA G(S(KC_4)) -#define WIN_PRTA G(S(KC_S)) -#define MAC_SEARCH G(KC_SPC) +#define SYS_PRT G(S(KC_3)) +#define MAC_PRTA G(S(KC_4)) +#define WIN_PRTA G(S(KC_S)) +#define MAC_SEARCH G(KC_SPC) diff --git a/keyboards/nuphy/air75_v2/ansi/config.h b/keyboards/nuphy/air75_v2/ansi/config.h index 5b4c102f5f79..d60889c3bbdf 100644 --- a/keyboards/nuphy/air75_v2/ansi/config.h +++ b/keyboards/nuphy/air75_v2/ansi/config.h @@ -17,20 +17,20 @@ along with this program. If not, see . #pragma once -#define DEV_MODE_PIN C0 -#define SYS_MODE_PIN C1 -#define DC_BOOST_PIN C2 -#define NRF_RESET_PIN B4 -#define NRF_TEST_PIN B5 -#define NRF_WAKEUP_PIN B8 -#define DRIVER_LED_CS_PIN C6 -#define DRIVER_SIDE_PIN C8 -#define DRIVER_SIDE_CS_PIN C9 +#define DEV_MODE_PIN C0 +#define SYS_MODE_PIN C1 +#define DC_BOOST_PIN C2 +#define NRF_RESET_PIN B4 +#define NRF_TEST_PIN B5 +#define NRF_WAKEUP_PIN B8 +#define DRIVER_LED_CS_PIN C6 +#define DRIVER_SIDE_PIN C8 +#define DRIVER_SIDE_CS_PIN C9 -#define SERIAL_DRIVER SD1 -#define SD1_TX_PIN B6 -#define SD1_TX_PAL_MODE 0 -#define SD1_RX_PIN B7 -#define SD1_RX_PAL_MODE 0 +#define SERIAL_DRIVER SD1 +#define SD1_TX_PIN B6 +#define SD1_TX_PAL_MODE 0 +#define SD1_RX_PIN B7 +#define SD1_RX_PAL_MODE 0 -#define EECONFIG_KB_DATA_SIZE 8 +#define EECONFIG_KB_DATA_SIZE 8 diff --git a/keyboards/nuphy/air75_v2/ansi/kb_util.c b/keyboards/nuphy/air75_v2/ansi/kb_util.c index 3f927de406d3..069c48d13e1d 100644 --- a/keyboards/nuphy/air75_v2/ansi/kb_util.c +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.c @@ -26,15 +26,15 @@ DEV_INFO_STRUCT dev_info = { .link_mode = LINK_USB, .rf_state = RF_IDLE, }; -bool f_bat_hold = 0; -bool f_sys_show = 0; -bool f_sleep_show = 0; -bool f_send_channel = 0; -bool f_dial_sw_init_ok = 0; -bool f_rf_sw_press = 0; -bool f_dev_reset_press = 0; -bool f_rgb_test_press = 0; -bool f_bat_num_show = 0; +bool f_bat_hold = 0; +bool f_sys_show = 0; +bool f_sleep_show = 0; +bool f_send_channel = 0; +bool f_dial_sw_init_ok = 0; +bool f_rf_sw_press = 0; +bool f_dev_reset_press = 0; +bool f_rgb_test_press = 0; +bool f_bat_num_show = 0; uint8_t rf_blink_cnt = 0; uint8_t rf_sw_temp = 0; @@ -49,7 +49,7 @@ host_driver_t *m_host_driver = 0; extern bool f_rf_new_adv_ok; extern report_keyboard_t *keyboard_report; -extern report_nkro_t *nkro_report; +extern report_nkro_t *nkro_report; extern uint8_t bitkb_report_buf[32]; extern uint8_t bytekb_report_buf[8]; extern uint8_t side_mode; @@ -93,7 +93,9 @@ void gpio_init(void) { void long_press_key(void) { static uint32_t long_press_timer = 0; - if (timer_elapsed32(long_press_timer) < 100) return; + if (timer_elapsed32(long_press_timer) < 100) { + return; + } long_press_timer = timer_read32(); // Open a new RF device @@ -111,7 +113,9 @@ void long_press_key(void) { uart_send_cmd(CMD_NEW_ADV, 0, 1); wait_ms(20); uart_receive_pro(); - if (f_rf_new_adv_ok) break; + if (f_rf_new_adv_ok) { + break; + } } } } else { @@ -126,9 +130,9 @@ void long_press_key(void) { if (dev_info.link_mode != LINK_USB) { if (dev_info.link_mode != LINK_RF_24) { - dev_info.link_mode = LINK_BT_1; - dev_info.ble_channel = LINK_BT_1; - dev_info.rf_channel = LINK_BT_1; + dev_info.link_mode = LINK_BT_1; + dev_info.ble_channel = LINK_BT_1; + dev_info.rf_channel = LINK_BT_1; } } else { dev_info.ble_channel = LINK_BT_1; @@ -212,7 +216,9 @@ void break_all_key(void) { * @param mode : link mode */ void switch_dev_link(uint8_t mode) { - if (mode > LINK_USB) return; + if (mode > LINK_USB) { + return; + } break_all_key(); @@ -242,15 +248,21 @@ void dial_sw_scan(void) { static bool f_first = true; if (!f_first) { - if (timer_elapsed32(dial_scan_timer) < 20) return; + if (timer_elapsed32(dial_scan_timer) < 20) { + return; + } } dial_scan_timer = timer_read32(); gpio_set_pin_input_high(DEV_MODE_PIN); gpio_set_pin_input_high(SYS_MODE_PIN); - if (gpio_read_pin(DEV_MODE_PIN)) dial_scan |= 0X01; - if (gpio_read_pin(SYS_MODE_PIN)) dial_scan |= 0X02; + if (gpio_read_pin(DEV_MODE_PIN)) { + dial_scan |= 0X01; + } + if (gpio_read_pin(SYS_MODE_PIN)) { + dial_scan |= 0X02; + } if (dial_save != dial_scan) { break_all_key(); @@ -309,63 +321,68 @@ void dial_sw_scan(void) { * @brief power on scan dial switch. */ void dial_sw_fast_scan(void) { -{ - uint8_t dial_scan_dev = 0; - uint8_t dial_scan_sys = 0; - uint8_t dial_check_dev = 0; - uint8_t dial_check_sys = 0; - uint8_t debounce = 0; - - gpio_set_pin_input_high(DEV_MODE_PIN); - gpio_set_pin_input_high(SYS_MODE_PIN); - - // Debounce to get a stable state - for(debounce=0; debounce<10; debounce++) { - dial_scan_dev = 0; - dial_scan_sys = 0; - if (gpio_read_pin(DEV_MODE_PIN)) dial_scan_dev = 0x01; - else dial_scan_dev = 0; - if (gpio_read_pin(SYS_MODE_PIN)) dial_scan_sys = 0x01; - else dial_scan_sys = 0; - if((dial_scan_dev != dial_check_dev)||(dial_scan_sys != dial_check_sys)) - { - dial_check_dev = dial_scan_dev; - dial_check_sys = dial_scan_sys; - debounce = 0; + { + uint8_t dial_scan_dev = 0; + uint8_t dial_scan_sys = 0; + uint8_t dial_check_dev = 0; + uint8_t dial_check_sys = 0; + uint8_t debounce = 0; + + gpio_set_pin_input_high(DEV_MODE_PIN); + gpio_set_pin_input_high(SYS_MODE_PIN); + + // Debounce to get a stable state + for (debounce = 0; debounce < 10; debounce++) { + dial_scan_dev = 0; + dial_scan_sys = 0; + if (gpio_read_pin(DEV_MODE_PIN)) { + dial_scan_dev = 0x01; + } else { + dial_scan_dev = 0; + } + if (gpio_read_pin(SYS_MODE_PIN)) { + dial_scan_sys = 0x01; + } else { + dial_scan_sys = 0; + } + if ((dial_scan_dev != dial_check_dev) || (dial_scan_sys != dial_check_sys)) { + dial_check_dev = dial_scan_dev; + dial_check_sys = dial_scan_sys; + debounce = 0; + } + wait_ms(1); } - wait_ms(1); - } - // RF link mode - if (dial_scan_dev) { - if (dev_info.link_mode != LINK_USB) { - switch_dev_link(LINK_USB); - } - } else { - if (dev_info.link_mode != dev_info.rf_channel) { - switch_dev_link(dev_info.rf_channel); + // RF link mode + if (dial_scan_dev) { + if (dev_info.link_mode != LINK_USB) { + switch_dev_link(LINK_USB); + } + } else { + if (dev_info.link_mode != dev_info.rf_channel) { + switch_dev_link(dev_info.rf_channel); + } } - } - // Win or Mac - if (dial_scan_sys) { - if (dev_info.sys_sw_state != SYS_SW_MAC) { - default_layer_set(1 << 0); - dev_info.sys_sw_state = SYS_SW_MAC; - keymap_config.nkro = 0; - break_all_key(); - } - } else { - if (dev_info.sys_sw_state != SYS_SW_WIN) { - //f_sys_show = 1; - default_layer_set(1 << 2); - dev_info.sys_sw_state = SYS_SW_WIN; - keymap_config.nkro = 1; - break_all_key(); + // Win or Mac + if (dial_scan_sys) { + if (dev_info.sys_sw_state != SYS_SW_MAC) { + default_layer_set(1 << 0); + dev_info.sys_sw_state = SYS_SW_MAC; + keymap_config.nkro = 0; + break_all_key(); + } + } else { + if (dev_info.sys_sw_state != SYS_SW_WIN) { + // f_sys_show = 1; + default_layer_set(1 << 2); + dev_info.sys_sw_state = SYS_SW_WIN; + keymap_config.nkro = 1; + break_all_key(); + } } } } -} /** * @brief timer process. @@ -381,16 +398,23 @@ void timer_pro(void) { } // step 10ms - if (timer_elapsed32(interval_timer) < 10) + if (timer_elapsed32(interval_timer) < 10) { return; - else + } else { interval_timer = timer_read32(); + } - if (rf_link_show_time < RF_LINK_SHOW_TIME) rf_link_show_time++; + if (rf_link_show_time < RF_LINK_SHOW_TIME) { + rf_link_show_time++; + } - if (no_act_time < 0xffff) no_act_time++; + if (no_act_time < 0xffff) { + no_act_time++; + } - if (rf_linking_time < 0xffff) rf_linking_time++; + if (rf_linking_time < 0xffff) { + rf_linking_time++; + } } /** diff --git a/keyboards/nuphy/air75_v2/ansi/kb_util.h b/keyboards/nuphy/air75_v2/ansi/kb_util.h index 2e5049914573..e40f5c4081c1 100644 --- a/keyboards/nuphy/air75_v2/ansi/kb_util.h +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.h @@ -39,74 +39,72 @@ typedef enum { } TYPE_RX_STATE; - -#define RF_IDLE 0 -#define RF_PAIRING 1 -#define RF_LINKING 2 -#define RF_CONNECT 3 -#define RF_DISCONNECT 4 -#define RF_SLEEP 5 -#define RF_SNIF 6 -#define RF_INVALID 0XFE -#define RF_ERR_STATE 0XFF - -#define CMD_POWER_UP 0XF0 -#define CMD_SLEEP 0XF1 -#define CMD_HAND 0XF2 -#define CMD_SNIF 0XF3 -#define CMD_24G_SUSPEND 0XF4 -#define CMD_IDLE_EXIT 0XFE - -#define CMD_RPT_MS 0XE0 -#define CMD_RPT_BYTE_KB 0XE1 -#define CMD_RPT_BIT_KB 0XE2 -#define CMD_RPT_CONSUME 0XE3 -#define CMD_RPT_SYS 0XE4 - -#define CMD_SET_LINK 0XC0 -#define CMD_SET_CONFIG 0XC1 -#define CMD_GET_CONFIG 0XC2 -#define CMD_SET_NAME 0XC3 -#define CMD_GET_NAME 0XC4 -#define CMD_CLR_DEVICE 0XC5 -#define CMD_NEW_ADV 0XC7 -#define CMD_RF_STS_SYSC 0XC9 -#define CMD_SET_24G_NAME 0XCA -#define CMD_GO_TEST 0XCF -#define CMD_RF_DFU 0XB1 - -#define CMD_WRITE_DATA 0X80 -#define CMD_READ_DATA 0X81 - -#define LINK_RF_24 0 -#define LINK_BT_1 1 -#define LINK_BT_2 2 -#define LINK_BT_3 3 -#define LINK_USB 4 - -#define UART_HEAD 0x5A -#define FUNC_VALID_LEN 32 -#define UART_MAX_LEN 64 - -#define SYS_SW_WIN 0xa1 -#define SYS_SW_MAC 0xa2 - -#define RF_LINK_SHOW_TIME 300 - -#define HOST_USB_TYPE 0 -#define HOST_BLE_TYPE 1 -#define HOST_RF_TYPE 2 - -#define LINK_TIMEOUT (100 * 120) -#define SLEEP_TIME_DELAY (100 * 360) -#define POWER_DOWN_DELAY (24) - -#define RF_LONG_PRESS_DELAY 30 -#define DEV_RESET_PRESS_DELAY 30 -#define RGB_TEST_PRESS_DELAY 30 - -typedef struct -{ +#define RF_IDLE 0 +#define RF_PAIRING 1 +#define RF_LINKING 2 +#define RF_CONNECT 3 +#define RF_DISCONNECT 4 +#define RF_SLEEP 5 +#define RF_SNIF 6 +#define RF_INVALID 0XFE +#define RF_ERR_STATE 0XFF + +#define CMD_POWER_UP 0XF0 +#define CMD_SLEEP 0XF1 +#define CMD_HAND 0XF2 +#define CMD_SNIF 0XF3 +#define CMD_24G_SUSPEND 0XF4 +#define CMD_IDLE_EXIT 0XFE + +#define CMD_RPT_MS 0XE0 +#define CMD_RPT_BYTE_KB 0XE1 +#define CMD_RPT_BIT_KB 0XE2 +#define CMD_RPT_CONSUME 0XE3 +#define CMD_RPT_SYS 0XE4 + +#define CMD_SET_LINK 0XC0 +#define CMD_SET_CONFIG 0XC1 +#define CMD_GET_CONFIG 0XC2 +#define CMD_SET_NAME 0XC3 +#define CMD_GET_NAME 0XC4 +#define CMD_CLR_DEVICE 0XC5 +#define CMD_NEW_ADV 0XC7 +#define CMD_RF_STS_SYSC 0XC9 +#define CMD_SET_24G_NAME 0XCA +#define CMD_GO_TEST 0XCF +#define CMD_RF_DFU 0XB1 + +#define CMD_WRITE_DATA 0X80 +#define CMD_READ_DATA 0X81 + +#define LINK_RF_24 0 +#define LINK_BT_1 1 +#define LINK_BT_2 2 +#define LINK_BT_3 3 +#define LINK_USB 4 + +#define UART_HEAD 0x5A +#define FUNC_VALID_LEN 32 +#define UART_MAX_LEN 64 + +#define SYS_SW_WIN 0xa1 +#define SYS_SW_MAC 0xa2 + +#define RF_LINK_SHOW_TIME 300 + +#define HOST_USB_TYPE 0 +#define HOST_BLE_TYPE 1 +#define HOST_RF_TYPE 2 + +#define LINK_TIMEOUT (100 * 120) +#define SLEEP_TIME_DELAY (100 * 360) +#define POWER_DOWN_DELAY (24) + +#define RF_LONG_PRESS_DELAY 30 +#define DEV_RESET_PRESS_DELAY 30 +#define RGB_TEST_PRESS_DELAY 30 + +typedef struct { uint8_t RXDState; uint8_t RXDLen; uint8_t RXDOverTime; @@ -116,8 +114,7 @@ typedef struct uint8_t RXDBuf[UART_MAX_LEN]; } USART_MGR_STRUCT; -typedef struct -{ +typedef struct { uint8_t link_mode; uint8_t rf_channel; uint8_t ble_channel; @@ -128,8 +125,7 @@ typedef struct uint8_t sys_sw_state; } DEV_INFO_STRUCT; -typedef struct -{ +typedef struct { uint8_t default_brightness_flag; uint8_t ee_side_mode; uint8_t ee_side_light; diff --git a/keyboards/nuphy/air75_v2/ansi/rf.c b/keyboards/nuphy/air75_v2/ansi/rf.c index f01dcb6c8904..3c960a8d4c0b 100644 --- a/keyboards/nuphy/air75_v2/ansi/rf.c +++ b/keyboards/nuphy/air75_v2/ansi/rf.c @@ -21,11 +21,11 @@ along with this program. If not, see . #include "rf_driver.h" USART_MGR_STRUCT Usart_Mgr; -#define RX_SBYTE Usart_Mgr.RXDBuf[0] -#define RX_CMD Usart_Mgr.RXDBuf[1] -#define RX_ACK Usart_Mgr.RXDBuf[2] -#define RX_LEN Usart_Mgr.RXDBuf[3] -#define RX_DAT Usart_Mgr.RXDBuf[4] +#define RX_SBYTE Usart_Mgr.RXDBuf[0] +#define RX_CMD Usart_Mgr.RXDBuf[1] +#define RX_ACK Usart_Mgr.RXDBuf[2] +#define RX_LEN Usart_Mgr.RXDBuf[3] +#define RX_DAT Usart_Mgr.RXDBuf[4] bool f_uart_ack = 0; bool f_rf_read_data_ok = 0; @@ -64,18 +64,15 @@ void uart_receive_pro(void); void break_all_key(void); uint16_t host_last_consumer_usage(void); - - /** * @brief Uart auto nkey send */ -bool f_bit_kb_act = 0; -static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report, uint8_t size) -{ +bool f_bit_kb_act = 0; +static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report, uint8_t size) { uint8_t i, j, byte_index; uint8_t change_mask, offset_mask; - uint8_t key_code = 0; - bool f_byte_send = 0, f_bit_send = 0; + uint8_t key_code = 0; + bool f_byte_send = 0, f_bit_send = 0; if (pre_bit_report[0] ^ now_bit_report[0]) { bytekb_report_buf[0] = now_bit_report[0]; @@ -128,16 +125,16 @@ static void uart_auto_nkey_send(uint8_t *pre_bit_report, uint8_t *now_bit_report } } - /** * @brief Uart send keys report. */ -void uart_send_report_repeat(void) -{ +void uart_send_report_repeat(void) { static uint32_t interval_timer = 0; - if (dev_info.link_mode == LINK_USB) return; - keyboard_protocol = 1; + if (dev_info.link_mode == LINK_USB) { + return; + } + keyboard_protocol = 1; if (timer_elapsed32(interval_timer) > 50) { interval_timer = timer_read32(); @@ -145,10 +142,10 @@ void uart_send_report_repeat(void) uart_send_report(CMD_RPT_BYTE_KB, bytekb_report_buf, 8); wait_us(200); - if(f_bit_kb_act) + if (f_bit_kb_act) { uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16); - } - else { + } + } else { f_bit_kb_act = 0; } } @@ -210,7 +207,7 @@ void RF_Protocol_Receive(void) { if (Usart_Mgr.RXDState == RX_Done) { f_uart_ack = 1; - sync_lost = 0; + sync_lost = 0; if (Usart_Mgr.RXDLen > 4) { for (i = 0; i < RX_LEN; i++) @@ -256,10 +253,13 @@ void RF_Protocol_Receive(void) { dev_info.rf_charge = Usart_Mgr.RXDBuf[7]; - if (Usart_Mgr.RXDBuf[8] <= 100) dev_info.rf_battery = Usart_Mgr.RXDBuf[8]; - if (dev_info.rf_charge & 0x01) dev_info.rf_battery = 100; - } - else { + if (Usart_Mgr.RXDBuf[8] <= 100) { + dev_info.rf_battery = Usart_Mgr.RXDBuf[8]; + } + if (dev_info.rf_charge & 0x01) { + dev_info.rf_battery = 100; + } + } else { if (dev_info.rf_state != RF_INVALID) { if (error_cnt >= 5) { error_cnt = 0; @@ -423,7 +423,9 @@ uint8_t uart_send_cmd(uint8_t cmd, uint8_t wait_ack, uint8_t delayms) { if (wait_ack) { while (wait_ack--) { wait_ms(1); - if (f_uart_ack) return TX_OK; + if (f_uart_ack) { + return TX_OK; + } } } else { return TX_OK; @@ -439,10 +441,11 @@ void dev_sts_sync(void) { static uint32_t interval_timer = 0; static uint8_t link_state_temp = RF_DISCONNECT; - if (timer_elapsed32(interval_timer) < 200) + if (timer_elapsed32(interval_timer) < 200) { return; - else + } else { interval_timer = timer_read32(); + } if (f_rf_reset) { f_rf_reset = 0; @@ -451,8 +454,7 @@ void dev_sts_sync(void) { wait_ms(50); gpio_write_pin_high(NRF_RESET_PIN); wait_ms(50); - } - else if (f_send_channel) { + } else if (f_send_channel) { f_send_channel = 0; uart_send_cmd(CMD_SET_LINK, 10, 10); } @@ -464,8 +466,7 @@ void dev_sts_sync(void) { break_all_key(); } rf_blink_cnt = 0; - } - else { + } else { if (host_mode != HOST_RF_TYPE) { host_mode = HOST_RF_TYPE; break_all_key(); @@ -474,14 +475,13 @@ void dev_sts_sync(void) { if (dev_info.rf_state != RF_CONNECT) { if (disconnect_delay >= 10) { - rf_blink_cnt = 3; + rf_blink_cnt = 3; rf_link_show_time = 0; - link_state_temp = dev_info.rf_state; + link_state_temp = dev_info.rf_state; } else { disconnect_delay++; } - } - else if (dev_info.rf_state == RF_CONNECT) { + } else if (dev_info.rf_state == RF_CONNECT) { rf_linking_time = 0; disconnect_delay = 0; rf_blink_cnt = 0; @@ -542,9 +542,15 @@ uint8_t get_checksum(uint8_t *buf, uint8_t len) { * @param report_size report_size */ void uart_send_report(uint8_t report_type, uint8_t *report_buf, uint8_t report_size) { - if (f_dial_sw_init_ok == 0) return; - if (dev_info.link_mode == LINK_USB) return; - if (dev_info.rf_state != RF_CONNECT) return; + if (f_dial_sw_init_ok == 0) { + return; + } + if (dev_info.link_mode == LINK_USB) { + return; + } + if (dev_info.rf_state != RF_CONNECT) { + return; + } Usart_Mgr.TXDBuf[0] = UART_HEAD; Usart_Mgr.TXDBuf[1] = report_type; @@ -571,8 +577,7 @@ void uart_receive_pro(void) { if (Usart_Mgr.RXDLen >= UART_MAX_LEN) { uart_read(); - } - else { + } else { Usart_Mgr.RXDBuf[Usart_Mgr.RXDLen++] = uart_read(); } @@ -586,7 +591,7 @@ void uart_receive_pro(void) { rcv_start = false; Usart_Mgr.RXDState = RX_Done; RF_Protocol_Receive(); - Usart_Mgr.RXDLen = 0; + Usart_Mgr.RXDLen = 0; } } @@ -621,7 +626,9 @@ void rf_device_init(void) { wait_ms(5); uart_receive_pro(); // receive data uart_receive_pro(); // parsing data - if (f_rf_hand_ok) break; + if (f_rf_hand_ok) { + break; + } } timeout = 10; @@ -631,7 +638,9 @@ void rf_device_init(void) { wait_ms(5); uart_receive_pro(); uart_receive_pro(); - if (f_rf_read_data_ok) break; + if (f_rf_read_data_ok) { + break; + } } timeout = 10; @@ -641,7 +650,9 @@ void rf_device_init(void) { wait_ms(5); uart_receive_pro(); uart_receive_pro(); - if (f_rf_sts_sysc_ok) break; + if (f_rf_sts_sysc_ok) { + break; + } } uart_send_cmd(CMD_SET_NAME, 10, 20); diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index be35313ce2ca..a12cc07e3e3e 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -20,15 +20,15 @@ along with this program. If not, see . #include "side_table.h" #include "ws2812.h" -uint8_t side_mode = 0; -uint8_t side_light = 3; -uint8_t side_speed = 2; -uint8_t side_rgb = 1; -uint8_t side_colour = 0; -uint8_t side_play_point = 0; -uint8_t side_play_cnt = 0; -uint32_t side_play_timer = 0; -uint8_t r_temp, g_temp, b_temp; +uint8_t side_mode = 0; +uint8_t side_light = 3; +uint8_t side_speed = 2; +uint8_t side_rgb = 1; +uint8_t side_colour = 0; +uint8_t side_play_point = 0; +uint8_t side_play_cnt = 0; +uint32_t side_play_timer = 0; +uint8_t r_temp, g_temp, b_temp; rgb_led_t side_leds[SIDE_LED_NUM] = {0}; extern DEV_INFO_STRUCT dev_info; @@ -87,12 +87,18 @@ void side_light_control(uint8_t dir) { * @note save to eeprom. */ void side_speed_control(uint8_t dir) { - if ((side_speed) > SIDE_SPEED_MAX) (side_speed) = SIDE_SPEED_MAX / 2; + if ((side_speed) > SIDE_SPEED_MAX) { + (side_speed) = SIDE_SPEED_MAX / 2; + } if (dir) { - if ((side_speed)) side_speed--; + if ((side_speed)) { + side_speed--; + } } else { - if ((side_speed) < SIDE_SPEED_MAX) side_speed++; + if ((side_speed) < SIDE_SPEED_MAX) { + side_speed++; + } } kb_config.ee_side_speed = side_speed; eeconfig_update_kb_datablock(&kb_config); @@ -156,7 +162,7 @@ void side_mode_control(uint8_t dir) { side_mode = SIDE_OFF; } } - side_play_point = 0; + side_play_point = 0; kb_config.ee_side_mode = side_mode; eeconfig_update_kb_datablock(&kb_config); } @@ -317,10 +323,14 @@ void sys_led_show(void) { static void light_point_playing(uint8_t trend, uint8_t step, uint8_t len, uint8_t *point) { if (trend) { *point += step; - if (*point >= len) *point -= len; + if (*point >= len) { + *point -= len; + } } else { *point -= step; - if (*point >= len) *point = len - (255 - *point) - 1; + if (*point >= len) { + *point = len - (255 - *point) - 1; + } } } @@ -330,16 +340,20 @@ static void light_point_playing(uint8_t trend, uint8_t step, uint8_t len, uint8_ static void side_wave_mode_show(void) { uint8_t play_index; - if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) { return; - else + } else { side_play_cnt -= side_speed_tab[side_mode][side_speed]; - if (side_play_cnt > 20) side_play_cnt = 0; + } + if (side_play_cnt > 20) { + side_play_cnt = 0; + } - if (side_rgb) + if (side_rgb) { light_point_playing(0, 3, FLOW_COLOUR_TAB_LEN, &side_play_point); - else + } else { light_point_playing(0, 2, WAVE_TAB_LEN, &side_play_point); + } play_index = side_play_point; for (int i = 0; i < SIDE_LINE; i++) { @@ -370,11 +384,14 @@ static void side_wave_mode_show(void) { * @brief side_spectrum_mode_show. */ static void side_spectrum_mode_show(void) { - if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) { return; - else + } else { side_play_cnt -= side_speed_tab[side_mode][side_speed]; - if (side_play_cnt > 20) side_play_cnt = 0; + } + if (side_play_cnt > 20) { + side_play_cnt = 0; + } light_point_playing(1, 1, FLOW_COLOUR_TAB_LEN, &side_play_point); @@ -397,17 +414,22 @@ static void side_spectrum_mode_show(void) { static void side_breathe_mode_show(void) { static uint8_t play_point = 0; - if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) { return; - else + } else { side_play_cnt -= side_speed_tab[side_mode][side_speed]; - if (side_play_cnt > 20) side_play_cnt = 0; + } + if (side_play_cnt > 20) { + side_play_cnt = 0; + } light_point_playing(0, 1, BREATHE_TAB_LEN, &play_point); if (0) { if (play_point == 0) { - if (++side_play_point >= SIDE_COLOUR_MAX) side_play_point = 0; + if (++side_play_point >= SIDE_COLOUR_MAX) { + side_play_point = 0; + } } r_temp = colour_lib[side_play_point][0]; @@ -435,13 +457,18 @@ static void side_breathe_mode_show(void) { static void side_static_mode_show(void) { uint8_t play_index; - if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) { return; - else + } else { side_play_cnt -= side_speed_tab[side_mode][side_speed]; - if (side_play_cnt > 20) side_play_cnt = 0; + } + if (side_play_cnt > 20) { + side_play_cnt = 0; + } - if (side_play_point >= SIDE_COLOUR_MAX) side_play_point = 0; + if (side_play_point >= SIDE_COLOUR_MAX) { + side_play_point = 0; + } for (int i = 0; i < SIDE_LINE; i++) { if (0) { @@ -467,11 +494,14 @@ static void side_static_mode_show(void) { * @brief side_off_mode_show. */ static void side_off_mode_show(void) { - if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) + if (side_play_cnt <= side_speed_tab[side_mode][side_speed]) { return; - else + } else { side_play_cnt -= side_speed_tab[side_mode][side_speed]; - if (side_play_cnt > 20) side_play_cnt = 0; + } + if (side_play_cnt > 20) { + side_play_cnt = 0; + } r_temp = 0x00; g_temp = 0x00; @@ -511,10 +541,11 @@ void rf_led_show(void) { } if (rf_blink_cnt) { - if (dev_info.rf_state == RF_PAIRING) + if (dev_info.rf_state == RF_PAIRING) { rf_blink_priod = RF_LED_PAIR_PERIOD; - else + } else { rf_blink_priod = RF_LED_LINK_PERIOD; + } if (timer_elapsed32(rf_blink_timer) > (rf_blink_priod >> 1)) { r_temp = 0x00; @@ -534,8 +565,7 @@ void rf_led_show(void) { /** * @brief bat_num_led. */ -void bat_num_led(uint8_t bat_percent) -{ +void bat_num_led(uint8_t bat_percent) { uint8_t r, g, b; uint8_t bat_idx = bat_percent / 17; uint8_t bat_lvl = 1 + ((bat_percent - 1) / 10); @@ -545,24 +575,21 @@ void bat_num_led(uint8_t bat_percent) b = bat_percent_tab[bat_idx][2]; // set percent - for (uint8_t i = 0; i < bat_lvl ; i++) { + for (uint8_t i = 0; i < bat_lvl; i++) { rgb_matrix_set_color(29 - i, r, g, b); } } -void num_led_show(void) -{ - static uint8_t num_bat_temp = 0; - num_bat_temp = dev_info.rf_battery; +void num_led_show(void) { + static uint8_t num_bat_temp = 0; + num_bat_temp = dev_info.rf_battery; bat_num_led(num_bat_temp); } -void bat_led_close(void) -{ - for(int i=20; i<=29; i++) { - rgb_matrix_set_color(i,0,0,0); +void bat_led_close(void) { + for (int i = 20; i <= 29; i++) { + rgb_matrix_set_color(i, 0, 0, 0); } - } /** @@ -570,7 +597,7 @@ void bat_led_close(void) */ void bat_percent_led(uint8_t bat_percent) { uint8_t bat_idx = bat_percent / 17; - uint8_t bright = side_light; + uint8_t bright = side_light; if (bright < 1) { bright = 1; } @@ -667,7 +694,6 @@ void bat_led_show(void) { * @brief device_reset_show. */ void device_reset_show(void) { - gpio_write_pin_high(DC_BOOST_PIN); gpio_set_pin_output_push_pull(DRIVER_SIDE_CS_PIN); gpio_set_pin_output_push_pull(DRIVER_LED_CS_PIN); @@ -724,9 +750,8 @@ void device_reset_init(void) { /** * RGB test -*/ -void rgb_test_show(void) -{ + */ +void rgb_test_show(void) { // open power control gpio_write_pin_high(DC_BOOST_PIN); gpio_set_pin_output_push_pull(DRIVER_LED_CS_PIN); diff --git a/keyboards/nuphy/air75_v2/ansi/side.h b/keyboards/nuphy/air75_v2/ansi/side.h index 578b2818ac97..10787c5fc82c 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.h +++ b/keyboards/nuphy/air75_v2/ansi/side.h @@ -15,15 +15,15 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#define SIDE_BRIGHT_MAX 4 -#define SIDE_SPEED_MAX 4 -#define SIDE_COLOUR_MAX 8 +#define SIDE_BRIGHT_MAX 4 +#define SIDE_SPEED_MAX 4 +#define SIDE_COLOUR_MAX 8 -#define SIDE_LINE 6 -#define SIDE_LED_NUM 12 +#define SIDE_LINE 6 +#define SIDE_LED_NUM 12 -#define RF_LED_LINK_PERIOD 500 -#define RF_LED_PAIR_PERIOD 250 +#define RF_LED_LINK_PERIOD 500 +#define RF_LED_PAIR_PERIOD 250 /* side rgb mode */ enum { diff --git a/keyboards/nuphy/air75_v2/ansi/side_driver.c b/keyboards/nuphy/air75_v2/ansi/side_driver.c index 00b4c2712783..4c1feb4b5bc7 100644 --- a/keyboards/nuphy/air75_v2/ansi/side_driver.c +++ b/keyboards/nuphy/air75_v2/ansi/side_driver.c @@ -24,49 +24,47 @@ along with this program. If not, see . /* Adapted from https://github.com/bigjosh/SimpleNeoPixelDemo/ */ #ifndef NOP_FUDGE -#if defined(STM32F0XX) || defined(STM32F1XX) || defined(GD32VF103) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) || defined(WB32F3G71xx) || defined(WB32FQ95xx) -#define NOP_FUDGE 0.4 -#else -#error("NOP_FUDGE configuration required") -#define NOP_FUDGE 1 // this just pleases the compiler so the above error is easier to spot -#endif +# if defined(STM32F0XX) || defined(STM32F1XX) || defined(GD32VF103) || defined(STM32F3XX) || defined(STM32F4XX) || defined(STM32L0XX) || defined(WB32F3G71xx) || defined(WB32FQ95xx) +# define NOP_FUDGE 0.4 +# else +# error("NOP_FUDGE configuration required") +# define NOP_FUDGE 1 // this just pleases the compiler so the above error is easier to spot +# endif #endif // Push Pull or Open Drain Configuration // Default Push Pull #ifndef WS2812_EXTERNAL_PULLUP -#define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_PUSHPULL +# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_PUSHPULL #else -#define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_OPENDRAIN +# define WS2812_OUTPUT_MODE PAL_MODE_OUTPUT_OPENDRAIN #endif // The reset gap can be 6000 ns, but depending on the LED strip it may have to be increased // to values like 600000 ns. If it is too small, the pixels will show nothing most of the time. #ifndef WS2812_RES -#define WS2812_RES (1000 * WS2812_TRST_US) // Width of the low gap between bits to cause a frame to latch +# define WS2812_RES (1000 * WS2812_TRST_US) // Width of the low gap between bits to cause a frame to latch #endif -#define NUMBER_NOPS 6 -#define CYCLES_PER_SEC (CPU_CLOCK / NUMBER_NOPS * NOP_FUDGE) -#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives -#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC) +#define NUMBER_NOPS 6 +#define CYCLES_PER_SEC (CPU_CLOCK / NUMBER_NOPS * NOP_FUDGE) +#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives +#define NS_PER_CYCLE (NS_PER_SEC / CYCLES_PER_SEC) #define NS_TO_CYCLES(n) ((n) / NS_PER_CYCLE) #define wait_ns(x) \ do { \ for (int i = 0; i < NS_TO_CYCLES(x); i++) { \ - __asm__ volatile( \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t"); \ + __asm__ volatile("nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t"); \ } \ } while (0) -void side_sendByte(uint8_t byte) -{ +void side_sendByte(uint8_t byte) { // WS2812 protocol wants most significant bits first for (unsigned char bit = 0; bit < 8; bit++) { bool is_one = byte & (1 << (7 - bit)); @@ -88,8 +86,7 @@ void side_sendByte(uint8_t byte) } // Setleds for standard RGB -void side_ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) -{ +void side_ws2812_setleds(rgb_led_t *ledarray, uint16_t leds) { // this code is very time dependent, so we need to disable interrupts chSysLock(); diff --git a/keyboards/nuphy/air75_v2/ansi/sleep.c b/keyboards/nuphy/air75_v2/ansi/sleep.c index df12b04f907d..0c23db9c7418 100644 --- a/keyboards/nuphy/air75_v2/ansi/sleep.c +++ b/keyboards/nuphy/air75_v2/ansi/sleep.c @@ -33,23 +33,26 @@ uint8_t uart_send_cmd(uint8_t cmd, uint8_t ack_cnt, uint8_t delayms); * @brief Sleep Handle. */ void sleep_handle(void) { - static uint32_t delay_step_timer = 0; + static uint32_t delay_step_timer = 0; static uint8_t usb_suspend_debounce = 0; - static uint32_t rf_disconnect_time = 0; + static uint32_t rf_disconnect_time = 0; /* 50ms interval */ - if (timer_elapsed32(delay_step_timer) < 50) return; + if (timer_elapsed32(delay_step_timer) < 50) { + return; + } delay_step_timer = timer_read32(); // sleep process if (f_goto_sleep) { f_goto_sleep = 0; - if(kb_config.sleep_enable) { - if (dev_info.rf_state == RF_CONNECT) + if (kb_config.sleep_enable) { + if (dev_info.rf_state == RF_CONNECT) { uart_send_cmd(CMD_SET_CONFIG, 5, 5); - else + } else { uart_send_cmd(CMD_SLEEP, 5, 5); + } // power off LED gpio_set_pin_output_push_pull(DC_BOOST_PIN); @@ -82,8 +85,9 @@ void sleep_handle(void) { } // sleep check - if (f_goto_sleep || f_wakeup_prepare) + if (f_goto_sleep || f_wakeup_prepare) { return; + } if (dev_info.link_mode == LINK_USB) { if (USB_DRIVER.state == USB_SUSPENDED) { usb_suspend_debounce++; @@ -105,7 +109,7 @@ void sleep_handle(void) { rf_disconnect_time++; if (rf_disconnect_time > 5 * 20) { rf_disconnect_time = 0; - f_goto_sleep = 1; + f_goto_sleep = 1; } } } From df959ae2fdfe868ba9548c4b0550e91293bc2ce6 Mon Sep 17 00:00:00 2001 From: nuphy-src Date: Thu, 20 Jun 2024 15:44:03 +0800 Subject: [PATCH 16/16] fixes the spelling and formatting errors Revert "Remove function" This reverts commit 861b3fc0daa86ba29e6b9826640e9104969c9f46. revert commit remove function --- keyboards/nuphy/air75_v2/ansi/ansi.c | 8 ++++---- keyboards/nuphy/air75_v2/ansi/kb_util.c | 14 +++++++------- keyboards/nuphy/air75_v2/ansi/kb_util.h | 8 ++++---- keyboards/nuphy/air75_v2/ansi/rf.c | 14 +++++++------- keyboards/nuphy/air75_v2/ansi/side.c | 16 ++++++++-------- keyboards/nuphy/air75_v2/ansi/side_driver.c | 2 +- keyboards/nuphy/air75_v2/ansi/sleep.c | 2 +- 7 files changed, 32 insertions(+), 32 deletions(-) diff --git a/keyboards/nuphy/air75_v2/ansi/ansi.c b/keyboards/nuphy/air75_v2/ansi/ansi.c index 16fd2cb4b856..2154656713cc 100644 --- a/keyboards/nuphy/air75_v2/ansi/ansi.c +++ b/keyboards/nuphy/air75_v2/ansi/ansi.c @@ -152,13 +152,13 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { case SIDE_VAI: if (record->event.pressed) { - side_light_contol(1); + side_light_control(1); } return false; case SIDE_VAD: if (record->event.pressed) { - side_light_contol(0); + side_light_control(0); } return false; @@ -176,13 +176,13 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { case SIDE_SPI: if (record->event.pressed) { - side_speed_contol(1); + side_speed_control(1); } return false; case SIDE_SPD: if (record->event.pressed) { - side_speed_contol(0); + side_speed_control(0); } return false; diff --git a/keyboards/nuphy/air75_v2/ansi/kb_util.c b/keyboards/nuphy/air75_v2/ansi/kb_util.c index bb18df1105c0..4f53a56357c7 100644 --- a/keyboards/nuphy/air75_v2/ansi/kb_util.c +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.c @@ -22,7 +22,7 @@ along with this program. If not, see . kb_config_t kb_config; DEV_INFO_STRUCT dev_info = { - .rf_baterry = 100, + .rf_battery = 100, .link_mode = LINK_USB, .rf_state = RF_IDLE, }; @@ -59,15 +59,15 @@ extern uint8_t side_rgb; extern uint8_t side_colour; /** - * @brief gpio initial. + * @brief Initialize GPIO. */ void gpio_init(void) { - /* enable led power driver */ + /* enable LED power driver */ gpio_set_pin_output_push_pull(DRIVER_LED_CS_PIN); gpio_set_pin_output_push_pull(DRIVER_SIDE_CS_PIN); gpio_write_pin_low(DRIVER_LED_CS_PIN); gpio_write_pin_low(DRIVER_SIDE_CS_PIN); - /* set side led pin output low */ + /* set side LED pin output low */ gpio_set_pin_output_push_pull(DRIVER_SIDE_PIN); gpio_write_pin_low(DRIVER_SIDE_PIN); /* config RF module pin */ @@ -82,7 +82,7 @@ void gpio_init(void) { /* config dial switch pin */ gpio_set_pin_input_high(DEV_MODE_PIN); gpio_set_pin_input_high(SYS_MODE_PIN); - /* open led DC driver */ + /* open LED DC driver */ gpio_set_pin_output_push_pull(DC_BOOST_PIN); gpio_write_pin_high(DC_BOOST_PIN); } @@ -118,7 +118,7 @@ void long_press_key(void) { rf_sw_press_delay = 0; } - // The device is restored to factory Settings + // The device is restored to factory settings if (f_dev_reset_press) { dev_reset_press_delay++; if (dev_reset_press_delay >= DEV_RESET_PRESS_DELAY) { @@ -399,7 +399,7 @@ void timer_pro(void) { void londing_eeprom_data(void) { eeconfig_read_kb_datablock(&kb_config); if (kb_config.default_brightness_flag != 0xA5) { - /* first power on, set rgb matrix brightness at middle level*/ + /* upon first power on, set RGB matrix brightness to middle level */ rgb_matrix_sethsv(255, 255, RGB_MATRIX_MAXIMUM_BRIGHTNESS - RGB_MATRIX_VAL_STEP * 2); kb_config.default_brightness_flag = 0xA5; kb_config.ee_side_mode = side_mode; diff --git a/keyboards/nuphy/air75_v2/ansi/kb_util.h b/keyboards/nuphy/air75_v2/ansi/kb_util.h index 47ef18e8f493..2e5049914573 100644 --- a/keyboards/nuphy/air75_v2/ansi/kb_util.h +++ b/keyboards/nuphy/air75_v2/ansi/kb_util.h @@ -47,7 +47,7 @@ typedef enum { #define RF_DISCONNECT 4 #define RF_SLEEP 5 #define RF_SNIF 6 -#define RF_INVAILD 0XFE +#define RF_INVALID 0XFE #define RF_ERR_STATE 0XFF #define CMD_POWER_UP 0XF0 @@ -124,7 +124,7 @@ typedef struct uint8_t rf_state; uint8_t rf_charge; uint8_t rf_led; - uint8_t rf_baterry; + uint8_t rf_battery; uint8_t sys_sw_state; } DEV_INFO_STRUCT; @@ -147,8 +147,8 @@ void rf_device_init(void); void uart_send_report_repeat(void); void uart_receive_pro(void); void uart_send_report(uint8_t report_type, uint8_t *report_buf, uint8_t report_size); -void side_speed_contol(uint8_t dir); -void side_light_contol(uint8_t dir); +void side_speed_control(uint8_t dir); +void side_light_control(uint8_t dir); void side_colour_control(uint8_t dir); void side_mode_control(uint8_t dir); void side_led_show(void); diff --git a/keyboards/nuphy/air75_v2/ansi/rf.c b/keyboards/nuphy/air75_v2/ansi/rf.c index 9efd372e4261..f01dcb6c8904 100644 --- a/keyboards/nuphy/air75_v2/ansi/rf.c +++ b/keyboards/nuphy/air75_v2/ansi/rf.c @@ -146,7 +146,7 @@ void uart_send_report_repeat(void) wait_us(200); if(f_bit_kb_act) - uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16); + uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16); } else { f_bit_kb_act = 0; @@ -256,11 +256,11 @@ void RF_Protocol_Receive(void) { dev_info.rf_charge = Usart_Mgr.RXDBuf[7]; - if (Usart_Mgr.RXDBuf[8] <= 100) dev_info.rf_baterry = Usart_Mgr.RXDBuf[8]; - if (dev_info.rf_charge & 0x01) dev_info.rf_baterry = 100; + if (Usart_Mgr.RXDBuf[8] <= 100) dev_info.rf_battery = Usart_Mgr.RXDBuf[8]; + if (dev_info.rf_charge & 0x01) dev_info.rf_battery = 100; } else { - if (dev_info.rf_state != RF_INVAILD) { + if (dev_info.rf_state != RF_INVALID) { if (error_cnt >= 5) { error_cnt = 0; f_send_channel = 1; @@ -506,7 +506,7 @@ void dev_sts_sync(void) { /** * @brief Uart send bytes. * @param Buffer data buf - * @param Length data lenght + * @param Length data length */ void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length) { gpio_write_pin_low(NRF_WAKEUP_PIN); @@ -521,7 +521,7 @@ void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length) { /** * @brief get checksum. * @param buf data buf - * @param len data lenght + * @param len data length */ uint8_t get_checksum(uint8_t *buf, uint8_t len) { uint8_t i; @@ -560,7 +560,7 @@ void uart_send_report(uint8_t report_type, uint8_t *report_buf, uint8_t report_s } /** - * @brief Uart receives data and processes it after completion,. + * @brief Uart receives data and processes it after completion. */ void uart_receive_pro(void) { static bool rcv_start = false; diff --git a/keyboards/nuphy/air75_v2/ansi/side.c b/keyboards/nuphy/air75_v2/ansi/side.c index 38d46aa65a64..a853e8816e7b 100644 --- a/keyboards/nuphy/air75_v2/ansi/side.c +++ b/keyboards/nuphy/air75_v2/ansi/side.c @@ -89,7 +89,7 @@ void side_ws2812_setleds(rgb_led_t *ledarray, uint16_t leds); void rgb_matrix_update_pwm_buffers(void); /** - * @brief side leds set color vaule. + * @brief side leds set color value. * @param index: index of side_leds[]. * @param ... */ @@ -111,7 +111,7 @@ void side_rgb_refresh(void) { * @param dir: 0 - decrease, 1 - increase. * @note save to eeprom. */ -void side_light_contol(uint8_t dir) { +void side_light_control(uint8_t dir) { if (dir) { if (side_light > SIDE_BRIGHT_MAX) { return; @@ -132,7 +132,7 @@ void side_light_contol(uint8_t dir) { * @param dir: 0 - decrease, 1 - increase. * @note save to eeprom. */ -void side_speed_contol(uint8_t dir) { +void side_speed_control(uint8_t dir) { if ((side_speed) > SIDE_SPEED_MAX) (side_speed) = SIDE_SPEED_MAX / 2; if (dir) { @@ -588,7 +588,7 @@ void bat_num_led(uint8_t bat_percent) void num_led_show(void) { static uint8_t num_bat_temp = 0; - num_bat_temp = dev_info.rf_baterry; + num_bat_temp = dev_info.rf_battery; bat_num_led(num_bat_temp); } @@ -659,7 +659,7 @@ void bat_led_show(void) { f_init = 0; bat_show_time = timer_read32(); charge_state = dev_info.rf_charge; - bat_percent = dev_info.rf_baterry; + bat_percent = dev_info.rf_battery; } if (charge_state != dev_info.rf_charge) { @@ -680,13 +680,13 @@ void bat_led_show(void) { if (charge_state == 0x03) { bat_show_breath = true; } else if (charge_state & 0x01) { - dev_info.rf_baterry = 100; + dev_info.rf_battery = 100; } } - if (bat_percent != dev_info.rf_baterry) { + if (bat_percent != dev_info.rf_battery) { if (timer_elapsed32(bat_per_debounce) > 1000) { - bat_percent = dev_info.rf_baterry; + bat_percent = dev_info.rf_battery; } } else { bat_per_debounce = timer_read32(); diff --git a/keyboards/nuphy/air75_v2/ansi/side_driver.c b/keyboards/nuphy/air75_v2/ansi/side_driver.c index 7ecdc52db5b8..00b4c2712783 100644 --- a/keyboards/nuphy/air75_v2/ansi/side_driver.c +++ b/keyboards/nuphy/air75_v2/ansi/side_driver.c @@ -28,7 +28,7 @@ along with this program. If not, see . #define NOP_FUDGE 0.4 #else #error("NOP_FUDGE configuration required") -#define NOP_FUDGE 1 // this just pleases the compile so the above error is easier to spot +#define NOP_FUDGE 1 // this just pleases the compiler so the above error is easier to spot #endif #endif diff --git a/keyboards/nuphy/air75_v2/ansi/sleep.c b/keyboards/nuphy/air75_v2/ansi/sleep.c index e553262f9c67..df12b04f907d 100644 --- a/keyboards/nuphy/air75_v2/ansi/sleep.c +++ b/keyboards/nuphy/air75_v2/ansi/sleep.c @@ -51,7 +51,7 @@ void sleep_handle(void) { else uart_send_cmd(CMD_SLEEP, 5, 5); - // power off led + // power off LED gpio_set_pin_output_push_pull(DC_BOOST_PIN); gpio_write_pin_low(DC_BOOST_PIN);