From f516f5f2df8f04167d67bab61ce06e52af44b45b Mon Sep 17 00:00:00 2001 From: slay-t Date: Tue, 30 Apr 2019 05:14:03 +0900 Subject: [PATCH] [Add keyboard] Add Dozen0 BLE --- keyboards/dozen0_ble/board/custom_board.h | 89 +++++++++++ keyboards/dozen0_ble/config.h | 69 ++++++++ keyboards/dozen0_ble/dozen0_ble.h | 8 + keyboards/dozen0_ble/keymaps/default/keymap.c | 150 ++++++++++++++++++ keyboards/dozen0_ble/ld/nrf52840.ld | 117 ++++++++++++++ keyboards/dozen0_ble/rev1/config.h | 6 + keyboards/dozen0_ble/rev1/pin_assign.h | 53 +++++++ keyboards/dozen0_ble/rev1/rev1.c | 12 ++ keyboards/dozen0_ble/rev1/rev1.h | 19 +++ keyboards/dozen0_ble/rev1/rules.mk | 13 ++ keyboards/dozen0_ble/rules.mk | 36 +++++ 11 files changed, 572 insertions(+) create mode 100644 keyboards/dozen0_ble/board/custom_board.h create mode 100644 keyboards/dozen0_ble/config.h create mode 100644 keyboards/dozen0_ble/dozen0_ble.h create mode 100644 keyboards/dozen0_ble/keymaps/default/keymap.c create mode 100644 keyboards/dozen0_ble/ld/nrf52840.ld create mode 100644 keyboards/dozen0_ble/rev1/config.h create mode 100644 keyboards/dozen0_ble/rev1/pin_assign.h create mode 100644 keyboards/dozen0_ble/rev1/rev1.c create mode 100644 keyboards/dozen0_ble/rev1/rev1.h create mode 100644 keyboards/dozen0_ble/rev1/rules.mk create mode 100644 keyboards/dozen0_ble/rules.mk diff --git a/keyboards/dozen0_ble/board/custom_board.h b/keyboards/dozen0_ble/board/custom_board.h new file mode 100644 index 000000000000..552c21208135 --- /dev/null +++ b/keyboards/dozen0_ble/board/custom_board.h @@ -0,0 +1,89 @@ +/** + * Copyright (c) 2014 - 2017, Nordic Semiconductor ASA + * Copyright (c) 2018, Sekigon + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form, except as embedded into a Nordic + * Semiconductor ASA integrated circuit in a product or a software update for + * such product, must reproduce the above copyright notice, this list of + * conditions and the following disclaimer in the documentation and/or other + * materials provided with the distribution. + * + * 3. Neither the name of Nordic Semiconductor ASA nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * 4. This software, with or without modification, must only be used with a + * Nordic Semiconductor ASA integrated circuit. + * + * 5. Any software provided in binary form under this license must not be reverse + * engineered, decompiled, modified and/or disassembled. + * + * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ +#ifndef CUSTOM_BOARD_H +#define CUSTOM_BOARD_H + +#ifdef __cplusplus +extern "C" { +#endif + +//#include "nrf_gpio.h" + +#define GPIO(port, pin) ((port << 5) | pin) +#define PIN1 GPIO(0,8) +#define PIN2 GPIO(0,11) +#define PIN5 GPIO(0,18) +#define PIN6 GPIO(0,16) +#define PIN7 GPIO(0,19) +#define PIN8 GPIO(0,20) +#define PIN9 GPIO(0,22) +#define PIN10 GPIO(0,23) +#define PIN11 GPIO(1,0) +#define PIN12 GPIO(1,3) + +#define PIN13 GPIO(0,9) +#define PIN14 GPIO(0,10) +#define PIN15 GPIO(1,15) +#define PIN16 GPIO(1,14) +#define PIN17 GPIO(0,3) +#define PIN18 GPIO(0,30) +#define PIN19 GPIO(0,0) +#define PIN20 GPIO(0,5) +//#define NRF_LOG_ENABLED 0 +//#define NRF_LOG_BACKEND_SERIAL_USES_UART 0 +//#define NRF_LOG_BACKEND_SERIAL_UART_TX_PIN 5 +#define NRF_LOG_BACKEND_UART_TX_PIN 8 +//#define DEBUG +// Low frequency clock source to be used by the SoftDevice +#ifdef S210 +// #define NRF_CLOCK_LFCLKSRC NRF_CLOCK_LFCLKSRC_XTAL_20_PPM +#else +#define NRF_CLOCK_LFCLKSRC {.source = NRF_CLOCK_LF_SRC_RC, \ + .rc_ctiv = 16, \ + .rc_temp_ctiv = 2, \ + .xtal_accuracy = 0} +#endif + +#ifdef __cplusplus +} +#endif + +#endif // CUSTOM_BOARD_H diff --git a/keyboards/dozen0_ble/config.h b/keyboards/dozen0_ble/config.h new file mode 100644 index 000000000000..865639f6b0d6 --- /dev/null +++ b/keyboards/dozen0_ble/config.h @@ -0,0 +1,69 @@ +/* +Copyright 2019 yynmt +Copyright 2019 slay-t + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef CONFIG_H +#define CONFIG_H + +/* USB Device descriptor parameter */ +#define VENDOR_ID 0xFEED +#define PRODUCT_ID 0x0000 +#define DEVICE_VER 0x0001 +#define MANUFACTURER yynmt +#define PRODUCT Dozen0 BLE +#define DESCRIPTION 12 keys macropad + +/* key matrix size */ +#define MATRIX_ROWS 1 +#define MATRIX_COLS 12 + +/* COL2ROW, ROW2COL, or CUSTOM_MATRIX */ +#define DIODE_DIRECTION COL2ROW + +/* number of backlight levels */ +//#define BACKLIGHT_LEVELS 3 + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCING_DELAY 5 + +/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ +#define LOCKING_SUPPORT_ENABLE +/* Locking resynchronize hack */ +#define LOCKING_RESYNC_ENABLE + +/* key combination for command */ +#define IS_COMMAND() ( \ + keyboard_report->mods == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)) \ +) + +/* + * Feature disable options + * These options are also useful to firmware size reduction. + */ + +/* disable debug print */ +//#define NO_DEBUG + +/* disable print */ +//#define NO_PRINT + +/* disable action features */ +//#define NO_ACTION_LAYER +//#define NO_ACTION_TAPPING +//#define NO_ACTION_ONESHOT +//#define NO_ACTION_MACRO +//#define NO_ACTION_FUNCTION + +#endif diff --git a/keyboards/dozen0_ble/dozen0_ble.h b/keyboards/dozen0_ble/dozen0_ble.h new file mode 100644 index 000000000000..1a03cfe525b8 --- /dev/null +++ b/keyboards/dozen0_ble/dozen0_ble.h @@ -0,0 +1,8 @@ +#ifndef DOZEN0_BLE_H_ +#define DOZEN0_BLE_H_ + +#include "quantum.h" +#include "rev1.h" + + +#endif /* DOZEN0_BLE_H_ */ diff --git a/keyboards/dozen0_ble/keymaps/default/keymap.c b/keyboards/dozen0_ble/keymaps/default/keymap.c new file mode 100644 index 000000000000..e02220b53b9f --- /dev/null +++ b/keyboards/dozen0_ble/keymaps/default/keymap.c @@ -0,0 +1,150 @@ +/* +Copyright 2018 Sekigon + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#include QMK_KEYBOARD_H +#include "app_ble_func.h" + +enum custom_keycodes { + AD_WO_L = SAFE_RANGE, /* Start advertising without whitelist */ + BLE_DIS, /* Disable BLE HID sending */ + BLE_EN, /* Enable BLE HID sending */ + USB_DIS, /* Disable USB HID sending */ + USB_EN, /* Enable USB HID sending */ + DELBNDS, /* Delete all bonding */ + ADV_ID0, /* Start advertising to PeerID 0 */ + ADV_ID1, /* Start advertising to PeerID 1 */ + ADV_ID2, /* Start advertising to PeerID 2 */ + ADV_ID3, /* Start advertising to PeerID 3 */ + ADV_ID4, /* Start advertising to PeerID 4 */ + BATT_LV, /* Display battery level in milli volts */ + DEL_ID0, /* Delete bonding of PeerID 0 */ + DEL_ID1, /* Delete bonding of PeerID 1 */ + DEL_ID2, /* Delete bonding of PeerID 2 */ + DEL_ID3, /* Delete bonding of PeerID 3 */ + DEL_ID4, /* Delete bonding of PeerID 4 */ + ENT_DFU, /* Start bootloader */ + ENT_SLP, /* Deep sleep mode */ + QWERTY, + COLEMAK, + DVORAK, + LOWER, + RAISE, + ADJUST, + //BACKLIT, + //EISU, + //KANA, + //RGBRST +}; + +extern keymap_config_t keymap_config; + +enum layer_number { + _TWELVE = 0, + _LOWER, +// _RAISE, +}; + +const uint16_t PROGMEM +keymaps[][MATRIX_ROWS][MATRIX_COLS] = { +[_TWELVE] = + +LAYOUT( \ + LCTL(KC_X), LCTL(KC_C), LCTL(KC_V), KC_UP, KC_DEL, KC_BSPC, \ + KC_LCTRL, KC_LSFT, KC_LEFT, KC_DOWN, KC_RIGHT, LT(_LOWER, KC_ENT) \ + + +), +[_LOWER] = +LAYOUT( \ + AD_WO_L, ADV_ID0, ADV_ID1, DEL_ID0, BATT_LV, ENT_SLP, \ + ENT_DFU, USB_DIS, USB_EN, BLE_DIS, BLE_EN, _______ \ + +), + +}; + +bool process_record_user(uint16_t keycode, keyrecord_t *record) { + char str[16]; + + if (record->event.pressed) { + switch (keycode) { + case DELBNDS: + delete_bonds(); + return false; + case AD_WO_L: + restart_advertising_wo_whitelist(); + return false; + case USB_EN: + set_usb_enabled(true); + return false; + break; + case USB_DIS: + set_usb_enabled(false); + return false; + break; + case BLE_EN: + set_ble_enabled(true); + return false; + break; + case BLE_DIS: + set_ble_enabled(false); + return false; + break; + case ADV_ID0: + restart_advertising_id(0); + return false; + case ADV_ID1: + restart_advertising_id(1); + return false; + case ADV_ID2: + restart_advertising_id(2); + return false; + case ADV_ID3: + restart_advertising_id(3); + return false; + case ADV_ID4: + restart_advertising_id(4); + return false; + case DEL_ID0: + delete_bond_id(0); + return false; + case DEL_ID1: + delete_bond_id(1); + return false; + case DEL_ID2: + delete_bond_id(2); + return false; + case DEL_ID3: + delete_bond_id(3); + return false; + case BATT_LV: + sprintf(str, "%4dmV", get_vcc()); + send_string(str); + return false; + case ENT_DFU: + bootloader_jump(); + return false; + } + } else if (!record->event.pressed) { + switch (keycode) { + case ENT_SLP: + sleep_mode_enter(); + return false; + } + } + return true; +}; diff --git a/keyboards/dozen0_ble/ld/nrf52840.ld b/keyboards/dozen0_ble/ld/nrf52840.ld new file mode 100644 index 000000000000..8ce665c0f546 --- /dev/null +++ b/keyboards/dozen0_ble/ld/nrf52840.ld @@ -0,0 +1,117 @@ +/* Linker script to configure memory regions. */ + +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x26000, LENGTH = 0xda000 + RAM (rwx) : ORIGIN = 0x2000BC70, LENGTH = 0x34390 +} + +SECTIONS +{ +} + +SECTIONS +{ + . = ALIGN(16); + .mem_section_dummy_ram : + { + } + .log_dynamic_data : + { + PROVIDE(__start_log_dynamic_data = .); + KEEP(*(SORT(.log_dynamic_data*))) + PROVIDE(__stop_log_dynamic_data = .); + } > RAM + .fs_data : + { + PROVIDE(__start_fs_data = .); + KEEP(*(.fs_data)) + PROVIDE(__stop_fs_data = .); + } > RAM + .cli_sorted_cmd_ptrs : + { + PROVIDE(__start_cli_sorted_cmd_ptrs = .); + KEEP(*(.cli_sorted_cmd_ptrs)) + PROVIDE(__stop_cli_sorted_cmd_ptrs = .); + } > RAM + +} INSERT AFTER .data; + +SECTIONS +{ + .mem_section_dummy_rom : + { + } + .sdh_soc_observers : + { + PROVIDE(__start_sdh_soc_observers = .); + KEEP(*(SORT(.sdh_soc_observers*))) + PROVIDE(__stop_sdh_soc_observers = .); + } > FLASH + .sdh_ble_observers : + { + PROVIDE(__start_sdh_ble_observers = .); + KEEP(*(SORT(.sdh_ble_observers*))) + PROVIDE(__stop_sdh_ble_observers = .); + } > FLASH + .pwr_mgmt_data : + { + PROVIDE(__start_pwr_mgmt_data = .); + KEEP(*(SORT(.pwr_mgmt_data*))) + PROVIDE(__stop_pwr_mgmt_data = .); + } > FLASH + .log_const_data : + { + PROVIDE(__start_log_const_data = .); + KEEP(*(SORT(.log_const_data*))) + PROVIDE(__stop_log_const_data = .); + } > FLASH + .nrf_balloc : + { + PROVIDE(__start_nrf_balloc = .); + KEEP(*(.nrf_balloc)) + PROVIDE(__stop_nrf_balloc = .); + } > FLASH + .sdh_state_observers : + { + PROVIDE(__start_sdh_state_observers = .); + KEEP(*(SORT(.sdh_state_observers*))) + PROVIDE(__stop_sdh_state_observers = .); + } > FLASH + .sdh_stack_observers : + { + PROVIDE(__start_sdh_stack_observers = .); + KEEP(*(SORT(.sdh_stack_observers*))) + PROVIDE(__stop_sdh_stack_observers = .); + } > FLASH + .sdh_req_observers : + { + PROVIDE(__start_sdh_req_observers = .); + KEEP(*(SORT(.sdh_req_observers*))) + PROVIDE(__stop_sdh_req_observers = .); + } > FLASH + .nrf_queue : + { + PROVIDE(__start_nrf_queue = .); + KEEP(*(.nrf_queue)) + PROVIDE(__stop_nrf_queue = .); + } > FLASH + .cli_command : + { + PROVIDE(__start_cli_command = .); + KEEP(*(.cli_command)) + PROVIDE(__stop_cli_command = .); + } > FLASH + .crypto_data : + { + PROVIDE(__start_crypto_data = .); + KEEP(*(SORT(.crypto_data*))) + PROVIDE(__stop_crypto_data = .); + } > FLASH + +} INSERT AFTER .text + +INCLUDE "nrf_common.ld" diff --git a/keyboards/dozen0_ble/rev1/config.h b/keyboards/dozen0_ble/rev1/config.h new file mode 100644 index 000000000000..99cb819dabc6 --- /dev/null +++ b/keyboards/dozen0_ble/rev1/config.h @@ -0,0 +1,6 @@ +#pragma once + +#include "custom_board.h" + +#define ENABLE_STARTUP_ADV_NOLIST +#define IS_LEFT_HAND true diff --git a/keyboards/dozen0_ble/rev1/pin_assign.h b/keyboards/dozen0_ble/rev1/pin_assign.h new file mode 100644 index 000000000000..d74cfcbf34db --- /dev/null +++ b/keyboards/dozen0_ble/rev1/pin_assign.h @@ -0,0 +1,53 @@ +/* + * pin_assign.h + */ + +#pragma once + +#include "custom_board.h" + + +#undef B0 +#undef B1 +#undef B2 +#undef B3 +#undef B4 +#undef B5 +#undef B6 +#undef C6 +#undef D0 +#undef D1 +#undef D2 +#undef D3 +#undef D4 +#undef D7 +#undef E6 +#undef F4 +#undef F5 +#undef F6 +#undef F7 + +#define D3 PIN1 +#define D2 PIN2 +#define D1 PIN5 +#define D0 PIN6 +#define D4 PIN7 +#define C6 PIN8 +#define D7 PIN9 +#define E6 PIN10 +#define B4 PIN11 +#define B5 PIN12 +#define B6 PIN13 +#define B2 PIN14 +#define B3 PIN15 +#define B1 PIN16 +#define F7 PIN17 +#define F6 PIN18 +#define F5 PIN19 +#define F4 PIN20 + +#define THIS_DEVICE_ROWS MATRIX_ROWS +#define THIS_DEVICE_COLS MATRIX_COLS + +#define MATRIX_ROW_PINS { F4 } +#define MATRIX_COL_PINS { B6, B2, B3, B1, F7, F6, B5, B4, E6, D7, C6, D4 } diff --git a/keyboards/dozen0_ble/rev1/rev1.c b/keyboards/dozen0_ble/rev1/rev1.c new file mode 100644 index 000000000000..ac1d02bb1da2 --- /dev/null +++ b/keyboards/dozen0_ble/rev1/rev1.c @@ -0,0 +1,12 @@ +/* + * rev1.c + */ + +#include "matrix.h" +#include "quantum.h" +#include "nrf.h" +#include "app_ble_func.h" + +void matrix_init_user() { + set_usb_enabled(true); +} diff --git a/keyboards/dozen0_ble/rev1/rev1.h b/keyboards/dozen0_ble/rev1/rev1.h new file mode 100644 index 000000000000..d60fb6cdab39 --- /dev/null +++ b/keyboards/dozen0_ble/rev1/rev1.h @@ -0,0 +1,19 @@ +/* + * rev1.h + */ + +#pragma once + +#include "quantum.h" + + +// This a shortcut to help you visually see your layout. +// The first section contains all of the arguements +// The second converts the arguments into a two-dimensional array +#define LAYOUT(\ + K00, K01, K02, K03, K04, K05, \ + K06, K07, K08, K09, K10, K11 \ +) \ +{ \ + { K00, K01, K02, K03, K04, K05, K06, K07, K08, K09, K10, K11 }, \ +} diff --git a/keyboards/dozen0_ble/rev1/rules.mk b/keyboards/dozen0_ble/rev1/rules.mk new file mode 100644 index 000000000000..bb059a9880cb --- /dev/null +++ b/keyboards/dozen0_ble/rev1/rules.mk @@ -0,0 +1,13 @@ + +RGBLIGHT_ENABLE = no + +# it should exist either in /ld/ +MCU_LDSCRIPT = nrf52840 +MCU_SERIES = NRF52840 +NRFSDK_ROOT := $(NRFSDK15_ROOT) #Path to nRF SDK v15.0.0 + +# project specific files +#SRC = matrix.c + +# NRF_SEPARATE = master +#CFLAGS += -DNRF_XTAL_32MHZ \ No newline at end of file diff --git a/keyboards/dozen0_ble/rules.mk b/keyboards/dozen0_ble/rules.mk new file mode 100644 index 000000000000..ab1c2925762e --- /dev/null +++ b/keyboards/dozen0_ble/rules.mk @@ -0,0 +1,36 @@ + +DEFAULT_FOLDER = dozen0_ble/rev1 + +NRF_DEBUG = no + +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = yes # Console for debug +COMMAND_ENABLE = yes # Commands for debug and configuration +SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend +NKRO_ENABLE = no # USB Nkey Rollover +CUSTOM_MATRIX = yes # This flag should be on for nrf52 +TAP_DANCE_ENABLE = no + +## chip/board settings +MCU_FAMILY = NRF52 +# linker script to use +# Cortex version +# Teensy LC is cortex-m0; Teensy 3.x are cortex-m4 +MCU = cortex-m4 +# ARM version, CORTEX-M0/M1 are 6, CORTEX-M3/M4/M7 are 7 +ARMV = 7 +# If you want to be able to jump to bootloader from firmware on STM32 MCUs, +# set the correct BOOTLOADER_ADDRESS. Either set it here, or define it in +# ./bootloader_defs.h or in ./boards//bootloader_defs.h (if you have +# a custom board definition that you plan to reuse). +# If you're not setting it here, leave it commented out. +# It is chip dependent, the correct number can be looked up here (page 175): +# http://www.st.com/web/en/resource/technical/document/application_note/CD00167594.pdf +# This also requires a patch to chibios: +# /tmk_core/tool/chibios/ch-bootloader-jump.patch +#STM32_BOOTLOADER_ADDRESS = 0x1FFFC800 + +# Build Options +# comment out to disable the options. +#