Skip to content

Commit

Permalink
Reduce the size of the compiled firmware for the ble51 series
Browse files Browse the repository at this point in the history
  • Loading branch information
yangdigi committed Jun 22, 2024
1 parent 7e30db1 commit 9b47ba2
Show file tree
Hide file tree
Showing 138 changed files with 4,738 additions and 2,154 deletions.
76 changes: 10 additions & 66 deletions keyboards/ydkb/ble660c_980c/config.h
Original file line number Diff line number Diff line change
@@ -1,91 +1,35 @@
#pragma once

#include "config_common.h"
#include "config_ble51.h"

/* USB Device descriptor parameter */
#define FW_VER QMK_DM4S
#define FW_VER_VIA VIA_DM4S
#define FW_VER_VIAL VIAL_DMCL
#define FW_VER_DATE DO5U
#define VENDOR_ID 0x9D5B
#define PRODUCT_ID 0x19C1
#define DEVICE_VER 0x0001
#define MANUFACTURER YDKB
#define PRODUCT BLE660C/BLE980C (FW_VER)


/* matrix size */
#define MATRIX_ROWS 7
#define MATRIX_COLS 16



#define TAPPING_TOGGLE 2

#define TAPPING_TERM 200
#define IGNORE_MOD_TAP_INTERRUPT // this makes it possible to do rolling combos (zx) with keys that convert to other keys on hold (z becomes ctrl when you hold it, and when this option isn't enabled, z rapidly followed by x actually sends Ctrl-x. That's bad.)


/* key combination for command */
#define IS_COMMAND() ( \
(get_mods() == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT))) || \
(get_mods() == (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_LCTRL) | MOD_BIT(KC_RSHIFT))) \
)
/* disable command for default layer */
#define MAGIC_KEY_SWITCH_LAYER_WITH_FKEYS 0
#define MAGIC_KEY_SWITCH_LAYER_WITH_NKEYS 0

/* fix space cadet rollover issue */
#define DISABLE_SPACE_CADET_ROLLOVER

#if defined(__AVR_ATmega32U4__) || defined(__AVR_AT90USB1286__)
#define UCSR1D _SFR_MEM8(0xCB)
#define RTSEN 0
#define CTSEN 1

#define SERIAL_UART_BAUD 76800
#define SERIAL_UART_DATA UDR1
#define SERIAL_UART_UBRR ((F_CPU/(8.0*SERIAL_UART_BAUD)-1+0.5))
#define SERIAL_UART_RXD_VECT USART1_RX_vect
#define SERIAL_UART_TXD_READY (UCSR1A&(1<<UDRE1))
#define SERIAL_UART_INIT() do { \
cli(); \
UBRR1L = (uint8_t) SERIAL_UART_UBRR; \
UBRR1H = ((uint16_t)SERIAL_UART_UBRR>>8); \
UCSR1B |= (1<<RXCIE1) | (1<<RXEN1); \
UCSR1B |= (0<<TXCIE1) | (1<<TXEN1); \
UCSR1C |= (0<<UPM11) | (0<<UPM10); \
UCSR1A |= (1<<U2X1); \
sei(); \
} while(0)
#else
#error "USART configuration is needed."
#endif
/* BT Power Control */
#define BT_POWERED (~PORTE & (1<<6))
#define bt_power_init() do { DDRE |= (1<<6); PORTE &= ~(1<<6);} while(0)
#define turn_off_bt() do { PORTE |= (1<<6); UCSR1B &= ~(1<<TXEN1);} while(0)
#define turn_on_bt() do { PORTE &= ~(1<<6); UCSR1B |= (1<<TXEN1);} while(0)
#define bt_power_init() do { DDRE |= (1<<6); PORTE &= ~(1<<6);} while(0)
#define bt_power_reset() do {PORTE |= (1<<6); WAIT_MS(100); PORTE &= ~(1<<6);} while(0)
#define turn_off_bt() do { PORTE |= (1<<6); UCSR1B = (1<<RXCIE1 | 1<<RXEN1); } while(0)
#define turn_on_bt() do { PORTE &= ~(1<<6); if (UCSR1B == (1<<RXCIE1 | 1<<RXEN1)) WAIT_MS(200); UCSR1B = (1<<RXCIE1 | 1<<RXEN1 | 1<<TXEN1); } while(0)

#define BLE_NAME_VARIABLE
#define BLE_BATTERY_SERVICE
#define BT_POWER_SAVE_TIME 3000
#define BLE51_CONSUMER_ON_DELAY 50

