diff --git a/keyboards/nuphy/gem80/ansi/ansi.c b/keyboards/nuphy/gem80/ansi/ansi.c new file mode 100644 index 000000000000..6047446b4747 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/ansi.c @@ -0,0 +1,823 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include QMK_KEYBOARD_H +#include "ansi.h" +#include "usb_main.h" + + + +#define RF_LONG_PRESS_DELAY 30 +#define DEV_RESET_PRESS_DELAY 30 +#define RGB_TEST_PRESS_DELAY 30 + +user_config_t user_config; + +DEV_INFO_STRUCT dev_info = + { + .rf_baterry = 100, + .link_mode = LINK_USB, + .rf_state = RF_IDLE, +}; + +uint16_t rf_linking_time = 0; +uint16_t rf_link_show_time = 0; +uint8_t rf_blink_cnt = 0; +uint16_t no_act_time = 0; +uint8_t rf_sw_temp = 0; +uint16_t dev_reset_press_delay = 0; +uint16_t rf_sw_press_delay = 0; +uint16_t rgb_test_press_delay = 0; +uint8_t host_mode; +host_driver_t *m_host_driver = 0; + +extern uint8_t side_mode; +extern uint8_t side_light; +extern uint8_t side_speed; +extern uint8_t side_rgb; +extern uint8_t side_colour; +extern uint8_t logo_mode; +extern uint8_t logo_light; +extern uint8_t logo_speed; +extern uint8_t logo_rgb; +extern uint8_t logo_colour; +extern uint8_t uart_bit_report_buf[32]; +extern uint8_t bitkb_report_buf[32]; +extern uint8_t bytekb_report_buf[8]; + +bool f_goto_sleep = 0; +bool f_bat_show = 0; +bool f_bat_hold = 0; +bool f_chg_show = 1; +bool f_sys_show = 0; +bool f_sleep_show = 0; +bool f_func_save = 0; +bool f_rf_read_data_ok = 0; +bool f_rf_sts_sysc_ok = 0; +bool f_rf_new_adv_ok = 0; +bool f_rf_reset = 0; +bool f_send_channel = 0; +bool f_rf_send_bitkb = 0; +bool f_rf_send_byte = 0; +bool f_rf_send_consume = 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_win_lock = 0; +bool f_uart_ack = 0; +bool f_rf_hand_ok = 0; + + +void rf_uart_init(void); +void rf_device_init(void); +void m_side_led_show(void); +void dev_sts_sync(void); +void uart_send_report_func(void); +void uart_receive_pro(void); +void Sleep_Handle(void); +uint8_t uart_send_cmd(uint8_t cmd, uint8_t ack_cnt, uint8_t delayms); +void uart_send_report(uint8_t report_type, uint8_t *report_buf, uint8_t report_size); +void device_reset_show(void); +void device_reset_init(void); +void rgb_test_show(void); + +extern void light_speed_contol(uint8_t fast); +extern void light_level_control(uint8_t brighten); +extern void side_colour_control(uint8_t dir); +extern void side_mode_control(uint8_t dir); +extern void logo_light_speed_contol(uint8_t fast); +extern void logo_light_level_control(uint8_t brighten); +extern void logo_side_colour_control(uint8_t dir); +extern void logo_side_mode_control(uint8_t dir); + + +void flash_data_manage(void) +{ + if (f_func_save) { + f_func_save = 0; + uart_send_cmd(CMD_WRITE_DATA, 20, 30); + } +} + +/** + * @brief gpio initial. + */ +void m_gpio_init(void) +{ + setPinOutput(DC_BOOST_PIN); writePinHigh(DC_BOOST_PIN); + + setPinInput(DRIVER_LED_CS_PIN); + setPinInput(DRIVER_SIDE_CS_PIN); + setPinOutput(DRIVER_SIDE_PIN); writePinLow(DRIVER_SIDE_PIN); +#if(WORK_MODE == THREE_MODE) + setPinOutput(NRF_WAKEUP_PIN); + writePinHigh(NRF_WAKEUP_PIN); + + setPinInputHigh(NRF_BOOT_PIN); + + setPinOutput(NRF_RESET_PIN); writePinLow(NRF_RESET_PIN); + wait_ms(50); + writePinHigh(NRF_RESET_PIN); + + setPinInputHigh(DEV_MODE_PIN); +#endif + setPinInputHigh(SYS_MODE_PIN); + + // open power + setPinOutput(DC_BOOST_PIN); + writePinHigh(DC_BOOST_PIN); + + setPinOutput(DRIVER_LED_CS_PIN); + writePinLow(DRIVER_LED_CS_PIN); + + setPinOutput(DRIVER_SIDE_CS_PIN); + writePinLow(DRIVER_SIDE_CS_PIN); +} + +/** + * @brief long press key process. + */ +void long_press_key(void) +{ + static uint32_t long_press_timer = 0; + + if (timer_elapsed32(long_press_timer) < 100) return; + long_press_timer = timer_read32(); + if (f_rf_sw_press) { + rf_sw_press_delay++; + if (rf_sw_press_delay >= RF_LONG_PRESS_DELAY) { + f_rf_sw_press = 0; + dev_info.link_mode = rf_sw_temp; + dev_info.rf_channel = rf_sw_temp; + dev_info.ble_channel = rf_sw_temp; + uint8_t timeout = 5; + while (timeout--) { + uart_send_cmd(CMD_NEW_ADV, 0, 1); + wait_ms(20); + if (f_rf_new_adv_ok) break; + } + } + } else { + rf_sw_press_delay = 0; + } + if (f_dev_reset_press) { + dev_reset_press_delay++; + if (dev_reset_press_delay >= DEV_RESET_PRESS_DELAY) { + f_dev_reset_press = 0; +#if(WORK_MODE == THREE_MODE) + 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; + } + } else { + dev_info.ble_channel = LINK_BT_1; + dev_info.rf_channel = LINK_BT_1; + } + + uart_send_cmd(CMD_SET_LINK, 10, 10); + wait_ms(500); + uart_send_cmd(CMD_CLR_DEVICE, 10, 10); +#endif + eeconfig_init(); + device_reset_show(); + device_reset_init(); + + keymap_config.no_gui = 0; + f_win_lock = 0; + + if (dev_info.sys_sw_state == SYS_SW_MAC) { + default_layer_set(1 << 0); + keymap_config.nkro = 0; + } else { + default_layer_set(1 << 2); + keymap_config.nkro = 1; + } + } + } else { + dev_reset_press_delay = 0; + } + + + if (f_rgb_test_press) { + rgb_test_press_delay++; + if (rgb_test_press_delay >= RGB_TEST_PRESS_DELAY) { + f_rgb_test_press = 0; + rgb_test_show(); + } + } else { + rgb_test_press_delay = 0; + } +} + +/** + * @brief Release all keys, clear keyboard report. + */ +void m_break_all_key(void) +{ + uint8_t report_buf[16]; + bool nkro_temp = keymap_config.nkro; + + clear_weak_mods(); + clear_mods(); + clear_keyboard(); + + keymap_config.nkro = 1; + memset(keyboard_report, 0, sizeof(report_keyboard_t)); + host_keyboard_send(keyboard_report); + wait_ms(10); + + keymap_config.nkro = 0; + memset(keyboard_report, 0, sizeof(report_keyboard_t)); + host_keyboard_send(keyboard_report); + wait_ms(10); + + keymap_config.nkro = nkro_temp; + + + if (dev_info.link_mode != LINK_USB) { + memset(report_buf, 0, 16); + uart_send_report(CMD_RPT_BIT_KB, report_buf, 16); + wait_ms(10); + uart_send_report(CMD_RPT_BYTE_KB, report_buf, 8); + wait_ms(10); + } + + memset(uart_bit_report_buf, 0, sizeof(uart_bit_report_buf)); + memset(bitkb_report_buf, 0, sizeof(bitkb_report_buf)); + memset(bytekb_report_buf, 0, sizeof(bytekb_report_buf)); +} + +/** + * @brief switch device link mode. + * @param mode : link mode + */ +#if(WORK_MODE == THREE_MODE) +static void switch_dev_link(uint8_t mode) { + if (mode > LINK_USB) return; + + m_break_all_key(); + + dev_info.link_mode = mode; + + dev_info.rf_state = RF_IDLE; + f_send_channel = 1; + + if (mode == LINK_USB) { + host_mode = HOST_USB_TYPE; + host_set_driver(m_host_driver); + rf_link_show_time = 0; + } else { + host_mode = HOST_RF_TYPE; + + host_set_driver(0); + } +} + +#endif + +/** + * @brief scan dial switch. + */ +void dial_sw_scan(void) +{ + uint8_t dial_scan = 0; + static uint8_t dial_save = 0xf0; + static uint8_t debounce = 0; + static uint32_t dial_scan_timer = 0; + static bool flag_power_on = 1; + + if (!flag_power_on) { + if (timer_elapsed32(dial_scan_timer) < 20) return; + } + dial_scan_timer = timer_read32(); + +#if(WORK_MODE == THREE_MODE) + setPinInputHigh(DEV_MODE_PIN); +#endif + setPinInputHigh(SYS_MODE_PIN); +#if(WORK_MODE == THREE_MODE) + if (readPin(DEV_MODE_PIN)) dial_scan |= 0X01; +#endif + if (readPin(SYS_MODE_PIN)) dial_scan |= 0X02; + + if (dial_save != dial_scan) { + m_break_all_key(); + dial_save = dial_scan; + no_act_time = 0; + rf_linking_time = 0; + debounce = 25; + f_dial_sw_init_ok = 0; + return; + } else if (debounce) { + debounce--; + return; + } + +#if(WORK_MODE == THREE_MODE) + + if (dial_scan & 0x01) { + 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); + } + } + +#endif + + if (dial_scan & 0x02) { + if (dev_info.sys_sw_state != SYS_SW_MAC) { + f_sys_show = 1; + default_layer_set(1 << 0); + dev_info.sys_sw_state = SYS_SW_MAC; + f_win_lock = keymap_config.no_gui; + m_break_all_key(); + } + keymap_config.nkro = 0; + keymap_config.no_gui = 0; + } 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.no_gui = f_win_lock; + m_break_all_key(); + } + keymap_config.nkro = 1; + } + + if (f_dial_sw_init_ok == 0) { + f_dial_sw_init_ok = 1; + flag_power_on = 0; + +#if(WORK_MODE == THREE_MODE) + + if (dev_info.link_mode != LINK_USB) { + host_set_driver(0); + } +#endif + } +} + +/** + * @brief power on scan dial switch. + */ +void m_power_on_dial_sw_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; + + f_win_lock = 0; +#if(WORK_MODE == THREE_MODE) + setPinInputHigh(DEV_MODE_PIN); +#endif + setPinInputHigh(SYS_MODE_PIN); + + for(debounce=0; debounce<10; debounce++) { + dial_scan_dev = 0; + dial_scan_sys = 0; +#if(WORK_MODE == THREE_MODE) + if (readPin(DEV_MODE_PIN)) dial_scan_dev = 0x01; + else dial_scan_dev = 0; +#endif + if (readPin(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); + } +#if(WORK_MODE == THREE_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); + } + } +#endif + 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; + f_win_lock = keymap_config.no_gui; + keymap_config.no_gui = 0; + m_break_all_key(); + } + } else { + if (dev_info.sys_sw_state != SYS_SW_WIN) { + default_layer_set(1 << 2); + dev_info.sys_sw_state = SYS_SW_WIN; + keymap_config.nkro = 1; + m_break_all_key(); + } + } +} + +/* qmk process record */ +bool process_record_user(uint16_t keycode, keyrecord_t *record) +{ + no_act_time = 0; + + switch (keycode) { + case RF_DFU: + if (record->event.pressed) { + if (dev_info.link_mode != LINK_USB) return false; + uart_send_cmd(CMD_RF_DFU, 10, 20); + } + return false; + + case LNK_USB: + if (record->event.pressed) { + m_break_all_key(); + } else { + dev_info.link_mode = LINK_USB; + uart_send_cmd(CMD_SET_LINK, 10, 10); + rf_blink_cnt = 3; + } + return false; + + case LNK_RF: + if (record->event.pressed) { + if (dev_info.link_mode != LINK_USB) { + rf_sw_temp = LINK_RF_24; + f_rf_sw_press = 1; + m_break_all_key(); + } + } else if (f_rf_sw_press) { + f_rf_sw_press = 0; + if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) { + dev_info.link_mode = rf_sw_temp; + dev_info.rf_channel = rf_sw_temp; + dev_info.ble_channel = rf_sw_temp; + uart_send_cmd(CMD_SET_LINK, 10, 20); + } + } + return false; + + case LNK_BLE1: + if (record->event.pressed) { + if (dev_info.link_mode != LINK_USB) { + rf_sw_temp = LINK_BT_1; + f_rf_sw_press = 1; + m_break_all_key(); + } + } else if (f_rf_sw_press) { + f_rf_sw_press = 0; + if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) { + dev_info.link_mode = rf_sw_temp; + dev_info.rf_channel = rf_sw_temp; + dev_info.ble_channel = rf_sw_temp; + uart_send_cmd(CMD_SET_LINK, 10, 20); + } + } + return false; + + case LNK_BLE2: + if (record->event.pressed) { + if (dev_info.link_mode != LINK_USB) { + rf_sw_temp = LINK_BT_2; + f_rf_sw_press = 1; + m_break_all_key(); + } + } else if (f_rf_sw_press) { + f_rf_sw_press = 0; + if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) { + dev_info.link_mode = rf_sw_temp; + dev_info.rf_channel = rf_sw_temp; + dev_info.ble_channel = rf_sw_temp; + uart_send_cmd(CMD_SET_LINK, 10, 20); + } + } + return false; + + case LNK_BLE3: + if (record->event.pressed) { + if (dev_info.link_mode != LINK_USB) { + rf_sw_temp = LINK_BT_3; + f_rf_sw_press = 1; + m_break_all_key(); + } + } else if (f_rf_sw_press) { + f_rf_sw_press = 0; + if (rf_sw_press_delay < RF_LONG_PRESS_DELAY) { + dev_info.link_mode = rf_sw_temp; + dev_info.rf_channel = rf_sw_temp; + dev_info.ble_channel = rf_sw_temp; + uart_send_cmd(CMD_SET_LINK, 10, 20); + } + } + return false; + + case MAC_TASK: + if (record->event.pressed) { + host_consumer_send(0x029F); + } else { + host_consumer_send(0); + } + return false; + + case MAC_SEARCH: + if (record->event.pressed) { + register_code(KC_LGUI); + register_code(KC_SPACE); + wait_ms(50); + unregister_code(KC_LGUI); + unregister_code(KC_SPACE); + } + return false; + + case MAC_VOICE: + if (record->event.pressed) { + host_consumer_send(0xcf); + } else { + host_consumer_send(0); + } + return false; + + case MAC_CONSOLE: + if (record->event.pressed) { + host_consumer_send(0x02A0); + } else { + host_consumer_send(0); + } + return false; + + case MAC_DND: + if (record->event.pressed) { + host_system_send(0x9b); + } else { + host_system_send(0); + } + return false; + + case SIDE_VAI: + if (record->event.pressed) { + light_level_control(1); + } + return false; + + case SIDE_VAD: + if (record->event.pressed) { + light_level_control(0); + } + return false; + + case SIDE_MOD: + if (record->event.pressed) { + side_mode_control(1); + } + return false; + + case SIDE_HUI: + if (record->event.pressed) { + side_colour_control(1); + } + return false; + + case SIDE_SPI: + if (record->event.pressed) { + light_speed_contol(1); + } + return false; + + case SIDE_SPD: + if (record->event.pressed) { + light_speed_contol(0); + } + return false; + + case LOGO_VAI: + if (record->event.pressed) { + logo_light_level_control(1); + } + return false; + case LOGO_VAD: + if (record->event.pressed) { + logo_light_level_control(0); + } + return false; + case LOGO_MOD: + if (record->event.pressed) { + logo_side_mode_control(1); + } + return false; + case LOGO_HUI: + if (record->event.pressed) { + logo_side_colour_control(1); + } + return false; + case LOGO_SPI: + if (record->event.pressed) { + logo_light_speed_contol(1); + } + return false; + case LOGO_SPD: + if (record->event.pressed) { + logo_light_speed_contol(0); + } + return false; + + case DEV_RESET: + if (record->event.pressed) { + f_dev_reset_press = 1; + m_break_all_key(); + } else { + f_dev_reset_press = 0; + } + return false; + + case SLEEP_MODE: + if (record->event.pressed) { + f_dev_sleep_enable = !f_dev_sleep_enable; + f_sleep_show = 1; + eeconfig_update_user_datablock(&user_config); + } + return false; + + case BAT_SHOW: + if (record->event.pressed) { + f_bat_hold = !f_bat_hold; + } + return false; + + case WIN_LOCK: + if (record->event.pressed) { + keymap_config.no_gui = !keymap_config.no_gui; + eeconfig_update_keymap(keymap_config.raw); + m_break_all_key(); + } else unregister_code16(keycode); + break; + + case RGB_TEST: + if (record->event.pressed) { + f_rgb_test_press = 1; + } else { + f_rgb_test_press = 0; + } + return false; + + case SHIFT_GRV: + if (record->event.pressed) { + register_code(KC_LSFT); + register_code(KC_GRV); + } + else { + unregister_code(KC_LSFT); + unregister_code(KC_GRV); + } + return false; + + default: + return true; + } + + return true; +} + +/** + * @brief timer process. + */ +void timer_pro(void) { + static uint32_t interval_timer = 0; + static bool f_first = true; + + if (f_first) { + f_first = false; + interval_timer = timer_read32(); + m_host_driver = host_get_driver(); + } + + if (timer_elapsed32(interval_timer) < 10) + return; + else + interval_timer = timer_read32(); + + if (rf_link_show_time < RF_LINK_SHOW_TIME) rf_link_show_time++; + + if (no_act_time < 0xffff) no_act_time++; + + if (rf_linking_time < 0xffff) rf_linking_time++; + +#if(WORK_MODE == THREE_MODE) + if (rf_linking_time < 0xffff) + rf_linking_time++; +#endif +} + +/** + * @brief londing eeprom data. + */ +void m_londing_eeprom_data(void) +{ + eeconfig_read_user_datablock(&user_config); + if (user_config.default_brightness_flag != 0xA5) { + rgb_matrix_sethsv( RGB_DEFAULT_COLOUR, + 255, + RGB_MATRIX_MAXIMUM_BRIGHTNESS - RGB_MATRIX_VAL_STEP * 2); + user_config.default_brightness_flag = 0xA5; + user_config.ee_side_mode = side_mode; + user_config.ee_side_light = side_light; + user_config.ee_side_speed = side_speed; + user_config.ee_side_rgb = side_rgb; + user_config.ee_side_colour = side_colour; + user_config.ee_logo_mode = logo_mode; + user_config.ee_logo_light = logo_light; + user_config.ee_logo_speed = logo_speed; + user_config.ee_logo_rgb = logo_rgb; + user_config.ee_logo_colour = logo_colour; +#if(WORK_MODE == THREE_MODE) + f_dev_sleep_enable = 1; +#else + f_dev_sleep_enable = 0; +#endif + eeconfig_update_user_datablock(&user_config); + } else { + side_mode = user_config.ee_side_mode; + side_light = user_config.ee_side_light; + side_speed = user_config.ee_side_speed; + side_rgb = user_config.ee_side_rgb; + side_colour = user_config.ee_side_colour; + logo_mode = user_config.ee_logo_mode; + logo_light = user_config.ee_logo_light; + logo_speed = user_config.ee_logo_speed; + logo_rgb = user_config.ee_logo_rgb; + logo_colour = user_config.ee_logo_colour; + } + +} + +/* qmk keyboard post init */ +void keyboard_post_init_user(void) +{ + m_gpio_init(); +#if(WORK_MODE == THREE_MODE) + rf_uart_init(); + wait_ms(500); + rf_device_init(); +#endif + + m_break_all_key(); + m_londing_eeprom_data(); + m_power_on_dial_sw_scan(); + +#if(WORK_MODE == USB_MODE) + rf_link_show_time = 0; +#endif +} + + +bool rgb_matrix_indicators_user(void) +{ + return true; +} + +bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) +{ + if (keymap_config.no_gui) { + rgb_matrix_set_color(16, 0x00, 0x80, 0x00); + } + + rgb_matrix_set_color(RGB_MATRIX_LED_COUNT-1, 0, 0, 0); + return true; +} + +/* qmk housekeeping task */ +void housekeeping_task_user(void) +{ + timer_pro(); + +#if(WORK_MODE == THREE_MODE) + uart_receive_pro(); + + uart_send_report_func(); + + dev_sts_sync(); + +#endif + + long_press_key(); + + dial_sw_scan(); + + flash_data_manage(); + + m_side_led_show(); + + Sleep_Handle(); + +} diff --git a/keyboards/nuphy/gem80/ansi/ansi.h b/keyboards/nuphy/gem80/ansi/ansi.h new file mode 100644 index 000000000000..99dde96276c0 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/ansi.h @@ -0,0 +1,189 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#include "quantum.h" + + +#define MAC_PRT G(S(KC_3)) +#define MAC_PRTA G(S(KC_4)) +#define WIN_PRTA G(S(KC_S)) + +#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_INVAILD 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 + +enum custom_keycodes { + RF_DFU = QK_KB_0, + LNK_USB, + LNK_RF, + LNK_BLE1, + LNK_BLE2, + LNK_BLE3, + + MAC_TASK, + MAC_SEARCH, + MAC_VOICE, + MAC_CONSOLE, + MAC_DND, + + WIN_LOCK, + DEV_RESET, + SLEEP_MODE, + BAT_SHOW, + RGB_TEST, + SHIFT_GRV, + + SIDE_VAI, + SIDE_VAD, + SIDE_MOD, + SIDE_HUI, + SIDE_SPI, + SIDE_SPD, + + LOGO_VAI, + LOGO_VAD, + LOGO_MOD, + LOGO_HUI, + LOGO_SPI, + LOGO_SPD +}; + + +typedef enum { + RX_Idle, + RX_Receiving, + RX_Done, + RX_Fail, + RX_OV_ERR, + RX_SUM_ERR, + RX_CMD_ERR, + RX_DATA_ERR, + RX_DATA_OV, + RX_FORMAT_ERR, + + TX_OK = 0XE0, + TX_DONE, + TX_BUSY, + TX_TIMEOUT, + TX_DATA_ERR, + +} TYPE_RX_STATE; + +typedef struct +{ + uint8_t RXDState; + uint8_t RXDLen; + uint8_t RXDOverTime; + uint8_t TXDLenBack; + uint8_t TXDOffset; + uint8_t TXDBuf[UART_MAX_LEN]; + uint8_t RXDBuf[UART_MAX_LEN]; +} USART_MGR_STRUCT; + +typedef struct +{ + uint8_t link_mode; + uint8_t rf_channel; + uint8_t ble_channel; + uint8_t rf_state; + uint8_t rf_charge; + uint8_t rf_led; + uint8_t rf_baterry; + uint8_t sys_sw_state; +} DEV_INFO_STRUCT; + + +typedef struct +{ + uint8_t bit0: 1; + uint8_t bit1: 1; + uint8_t bit2: 1; + uint8_t bit3: 1; + uint8_t bit4: 1; + uint8_t bit5: 1; + uint8_t bit6: 1; + uint8_t bit7: 1; +}m_8bit; + + +typedef struct +{ + uint8_t default_brightness_flag; + uint8_t ee_side_mode; + uint8_t ee_side_light; + uint8_t ee_side_speed; + uint8_t ee_side_rgb; + uint8_t ee_side_colour; + uint8_t ee_logo_mode; + uint8_t ee_logo_light; + uint8_t ee_logo_speed; + uint8_t ee_logo_rgb; + uint8_t ee_logo_colour; + m_8bit ee_dev_config; +} user_config_t; + + + +extern user_config_t user_config; +#define f_dev_sleep_enable user_config.ee_dev_config.bit0 diff --git a/keyboards/nuphy/gem80/ansi/config.h b/keyboards/nuphy/gem80/ansi/config.h new file mode 100644 index 000000000000..898591e699d9 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/config.h @@ -0,0 +1,35 @@ + +#pragma once + +#define USB_MODE 0 +#define THREE_MODE 1 +#define WORK_MODE THREE_MODE +#define TAP_CODE_DELAY 8 +#define DYNAMIC_KEYMAP_MACRO_DELAY 8 +#define EECONFIG_USER_DATA_SIZE 12 +#define DEV_MODE_PIN C0 +#define SYS_MODE_PIN C1 +#define DC_BOOST_PIN C2 +#define NRF_RESET_PIN B4 +#define NRF_BOOT_PIN B5 +#define NRF_WAKEUP_PIN B8 +#define WS2812_PWM_DRIVER PWMD3 +#define WS2812_PWM_CHANNEL 2 +#define WS2812_PWM_PAL_MODE 1 +#define WS2812_DMA_STREAM STM32_DMA1_STREAM3 +#define WS2812_DMA_CHANNEL 3 +#define WS2812_PWM_TARGET_PERIOD 800000 +#define DRIVER_RGB_DI_PIN A7 +#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 RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_CUSTOM_position_mode +#define RGB_DEFAULT_COLOUR 168 +#define RGB_DISABLE_WHEN_USB_SUSPENDED + + diff --git a/keyboards/nuphy/gem80/ansi/halconf.h b/keyboards/nuphy/gem80/ansi/halconf.h new file mode 100644 index 000000000000..7fa16ba1f91d --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/halconf.h @@ -0,0 +1,9 @@ +#pragma once + +#include_next + +#undef HAL_USE_PWM +#define HAL_USE_PWM TRUE + +#undef HAL_USE_SERIAL +#define HAL_USE_SERIAL TRUE diff --git a/keyboards/nuphy/gem80/ansi/info.json b/keyboards/nuphy/gem80/ansi/info.json new file mode 100644 index 000000000000..c85fe74dc6b7 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/info.json @@ -0,0 +1,283 @@ +{ + "keyboard_name": "NuPhy Gem80", + "manufacturer": "NuPhy", + "usb":{ + "vid": "0x19F5", + "pid": "0x3275", + "device_version": "1.0.0", + "no_startup_check": true + }, + "features": { + "bootmagic": true, + "mousekey": true, + "extrakey": true, + "console": false, + "command": false, + "nkro": true, + "key_lock": true, + "rgb_matrix": true + }, + "processor": "STM32F072", + "bootloader": "stm32-dfu", + "dynamic_keymap": { + "layer_count": 8 + }, + "debounce": 5, + "build": { + "debounce_type": "sym_eager_pk" + }, + "matrix_pins": { + "cols": ["A4", "A5", "A6", "B9", "B0", "B1", "B10", "B11", "B12", "B13", "B14", "B15", "A8", "A9", "A10", "A15", "B3"], + "rows": ["C14", "C15", "A0", "A1", "A2", "A3"] + }, + "diode_direction": "COL2ROW", + "ws2812": { + "pin": "A7", + "driver": "pwm" + }, + "rgb_matrix": { + "driver": "ws2812", + "center_point": [80, 20], + "max_brightness": 190, + "val_steps": 38, + "speed_steps": 52, + "animations": { + "gradient_up_down": true, + "gradient_left_right": true, + "breathing": true, + "band_sat": true, + "band_val": true, + "band_pinwheel_sat": true, + "band_pinwheel_val": true, + "band_spiral_sat": true, + "band_spiral_val": true, + "cycle_all": true, + "cycle_left_right": true, + "cycle_up_down": true, + "rainbow_moving_chevron": true, + "cycle_out_in": true, + "cycle_out_in_dual": true, + "cycle_pinwheel": true, + "cycle_spiral": true, + "dual_beacon": true, + "rainbow_beacon": true, + "rainbow_pinwheels": true, + "raindrops": true, + "jellybean_raindrops": true, + "hue_breathing": true, + "hue_pendulum": true, + "hue_wave": true, + "typing_heatmap": true, + "digital_rain": true, + "solid_reactive_simple": true, + "solid_reactive": true, + "solid_reactive_wide": true, + "solid_reactive_multiwide": true, + "solid_reactive_cross": true, + "solid_reactive_multicross": true, + "solid_reactive_nexus": true, + "solid_reactive_multinexus": true, + "splash": true, + "multisplash": true, + "solid_splash": true, + "solid_multisplash": true + }, + "layout": [ + {"matrix": [0, 0], "x": 0, "y": 0, "flags": 4}, + {"matrix": [0, 1], "x": 12.5, "y": 0, "flags": 4}, + {"matrix": [0, 2], "x": 22.5, "y": 0, "flags": 4}, + {"matrix": [0, 3], "x": 32.5, "y": 0, "flags": 4}, + {"matrix": [0, 4], "x": 42.5, "y": 0, "flags": 4}, + {"matrix": [0, 5], "x": 55, "y": 0, "flags": 4}, + {"matrix": [0, 6], "x": 65, "y": 0, "flags": 4}, + {"matrix": [0, 7], "x": 75, "y": 0, "flags": 4}, + {"matrix": [0, 8], "x": 85, "y": 0, "flags": 4}, + {"matrix": [0, 9], "x": 97.5, "y": 0, "flags": 4}, + {"matrix": [0, 10], "x": 107.5, "y": 0, "flags": 4}, + {"matrix": [0, 11], "x": 117.5, "y": 0, "flags": 4}, + {"matrix": [0, 12], "x": 127.5, "y": 0, "flags": 4}, + {"matrix": [0, 13], "x": 140, "y": 0, "flags": 4}, + {"matrix": [0, 14], "x": 152.5, "y": 0, "flags": 4}, + {"matrix": [0, 15], "x": 162.5, "y": 0, "flags": 4}, + {"matrix": [0, 16], "x": 172.5, "y": 0, "flags": 4}, + + {"matrix": [1, 16], "x": 172.5, "y": 10, "flags": 4}, + {"matrix": [1, 15], "x": 162.5, "y": 10, "flags": 4}, + {"matrix": [1, 14], "x": 152.5, "y": 10, "flags": 4}, + {"matrix": [1, 13], "x": 130, "y": 10, "flags": 4}, + {"matrix": [1, 12], "x": 120, "y": 10, "flags": 4}, + {"matrix": [1, 11], "x": 110, "y": 10, "flags": 4}, + {"matrix": [1, 10], "x": 100, "y": 10, "flags": 4}, + {"matrix": [1, 9], "x": 90, "y": 10, "flags": 4}, + {"matrix": [1, 8], "x": 80, "y": 10, "flags": 4}, + {"matrix": [1, 7], "x": 70, "y": 10, "flags": 4}, + {"matrix": [1, 6], "x": 60, "y": 10, "flags": 4}, + {"matrix": [1, 5], "x": 50, "y": 10, "flags": 4}, + {"matrix": [1, 4], "x": 40, "y": 10, "flags": 4}, + {"matrix": [1, 3], "x": 30, "y": 10, "flags": 4}, + {"matrix": [1, 2], "x": 20, "y": 10, "flags": 4}, + {"matrix": [1, 1], "x": 10, "y": 10, "flags": 4}, + {"matrix": [1, 0], "x": 0, "y": 10, "flags": 4}, + + {"matrix": [2, 0], "x": 0, "y": 20, "flags": 4}, + {"matrix": [2, 1], "x": 15, "y": 20, "flags": 4}, + {"matrix": [2, 2], "x": 25, "y": 20, "flags": 4}, + {"matrix": [2, 3], "x": 35, "y": 20, "flags": 4}, + {"matrix": [2, 4], "x": 45, "y": 20, "flags": 4}, + {"matrix": [2, 5], "x": 55, "y": 20, "flags": 4}, + {"matrix": [2, 6], "x": 65, "y": 20, "flags": 4}, + {"matrix": [2, 7], "x": 75, "y": 20, "flags": 4}, + {"matrix": [2, 8], "x": 85, "y": 20, "flags": 4}, + {"matrix": [2, 9], "x": 95, "y": 20, "flags": 4}, + {"matrix": [2, 10], "x": 105, "y": 20, "flags": 4}, + {"matrix": [2, 11], "x": 115, "y": 20, "flags": 4}, + {"matrix": [2, 12], "x": 125, "y": 20, "flags": 4}, + {"matrix": [2, 13], "x": 135, "y": 20, "flags": 4}, + {"matrix": [2, 14], "x": 152.5, "y": 20, "flags": 4}, + {"matrix": [2, 15], "x": 162.5, "y": 20, "flags": 4}, + {"matrix": [2, 16], "x": 172.5, "y": 20, "flags": 4}, + + {"matrix": [3, 13], "x": 127.5, "y": 30, "flags": 4}, + {"matrix": [3, 11], "x": 117.5, "y": 30, "flags": 4}, + {"matrix": [3, 10], "x": 107.5, "y": 30, "flags": 4}, + {"matrix": [3, 9], "x": 97.5, "y": 30, "flags": 4}, + {"matrix": [3, 8], "x": 87.5, "y": 30, "flags": 4}, + {"matrix": [3, 7], "x": 77.5, "y": 30, "flags": 4}, + {"matrix": [3, 6], "x": 67.5, "y": 30, "flags": 4}, + {"matrix": [3, 5], "x": 57.5, "y": 30, "flags": 4}, + {"matrix": [3, 4], "x": 47.5, "y": 30, "flags": 4}, + {"matrix": [3, 3], "x": 37.5, "y": 30, "flags": 4}, + {"matrix": [3, 2], "x": 27.5, "y": 30, "flags": 4}, + {"matrix": [3, 1], "x": 17.5, "y": 30, "flags": 4}, + {"matrix": [3, 0], "x": 0, "y": 30, "flags": 4}, + + {"matrix": [4, 0], "x": 0, "y": 40, "flags": 4}, + {"matrix": [4, 2], "x": 22.5, "y": 40, "flags": 4}, + {"matrix": [4, 3], "x": 32.5, "y": 40, "flags": 4}, + {"matrix": [4, 4], "x": 42.5, "y": 40, "flags": 4}, + {"matrix": [4, 5], "x": 52.5, "y": 40, "flags": 4}, + {"matrix": [4, 6], "x": 62.5, "y": 40, "flags": 4}, + {"matrix": [4, 7], "x": 72.5, "y": 40, "flags": 4}, + {"matrix": [4, 8], "x": 82.5, "y": 40, "flags": 4}, + {"matrix": [4, 9], "x": 92.5, "y": 40, "flags": 4}, + {"matrix": [4, 10], "x": 102.5, "y": 40, "flags": 4}, + {"matrix": [4, 11], "x": 112.5, "y": 40, "flags": 4}, + {"matrix": [4, 13], "x": 122.5, "y": 40, "flags": 4}, + {"matrix": [4, 14], "x": 162.5, "y": 40, "flags": 4}, + + {"matrix": [5, 15], "x": 172.5, "y": 50, "flags": 4}, + {"matrix": [5, 14], "x": 162.5, "y": 50, "flags": 4}, + {"matrix": [5, 13], "x": 152.5, "y": 50, "flags": 4}, + {"matrix": [5, 12], "x": 137.5, "y": 50, "flags": 4}, + {"matrix": [5, 10], "x": 125, "y": 50, "flags": 4}, + {"matrix": [5, 11], "x": 112.5, "y": 50, "flags": 4}, + {"matrix": [5, 9], "x": 100, "y": 50, "flags": 4}, + {"matrix": [5, 6], "x": 37.5, "y": 50, "flags": 4}, + {"matrix": [5, 2], "x": 25, "y": 50, "flags": 4}, + {"matrix": [5, 1], "x": 12.5, "y": 50, "flags": 4}, + {"matrix": [5, 0], "x": 0, "y": 50, "flags": 4}, + {"flags": 4} + ] + }, + "layouts": { + "LAYOUT": { + "layout": [ + {"label": "Esc", "matrix": [0, 0], "x": 0, "y": 0}, + {"label": "F1", "matrix": [0, 1], "x": 1.25, "y": 0}, + {"label": "F2", "matrix": [0, 2], "x": 2.25, "y": 0}, + {"label": "F3", "matrix": [0, 3], "x": 3.25, "y": 0}, + {"label": "F4", "matrix": [0, 4], "x": 4.25, "y": 0}, + {"label": "F5", "matrix": [0, 5], "x": 5.5, "y": 0}, + {"label": "F6", "matrix": [0, 6], "x": 6.5, "y": 0}, + {"label": "F7", "matrix": [0, 7], "x": 7.5, "y": 0}, + {"label": "F8", "matrix": [0, 8], "x": 8.5, "y": 0}, + {"label": "F9", "matrix": [0, 9], "x": 9.75, "y": 0}, + {"label": "F10", "matrix": [0, 10], "x": 10.75, "y": 0}, + {"label": "F11", "matrix": [0, 11], "x": 11.75, "y": 0}, + {"label": "F12", "matrix": [0, 12], "x": 12.75, "y": 0}, + {"label": "F13", "matrix": [0, 13], "x": 14, "y": 0}, + {"label": "Print", "matrix": [0, 14], "x": 15.25, "y": 0}, + {"label": "Lock", "matrix": [0, 15], "x": 16.25, "y": 0}, + {"label": "Pause", "matrix": [0, 16], "x": 17.25, "y": 0}, + + {"label": "~`", "matrix": [1, 0], "x": 0, "y": 1}, + {"label": "!1", "matrix": [1, 1], "x": 1, "y": 1}, + {"label": "@2", "matrix": [1, 2], "x": 2, "y": 1}, + {"label": "#3", "matrix": [1, 3], "x": 3, "y": 1}, + {"label": "$4", "matrix": [1, 4], "x": 4, "y": 1}, + {"label": "%5", "matrix": [1, 5], "x": 5, "y": 1}, + {"label": "^6", "matrix": [1, 6], "x": 6, "y": 1}, + {"label": "&7", "matrix": [1, 7], "x": 7, "y": 1}, + {"label": "*8", "matrix": [1, 8], "x": 8, "y": 1}, + {"label": "(9", "matrix": [1, 9], "x": 9, "y": 1}, + {"label": ")0", "matrix": [1, 10], "x": 10, "y": 1}, + {"label": "_-", "matrix": [1, 11], "x": 11, "y": 1}, + {"label": "+=", "matrix": [1, 12], "x": 12, "y": 1}, + {"label": "Backsp", "matrix": [1, 13], "x": 13, "y": 1, "w": 2}, + {"label": "Ins", "matrix": [1, 14], "x": 15.25, "y": 1}, + {"label": "Home", "matrix": [1, 15], "x": 16.25, "y": 1}, + {"label": "PageUp", "matrix": [1, 16], "x": 17.25, "y": 1}, + + {"label": "Tab", "matrix": [2, 0], "x": 0, "y": 2, "w": 1.5}, + {"label": "Q", "matrix": [2, 1], "x": 1.5, "y": 2}, + {"label": "W", "matrix": [2, 2], "x": 2.5, "y": 2}, + {"label": "E", "matrix": [2, 3], "x": 3.5, "y": 2}, + {"label": "R", "matrix": [2, 4], "x": 4.5, "y": 2}, + {"label": "T", "matrix": [2, 5], "x": 5.5, "y": 2}, + {"label": "Y", "matrix": [2, 6], "x": 6.5, "y": 2}, + {"label": "U", "matrix": [2, 7], "x": 7.5, "y": 2}, + {"label": "I", "matrix": [2, 8], "x": 8.5, "y": 2}, + {"label": "O", "matrix": [2, 9], "x": 9.5, "y": 2}, + {"label": "P", "matrix": [2, 10], "x": 10.5, "y": 2}, + {"label": "{[", "matrix": [2, 11], "x": 11.5, "y": 2}, + {"label": "}]", "matrix": [2, 12], "x": 12.5, "y": 2}, + {"label": "|\\", "matrix": [2, 13], "x": 13.5, "y": 2, "w": 1.5}, + {"label": "Del", "matrix": [2, 14], "x": 15.25, "y": 2}, + {"label": "End", "matrix": [2, 15], "x": 16.25, "y": 2}, + {"label": "PageDn", "matrix": [2, 16], "x": 17.25, "y": 2}, + + {"label": "Caps", "matrix": [3, 0], "x": 0, "y": 3, "w": 1.75}, + {"label": "A", "matrix": [3, 1], "x": 1.75, "y": 3}, + {"label": "S", "matrix": [3, 2], "x": 2.75, "y": 3}, + {"label": "D", "matrix": [3, 3], "x": 3.75, "y": 3}, + {"label": "F", "matrix": [3, 4], "x": 4.75, "y": 3}, + {"label": "G", "matrix": [3, 5], "x": 5.75, "y": 3}, + {"label": "H", "matrix": [3, 6], "x": 6.75, "y": 3}, + {"label": "J", "matrix": [3, 7], "x": 7.75, "y": 3}, + {"label": "K", "matrix": [3, 8], "x": 8.75, "y": 3}, + {"label": "L", "matrix": [3, 9], "x": 9.75, "y": 3}, + {"label": ":", "matrix": [3, 10], "x": 10.75, "y": 3}, + {"label": "\"", "matrix": [3, 11], "x": 11.75, "y": 3}, + {"label": "Enter", "matrix": [3, 13], "x": 12.75, "y": 3, "w": 2.25}, + + {"label": "Shift", "matrix": [4, 0], "x": 0, "y": 4, "w": 2.25}, + {"label": "Z", "matrix": [4, 2], "x": 2.25, "y": 4}, + {"label": "X", "matrix": [4, 3], "x": 3.25, "y": 4}, + {"label": "C", "matrix": [4, 4], "x": 4.25, "y": 4}, + {"label": "V", "matrix": [4, 5], "x": 5.25, "y": 4}, + {"label": "B", "matrix": [4, 6], "x": 6.25, "y": 4}, + {"label": "N", "matrix": [4, 7], "x": 7.25, "y": 4}, + {"label": "M", "matrix": [4, 8], "x": 8.25, "y": 4}, + {"label": "<,", "matrix": [4, 9], "x": 9.25, "y": 4}, + {"label": ">.", "matrix": [4, 10], "x": 10.25, "y": 4}, + {"label": "?/", "matrix": [4, 11], "x": 11.25, "y": 4}, + {"label": "Shift", "matrix": [4, 13], "x": 12.25, "y": 4, "w": 2.75}, + {"label": "↑", "matrix": [4, 14], "x": 16.25, "y": 4}, + + {"label": "Ctrl", "matrix": [5, 0], "x": 0, "y": 5, "w": 1.25}, + {"label": "Opt", "matrix": [5, 1], "x": 1.25, "y": 5, "w": 1.25}, + {"label": "Cmd", "matrix": [5, 2], "x": 2.5, "y": 5, "w": 1.25}, + {"label": "Space", "matrix": [5, 6], "x": 3.75, "y": 5, "w": 6.25}, + {"label": "Cmd", "matrix": [5, 9], "x": 10, "y": 5, "w": 1.25}, + {"label": "Opt", "matrix": [5, 11], "x": 11.25, "y": 5, "w": 1.25}, + {"label": "Fn", "matrix": [5, 10], "x": 12.5, "y": 5, "w": 1.25}, + {"label": "Ctrl", "matrix": [5, 12], "x": 13.75, "y": 5, "w": 1.25}, + {"label": "←", "matrix": [5, 13], "x": 15.25, "y": 5}, + {"label": "↓", "matrix": [5, 14], "x": 16.25, "y": 5}, + {"label": "→", "matrix": [5, 15], "x": 17.25, "y": 5} + + ] + } + } +} + diff --git a/keyboards/nuphy/gem80/ansi/keymaps/via/NuPhy Gem80 via3.json b/keyboards/nuphy/gem80/ansi/keymaps/via/NuPhy Gem80 via3.json new file mode 100644 index 000000000000..80f831851ca9 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/keymaps/via/NuPhy Gem80 via3.json @@ -0,0 +1,234 @@ +{ + "name": "NuPhy Gem80", + "vendorId": "0x19F5", + "productId": "0x3275", + "matrix": { + "rows": 6, + "cols": 17 + }, + "layouts": { + "keymap": [ + ["0,0",{"x":0.25},"0,1","0,2","0,3","0,4",{"x":0.25},"0,5","0,6","0,7","0,8",{"x":0.25},"0,9","0,10","0,11","0,12",{"x":0.25},"0,13",{"x":0.25},"0,14","0,15","0,16"], + [{"y":0.25},"1,0","1,1","1,2","1,3","1,4","1,5","1,6","1,7","1,8","1,9","1,10","1,11","1,12",{"w":2},"1,13",{"x":0.25},"1,14","1,15","1,16"], + [{"w":1.5},"2,0","2,1","2,2","2,3","2,4","2,5","2,6","2,7","2,8","2,9","2,10","2,11","2,12",{"w":1.5},"2,13",{"x":0.25},"2,14","2,15","2,16"], + [{"w":1.75},"3,0","3,1","3,2","3,3","3,4","3,5","3,6","3,7","3,8","3,9","3,10","3,11",{"w":2.25},"3,13"], + [{"w":2.25},"4,0","4,2","4,3","4,4","4,5","4,6","4,7","4,8","4,9","4,10","4,11",{"w":2.75},"4,13",{"x":1.25},"4,14"], + [{"w":1.25},"5,0",{"w":1.25},"5,1",{"w":1.25},"5,2",{"w":6.25},"5,6",{"w":1.25},"5,9",{"w":1.25},"5,11",{"w":1.25},"5,10",{"w":1.25},"5,12",{"x":0.25},"5,13","5,14","5,15"] + ] + }, + "menus": [ + { + "label": "Lighting", + "content": [ + { + "label": "Backlight", + "content": [ + { + "label": "Brightness", + "type": "range", + "options": [0, 255], + "content": ["id_qmk_rgb_matrix_brightness", 3, 1] + }, + { + "label": "Effect", + "type": "dropdown", + "content": ["id_qmk_rgb_matrix_effect", 3, 2], + "options": [ + "All Off", + "Solid Color", + "Gradient Up/Down", + "Gradient Left/Right", + "Breathing", + "Band Sat.", + "Band Val.", + "Pinwheel Sat.", + "Pinwheel Val.", + "Spiral Sat.", + "Spiral Val.", + "Cycle All", + "Cycle Left/Right", + "Cycle Up/Down", + "Rainbow Moving Chevron", + "Cycle Out/In", + "Cycle Out/In Dual", + "Cycle Pinwheel", + "Cycle Spiral", + "Dual Beacon", + "Rainbow Beacon", + "Rainbow Pinwheels", + "Raindrops", + "Jellybean Raindrops", + "Hue Breathing", + "Hue Pendulum", + "Hue Wave", + "Typing Heatmap", + "Digital Rain", + "Reactive Simple", + "Reactive", + "Reactive Wide", + "Reactive Multiwide", + "Reactive Cross", + "Reactive Multicross", + "Reactive Nexus", + "Reactive MultiNexus", + "Splash", + "MultiSplash", + "Solid Splash", + "Solid MultiSplash", + "game_mode", + "position_mode" + ] + }, + { + "showIf": "{id_qmk_rgb_matrix_effect} != 0", + "label": "Effect Speed", + "type": "range", + "options": [0, 255], + "content": ["id_qmk_rgb_matrix_effect_speed", 3, 3] + }, + { + "showIf": "{id_qmk_rgb_matrix_effect} != 0", + "label": "Color", + "type": "color", + "content": ["id_qmk_rgb_matrix_color", 3, 4] + } + ] + } + ] + } + ], +"keycodes": [ + "qmk_lighting" +], +"customKeycodes": [ + { + "name": "RF\nDFU", + "title": "RF DFU" + }, + { + "name": "Link\nUSB", + "title": "Link USB" + }, + { + "name": "Link\nRF", + "title": "Link RF" + }, + { + "name": "Link\nBLE_1", + "title": "Link BLE_1" + }, + { + "name": "Link\nBLE_2", + "title": "Link BLE_2" + }, + { + "name": "Link\nBLE_3", + "title": "Link BLE_3" + }, + { + "name": "Mac\nTask", + "title": "Mac Task" + }, + { + "name": "Mac\nSearch", + "title": "Mac Search" + }, + { + "name": "Mac\nVoice", + "title": "Mac Siri Voice" + }, + { + "name": "Mac\nConsole", + "title": "Mac Console" + }, + { + "name": "Mac\nDnt", + "title": "Mac Dnt" + }, + { + "name": "Print\nWhole", + "title": "PrintWhole" + }, + { + "name": "Print\nArea", + "title": "PrintArea" + }, + { + "name": "Win\nlock", + "title": "Win lock" + }, + { + "name": "Dev\nReset", + "title": "Device Reset" + }, + { + "name": "Sleep\nMode", + "title": "Auto Sleep" + }, + { + "name": "Bat\nShow", + "title": "Battery Show" + }, + { + "name": "RGB\nTest", + "title": "Hold for 3 seconds for RGB color test" + }, + { + "name": "Tilde", + "title": "SHIFT+` = ~" + }, + { + "name": "Side\nLight+", + "title": "Side Light +" + }, + { + "name": "Side\nLight-", + "title": "Side Light -" + }, + { + "name": "Side\nMode", + "title": "Side Next Mode" + }, + { + "name": "Side\nColor", + "title": "Side Next Color" + }, + { + "name": "Side\nFast", + "title": "Side Speed +" + }, + { + "name": "Side\nSlow", + "title": "Side Speed -" + }, + { + "name": "Logo\nLight+", + "title": "Logo Light +" + }, + { + "name": "Logo\nLight-", + "title": "Logo Light -" + }, + { + "name": "Logo\nMode", + "title": "Logo Next Mode" + }, + { + "name": "Logo\nColor", + "title": "Logo Next Color" + }, + { + "name": "Logo\nFast", + "title": "Logo Speed +" + }, + { + "name": "Logo\nSlow", + "title": "Logo Speed -" + } + + + + + +] +} diff --git a/keyboards/nuphy/gem80/ansi/keymaps/via/keymap.c b/keyboards/nuphy/gem80/ansi/keymaps/via/keymap.c new file mode 100644 index 000000000000..f55db2150ab6 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/keymaps/via/keymap.c @@ -0,0 +1,73 @@ +#include QMK_KEYBOARD_H + +const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + +// layer Mac +[0] = LAYOUT( + KC_ESC, KC_BRID, KC_BRIU, MAC_TASK, MAC_SEARCH, MAC_VOICE, MAC_DND, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_PAUSE, KC_SCRL, MAC_PRTA, KC_NO, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, + KC_LCTL, KC_LOPT, KC_LCMD, KC_SPC, KC_RCMD, KC_ROPT, MO(1), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT), +// layer Mac Fn +#if(WORK_MODE == THREE_MODE) +[1] = LAYOUT( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_F13, _______, MAC_PRT, _______, + _______, LNK_BLE1, LNK_BLE2, LNK_BLE3, LNK_RF, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, DEV_RESET, SLEEP_MODE, BAT_SHOW, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, MO(5), MO(4), RGB_SPD, RGB_SPI, _______, _______, RGB_VAI, + _______, _______, _______, _______, _______, _______, MO(1), _______, RGB_MOD, RGB_VAD, RGB_HUI), +#else +[1] = LAYOUT( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_F13, _______, MAC_PRT, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, DEV_RESET, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, MO(5), MO(4), RGB_SPD, RGB_SPI, _______, _______, RGB_VAI, + _______, _______, _______, _______, _______, _______, MO(1), _______, RGB_MOD, RGB_VAD, RGB_HUI), +#endif +// layer win +[2] = LAYOUT( + KC_ESC, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_PAUSE, KC_SCRL, WIN_PRTA, WIN_LOCK, + KC_GRV, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, KC_INS, KC_HOME, KC_PGUP, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_DEL, KC_END, KC_PGDN, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, + KC_LCTL, KC_LWIN, KC_LALT, KC_SPC, KC_RALT, KC_RWIN, MO(3), KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT), +// layer win Fn +#if(WORK_MODE == THREE_MODE) +[3] = LAYOUT( + _______, KC_BRID, KC_BRIU, _______, _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_NO, _______, KC_PSCR, KC_NO, + _______, LNK_BLE1, LNK_BLE2, LNK_BLE3, LNK_RF, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, DEV_RESET, SLEEP_MODE, BAT_SHOW, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, MO(5), MO(4), RGB_SPD, RGB_SPI, _______, _______, RGB_VAI, + _______, _______, _______, _______, _______, _______, MO(3), _______, RGB_MOD, RGB_VAD, RGB_HUI), +#else +[3] = LAYOUT( + _______, KC_BRID, KC_BRIU, _______, _______, _______, _______, KC_MPRV, KC_MPLY, KC_MNXT, KC_MUTE, KC_VOLD, KC_VOLU, KC_NO, _______, KC_PSCR, KC_NO, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, DEV_RESET, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, MO(5), MO(4), RGB_SPD, RGB_SPI, _______, _______, RGB_VAI, + _______, _______, _______, _______, _______, _______, MO(3), _______, RGB_MOD, RGB_VAD, RGB_HUI), +#endif +// layer 4 +[4] = LAYOUT( + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, RGB_TEST, _______, _______, _______, _______, SIDE_SPD, SIDE_SPI, _______, _______, SIDE_VAI, + _______, _______, _______, _______, _______, _______, MO(4), _______, SIDE_MOD, SIDE_VAD, SIDE_HUI), +// layer 4 +[5] = LAYOUT( + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, + _______, _______, _______, _______, _______, _______, _______, _______, LOGO_SPD, LOGO_SPI, _______, _______, LOGO_VAI, + _______, _______, _______, _______, _______, _______, MO(5), _______, LOGO_MOD, LOGO_VAD, LOGO_HUI), +}; diff --git a/keyboards/nuphy/gem80/ansi/keymaps/via/rgb_matrix_user.inc b/keyboards/nuphy/gem80/ansi/keymaps/via/rgb_matrix_user.inc new file mode 100644 index 000000000000..3d2a7cca0ba7 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/keymaps/via/rgb_matrix_user.inc @@ -0,0 +1,49 @@ + +RGB_MATRIX_EFFECT(game_mode) +RGB_MATRIX_EFFECT(position_mode) + +#ifdef RGB_MATRIX_CUSTOM_EFFECT_IMPLS + +extern rgb_config_t rgb_matrix_config; + +static bool game_mode(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + for (uint8_t i = led_min; i < led_max; i++) { + rgb_matrix_set_color(i, 0x00, 0x00, 0x00); + } + + RGB rgb = hsv_to_rgb(rgb_matrix_config.hsv); + rgb_matrix_set_color(0, rgb.r, rgb.g, rgb.b); // ESC + + rgb_matrix_set_color(36, rgb.r, rgb.g, rgb.b); // W + rgb_matrix_set_color(60, rgb.r, rgb.g, rgb.b); // D + rgb_matrix_set_color(61, rgb.r, rgb.g, rgb.b); // S + rgb_matrix_set_color(62, rgb.r, rgb.g, rgb.b); // A + + rgb_matrix_set_color(76, rgb.r, rgb.g, rgb.b); // up + rgb_matrix_set_color(77, rgb.r, rgb.g, rgb.b); // right + rgb_matrix_set_color(78, rgb.r, rgb.g, rgb.b); // down + rgb_matrix_set_color(79, rgb.r, rgb.g, rgb.b); // left + + return rgb_matrix_check_finished_leds(led_max); +} + +static bool position_mode(effect_params_t* params) { + RGB_MATRIX_USE_LIMITS(led_min, led_max); + + for (uint8_t i = led_min; i < led_max; i++) { + rgb_matrix_set_color(i, 0x00, 0x00, 0x00); + } + + RGB rgb = hsv_to_rgb(rgb_matrix_config.hsv); + + rgb_matrix_set_color(56, rgb.r, rgb.g, rgb.b); // J + rgb_matrix_set_color(59, rgb.r, rgb.g, rgb.b); // D + rgb_matrix_set_color(76, rgb.r, rgb.g, rgb.b); + + return rgb_matrix_check_finished_leds(led_max); +} + + +#endif // RGB_MATRIX_CUSTOM_EFFECT_IMPLS diff --git a/keyboards/nuphy/gem80/ansi/keymaps/via/rules.mk b/keyboards/nuphy/gem80/ansi/keymaps/via/rules.mk new file mode 100644 index 000000000000..d475530c871c --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/keymaps/via/rules.mk @@ -0,0 +1,3 @@ +VIA_ENABLE = yes + +RGB_MATRIX_CUSTOM_USER = yes diff --git a/keyboards/nuphy/gem80/ansi/mcuconf.h b/keyboards/nuphy/gem80/ansi/mcuconf.h new file mode 100644 index 000000000000..2325fc99e868 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/mcuconf.h @@ -0,0 +1,12 @@ +#pragma once + +#include_next + +#undef STM32_PWM_USE_TIM3 +#define STM32_PWM_USE_TIM3 TRUE + +#undef STM32_PWM_USE_ADVANCED +#define STM32_PWM_USE_ADVANCED TRUE + +#undef STM32_SERIAL_USE_USART1 +#define STM32_SERIAL_USE_USART1 TRUE diff --git a/keyboards/nuphy/gem80/ansi/readme.md b/keyboards/nuphy/gem80/ansi/readme.md new file mode 100644 index 000000000000..07891ba65d0c --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/readme.md @@ -0,0 +1,24 @@ +c# NuPhy Gem80 + +*NuPhy Gem80 is a standard 88 key keyboard.* +![NuPhy Gem80](https://imgur.com/a/kdaVfkx) + +* Keyboard Maintainer: [nuphy](https://github.com/nuphy-src) +* Hardware Supported: NuPhy Gem80 PCB +* Hardware Availability: Private + +Make example for this keyboard (after setting up your build environment): + + make nuphy/gem80/ansi:default + +Flashing example for this keyboard: + + make nuphy/gem80/ansi:default:flash + +See the [build environment setup](https://docs.qmk.fm/#/getting_started_build_tools) and the [make instructions](https://docs.qmk.fm/#/getting_started_make_guide) for more information. Brand new to QMK? Start with our [Complete Newbs Guide](https://docs.qmk.fm/#/newbs). + +## Bootloader + +Enter the bootloader in one way: + +* **Bootmagic reset**: Hold down the key at (0,0) in the matrix (usually the top left key or Escape) and plug in the keyboard diff --git a/keyboards/nuphy/gem80/ansi/rf.c b/keyboards/nuphy/gem80/ansi/rf.c new file mode 100644 index 000000000000..fbbcf24d1cdc --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/rf.c @@ -0,0 +1,728 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later +#include "ansi.h" +#include "uart.h" // qmk uart.h + +#define UART_HEAD 0x5A +#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] + +uint8_t func_tab[32] = {0}; +uint8_t disconnect_delay = 0; +uint8_t uart_bit_report_buf[32] = {0}; +uint8_t bitkb_report_buf[32] = {0}; +uint8_t bytekb_report_buf[8] = {0}; +uint8_t mouse_report_buf[5] = {0}; +uint8_t sync_lost = 0; +uint16_t conkb_report; +uint16_t syskb_report; +uint16_t host_last_consumer_usage(void); + +bool f_wakeup_prepare = 0; +bool f_bit_kb_act = 0; + +extern uint8_t host_mode; +extern uint8_t rf_blink_cnt; +extern uint16_t rf_link_show_time; +extern uint16_t rf_linking_time; +extern uint16_t no_act_time; +extern bool f_uart_ack; +extern bool f_rf_read_data_ok; +extern bool f_rf_sts_sysc_ok; +extern bool f_rf_new_adv_ok; +extern bool f_rf_reset; +extern bool f_send_channel; +extern bool f_rf_hand_ok; +extern bool f_rf_send_bitkb; +extern bool f_rf_send_byte; +extern bool f_rf_send_consume; +extern bool f_dial_sw_init_ok; +extern bool f_goto_sleep; +extern host_driver_t *m_host_driver; +extern DEV_INFO_STRUCT dev_info; +USART_MGR_STRUCT Usart_Mgr; + +report_mouse_t mousekey_get_report(void); +void uart_send_report(uint8_t report_type, uint8_t *report_buf, uint8_t report_size); +void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length); +uint8_t get_checksum(uint8_t *buf, uint8_t len); +void uart_receive_pro(void); +void m_break_all_key(void); + +static void UsartMgr_RXD_Reset(void) +{ + Usart_Mgr.RXDLen = 0; + Usart_Mgr.RXDState = RX_Idle; + Usart_Mgr.RXDOverTime = 0; +} + +/** + * @brief Parsing the data received from the RF module. + */ +void RF_Protocol_Receive(void) +{ + uint8_t i, check_sum = 0; + + if (Usart_Mgr.RXDState == RX_Done) { + f_uart_ack = 1; + sync_lost = 0; + + if (Usart_Mgr.RXDLen > 4) { + for (i = 0; i < RX_LEN; i++) + check_sum += Usart_Mgr.RXDBuf[4 + i]; + + if (check_sum != Usart_Mgr.RXDBuf[4 + i]) { + Usart_Mgr.RXDState = RX_SUM_ERR; + return; + } + } else if (Usart_Mgr.RXDLen == 3) { + if (Usart_Mgr.RXDBuf[2] == 0xA0) + { + f_uart_ack = 1; + } + } + + switch (RX_CMD) { + case CMD_POWER_UP: break; + case CMD_SLEEP: break; + case CMD_HAND: { + f_rf_hand_ok = 1; + break; + } + + case CMD_24G_SUSPEND: { + f_goto_sleep = 1; + break; + } + + case CMD_SET_LINK: { + break; + } + + case CMD_NEW_ADV: { + f_rf_new_adv_ok = 1; + break; + } + + case CMD_RF_STS_SYSC: { + static uint8_t error_cnt = 0; + if (dev_info.link_mode == Usart_Mgr.RXDBuf[4]) { + error_cnt = 0; + dev_info.rf_state = Usart_Mgr.RXDBuf[5]; + + if ((dev_info.rf_state == RF_CONNECT) && ((Usart_Mgr.RXDBuf[6] & 0xf8) == 0)) { + dev_info.rf_led = Usart_Mgr.RXDBuf[6]; + } + + if ((Usart_Mgr.RXDBuf[7] & 0xfc) == 0) + dev_info.rf_charge = Usart_Mgr.RXDBuf[7]; + + if (Usart_Mgr.RXDBuf[8] <= 100) + dev_info.rf_baterry = Usart_Mgr.RXDBuf[8]; + } + else { + if (dev_info.rf_state != RF_INVAILD) { + if (error_cnt >= 5) { + error_cnt = 0; + f_send_channel = 1; + } else { + error_cnt++; + } + } + } + + f_rf_sts_sysc_ok = 1; + break; + } + + case CMD_CLR_DEVICE: { + break; + } + + case CMD_GET_NAME: + break; + + case CMD_SET_NAME: + break; + + case CMD_SET_24G_NAME: + break; + + case CMD_RPT_BYTE_KB: { + f_rf_send_byte = 0; + break; + } + + case CMD_RPT_BIT_KB: { + f_rf_send_bitkb = 0; + break; + } + + case CMD_RPT_CONSUME: { + f_rf_send_consume = 0; + break; + } + + case CMD_RPT_SYS: + break; + + case CMD_WRITE_DATA: + break; + + case CMD_READ_DATA: { + memcpy(func_tab, &Usart_Mgr.RXDBuf[4], 32); + + if (func_tab[4] <= LINK_USB) { + dev_info.link_mode = func_tab[4]; + } + + if (func_tab[5] < LINK_USB) { + dev_info.rf_channel = func_tab[5]; + } + + if ((func_tab[6] <= LINK_BT_3) && (func_tab[6] >= LINK_BT_1)) { + dev_info.ble_channel = func_tab[6]; + } + + f_rf_read_data_ok = 1; + break; + } + + default: + Usart_Mgr.RXDState = RX_CMD_ERR; + return; + } + + UsartMgr_RXD_Reset(); + } +} + + +/** + * @brief Uart auto send + */ +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; + + if (pre_bit_report[0] ^ now_bit_report[0]) { + bytekb_report_buf[0] = now_bit_report[0]; + f_byte_send = 1; + } + + for (i = 1; i < size; i++) { + change_mask = pre_bit_report[i] ^ now_bit_report[i]; + offset_mask = 1; + for (j = 0; j < 8; j++) { + if (change_mask & offset_mask) { + if (now_bit_report[i] & offset_mask) { + for (byte_index = 2; byte_index < 8; byte_index++) { + if (bytekb_report_buf[byte_index] == 0) { + bytekb_report_buf[byte_index] = key_code; + f_byte_send = 1; + break; + } + } + + if (byte_index >= 8) { + uart_bit_report_buf[i] |= offset_mask; + f_bit_send = 1; + } + } else { + for (byte_index = 2; byte_index < 8; byte_index++) { + if (bytekb_report_buf[byte_index] == key_code) { + bytekb_report_buf[byte_index] = 0; + f_byte_send = 1; + break; + ; + } + } + if (byte_index >= 8) { + uart_bit_report_buf[i] &= ~offset_mask; + f_bit_send = 1; + } + } + } + key_code++; + offset_mask <<= 1; + } + } + + if (f_bit_send) { + f_bit_kb_act = 1; + uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16); + } + + if (f_byte_send) { + uart_send_report(CMD_RPT_BYTE_KB, bytekb_report_buf, 8); + } +} + +/** + * @brief Uart send keys report. + * @note Call in host.c + */ +void uart_send_report_func(void) +{ + static uint32_t interval_timer = 0; + + if (dev_info.link_mode == LINK_USB) return; + keyboard_protocol = 1; + + if(keymap_config.nkro) { + keyboard_report->nkro.mods = get_mods() | get_weak_mods(); + } + + if ((dev_info.sys_sw_state == SYS_SW_MAC) && (memcmp(bytekb_report_buf, keyboard_report->raw, 8))) { + no_act_time = 0; + keyboard_report->raw[1] = 0; + memcpy(bytekb_report_buf, keyboard_report->raw, 8); + uart_send_report(CMD_RPT_BYTE_KB, bytekb_report_buf, 8); + } + else if ((dev_info.sys_sw_state == SYS_SW_WIN) && (memcmp(bitkb_report_buf, &keyboard_report->nkro.mods, KEYBOARD_REPORT_BITS+1))) { + no_act_time = 0; + uart_auto_nkey_send(bitkb_report_buf, &keyboard_report->nkro.mods, KEYBOARD_REPORT_BITS+1); + memcpy(&bitkb_report_buf[0], &keyboard_report->nkro.mods, KEYBOARD_REPORT_BITS+1); + } + else if (timer_elapsed32(interval_timer) > 100) + { + interval_timer = timer_read32(); + if (no_act_time <= 200) { + uart_send_report(CMD_RPT_BYTE_KB, bytekb_report_buf, 8); + + if (f_bit_kb_act) + uart_send_report(CMD_RPT_BIT_KB, uart_bit_report_buf, 16); + } else { + f_bit_kb_act = 0; + } + } +} + +/** + * @brief Uart send consumer keys report. + * @note Call in host.c + */ +void uart_send_consumer_report(void) +{ + no_act_time = 0; + conkb_report = host_last_consumer_usage(); + uart_send_report(CMD_RPT_CONSUME, (uint8_t *)(&conkb_report), 2); +} + +/** + * @brief Uart send mouse keys report. + * @note Call in host.c + */ +void uart_send_mouse_report(void) +{ + report_mouse_t mouse_report = mousekey_get_report(); + no_act_time = 0; + memcpy(mouse_report_buf, &mouse_report.buttons, 5); + uart_send_report(CMD_RPT_MS, mouse_report_buf, 5); +} + +/** + * @brief Uart send system keys report. + * @note Call in host.c + */ +void uart_send_system_report(void) +{ + no_act_time = 0; + syskb_report = host_last_system_usage(); + uart_send_report(CMD_RPT_SYS, (uint8_t *)(&syskb_report), 2); +} + +/** + * @brief Uart send cmd. + * @param cmd: cmd. + * @param wait_ack: wait time for ack after sending. + * @param delayms: delay before sending. + */ +uint8_t uart_send_cmd(uint8_t cmd, uint8_t wait_ack, uint8_t delayms) +{ + uint8_t i; + + wait_ms(delayms); + + memset(&Usart_Mgr.TXDBuf[0], 0, UART_MAX_LEN); + + Usart_Mgr.TXDBuf[0] = UART_HEAD; + Usart_Mgr.TXDBuf[1] = cmd; + Usart_Mgr.TXDBuf[2] = 0x00; + + switch (cmd) { + case CMD_POWER_UP: { + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = 0; + Usart_Mgr.TXDBuf[5] = 0; + break; + } + case CMD_SNIF: { + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = 0; + Usart_Mgr.TXDBuf[5] = 0; + break; + } + case CMD_SLEEP: { + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = 0; + Usart_Mgr.TXDBuf[5] = 0; + break; + } + case CMD_HAND: { + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = 0; + Usart_Mgr.TXDBuf[5] = 0; + break; + } + case CMD_RF_STS_SYSC: { + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = dev_info.link_mode; + Usart_Mgr.TXDBuf[5] = dev_info.link_mode; + break; + } + case CMD_SET_LINK: { + dev_info.rf_state = RF_LINKING; + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = dev_info.link_mode; + Usart_Mgr.TXDBuf[5] = dev_info.link_mode; + + rf_linking_time = 0; + disconnect_delay = 0xff; + break; + } + case CMD_NEW_ADV: { + dev_info.rf_state = RF_PAIRING; + Usart_Mgr.TXDBuf[3] = 2; + Usart_Mgr.TXDBuf[4] = dev_info.link_mode; + Usart_Mgr.TXDBuf[5] = 1; + Usart_Mgr.TXDBuf[6] = dev_info.link_mode + 1; + + rf_linking_time = 0; + disconnect_delay = 0xff; + + f_rf_new_adv_ok = 0; + break; + } + case CMD_CLR_DEVICE: { + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = 0; + Usart_Mgr.TXDBuf[5] = 0; + break; + } + case CMD_SET_CONFIG: { + Usart_Mgr.TXDBuf[3] = 1; + Usart_Mgr.TXDBuf[4] = POWER_DOWN_DELAY; + Usart_Mgr.TXDBuf[5] = POWER_DOWN_DELAY; + break; + } + case CMD_SET_NAME: { + Usart_Mgr.TXDBuf[3] = 14; // data len + Usart_Mgr.TXDBuf[4] = 1; // type + Usart_Mgr.TXDBuf[5] = 12; // data: ble name len + Usart_Mgr.TXDBuf[6] = 'N'; // data: ble name + Usart_Mgr.TXDBuf[7] = 'u'; // data: ble name + Usart_Mgr.TXDBuf[8] = 'P'; // data: ble name + Usart_Mgr.TXDBuf[9] = 'h'; // data: ble name + Usart_Mgr.TXDBuf[10] = 'y'; // data: ble name + Usart_Mgr.TXDBuf[11] = ' '; // data: ble name + Usart_Mgr.TXDBuf[12] = 'G'; // data: ble name + Usart_Mgr.TXDBuf[13] = 'e'; // data: ble name + Usart_Mgr.TXDBuf[14] = 'm'; // data: ble name + Usart_Mgr.TXDBuf[15] = '8'; // data: ble name + Usart_Mgr.TXDBuf[16] = '0'; // data: ble name + Usart_Mgr.TXDBuf[17] = '-'; // data: ble name + Usart_Mgr.TXDBuf[18] = get_checksum(Usart_Mgr.TXDBuf + 4, Usart_Mgr.TXDBuf[3]); // sum + break; + } + + case CMD_SET_24G_NAME: { + Usart_Mgr.TXDBuf[3] = 38; + Usart_Mgr.TXDBuf[4] = 38; + Usart_Mgr.TXDBuf[5] = 3; + Usart_Mgr.TXDBuf[6] = 'N'; + Usart_Mgr.TXDBuf[8] = 'u'; + Usart_Mgr.TXDBuf[10] = 'P'; + Usart_Mgr.TXDBuf[12] = 'h'; + Usart_Mgr.TXDBuf[14] = 'y'; + Usart_Mgr.TXDBuf[16] = ' '; + Usart_Mgr.TXDBuf[18] = 'G'; + Usart_Mgr.TXDBuf[20] = 'e'; + Usart_Mgr.TXDBuf[22] = 'm'; + Usart_Mgr.TXDBuf[24] = '8'; + Usart_Mgr.TXDBuf[26] = '0'; + Usart_Mgr.TXDBuf[28] = ' '; + Usart_Mgr.TXDBuf[30] = 'D'; + Usart_Mgr.TXDBuf[32] = 'o'; + Usart_Mgr.TXDBuf[34] = 'n'; + Usart_Mgr.TXDBuf[36] = 'g'; + Usart_Mgr.TXDBuf[38] = 'l'; + Usart_Mgr.TXDBuf[40] = 'e'; + Usart_Mgr.TXDBuf[42] = get_checksum(Usart_Mgr.TXDBuf + 4, Usart_Mgr.TXDBuf[3]); // sum + break; + } + + case CMD_READ_DATA: { + Usart_Mgr.TXDBuf[3] = 2; + Usart_Mgr.TXDBuf[4] = 0x00; + Usart_Mgr.TXDBuf[5] = FUNC_VALID_LEN; + Usart_Mgr.TXDBuf[6] = FUNC_VALID_LEN; + break; + } + case CMD_WRITE_DATA: { + func_tab[4] = dev_info.link_mode; + func_tab[5] = dev_info.rf_channel; + func_tab[6] = dev_info.ble_channel; + + Usart_Mgr.TXDBuf[3] = FUNC_VALID_LEN + 2; + Usart_Mgr.TXDBuf[4] = 0; + Usart_Mgr.TXDBuf[5] = FUNC_VALID_LEN; + + for (i = 0; i < FUNC_VALID_LEN; i++) { + Usart_Mgr.TXDBuf[6 + i] = func_tab[i]; + } + Usart_Mgr.TXDBuf[6 + i] = get_checksum(func_tab, FUNC_VALID_LEN); + Usart_Mgr.TXDBuf[6 + i] += 0; + Usart_Mgr.TXDBuf[6 + i] += FUNC_VALID_LEN; + break; + } + case CMD_RF_DFU: { + Usart_Mgr.TXDBuf[3] = 1; // len + Usart_Mgr.TXDBuf[4] = 0; // dat + Usart_Mgr.TXDBuf[5] = 0; // sum + break; + } + + default: + break; + } + + f_uart_ack = 0; + UART_Send_Bytes(Usart_Mgr.TXDBuf, Usart_Mgr.TXDBuf[3] + 5); + + if (wait_ack) { + while (wait_ack--) { + wait_ms(1); + if (f_uart_ack) return TX_OK; + } + } else { + return TX_OK; + } + + return TX_TIMEOUT; +} + +/** + * @brief RF module state sync. + */ +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) return; + else interval_timer = timer_read32(); + + if (f_rf_reset) { + f_rf_reset = 0; + wait_ms(300); + writePinLow(NRF_RESET_PIN); + wait_ms(50); + writePinHigh(NRF_RESET_PIN); + wait_ms(50); + } + else if (f_send_channel) { + f_send_channel = 0; + uart_send_cmd(CMD_SET_LINK, 10, 10); + } + + if (dev_info.link_mode == LINK_USB) { + rf_blink_cnt = 0; + if (host_mode != HOST_USB_TYPE) { + host_mode = HOST_USB_TYPE; + host_set_driver(m_host_driver); + m_break_all_key(); + } + } + else { + if (host_mode != HOST_RF_TYPE) { + host_mode = HOST_RF_TYPE; + m_break_all_key(); + host_set_driver(0); + } + + if (dev_info.rf_state != RF_CONNECT) { + if (disconnect_delay >= 10) { + rf_blink_cnt = 3; + rf_link_show_time = 0; + link_state_temp = dev_info.rf_state; + } else { + disconnect_delay++; + } + } + else if (dev_info.rf_state == RF_CONNECT) { + rf_linking_time = 0; + disconnect_delay = 0; + rf_blink_cnt = 0; + + if (link_state_temp != RF_CONNECT) { + link_state_temp = RF_CONNECT; + if (dev_info.link_mode == LINK_RF_24) { + uart_send_cmd(CMD_SET_24G_NAME, 10, 30); + } + } + } + } + + uart_send_cmd(CMD_RF_STS_SYSC, 0, 0); + + if (dev_info.link_mode != LINK_USB) { + if (++sync_lost >= 5) { + sync_lost = 0; + f_rf_reset = 1; + } + } +} + +/** + * @brief RF module initial. + */ +void rf_device_init(void) +{ + uint8_t timeout = 0; + void uart_receive_pro(void); + + timeout = 10; + f_rf_hand_ok = 0; + while (timeout--) { + uart_send_cmd(CMD_HAND, 0, 20); + wait_ms(5); + uart_receive_pro(); + uart_receive_pro(); + if (f_rf_hand_ok) + break; + } + + timeout = 10; + f_rf_read_data_ok = 0; + while (timeout--) { + uart_send_cmd(CMD_READ_DATA, 0, 20); + wait_ms(5); + uart_receive_pro(); + uart_receive_pro(); + if (f_rf_read_data_ok) + break; + } + + timeout = 10; + f_rf_sts_sysc_ok = 0; + while (timeout--) { + uart_send_cmd(CMD_RF_STS_SYSC, 0, 20); + wait_ms(5); + uart_receive_pro(); + uart_receive_pro(); + if (f_rf_sts_sysc_ok) + break; + } + + uart_send_cmd(CMD_SET_24G_NAME, 10, 20); + + uart_send_cmd(CMD_SET_NAME, 10, 20); +} + +/** + * @brief Uart send bytes. + * @param Buffer data buf + * @param Length data lenght + */ +void UART_Send_Bytes(uint8_t *Buffer, uint32_t Length) +{ + writePinLow(NRF_WAKEUP_PIN); + wait_us(50); + + uart_transmit(Buffer, Length); + + wait_us(50 + Length * 22); + writePinHigh(NRF_WAKEUP_PIN); +} + +uint8_t get_checksum(uint8_t *buf, uint8_t len) +{ + uint8_t i; + uint8_t checksum = 0; + + for (i = 0; i < len; i++) + checksum += *buf++; + + checksum ^= UART_HEAD; + + return checksum; +} + +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; + + Usart_Mgr.TXDBuf[0] = UART_HEAD; + Usart_Mgr.TXDBuf[1] = report_type; + Usart_Mgr.TXDBuf[2] = 0x01; + Usart_Mgr.TXDBuf[3] = report_size; + + memcpy(&Usart_Mgr.TXDBuf[4], report_buf, report_size); + Usart_Mgr.TXDBuf[4 + report_size] = get_checksum(&Usart_Mgr.TXDBuf[4], report_size); + + UART_Send_Bytes(&Usart_Mgr.TXDBuf[0], report_size + 5); + + wait_us(50); +} + +/** + * @brief Uart receives data and processes it after completion,. + */ +void uart_receive_pro(void) +{ + static bool rcv_start = false; + + if (uart_available()) { + rcv_start = true; + while (uart_available()) { + if (Usart_Mgr.RXDLen >= UART_MAX_LEN) { + uart_read(); + Usart_Mgr.RXDState = RX_DATA_OV; + } else { + Usart_Mgr.RXDBuf[Usart_Mgr.RXDLen++] = uart_read(); + } + } + + } else if (rcv_start) { + rcv_start = false; + Usart_Mgr.RXDState = RX_Done; + RF_Protocol_Receive(); + Usart_Mgr.RXDLen = 0; + } +} + +/** + * @brief RF uart initial. + */ +void rf_uart_init(void) { + /* set uart buad as 460800 */ + uart_init(460800); + + /* Enable parity check */ + USART1->CR1 &= ~((uint32_t)USART_CR1_UE); + USART1->CR1 |= USART_CR1_M0 | USART_CR1_PCE; + USART1->CR1 |= USART_CR1_UE; + + /* set Rx and Tx pin pull up */ + GPIOB->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR6 | GPIO_OSPEEDER_OSPEEDR7); + GPIOB->PUPDR |= (GPIO_PUPDR_PUPDR6_0 | GPIO_PUPDR_PUPDR7_0); +} \ No newline at end of file diff --git a/keyboards/nuphy/gem80/ansi/rules.mk b/keyboards/nuphy/gem80/ansi/rules.mk new file mode 100644 index 000000000000..c2c4aa6ac9ea --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/rules.mk @@ -0,0 +1,7 @@ +SRC += side.c +SRC += rf.c +SRC += sleep.c +SRC += side_driver.c +SRC += side_logo.c +QUANTUM_LIB_SRC += uart.c + diff --git a/keyboards/nuphy/gem80/ansi/side.c b/keyboards/nuphy/gem80/ansi/side.c new file mode 100644 index 000000000000..5264f2c7d176 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/side.c @@ -0,0 +1,1013 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later +#include "ansi.h" +#include "side_table.h" + +#define SIDE_WAVE_1 0 +#define SIDE_WAVE_2 1 +#define SIDE_MIX 2 +#define SIDE_STATIC 3 +#define SIDE_BREATH 4 +#define SIDE_OFF 5 +#define LIGHT_COLOUR_MAX 8 +#define SIDE_COLOUR_MAX 8 +#define LIGHT_SPEED_MAX 4 +#define RF_LED_LINK_PERIOD 500 +#define RF_LED_PAIR_PERIOD 250 +#define SIDE_LINE 5 +#define CHARGING_SHIFT 0 +#define RFLINK_SHIFT 0 +#define CHARGING_BREATHE 1 +#define RFLINK_BLINK 1 +#define LOW_BAT_BLINK_PRIOD 500 +#define SIDE_LED_NUM 12 + +const uint8_t side_speed_table[6][5] = { + [SIDE_WAVE_1] = {24, 30, 36, 42, 50}, + [SIDE_WAVE_2] = {24, 30, 36, 42, 50}, + [SIDE_MIX] = {14, 20, 28, 36, 50}, + [SIDE_STATIC] = {50, 50, 50, 50, 50}, + [SIDE_BREATH] = {14, 20, 28, 36, 50}, + [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] = { + 0, + 1, + 2, + 3, + 4, +}; + + +bool f_charging = 1; + +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 low_bat_blink_cnt = 6; +uint8_t side_play_cnt = 0; +uint32_t side_play_timer = 0; + +uint8_t r_temp, g_temp, b_temp; +extern DEV_INFO_STRUCT dev_info; +extern bool f_bat_hold; +extern bool f_sleep_show; +extern bool f_dial_sw_init_ok; +extern uint8_t logo_mode; +extern uint8_t logo_light; +extern uint8_t logo_speed; +extern uint8_t logo_rgb; +extern uint8_t logo_colour; +extern uint8_t logo_play_point; +extern uint8_t rf_blink_cnt; +extern uint16_t rf_link_show_time; +extern uint8_t logo_play_cnt; +extern uint32_t logo_play_timer; + +LED_TYPE side_leds[SIDE_LED_NUM] = {0}; +void side_ws2812_setleds(LED_TYPE *ledarray, uint16_t leds); +void rgb_matrix_update_pwm_buffers(void); +void m_logo_led_show(void); + +/** + * @brief side leds set color vaule. + * @param index: index of side_leds[]. + * @param ... + */ +void side_rgb_set_color(int index, uint8_t red, uint8_t green, uint8_t blue) +{ + side_leds[index].r = red; + side_leds[index].g = green; + side_leds[index].b = blue; +} + +/** + * @brief refresh side leds. + */ +void side_rgb_refresh(void) +{ + side_ws2812_setleds(side_leds, SIDE_LED_NUM); +} + + +/** + * @brief Adjusting the brightness of side lights. + * @param dir: 0 - decrease, 1 - increase. + * @note save to eeprom. + */ +void light_level_control(uint8_t brighten) +{ + if (brighten) + { + if (side_light == 5) { + return; + } else + side_light++; + } else + { + if (side_light == 0) { + return; + } else + side_light--; + } + user_config.ee_side_light = side_light; + eeconfig_update_user_datablock(&user_config); +} + +/** + * @brief Adjusting the speed of side lights. + * @param dir: 0 - decrease, 1 - increase. + * @note save to eeprom. + */ +void light_speed_contol(uint8_t fast) +{ + if ((side_speed) > LIGHT_SPEED_MAX) + (side_speed) = LIGHT_SPEED_MAX / 2; + + if (fast) { + if ((side_speed)) side_speed--; + } else { + if ((side_speed) < LIGHT_SPEED_MAX) side_speed++; + } + user_config.ee_side_speed = side_speed; + eeconfig_update_user_datablock(&user_config); +} + +/** + * @brief Switch to the next color of side lights. + * @param dir: 0 - prev, 1 - next. + * @note save to eeprom. + */ +void side_colour_control(uint8_t dir) +{ + if ((side_mode != SIDE_WAVE_1)&&(side_mode != SIDE_WAVE_2)){ + if (side_rgb) { + side_rgb = 0; + side_colour = 0; + } + } + + if (dir) { + if (side_rgb) { + side_rgb = 0; + side_colour = 0; + } else { + side_colour++; + if (side_colour >= LIGHT_COLOUR_MAX) { + side_rgb = 1; + side_colour = 0; + } + } + } else { + if (side_rgb) { + side_rgb = 0; + side_colour = LIGHT_COLOUR_MAX - 1; + } else { + side_colour--; + if (side_colour >= LIGHT_COLOUR_MAX) { + side_rgb = 1; + side_colour = 0; + } + } + } + user_config.ee_side_rgb = side_rgb; + user_config.ee_side_colour = side_colour; + eeconfig_update_user_datablock(&user_config); +} + +/** + * @brief Change the color mode of side lights. + * @param dir: 0 - prev, 1 - next. + * @note save to eeprom. + */ +void side_mode_control(uint8_t dir) +{ + if (dir) { + side_mode++; + if (side_mode > SIDE_OFF) { + side_mode = 0; + } + } else { + if (side_mode > 0) { + side_mode--; + } else { + side_mode = SIDE_OFF; + } + } + side_play_point = 0; + user_config.ee_side_mode = side_mode; + eeconfig_update_user_datablock(&user_config); +} + +/** + * @brief set left side leds. + * @param ... + */ +void set_side_rgb(uint8_t r, uint8_t g, uint8_t b) +{ + for (int i = 0; i < SIDE_LINE; i++) + side_rgb_set_color(i, r >> 2, g >> 2, b >> 2); +} + +/** + * @brief set left side leds. + */ +void sys_sw_led_show(void) +{ + static uint32_t sys_show_timer = 0; + static bool sys_show_flag = false; + extern bool f_sys_show; + + if (f_sys_show) { + f_sys_show = false; + sys_show_timer = timer_read32(); + sys_show_flag = true; + } + + if (sys_show_flag) { + if (dev_info.sys_sw_state == SYS_SW_MAC) { + r_temp = 0x80; + g_temp = 0x80; + b_temp = 0x80; + } else { + r_temp = 0x00; + g_temp = 0x00; + b_temp = 0x80; + } + if ((timer_elapsed32(sys_show_timer) / 500) % 2 == 0) { + set_side_rgb(r_temp, g_temp, b_temp); + } else { + set_side_rgb(0x00, 0x00, 0x00); + } + if (timer_elapsed32(sys_show_timer) >= (3000-50)) { + #if(WORK_MODE == USB_MODE) + if(timer_elapsed32(sys_show_timer) <= 4000) set_side_rgb(r_temp, g_temp, b_temp); + else sys_show_flag = false; + #else + sys_show_flag = false; + #endif + } + } +} + +/** + * @brief sleep_sw_led_show. + */ +void sleep_sw_led_show(void) +{ + static uint32_t sleep_show_timer = 0; + static bool sleep_show_flag = false; + + if (f_sleep_show) { + f_sleep_show = false; + sleep_show_timer = timer_read32(); + sleep_show_flag = true; + } + + if (sleep_show_flag) { + if (f_dev_sleep_enable) { + r_temp = 0x00; + g_temp = 0x80; + b_temp = 0x00; + } else { + r_temp = 0x80; + g_temp = 0x00; + b_temp = 0x00; + } + if ((timer_elapsed32(sleep_show_timer) / 500) % 2 == 0) { + set_side_rgb(r_temp, g_temp, b_temp); + } else { + set_side_rgb(0x00, 0x00, 0x00); + } + if (timer_elapsed32(sleep_show_timer) >= (3000-50)) { + sleep_show_flag = false; + } + } +} + +/** + * @brief sys_led_show. + */ +void sys_led_show(void) { + if (dev_info.link_mode == LINK_USB) { + if (host_keyboard_led_state().caps_lock) { + set_side_rgb(0X00, 0x80, 0x80); + } + } + + else { + if (dev_info.rf_led & 0x02) { + set_side_rgb(0X00, 0x80, 0x80); + } + } +} + +/** + * @brief light_point_playing. + * @param trend: + * @param step: + * @param len: + * @param point: + */ +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; + } else { + *point -= step; + if (*point >= len) *point = len - (255 - *point) - 1; + } +} + +/** + * @brief count_rgb_light. + * @param light_temp: + */ +static void count_rgb_light(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. + */ +static void side_wave_mode_show_1(void) +{ + uint8_t play_index; + + //------------------------------ + if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + return; + else + side_play_cnt -= side_speed_table[side_mode][side_speed]; + if (side_play_cnt > 20) side_play_cnt = 0; + + //------------------------------ + if (side_rgb) + light_point_playing(0, 1, FLOW_COLOUR_TAB_LEN, &side_play_point); + 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++) { + if (side_rgb) { + r_temp = flow_rainbow_colour_tab[play_index][0]; + g_temp = flow_rainbow_colour_tab[play_index][1]; + b_temp = flow_rainbow_colour_tab[play_index][2]; + + light_point_playing(1, 8, FLOW_COLOUR_TAB_LEN, &play_index); + } else { + r_temp = colour_lib[side_colour][0]; + g_temp = colour_lib[side_colour][1]; + 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]); + } + + count_rgb_light(side_light_table[side_light]); + + side_rgb_set_color(side_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + + } +} +static void side_wave_mode_show_2(void) +{ + uint8_t play_index; + static uint8_t breathe = 0; + uint8_t breath_temp; + + //------------------------------ + if (side_play_cnt <= (side_speed_table[side_mode][side_speed])) + return; + else + side_play_cnt -= side_speed_table[side_mode][side_speed]; + if (side_play_cnt > 20) side_play_cnt = 0; + + //------------------------------ + if (side_rgb) { + light_point_playing(0, 1, FLOW_COLOUR_TAB_LEN, &side_play_point); + light_point_playing(0, 1, SIDE_WAVE_TAB_LEN, &breathe); + } + else + light_point_playing(0, 1, SIDE_WAVE_TAB_LEN, &side_play_point); + + breath_temp = breathe; + play_index = side_play_point; + for (int i = 0; i < SIDE_LINE; i++) { + if (side_rgb) { + r_temp = flow_rainbow_colour_tab[play_index][0]; + g_temp = flow_rainbow_colour_tab[play_index][1]; + b_temp = flow_rainbow_colour_tab[play_index][2]; + + light_point_playing(1, 16, FLOW_COLOUR_TAB_LEN, &play_index); + + light_point_playing(1, 32, SIDE_WAVE_TAB_LEN, &breath_temp); + count_rgb_light(side_wave_data_tab[breath_temp]); + + } else { + r_temp = colour_lib[side_colour][0]; + g_temp = colour_lib[side_colour][1]; + b_temp = colour_lib[side_colour][2]; + + light_point_playing(1, 24, SIDE_WAVE_TAB_LEN, &play_index); + count_rgb_light(side_wave_data_tab[play_index]); + } + + count_rgb_light(side_light_table[side_light]); + side_rgb_set_color(side_led_index_tab[i], r_temp, g_temp, b_temp); + } +} + +/** + * @brief side_spectrum_mode_show. + */ +static void side_spectrum_mode_show(void) +{ + if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + return; + else + side_play_cnt -= side_speed_table[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); + + r_temp = flow_rainbow_colour_tab[side_play_point][0]; + 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]); + + for (int i = 0; i < SIDE_LINE; i++) { + side_rgb_set_color(side_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + +/** + * @brief side_breathe_mode_show. + */ +static void side_breathe_mode_show(void) +{ + static uint8_t play_point = 0; + + if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + return; + else + side_play_cnt -= side_speed_table[side_mode][side_speed]; + 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 >= LIGHT_COLOUR_MAX) + side_play_point = 0; + } + + r_temp = colour_lib[side_play_point][0]; + g_temp = colour_lib[side_play_point][1]; + b_temp = colour_lib[side_play_point][2]; + } else { + r_temp = colour_lib[side_colour][0]; + g_temp = colour_lib[side_colour][1]; + b_temp = colour_lib[side_colour][2]; + } + + count_rgb_light(breathe_data_tab[play_point]); + count_rgb_light(side_light_table[side_light]); + + for (int i = 0; i < SIDE_LINE; i++) { + side_rgb_set_color(side_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + +/** + * @brief side_static_mode_show. + */ +static void side_static_mode_show(void) +{ + uint8_t play_index; + + if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + return; + else + side_play_cnt -= side_speed_table[side_mode][side_speed]; + if (side_play_cnt > 20) side_play_cnt = 0; + + if (side_play_point >= SIDE_COLOUR_MAX) side_play_point = 0; + + for (int i = 0; i < SIDE_LINE; i++) { + if (0) { + r_temp = flow_rainbow_colour_tab[16 * i][0]; + g_temp = flow_rainbow_colour_tab[16 * i][1]; + b_temp = flow_rainbow_colour_tab[16 * i][2]; + light_point_playing(0, 24, FLOW_COLOUR_TAB_LEN, &play_index); + } else + { + r_temp = colour_lib[side_colour][0]; + g_temp = colour_lib[side_colour][1]; + b_temp = colour_lib[side_colour][2]; + } + + count_rgb_light(side_light_table[side_light]); + + side_rgb_set_color(side_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + +/** + * @brief side_off_mode_show. + */ +static void side_off_mode_show(void) +{ + if (side_play_cnt <= side_speed_table[side_mode][side_speed]) + return; + else + side_play_cnt -= side_speed_table[side_mode][side_speed]; + if (side_play_cnt > 20) side_play_cnt = 0; + + r_temp = 0x00; + g_temp = 0x00; + b_temp = 0x00; + + for (int i = 0; i < SIDE_LINE; i++) { + side_rgb_set_color(side_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + + +void bat_charging_breathe(void) +{ + static uint32_t interval_timer = 0; + static uint8_t play_point = 0; + + if (timer_elapsed32(interval_timer) > 10) { + interval_timer = timer_read32(); + light_point_playing(0, 1, BREATHE_TAB_LEN, &play_point); + } + + r_temp = 0x80; g_temp = 0x40; b_temp = 0x00; + count_rgb_light(breathe_data_tab[play_point]); + set_side_rgb(r_temp, g_temp, b_temp); +} + + +void bat_charging_design(uint8_t init, uint8_t r, uint8_t g, uint8_t b) +{ + static uint32_t interval_timer = 0; + static uint16_t show_mask = 0x00; + static bool f_move_trend = 0; + uint16_t bit_mask = 1; + uint8_t i; + + if (timer_elapsed32(interval_timer) > 100) { + interval_timer = timer_read32(); + + if (f_move_trend) { + show_mask >>= 1; + if (show_mask == 0x1f >> (SIDE_LINE - init)) + f_move_trend = 0; + } else { + show_mask <<= 1; + show_mask |= 1; + if (show_mask == 0x7f) + f_move_trend = 1; + } + } + + for (i = 0; i < SIDE_LINE; i++) { + if (show_mask & bit_mask) { + side_rgb_set_color(i, r, g, b); + } else { + side_rgb_set_color(i, 0x00, 0x00, 0x00); + } + bit_mask <<= 1; + } +} + +void rf_show_blink(void) +{ + extern uint8_t rf_blink_cnt; + static uint32_t interval_timer = 0; + uint16_t show_priod; + + if (rf_blink_cnt) { + if (dev_info.rf_state == RF_PAIRING) + show_priod = 250; + else + show_priod = 500; + + if (timer_elapsed32(interval_timer) > (show_priod >> 1)) { + r_temp = 0x00; g_temp = 0x00; b_temp = 0x00; + } + + if (timer_elapsed32(interval_timer) >= show_priod) { + rf_blink_cnt--; + interval_timer = timer_read32(); + } + } + else { + interval_timer = timer_read32(); + } + + set_side_rgb(r_temp, g_temp, b_temp); +} + +void rf_show_design(uint8_t r, uint8_t g, uint8_t b) +{ + static uint32_t interval_timer = 0; + static uint16_t show_mask = 0x04; + uint16_t show_mask_temp = 0; + uint16_t show_priod; + uint16_t bit_mask = 1; + uint8_t i; + + if (dev_info.rf_state == RF_PAIRING) + show_priod = 100; + else + show_priod = 200; + + if (timer_elapsed32(interval_timer) > show_priod) { + interval_timer = timer_read32(); + + show_mask_temp = (show_mask << 1) | (show_mask >> 1); + show_mask_temp |= 0x04; + show_mask |= show_mask_temp; + + if (show_mask == 0x7f) + show_mask = 0x0; + } + + for (i = 0; i < SIDE_LINE; i++) { + if (show_mask & bit_mask) { + side_rgb_set_color(i, r >> 2, g >> 2, b >> 2); + } else { + side_rgb_set_color(i, 0x00, 0x00, 0x00); + } + bit_mask <<= 1; + } +} + +/** + * @brief rf_led_show. + */ +void rf_led_show(void) +{ +#if(WORK_MODE == THREE_MODE) + static bool flag_power_on = 1; +#endif + + if (dev_info.link_mode == LINK_RF_24) { + r_temp = 0x00; + g_temp = 0x80; + b_temp = 0x00; + } else if (dev_info.link_mode == LINK_USB) { + r_temp = 0x80; + g_temp = 0x80; + b_temp = 0x00; +#if(WORK_MODE == THREE_MODE) + if (flag_power_on && (rf_link_show_time < RF_LINK_SHOW_TIME)) return; +#endif + } else { + r_temp = 0x00; + g_temp = 0x00; + b_temp = 0x80; + } + +#if(WORK_MODE == THREE_MODE) + flag_power_on = 0; +#endif + if (rf_blink_cnt) { + #if (RFLINK_SHIFT) + rf_show_design(r_temp, g_temp, b_temp); + #else + rf_show_blink(); + #endif + } + else if (rf_link_show_time < RF_LINK_SHOW_TIME) { + set_side_rgb(r_temp, g_temp, b_temp); + } +} + +void low_bat_show(void) +{ + static uint32_t interval_timer = 0; + + r_temp = 0x80, g_temp = 0, b_temp = 0; + + if(low_bat_blink_cnt) + { + if (timer_elapsed32(interval_timer) > (LOW_BAT_BLINK_PRIOD >> 1)) { + r_temp = 0x00; g_temp = 0x00; b_temp = 0x00; + } + + if (timer_elapsed32(interval_timer) >= LOW_BAT_BLINK_PRIOD) { + interval_timer = timer_read32(); + low_bat_blink_cnt--; + } + } + + set_side_rgb(r_temp, g_temp, b_temp); +} + + + +/** + * @brief bat_percent_led. + */ +void bat_percent_led(uint8_t bat_percent) +{ + uint8_t i; + uint8_t bat_end_led = 0; + uint8_t bat_r, bat_g, bat_b; + + if (bat_percent <= 20) { + bat_end_led = 0; + bat_r = 0x80, bat_g = 0, bat_b = 0; + } else if (bat_percent <= 40) { + bat_end_led = 1; + bat_r = 0x80, bat_g = 0x40, bat_b = 0; + } else if (bat_percent <= 50) { + bat_end_led = 2; + bat_r = 0x80, bat_g = 0x40, bat_b = 0; + } else if (bat_percent <= 80) { + bat_end_led = 3; + bat_r = 0x80, bat_g = 0x80, bat_b = 0; + } else { + bat_end_led = 4; + bat_r = 0, bat_g = 0x80, bat_b = 0; + } + + if (f_charging) { + low_bat_blink_cnt = 6; + #if (CHARGING_SHIFT) + bat_charging_design(bat_end_led, bat_r >> 2, bat_g >> 2, bat_b >> 2); + #else + bat_charging_breathe(); + #endif + } + else if(bat_percent < 10) { + low_bat_show(); + } + else { + bat_end_led = 4; + low_bat_blink_cnt = 6; + for (i = 0; i <= bat_end_led; i++) + side_rgb_set_color(i, bat_r >> 2, bat_g >> 2, bat_b >> 2); + + for (; i < SIDE_LINE; i++) + side_rgb_set_color(i, 0, 0, 0); + } +} + +/** + * @brief bat_led_show. + */ +void bat_led_show(void) +{ + static bool bat_show_flag = true; + static uint32_t bat_show_time = 0; + static uint32_t bat_sts_debounce = 0; + static uint32_t bat_per_debounce = 0; + static uint8_t charge_state = 0; + static uint8_t bat_percent = 0; + static bool f_init = 1; + + if(dev_info.link_mode != LINK_USB) + { + extern uint16_t rf_link_show_time; + if(rf_link_show_time < RF_LINK_SHOW_TIME) + return; + + if(dev_info.rf_state != RF_CONNECT) + return; + } + + if (f_init) { + f_init = 0; + bat_show_time = timer_read32(); + charge_state = dev_info.rf_charge; + bat_percent = dev_info.rf_baterry; + } + + if (charge_state != dev_info.rf_charge) { + if (timer_elapsed32(bat_sts_debounce) > 1000) { + if (((charge_state & 0x01) == 0) && ((dev_info.rf_charge & 0x01) != 0)) { + bat_show_flag = true; + f_charging = true; + bat_show_time = timer_read32(); + } + charge_state = dev_info.rf_charge; + } + } + else { + bat_sts_debounce = timer_read32(); + if (timer_elapsed32(bat_show_time) > 5000) { + bat_show_flag = false; + f_charging = false; + } + if (charge_state == 0x03) { + f_charging = true; + } else if (!(charge_state & 0x01)) { + f_charging = 0; + } + } + + if (bat_percent != dev_info.rf_baterry) { + if (timer_elapsed32(bat_per_debounce) > 1000) { + bat_percent = dev_info.rf_baterry; + } + } + else { + bat_per_debounce = timer_read32(); + + if ( (bat_percent < 10) && (!(charge_state&0x01))) { + bat_show_flag = true; + bat_show_time = timer_read32(); + + if(rgb_matrix_config.hsv.v > RGB_MATRIX_VAL_STEP) { + rgb_matrix_config.hsv.v = RGB_MATRIX_VAL_STEP; + } + + if(side_light > 1) { + side_light = 1; + } + + if(logo_light >1) { + logo_light = 1; + } + + } + } + + if (f_bat_hold || bat_show_flag) { + bat_percent_led(bat_percent); + } +} + +/** + * @brief device_reset_show. + */ +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); + for (int blink_cnt = 0; blink_cnt < 3; blink_cnt++) { + rgb_matrix_set_color_all(0x10, 0x10, 0x10); + for (int i = 0; i < SIDE_LED_NUM; i++) { + side_rgb_set_color(i, 0x10, 0x10, 0x10); + } + rgb_matrix_update_pwm_buffers(); + side_rgb_refresh(); + wait_ms(200); + + rgb_matrix_set_color_all(0x00, 0x00, 0x00); + for (int i = 0; i < SIDE_LED_NUM; i++) { + side_rgb_set_color(i, 0x00, 0x00, 0x00); + } + rgb_matrix_update_pwm_buffers(); + side_rgb_refresh(); + wait_ms(200); + } +} + +/** + * @brief device_reset_init. + */ +void device_reset_init(void) +{ + side_mode = 0; + side_light = 3; + side_speed = 2; + side_rgb = 1; + side_colour = 0; + side_play_point = 0; + + side_play_cnt = 0; + side_play_timer = timer_read32(); + + logo_mode = 0; + logo_light = 3; + logo_speed = 2; + logo_rgb = 1; + logo_colour = 0; + logo_play_point = 0; + + logo_play_cnt = 0; + logo_play_timer = timer_read32(); + + f_bat_hold = false; + + rgb_matrix_enable(); + rgb_matrix_mode(RGB_MATRIX_DEFAULT_MODE); + rgb_matrix_set_speed(255 - RGB_MATRIX_SPD_STEP * 2); + rgb_matrix_sethsv(RGB_DEFAULT_COLOUR,255, RGB_MATRIX_MAXIMUM_BRIGHTNESS - RGB_MATRIX_VAL_STEP * 2); + + user_config.default_brightness_flag = 0xA5; + user_config.ee_side_mode = side_mode; + user_config.ee_side_light = side_light; + user_config.ee_side_speed = side_speed; + user_config.ee_side_rgb = side_rgb; + user_config.ee_side_colour = side_colour; + user_config.ee_logo_mode = logo_mode; + user_config.ee_logo_light = logo_light; + user_config.ee_logo_speed = logo_speed; + user_config.ee_logo_rgb = logo_rgb; + user_config.ee_logo_colour = logo_colour; +#if(WORK_MODE == THREE_MODE) + f_dev_sleep_enable = 1; +#endif + eeconfig_update_user_datablock(&user_config); +} + +void rgb_test_show(void) +{ + writePinHigh(DC_BOOST_PIN); + setPinOutput(DRIVER_LED_CS_PIN); + writePinLow(DRIVER_LED_CS_PIN); + + rgb_matrix_set_color_all(0xFF, 0x00, 0x00); + for (int i = 0; i < SIDE_LED_NUM; i++) + side_rgb_set_color(i, 0xFF, 0x00, 0x00); + rgb_matrix_update_pwm_buffers(); + side_rgb_refresh(); + wait_ms(1000); + rgb_matrix_set_color_all(0x00, 0xFF, 0x00); + for (int i = 0; i < SIDE_LED_NUM; i++) + side_rgb_set_color(i, 0x00, 0xFF, 0x00); + rgb_matrix_update_pwm_buffers(); + side_rgb_refresh(); + wait_ms(1000); + rgb_matrix_set_color_all(0x00, 0x00, 0xFF); + for (int i = 0; i < SIDE_LED_NUM; i++) + side_rgb_set_color(i, 0x00, 0x00, 0xFF); + rgb_matrix_update_pwm_buffers(); + side_rgb_refresh(); + wait_ms(1000); +} + +/** + * @brief side_led_show. + */ +void m_side_led_show(void) +{ + static uint32_t side_refresh_time = 0; + static bool flag_power_on = 1; + + if (flag_power_on) { + if (!f_dial_sw_init_ok) return; + flag_power_on = 0; + } + + side_play_cnt += timer_elapsed32(side_play_timer); + side_play_timer = timer_read32(); + + switch (side_mode) { + case SIDE_WAVE_1: side_wave_mode_show_1(); break; + case SIDE_WAVE_2: side_wave_mode_show_2(); break; + case SIDE_MIX: side_spectrum_mode_show(); break; + case SIDE_BREATH: side_breathe_mode_show(); break; + case SIDE_STATIC: side_static_mode_show(); break; + case SIDE_OFF: side_off_mode_show(); break; + } + +#if(WORK_MODE == THREE_MODE) + bat_led_show(); +#endif + sys_led_show(); + sys_sw_led_show(); + sleep_sw_led_show(); + rf_led_show(); + + m_logo_led_show(); + + if (timer_elapsed32(side_refresh_time) > 50) { + side_refresh_time = timer_read32(); + side_rgb_refresh(); + } +} diff --git a/keyboards/nuphy/gem80/ansi/side_driver.c b/keyboards/nuphy/gem80/ansi/side_driver.c new file mode 100644 index 000000000000..daa1c27e0f1b --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/side_driver.c @@ -0,0 +1,91 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later +#include +#include + +#include "quantum.h" +#include "ws2812.h" + +/* 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 compile 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 +#else +#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 +#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 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"); \ + } \ + } while (0) + +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)); + // using something like wait_ns(is_one ? T1L : T0L) here throws off timings + if (is_one) { + // 1 + writePinHigh(DRIVER_SIDE_PIN); + wait_ns(WS2812_T1H); + writePinLow(DRIVER_SIDE_PIN); + wait_ns(WS2812_T1L); + } else { + // 0 + writePinHigh(DRIVER_SIDE_PIN); + wait_ns(WS2812_T0H); + writePinLow(DRIVER_SIDE_PIN); + wait_ns(WS2812_T0L); + } + } +} + +// Setleds for standard RGB +void side_ws2812_setleds(LED_TYPE *ledarray, uint16_t leds) +{ + // this code is very time dependent, so we need to disable interrupts + chSysLock(); + + for (uint8_t i = 0; i < leds; i++) { + // WS2812 protocol dictates grb order + side_sendByte(ledarray[i].g); + side_sendByte(ledarray[i].r); + side_sendByte(ledarray[i].b); + } + + // wait_ns(WS2812_RES); + + chSysUnlock(); +} diff --git a/keyboards/nuphy/gem80/ansi/side_logo.c b/keyboards/nuphy/gem80/ansi/side_logo.c new file mode 100644 index 000000000000..4dd6c0ad1092 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/side_logo.c @@ -0,0 +1,370 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later +#include "ansi.h" + +#define STARRY_INDEX_LEN (160) +#define WAVE_TAB_LEN (112 + 16) +#define BREATHE_TAB_LEN 128 +#define MIXCOLOUR_TAB_LEN 144 +#define FLOW_COLOUR_TAB_LEN 224 +#define FIREWORK_INDEX_LEN (158) +#define STARRY_DATA_LEN 96 +#define TIDE_DATA_LEN 120 +#define SIDE_WAVE_1 0 +#define SIDE_WAVE_2 1 +#define SIDE_MIX 2 +#define SIDE_STATIC 3 +#define SIDE_BREATH 4 +#define SIDE_OFF 5 +#define LOGO_LINE 7 +#define LIGHT_COLOUR_MAX 8 +#define SIDE_COLOUR_MAX 8 +#define LIGHT_SPEED_MAX 4 + +extern const uint8_t side_speed_table[6][5]; +extern const uint8_t side_light_table[6]; +extern const uint8_t light_value_tab[101]; +extern const uint8_t breathe_data_tab[BREATHE_TAB_LEN]; +extern const uint8_t wave_data_tab[WAVE_TAB_LEN]; +extern const uint8_t flow_rainbow_colour_tab[FLOW_COLOUR_TAB_LEN][3]; +extern const uint8_t colour_lib[9][3]; +extern uint8_t r_temp, g_temp, b_temp; +extern user_config_t user_config; +extern void side_rgb_set_color(int index, uint8_t red, uint8_t green, uint8_t blue); + + +const uint8_t logo_led_index_tab[LOGO_LINE] = { + 5, + 6, + 7, + 8, + 9, + 10, + 11, +}; + +uint8_t logo_mode = 0; +uint8_t logo_light = 3; +uint8_t logo_speed = 2; +uint8_t logo_rgb = 1; +uint8_t logo_colour = 0; +uint8_t logo_play_point = 0; +uint8_t logo_play_cnt = 0; +uint32_t logo_play_timer = 0; + + +void logo_light_level_control(uint8_t brighten) +{ + if (brighten) { + if (logo_light == 5) { + return; + } else + logo_light++; + } else + { + if (logo_light == 0) { + return; + } else + logo_light--; + } + user_config.ee_logo_light = logo_light; + eeconfig_update_user_datablock(&user_config); +} + +void logo_light_speed_contol(uint8_t fast) +{ + if ((logo_speed) > LIGHT_SPEED_MAX) + (logo_speed) = LIGHT_SPEED_MAX / 2; + + if (fast) { + if ((logo_speed)) logo_speed--; + } else { + if ((logo_speed) < LIGHT_SPEED_MAX) logo_speed++; + } + user_config.ee_logo_speed = logo_speed; + eeconfig_update_user_datablock(&user_config); +} + +void logo_side_colour_control(uint8_t dir) +{ + if ((logo_mode != SIDE_WAVE_1)&&(logo_mode != SIDE_WAVE_2)){ + if (logo_rgb) { + logo_rgb = 0; + logo_colour = 0; + } + } + + if (dir) { + if (logo_rgb) { + logo_rgb = 0; + logo_colour = 0; + } else { + logo_colour++; + if (logo_colour >= LIGHT_COLOUR_MAX) { + logo_rgb = 1; + logo_colour = 0; + } + } + } else { + if (logo_rgb) { + logo_rgb = 0; + logo_colour = LIGHT_COLOUR_MAX - 1; + } else { + logo_colour--; + if (logo_colour >= LIGHT_COLOUR_MAX) { + logo_rgb = 1; + logo_colour = 0; + } + } + } + user_config.ee_logo_rgb = logo_rgb; + user_config.ee_logo_colour = logo_colour; + eeconfig_update_user_datablock(&user_config); +} + +void logo_side_mode_control(uint8_t dir) +{ + if (dir) { + logo_mode++; + if (logo_mode > SIDE_OFF) { + logo_mode = 0; + } + } else { + if (logo_mode > 0) { + logo_mode--; + } else { + logo_mode = SIDE_OFF; + } + } + logo_play_point = 0; + user_config.ee_logo_mode = logo_mode; + eeconfig_update_user_datablock(&user_config); +} + + +void set_logo_rgb(uint8_t r, uint8_t g, uint8_t b) +{ + for (int i = 5; i < 12; i++) + side_rgb_set_color(i, r >> 2, g >> 2, b >> 2); +} + +static void logo_light_point_playing(uint8_t trend, uint8_t step, uint8_t len, uint8_t *point) +{ + if (trend) { + *point += step; + if (*point >= len) *point -= len; + } else { + *point -= step; + if (*point >= len) *point = len - (255 - *point) - 1; + } +} + +static void logo_count_rgb_light(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; +} + +static void logo_wave_mode_show_1(void) +{ + uint8_t play_index; + + //------------------------------ + if (logo_play_cnt <= side_speed_table[logo_mode][logo_speed]) + return; + else + logo_play_cnt -= side_speed_table[logo_mode][logo_speed]; + if (logo_play_cnt > 20) logo_play_cnt = 0; + + //------------------------------ + if (logo_rgb) + logo_light_point_playing(0, 1, FLOW_COLOUR_TAB_LEN, &logo_play_point); + else + logo_light_point_playing(0, 1, WAVE_TAB_LEN, &logo_play_point); + + play_index = logo_play_point; + for (int i = 0; i < LOGO_LINE; i++) { + if (logo_rgb) { + r_temp = flow_rainbow_colour_tab[play_index][0]; + g_temp = flow_rainbow_colour_tab[play_index][1]; + b_temp = flow_rainbow_colour_tab[play_index][2]; + + logo_light_point_playing(1, 5, FLOW_COLOUR_TAB_LEN, &play_index); + } else { + r_temp = colour_lib[logo_colour][0]; + g_temp = colour_lib[logo_colour][1]; + b_temp = colour_lib[logo_colour][2]; + + logo_light_point_playing(1, 12, WAVE_TAB_LEN, &play_index); + logo_count_rgb_light(wave_data_tab[play_index]); + } + + logo_count_rgb_light(side_light_table[logo_light]); + side_rgb_set_color(logo_led_index_tab[i], r_temp >> 1, g_temp >> 1, b_temp >> 1); + } +} +static void logo_wave_mode_show_2(void) +{ + uint8_t play_index; + + //------------------------------ + if (logo_play_cnt <= side_speed_table[logo_mode][logo_speed]) + return; + else + logo_play_cnt -= side_speed_table[logo_mode][logo_speed]; + if (logo_play_cnt > 20) logo_play_cnt = 0; + + //------------------------------ + if (logo_rgb) + logo_light_point_playing(0, 1, FLOW_COLOUR_TAB_LEN, &logo_play_point); + else + logo_light_point_playing(0, 1, WAVE_TAB_LEN, &logo_play_point); + + play_index = logo_play_point; + for (int i = 0; i < LOGO_LINE; i++) { + if (logo_rgb) { + r_temp = flow_rainbow_colour_tab[play_index][0]; + g_temp = flow_rainbow_colour_tab[play_index][1]; + b_temp = flow_rainbow_colour_tab[play_index][2]; + + logo_light_point_playing(1, 16, FLOW_COLOUR_TAB_LEN, &play_index); + } else { + r_temp = colour_lib[logo_colour][0]; + g_temp = colour_lib[logo_colour][1]; + b_temp = colour_lib[logo_colour][2]; + + logo_light_point_playing(1, 12, WAVE_TAB_LEN, &play_index); + logo_count_rgb_light(wave_data_tab[play_index]); + } + + logo_count_rgb_light(side_light_table[logo_light]); + side_rgb_set_color(logo_led_index_tab[i], r_temp >> 1, g_temp >> 1, b_temp >> 1); + } +} + +static void logo_spectrum_mode_show(void) +{ + if (logo_play_cnt <= side_speed_table[logo_mode][logo_speed]) + return; + else + logo_play_cnt -= side_speed_table[logo_mode][logo_speed]; + if (logo_play_cnt > 20) logo_play_cnt = 0; + + logo_light_point_playing(1, 1, FLOW_COLOUR_TAB_LEN, &logo_play_point); + + r_temp = flow_rainbow_colour_tab[logo_play_point][0]; + g_temp = flow_rainbow_colour_tab[logo_play_point][1]; + b_temp = flow_rainbow_colour_tab[logo_play_point][2]; + + logo_count_rgb_light(side_light_table[logo_light]); + + for (int i = 0; i < LOGO_LINE; i++) { + side_rgb_set_color(logo_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + +static void logo_breathe_mode_show(void) +{ + static uint8_t play_point = 0; + + if (logo_play_cnt <= side_speed_table[logo_mode][logo_speed]) + return; + else + logo_play_cnt -= side_speed_table[logo_mode][logo_speed]; + if (logo_play_cnt > 20) logo_play_cnt = 0; + + logo_light_point_playing(0, 1, BREATHE_TAB_LEN, &play_point); + + if (0) { + if (play_point == 0) { + if (++logo_play_point >= LIGHT_COLOUR_MAX) + logo_play_point = 0; + } + + r_temp = colour_lib[logo_play_point][0]; + g_temp = colour_lib[logo_play_point][1]; + b_temp = colour_lib[logo_play_point][2]; + } else { + r_temp = colour_lib[logo_colour][0]; + g_temp = colour_lib[logo_colour][1]; + b_temp = colour_lib[logo_colour][2]; + } + + logo_count_rgb_light(breathe_data_tab[play_point]); + logo_count_rgb_light(side_light_table[logo_light]); + + for (int i = 0; i < LOGO_LINE; i++) { + side_rgb_set_color(logo_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + +static void logo_static_mode_show(void) +{ + uint8_t play_index; + + if (logo_play_cnt <= side_speed_table[logo_mode][logo_speed]) + return; + else + logo_play_cnt -= side_speed_table[logo_mode][logo_speed]; + if (logo_play_cnt > 20) logo_play_cnt = 0; + + if (logo_play_point >= SIDE_COLOUR_MAX) logo_play_point = 0; + + for (int i = 0; i < LOGO_LINE; i++) { + if (0) { + r_temp = flow_rainbow_colour_tab[16 * i][0]; + g_temp = flow_rainbow_colour_tab[16 * i][1]; + b_temp = flow_rainbow_colour_tab[16 * i][2]; + logo_light_point_playing(0, 24, FLOW_COLOUR_TAB_LEN, &play_index); + } else + { + r_temp = colour_lib[logo_colour][0]; + g_temp = colour_lib[logo_colour][1]; + b_temp = colour_lib[logo_colour][2]; + } + + logo_count_rgb_light(side_light_table[logo_light]); + + side_rgb_set_color(logo_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + +static void logo_off_mode_show(void) +{ + if (logo_play_cnt <= side_speed_table[logo_mode][logo_speed]) + return; + else + logo_play_cnt -= side_speed_table[logo_mode][logo_speed]; + if (logo_play_cnt > 20) logo_play_cnt = 0; + + r_temp = 0x00; + g_temp = 0x00; + b_temp = 0x00; + + for (int i = 0; i < LOGO_LINE; i++) { + side_rgb_set_color(logo_led_index_tab[i], r_temp >> 2, g_temp >> 2, b_temp >> 2); + } +} + +void m_logo_led_show(void) +{ + logo_play_cnt += timer_elapsed32(logo_play_timer); + logo_play_timer = timer_read32(); + + switch (logo_mode) { + case SIDE_WAVE_1: logo_wave_mode_show_1(); break; + case SIDE_WAVE_2: logo_wave_mode_show_2(); break; + case SIDE_MIX: logo_spectrum_mode_show(); break; + case SIDE_BREATH: logo_breathe_mode_show(); break; + case SIDE_STATIC: logo_static_mode_show(); break; + case SIDE_OFF: logo_off_mode_show(); break; + } +} diff --git a/keyboards/nuphy/gem80/ansi/side_table.h b/keyboards/nuphy/gem80/ansi/side_table.h new file mode 100644 index 000000000000..951dae4a5cfc --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/side_table.h @@ -0,0 +1,373 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later +#pragma once + +#define STARRY_INDEX_LEN (160) +#define WAVE_TAB_LEN (112 + 16) +#define SIDE_WAVE_TAB_LEN (128 + 48 + 16) +#define BREATHE_TAB_LEN 128 +#define MIXCOLOUR_TAB_LEN 144 +#define FLOW_COLOUR_TAB_LEN 224 +#define FIREWORK_INDEX_LEN (158) +#define STARRY_DATA_LEN 96 +#define TIDE_DATA_LEN 120 + + +const uint8_t light_value_tab[101] = +{ + 0, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, + 33, 34, 36, 37, 39, 40, 42, 43, + 45, 47, 49, 51, 53, 55, 57, 59, + 61, 63, 65, 67, 69, 71, 73, 75, + 77, 79, 81, 83, 85, 87, 89, 91, + 94, 96, 99, 101, 104, 106, 109, 111, + 114, 116, 119, 121, 124, 126, 129, 131, + 134, 137, 140, 143, 146, 149, 152, 155, + 158, 161, 164, 167, 170, 173, 176, 179, + 182, 185, 188, 191, 194, 197, 200, 203, + 206, 209, 213, 216, 220, 223, 227, 230, + 234, 237, 241, 245, 248, 251, 255, 255, + 255, +}; + +const uint8_t breathe_data_tab[BREATHE_TAB_LEN]= +{ + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 12, 14, 16, 18, 20, + 22, 24, 27, 30, 33, 36, 39, 42, + 45, 49, 53, 57, 61, 65, 69, 73, + 77, 81, 85, 89, 94, 99, 104, 109, + 114, 119, 124, 129, 134, 140, 146, 152, + 158, 164, 170, 176, 182, 188, 194, 200, + 206, 213, 220, 227, 234, 241, 248, 255, + + 255, 248, 241, 234, 227, 220, 213, 206, + 200, 194, 188, 182, 176, 170, 164, 158, + 152, 146, 140, 134, 129, 124, 119, 114, + 109, 104, 99, 94, 89, 85, 81, 77, + 73, 69, 65, 61, 57, 53, 49, 45, + 42, 39, 36, 33, 30, 27, 24, 22, + 20, 18, 16, 14, 12, 10, 9, 8, + 7, 6, 5, 4, 3, 2, 1, 0, +}; + +const uint8_t side_wave_data_tab[SIDE_WAVE_TAB_LEN]= +{ + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 12, 14, 16, 18, 20, + 22, 23, 24, 25, 27, 28, 30, 31, + 33, 34, 36, 37, 39, 40, 42, 43, + 45, 47, 49, 51, 53, 55, 57, 59, + 61, 63, 65, 76, 69, 71, 73, 75, + 77, 81, 85, 89, 94, 99, 104, 109, + 114, 119, 124, 129, 134, 140, 146, 152, + 158, 164, 170, 176, 182, 188, 194, 200, + 206, 213, 220, 227, 234, 241, 248, 255, + + 255, 248, 241, 234, 227, 220, 213, 206, + 200, 194, 188, 182, 176, 170, 164, 158, + 152, 146, 140, 134, 129, 124, 119, 114, + 109, 104, 99, 94, 89, 85, 81, 77, + 73, 69, 65, 61, 57, 53, 49, 45, + 42, 39, 36, 33, 30, 27, 24, 22, + 20, 18, 16, 14, 12, 10, 9, 8, + 7, 6, 5, 4, 3, 2, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, +}; + +const uint8_t wave_data_tab[WAVE_TAB_LEN]= +{ + 8, 9, 10, 12, 14, 16, 18, 20, + 22, 23, 24, 25, 27, 28, 30, 31, + 33, 34, 36, 37, 39, 40, 42, 43, + 45, 47, 49, 51, 53, 55, 57, 59, + 61, 63, 65, 76, 69, 71, 73, 75, + 77, 81, 85, 89, 94, 99, 104, 109, + 114, 119, 124, 129, 134, 140, 146, 152, + 158, 164, 170, 176, 182, 188, 194, 200, + 206, 213, 220, 227, 234, 241, 248, 255, + + 255, 248, 241, 234, 227, 220, 213, 206, + 200, 194, 188, 182, 176, 170, 164, 158, + 152, 146, 140, 134, 129, 124, 119, 114, + 109, 104, 99, 94, 89, 85, 81, 77, + 73, 69, 65, 61, 57, 53, 49, 45, + 42, 39, 36, 33, 30, 27, 24, 22, + 20, 18, 16, 14, 12, 10, 9, 8, +}; + + + + +const uint8_t flow_tab_1[][3] = +{ + {255, 8, 8}, + {255, 255, 8}, + {8, 255, 8}, + {8, 255, 255}, + {8, 8, 255}, + {255, 8, 255}, +}; + +const uint8_t flow_rainbow_colour_tab[FLOW_COLOUR_TAB_LEN][3]= +{ + {255, 8, 8}, + {255, 8, 8}, + {255, 8, 8}, + {255, 8, 8}, + {255, 10, 8}, + {255, 14, 8}, + {255, 18, 8}, + {255, 22, 8}, + {255, 26, 8}, + {255, 32, 8}, + {255, 38, 8}, + {255, 44, 8}, + {255, 50, 8}, + {255, 57, 8}, + {255, 65, 8}, + {255, 73, 8}, + + {255, 81, 8}, + {255, 89, 8}, + {255, 99, 8}, + {255, 109, 8}, + {255, 119, 8}, + {255, 129, 8}, + {255, 140, 8}, + {255, 152, 8}, + {255, 164, 8}, + {255, 176, 8}, + {255, 188, 8}, + {255, 200, 8}, + {255, 213, 8}, + {255, 227, 8}, + {255, 241, 8}, + {255, 255, 8}, + + {248, 255, 8}, + {234, 255, 8}, + {220, 255, 8}, + {206, 255, 8}, + {194, 255, 8}, + {182, 255, 8}, + {170, 255, 8}, + {158, 255, 8}, + {146, 255, 8}, + {134, 255, 8}, + {124, 255, 8}, + {114, 255, 8}, + {104, 255, 8}, + {94, 255, 8}, + {85, 255, 8}, + {77, 255, 8}, + + {69, 255, 8}, + {61, 255, 8}, + {53, 255, 8}, + {47, 255, 8}, + {41, 255, 8}, + {35, 255, 8}, + {29, 255, 8}, + {24, 255, 8}, + {20, 255, 8}, + {16, 255, 8}, + {12, 255, 8}, + {8, 255, 8}, + {8, 255, 8}, + {8, 255, 8}, + {8, 255, 8}, + {8, 255, 8}, + + {8, 255, 8, }, + {8, 255, 8, }, + {8, 255, 8, }, + {8, 255, 8, }, + {8, 255, 10, }, + {8, 255, 14, }, + {8, 255, 18, }, + {8, 255, 22, }, + {8, 255, 26, }, + {8, 255, 32, }, + {8, 255, 38, }, + {8, 255, 44, }, + {8, 255, 50, }, + {8, 255, 57, }, + {8, 255, 65, }, + {8, 255, 73, }, + + {8, 255, 81, }, + {8, 255, 89, }, + {8, 255, 99, }, + {8, 255, 109,}, + {8, 255, 119,}, + {8, 255, 129,}, + {8, 255, 140 }, + {8, 255, 152 }, + {8, 255, 164,}, + {8, 255, 176, }, + {8, 255, 188,}, + {8, 255, 200,}, + {8, 255, 213,}, + {8, 255, 227,}, + {8, 255, 241,}, + {8, 255, 255,}, + + {8, 248, 255,}, + {8, 234, 255,}, + {8, 220, 255,}, + {8, 206, 255,}, + {8, 194, 255,}, + {8, 182, 255,}, + {8, 170, 255,}, + {8, 158, 255,}, + {8, 146, 255,}, + {8, 134, 255,}, + {8, 124, 255,}, + {8, 114, 255,}, + {8, 104, 255,}, + {8, 94, 255,}, + {8, 85, 255,}, + {8, 77, 255,}, + + {8, 69, 255,}, + {8, 61, 255,}, + {8, 53, 255,}, + {8, 47, 255,}, + {8, 41, 255,}, + {8, 35, 255,}, + {8, 29, 255,}, + {8, 24, 255,}, + {8, 20, 255,}, + {8, 16, 255,}, + {8, 12, 255,}, + {8, 8, 255,}, + {8, 8, 255,}, + {8, 8, 255,}, + {8, 8, 255,}, + {8, 8, 255,}, + + {8, 8, 255,}, + {8, 8, 255,}, + {8, 8, 255,}, + {8, 8, 255,}, + {10, 8, 255,}, + {14, 8, 255,}, + {18, 8, 255,}, + {22, 8, 255,}, + {26, 8, 255,}, + {32, 8, 255,}, + {38, 8, 255,}, + {44, 8, 255,}, + {50, 8, 255,}, + {57, 8, 255,}, + {65, 8, 255,}, + {73, 8, 255,}, + + {81, 8, 255,}, + {89, 8, 255,}, + {99, 8, 255,}, + {109, 8, 255,}, + {119, 8, 255,}, + {129, 8, 255,}, + {140, 8, 255,}, + {152, 8, 255,}, + {164, 8, 255,}, + {176, 8, 255,}, + {188, 8, 255,}, + {200, 8, 255,}, + {213, 8, 255,}, + {227, 8, 255,}, + {241, 8, 255,}, + {255, 8, 255,}, + + {255, 8, 255,}, + {255, 8, 255,}, + {255, 8, 255,}, + {255, 8, 255,}, + {255, 10, 255,}, + {255, 14, 255,}, + {255, 18, 255,}, + {255, 22, 255,}, + {255, 26, 255,}, + {255, 32, 255,}, + {255, 38, 255,}, + {255, 44, 255,}, + {255, 50, 255,}, + {255, 57, 255,}, + {255, 65, 255,}, + {255, 73, 255,}, + + {255, 81, 255,}, + {255, 89, 255,}, + {255, 99, 255,}, + {255, 109, 255,}, + {255, 119, 255,}, + {255, 129, 255,}, + {255, 140, 255,}, + {255, 152, 255,}, + {255, 164, 255,}, + {255, 176, 255,}, + {255, 188, 255,}, + {255, 200, 255,}, + {255, 213, 255,}, + {255, 227, 255,}, + {255, 241, 255,}, + {255, 255, 255,}, + + {255, 248, 248,}, + {255, 234, 234,}, + {255, 220, 220,}, + {255, 206, 206,}, + {255, 194, 194,}, + {255, 182, 182,}, + {255, 170, 170,}, + {255, 158, 158,}, + {255, 146, 146,}, + {255, 134, 134,}, + {255, 124, 124,}, + {255, 114, 114,}, + {255, 104, 104,}, + {255, 94, 94, }, + {255, 85, 85, }, + {255, 77, 77, }, + // + {255, 69, 69, }, + {255, 61, 61, }, + {255, 53, 53, }, + {255, 47, 47, }, + {255, 41, 41, }, + {255, 35, 35, }, + {255, 29, 29, }, + {255, 24, 24, }, + {255, 20, 20, }, + {255, 16, 16, }, + {255, 12, 12, }, + {255, 8, 8, }, + {255, 8, 8, }, + {255, 8, 8, }, + {255, 8, 8, }, + {255, 8, 8, }, + +}; + + +const uint8_t colour_lib[9][3] = +{ + {0xff, 0x00, 0x00}, + {0xff, 0x80, 0x00}, + {0xff, 0xff, 0x00}, + {0x00, 0xff, 0x00}, + {0x00, 0xff, 0xff}, + {0x00, 0x00, 0xff}, + {0x80, 0x00, 0xff}, + {0xc0, 0xc0, 0xff}, + {0x00, 0x00, 0x00}, +}; + diff --git a/keyboards/nuphy/gem80/ansi/sleep.c b/keyboards/nuphy/gem80/ansi/sleep.c new file mode 100644 index 000000000000..3b0f735f94e8 --- /dev/null +++ b/keyboards/nuphy/gem80/ansi/sleep.c @@ -0,0 +1,100 @@ +// Copyright 2023 Persama (@Persama) +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "ansi.h" +#include "hal_usb.h" +#include "usb_main.h" + +extern DEV_INFO_STRUCT dev_info; +extern uint16_t rf_linking_time; +extern uint16_t no_act_time; +extern bool f_goto_sleep; +extern bool f_wakeup_prepare; + +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 uint8_t usb_suspend_debounce; + static bool f_usb_sleep = 0; + + /* 50ms interval */ + if (timer_elapsed32(delay_step_timer) < 50) return; + delay_step_timer = timer_read32(); + + if (f_goto_sleep) { + f_goto_sleep = 0; + + if (dev_info.rf_state == RF_CONNECT) + uart_send_cmd(CMD_SET_CONFIG, 5, 5); + else + uart_send_cmd(CMD_SLEEP, 5, 5); + + setPinOutput(DC_BOOST_PIN); + writePinLow(DC_BOOST_PIN); + + setPinInput(DRIVER_LED_CS_PIN); + setPinInput(DRIVER_SIDE_CS_PIN); + + f_wakeup_prepare = 1; + } else if(f_usb_sleep) { + setPinInput(DRIVER_LED_CS_PIN); + setPinInput(DRIVER_SIDE_CS_PIN); + } else { + setPinOutput(DRIVER_LED_CS_PIN); + writePinLow(DRIVER_LED_CS_PIN); + setPinOutput(DRIVER_SIDE_CS_PIN); + writePinLow(DRIVER_SIDE_CS_PIN); + } + + if (f_wakeup_prepare && (no_act_time < 10)) { + f_wakeup_prepare = 0; + writePinHigh(DC_BOOST_PIN); + + setPinOutput(DRIVER_LED_CS_PIN); + writePinLow(DRIVER_LED_CS_PIN); + setPinOutput(DRIVER_SIDE_CS_PIN); + writePinLow(DRIVER_SIDE_CS_PIN); + + uart_send_cmd(CMD_HAND, 0, 1); + + if (dev_info.link_mode == LINK_USB) { + usb_lld_wakeup_host(&USB_DRIVER); + restart_usb_driver(&USB_DRIVER); + } + } + + if (f_goto_sleep || f_wakeup_prepare) return; + + if (dev_info.link_mode == LINK_USB) { + if (USB_DRIVER.state == USB_SUSPENDED) { + usb_suspend_debounce++; + if (usb_suspend_debounce >= 20) { + f_goto_sleep = 1; + } + } else { + usb_suspend_debounce = 0; + + if (no_act_time >= SLEEP_TIME_DELAY) { + f_usb_sleep = 1; + } else { + f_usb_sleep = 0; + } + } + } else { + f_usb_sleep = 0; + if (dev_info.rf_state == RF_CONNECT) { + if (no_act_time >= SLEEP_TIME_DELAY) { + f_goto_sleep = 1; + } + } else if (rf_linking_time >= LINK_TIMEOUT) { + rf_linking_time = 0; + f_goto_sleep = 1; + } + } + + +}