#define UPDATE_BATTERY_WHEN_CHARGING
#define BATTERY_CHARGING (~PINE & (1<<2))
#define CHARGING_FIX_VALUE 40
#define CHARGING_FIX_VALUE 50
#define CHARGING_STATE_INIT() do { DDRE &= ~(1<<2); PORTE |= (1<<2);} while(0)
/*
* Feature disable options
* These options are also useful to firmware size reduction.
*/
/* disable debug print */
//#define NO_DEBUG

/* disable print */
//#define NO_PRINT
#define BLE51_CONSUMER_ON_DELAY 50 //scan slower

/* disable action features */
//#define NO_ACTION_LAYER
//#define NO_ACTION_TAPPING
//#define NO_ACTION_ONESHOT
//#define NO_ACTION_MACRO
//#define NO_ACTION_FUNCTION
2 changes: 0 additions & 2 deletions keyboards/ydkb/ble660c_980c/keymaps/vial/config.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#pragma once
#undef PRODUCT
#define PRODUCT BLE660C_980C (FW_VER_VIAL)
#define DYNAMIC_KEYMAP_LAYER_COUNT 3
#define FLASH_KEYMAP_COUNT 2
#define VIAL_KEYBOARD_UID {0x2E, 0xE6, 0x0E, 0x23, 0x34, 0xEF, 0x99, 0x37}
5 changes: 3 additions & 2 deletions keyboards/ydkb/ble660c_980c/keymaps/vial/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ VIA_ENABLE = yes
VIAL_ENABLE = yes
VIAL_INSECURE = yes
QMK_SETTINGS = no
TAP_DANCE_ENABLE = no
COMBO_ENABLE = no
TAP_DANCE_ENABLE = yes
COMBO_ENABLE = yes
KEY_OVERRIDE_ENABLE = no
6 changes: 3 additions & 3 deletions keyboards/ydkb/ble660c_980c/keymaps/vial/vial.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"matrix": {"rows": 7, "cols": 16},
"customKeycodes": [
{"name": "BT/USB", "title": "", "shortName": "BT/USB"},
{"name": "RESET", "title": "", "shortName": "RESET"},
{"name": "BAT%", "title": "", "shortName": "BATT LEVEL"},
{"name": "LkMode", "title": "", "shortName": "LOCK MODE"}
{"name": "BLERST", "title": "", "shortName": "BLERST"},
{"name": "BAT%", "title": "", "shortName": "BAT%"},
{"name": "LkMode", "title": "", "shortName": "LkMode"}
],
"layouts": {
"labels":[["Keyboard", "BLE660C", "BLE980C"]],
Expand Down
48 changes: 26 additions & 22 deletions keyboards/ydkb/ble660c_980c/led_fn.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,51 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

extern bool is_980c;

void led_all_off(void) {
DDRB |= (1<<6 |1<<5);
if (is_980c) {
PORTB &= ~(1<<6 |1<<5);
DDRD |= (1<<7);
PORTD &= ~(1<<7);
} else {
PORTB |= (1<<6 |1<<5);
}
}

#if 0
void led_set_user(uint8_t usb_led)
{
if (is_980c) {
PORTD &= ~(1<<7);
PORTB &= ~(1<<6 | 1<<5);
} else {
PORTB |= (1<<6 | 1<<5);
}

if (usb_led & (1<<USB_LED_NUM_LOCK)) {
if (is_980c) PORTD |= (1<<7);
} else {
if (is_980c) PORTD &= ~(1<<7);
}

if (usb_led & (1<<USB_LED_CAPS_LOCK)) {
if (is_980c) PORTB |= (1<<6);
else PORTB &= ~(1<<5);
} else {
if (is_980c) PORTB &= ~(1<<6);
else PORTB |= (1<<5);
}

if (usb_led & (1<<USB_LED_SCROLL_LOCK)) {
if (is_980c) PORTB |= (1<<5);
else PORTB &= ~(1<<6);
} else {
if (is_980c) PORTB &= ~(1<<5);
else PORTB |= (1<<6);
}
}
#endif

void post_process_record_user(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case USER00:
command_extra(KC_U);
break;
case USER01: //RESET
command_extra(KC_B);
break;
case USER02: //BATTERY LEVEL
command_extra(KC_V);
break;
case USER03: //LOCK MODE
command_extra(KC_L);
break;
}
static const uint8_t userx_to_command[4] = {
KC_U, // 0 Host Switch
KC_B, // 1 Reset
KC_V, // 2 Output Battery Value
KC_L // 3 Lock Mode
};
if (keycode >= USER00 && keycode < USER04) command_extra(userx_to_command[keycode-USER00]);
}
}
Loading

0 comments on commit 9b47ba2

Please sign in to comment.