├── .editorconfig ├── .gitattributes ├── .gitignore ├── .gitmodules ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── doc ├── README.md ├── building_on_windows.md ├── building_with_wine.md ├── disable_libinput_debouncing.md ├── doxygen │ ├── doxygen_config │ └── doxygen_layout.xml ├── efm8 │ └── efm_io.md ├── hardware_notes.md ├── hid │ ├── hid_consumer_linux.md │ ├── hid_system_linux.md │ ├── hid_to_linux_input_events.md │ └── hid_to_xkeysym.md ├── imgs │ ├── box.png │ ├── efm8_io.png │ └── keyplus_logo.svg ├── internal_setting_format.md ├── keycodes.md ├── layout_format.md ├── mini-nrf24l01-smd.jpg ├── nrf24_modules.md ├── nrf24lu1p-usb.jpg ├── nrf52 │ └── nrf52_sdk.md ├── porting_from_qmk.md └── supported_hardware.md ├── env ├── .gitignore ├── clean_all_build_dir.sh ├── compile_sdcc.sh ├── enter_env.sh ├── generate_doc.sh ├── test_build.sh └── ubuntu-16.04-setup.sh ├── host-software ├── Pipfile ├── README.md ├── appimage │ ├── .gitignore │ ├── apprun.sh │ ├── build.sh │ ├── keyplus-cli.desktop │ └── keyplus.yml ├── build.bat ├── editor │ ├── editor.py │ ├── key_widgets.py │ └── layouts ├── etc │ ├── libinput │ │ └── local-overrides.quirks │ └── udev │ │ └── rules.d │ │ ├── 50-keyplus.rules │ │ └── 98-silabs.rules ├── hidapi.dll ├── keyplus-cli ├── keyplus.ico ├── keyplus │ ├── __init__.py │ ├── cdata_types.py │ ├── chip_id.py │ ├── constants │ │ ├── __init__.py │ │ ├── error.py │ │ ├── rf.py │ │ ├── scan_mode.py │ │ ├── settings.py │ │ ├── usb.py │ │ └── usb_commands.py │ ├── debug.py │ ├── device_info.py │ ├── error_table.py │ ├── exceptions.py │ ├── hidpp.py │ ├── io_map │ │ ├── __init__.py │ │ ├── common.py │ │ ├── efm8.py │ │ ├── io_mapper.py │ │ ├── mega.py │ │ ├── nrf52.py │ │ ├── virtual.py │ │ └── xmega.py │ ├── keyboard.py │ ├── keycodes │ │ ├── __init__.py │ │ ├── keycode_mapper.py │ │ ├── keycodes.py │ │ ├── lang_map │ │ │ ├── Albanian0.py │ │ │ ├── Arabic0.py │ │ │ ├── Arabic1.py │ │ │ ├── Belarusian0.py │ │ │ ├── Bulgarian0.py │ │ │ ├── Catalan0.py │ │ │ ├── Chinese0.py │ │ │ ├── Croatian0.py │ │ │ ├── Czech0.py │ │ │ ├── Danish0.py │ │ │ ├── Dutch0.py │ │ │ ├── English0.py │ │ │ ├── English1.py │ │ │ ├── English2.py │ │ │ ├── Estonian0.py │ │ │ ├── Finnish0.py │ │ │ ├── French0.py │ │ │ ├── French1.py │ │ │ ├── French2.py │ │ │ ├── French3.py │ │ │ ├── German0.py │ │ │ ├── German1.py │ │ │ ├── Greek0.py │ │ │ ├── Hebrew0.py │ │ │ ├── Hindi0.py │ │ │ ├── Hungarian0.py │ │ │ ├── Icelandic0.py │ │ │ ├── Indonesian0.py │ │ │ ├── Italian0.py │ │ │ ├── Italian1.py │ │ │ ├── Japanese0.py │ │ │ ├── Korean0.py │ │ │ ├── Latvian0.py │ │ │ ├── Lithuanian0.py │ │ │ ├── Macedonian0.py │ │ │ ├── Marathi0.py │ │ │ ├── Norwegian0.py │ │ │ ├── Polish0.py │ │ │ ├── Portuguese0.py │ │ │ ├── Portuguese1.py │ │ │ ├── Romanian0.py │ │ │ ├── Russian0.py │ │ │ ├── Serbian0.py │ │ │ ├── Slovak0.py │ │ │ ├── Slovene0.py │ │ │ ├── Spanish0.py │ │ │ ├── Spanish1.py │ │ │ ├── Swedish0.py │ │ │ ├── Tamil0.py │ │ │ ├── Thai0.py │ │ │ ├── Turkish0.py │ │ │ ├── Ukrainian0.py │ │ │ ├── Vietnamese0.py │ │ │ └── hid_keycodes.py │ │ └── mapped_keycodes.py │ ├── layout │ │ ├── __init__.py │ │ ├── debounce_profiles.py │ │ ├── device.py │ │ ├── ekc_data.py │ │ ├── keyboard_layout.py │ │ ├── layout.py │ │ ├── parser_info.py │ │ ├── rf_settings.py │ │ ├── scan_mode.py │ │ └── user_keycodes.py │ ├── settings.py │ ├── usb_ids.py │ ├── utility │ │ ├── __init__.py │ │ ├── crc16.py │ │ └── round_keys.py │ └── version.py ├── keyplus_flasher.py ├── led │ ├── editor.py │ ├── layouts │ │ ├── 60-percent.json │ │ ├── ansi.json │ │ ├── dox-left.json │ │ ├── dox-right.json │ │ ├── jemini-v5.json │ │ └── ortho_4x6.json │ ├── led_vm.py │ ├── rgb.cl │ ├── rgb_init.cl │ └── sexpr.py ├── setup.py ├── test_api.py └── uniflash │ ├── README.md │ ├── __init__.py │ ├── bootloader.md │ ├── btool.py │ ├── crc16.py │ ├── rf.md │ └── uniflash.py ├── layouts ├── 1key.yaml ├── 32u4_many_rows.yaml ├── 32u4_test.yaml ├── 32u4_test_row_col.yaml ├── 40percent.yaml ├── README.md ├── alpha_split.yaml ├── arbitrary_map_tester.yaml ├── basic_split_test.yaml ├── efm8_1key.yaml ├── efm8_4key.yaml ├── efm8_4x6.yaml ├── matrix_col_tester.yaml ├── matrix_row_tester.yaml ├── nrf52_4key.yaml ├── nrf52_dongle.yaml ├── small_split_test.yaml ├── spectre.yaml ├── split_40.yaml ├── test_rf_config.yaml ├── test_rf_config2.yaml └── virtual.yaml ├── ports ├── atmega32u4 │ ├── Makefile │ ├── README.md │ ├── boards │ │ ├── atmel-dfu │ │ │ └── config.mk │ │ └── default │ │ │ └── config.mk │ ├── bootloaders │ │ ├── atmel_dfu │ │ │ ├── README.md │ │ │ ├── atmel_bootloader.c │ │ │ ├── atmel_bootloader.h │ │ │ └── dfu_driver.S │ │ └── lufa_dfu │ │ │ ├── BootloaderDFU.c │ │ │ ├── BootloaderDFU.h │ │ │ ├── demoapp.c │ │ │ └── makefile │ ├── doxygen.md │ └── src │ │ ├── config.h │ │ ├── flash.c │ │ ├── fuses.c │ │ ├── hardware.c │ │ ├── io_map.c │ │ ├── io_map │ │ ├── avr_port_util.h │ │ └── iom32u4.h │ │ ├── main.c │ │ ├── matrix_scanner.c │ │ ├── port_impl │ │ └── hardware.h │ │ ├── timer.c │ │ ├── usb_32u4.c │ │ ├── usb_32u4.h │ │ ├── usb_descriptors.c │ │ ├── usb_keyboard.c │ │ ├── usb_keyboard.h │ │ ├── usb_reports.c │ │ └── usb_user_impl.h ├── atmega8 │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── aes │ │ ├── aes-min │ │ │ ├── .gitignore │ │ │ ├── LICENSE.txt │ │ │ ├── Makefile.am │ │ │ ├── README.md │ │ │ ├── aes-add-round-key.h │ │ │ ├── aes-decrypt.c │ │ │ ├── aes-encrypt.c │ │ │ ├── aes-inv.c │ │ │ ├── aes-inv.h │ │ │ ├── aes-key-schedule-round.c │ │ │ ├── aes-key-schedule-round.h │ │ │ ├── aes-key-schedule.c │ │ │ ├── aes-min.pc.in │ │ │ ├── aes-mix-columns-inv.c │ │ │ ├── aes-mix-columns.c │ │ │ ├── aes-mix-columns.h │ │ │ ├── aes-mul.c │ │ │ ├── aes-mul.h │ │ │ ├── aes-mul2.h │ │ │ ├── aes-otfks-decrypt.c │ │ │ ├── aes-otfks-encrypt.c │ │ │ ├── aes-print-block.h │ │ │ ├── aes-rotate.h │ │ │ ├── aes-sbox-inv-small.c │ │ │ ├── aes-sbox-inv.c │ │ │ ├── aes-sbox-small.c │ │ │ ├── aes-sbox.c │ │ │ ├── aes-sbox.h │ │ │ ├── aes-shift-rows-inv.c │ │ │ ├── aes-shift-rows.c │ │ │ ├── aes-shift-rows.h │ │ │ ├── aes.h │ │ │ ├── autogen.sh │ │ │ ├── configure.ac │ │ │ ├── python │ │ │ │ ├── ac0254.txt │ │ │ │ ├── gmul.py │ │ │ │ ├── parse-vectors.py │ │ │ │ └── pow254test.py │ │ │ └── tests │ │ │ │ ├── aes-encrypt-test.c │ │ │ │ ├── aes-inv-test.c │ │ │ │ ├── aes-key-schedule-test.c │ │ │ │ ├── aes-sbox-test.c │ │ │ │ ├── aes-test-vectors.h │ │ │ │ └── aes-vectors-test.c │ │ ├── aes.mk │ │ ├── avr-crypto-lib │ │ │ ├── aes.h │ │ │ ├── aes128_dec.c │ │ │ ├── aes128_dec.h │ │ │ ├── aes128_enc.c │ │ │ ├── aes128_enc.h │ │ │ ├── aes192_dec.c │ │ │ ├── aes192_dec.h │ │ │ ├── aes192_enc.c │ │ │ ├── aes192_enc.h │ │ │ ├── aes256_dec.c │ │ │ ├── aes256_dec.h │ │ │ ├── aes256_enc.c │ │ │ ├── aes256_enc.h │ │ │ ├── aes_aleph_enc-asm.S │ │ │ ├── aes_aleph_keyschedule-asm.S │ │ │ ├── aes_dec-asm.S │ │ │ ├── aes_dec-asm_faster.S │ │ │ ├── aes_dec.c │ │ │ ├── aes_dec.h │ │ │ ├── aes_enc-asm.S │ │ │ ├── aes_enc.c │ │ │ ├── aes_enc.h │ │ │ ├── aes_invsbox-asm.S │ │ │ ├── aes_invsbox.c │ │ │ ├── aes_invsbox.h │ │ │ ├── aes_keyschedule-asm.S │ │ │ ├── aes_keyschedule.c │ │ │ ├── aes_keyschedule.h │ │ │ ├── aes_sbox-asm.S │ │ │ ├── aes_sbox.c │ │ │ ├── aes_sbox.h │ │ │ ├── aes_types.h │ │ │ └── avr-asm-macros.S │ │ └── tiny_aes128 │ │ │ ├── Makefile │ │ │ ├── README.md │ │ │ ├── aes.c │ │ │ ├── aes.h │ │ │ ├── test.c │ │ │ └── unlicense.txt │ ├── clock.c │ ├── clock.h │ ├── config.h │ ├── eeprom_map.h │ ├── hardware │ ├── hardware.c │ ├── hardware_user_impl.h │ ├── main.c │ ├── nonce.c │ ├── scan.c │ └── scan.h ├── efm8 │ ├── Makefile │ ├── README.md │ ├── boards │ │ ├── default │ │ │ └── config.mk │ │ ├── efm8ub10_qfn20 │ │ │ └── config.mk │ │ └── efm8ub30_qfn20 │ │ │ └── config.mk │ ├── doxygen.md │ ├── efm8 │ │ ├── boards.mk │ │ ├── efm8.mk │ │ ├── efm8_program.mk │ │ ├── efm8_util │ │ │ ├── delay.c │ │ │ ├── delay.h │ │ │ ├── io.h │ │ │ ├── reset.h │ │ │ ├── uid.h │ │ │ └── watchdog.h │ │ ├── lib │ │ │ ├── efm8_assert │ │ │ │ ├── assert.c │ │ │ │ └── assert.h │ │ │ └── efm8_usb │ │ │ │ ├── Readme.txt │ │ │ │ ├── inc │ │ │ │ └── efm8_usb.h │ │ │ │ └── src │ │ │ │ ├── efm8_usbd.c │ │ │ │ ├── efm8_usbdch9.c │ │ │ │ ├── efm8_usbdep.c │ │ │ │ └── efm8_usbdint.c │ │ ├── mcu │ │ │ ├── C8051F380 │ │ │ │ ├── USBXpress │ │ │ │ │ └── c8051f380_usbxpress.lib │ │ │ │ ├── VCPXpress │ │ │ │ │ ├── VCPXpress.h │ │ │ │ │ └── VCPXpress.lib │ │ │ │ ├── inc │ │ │ │ │ ├── C8051F380.INC │ │ │ │ │ ├── C8051F380_defs.h │ │ │ │ │ ├── SI_C8051F380_Defs.h │ │ │ │ │ ├── SI_C8051F380_Defs.inc │ │ │ │ │ ├── SI_C8051F380_Register_Enums.h │ │ │ │ │ ├── SI_C8051F380_Register_Enums.inc │ │ │ │ │ └── SI_C8051F380_SI_Defs.h │ │ │ │ ├── meta-inf │ │ │ │ │ ├── appbuilder.properties │ │ │ │ │ ├── callbacks.info │ │ │ │ │ ├── layout.properties │ │ │ │ │ └── plugins.info │ │ │ │ └── peripheral_driver │ │ │ │ │ ├── inc │ │ │ │ │ └── usb_0.h │ │ │ │ │ └── src │ │ │ │ │ └── usb_0.c │ │ │ ├── EFM8UB1 │ │ │ │ ├── USBXpress │ │ │ │ │ └── efm8ub1_usbxpress.lib │ │ │ │ ├── VCPXpress │ │ │ │ │ ├── VCPXpress.h │ │ │ │ │ └── VCPXpress.lib │ │ │ │ ├── bsp │ │ │ │ │ └── efm8_memory_lcd │ │ │ │ │ │ ├── spi.c │ │ │ │ │ │ └── tick.c │ │ │ │ ├── inc │ │ │ │ │ ├── SI_EFM8UB1_Defs.h │ │ │ │ │ ├── SI_EFM8UB1_Defs.inc │ │ │ │ │ ├── SI_EFM8UB1_Devices.h │ │ │ │ │ ├── SI_EFM8UB1_Register_Enums.h │ │ │ │ │ └── SI_EFM8UB1_Register_Enums.inc │ │ │ │ └── peripheral_driver │ │ │ │ │ ├── inc │ │ │ │ │ ├── adc_0.h │ │ │ │ │ ├── i2c_0.h │ │ │ │ │ ├── pca_0.h │ │ │ │ │ ├── pwr.h │ │ │ │ │ ├── smb_0.h │ │ │ │ │ ├── spi_0.h │ │ │ │ │ ├── uart_0.h │ │ │ │ │ ├── uart_1.h │ │ │ │ │ ├── usb_0.h │ │ │ │ │ └── wdt_0.h │ │ │ │ │ └── src │ │ │ │ │ ├── adc_0.c │ │ │ │ │ ├── pca_0.c │ │ │ │ │ ├── pwr.c │ │ │ │ │ ├── smb_0.c │ │ │ │ │ ├── spi_0.c │ │ │ │ │ ├── uart_0.c │ │ │ │ │ ├── uart_1.c │ │ │ │ │ ├── usb_0.c │ │ │ │ │ └── wdt_0.c │ │ │ ├── EFM8UB2 │ │ │ │ ├── USBXpress │ │ │ │ │ └── efm8ub2_usbxpress.lib │ │ │ │ ├── VCPXpress │ │ │ │ │ ├── VCPXpress.h │ │ │ │ │ └── VCPXpress.lib │ │ │ │ ├── bsp │ │ │ │ │ └── efm8_memory_lcd │ │ │ │ │ │ ├── spi.c │ │ │ │ │ │ └── tick.c │ │ │ │ ├── inc │ │ │ │ │ ├── SI_EFM8UB2_Defs.h │ │ │ │ │ ├── SI_EFM8UB2_Defs.inc │ │ │ │ │ ├── SI_EFM8UB2_Devices.h │ │ │ │ │ ├── SI_EFM8UB2_Register_Enums.h │ │ │ │ │ └── SI_EFM8UB2_Register_Enums.inc │ │ │ │ └── peripheral_driver │ │ │ │ │ ├── inc │ │ │ │ │ ├── adc_0.h │ │ │ │ │ ├── i2c_0.h │ │ │ │ │ ├── pca_0.h │ │ │ │ │ ├── pwr.h │ │ │ │ │ ├── smb_0.h │ │ │ │ │ ├── spi_0.h │ │ │ │ │ ├── uart_0.h │ │ │ │ │ ├── uart_1.h │ │ │ │ │ ├── usb_0.h │ │ │ │ │ └── wdt_0.h │ │ │ │ │ └── src │ │ │ │ │ ├── adc_0.c │ │ │ │ │ ├── pca_0.c │ │ │ │ │ ├── pwr.c │ │ │ │ │ ├── smb_0.c │ │ │ │ │ ├── spi_0.c │ │ │ │ │ ├── uart_0.c │ │ │ │ │ ├── uart_1.c │ │ │ │ │ ├── usb_0.c │ │ │ │ │ └── wdt_0.c │ │ │ ├── EFM8UB3 │ │ │ │ ├── USBXpress │ │ │ │ │ └── efm8ub3_usbxpress.lib │ │ │ │ ├── VCPXpress │ │ │ │ │ ├── VCPXpress.h │ │ │ │ │ └── VCPXpress.lib │ │ │ │ ├── inc │ │ │ │ │ ├── SI_EFM8UB3_Defs.h │ │ │ │ │ ├── SI_EFM8UB3_Defs.inc │ │ │ │ │ ├── SI_EFM8UB3_Devices.h │ │ │ │ │ ├── SI_EFM8UB3_Register_Enums.h │ │ │ │ │ └── SI_EFM8UB3_Register_Enums.inc │ │ │ │ └── peripheral_driver │ │ │ │ │ ├── inc │ │ │ │ │ ├── adc_0.h │ │ │ │ │ ├── i2c_0.h │ │ │ │ │ ├── pca_0.h │ │ │ │ │ ├── pwr.h │ │ │ │ │ ├── smb_0.h │ │ │ │ │ ├── spi_0.h │ │ │ │ │ ├── uart_0.h │ │ │ │ │ ├── uart_1.h │ │ │ │ │ ├── usb_0.h │ │ │ │ │ └── wdt_0.h │ │ │ │ │ └── src │ │ │ │ │ ├── adc_0.c │ │ │ │ │ ├── pca_0.c │ │ │ │ │ ├── pwr.c │ │ │ │ │ ├── smb_0.c │ │ │ │ │ ├── spi_0.c │ │ │ │ │ ├── uart_0.c │ │ │ │ │ ├── uart_1.c │ │ │ │ │ ├── usb_0.c │ │ │ │ │ └── wdt_0.c │ │ │ └── EFM8UB4 │ │ │ │ ├── inc │ │ │ │ ├── SI_EFM8UB4_Defs.h │ │ │ │ ├── SI_EFM8UB4_Defs.inc │ │ │ │ ├── SI_EFM8UB4_Devices.h │ │ │ │ ├── SI_EFM8UB4_Register_Enums.h │ │ │ │ └── SI_EFM8UB4_Register_Enums.inc │ │ │ │ └── peripheral_driver │ │ │ │ ├── inc │ │ │ │ └── usb_0.h │ │ │ │ └── src │ │ │ │ └── usb_0.c │ │ ├── obj_file.mk │ │ ├── scripts │ │ │ └── hex-size.sh │ │ ├── sdcc.mk │ │ └── si8051Base │ │ │ ├── compiler_defs.h │ │ │ ├── endian.h │ │ │ └── si_toolchain.h │ └── src │ │ ├── common.h │ │ ├── config.h │ │ ├── efm8_config.h │ │ ├── efm8_port_util.c │ │ ├── efm8_port_util.h │ │ ├── hardware.c │ │ ├── io_map │ │ ├── efm8_20_pin.h │ │ ├── efm8_24_pin.h │ │ ├── efm8_32_pin.h │ │ └── efm8_48_pin.h │ │ ├── main.c │ │ ├── matrix_scanner.c │ │ ├── port_impl │ │ ├── flash.c │ │ ├── hardware.c │ │ ├── hardware.h │ │ ├── led.c │ │ ├── timer.c │ │ └── usb_reports.c │ │ ├── usb_defs.h │ │ ├── usb_optional.c │ │ ├── usb_test.c │ │ ├── usb_test.h │ │ ├── usb_user_impl.h │ │ └── usbconfig.h ├── linux │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── etc │ │ ├── modules-load.d │ │ │ └── keyplus.conf │ │ ├── systemd │ │ │ └── system │ │ │ │ └── keyplusd.service │ │ ├── sysusers.d │ │ │ └── keyplusd.conf │ │ └── udev │ │ │ └── rules.d │ │ │ └── 85-keyplusd.rules │ ├── setup.sh │ └── src │ │ ├── cmdline.c │ │ ├── cmdline.h │ │ ├── config.h │ │ ├── debug.h │ │ ├── device_manager.c │ │ ├── device_manager.h │ │ ├── event_codes.c │ │ ├── event_codes.h │ │ ├── event_mapper.c │ │ ├── event_mapper.h │ │ ├── jsmn.h │ │ ├── keyplus_mainloop.c │ │ ├── keyplus_mainloop.h │ │ ├── keyplusd.c │ │ ├── port_impl │ │ ├── flash.c │ │ ├── hardware.c │ │ ├── hardware.h │ │ ├── timer.c │ │ ├── unused.c │ │ └── virtual_report.c │ │ ├── settings_loader.c │ │ ├── settings_loader.h │ │ ├── stats.c │ │ ├── stats.h │ │ ├── stats_parser.c │ │ ├── stats_parser.h │ │ ├── udev_helpers.c │ │ ├── udev_helpers.h │ │ ├── virtual_input.c │ │ └── virtual_input.h ├── nrf24lu1 │ ├── Makefile │ ├── README.md │ ├── bins │ │ ├── nordic_boot24lu1p-f32.hex │ │ ├── nrf24lu1_bootloader-f16.hex │ │ ├── nrf24lu1_bootloader-f32.hex │ │ └── testing-info-page.hex │ ├── boards │ │ ├── 512_bootloader │ │ │ └── config.mk │ │ ├── default │ │ │ └── config.mk │ │ └── unirecv │ │ │ └── config.mk │ ├── doxygen.md │ ├── scripts │ │ ├── flash_hex.sh │ │ ├── hex-size.sh │ │ ├── pretty_hex.sh │ │ ├── sizes.zsh │ │ ├── sort-intel-hex │ │ └── strip_chip_id.sh │ └── src │ │ ├── aes.c │ │ ├── config.h │ │ ├── crtxinit.S │ │ ├── debug.h │ │ ├── descriptors.c │ │ ├── flash.c │ │ ├── hardware.c │ │ ├── led.c │ │ ├── main.c │ │ ├── nonce.c │ │ ├── nrf24.c │ │ ├── nrf24lu1.h │ │ ├── nrf24lu1_usb.h │ │ ├── nrf24lu1_usb_regs.h │ │ ├── port_impl │ │ └── hardware.h │ │ ├── timer.c │ │ ├── usb.c │ │ ├── usb_nrf24lu1.h │ │ ├── usb_reports.c │ │ ├── usb_user_impl.h │ │ └── util.c ├── nrf52 │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── boards │ │ ├── nrf52840_dk │ │ │ ├── board_config.h │ │ │ ├── config.mk │ │ │ ├── led.c │ │ │ └── sdk_config.h │ │ ├── nrf52840_dk_ble │ │ │ ├── board_config.h │ │ │ ├── config.mk │ │ │ ├── gdb_cmds │ │ │ ├── led.c │ │ │ └── sdk_config.h │ │ └── nrf52840_dongle │ │ │ ├── board_config.h │ │ │ ├── config.mk │ │ │ ├── led.c │ │ │ └── sdk_config.h │ ├── gdb_cmds │ ├── ld-scripts │ │ ├── mbr_nrf52840.ld │ │ ├── plain_nrf52840.ld │ │ └── s140_ble.ld │ ├── nrf52.mk │ └── src │ │ ├── ble_test.c │ │ ├── config.h │ │ ├── esb_timeslot.c │ │ ├── esb_timeslot.h │ │ ├── extra │ │ └── fifo.h │ │ ├── io_map │ │ ├── nrf52810.h │ │ ├── nrf52811.h │ │ ├── nrf52832.h │ │ └── nrf52840.h │ │ ├── kp_ble │ │ └── hid.c │ │ ├── main.c │ │ ├── nrf52_esb.c │ │ ├── nrf52_usb.c │ │ ├── nrf52_usb.h │ │ ├── port_impl │ │ ├── aes.c │ │ ├── flash.c │ │ ├── hardware.c │ │ ├── hardware.h │ │ ├── io_map.c │ │ ├── led.c │ │ ├── matrix_scanner.c │ │ ├── nonce.c │ │ ├── nrf24.c │ │ ├── timer.c │ │ └── usb_reports.c │ │ ├── serial_num.c │ │ ├── serial_num.h │ │ └── usb_user_impl.h └── xmega │ ├── .gitignore │ ├── Makefile │ ├── README.md │ ├── boards │ ├── alpha_split │ │ ├── board_config.h │ │ └── config.mk │ ├── default │ │ ├── board_config.h │ │ └── config.mk │ ├── keyplus_mini │ │ ├── board_config.h │ │ └── config.mk │ ├── old_test_board │ │ └── config.mk │ └── plain │ │ ├── board_config.h │ │ └── config.mk │ ├── doxygen.md │ ├── ld-scripts │ ├── README.md │ ├── avrxmega2.xn │ ├── avrxmega4.xn │ ├── avrxmega5.xn │ ├── avrxmega6.xn │ └── avrxmega7.xn │ ├── scripts │ ├── flash_hex.sh │ ├── fuse_hex.sh │ ├── get_fuses.sh │ ├── prod_flash.sh │ └── prod_loop.sh │ └── src │ ├── aes.c │ ├── avr_util.h │ ├── config.h │ ├── debug.c │ ├── descriptors.c │ ├── dual_usb.c │ ├── dual_usb.h │ ├── eeprom_map.h │ ├── fuses.c │ ├── hardware.c │ ├── io_map │ ├── xio100.h │ ├── xio44.h │ └── xio64.h │ ├── led_vm.c │ ├── led_vm.h │ ├── main.c │ ├── matrix_scanner.c │ ├── nrf24.c │ ├── port_impl │ ├── flash.c │ ├── hardware.h │ ├── io_map.c │ ├── led.c │ └── timer.c │ ├── power.c │ ├── power.h │ ├── usb_reports.c │ ├── usb_user_impl.h │ ├── wired.c │ ├── wired.h │ ├── ws2812.c │ ├── ws2812.h │ ├── ws2812_config.h │ ├── xmega_hardware.h │ ├── xmega_hardware │ ├── aes.c │ ├── aes.h │ ├── avr_compiler.h │ ├── twi_example.c │ ├── twi_master_driver.c │ ├── twi_master_driver.h │ ├── twi_slave_driver.c │ ├── twi_slave_driver.h │ └── xmega_hardware.mk │ └── xusb │ ├── makefile │ ├── usb.h │ ├── usb_requests.c │ ├── usb_standard.h │ └── xmega │ ├── makefile │ ├── usb_xmega.c │ ├── usb_xmega.h │ └── usb_xmega_internal.h └── src ├── arch ├── 8051 │ └── hardware.h ├── README.md ├── arm │ └── armgcc.mk └── avr │ ├── avr.mk │ ├── eeprom_map.h │ ├── matrix_scanner.h │ └── nonce.c ├── boards.mk ├── core ├── README.md ├── aes.h ├── bootloader.h ├── chip_id.h ├── core.mk ├── crc.c ├── crc.h ├── debug.h ├── error.c ├── error.h ├── flash.c ├── flash.h ├── hardware.c ├── hardware.h ├── hidpp20.h ├── io_map.c ├── io_map.h ├── keycode.c ├── keycode.h ├── layout.c ├── layout.h ├── led.c ├── led.h ├── macro.c ├── macro.h ├── matrix_interpret.c ├── matrix_interpret.h ├── matrix_scanner.c ├── matrix_scanner.h ├── mods.c ├── mods.h ├── mouse.c ├── mouse.h ├── nonce.c ├── nonce.h ├── nrf24.c ├── nrf24.h ├── nrf24_registers.h ├── nrf52_esb.h ├── packet.c ├── packet.h ├── rf.c ├── rf.h ├── ring_buf.c ├── ring_buf.h ├── settings.c ├── settings.h ├── timer.h ├── unifying.c ├── unifying.h ├── usb_commands.c ├── usb_commands.h ├── util.c ├── util.h └── version.h ├── doxygen_main_page.md ├── hid_reports ├── README.md ├── ble_reports.h ├── hid_reports.c ├── hid_reports.h ├── hid_reports.mk ├── keyboard_report.c ├── keyboard_report.h ├── media_report.c ├── media_report.h ├── mouse_report.c ├── mouse_report.h ├── usb_reports.h ├── vendor_report.c ├── vendor_report.h └── virtual_reports.h ├── key_handlers ├── README.md ├── key_custom.c ├── key_custom.h ├── key_handlers.c ├── key_handlers.h ├── key_handlers.mk ├── key_hold.c ├── key_hold.h ├── key_macro.c ├── key_macro.h ├── key_media.c ├── key_media.h ├── key_mouse.c ├── key_mouse.h ├── key_normal.c ├── key_normal.h ├── key_tap.c └── key_tap.h ├── keyplus.mk ├── kp_ble └── hid.h ├── obj_file.mk └── usb ├── README.md ├── common.h ├── desc ├── common.h ├── compact │ ├── descriptors.c │ ├── descriptors.h │ └── hid_descriptors.c └── normal │ ├── descriptors.c │ ├── descriptors.h │ └── hid_descriptors.c ├── descriptors.h ├── usb.mk └── util ├── descriptor_defs.h ├── hut_consumer.h ├── hut_desktop.h ├── hut_keyboard.h ├── hut_led.h ├── requests.h ├── usb_hid.h └── webusb.h /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | insert_final_newline = true 9 | indent_style = space 10 | indent_size = 4 11 | trim_trailing_whitespace = true 12 | 13 | [*.{c,cpp,h}] 14 | indent_style = space 15 | indent_size = 4 16 | 17 | # 2 space indentation 18 | [*.yaml] 19 | indent_style = space 20 | indent_size = 2 21 | 22 | # 4 space indentation 23 | [*.{py,sh}] 24 | indent_style = space 25 | indent_size = 4 26 | 27 | # 8 tab indent 28 | [*.S] 29 | indent_style = tab 30 | indent_size = 8 31 | 32 | # 4 tab indentation 33 | [{Makefile, *.mk}] 34 | indent_style = tab 35 | indent_size = 4 36 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.h linguist-language=C 2 | *.c linguist-language=C 3 | ports/efm8/efm8/mcu/* linguist-vendored 4 | ports/efm8/efm8/lib/* linguist-vendored 5 | ports/efm8/efm8/si8051Base/* linguist-vendored 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.lst 2 | *.hex 3 | *.pyc 4 | *.fuse 5 | *.spec 6 | *.egg-info 7 | build$ 8 | !build.sh 9 | dist 10 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "src/arch/avr/avr-makefile"] 2 | path = src/arch/avr/avr-makefile 3 | url = https://github.com/ahtn/avr-makefile 4 | remote = master 5 | [submodule "ports/atmega32u4/bootloaders/kp_boot_32u4"] 6 | path = ports/atmega32u4/bootloaders/kp_boot_32u4 7 | url = https://github.com/ahtn/kp_boot_32u4 8 | remote = master 9 | [submodule "ports/xmega/xusb-boot"] 10 | path = ports/xmega/xusb-boot 11 | url = https://github.com/ahtn/xusb-boot 12 | [submodule "ports/nrf24lu1/nrf24lu1p-512-bootloader"] 13 | path = ports/nrf24lu1/nrf24lu1p-512-bootloader 14 | url = https://github.com/ahtn/nrf24lu1p-512-bootloader 15 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | matrix: 2 | include: 3 | - os: linux 4 | sudo: true 5 | dist: xenial 6 | language: c 7 | addons: 8 | apt: 9 | packages: 10 | - make 11 | - python 12 | - libpython-dev 13 | - libffi-dev 14 | - python3 15 | - python3-pip 16 | - libhidapi-hidraw0 17 | - python3-venv 18 | - desktop-file-utils 19 | - libevdev-dev 20 | - libudev-dev 21 | # before_install: 22 | # - 23 | install: 24 | - 'cd env' 25 | - './ubuntu-16.04-setup.sh' 26 | - 'cd ..' 27 | script: 28 | # Setup the build environment 29 | - 'source env/enter_env.sh' 30 | # Run the test builds 31 | - 'env/test_build.sh' 32 | # after_success: 33 | # - echo "After_Success" 34 | 35 | # vim:sw=2: 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 jem@seethis.link 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is furnished to do 10 | so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Documentation Index 3 | 4 | ## Layout 5 | 6 | * [Layout file format](layout_format.md) 7 | * [Keycode documentation](keycodes.md) 8 | * [Porting from QMK](porting_from_qmk.md) 9 | 10 | ## Build instructions 11 | 12 | * [Building with xmega](../ports/xmega/README.md) 13 | * [Building with atmega32u4](../ports/atmega32u4/README.md) 14 | * [Building with efm8](../ports/efm8/README.md) 15 | 16 | * [Building `keyplus_flasher` for Windows](building_on_windows.md) 17 | * [Building `keyplus_flasher` with Wine](building_with_wine.md) 18 | 19 | ## Hardware 20 | 21 | * [Hardware notes](hardware_notes.md) 22 | * [Supported hardware](supported_hardware.md) 23 | * [nRF24 modules](nrf24_modules.md) 24 | 25 | ### EFM8 26 | * [EFM8 IO configuration](efm8/efm_io.md) 27 | -------------------------------------------------------------------------------- /doc/building_on_windows.md: -------------------------------------------------------------------------------- 1 | ## Building keyplus flasher on Windows 2 | 3 | Install python3.5, then run the following command from the `host-software` directory of the repo: 4 | 5 | ```batch 6 | C:\Python27\Scripts\pip install -U keyplus pyqt5 pyinstaller 7 | build.bat 8 | ``` 9 | -------------------------------------------------------------------------------- /doc/disable_libinput_debouncing.md: -------------------------------------------------------------------------------- 1 | # Disabling libinput button debouncing for a device on Linux 2 | 3 | The [libinput library provise software button debouncing]( 4 | https://wayland.freedesktop.org/libinput/doc/latest/button-debouncing.html) 5 | on Linux. However, this can sometimes cause issues when running macros on 6 | devices. It's possible do disable this feature for a device using [device 7 | quirks](https://wayland.freedesktop.org/libinput/doc/latest/device-quirks.html). 8 | 9 | To disable software debouncing on a keyplus device create, create the file 10 | [`/etc/libinput/local-overrides.quirks`](../host-software/etc/libinput) 11 | with the following contents. 12 | 13 | ``` 14 | [keyplus mouse] 15 | MatchUdevType=mouse 16 | MatchBus=usb 17 | MatchVendor=0x1209 18 | MatchProduct=0xBB00 19 | ModelBouncingKeys=1 20 | 21 | [keyplus keyboard] 22 | MatchUdevType=keyboard 23 | MatchBus=usb 24 | MatchVendor=0x1209 25 | MatchProduct=0xBB00 26 | ModelBouncingKeys=1 27 | ``` 28 | 29 | Then run `sudo udevadm hwdb --update` and reboot the system for the settings 30 | to take effect. 31 | -------------------------------------------------------------------------------- /doc/hid/hid_system_linux.md: -------------------------------------------------------------------------------- 1 | # Supported events in the Desktop HID Usage Table 2 | 3 | Supported events: 4 | Event type 0 (EV_SYN) 5 | Event type 1 (EV_KEY) 6 | Event code 103 (KEY_UP) 7 | Event code 105 (KEY_LEFT) 8 | Event code 106 (KEY_RIGHT) 9 | Event code 108 (KEY_DOWN) 10 | Event code 116 (KEY_POWER) 11 | Event code 138 (KEY_HELP) 12 | Event code 139 (KEY_MENU) 13 | Event code 142 (KEY_SLEEP) 14 | Event code 143 (KEY_WAKEUP) 15 | Event code 148 (KEY_PROG1) 16 | Event code 174 (KEY_EXIT) 17 | Event code 227 (KEY_SWITCHVIDEOMODE) 18 | Event code 353 (KEY_SELECT) 19 | Event code 356 (KEY_POWER2) 20 | Event code 408 (KEY_RESTART) 21 | Event code 438 (KEY_CONTEXT_MENU) 22 | Event type 3 (EV_ABS) 23 | Event code 40 (ABS_MISC) 24 | Value 0 25 | Min 1 26 | Max 183 27 | Event type 4 (EV_MSC) 28 | Event code 4 (MSC_SCAN) 29 | 0x81: ABS_MISC 30 | 0x81: KEY_POWER 31 | 0x82: KEY_SLEEP 32 | 0x83: KEY_WAKEUP 33 | 0x84: KEY_CONTEXT_MENU 34 | 0x85: KEY_MENU 35 | 0x86: KEY_PROG1 36 | 0x87: KEY_HELP 37 | 0x88: KEY_EXIT 38 | 0x89: KEY_SELECT 39 | 0x8a: KEY_RIGHT 40 | 0x8b: KEY_LEFT 41 | 0x8c: KEY_UP 42 | 0x8d: KEY_DOWN 43 | 0x8e: KEY_POWER2 44 | 0x8f: KEY_RESTART 45 | 0xb5: KEY_SWITCHVIDEOMODE 46 | -------------------------------------------------------------------------------- /doc/imgs/box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/doc/imgs/box.png -------------------------------------------------------------------------------- /doc/imgs/efm8_io.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/doc/imgs/efm8_io.png -------------------------------------------------------------------------------- /doc/internal_setting_format.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | All the key layout information is contained in two key segments: 4 | 5 | 1. Settings block (512 bytes) 6 | 2. Layout block (variable) 7 | 8 | ## Settings 9 | 10 | ## Layout 11 | The layout is stored 12 | ### Key num map 13 | `key_num_map_size = g_scan_plan.rows * (g_scan_plan.max_col_pin_num+1)` 14 | 15 | ### External keycode table 16 | `` 17 | ### Layout table 18 | #### Layout header 19 | #### Layout data 20 | -------------------------------------------------------------------------------- /doc/mini-nrf24l01-smd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/doc/mini-nrf24l01-smd.jpg -------------------------------------------------------------------------------- /doc/nrf24lu1p-usb.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/doc/nrf24lu1p-usb.jpg -------------------------------------------------------------------------------- /doc/supported_hardware.md: -------------------------------------------------------------------------------- 1 | # Supported hardware 2 | 3 | ## Fully supported 4 | 5 | MCUs in this category support all the latest and greatest features of keyplus. 6 | 7 | * ATxmega32a4u (recommended) 8 | * keyplus mini 9 | * ATxmega32/64/128 10 | * nRF24LU1+ 11 | * Logitech Unifying Receiver 12 | 13 | ## Partial support 14 | 15 | These MCUs may not support all the features of keyplus. 16 | See the linked issue to find out more. 17 | 18 | * [ATmega32u4](https://github.com/ahtn/keyplus/issues/27) 19 | * [EFM8](https://github.com/ahtn/keyplus/issues/26) 20 | 21 | ## Planned support 22 | 23 | There are plans to begin work for these MCUs sometime in the future. 24 | 25 | * ATmega32u2 26 | * AT90USB1286 27 | * [nRF52840](https://github.com/ahtn/keyplus/issues/28) 28 | 29 | ## Legacy 30 | 31 | These MCUs were supported in the past but are no longer maintained. 32 | 33 | * ATmegaXX8p(a) 34 | -------------------------------------------------------------------------------- /env/.gitignore: -------------------------------------------------------------------------------- 1 | avr* 2 | sdcc-* 3 | gcc-arm-none-eabi-* 4 | nRF5_SDK_* 5 | -------------------------------------------------------------------------------- /env/clean_all_build_dir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | TARGETS="atmega32u4 xmega nrf24lu1 efm8 nrf52 linux" 4 | 5 | for target in $TARGETS; do 6 | rm -fr ports/$target/build 7 | done 8 | -------------------------------------------------------------------------------- /env/generate_doc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Test building the documentation 4 | doxygen doc/doxygen/doxygen_config 5 | 6 | if [[ -z $1 ]]; then 7 | xdg-open build/doc/html/index.html 8 | fi 9 | -------------------------------------------------------------------------------- /host-software/Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | "e1839a8" = {path = ".", editable = true} 8 | "3076366" = {path = "./../../python-efm8boot", editable = true} 9 | "0c43736" = {path = "./../../python-easyhid", editable = true} 10 | 11 | [dev-packages] 12 | 13 | [requires] 14 | python_version = "3.6" 15 | -------------------------------------------------------------------------------- /host-software/README.md: -------------------------------------------------------------------------------- 1 | 2 | Python dependencies 3 | 4 | ``` 5 | PySide pyyaml cffi hexdump intelhex 6 | ``` 7 | 8 | Other dependencies: hidapi 9 | 10 | ## GUI programming tool 11 | 12 | To run the GUI programming tool 13 | ``` 14 | ./keyplus_flasher.py 15 | ``` 16 | 17 | ## Command line tool 18 | 19 | A command line tool to control keyplus devices is also provided. For a list of 20 | avaliable commands run 21 | 22 | ``` 23 | ./keyplus_cli.py -h 24 | ``` 25 | 26 | Program a device with the given serial number: 27 | ``` 28 | ./keyplus_cli.py program --serial 5W162 --layout layout_file.yaml 29 | ``` 30 | 31 | Program a device giving it a new device id: 32 | ``` 33 | ./keyplus_cli.py program --new-id 11 --layout layout_file.yaml --rf rf_file.yaml 34 | ``` 35 | Note since we didn't give a serial number, device id, etc. this command would 36 | attempt to program any connected device. 37 | -------------------------------------------------------------------------------- /host-software/appimage/.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | pkg2appimage 3 | keyplus-cli 4 | -------------------------------------------------------------------------------- /host-software/appimage/apprun.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export APPDIR="$(dirname "$(readlink -f "$0")")" 4 | export PATH="$APPDIR/usr/bin/:$PATH" 5 | export LD_LIBRARY_PATH="$APPDIR/usr/lib:$APPDIR/usr/lib/x86_64-linux-gnu:$PATH" 6 | export XDG_DATA_DIRS="$APPDIR/usr/share/:/usr/share/:$XDG_DATA_DIRS" 7 | export PYTHONPATH="$APPDIR/ENV/lib/python3.5/site-packages" 8 | 9 | # source "$APPDIR/ENV/bin/activate" 10 | python3 "$APPDIR/ENV/bin/keyplus-cli" "$@" 11 | -------------------------------------------------------------------------------- /host-software/appimage/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git clone https://github.com/AppImage/pkg2appimage 4 | 5 | bash -ex ./pkg2appimage/pkg2appimage ./keyplus.yml 6 | -------------------------------------------------------------------------------- /host-software/appimage/keyplus-cli.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Type=Application 3 | Name=keyplus-cli 4 | Icon=keyplus-cli 5 | Exec=python3 bin/keyplus-cli 6 | Comment=A tool for controlling keyplus keyboards 7 | Categories=Utility; 8 | Keywords=Python;keyboard;flasher; 9 | -------------------------------------------------------------------------------- /host-software/build.bat: -------------------------------------------------------------------------------- 1 | :: Need `pip3 install pyinstaller` 2 | 3 | :: Need to set this to the python3 Scripts directory where pyinstaller.exe is 4 | set pyscripts=%USERPROFILE%\local\Python36-32\Scripts\ 5 | 6 | %pyscripts%\pyinstaller -w --onefile --add-data="hidapi.dll;." --icon keyplus.ico keyplus_flasher.py 7 | -------------------------------------------------------------------------------- /host-software/editor/layouts: -------------------------------------------------------------------------------- 1 | ../led/layouts -------------------------------------------------------------------------------- /host-software/etc/libinput/local-overrides.quirks: -------------------------------------------------------------------------------- 1 | # Run this command to update 2 | # sudo udevadm hwdb --update 3 | # reboot 4 | 5 | [keyplus mouse] 6 | MatchUdevType=mouse 7 | MatchBus=usb 8 | MatchVendor=0x1209 9 | MatchProduct=0xBB00 10 | ModelBouncingKeys=1 11 | 12 | [keyplus keyboard] 13 | MatchUdevType=keyboard 14 | MatchBus=usb 15 | MatchVendor=0x1209 16 | MatchProduct=0xBB00 17 | ModelBouncingKeys=1 18 | -------------------------------------------------------------------------------- /host-software/hidapi.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/host-software/hidapi.dll -------------------------------------------------------------------------------- /host-software/keyplus.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/host-software/keyplus.ico -------------------------------------------------------------------------------- /host-software/keyplus/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | from keyplus.constants import * 8 | from keyplus.keyboard import KeyplusKeyboard, find_devices 9 | from keyplus.version import __version__ 10 | -------------------------------------------------------------------------------- /host-software/keyplus/constants/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | from keyplus.constants.error import * 8 | from keyplus.constants.rf import * 9 | from keyplus.constants.scan_mode import * 10 | from keyplus.constants.settings import * 11 | from keyplus.constants.usb import * 12 | from keyplus.constants.usb_commands import * 13 | -------------------------------------------------------------------------------- /host-software/keyplus/constants/rf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | PWR_NEG_18DB = 0x00 8 | PWR_NEG_12DB = 0x01 9 | PWR_NEG_6DB = 0x02 10 | PWR_0DB = 0x03 11 | 12 | POWER_STR_MAP = { 13 | PWR_NEG_18DB: "-18dB", 14 | PWR_NEG_12DB: "-12dB", 15 | PWR_NEG_6DB: "-6dB", 16 | PWR_0DB: "0dB", 17 | } 18 | 19 | RF_DR_LOW = 5 20 | RF_DR_HIGH = 3 21 | RF_DR_250KBPS = (1 << RF_DR_LOW) 22 | RF_DR_1MBPS = 0 23 | RF_DR_2MBPS = (1 << RF_DR_HIGH) 24 | 25 | DATA_RATE_STR_MAP = { 26 | RF_DR_250KBPS: "250kbps", 27 | RF_DR_1MBPS: "1mbps", 28 | RF_DR_2MBPS: "2mbps", 29 | } 30 | -------------------------------------------------------------------------------- /host-software/keyplus/constants/scan_mode.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | MATRIX_SCANNER_MODE_NO_MATRIX = 0x00 8 | MATRIX_SCANNER_MODE_COL_ROW = 0x01 9 | MATRIX_SCANNER_MODE_ROW_COL = 0x02 10 | MATRIX_SCANNER_MODE_PIN_GND = 0x03 11 | MATRIX_SCANNER_MODE_PIN_VCC = 0x04 12 | MATRIX_SCANNER_MODE_VIRTUAL = 0x05 13 | 14 | SCAN_MODE_STR_MAP = { 15 | MATRIX_SCANNER_MODE_NO_MATRIX: "none", 16 | MATRIX_SCANNER_MODE_COL_ROW: "diodes column to row", 17 | MATRIX_SCANNER_MODE_ROW_COL: "diodes row to column", 18 | MATRIX_SCANNER_MODE_PIN_GND: "pin_gnd", 19 | MATRIX_SCANNER_MODE_PIN_VCC: "pin_vcc", 20 | MATRIX_SCANNER_MODE_VIRTUAL: "virtual", 21 | } 22 | 23 | INVALID_KEY_NUMBER = 0xff 24 | 25 | def is_valid_scan_mode(mode): 26 | return mode in SCAN_MODE_STR_MAP 27 | 28 | def scan_mode_to_str(mode): 29 | if mode in SCAN_MODE_STR_MAP: 30 | return SCAN_MODE_STR_MAP[mode] 31 | else: 32 | return "Unknown({})".format(mode) 33 | -------------------------------------------------------------------------------- /host-software/keyplus/constants/usb.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | # TODO: might need to make this data device dependant since the efm8 port 8 | # might need to use a different endpoint configuration 9 | TYPE0_INTERFACE_BOOT_KEYBOARD = 0 10 | TYPE0_INTERFACE_MOUSE = 1 11 | TYPE0_INTERFACE_MEDIA = 2 12 | TYPE0_INTERFACE_VENDOR = 3 13 | TYPE0_INTERFACE_NKRO_KEYBOARD = 4 14 | 15 | TYPE1_INTERFACE_BOOT_KEYBOARD = 0 16 | TYPE1_INTERFACE_SHARED_HID = 1 17 | TYPE1_INTERFACE_VENDOR = 2 18 | 19 | USB_VERSION_ACCESS_TYPE_bp = (12) 20 | USB_VERSION_ACCESS_TYPE_MASK = (0xf000) 21 | USB_VERSION_HID_INTERFACE_3 = (0 << USB_VERSION_ACCESS_TYPE_bp) # TYPE0 22 | USB_VERSION_HID_INTERFACE_2 = (1 << USB_VERSION_ACCESS_TYPE_bp) # TYPE1 23 | # USB_VERSION_HID_INTERFACE_1 = (2 << USB_VERSION_ACCESS_TYPE_bp) 24 | # USB_VERSION_HID_INTERFACE_0 = (3 << USB_VERSION_ACCESS_TYPE_bp) 25 | -------------------------------------------------------------------------------- /host-software/keyplus/debug.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | from keyplus.version import __version__ 8 | 9 | IS_PRE_RELASE = ('pre' in __version__) 10 | 11 | class DEBUG(object): 12 | """ 13 | The static variables in this class can be used to turn on and off debug 14 | messages. 15 | """ 16 | usb_cmd_timing = False and IS_PRE_RELASE 17 | usb_cmd = False and IS_PRE_RELASE 18 | parsing = False and IS_PRE_RELASE 19 | parsing_extra = False and IS_PRE_RELASE 20 | layout = True and IS_PRE_RELASE 21 | gui = True and IS_PRE_RELASE 22 | misc = True and IS_PRE_RELASE 23 | -------------------------------------------------------------------------------- /host-software/keyplus/io_map/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | # from keyplus.io_map.common import * 8 | # from keyplus.io_map.chip_id import * 9 | # from keyplus.io_map.io_mapper import get_io_mapper_for_chip 10 | -------------------------------------------------------------------------------- /host-software/keyplus/io_map/io_mapper.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | import keyplus.io_map.xmega 8 | import keyplus.io_map.mega 9 | import keyplus.io_map.efm8 10 | import keyplus.io_map.nrf52 11 | import keyplus.io_map.virtual 12 | import keyplus.chip_id 13 | 14 | from keyplus.exceptions import KeyplusSettingsError 15 | 16 | IO_MAPPER_LOOKUP_TABLE = { 17 | 'AVR_XMEGA' : keyplus.io_map.xmega.IoMapperXmega, 18 | 'AVR_MEGA' : keyplus.io_map.mega.IoMapperAVRMega, 19 | 'EFM8' : keyplus.io_map.efm8.IoMapperEFM8, 20 | 'nRF52' : keyplus.io_map.nrf52.IoMapperNRF52, 21 | 'virtual' : keyplus.io_map.virtual.IoMapperVirtual, 22 | } 23 | 24 | def get_io_mapper_for_chip(chip_id): 25 | chip = keyplus.chip_id.lookup_chip_id(chip_id) 26 | if chip.architecture in IO_MAPPER_LOOKUP_TABLE: 27 | return IO_MAPPER_LOOKUP_TABLE[chip.architecture](chip_id) 28 | else: 29 | return None 30 | 31 | -------------------------------------------------------------------------------- /host-software/keyplus/io_map/mega.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | import keyplus.chip_id 7 | 8 | from keyplus.io_map.common import PinMap, IoMapperAVR 9 | 10 | AVRMegaU4 = PinMap( 11 | ports = { 12 | 'B': 0, 13 | 'C': 1, 14 | 'D': 2, 15 | 'E': 3, 16 | 'F': 4, 17 | }, 18 | pins = [ 19 | 0xff, 20 | 0xc0, 21 | 0xff, 22 | 0x44, 23 | 0xf3, 24 | ], 25 | gpio_count = 26, 26 | default_rows = [ 27 | ], 28 | default_cols = [ 29 | ], 30 | port_size = 8 31 | ) 32 | 33 | class IoMapperAVRMega(IoMapperAVR): 34 | AVR_MEGA_SERIES_TABLE = { 35 | 'U2': None, 36 | 'U4': AVRMegaU4, 37 | 'U6': None, # same as A series 38 | } 39 | 40 | def __init__(self, chip_id): 41 | super(IoMapperAVRMega, self).__init__() 42 | self.chip_info = keyplus.chip_id.lookup_chip_id(chip_id) 43 | 44 | assert(self.chip_info != None) 45 | assert(self.chip_info.architecture == 'AVR_MEGA') 46 | assert(self.chip_info.series in self.AVR_MEGA_SERIES_TABLE) 47 | self.pin_map = IoMapperAVRMega.AVR_MEGA_SERIES_TABLE[self.chip_info.series] 48 | -------------------------------------------------------------------------------- /host-software/keyplus/io_map/nrf52.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | import keyplus.chip_id 7 | 8 | from keyplus.io_map.common import PinMap, IoMapperNumbered 9 | 10 | NRF52_48GPIO = PinMap( 11 | ports = { 12 | 'P0': 0, 13 | 'P1': 1, 14 | }, 15 | pins = [ 16 | 0xffffffff, 17 | 0x0000ffff, 18 | ], 19 | gpio_count = 48, 20 | port_size = 32 21 | ) 22 | 23 | class IoMapperNRF52(IoMapperNumbered): 24 | PIN_MAP_TABLE = { 25 | 73: NRF52_48GPIO, 26 | 93: NRF52_48GPIO, 27 | } 28 | 29 | def __init__(self, chip_id): 30 | super(IoMapperNRF52, self).__init__() 31 | self.chip_info = keyplus.chip_id.lookup_chip_id(chip_id) 32 | 33 | assert(self.chip_info != None) 34 | assert(self.chip_info.architecture == 'nRF52') 35 | assert(self.chip_info.pins in self.PIN_MAP_TABLE) 36 | self.pin_map = IoMapperNRF52.PIN_MAP_TABLE[self.chip_info.pins] 37 | -------------------------------------------------------------------------------- /host-software/keyplus/keycodes/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | from keyplus.keycodes.keycodes import * 8 | from keyplus.keycodes.mapped_keycodes import * 9 | from keyplus.keycodes.keycode_mapper import * 10 | -------------------------------------------------------------------------------- /host-software/keyplus/layout/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | from keyplus.layout.scan_mode import ScanMode 8 | from keyplus.layout.device import LayoutDevice 9 | from keyplus.layout.rf_settings import LayoutRFSettings 10 | from keyplus.layout.keyboard_layout import LayoutKeyboard, LayoutLayer, LayoutDeviceKeycodes 11 | from keyplus.layout.layout import KeyplusLayout 12 | -------------------------------------------------------------------------------- /host-software/keyplus/layout/debounce_profiles.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | DEBOUNCE_PROFILE_TABLE = { 8 | "default": { 9 | "debounce_time_press": 5, 10 | "debounce_time_release": 10, 11 | "trigger_time_press": 1, 12 | "trigger_time_release": 3, 13 | "parasitic_discharge_delay_idle": 2.0, 14 | "parasitic_discharge_delay_debouncing": 10.0, 15 | }, 16 | "cherry_mx": { 17 | "debounce_time_press": 5, 18 | "debounce_time_release": 5, 19 | "trigger_time_press": 0, 20 | "trigger_time_release": 2, 21 | "parasitic_discharge_delay_idle": 2.0, 22 | "parasitic_discharge_delay_debouncing": 10.0, 23 | }, 24 | "kailh_box": { 25 | "debounce_time_press": 8, 26 | "debounce_time_release": 8, 27 | "trigger_time_press": 2, 28 | "trigger_time_release": 3, 29 | "parasitic_discharge_delay_idle": 2.0, 30 | "parasitic_discharge_delay_debouncing": 10.0, 31 | }, 32 | } 33 | -------------------------------------------------------------------------------- /host-software/keyplus/settings.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | from keyplus.cdata_types import settings_t 8 | 9 | class KeyplusSettings(settings_t): 10 | pass 11 | -------------------------------------------------------------------------------- /host-software/keyplus/utility/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | 7 | from keyplus.utility.crc16 import crc16_bytes, is_valid_crc16, crc16 8 | from keyplus.utility.round_keys import gen_final_round_key 9 | 10 | def list_to_map(list_): 11 | return dict({(i, v) for (i, v) in enumerate(list_)}) 12 | 13 | def inverse_map(mapping): 14 | return dict([v, k] for (k, v) in mapping.items()) 15 | 16 | def uint24_le(data): 17 | return [ 18 | (data >> 0) & 0xff, 19 | (data >> 8) & 0xff, 20 | (data >> 16) & 0xff, 21 | ] 22 | -------------------------------------------------------------------------------- /host-software/keyplus/version.py: -------------------------------------------------------------------------------- 1 | __version__='0.4.0pre1' 2 | -------------------------------------------------------------------------------- /host-software/led/layouts/jemini-v5.json: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | "", 4 | "" 5 | ], 6 | [ 7 | "", 8 | "" 9 | ], 10 | [ 11 | "", 12 | "" 13 | ], 14 | [ 15 | { 16 | "rx": 2, 17 | "ry": -0.5 18 | }, 19 | "" 20 | ], 21 | [ 22 | "" 23 | ], 24 | [ 25 | "" 26 | ], 27 | [ 28 | { 29 | "rx": 3, 30 | "ry": -0.75 31 | }, 32 | "" 33 | ], 34 | [ 35 | "" 36 | ], 37 | [ 38 | "" 39 | ], 40 | [ 41 | { 42 | "rx": 3.5, 43 | "ry": 2.75 44 | }, 45 | "" 46 | ], 47 | [ 48 | { 49 | "rx": 4, 50 | "ry": -0.25 51 | }, 52 | "", 53 | "" 54 | ], 55 | [ 56 | "", 57 | "" 58 | ], 59 | [ 60 | "", 61 | "" 62 | ], 63 | [ 64 | { 65 | "rx": 4.5, 66 | "ry": 2.75, 67 | "w": 1.25 68 | }, 69 | "" 70 | ], 71 | [ 72 | { 73 | "r": 10, 74 | "rx": 5.92364817766693, 75 | "ry": 2.765192246987792, 76 | "w": 1.25 77 | }, 78 | "" 79 | ], 80 | [ 81 | { 82 | "r": 30, 83 | "rx": 7.46854767188273, 84 | "ry": 3.100600697855057, 85 | "w": 1.25 86 | }, 87 | "" 88 | ] 89 | ] 90 | -------------------------------------------------------------------------------- /host-software/led/layouts/ortho_4x6.json: -------------------------------------------------------------------------------- 1 | [ 2 | [ 3 | { 4 | "a": 7 5 | }, 6 | "", 7 | "", 8 | "", 9 | "", 10 | "", 11 | "" 12 | ], 13 | [ 14 | "", 15 | "", 16 | "", 17 | "", 18 | "", 19 | "" 20 | ], 21 | [ 22 | "", 23 | "", 24 | "", 25 | "", 26 | "", 27 | "" 28 | ], 29 | [ 30 | "", 31 | "", 32 | "", 33 | "", 34 | "", 35 | "" 36 | ] 37 | ] -------------------------------------------------------------------------------- /host-software/led/rgb.cl: -------------------------------------------------------------------------------- 1 | ( 2 | (IF_EQ h 0 3 | ( 4 | (LOAD_PIXEL h 255 199) 5 | ) 6 | ) 7 | (IF_EQ h 255 8 | ( 9 | (LOAD_PIXEL h 255 200) 10 | ) 11 | ) 12 | (IF_EQ v 200 13 | ( 14 | (SUB_VEC3 1 0 0) 15 | ) 16 | ) 17 | (IF_EQ v 199 18 | ( 19 | (ADD_VEC3 1 0 0) 20 | ) 21 | ) 22 | (SHOW_HSV) 23 | ) 24 | -------------------------------------------------------------------------------- /host-software/led/rgb_init.cl: -------------------------------------------------------------------------------- 1 | ( 2 | (LOAD_PIXEL PIXEL_NUM 255 200) 3 | ) 4 | -------------------------------------------------------------------------------- /host-software/setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2018 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | from setuptools import setup, find_packages 7 | import os 8 | import sys 9 | 10 | if sys.version_info < (3, 5): 11 | sys.exit("Requires python 3.5+") 12 | 13 | # Load the version number 14 | fields = {} 15 | with open(os.path.join("keyplus", "version.py")) as f: 16 | exec(f.read(), fields) 17 | __version__ = fields['__version__'] 18 | 19 | 20 | setup( 21 | name = 'keyplus', 22 | version = __version__, 23 | description = "Python library for interfacing with keyplus keyboards.", 24 | url = "http://github.com/ahtn/keyplus", 25 | author = "jem", 26 | author_email = "jem@seethis.link", 27 | license = 'MIT', 28 | packages = find_packages(include=['keyplus', 'keyplus.*']), 29 | install_requires = [ 30 | 'cstruct', 'hexdump', 'intelhex', 'ruamel.yaml', 'colorama', 31 | # Closely related 32 | 'easyhid>=0.0.10', 33 | 'xusbboot>=0.0.2', 34 | 'efm8boot>=0.0.7', 35 | 'kp_boot_32u4>=0.0.2', 36 | ], 37 | keywords = ['keyboard', 'usb', 'hid'], 38 | scripts = ['keyplus-cli'], 39 | zip_safe = False, 40 | ) 41 | -------------------------------------------------------------------------------- /host-software/uniflash/README.md: -------------------------------------------------------------------------------- 1 | 2 | TODO: automate this this stuff 3 | 4 | ## Dependencies 5 | 6 | The current python dependencies: `intelhex pyusb` 7 | 8 | ## Flashing a unifying receiver 9 | 10 | 11 | ```sh 12 | 13 | sudo ./uniflash.py icp 14 | sleep 2 15 | sudo ./uniflash.py info 16 | 17 | ``` 18 | 19 | Check that `mcu is nRF24LU1+`. Note not all unifying receivers use the same 20 | microprocessor. Only devices that use the nRF24LU1+ are supported. If your 21 | device is supported, you should then be able to run the following command 22 | to flash a hex file to it: 23 | 24 | ```sh 25 | sudo ./uniflash.py flash 26 | ``` 27 | 28 | ## Restore Unifying receiver firmware. 29 | 30 | If you would like to restore the back to the original unifying receiver 31 | firmware, you can use the [firmware hex files provide by logitech here]( 32 | https://github.com/Logitech/fw_updates/tree/master/RQR12 33 | ). 34 | -------------------------------------------------------------------------------- /host-software/uniflash/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/host-software/uniflash/__init__.py -------------------------------------------------------------------------------- /host-software/uniflash/btool.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # Copyright 2017 jem@seethis.link 4 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 5 | 6 | def u16(x): 7 | return x & 0xffff 8 | 9 | def little_endian_u16(data): 10 | return (data[0]) | (data[1] << 8) 11 | 12 | def big_endian_u16(data): 13 | return (data[0] << 8) | (data[1]) 14 | 15 | def u8(x): 16 | return x & 0xff 17 | 18 | def hi(x): 19 | return u8(x >> 8) 20 | 21 | def lo(x): 22 | return u8(x) 23 | 24 | -------------------------------------------------------------------------------- /host-software/uniflash/rf.md: -------------------------------------------------------------------------------- 1 | ## Channel switching 2 | 3 | * nRF24 supports 128 channels, controlled by `RF_CH` register 4 | * channel frequency is `2400 + RF_CH` MHz 5 | * At 2Mbps, channels overlap and need to be spaced ±2MHz 6 | * Uses channels `x*3 + 2` 7 | * Some devices don't use all the channels in that range 8 | -------------------------------------------------------------------------------- /layouts/1key.yaml: -------------------------------------------------------------------------------- 1 | # Written in 2017 by jem@seethis.link 2 | # This file is released into the public domain as per the CC0 Public Domain 3 | # Dedication (http://creativecommons.org/publicdomain/zero/1.0/) 4 | --- 5 | 6 | devices: 7 | pro micro 1 key ⌨️ : 8 | id: 0 9 | scan_mode: 10 | mode: pin_gnd # options: col_row, pins, none 11 | pins: [D1] 12 | layout: 1key 13 | 14 | layouts: 15 | 1key: 16 | layers: [ 17 | [ # layer 0 (base) 18 | [ 19 | a 20 | ] 21 | ], 22 | ] 23 | -------------------------------------------------------------------------------- /layouts/32u4_many_rows.yaml: -------------------------------------------------------------------------------- 1 | # Written in 2017 by jem@seethis.link 2 | # This file is released into the public domain as per the CC0 Public Domain 3 | # Dedication (http://creativecommons.org/publicdomain/zero/1.0/) 4 | --- 5 | 6 | devices: 7 | 32u4 many row test: 8 | id: 0 9 | scan_mode: 10 | mode: col_row # options: col_row, pins, none 11 | cols: [B6] 12 | # NOTE: D5 is the TX_LED on the pro micro 13 | rows: [ D0,D1,D2,D3,D4,C6,D7,E6,B4,B5,F4,F5,F6,F7,B1,B3,B2, D5 ] 14 | matrix_map: [ 15 | r0c0, r1c0, r2c0, r3c0, r4c0, r5c0, r6c0, r7c0, r8c0, r9c0, r10c0, 16 | r11c0, r12c0, r13c0, r14c0, r15c0, r16c0, r17c0 17 | ] 18 | layout: test_layout 19 | 20 | layouts: 21 | test_layout: 22 | layers: [ 23 | [ # layer 0 (base) 24 | [ 25 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H 26 | ] 27 | ], 28 | ] 29 | -------------------------------------------------------------------------------- /layouts/32u4_test.yaml: -------------------------------------------------------------------------------- 1 | # Written in 2017 by jem@seethis.link 2 | # This file is released into the public domain as per the CC0 Public Domain 3 | # Dedication (http://creativecommons.org/publicdomain/zero/1.0/) 4 | --- 5 | 6 | devices: 7 | 32u4 test matrix: 8 | id: 0 9 | scan_mode: 10 | mode: col_row # options: col_row, pins, none 11 | cols: [D1, D0, D4, C6, D7, E6] 12 | rows: [B4, B5, F4, F5] 13 | matrix_map: [ 14 | r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, 15 | r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, 16 | r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, 17 | r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, 18 | ] 19 | layout: Test Layout 20 | 21 | layouts: 22 | TEST LAYOUT: 23 | layers: [ 24 | [ # layer 0 (base) 25 | [ 26 | a, b, c, d, e, f, 27 | g, h, i, j, k, l, 28 | m, n, o, p, q, r, 29 | s, t, u, v, w, x, 30 | ] 31 | ], 32 | ] 33 | -------------------------------------------------------------------------------- /layouts/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Layout documentation 3 | 4 | * [Layout file format](../doc/layout_format.md) 5 | * [Keycode documentation](../doc/keycodes.md) 6 | -------------------------------------------------------------------------------- /layouts/efm8_1key.yaml: -------------------------------------------------------------------------------- 1 | # Written in 2018 by jem@seethis.link 2 | # This file is released into the public domain as per the CC0 Public Domain 3 | # Dedication (http://creativecommons.org/publicdomain/zero/1.0/) 4 | --- 5 | 6 | devices: 7 | "EFM8 test": 8 | scan_mode: 9 | mode: pin_gnd 10 | pins: [P1.2] 11 | layout: 1key 12 | 13 | layouts: 14 | 1key: 15 | layers: [ 16 | [ # layer 0 (base) 17 | [ 18 | 1, 19 | ] 20 | ], 21 | ] 22 | -------------------------------------------------------------------------------- /layouts/efm8_4key.yaml: -------------------------------------------------------------------------------- 1 | # Written in 2018 by jem@seethis.link 2 | # This file is released into the public domain as per the CC0 Public Domain 3 | # Dedication (http://creativecommons.org/publicdomain/zero/1.0/) 4 | --- 5 | 6 | devices: 7 | "EFM8 ‏لوحة المفاتيحキーボード": 8 | scan_mode: 9 | mode: pin_gnd 10 | pins: [P2.0, P2.1, P1.7, P1.6] 11 | layout: 4key 12 | 13 | layouts: 14 | 4key: 15 | layers: [ 16 | [ # layer 0 (base) 17 | [ 18 | 1, 2, 3, 4 19 | ] 20 | ], 21 | ] 22 | -------------------------------------------------------------------------------- /layouts/efm8_4x6.yaml: -------------------------------------------------------------------------------- 1 | # Written in 2018 by jem@seethis.link 2 | # This file is released into the public domain as per the CC0 Public Domain 3 | # Dedication (http://creativecommons.org/publicdomain/zero/1.0/) 4 | --- 5 | 6 | devices: 7 | "EFM8 4x6 🐈🛏️": 8 | scan_mode: 9 | mode: col_row 10 | rows: [P2.0, P2.1, P1.7, P1.6] 11 | cols: [P0.2, P0.3, P0.4, P0.5, P0.6, P0.7] 12 | 13 | matrix_map: [ 14 | r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, 15 | r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, 16 | r2c0, r2c1, r2c2, r2c3, r2c4, r2c5, 17 | r3c0, r3c1, r3c2, r3c3, r3c4, r3c5, 18 | ] 19 | layout: 4x6 20 | 21 | layouts: 22 | 4x6: 23 | layers: [ 24 | [ # layer 0 (base) 25 | [ 26 | 0, a, b, c, d, e, 27 | 1, f, g, h, i, j, 28 | 2, l, k, m, n, o, 29 | 3, p, q, r, s, t 30 | ] 31 | ], 32 | ] 33 | -------------------------------------------------------------------------------- /layouts/nrf52_4key.yaml: -------------------------------------------------------------------------------- 1 | # Written in 2019 by jem@seethis.link 2 | # This file is released into the public domain as per the CC0 Public Domain 3 | # Dedication (http://creativecommons.org/publicdomain/zero/1.0/) 4 | --- 5 | 6 | devices: 7 | "nRF52_dk 4key": 8 | id: 0 9 | wireless_split: true 10 | wireless_mouse: true 11 | wired_split: false 12 | scan_mode: 13 | mode: pin_gnd 14 | pins: [P0.11, P0.12, P0.24, P0.25] 15 | layout: 4key 16 | 17 | layouts: 18 | 4key: 19 | layers: [ 20 | [ # layer 0 (base) 21 | [ 22 | # 1, 2, VOLU, VOLD 23 | 1, 2, MS_D, MS_U 24 | ] 25 | ], 26 | ] 27 | -------------------------------------------------------------------------------- /layouts/nrf52_dongle.yaml: -------------------------------------------------------------------------------- 1 | # 1 button layout for Nordic nRF52840 dongle 2 | devices: 3 | nrf52840_dongle: 4 | id: 0 5 | wireless_split: true 6 | wireless_mouse: true 7 | wired_split: false 8 | scan_mode: 9 | mode: pin_gnd 10 | pins: [P1.06] 11 | layout: 1key 12 | 13 | layouts: 14 | 1key: 15 | layers: [ 16 | [ # layer 0 (base) 17 | [ 18 | x, 19 | ] 20 | ], 21 | ] 22 | -------------------------------------------------------------------------------- /layouts/test_rf_config.yaml: -------------------------------------------------------------------------------- 1 | # Generated on 2017-22-11 at 23:22 2 | rf_settings: 3 | aes_encryption_key: 9febeb27209e131ceaf812f73feed577 4 | rf_channel: 0x08 5 | auto_retransmit_count: 8 # options: 0-15 6 | # TODO: should include retransmit delay option 7 | data_rate: 2mbps # options: 2mbps, 1mbps, 250kbps 8 | transmit_power: 0dB # options: 0dB, -6dB, -12dB, -18dB 9 | pipe0: '2aef63473c' 10 | pipe1: '168d715956' 11 | pipe2: 'c1' 12 | pipe3: 'fc' 13 | pipe4: '63' 14 | pipe5: '00' 15 | -------------------------------------------------------------------------------- /layouts/test_rf_config2.yaml: -------------------------------------------------------------------------------- 1 | # Generated on 2018-20-22 at 23:20 2 | rf_settings: 3 | aes_encryption_key: b3788d2bd5d8c564f86e3110ddc43795 4 | auto_retransmit_count: 15 5 | data_rate: 2mbps 6 | pipe0: 2c8147eab0 7 | pipe1: b1646d37a8 8 | pipe2: '72' 9 | pipe3: '01' 10 | pipe4: f6 11 | pipe5: '00' 12 | rf_channel: 35 13 | transmit_power: 0db 14 | 15 | 16 | # Tested all the channels on a device: 17 | # works m720: 18 | # 5, 8, 14, 17, 32, 35, 41, 44, 62, 65, 71, 74 19 | # doesn't: 20 | # 11, 20, 23, 26, 29, 38, 47, 50, 53, 56, 59, 68 21 | -------------------------------------------------------------------------------- /ports/atmega32u4/README.md: -------------------------------------------------------------------------------- 1 | 2 | # Links 3 | 4 | * USB code based of [Teensy USB keyboard example for ATmega32u4](https://www.pjrc.com/teensy/usb_keyboard.html) 5 | -------------------------------------------------------------------------------- /ports/atmega32u4/boards/atmel-dfu/config.mk: -------------------------------------------------------------------------------- 1 | # Build 2 | 3 | C_SRC += # extra includes 4 | 5 | BOOTLOADER = atmel_dfu 6 | 7 | USE_USB := 1 8 | USE_SCANNER := 1 9 | USE_NRF24 := 0 10 | USE_CHECK_PIN := 0 11 | USE_I2C := 0 12 | USE_HARDWARE_SPECIFIC_SCAN := 0 13 | -------------------------------------------------------------------------------- /ports/atmega32u4/boards/default/config.mk: -------------------------------------------------------------------------------- 1 | # Build 2 | 3 | C_SRC += # extra includes 4 | 5 | BOOTLOADER = kp_boot_32u4 6 | 7 | USE_USB := 1 8 | USE_SCANNER := 1 9 | USE_NRF24 := 0 10 | USE_CHECK_PIN := 0 11 | USE_I2C := 0 12 | USE_HARDWARE_SPECIFIC_SCAN := 0 13 | -------------------------------------------------------------------------------- /ports/atmega32u4/bootloaders/atmel_dfu/README.md: -------------------------------------------------------------------------------- 1 | 2 | default fuses: 3 | 4 | LFUSE = 5E 5 | HFUSE = D9 6 | EFUSE = C3 # --> EFUSE = F3 7 | 8 | * [USB DFU Bootlooder Datasheet](http://www.atmel.com/Images/doc7618.pdf) 9 | * [Prebuild Atmel USB DFU Bootloader hex files](http://www.atmel.com/Images/megaUSB_DFU_Bootloaders.zip) 10 | * [C API to bootloader functions](https://github.com/komar007/atmel_bootloader) 11 | -------------------------------------------------------------------------------- /ports/atmega32u4/bootloaders/lufa_dfu/demoapp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * demoapp.c 3 | * 4 | * Created: 29/05/2013 3:20:43 PM 5 | * Author: Stanley Lio 6 | */ 7 | 8 | 9 | #define F_CPU 16000000UL 10 | #include 11 | #include 12 | 13 | int main(void) 14 | { 15 | DDRB = 255; 16 | DDRD = 255; 17 | 18 | while(1) 19 | { 20 | PORTB = 0; 21 | PORTD = 255; 22 | _delay_ms(1000); 23 | PORTB = 255; 24 | PORTD = 0; 25 | _delay_ms(1000); 26 | } 27 | } -------------------------------------------------------------------------------- /ports/atmega32u4/doxygen.md: -------------------------------------------------------------------------------- 1 | @dir ports/atmega32u4 2 | 3 | TODO: add support for ATmega32u2 and AT90USB1286/AT90USB1287, 4 | 5 | ## Feature support 6 | 7 | * USB 8 | * TODO: nRF24 wireless receiver 9 | * TODO: I2C split 10 | * TODO: (maybe) nRF24 wireless transmitter 11 | * TODO: (maybe) battery operation 12 | -------------------------------------------------------------------------------- /ports/atmega32u4/src/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef USB_VID 7 | #define USB_VID 0x1209 8 | #endif 9 | 10 | #ifndef USB_PID 11 | #define USB_PID 0xBB00 12 | #endif 13 | 14 | #define DEVICE_ID 0 15 | 16 | #ifndef USB_DEVICE_VERSION 17 | #define USB_DEVICE_VERSION 0x0000 18 | #endif 19 | 20 | // 0ms trigger tim on release, 8ms debounce time 21 | #define DEBOUNCE_PRESS_TIME 8 22 | #define DEBOUNCE_PRESS_TRIGGER_TIME 0 23 | 24 | // 0ms trigger time on release, 10ms debounce time 25 | #define DEBOUNCE_RELEASE_TIME 20 26 | #define DEBOUNCE_RELEASE_TRIGGER_TIME 2 27 | 28 | #define SCANNER_MATRIX_DELTA 1 29 | 30 | #ifndef INTERNAL_SCAN_METHOD 31 | #define INTERNAL_SCAN_METHOD (MATRIX_SCANNER_INTERNAL_FAST_ROW_COL) 32 | #endif 33 | 34 | #ifndef MAX_NUM_ROWS 35 | #define MAX_NUM_ROWS 18 36 | #endif 37 | 38 | // Use the SPI handling provided by core/nrf24.c 39 | #define NRF24_INBUILT_SPI_HANDLING 1 40 | -------------------------------------------------------------------------------- /ports/atmega32u4/src/io_map.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/hardware.h" 5 | 6 | #if defined(__AVR_ATmega32U4__) \ 7 | || defined(__AVR_ATmega16U4) \ 8 | || defined(__AVR_ATmega32U2) \ 9 | || defined(__AVR_ATmega16U2) 10 | 11 | io_port_t * const g_io_port_map[IO_PORT_COUNT] = { 12 | &PORT(B), 13 | &PORT(C), 14 | &PORT(D), 15 | &PORT(E), 16 | &PORT(F), 17 | }; 18 | 19 | 20 | #elif defined(__AVR_AT90USB646) \ 21 | || defined(__AVR_AT90USB647) \ 22 | || defined(__AVR_AT90USB1286) \ 23 | || defined(__AVR_AT90USB1287) \ 24 | || defined(__AVR_ATmega32U6) 25 | #endif 26 | -------------------------------------------------------------------------------- /ports/atmega32u4/src/io_map/avr_port_util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | typedef volatile uint8_t register8_t; 9 | typedef volatile uint16_t register16_t; 10 | typedef volatile uint32_t register32_t; 11 | 12 | typedef struct PORT_struct { 13 | register8_t IN; 14 | register8_t DDR; 15 | register8_t OUT; 16 | } PORT_t; 17 | 18 | /// This macro allows us to the AVR ports as if they were a C structure 19 | #define PORT(port_letter) (*(PORT_t*)&(PIN ## port_letter)) 20 | -------------------------------------------------------------------------------- /ports/atmega32u4/src/io_map/iom32u4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_B_NUM 0 7 | #define PORT_C_NUM 1 8 | #define PORT_D_NUM 2 9 | #define PORT_E_NUM 3 10 | #define PORT_F_NUM 4 11 | 12 | // #define PORTB _SFR_IO8(0x05) 13 | // #define PORTC _SFR_IO8(0x08) 14 | // #define PORTD _SFR_IO8(0x0B) 15 | // #define PORTE _SFR_IO8(0x0E) 16 | // #define PORTF _SFR_IO8(0x11) 17 | #define PORT_TO_NUM(port_num) (\ 18 | (PINB <= &port && &port <= PORTB) ? (PORT_B_NUM) : \ 19 | (PINC <= &port && &port <= PORTC) ? (PORT_C_NUM) : \ 20 | (PIND <= &port && &port <= PORTD) ? (PORT_D_NUM) : \ 21 | (PINE <= &port && &port <= PORTE) ? (PORT_E_NUM) : \ 22 | (PINF <= &port && &port <= PORTF) ? (PORT_F_NUM) : 255 \ 23 | ) 24 | 25 | #define IO_PORT_COUNT 5 26 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_F_NUM, 7) ) 27 | 28 | #define PORT_B_USABLE_PINS 0xff 29 | #define PORT_C_USABLE_PINS 0xC0 30 | #define PORT_D_USABLE_PINS 0xff 31 | #define PORT_E_USABLE_PINS 0x44 32 | #define PORT_F_USABLE_PINS 0xf3 33 | 34 | // (8 + 2 + 8 + 2 + 6) 35 | #define IO_MAP_GPIO_COUNT (26) 36 | 37 | #ifndef IO_USABLE_PINS 38 | #define IO_USABLE_PINS { \ 39 | PORT_B_USABLE_PINS, \ 40 | PORT_C_USABLE_PINS, \ 41 | PORT_D_USABLE_PINS, \ 42 | PORT_E_USABLE_PINS, \ 43 | PORT_F_USABLE_PINS, \ 44 | } 45 | #endif 46 | -------------------------------------------------------------------------------- /ports/atmega32u4/src/port_impl/hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include "io_map/avr_port_util.h" 11 | 12 | #define static_delay_us(x) _delay_us(x) 13 | #define static_delay_ms(x) _delay_ms(x) 14 | 15 | #define enable_interrupts() do { \ 16 | sei(); \ 17 | } while(0); 18 | 19 | #define disable_interrupts() do { \ 20 | cli(); \ 21 | } while(0); 22 | 23 | // define flash pointer sizes 24 | #if MCU_FLASH_SIZE <= 64 25 | typedef uint16_t flash_ptr_t; 26 | typedef uint16_t flash_addr_t; 27 | typedef uint32_t flash_size_t; 28 | #else 29 | typedef uint16_t flash_ptr_t; 30 | typedef uint32_t flash_addr_t; 31 | typedef uint32_t flash_size_t; 32 | #endif 33 | 34 | #define MCU_BITNESS 8 35 | 36 | typedef PORT_t io_port_t; 37 | 38 | // SPM_PAGESIZE is in bytes 39 | // WARNING: some old versions of the datasheet incorrectly states that the page 40 | // size is 128 WORDS (i.e. 256 bytes), however the correct value should be 64 41 | // WORDS (i.e. 128 bytes). 42 | #define PAGE_SIZE (SPM_PAGESIZE) 43 | 44 | #if defined (__AVR_ATmega32U4__) 45 | #include "io_map/iom32u4.h" 46 | #else 47 | #error "Found unsupported MCU when trying to choose pin map" 48 | #endif 49 | -------------------------------------------------------------------------------- /ports/atmega32u4/src/usb_32u4.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/atmega32u4/src/usb_32u4.c -------------------------------------------------------------------------------- /ports/atmega32u4/src/usb_32u4.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | #include "core/flash.h" 12 | 13 | enum { 14 | PTR_DATA = 0, 15 | PTR_FLASH = 1, 16 | PTR_EEPROM = 2, 17 | }; 18 | 19 | typedef flash_ptr_t raw_ptr_t ; 20 | 21 | /// The fat pointer type is used to make it easier to pass data from various 22 | /// memory regions between functions. In addition to the address, this pointer 23 | /// includes the size and type of the memory region (ram, flash, eeprom). 24 | typedef struct fat_ptr_t { 25 | uint8_t type; 26 | uint16_t len; 27 | union { 28 | const uint8_t* data; 29 | flash_ptr_t flash; 30 | raw_ptr_t raw; 31 | } ptr; 32 | } fat_ptr_t; 33 | 34 | void usb_write_endpoint(uint8_t ep_number, const uint8_t *src, uint8_t length); 35 | void usb_read_endpoint(uint8_t ep_number, uint8_t *dest, uint8_t *length); 36 | 37 | /// Checks if the given USB endpoint is ready 38 | static inline bool usb_is_endpoint_ready(uint8_t ep_num) { 39 | uint8_t result; 40 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { 41 | UENUM = ep_num; 42 | result = UEINTX & (1< 5 | 6 | #include "core/util.h" 7 | 8 | #include "usb/util/descriptor_defs.h" 9 | #include "usb_32u4.h" 10 | 11 | bit_t is_in_endpoint_ready(uint8_t endpoint_num) { 12 | return usb_is_endpoint_ready(endpoint_num); 13 | } 14 | 15 | bit_t is_out_endpoint_ready(uint8_t endpoint_num) { 16 | return usb_is_endpoint_ready(endpoint_num); 17 | } 18 | 19 | void usb_write_in_endpoint( 20 | uint8_t endpoint_num, 21 | const uint8_t *data, 22 | uint8_t size 23 | ) { 24 | usb_write_endpoint(endpoint_num, data, size); 25 | } 26 | 27 | void usb_read_out_endpoint( 28 | uint8_t endpoint_num, 29 | uint8_t *dest, 30 | uint8_t *length 31 | ) { 32 | usb_read_endpoint(endpoint_num, dest, length); 33 | } 34 | -------------------------------------------------------------------------------- /ports/atmega32u4/src/usb_user_impl.h: -------------------------------------------------------------------------------- 1 | 2 | // define this value for ports that can't have IN and OUT endpoints using 3 | // the same endpoint number. 4 | #define ENDPOINT_IN_OUT_SEPARATE 5 | -------------------------------------------------------------------------------- /ports/atmega8/.gitignore: -------------------------------------------------------------------------------- 1 | .dep 2 | *.eep 3 | *.lss 4 | -------------------------------------------------------------------------------- /ports/atmega8/README.md: -------------------------------------------------------------------------------- 1 | # atmega8 keyplus wireless only keyboard 2 | 3 | The atmega8 code uses an atmegaXX8p(a) along with an nRF24L01+ and acts as a 4 | wireless only keyboard. 5 | 6 | Since the atmega8 doesn't have AES encryption hardware, a software implementation 7 | must be used. 8 | 9 | # TODO 10 | 11 | * add suport for wired opertation over i2c 12 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore objects and archives, anywhere in the tree. 2 | *.[oa] 3 | *.lo 4 | *.la 5 | # Ignore build output files 6 | /build 7 | 8 | # Ignore backup files 9 | *~ 10 | 11 | # Ignore autotools files 12 | .deps 13 | .libs 14 | /autom4te.cache 15 | /build-aux 16 | /config.h 17 | /config.h.in 18 | /config.log 19 | /config.status 20 | /configure 21 | /libtool 22 | /stamp-h1 23 | *.m4 24 | Makefile 25 | Makefile.in 26 | *.pc 27 | 28 | # Ignore Python files 29 | *.pyc 30 | *.pyd 31 | 32 | # Ignore Eclipse project files 33 | /.cproject 34 | /.project 35 | /.autotools 36 | /.settings 37 | /.pydevproject 38 | 39 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/LICENSE.txt: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | Copyright (c) 2014 Craig McQueen 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | ---------------------------------------------------------------------------- 22 | 23 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-add-round-key.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-add-round-key.h 3 | ****************************************************************************/ 4 | 5 | #ifndef AES_ADD_ROUND_KEY_H 6 | #define AES_ADD_ROUND_KEY_H 7 | 8 | /***************************************************************************** 9 | * Includes 10 | ****************************************************************************/ 11 | 12 | #include "aes.h" 13 | 14 | /***************************************************************************** 15 | * Inline functions 16 | ****************************************************************************/ 17 | 18 | /* XOR the specified round key into the AES block. 19 | * Fixed block size. 20 | */ 21 | static inline void aes_add_round_key(uint8_t p_block[AES_BLOCK_SIZE], const uint8_t p_round_key[AES_BLOCK_SIZE]) 22 | { 23 | uint_fast8_t i; 24 | 25 | for (i = 0; i < AES_BLOCK_SIZE; ++i) 26 | { 27 | p_block[i] ^= p_round_key[i]; 28 | } 29 | } 30 | 31 | #endif /* !defined(AES_ADD_ROUND_KEY_H) */ 32 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-inv.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-inv.h 3 | * 4 | * aes_inv() calculates multiplicative inverse in Galois field GF(2^8) with 5 | * reduction polynomial 0x11B. 6 | ****************************************************************************/ 7 | 8 | #ifndef AES_INV_H 9 | #define AES_INV_H 10 | 11 | /***************************************************************************** 12 | * Includes 13 | ****************************************************************************/ 14 | 15 | #include 16 | 17 | /***************************************************************************** 18 | * Function prototypes 19 | ****************************************************************************/ 20 | 21 | uint8_t aes_inv(uint8_t a); 22 | 23 | #endif /* !defined(AES_INV_H) */ 24 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-key-schedule-round.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-key-schedule-round.h 3 | * 4 | * In-place calculation of the next round of the AES-128 key schedule. 5 | * This is used for encryption with on-the-fly key schedule calculation. 6 | ****************************************************************************/ 7 | 8 | #ifndef AES_KEY_SCHEDULE_ROUND_H 9 | #define AES_KEY_SCHEDULE_ROUND_H 10 | 11 | /***************************************************************************** 12 | * Includes 13 | ****************************************************************************/ 14 | 15 | #include "aes.h" 16 | 17 | /***************************************************************************** 18 | * Function prototypes 19 | ****************************************************************************/ 20 | 21 | void aes128_key_schedule_round(uint8_t p_key[AES128_KEY_SIZE], uint8_t rcon); 22 | 23 | #endif /* !defined(AES_KEY_SCHEDULE_ROUND_H) */ 24 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-min.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: @PACKAGE_NAME@ 7 | Description: Minimal AES encryption with 128-bit key. 8 | Version: @PACKAGE_VERSION@ 9 | Libs: -L${libdir} -l@PACKAGE_NAME@-@PACKAGE_VERSION@ 10 | Cflags: -I${includedir}/@PACKAGE_NAME@-@PACKAGE_VERSION@ 11 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-mix-columns.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-mix-columns.h 3 | * 4 | * Prototypes for AES encryption mix-columns and decryption inverse steps. 5 | ****************************************************************************/ 6 | 7 | #ifndef AES_MIX_COLUMNS_H 8 | #define AES_MIX_COLUMNS_H 9 | 10 | /***************************************************************************** 11 | * Includes 12 | ****************************************************************************/ 13 | 14 | #include 15 | 16 | /***************************************************************************** 17 | * Function prototypes 18 | ****************************************************************************/ 19 | 20 | void aes_mix_columns(uint8_t p_block[AES_BLOCK_SIZE]); 21 | void aes_mix_columns_inv(uint8_t p_block[AES_BLOCK_SIZE]); 22 | 23 | #endif /* !defined(AES_MIX_COLUMNS_H) */ 24 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-mul.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-mul.h 3 | * 4 | * aes_mul() multiplies two numbers in Galois field GF(2^8) with reduction 5 | * polynomial 0x11B. 6 | ****************************************************************************/ 7 | 8 | #ifndef AES_MUL_H 9 | #define AES_MUL_H 10 | 11 | /***************************************************************************** 12 | * Includes 13 | ****************************************************************************/ 14 | 15 | #include 16 | 17 | /***************************************************************************** 18 | * Function prototypes 19 | ****************************************************************************/ 20 | 21 | uint8_t aes_mul(uint8_t a, uint8_t b); 22 | 23 | #endif /* !defined(AES_MUL_H) */ 24 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-print-block.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-print-block.h 3 | ****************************************************************************/ 4 | 5 | #ifndef AES_PRINT_BLOCK_H 6 | #define AES_PRINT_BLOCK_H 7 | 8 | /***************************************************************************** 9 | * Includes 10 | ****************************************************************************/ 11 | 12 | #include 13 | #include 14 | 15 | /***************************************************************************** 16 | * Inline functions 17 | ****************************************************************************/ 18 | 19 | static inline void print_block_hex(const uint8_t * p_block, size_t len) 20 | { 21 | while (len > 1) 22 | { 23 | printf("%02X ", *p_block++); 24 | len--; 25 | } 26 | if (len) 27 | { 28 | printf("%02X", *p_block); 29 | } 30 | printf("\n"); 31 | } 32 | 33 | 34 | #endif /* !defined(AES_PRINT_BLOCK_H) */ 35 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-rotate.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-rotate.h 3 | ****************************************************************************/ 4 | 5 | #ifndef AES_ROTATE_H 6 | #define AES_ROTATE_H 7 | 8 | /***************************************************************************** 9 | * Includes 10 | ****************************************************************************/ 11 | 12 | #include 13 | 14 | /***************************************************************************** 15 | * Inline functions 16 | ****************************************************************************/ 17 | 18 | /* Hopefully the compiler reduces this to a single rotate instruction. 19 | * However in testing with gcc on x86-64, it didn't happen. But it is target- 20 | * and compiler-specific. 21 | * 22 | * Alternatively for a particular platform: 23 | * - Use an intrinsic 8-bit rotate function provided by the compiler. 24 | * - Use inline assembler. 25 | * 26 | * TODO: Examine code produced on the target platform. 27 | */ 28 | static inline uint8_t aes_rotate_left_uint8(uint8_t a, uint_fast8_t num_bits) 29 | { 30 | return ((a << num_bits) | (a >> (8u - num_bits))); 31 | } 32 | 33 | #endif /* !defined(AES_MUL2_H) */ 34 | 35 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-sbox.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-sbox.h 3 | * 4 | * Prototypes for AES S-box and inverse S-box. 5 | ****************************************************************************/ 6 | 7 | #ifndef AES_SBOX_H 8 | #define AES_SBOX_H 9 | 10 | /***************************************************************************** 11 | * Includes 12 | ****************************************************************************/ 13 | 14 | #include "aes.h" 15 | 16 | #include 17 | 18 | /***************************************************************************** 19 | * Function prototypes 20 | ****************************************************************************/ 21 | 22 | uint8_t aes_sbox(uint8_t a); 23 | uint8_t aes_sbox_inv(uint8_t a); 24 | void aes_sbox_apply_block(uint8_t p_block[AES_BLOCK_SIZE]); 25 | void aes_sbox_inv_apply_block(uint8_t p_block[AES_BLOCK_SIZE]); 26 | 27 | 28 | #endif /* !defined(AES_SBOX_H) */ 29 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/aes-shift-rows.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | * aes-shift-rows.h 3 | * 4 | * Prototypes for AES encryption shift-rows and decryption inverse steps. 5 | ****************************************************************************/ 6 | 7 | #ifndef AES_SHIFT_ROWS_H 8 | #define AES_SHIFT_ROWS_H 9 | 10 | /***************************************************************************** 11 | * Includes 12 | ****************************************************************************/ 13 | 14 | #include 15 | 16 | /***************************************************************************** 17 | * Function prototypes 18 | ****************************************************************************/ 19 | 20 | void aes_shift_rows(uint8_t p_block[AES_BLOCK_SIZE]); 21 | void aes_shift_rows_inv(uint8_t p_block[AES_BLOCK_SIZE]); 22 | 23 | #endif /* !defined(AES_SHIFT_ROWS_H) */ 24 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/autogen.sh: -------------------------------------------------------------------------------- 1 | autoreconf --install || exit 1 2 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes-min/python/gmul.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | def gmul(a, b): 6 | a = int(a) 7 | b = int(b) 8 | result = 0 9 | while a: 10 | if a & 1: 11 | result ^= b 12 | a >>= 1 13 | b <<= 1 14 | if b & 0x100: 15 | b ^= 0x11B 16 | return result 17 | 18 | 19 | if __name__ == "__main__": 20 | print(gmul(sys.argv[1], sys.argv[2])) 21 | 22 | -------------------------------------------------------------------------------- /ports/atmega8/aes/aes.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2017 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | AES_MIN_SRC = \ 5 | aes/aes-min/aes-decrypt.c \ 6 | aes/aes-min/aes-encrypt.c \ 7 | aes/aes-min/aes-inv.c \ 8 | aes/aes-min/aes-key-schedule.c \ 9 | aes/aes-min/aes-key-schedule-round.c \ 10 | aes/aes-min/aes-mix-columns.c \ 11 | aes/aes-min/aes-mix-columns-inv.c \ 12 | aes/aes-min/aes-mul.c \ 13 | aes/aes-min/aes-shift-rows.c \ 14 | aes/aes-min/aes-shift-rows-inv.c \ 15 | aes/aes-min/aes-sbox.c \ 16 | aes/aes-min/aes-sbox-inv.c \ 17 | # aes/aes-min/aes-sbox-inv-small.c \ 18 | # aes/aes-min/aes-sbox-small.c \ 19 | 20 | 21 | AES_CRYPTO_LIB_ASM_SRC = \ 22 | aes/avr-crypto-lib/aes_aleph_keyschedule-asm.S \ 23 | aes/avr-crypto-lib/aes_invsbox-asm.S \ 24 | aes/avr-crypto-lib/aes_sbox-asm.S \ 25 | aes/avr-crypto-lib/avr-asm-macros.S \ 26 | aes/avr-crypto-lib/aes_enc-asm.S \ 27 | aes/avr-crypto-lib/aes_dec-asm_faster.S \ 28 | # aes/avr-crypto-lib/aes_dec-asm.S \ 29 | 30 | AES_TINY128_SRC = aes/tiny_aes128/aes.c 31 | 32 | ifeq ($(AES_LIB), tiny-aes128) 33 | CDEFS += -DAES_TINY128 -DECB=1 -DCBC=0 34 | C_SRC +=$(AES_TINY128_SRC) 35 | endif 36 | 37 | ifeq ($(AES_LIB), avr-crypto-lib) 38 | CDEFS += -DAES_CRYPTO_LIB 39 | ASM_SRC += $(AES_CRYPTO_LIB_ASM_SRC) 40 | endif 41 | 42 | ifeq ($(AES_LIB), aes-min) 43 | CDEFS += -DAES_MIN 44 | C_SRC +=$(AES_MIN_SRC) 45 | endif 46 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes.h: -------------------------------------------------------------------------------- 1 | /* aes.h */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes.h 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-30 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | #ifndef AES_H_ 28 | #define AES_H_ 29 | 30 | #include 31 | 32 | #include "aes_types.h" 33 | #include "aes128_enc.h" 34 | #include "aes192_enc.h" 35 | #include "aes256_enc.h" 36 | #include "aes128_dec.h" 37 | #include "aes192_dec.h" 38 | #include "aes256_dec.h" 39 | #include "aes_enc.h" 40 | #include "aes_dec.h" 41 | #include "aes_keyschedule.h" 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes128_dec.c: -------------------------------------------------------------------------------- 1 | /* aes128_dec.c */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes128_dec.c 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-30 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | 28 | #include "aes.h" 29 | #include "aes_dec.h" 30 | 31 | void aes128_dec(void *buffer, aes128_ctx_t *ctx){ 32 | aes_decrypt_core(buffer, (aes_genctx_t*)ctx, 10); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes128_enc.c: -------------------------------------------------------------------------------- 1 | /* aes128_enc.c */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes128_enc.c 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-30 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | 28 | #include "aes.h" 29 | #include "aes_enc.h" 30 | 31 | void aes128_enc(void *buffer, aes128_ctx_t *ctx) 32 | { 33 | aes_encrypt_core(buffer, (aes_genctx_t*) ctx, 10); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes192_dec.c: -------------------------------------------------------------------------------- 1 | /* aes192_dec.c */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes192_dec.c 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-31 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | 28 | #include "aes.h" 29 | #include "aes_dec.h" 30 | 31 | void aes192_dec(void *buffer, aes192_ctx_t *ctx){ 32 | aes_decrypt_core(buffer, (aes_genctx_t*)ctx, 12); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes192_enc.c: -------------------------------------------------------------------------------- 1 | /* aes192_enc.c */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes192_enc.c 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-31 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | 28 | #include "aes.h" 29 | #include "aes_enc.h" 30 | 31 | void aes192_enc(void *buffer, aes192_ctx_t *ctx) 32 | { 33 | aes_encrypt_core(buffer, (aes_genctx_t*) ctx, 12); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes256_dec.c: -------------------------------------------------------------------------------- 1 | /* aes256_dec.c */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes256_dec.c 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-31 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | 28 | #include "aes.h" 29 | #include "aes_dec.h" 30 | 31 | void aes256_dec(void *buffer, aes256_ctx_t *ctx){ 32 | aes_decrypt_core(buffer, (aes_genctx_t*)ctx, 14); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes256_enc.c: -------------------------------------------------------------------------------- 1 | /* aes256_enc.c */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes256_enc.c 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-31 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | 28 | #include "aes.h" 29 | #include "aes_enc.h" 30 | 31 | void aes256_enc(void *buffer, aes256_ctx_t *ctx){ 32 | aes_encrypt_core(buffer, (aes_genctx_t*)ctx, 14); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes_dec.h: -------------------------------------------------------------------------------- 1 | /* aes_dec.h */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes_dec.h 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-30 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | #ifndef AES_DEC_H_ 28 | #define AES_DEC_H_ 29 | #include "aes_types.h" 30 | #include 31 | 32 | 33 | void aes_decrypt_core(aes_cipher_state_t *state,const aes_genctx_t *ks, uint8_t rounds); 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes_enc.h: -------------------------------------------------------------------------------- 1 | /* aes_enc.h */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes_enc.h 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-30 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | #ifndef AES_ENC_H_ 28 | #define AES_ENC_H_ 29 | #include "aes_types.h" 30 | #include 31 | 32 | void aes_encrypt_core(aes_cipher_state_t *state, const aes_genctx_t *ks, 33 | uint8_t rounds); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes_invsbox.h: -------------------------------------------------------------------------------- 1 | /* aes_invsbox.h */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes_invsbox.h 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-30 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | #ifndef AES_INVSBOX_H_ 28 | #define AES_INVSBOX_H_ 29 | #include 30 | 31 | extern uint8_t aes_invsbox[]; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /ports/atmega8/aes/avr-crypto-lib/aes_sbox.h: -------------------------------------------------------------------------------- 1 | /* aes_sbox.h */ 2 | /* 3 | This file is part of the AVR-Crypto-Lib. 4 | Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org) 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * \file aes_sbox.h 21 | * \email bg@nerilex.org 22 | * \author Daniel Otte 23 | * \date 2008-12-30 24 | * \license GPLv3 or later 25 | * 26 | */ 27 | #ifndef AES_SBOX_H_ 28 | #define AES_SBOX_H_ 29 | #include 30 | 31 | extern uint8_t aes_sbox[]; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /ports/atmega8/aes/tiny_aes128/Makefile: -------------------------------------------------------------------------------- 1 | #CC = avr-gcc 2 | #CFLAGS = -Wall -mmcu=atmega16 -Os -Wl,-Map,test.map 3 | #OBJCOPY = avr-objcopy 4 | CC = gcc 5 | CFLAGS = -Wall -Os -Wl,-Map,test.map 6 | OBJCOPY = objcopy 7 | 8 | # include path to AVR library 9 | INCLUDE_PATH = /usr/lib/avr/include 10 | # splint static check 11 | SPLINT = splint test.c aes.c -I$(INCLUDE_PATH) +charindex -unrecog 12 | 13 | .SILENT: 14 | .PHONY: lint clean 15 | 16 | 17 | rom.hex : test.out 18 | # copy object-code to new image and format in hex 19 | $(OBJCOPY) -j .text -O ihex test.out rom.hex 20 | 21 | test.o : test.c 22 | # compiling test.c 23 | $(CC) $(CFLAGS) -c test.c -o test.o 24 | 25 | aes.o : aes.h aes.c 26 | # compiling aes.c 27 | $(CC) $(CFLAGS) -c aes.c -o aes.o 28 | 29 | test.out : aes.o test.o 30 | # linking object code to binary 31 | $(CC) $(CFLAGS) aes.o test.o -o test.out 32 | 33 | small: test.out 34 | $(OBJCOPY) -j .text -O ihex test.out rom.hex 35 | 36 | clean: 37 | rm -f *.OBJ *.LST *.o *.gch *.out *.hex *.map 38 | 39 | lint: 40 | $(call SPLINT) 41 | -------------------------------------------------------------------------------- /ports/atmega8/aes/tiny_aes128/aes.h: -------------------------------------------------------------------------------- 1 | #ifndef _AES_H_ 2 | #define _AES_H_ 3 | 4 | #include 5 | 6 | 7 | // #define the macros below to 1/0 to enable/disable the mode of operation. 8 | // 9 | // CBC enables AES128 encryption in CBC-mode of operation and handles 0-padding. 10 | // ECB enables the basic ECB 16-byte block algorithm. Both can be enabled simultaneously. 11 | 12 | // The #ifndef-guard allows it to be configured before #include'ing or at compile time. 13 | #ifndef CBC 14 | #define CBC 1 15 | #endif 16 | 17 | #ifndef ECB 18 | #define ECB 1 19 | #endif 20 | 21 | 22 | 23 | #if defined(ECB) && ECB 24 | 25 | void AES128_ECB_encrypt(const uint8_t* input, const uint8_t* key, uint8_t *output); 26 | void AES128_ECB_decrypt(const uint8_t* input, const uint8_t* key, uint8_t *output); 27 | 28 | #endif // #if defined(ECB) && ECB 29 | 30 | 31 | #if defined(CBC) && CBC 32 | 33 | void AES128_CBC_encrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 34 | void AES128_CBC_decrypt_buffer(uint8_t* output, uint8_t* input, uint32_t length, const uint8_t* key, const uint8_t* iv); 35 | 36 | #endif // #if defined(CBC) && CBC 37 | 38 | 39 | 40 | #endif //_AES_H_ 41 | -------------------------------------------------------------------------------- /ports/atmega8/aes/tiny_aes128/unlicense.txt: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /ports/atmega8/clock.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "clock.h" 5 | 6 | inline void clock_fast(void) { 7 | clock_prescale_set(FAST_SPEED_DIV); 8 | } 9 | 10 | inline void clock_slow(void) { 11 | clock_prescale_set(SLOW_SPEED_DIV); 12 | } 13 | -------------------------------------------------------------------------------- /ports/atmega8/clock.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | // NOTE: F_CPU is set to F_OSC/FAST_SPEED_DIV 10 | 11 | #if F_OSC==16000000 12 | #define FAST_SPEED_DIV clock_div_8 13 | #define SLOW_SPEED_DIV clock_div_256 14 | #elif F_OSC==8000000 15 | #define FAST_SPEED_DIV clock_div_8 16 | #define SLOW_SPEED_DIV clock_div_128 17 | #else 18 | #error "F_OSC unset or unsupported" 19 | #endif 20 | 21 | #define clock_delay_slow_us(X) _delay_us(X / (1 << (SLOW_SPEED_DIV-FAST_SPEED_DIV))) 22 | #define clock_delay_slow_ms(X) _delay_ms(X / (1 << (SLOW_SPEED_DIV-FAST_SPEED_DIV))) 23 | #define clock_delay_fast_us(X) _delay_us(X) 24 | #define clock_delay_fast_ms(X) _delay_ms(X) 25 | 26 | void clock_fast(void); 27 | void clock_slow(void); 28 | -------------------------------------------------------------------------------- /ports/atmega8/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define DEBOUNCE 5 7 | 8 | // If the master doesn't receive a response from a slave in this time, 9 | // it will consider it disconnected, and reset its key state. 10 | #define DISCONNECT_TIME 2 11 | 12 | #define SCANNER_MATRIX_DELTA 0 13 | 14 | #define NO_USB 15 | -------------------------------------------------------------------------------- /ports/atmega8/eeprom_map.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include 7 | 8 | #ifndef EEPROM_PAGE_SIZE 9 | #define EEPROM_PAGE_SIZE 32 10 | #endif 11 | 12 | // NOTE: we store each nonce value in a different page, to reduce the chance 13 | // that all the values get corrupted at once. 14 | #define EEPROM_NONCE_0 (uint16_t*)(EEPROM_PAGE_SIZE*1 + 0) 15 | #define EEPROM_NONCE_1 (uint16_t*)(EEPROM_PAGE_SIZE*2 + 0) 16 | #define EEPROM_NONCE_2 (uint16_t*)(EEPROM_PAGE_SIZE*3 + 0) 17 | -------------------------------------------------------------------------------- /ports/atmega8/hardware: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/atmega8/hardware -------------------------------------------------------------------------------- /ports/atmega8/hardware_user_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "util/delay.h" 7 | 8 | #define static_delay_us(x) _delay_us(x) 9 | #define static_delay_ms(x) _delay_ms(x) 10 | 11 | #define LAYOUT_SIZE 0 12 | -------------------------------------------------------------------------------- /ports/atmega8/scan.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "config.h" 7 | #include 8 | 9 | void matrix_init(void); 10 | bool matrix_scan_slow(void); 11 | void matrix_interrupt_mode(void); 12 | -------------------------------------------------------------------------------- /ports/efm8/boards/default/config.mk: -------------------------------------------------------------------------------- 1 | MCU = EFM8UB20F32 2 | MCU_SPECIFIC = EFM8UB20F32G_QFP32 3 | 4 | SETTINGS_ADDR = 0x7400 5 | LAYOUT_ADDR = 0x7600 6 | LAYOUT_SIZE = 0x0400 7 | FLASH_SIZE = $(CODE_SIZE) 8 | -------------------------------------------------------------------------------- /ports/efm8/boards/efm8ub10_qfn20/config.mk: -------------------------------------------------------------------------------- 1 | MCU = EFM8UB10F16 2 | MCU_SPECIFIC = EFM8UB10F16G_QFN20 3 | 4 | SETTINGS_ADDR = 0x7000 5 | LAYOUT_ADDR = 0x7200 6 | LAYOUT_SIZE = 0x0400 7 | FLASH_SIZE = $(CODE_SIZE) 8 | -------------------------------------------------------------------------------- /ports/efm8/boards/efm8ub30_qfn20/config.mk: -------------------------------------------------------------------------------- 1 | MCU = EFM8UB30F40 2 | MCU_SPECIFIC = EFM8UB30F40G_QFN20 3 | 4 | SETTINGS_ADDR = 0x7000 5 | LAYOUT_ADDR = 0x7200 6 | LAYOUT_SIZE = 0x0400 7 | FLASH_SIZE = $(CODE_SIZE) 8 | -------------------------------------------------------------------------------- /ports/efm8/doxygen.md: -------------------------------------------------------------------------------- 1 | @dir ports/efm8 2 | 3 | ## Feature support 4 | 5 | * USB 6 | -------------------------------------------------------------------------------- /ports/efm8/efm8/efm8_program.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | .PHONY: program-list 5 | program-list: 6 | $(INSPECT_8051) -slist 7 | 8 | .PHONY: program-efm8 9 | program-efm8: $(TARGET_HEX) 10 | $(FLASH_EFM8) -sn $(SERIAL_NUM) -upload $< -erasemode page 11 | 12 | .PHONY: program-c8051 13 | program-c8051: $(TARGET_HEX) 14 | $(FLASH_8051) -sn $(SERIAL_NUM) -upload $< -erasemode page 15 | 16 | .PHONY: program-hex-file 17 | program-hex-file: $(HEX_FILE) 18 | $(FLASH_8051) -sn $(SERIAL_NUM) -upload $< -erasemode full 19 | -------------------------------------------------------------------------------- /ports/efm8/efm8/efm8_util/delay.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "efm8_util/delay.h" 5 | 6 | // don't care too much if this isn't accurate 7 | void efm8_delay_us(uint16_t us) { 8 | while (us--) { 9 | __asm 10 | #if F_CPU >= 8000000ULL 11 | nop 12 | nop 13 | #endif 14 | #if F_CPU >= 16000000ULL 15 | nop 16 | nop 17 | #endif 18 | #if F_CPU >= 24000000ULL 19 | nop 20 | nop 21 | nop 22 | nop 23 | #endif 24 | #if F_CPU >= 32000000ULL 25 | nop 26 | nop 27 | nop 28 | nop 29 | #endif 30 | #if F_CPU >= 40000000ULL 31 | nop 32 | nop 33 | nop 34 | nop 35 | #endif 36 | #if F_CPU >= 48000000ULL 37 | nop 38 | nop 39 | nop 40 | nop 41 | #endif 42 | __endasm; 43 | } 44 | } 45 | 46 | void efm8_delay_ms(uint16_t ms) { 47 | while (ms--) { 48 | efm8_delay_us(1000); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ports/efm8/efm8/efm8_util/delay.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | void efm8_delay_us(uint16_t us); 7 | void efm8_delay_ms(uint16_t ms); 8 | -------------------------------------------------------------------------------- /ports/efm8/efm8/efm8_util/watchdog.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "efm8_util/io.h" 5 | 6 | // Disable the watchdog timer 7 | static inline 8 | void efm8_watchdog_disable(void) { 9 | PCA0MD &= ~PCA0MD_WDTE__BMASK; 10 | } 11 | -------------------------------------------------------------------------------- /ports/efm8/efm8/lib/efm8_assert/assert.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #ifndef NDEBUG 8 | void slab_Assert() 9 | { 10 | while ( 1 ); 11 | } 12 | #endif 13 | -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/C8051F380/USBXpress/c8051f380_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/C8051F380/USBXpress/c8051f380_usbxpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/C8051F380/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/C8051F380/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/C8051F380/meta-inf/appbuilder.properties: -------------------------------------------------------------------------------- 1 | frameworkId=c89051f380 2 | name=Silicon Labs C8051F380 Framework 3 | prefix=EFM8 4 | versionCategory=general 5 | architecture= 6 | #buildFileTemplates(sif930)=meta-inf/sif930.mak,meta-inf/sif930.uvopt,meta-inf/sif930.uvproj 7 | #buildFileTemplates(ezr32)=meta-inf/ezr32.mak,meta-inf/ezr32.eww,meta-inf/ezr32.ewd,meta-inf/ezr32.ewp 8 | #3buildFileTemplates(pc)=meta-inf/test.mak 9 | requiredIsdVersion=3.1.44 10 | #requiredSetups=boardHeader,callbackConfiguration,eventConfiguration,macros,additionalFiles,connectStackConfig 11 | 12 | # List of plugin option overrides 13 | #pluginOption(debug-print,usePort)=FALSE 14 | 15 | # Plugins info file, to declare virtual plugins and load the normal ones. 16 | pluginInfo=plugins.info 17 | 18 | # Location of sample apps properties file 19 | #sampleApps=../sample-apps/apps.info 20 | 21 | # Generator arguments 22 | generator.sourceroot=project 23 | generator.prependdevicename=true 24 | 25 | # Required feature level 26 | #requiredFeatureLevel=app_framework:6 27 | -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/C8051F380/meta-inf/callbacks.info: -------------------------------------------------------------------------------- 1 | #include PLATFORM_HEADER 2 | #include CONFIGURATION_HEADER 3 | #include "stack/include/ember.h" 4 | 5 | void main(void) 6 | { 7 | emberInit(); 8 | emberNetworkInit(); 9 | while (TRUE) { 10 | emberTick(); 11 | } 12 | } 13 | 14 | void emberIncomingMessageHandler(EmberIncomingMessage *message) 15 | { 16 | UNUSED_VAR(message); 17 | } 18 | 19 | void emberMessageSentHandler(EmberStatus status, EmberOutgoingMessage *message) 20 | { 21 | UNUSED_VAR(status); 22 | UNUSED_VAR(message); 23 | } 24 | 25 | void emberStackStatusHandler(EmberStatus status) 26 | { 27 | UNUSED_VAR(status); 28 | } 29 | 30 | void emberPacketTraceHandler(EmberMessageTrace *trace) 31 | { 32 | UNUSED_VAR(trace); 33 | } -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/C8051F380/meta-inf/layout.properties: -------------------------------------------------------------------------------- 1 | tabs=general, hal, plugins, callbacks, other 2 | 3 | general.name=General 4 | general.icon=EMBER 5 | general.0=application 6 | 7 | hal.name=HAL 8 | hal.icon=HAL 9 | hal.0=setup.boardHeader 10 | 11 | plugins.name=Plugins 12 | plugins.icon=PLUGIN 13 | plugins.0=plugins 14 | 15 | callbacks.name=Callbacks 16 | callbacks.icon=CALLBACK 17 | callbacks.0=setup.callbackConfiguration 18 | 19 | other.name=Other 20 | other.icon=OTHER 21 | other.0=setup.macros 22 | other.1=setup.eventConfiguration 23 | other.2=setup.additionalFiles 24 | other.3=setup.template 25 | 26 | -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/C8051F380/meta-inf/plugins.info: -------------------------------------------------------------------------------- 1 | This file can list directories where to load plugins from or 2 | # declare virtual plugins. 3 | # Any line that says: pluginDirectory=RELATIVE/PATH/ 4 | # will cause appbuilder to read in that directory for plugin subdirectories. 5 | # 6 | # Virtual plugins are declared with sections: 7 | # plugin(xxx) { 8 | # BLOCK IDENTICAL TO plugin.properties 9 | # } 10 | 11 | 12 | #pluginDirectory=../plugins/ 13 | 14 | 15 | -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB1/USBXpress/efm8ub1_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/EFM8UB1/USBXpress/efm8ub1_usbxpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB1/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/EFM8UB1/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB1/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB2/USBXpress/efm8ub2_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/EFM8UB2/USBXpress/efm8ub2_usbxpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB2/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/EFM8UB2/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB2/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | PCA0MD |= PCA0MD_WDTE__BMASK; 12 | PCA0CPH4 = 0x00; 13 | } 14 | 15 | void WDT0_stop() 16 | { 17 | PCA0MD &= ~PCA0MD_WDTE__BMASK; 18 | } 19 | 20 | void WDT0_feed() 21 | { 22 | PCA0CPH4 = 0x00; 23 | } 24 | 25 | void WDT0_init(uint8_t interval, 26 | WDT0_Timebase_t timebase, 27 | WDT0_IdleState_t idleState) 28 | { 29 | //Counter/Timer can not be modified when WDT enabled 30 | SLAB_ASSERT(!(PCA0MD & PCA0MD_WDTE__BMASK)); 31 | PCA0MD &= ~(PCA0MD_CPS__FMASK | PCA0MD_CIDL__BMASK); 32 | PCA0MD |= timebase + idleState; 33 | 34 | //Reload value is interval/256 35 | PCA0CPL4 = interval; 36 | } 37 | -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB3/USBXpress/efm8ub3_usbxpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/EFM8UB3/USBXpress/efm8ub3_usbxpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB3/VCPXpress/VCPXpress.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/efm8/mcu/EFM8UB3/VCPXpress/VCPXpress.lib -------------------------------------------------------------------------------- /ports/efm8/efm8/mcu/EFM8UB3/peripheral_driver/src/wdt_0.c: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * Copyright (c) 2015 by Silicon Laboratories Inc. All rights reserved. 3 | * 4 | * http://developer.silabs.com/legal/version/v11/Silicon_Labs_Software_License_Agreement.txt 5 | *****************************************************************************/ 6 | 7 | #include "wdt_0.h" 8 | #include "assert.h" 9 | 10 | void WDT0_start(){ 11 | WDTCN = 0xA5; 12 | } 13 | 14 | void WDT0_stop() 15 | { 16 | bool ea = IE_EA; 17 | IE_EA = 0; 18 | WDTCN = 0xDE; 19 | WDTCN = 0xAD; 20 | IE_EA = ea; 21 | } 22 | 23 | void WDT0_feed() 24 | { 25 | WDTCN = 0xA5; 26 | } 27 | 28 | void WDT0_init(uint8_t interval, 29 | WDT0_Timebase_t timebase, 30 | WDT0_IdleState_t idleState) 31 | { 32 | timebase=timebase; 33 | idleState=idleState; 34 | WDTCN = interval; 35 | } 36 | -------------------------------------------------------------------------------- /ports/efm8/efm8/scripts/hex-size.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | target_basename=`basename $1` 6 | target_dir=`dirname $1` 7 | old_hex_size_file="$target_dir/.old_hex_size-$target_basename.o" 8 | old_xram_size_file="$target_dir/.old_xram_size-$target_basename.o" 9 | 10 | code_size=$3 11 | 12 | old_hex_size=`cat "$old_hex_size_file"` 13 | hex_size=`size $1 | grep $1 | awk '{ printf $2 }'` 14 | if [[ $hex_size -eq "" ]]; then 15 | hex_size=0 16 | fi 17 | 18 | echo $hex_size > "$old_hex_size_file" 19 | printf -v size_in_hex "%x" "$hex_size" 20 | free_space16=$(($code_size - $hex_size)) 21 | echo -e "hex size: $hex_size \t0x$size_in_hex" 22 | echo "hex delta: $((hex_size - old_hex_size))" 23 | echo -e "free: $free_space16 (used $((100 * $hex_size / $code_size))% of $(($code_size)))" 24 | 25 | xram_info=$(grep "EXTERNAL RAM" $2) 26 | xram_used=$(echo $xram_info | awk '{ print $3; }') 27 | xram_total=$(echo $xram_info | awk '{ print $4; }') 28 | 29 | old_xram_size=`cat "$old_xram_size_file"` 30 | echo $xram_used > "$old_xram_size_file" 31 | echo -e "xram used: $xram_used ($((100 * $xram_used / $xram_total))% of $xram_total)" 32 | echo "xram delta: $((xram_used - old_xram_size))" 33 | -------------------------------------------------------------------------------- /ports/efm8/src/common.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | void usb_init(void); 7 | -------------------------------------------------------------------------------- /ports/efm8/src/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define USB_VID 0x1209 7 | #define USB_PID 0xBB00 8 | #define USB_DEVICE_VERSION 0x00 9 | 10 | #define INTERNAL_SCAN_METHOD MATRIX_SCANNER_INTERNAL_BASIC_SCAN 11 | 12 | // #define NO_MATRIX 13 | // #define MAX_NUM_ROWS 0 14 | 15 | #define USB_BUFFERED 0 16 | 17 | #define NO_SPLIT 1 18 | 19 | #ifndef BOOTLOADER_VID 20 | #define BOOTLOADER_VID 0x10C4 21 | #endif 22 | 23 | #ifndef BOOTLOADER_PID 24 | #if defined(EFM8UB1_DEVICE) 25 | #define BOOTLOADER_PID 0xEAC9 26 | #elif defined(EFM8UB2_DEVICE) 27 | #define BOOTLOADER_PID 0xEACA 28 | #elif defined(EFM8UB3_DEVICE) 29 | #define BOOTLOADER_PID 0xEACB 30 | #else 31 | #error "Unknown or unsupported device type." 32 | #endif 33 | #endif 34 | -------------------------------------------------------------------------------- /ports/efm8/src/efm8_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | -------------------------------------------------------------------------------- /ports/efm8/src/efm8_port_util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | /// @file 4 | /// 5 | /// @brief Functions for accessing the IO pins with indirect addressing 6 | /// 7 | /// 8051 has no way to access SFR with indirect addressing. This modules 8 | /// provide some functions for accessing the IO pins indirectly. 9 | 10 | #include 11 | 12 | /// @brief Initialize an EFM8 port registers. 13 | /// 14 | /// @param port_num The 8051 port number to setup 15 | /// @param mdout The value to set the EFM8 PxMDOUT register for the port. 16 | /// @param mdout The value to set the EFM8 PxMDIN register for the port. 17 | void efm8_port_setup(uint8_t port_num, uint8_t mdout, uint8_t mdin); 18 | 19 | /// @brief Reset the EFM8 IO port registers to their default state. 20 | void efm8_reset_ports(void); 21 | 22 | /// @brief Set bits in an 8051 port register 23 | /// 24 | /// @param port_num The 8051 port number to write 25 | void efm8_port_set(uint8_t port_num, uint8_t pin_mask); 26 | 27 | /// @brief Clear bits in an 8051 port register 28 | /// 29 | /// @param port_num The 8051 port number to write 30 | void efm8_port_clear(uint8_t port_num, uint8_t pin_mask); 31 | 32 | /// @brief Read bits from an 8051 port register 33 | /// 34 | /// @param port_num The 8051 port number to read 35 | uint8_t efm8_port_read(uint8_t port_num); 36 | -------------------------------------------------------------------------------- /ports/efm8/src/hardware.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/ports/efm8/src/hardware.c -------------------------------------------------------------------------------- /ports/efm8/src/io_map/efm8_20_pin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_0_NUM 0 7 | #define PORT_1_NUM 1 8 | #define PORT_2_NUM 2 9 | 10 | #define PORT_TO_NUM(port) ( \ 11 | (port == P0) ? (PORT_0_NUM) : \ 12 | (port == P1) ? (PORT_1_NUM) : \ 13 | (port == P2) ? (PORT_2_NUM) : 255 \ 14 | ) 15 | 16 | #define IO_PORT_COUNT 3 17 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_2_NUM, 1) ) 18 | 19 | #define PORT_0_USABLE_PINS 0xff 20 | #define PORT_1_USABLE_PINS 0x07 21 | #define PORT_2_USABLE_PINS 0x03 22 | 23 | #define IO_MAP_GPIO_COUNT (13) 24 | 25 | #ifndef IO_USABLE_PINS 26 | #define IO_USABLE_PINS { \ 27 | PORT_0_USABLE_PINS, \ 28 | PORT_1_USABLE_PINS, \ 29 | PORT_2_USABLE_PINS, \ 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /ports/efm8/src/io_map/efm8_24_pin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_0_NUM 0 7 | #define PORT_1_NUM 1 8 | #define PORT_2_NUM 2 9 | 10 | #define PORT_TO_NUM(port) ( \ 11 | (port == P0) ? (PORT_0_NUM) : \ 12 | (port == P1) ? (PORT_1_NUM) : \ 13 | (port == P2) ? (PORT_2_NUM) : 255 \ 14 | ) 15 | 16 | #define IO_PORT_COUNT 3 17 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_2_NUM, 1) ) 18 | 19 | #define PORT_0_USABLE_PINS 0xff 20 | #define PORT_1_USABLE_PINS 0x7f 21 | #define PORT_2_USABLE_PINS 0x03 22 | 23 | #define IO_MAP_GPIO_COUNT (17) 24 | 25 | #ifndef IO_USABLE_PINS 26 | #define IO_USABLE_PINS { \ 27 | PORT_0_USABLE_PINS, \ 28 | PORT_1_USABLE_PINS, \ 29 | PORT_2_USABLE_PINS, \ 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /ports/efm8/src/io_map/efm8_32_pin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_0_NUM 0 7 | #define PORT_1_NUM 1 8 | #define PORT_2_NUM 2 9 | #define PORT_3_NUM 3 10 | 11 | #define PORT_TO_NUM(port) ( \ 12 | (port == P0) ? (PORT_0_NUM) : \ 13 | (port == P1) ? (PORT_1_NUM) : \ 14 | (port == P2) ? (PORT_2_NUM) : \ 15 | (port == P3) ? (PORT_3_NUM) : 255 \ 16 | ) 17 | 18 | #define IO_PORT_COUNT 4 19 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_3_NUM, 0) ) 20 | 21 | #define PORT_0_USABLE_PINS 0xff 22 | #define PORT_1_USABLE_PINS 0xff 23 | #define PORT_2_USABLE_PINS 0xff 24 | #define PORT_3_USABLE_PINS 0x01 25 | 26 | #define IO_MAP_GPIO_COUNT (25) 27 | 28 | #ifndef IO_USABLE_PINS 29 | #define IO_USABLE_PINS { \ 30 | PORT_0_USABLE_PINS, \ 31 | PORT_1_USABLE_PINS, \ 32 | PORT_2_USABLE_PINS, \ 33 | PORT_3_USABLE_PINS, \ 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /ports/efm8/src/io_map/efm8_48_pin.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_0_NUM 0 7 | #define PORT_1_NUM 1 8 | #define PORT_2_NUM 2 9 | #define PORT_3_NUM 3 10 | #define PORT_4_NUM 4 11 | 12 | #define PORT_TO_NUM(port) ( \ 13 | (port == P0) ? (PORT_0_NUM) : \ 14 | (port == P1) ? (PORT_1_NUM) : \ 15 | (port == P2) ? (PORT_2_NUM) : \ 16 | (port == P3) ? (PORT_3_NUM) : \ 17 | (port == P4) ? (PORT_4_NUM) : 255 \ 18 | ) 19 | 20 | #define IO_PORT_COUNT 5 21 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_4_NUM, 0) ) 22 | 23 | #define PORT_0_USABLE_PINS 0xff 24 | #define PORT_1_USABLE_PINS 0xff 25 | #define PORT_2_USABLE_PINS 0xff 26 | #define PORT_3_USABLE_PINS 0xff 27 | #define PORT_4_USABLE_PINS 0xff 28 | 29 | #define IO_MAP_GPIO_COUNT (40) 30 | 31 | #ifndef IO_USABLE_PINS 32 | #define IO_USABLE_PINS { \ 33 | PORT_0_USABLE_PINS, \ 34 | PORT_1_USABLE_PINS, \ 35 | PORT_2_USABLE_PINS, \ 36 | PORT_3_USABLE_PINS, \ 37 | PORT_4_USABLE_PINS, \ 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /ports/efm8/src/port_impl/hardware.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/hardware.h" 5 | 6 | #include "peripheral_driver/inc/usb_0.h" 7 | #include "efm8_util/reset.h" 8 | 9 | void hardware_init(void) { 10 | } 11 | 12 | void pin_init(void) { 13 | } 14 | 15 | void reset_mcu(void) { 16 | // Disable the USB pull-up resistor, and wait a bit so the host has 17 | // a chance to see the device disconnect. 18 | USB_DisablePullUpResistor(); 19 | static_delay_ms(50); 20 | 21 | efm8_software_reset(); 22 | } 23 | 24 | void wdt_init(void) { 25 | } 26 | 27 | void wdt_kick(void) { 28 | } 29 | 30 | void bootloader_jmp(void) { 31 | USB_DisablePullUpResistor(); 32 | static_delay_ms(50); 33 | 34 | efm8_factory_bootloader_jump(); 35 | } 36 | -------------------------------------------------------------------------------- /ports/efm8/src/port_impl/hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "arch/8051/hardware.h" 7 | 8 | #include "efm8_util/io.h" 9 | 10 | // Some internal libraries define these because of keil, so get ride of them 11 | // so we can use them as identifiers 12 | #ifdef code 13 | #undef code 14 | #endif 15 | 16 | #ifdef bit 17 | #undef bit 18 | #endif 19 | 20 | #define enable_interrupts() do { \ 21 | IE_EA = 1; \ 22 | } while(0); 23 | 24 | #define disable_interrupts() do { \ 25 | IE_EA = 0; \ 26 | } while(0); 27 | 28 | // NOTE: not the best solution, but it's good enough 29 | #define dynamic_delay_us(t) efm8_delay_us(t) 30 | #define dynamic_delay_ms(t) efm8_delay_ms(t) 31 | 32 | #define static_delay_us(t) dynamic_delay_us(t) 33 | #define static_delay_ms(t) efm8_delay_ms(t) 34 | 35 | #define PAGE_SIZE 0x0200 36 | 37 | #define NO_IDLE_SLEEP 38 | 39 | #if (DEVICE_PKG_QFN20) 40 | #include "io_map/efm8_20_pin.h" 41 | #elif (DEVICE_PKG_QSOP24) 42 | #include "io_map/efm8_24_pin.h" 43 | #elif (DEVICE_PKG_QFN32) || (DEVICE_PKG_QFP32) 44 | #include "io_map/efm8_32_pin.h" 45 | #elif (DEVICE_PKG_QFP48) 46 | #include "io_map/efm8_48_pin.h" 47 | #else 48 | #error "Unknown package type" 49 | #endif 50 | -------------------------------------------------------------------------------- /ports/efm8/src/port_impl/led.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/led.h" 5 | 6 | void led_init(void) { 7 | } 8 | 9 | void led_testing_set(uint8_t led_number, uint8_t state) { 10 | UNREFERENCED_ARGUMENT(led_number); 11 | UNREFERENCED_ARGUMENT(state); 12 | } 13 | 14 | void led_testing_toggle(uint8_t led_num) { 15 | UNREFERENCED_ARGUMENT(led_num); 16 | } 17 | -------------------------------------------------------------------------------- /ports/efm8/src/port_impl/usb_reports.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "hid_reports/usb_reports.h" 5 | 6 | #include "usb_test.h" 7 | 8 | bit_t is_in_endpoint_ready(uint8_t endpoint_num) { 9 | return !USBD_EpIsBusy(endpoint_num); 10 | } 11 | 12 | bit_t is_out_endpoint_ready(uint8_t endpoint_num) { 13 | // // NOTE: only use one out endpoint 3, so just ignore endpoint_num arg 14 | UNREFERENCED_ARGUMENT(endpoint_num); 15 | return !USBD_EpIsBusy(EP3OUT); 16 | } 17 | 18 | void usb_write_in_endpoint( 19 | uint8_t endpoint_num, 20 | const XRAM uint8_t *data, 21 | uint8_t length 22 | ) { 23 | USBD_Write(endpoint_num, data, length, false); 24 | } 25 | 26 | void usb_read_out_endpoint( 27 | uint8_t endpoint_num, 28 | XRAM uint8_t *dest, 29 | uint8_t *length 30 | ) { 31 | UNREFERENCED_ARGUMENT(endpoint_num); 32 | if (USBD_Read(EP3OUT, dest, 64, false)) { 33 | *length = 0; 34 | } else { 35 | *length = 64; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /ports/efm8/src/usb_user_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | -------------------------------------------------------------------------------- /ports/linux/.gitignore: -------------------------------------------------------------------------------- 1 | stats.json 2 | -------------------------------------------------------------------------------- /ports/linux/etc/modules-load.d/keyplus.conf: -------------------------------------------------------------------------------- 1 | uinput 2 | -------------------------------------------------------------------------------- /ports/linux/etc/systemd/system/keyplusd.service: -------------------------------------------------------------------------------- 1 | [Unit] 2 | Description=keyplus emulator service 3 | 4 | [Service] 5 | Nice=-10 6 | User=keyplusd 7 | Group=keyplusd 8 | PIDFile=/tmp/keyplusd.lock 9 | StateDirectory=keyplusd 10 | StateDirectoryMode=0750 11 | StandardOutput=null 12 | StandardError=null 13 | StandardInput=null 14 | ExecStart=/usr/bin/keyplusd --as-user 15 | Restart=always 16 | 17 | [Install] 18 | WantedBy=multi-user.target 19 | -------------------------------------------------------------------------------- /ports/linux/etc/sysusers.d/keyplusd.conf: -------------------------------------------------------------------------------- 1 | #Type Name ID GECOS Home Directory Shell 2 | u keyplusd 394 "keyplus daemon user" /var/lib/keyplusd /sbin/nologin 3 | m keyplusd input - - 4 | -------------------------------------------------------------------------------- /ports/linux/setup.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # The user and group ID 4 | _id=394 5 | 6 | # Create the `keyplusd` user if it doesn't exist already 7 | if ! id -u keyplusd &> /dev/null; then 8 | groupadd -g $_id keyplusd 9 | useradd keyplusd \ 10 | --comment "keyplus daemon user" \ 11 | --system \ 12 | --home-dir "/" \ 13 | --shell /sbin/nologin \ 14 | --groups input \ 15 | --uid $_id \ 16 | --gid $_id 17 | fi 18 | -------------------------------------------------------------------------------- /ports/linux/src/cmdline.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | struct cmdline_args { 7 | const char* config; 8 | const char* lockfile; 9 | const char* stats; 10 | bool daemonize; 11 | bool restart; 12 | bool kill; 13 | }; 14 | 15 | void parse_cmdline_args(struct cmdline_args *args, int argc, char** argv); 16 | -------------------------------------------------------------------------------- /ports/linux/src/config.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define BOOTLOADER_VID 0 4 | #define BOOTLOADER_PID 0 5 | 6 | #define INTERNAL_SCAN_METHOD MATRIX_SCANNER_INTERNAL_NONE 7 | 8 | #define NO_MATRIX 9 | -------------------------------------------------------------------------------- /ports/linux/src/device_manager.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "core/settings.h" 9 | 10 | #include "udev_helpers.h" 11 | 12 | struct kp_evdev_device { 13 | int dev_id; 14 | int layout_id; 15 | char *path; 16 | struct libevdev *evdev; 17 | }; 18 | 19 | int device_manager_init(void); 20 | void device_manager_free(void); 21 | 22 | void device_manager_targets_reset(void); 23 | void device_manager_targets_add(virtual_device_header_t *target); 24 | 25 | int device_manager_enumerate(void); 26 | int device_manager_poll(bool block); 27 | -------------------------------------------------------------------------------- /ports/linux/src/keyplus_mainloop.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // TODO: probably move exit ability to a key_handler 7 | #ifndef DEBUG_EXIT_KEY 8 | #define DEBUG_EXIT_KEY KEY_F1 9 | #endif 10 | 11 | int kp_mainloop(int, const char **); 12 | void kp_mainloop_stop(void); 13 | -------------------------------------------------------------------------------- /ports/linux/src/port_impl/flash.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/flash.h" 5 | 6 | #include 7 | 8 | /// Emulates the flash read/write functionality used on the mcu 9 | -------------------------------------------------------------------------------- /ports/linux/src/port_impl/hardware.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/hardware.h" 5 | 6 | #include "debug.h" 7 | 8 | void hardware_init(void) { 9 | 10 | } 11 | 12 | NO_RETURN_ATTR void bootloader_jmp(void) { 13 | KP_LOG_ERROR("called unsupported function bootloader_jmp()"); 14 | exit(EXIT_FAILURE); 15 | } 16 | 17 | NO_RETURN_ATTR void reset_mcu(void) { 18 | KP_LOG_ERROR("called unsupported function reset_mcu()"); 19 | exit(EXIT_FAILURE); 20 | } 21 | -------------------------------------------------------------------------------- /ports/linux/src/port_impl/hardware.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #define F_CPU 0 6 | 7 | #define enable_interrupts() 8 | #define disable_interrupts() 9 | 10 | #define MCU_BITNESS 8 11 | #define IO_PORT_MAX_PIN_NUM 0 12 | #define IO_PORT_COUNT 0 13 | #define IO_MAP_GPIO_COUNT 0 14 | #define IO_USABLE_PINS {} 15 | 16 | #define SETTINGS_ADDR (0) 17 | #define LAYOUT_ADDR (SETTINGS_SIZE) 18 | #define LAYOUT_SIZE (4096 * 4) 19 | 20 | #define PAGE_SIZE 4096 21 | 22 | typedef int io_port_t; 23 | 24 | typedef size_t flash_addr_t; 25 | typedef size_t flash_size_t; 26 | typedef size_t flash_ptr_t; 27 | -------------------------------------------------------------------------------- /ports/linux/src/port_impl/timer.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/timer.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | static inline time_t ms_time(void) { 11 | int rc; 12 | struct timespec tp; 13 | 14 | rc = clock_gettime(CLOCK_MONOTONIC, &tp); 15 | if (rc < 0) { 16 | perror("clock_gettime() failed"); 17 | exit(EXIT_FAILURE); 18 | } 19 | return tp.tv_sec*1000 + (tp.tv_nsec / (1000*1000)); 20 | } 21 | 22 | uint8_t timer_read8_ms(void) { 23 | return ms_time(); 24 | } 25 | 26 | uint16_t timer_read16_ms(void) { 27 | return ms_time(); 28 | } 29 | 30 | uint32_t timer_read_ms(void) { 31 | return ms_time(); 32 | } 33 | -------------------------------------------------------------------------------- /ports/linux/src/port_impl/unused.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/led.h" 5 | 6 | void led_init(void) { 7 | } 8 | 9 | void led_testing_set(uint8_t led_number, uint8_t state) { 10 | } 11 | 12 | void led_testing_toggle(uint8_t led_num) { 13 | } 14 | -------------------------------------------------------------------------------- /ports/linux/src/settings_loader.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "settings_loader.h" 5 | 6 | #include "event_mapper.h" 7 | #include "device_manager.h" 8 | 9 | #include "debug.h" 10 | 11 | void load_virtual_device_settings(void) { 12 | flash_addr_t pos; 13 | uint32_t size; 14 | 15 | mapper_reset(); 16 | device_manager_targets_reset(); 17 | 18 | pos = LAYOUT_ADDR; 19 | flash_read((uint8_t*)&size, pos, sizeof(uint32_t)); 20 | pos += sizeof(uint32_t); 21 | 22 | KP_ASSERT(is_valid_storage_pos(pos + size)); 23 | 24 | while (pos < size) { 25 | struct virtual_device_header_t dev; 26 | flash_read((uint8_t*)&dev, pos, sizeof(dev)); 27 | device_manager_targets_add(&dev); 28 | pos += sizeof(virtual_device_header_t); 29 | 30 | mapper_set_map(dev.dev_id, virtual_storage_get_address(pos)); 31 | pos += KEY_MAP_SIZE; 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /ports/linux/src/settings_loader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | void load_virtual_device_settings(void); 7 | -------------------------------------------------------------------------------- /ports/linux/src/stats.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "event_codes.h" 8 | 9 | struct device_stats { 10 | uint8_t state; 11 | uint32_t keys[KEY_CNT]; 12 | }; 13 | 14 | enum { 15 | STATS_STATE_UNLOADED = 0, 16 | STATS_STATE_LOADED = 1, 17 | STATS_STATE_DISABLED = 2, 18 | }; 19 | 20 | void stats_reset(void); 21 | void stats_add_key(uint8_t dev_id, int event_code); 22 | void stats_set_press_count(uint8_t dev_id, int event_code, uint32_t press_count); 23 | void stats_enable_device(uint8_t dev_id, bool enable); 24 | 25 | void stats_load(const char *filename); 26 | void stats_save(const char *filename); 27 | -------------------------------------------------------------------------------- /ports/linux/src/stats_parser.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | int parse_stats_file(const char *filename); 7 | int parse_stats(const char *str, size_t len); 8 | const char* get_hid_code_name(uint16_t code); 9 | -------------------------------------------------------------------------------- /ports/linux/src/udev_helpers.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "core/layout.h" 11 | 12 | typedef enum udev_action { 13 | UDEV_ACTION_ADD, 14 | UDEV_ACTION_REMOVE, 15 | UDEV_ACTION_CHANGE, 16 | UDEV_ACTION_ONLINE, 17 | UDEV_ACTION_OFFLINE, 18 | } udev_action_type; 19 | 20 | typedef struct kp_udev_info { 21 | int kb_id; //< keyboard id to link to 22 | uint16_t vid; //< usb/hid vendor id 23 | uint16_t pid; //< usb/hid product id 24 | const char *serial; //< usb/hid serial number 25 | const char *name; //< usb/hid device name 26 | } kp_udev_info; 27 | 28 | int kp_udev_parse_action(struct udev_device *dev); 29 | int kp_udev_match(struct udev_device *dev, virtual_device_header_t *targets, size_t len); 30 | 31 | -------------------------------------------------------------------------------- /ports/linux/src/virtual_input.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | int create_virtual_keyboard(void); 7 | int create_virtual_mouse(void); 8 | 9 | void kp_virtual_keyboard_close(void); 10 | void kp_virtual_mouse_close(void); 11 | 12 | int kp_virtual_keyboard_send(unsigned int type, unsigned int code, int value); 13 | int kp_virtual_mouse_send(unsigned int type, unsigned int code, int value); 14 | -------------------------------------------------------------------------------- /ports/nrf24lu1/README.md: -------------------------------------------------------------------------------- 1 | # nrf24lu1+ port 2 | 3 | The nRF24LU1+ port acts as a wireless dongle for other keyplus keyboards. 4 | 5 | ## Functions support 6 | 7 | * USB 8 | * nRF24 wireless receiver 9 | -------------------------------------------------------------------------------- /ports/nrf24lu1/bins/nrf24lu1_bootloader-f16.hex: -------------------------------------------------------------------------------- 1 | :203E0000C2AF758150F183903E0005929086007F00F151F15102861890C7D67408F0E4F5E7 2 | :203E200020F8FEFFDFFEDEFBF0740390C7DEF0A3F090C7A9F0A3F0A3F0A3F0A3F0A3F07455 3 | :203E40002090C781F090C788F0A3F0C2C4F18330C4FBC2C490C7A8E0B4003690C7EEE0FFBC 4 | :203E6000A3E060027FFF90C7EBE0B4010790878D7E12C186B4020790879F7E29C186B4224F 5 | :203E80000E9087C87E18EE9FEE4001EFF8F15FE12FB4242975920030032590C7B6E05402F9 6 | :203EA00070F8F17090C64005928A8589847F40F151C2FDAA85A984D202DB02C203E12B90C2 7 | :203EC000C640E0FEA3E0FFBE011090C6807401F0A37401F090C7B77440F0BE020EF179EF91 8 | :203EE000C3337B08FA7900D203D202BE0320EF75F040A4F582E4200102744025F0F5830550 9 | :203F00009290C6807F40F15190C7B77440F0BE0404F179D202BE0609C201EF7002D201D2EC 10 | :203F200002BE070775B503F183E12990C7C7F030020D90C680E4F090C7B77440F0C2027427 11 | :203F40000390C7A9F0A3F0A3F090C7B47402F0C14D1592E0A30592F0A320FCFDDFF3220563 12 | :203F60009290C7008807F15190C7B5E8F078002275FAAA75FA55D2FD22F1708FFA20FCFD38 13 | :203F8000C2FD2275AB0F75ACFF75AD08221201100100000040151901010100000000010906 14 | :203FA0000229000101008019090400000203000000092111010001221800070581034000E2 15 | :203FC00001070501034000010600FF0900A180150025FF750895400901810209029102C0EA 16 | -------------------------------------------------------------------------------- /ports/nrf24lu1/bins/nrf24lu1_bootloader-f32.hex: -------------------------------------------------------------------------------- 1 | :207E0000C2AF758150F185907E0005929086007F00F153F15302861890C7D67408F0E4F561 2 | :207E200020F87D10FEFFDFFEDEFBDDF8F0740390C7DEF0A3F090C7A9F0A3F0A3F0A3F0A3AA 3 | :207E4000F0A3F0742090C781F090C788F0A3F0C2C4F18530C4FB90C7A8E0B4003690C7EEE8 4 | :207E6000E0FFA3E060027FFF90C7EBE0B4010790878F7E12C188B402079087A17E29C188FE 5 | :207E8000B4220E9087CA7E18EE9FEE4001EFF8F161E131B4242975920030032590C7B6E033 6 | :207EA000540270F8F17290C64005928A8589847F40F153C2FDAA85A984D202DB02C203E1E3 7 | :207EC0002D90C640E0FEA3E0FFBE011090C6807420F0A37400F090C7B77440F0BE020EF1DE 8 | :207EE0007BEFC3337B08FA7900D203D202BE0320EF75F040A4F582E4200102744025F0F52E 9 | :207F000083059290C6807F40F15390C7B77440F0BE0404F17BD202BE0609C201EF7002D2F3 10 | :207F200001D202BE070775B503F185E12B90C7C7F030020D90C680E4F090C7B77440F0C286 11 | :207F400002740390C7A9F0A3F0A3F090C7B47402F0C14F1592E0A30592F0A320FCFDDFF3D2 12 | :207F600022059290C7008807F15390C7B5E8F078002275FAAA75FA55D2FD22F1728FFA20C6 13 | :207F8000FCFDC2FD2275AB0F75ACFF75AD08221201100100000040091203BB01000000002E 14 | :207FA0000109022900010100801909040000020300000009211101000122180007058103D8 15 | :207FC000400001070501034000010600FF0900A180150025FF75089540090181020902912C 16 | :027FE00002C0DD 17 | -------------------------------------------------------------------------------- /ports/nrf24lu1/bins/testing-info-page.hex: -------------------------------------------------------------------------------- 1 | :10000000FFFFFFFFFFFFFFFFFFFFFF2ADE6FE5E4bb 2 | :00000001FF 3 | -------------------------------------------------------------------------------- /ports/nrf24lu1/boards/512_bootloader/config.mk: -------------------------------------------------------------------------------- 1 | 2 | # Generic nRF24LU1+ dongle 3 | SETTINGS_ADDR=0x6E00 4 | LAYOUT_ADDR=0x7000 5 | LAYOUT_SIZE=0x0C00 6 | NONCE_ADDR=0x7C00 7 | BOOTLOADER_ADDR=0x7E00 8 | 9 | # Use default settings for the other values. (see ./hardware_user_impl.h) 10 | CDEFS += -DUSE_UNIFYING_BOOTLOADER=0 11 | 12 | BOOTLOADER=bins/nrf24lu1_bootloader-f32.hex 13 | 14 | USE_MOUSE_GESTURE = 0 15 | 16 | ifeq ($(FLASH_SIZE), 16) 17 | BOOTLOADER=bins/nrf24lu1_bootloader-f16.hex 18 | CODE_SIZE=0x4000 19 | $(error "Curent build needs 32kb flash") 20 | else ifeq ($(FLASH_SIZE), 32) 21 | BOOTLOADER=bins/nrf24lu1_bootloader-f32.hex 22 | CODE_SIZE=0x8000 23 | else 24 | $(error Invalid size for flash='$(FLASH_SIZE)') 25 | endif 26 | -------------------------------------------------------------------------------- /ports/nrf24lu1/boards/default/config.mk: -------------------------------------------------------------------------------- 1 | $(error "Please provide the BOARD variable based on which bootloader you are using. Only use the board that matches your bootloader.") 2 | -------------------------------------------------------------------------------- /ports/nrf24lu1/boards/unirecv/config.mk: -------------------------------------------------------------------------------- 1 | 2 | # Unifying receiver 3 | SETTINGS_ADDR=0x6600 4 | LAYOUT_ADDR=0x6800 5 | LAYOUT_SIZE=0x0A00 6 | NONCE_ADDR=0x7200 7 | BOOTLOADER_ADDR=0x7400 8 | FLASH_SIZE=32 9 | 10 | CDEFS += -DUSE_UNIFYING_BOOTLOADER=1 11 | 12 | # Hexes using the unifying bootloader need to have the layout section erased 13 | KEYPLUS_CLI_LAYOUT_FLAGS=-e 14 | BOOTLOADER=/dev/null 15 | CODE_SIZE=0x8000 16 | 17 | USE_MOUSE_GESTURE = 0 18 | SUPPORT_MACRO = 1 19 | 20 | ifndef LAYOUT_FILE 21 | LAYOUT_FILE=blank 22 | endif 23 | -------------------------------------------------------------------------------- /ports/nrf24lu1/doxygen.md: -------------------------------------------------------------------------------- 1 | @dir ports/nrf24lu1 2 | 3 | ## Feature support 4 | 5 | * USB 6 | * nRF24 wireless receiver 7 | -------------------------------------------------------------------------------- /ports/nrf24lu1/scripts/flash_hex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | if [[ $# -ne 1 && $# -ne 2 ]]; then 6 | echo "Usage: $0 hex_file" 7 | fi 8 | 9 | ../host-software/keyplus_cli.py bootloader -d 6666:3333 10 | sleep 1.0 11 | ./nrf24lu1p-512-bootloader/scripts/flash.py write_hex $1 12 | -------------------------------------------------------------------------------- /ports/nrf24lu1/scripts/hex-size.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | target_basename=`basename $1` 6 | target_dir=`dirname $1` 7 | old_hex_size_file="$target_dir/.old_hex_size-$target_basename.o" 8 | old_xram_size_file="$target_dir/.old_xram_size-$target_basename.o" 9 | 10 | old_hex_size=`cat "$old_hex_size_file"` 11 | hex_size=`size $1 | grep $1 | awk '{ printf $2 }'` 12 | if [[ $hex_size -eq "" ]]; then 13 | hex_size=0 14 | fi 15 | echo $hex_size > "$old_hex_size_file" 16 | printf -v size_in_hex "%x" "$hex_size" 17 | free_space16=$((0x4000 - $hex_size)) 18 | free_space32=$((0x8000 - $hex_size)) 19 | echo -e "hex size: $hex_size \t0x$size_in_hex" 20 | echo "hex delta: $((hex_size - old_hex_size))" 21 | echo -e "free f16: $free_space16 (used $((100 * $hex_size / 0x4000))% of $((0x4000)))" 22 | echo -e "free f32: $free_space32 (used $((100 * $hex_size / 0x8000))% of $((0x8000)))" 23 | 24 | xram_info=$(grep "EXTERNAL RAM" $2) 25 | xram_used=$(echo $xram_info | awk '{ print $5; }') 26 | xram_total=$(echo $xram_info | awk '{ print $6; }') 27 | 28 | old_xram_size=`cat "$old_xram_size_file"` 29 | echo $xram_used > "$old_xram_size_file" 30 | echo -e "xram used: $xram_used ($((100 * $xram_used / $xram_total))% of $xram_total)" 31 | echo "xram delta: $((xram_used - old_xram_size))" 32 | -------------------------------------------------------------------------------- /ports/nrf24lu1/scripts/pretty_hex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | if [[ $# -ne 1 ]]; then 6 | echo "no hexfile given" 7 | exit 1 8 | fi 9 | 10 | 11 | target_file="$(basename -s ".hex" $1)-pretty.hex" 12 | hex2bin.py $1 | bin2hex.py - > "$target_file" 13 | -------------------------------------------------------------------------------- /ports/nrf24lu1/scripts/strip_chip_id.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # We use record type 0x05 to hold the CHIP ID. The `nrfburn` command can't 4 | # handle this record, so this command strips it from a hex file 5 | sed '/^:04000005/d' $1 6 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef DEVICE_ID 7 | #define DEVICE_ID 0x30 8 | #endif 9 | 10 | #ifndef USB_VID 11 | #define USB_VID 0x1209 12 | #endif 13 | 14 | #ifndef USB_PID 15 | #define USB_PID 0xBB02 16 | #endif 17 | 18 | #if USE_UNIFYING_BOOTLOADER 19 | #define BOOTLOADER_VID 0x046d 20 | #define BOOTLOADER_PID 0xaaaa 21 | #else 22 | #define BOOTLOADER_VID 0x1915 23 | #define BOOTLOADER_PID 0x0101 24 | #endif 25 | 26 | #ifndef USB_DEVICE_VERSION 27 | #define USB_DEVICE_VERSION 0x0000 28 | #endif 29 | 30 | #define RF_POLLING 0 31 | #define USB_BUFFERED 0 32 | 33 | #define NO_MATRIX 34 | 35 | // nRF24LU1+ dongle only needs 50mA max current 36 | #define CUSTOM_USB_CURRENT_LIMIT 50 37 | 38 | // Use the SPI handling provided by core/nrf24.c 39 | #define NRF24_INBUILT_SPI_HANDLING 1 40 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/crtxinit.S: -------------------------------------------------------------------------------- 1 | ; Copyright 2017 jem@seethis.link 2 | ; Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | .area GSINIT3 (CODE) 5 | 6 | XRAM_SIZE = 0x800 7 | XRAM_START = 0x8000 8 | 9 | USE_XINIT = 1 10 | 11 | ; Initializes variables for the SDCC C compiler 12 | ; need to copy XINIT to XISEG 13 | __mcs51_genXINIT:: 14 | .if USE_XINIT 15 | ; init xram 16 | orl _DPS, #0x01 17 | mov dptr, #s_XINIT ; dptr1 == s_XINIT (src) 18 | dec _DPS 19 | mov dptr, #s_XISEG ; dptr0 == s_XISEG (dest) 20 | 21 | mov r1, #l_XINIT ; LSB 22 | mov r2, #((l_XINIT+255) >> 8) 23 | 00001$: 24 | ; read byte 25 | inc _DPS 26 | movx a, @dptr 27 | inc dptr 28 | ; copy byte 29 | mov _DPS, #0x00 30 | movx @dptr, a 31 | inc dptr 32 | 33 | djnz r1, 00001$ 34 | djnz r2, 00001$ 35 | .endif 36 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/debug.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/led.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/led.h" 5 | 6 | #include "nrf24lu1.h" 7 | 8 | void led_init(void) { 9 | P0 = 0x30; // P05..4==1, P03..0==0 10 | 11 | P0ALT = 0x00; // all GPIO default behavior 12 | P0EXP = 0x00; 13 | 14 | /* P0DIR = 0x00; // all out; LED is on P03 */ 15 | P0DIR = 0x20; // P05 input, P04..0==0 16 | 17 | P03 = 0; 18 | } 19 | 20 | void led_testing_set(uint8_t led_number, uint8_t state) { 21 | if (led_number == 0) { 22 | P03 = state; 23 | } 24 | } 25 | 26 | void led_testing_toggle(uint8_t led_num) { 27 | UNREFERENCED_ARGUMENT(led_num); 28 | P03 = !P03; 29 | } 30 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/nrf24.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include "nrf24lu1.h" 7 | #include "core/nrf24.h" 8 | #include "core/rf.h" 9 | 10 | void nrf24_init(void) { 11 | RFCTL = 0x11; // enable SPI, 1/2 clock 12 | RFCON = 0x04; // enable RF clock, CSN low, CE low 13 | } 14 | 15 | inline uint8_t nrf24_spi_send_byte(uint8_t byte) { 16 | RFDAT = byte; 17 | RFSPIF = 0; 18 | while (!RFSPIF); 19 | byte = RFDAT; 20 | return byte; 21 | } 22 | 23 | inline void nrf24_csn(uint8_t val) { 24 | RFCSN = val; 25 | } 26 | 27 | inline void nrf24_ce(uint8_t val) { 28 | RFCE = val; 29 | } 30 | 31 | uint8_t nrf24_irq(void) { 32 | return RFIRQ; 33 | } 34 | 35 | void rf_enable_receive_irq(void) { 36 | RF_IRQEN = 1; 37 | } 38 | 39 | void rf_init_receive_irq(void) { 40 | rf_enable_receive_irq(); 41 | } 42 | 43 | void rf_disable_receive_irq(void) { 44 | RF_IRQEN = 0; 45 | } 46 | 47 | void nrf24lu1_rf_isr(void) __interrupt (ISR_RFIRQ) { 48 | rf_isr(); 49 | } 50 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/port_impl/hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // include common definitions for 8051 7 | #include "arch/8051/hardware.h" 8 | 9 | #include "nrf24lu1.h" 10 | 11 | #define enable_interrupts() do { \ 12 | EA = 1; \ 13 | } while(0); 14 | 15 | #define disable_interrupts() do { \ 16 | EA = 0; \ 17 | } while(0); 18 | 19 | // NOTE: not the best solution, but it's good enough 20 | void dynamic_delay_us(uint16_t us); 21 | #define static_delay_us(x) dynamic_delay_us(x) 22 | #define static_delay_ms(x) dynamic_delay_ms(x) 23 | 24 | #define PAGE_SIZE 0x0200 25 | 26 | #ifndef BOOTLOADER_ADDR 27 | #define BOOTLOADER_SIZE (1*PAGE_SIZE) 28 | #define BOOTLOADER_ADDR (FLASH_SIZE - BOOTLOADER_SIZE) 29 | #define BOOTLOADER_PAGE_COUNT (BOOTLOADER_SIZE / PAGE_SIZE) 30 | #define BOOTLOAEDR_PAGE_NUM (BOOTLOADER_ADDR / PAGE_SIZE) 31 | #endif 32 | 33 | #define LOGITECH_BOOTLOADER_ADDR 0x7400 34 | 35 | #ifndef NONCE_ADDR 36 | #define NONCE_ADDR (BOOTLOADER_ADDR - 1*PAGE_SIZE) 37 | #endif 38 | 39 | #define NO_IDLE_SLEEP 40 | 41 | #define IO_PORT_COUNT 0 42 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/usb_reports.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include "nrf24lu1_usb.h" 7 | #include "nrf24lu1_usb_regs.h" 8 | 9 | #include "core/util.h" 10 | 11 | #include "hid_reports/usb_reports.h" 12 | 13 | bit_t is_in_endpoint_ready(uint8_t endpoint_num) { 14 | return (USB_EP_IN_CS(endpoint_num) & CS_BSY) == 0; 15 | } 16 | 17 | void usb_write_in_endpoint( 18 | uint8_t endpoint_num, 19 | const XRAM uint8_t *data, 20 | uint8_t length 21 | ) { 22 | memcpy( 23 | USB_EP_IN_BUF(endpoint_num), 24 | data, 25 | length 26 | ); 27 | USB_EP_IN_BC(endpoint_num) = length; 28 | } 29 | 30 | extern XRAM uint8_t g_has_received_usb_data; 31 | 32 | bit_t is_out_endpoint_ready(uint8_t endpoint_num) { 33 | return is_bitn_set(g_has_received_usb_data, endpoint_num); 34 | } 35 | 36 | void usb_read_out_endpoint( 37 | uint8_t endpoint_num, 38 | XRAM uint8_t *dest, 39 | uint8_t *length 40 | ) { 41 | *length = USB_EP_OUT_BC(endpoint_num); 42 | memcpy( 43 | dest, 44 | USB_EP_OUT_BUF(endpoint_num), 45 | *length 46 | ); 47 | USB_EP_OUT_BC(endpoint_num) = 0xff; 48 | g_has_received_usb_data &= ~(1 << endpoint_num); 49 | } 50 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/usb_user_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "nrf24lu1_usb.h" 7 | #include "nrf24lu1_usb_regs.h" 8 | 9 | #define USB_EP0_IN_BUF (in0buf) 10 | 11 | #define USB_EP0_IN_WRITE(x) (in0bc = x) 12 | 13 | // clear hsnak bit 14 | #define USB_EP0_HSNAK() (ep0cs = EP0CS_HSNAK_bm) 15 | 16 | // set stall and dstall bits to stall during setup data transaction 17 | #define USB_EP0_STALL() (ep0cs = (EP0CS_DSTALL_bm | EP0CS_EP0STALL_bm)) 18 | -------------------------------------------------------------------------------- /ports/nrf24lu1/src/util.c: -------------------------------------------------------------------------------- 1 | 2 | static uint8_t read_info_page_byte(uint16_t addr) { 3 | __asm 4 | ; addr -> (DPL, DPH) 5 | set _INFEN ; make movx read from info page 6 | movx a, @dptr ; read value at addr (dptr) 7 | clr _INFEN ; disable reading from info page 8 | mov _DPL, a ; return value is stored in DPL 9 | __endasm; 10 | } 11 | -------------------------------------------------------------------------------- /ports/nrf52/.gitignore: -------------------------------------------------------------------------------- 1 | dev-tools 2 | documentation 3 | -------------------------------------------------------------------------------- /ports/nrf52/boards/nrf52840_dk/board_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | -------------------------------------------------------------------------------- /ports/nrf52/boards/nrf52840_dk/config.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2019 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | MCU = nrf52840 5 | MCU_STRING = nRF52840_QIAA 6 | NRF52_LINK_SCRIPT := ld-scripts/plain_nrf52840.ld 7 | 8 | C_SRC += \ 9 | $(BOARD_DIR)/$(BOARD)/led.c 10 | 11 | CDEFS += -DDEBUG 12 | 13 | 14 | USE_SOFTDEVICE := 0 15 | USE_BLUETOOTH := 0 16 | 17 | USE_USB := 1 18 | USE_SCANNER := 1 19 | USE_NRF24 := 1 20 | USE_NRF52_ESB := 1 21 | USE_UNIFYING := 1 22 | USE_CHECK_PIN := 0 23 | USE_I2C := 0 24 | -------------------------------------------------------------------------------- /ports/nrf52/boards/nrf52840_dk_ble/board_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | -------------------------------------------------------------------------------- /ports/nrf52/boards/nrf52840_dk_ble/config.mk: -------------------------------------------------------------------------------- 1 | 2 | LAYOUT_FILE ?= $(KEYPLUS_PATH)/../layouts/nrf52_4key.yaml 3 | RF_FILE ?= $(KEYPLUS_PATH)/../layouts/test_rf_config2.yaml 4 | 5 | MCU = nrf52840 6 | MCU_STRING = nRF52840_QIAA 7 | NRF52_LINK_SCRIPT := ld-scripts/s140_ble.ld 8 | 9 | GDB_CMD_FILE = $(BOARD_DIR)/$(BOARD)/gdb_cmds 10 | 11 | C_SRC += \ 12 | $(BOARD_DIR)/$(BOARD)/led.c \ 13 | 14 | 15 | USE_SOFTDEVICE := 1 16 | USE_BLUETOOTH := 1 17 | 18 | USE_USB := 1 19 | USE_SCANNER := 1 20 | USE_NRF24 := 1 21 | USE_NRF52_ESB := 1 22 | USE_UNIFYING := 1 23 | USE_CHECK_PIN := 0 24 | USE_I2C := 0 25 | -------------------------------------------------------------------------------- /ports/nrf52/boards/nrf52840_dk_ble/gdb_cmds: -------------------------------------------------------------------------------- 1 | # vim: ft=gdb 2 | target remote localhost:2331 3 | mon speed 10000 4 | mon flash download=1 5 | file ./build/nrf52840_dk_ble/nrf52_keyplus-nrf52840_dk_ble.out 6 | -------------------------------------------------------------------------------- /ports/nrf52/boards/nrf52840_dongle/board_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #define BOOTLOADER_VID 0x1915 5 | #define BOOTLOADER_PID 0x521f 6 | -------------------------------------------------------------------------------- /ports/nrf52/boards/nrf52840_dongle/config.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2019 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | MCU = nrf52840 5 | MCU_STRING = nRF52840_QIAA 6 | NRF52_LINK_SCRIPT := ld-scripts/mbr_nrf52840.ld 7 | 8 | # Bootloader reset pin on P0.19 9 | CDEFS += -DBOOTLOADER_RESET_PIN=19 10 | 11 | C_SRC += \ 12 | $(BOARD_DIR)/$(BOARD)/led.c 13 | 14 | 15 | USE_SOFTDEVICE := 0 16 | USE_BLUETOOTH := 0 17 | 18 | USE_USB := 1 19 | USE_SCANNER := 1 20 | USE_NRF24 := 1 21 | USE_NRF52_ESB := 1 22 | USE_UNIFYING := 1 23 | USE_CHECK_PIN := 0 24 | USE_I2C := 0 25 | -------------------------------------------------------------------------------- /ports/nrf52/gdb_cmds: -------------------------------------------------------------------------------- 1 | # vim: ft=gdb 2 | target remote localhost:2331 3 | mon speed 10000 4 | mon flash download=1 5 | # file ./build/nrf52840_dk_ble/nrf52_keyplus-nrf52840_dk_ble.out 6 | # file ./build/nrf52840_dk/nrf52_keyplus-nrf52840_dk.out 7 | -------------------------------------------------------------------------------- /ports/nrf52/src/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "board_config.h" 5 | 6 | #ifndef USB_VID 7 | #define USB_VID 0x1209 8 | #endif 9 | 10 | #ifndef USB_PID 11 | #define USB_PID 0xBB00 12 | #endif 13 | 14 | #ifndef USB_DEVICE_VERSION 15 | #define USB_DEVICE_VERSION 0x0000 16 | #endif 17 | 18 | #if !defined(BOOTLOADER_VID) && !defined(BOOTLOADER_PID) 19 | // TODO: lookup values for open and secure bootloader nrf52 20 | #define BOOTLOADER_VID 0x1915 21 | #define BOOTLOADER_PID 0x521f 22 | #endif 23 | 24 | #define SCANNER_MATRIX_DELTA 1 25 | 26 | #define INTERNAL_SCAN_METHOD (MATRIX_SCANNER_INTERNAL_FAST_ROW_COL) 27 | 28 | // Don't use the SPI handling provided by core/nrf24.c 29 | #define NRF24_INBUILT_SPI_HANDLING 0 30 | 31 | // Don't use the IRQ pin 32 | #define RF_POLLING 1 33 | 34 | #define USB_BUFFERED 1 35 | -------------------------------------------------------------------------------- /ports/nrf52/src/esb_timeslot.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include "nrf_esb.h" 7 | 8 | #include "extra/fifo.h" 9 | 10 | typedef struct timeslot_stats_t { 11 | uint32_t start; 12 | uint32_t end; 13 | uint32_t rx; 14 | uint32_t tx; 15 | uint32_t extensions; 16 | uint32_t blocked; 17 | uint32_t canceled; 18 | } timeslot_stats_t; 19 | 20 | 21 | struct timeslot_stats_t get_timeslot_stats(void); 22 | 23 | /// @brief Initialize timeslot handling 24 | uint32_t esb_timeslot_init(void); 25 | 26 | /// @brief Start requesting timeslots 27 | uint32_t esb_timeslot_start(void); 28 | 29 | /// @brief Stop requesting timeslots 30 | uint32_t esb_timeslot_stop(void); 31 | 32 | void esb_timeslot_ack_payload(nrf_esb_payload_t *tx_payload); 33 | 34 | /// @brief handler for system events 35 | void soc_evt_handler(uint32_t sys_evt, void *p_context); 36 | 37 | // NOTE: included here because the NRF_SDH_SOC_OBSERVER handler is in this file. 38 | void set_flash_busy_bit(void); 39 | bool is_flash_busy(void); 40 | -------------------------------------------------------------------------------- /ports/nrf52/src/io_map/nrf52810.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_0_NUM 0 7 | 8 | #define PORT_TO_NUM(port) ( \ 9 | (port == NRF_P0) ? (PORT_0_NUM) : 255 \ 10 | ) 11 | 12 | #define IO_PORT_COUNT GPIO_COUNT 13 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_0_NUM, 31) ) 14 | 15 | #define PORT_0_USABLE_PINS 0xffffffff 16 | 17 | #define IO_MAP_GPIO_COUNT (32) 18 | 19 | #ifndef IO_USABLE_PINS 20 | #define IO_USABLE_PINS { \ 21 | PORT_0_USABLE_PINS, \ 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /ports/nrf52/src/io_map/nrf52811.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_0_NUM 0 7 | 8 | #define PORT_TO_NUM(port) ( \ 9 | (port == NRF_P0) ? (PORT_0_NUM) : 255 \ 10 | ) 11 | 12 | #define IO_PORT_COUNT GPIO_COUNT 13 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_0_NUM, 31) ) 14 | 15 | #define PORT_0_USABLE_PINS 0xffffffff 16 | 17 | #define IO_MAP_GPIO_COUNT (32) 18 | 19 | #ifndef IO_USABLE_PINS 20 | #define IO_USABLE_PINS { \ 21 | PORT_0_USABLE_PINS, \ 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /ports/nrf52/src/io_map/nrf52832.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define PORT_0_NUM 0 7 | 8 | #define PORT_TO_NUM(port) ( \ 9 | (port == NRF_P0) ? (PORT_0_NUM) : 255 \ 10 | ) 11 | 12 | #define IO_PORT_COUNT GPIO_COUNT 13 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_0_NUM, 31) ) 14 | 15 | #define PORT_0_USABLE_PINS 0xffffffff 16 | 17 | #define IO_MAP_GPIO_COUNT (32) 18 | 19 | #ifndef IO_USABLE_PINS 20 | #define IO_USABLE_PINS { \ 21 | PORT_0_USABLE_PINS, \ 22 | } 23 | #endif 24 | -------------------------------------------------------------------------------- /ports/nrf52/src/io_map/nrf52840.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "nrf_gpio.h" 7 | 8 | #define PORT_0_NUM 0 9 | #define PORT_1_NUM 1 10 | 11 | #define PORT_TO_NUM(port) ( \ 12 | (port == NRF_P0) ? (PORT_0_NUM) : \ 13 | (port == NRF_P1) ? (PORT_1_NUM) : 255 \ 14 | ) 15 | 16 | #define IO_PORT_COUNT (GPIO_COUNT) 17 | #define IO_PORT_MAX_PIN_NUM ( IO_MAP_PIN_NUMBER(PORT_1_NUM, 15) ) 18 | 19 | #define PORT_0_USABLE_PINS 0xffffffff 20 | #define PORT_1_USABLE_PINS 0x0000ffff 21 | 22 | #define IO_MAP_GPIO_COUNT (32 + 16) 23 | 24 | #ifndef IO_USABLE_PINS 25 | #define IO_USABLE_PINS { \ 26 | PORT_0_USABLE_PINS, \ 27 | PORT_1_USABLE_PINS, \ 28 | } 29 | #endif 30 | -------------------------------------------------------------------------------- /ports/nrf52/src/kp_ble/hid.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "kp_ble/hid.h" 5 | 6 | #include "ble_hids.h" 7 | -------------------------------------------------------------------------------- /ports/nrf52/src/nrf52_usb.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | void usb_setup_nrf(void); 7 | 8 | bool is_usb_configured(void); 9 | bool is_usb_suspended(void); 10 | bool is_usb_remote_wakeup_enabled(void); 11 | void usb_init_power_clock(void); 12 | -------------------------------------------------------------------------------- /ports/nrf52/src/port_impl/hardware.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/hardware.h" 5 | 6 | #include "nrf_gpio.h" 7 | #include "nrf_log.h" 8 | #include "nrf_log_ctrl.h" 9 | #include "nrf_nvic.h" 10 | 11 | #include "serial_num.h" 12 | 13 | void hardware_init(void) { 14 | nrf52_init_serial_number(); 15 | } 16 | 17 | void bootloader_jmp(void) { 18 | #if BOOTLOADER_RESET_PIN 19 | NRF_LOG_FINAL_FLUSH(); 20 | static_delay_ms(100); 21 | 22 | nrf_gpio_cfg_output(BOOTLOADER_RESET_PIN); 23 | nrf_gpio_pin_clear(BOOTLOADER_RESET_PIN); 24 | #endif 25 | 26 | while (1) { } 27 | } 28 | 29 | void reset_mcu(void) { 30 | NRF_LOG_FINAL_FLUSH(); 31 | static_delay_ms(100); 32 | 33 | #if HAS_SOFTDEVICE 34 | sd_nvic_systemreset(); 35 | #else 36 | NVIC_SystemReset(); 37 | #endif 38 | 39 | while (1) { } 40 | } 41 | 42 | void wdt_kick(void) { 43 | // TODO: 44 | } 45 | -------------------------------------------------------------------------------- /ports/nrf52/src/port_impl/hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "nrf_nvic.h" 7 | #include "nrf_delay.h" 8 | #include "nrfx.h" 9 | 10 | #include "app_util_platform.h" 11 | 12 | #define static_delay_us(x) nrf_delay_us(x) 13 | #define static_delay_ms(x) nrf_delay_ms(x) 14 | 15 | // When using a SOFT DEVICE use these to disable all non-vital interrupts 16 | #define enable_interrupts() CRITICAL_REGION_EXIT() 17 | #define disable_interrupts() CRITICAL_REGION_ENTER() 18 | 19 | #define PAGE_SIZE 4096 20 | 21 | // define flash pointer sizes 22 | typedef uint32_t flash_ptr_t; 23 | typedef uint32_t flash_addr_t; 24 | typedef uint32_t flash_size_t; 25 | 26 | #define MCU_BITNESS 32 27 | #define IO_PORT_SIZE 32 28 | typedef NRF_GPIO_Type io_port_t; 29 | 30 | #if NRF52810_XXAA 31 | #include "io_map/nrf52810.h" 32 | #elif NRF52811_XXAA 33 | #include "io_map/nrf52811.h" 34 | #elif NRF52832_XXAA 35 | #include "io_map/nrf52832.h" 36 | #elif NRF52840_XXAA 37 | #include "io_map/nrf52840.h" 38 | #else 39 | #error "NRF chip type not defined" 40 | #endif 41 | -------------------------------------------------------------------------------- /ports/nrf52/src/port_impl/io_map.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/hardware.h" 5 | 6 | io_port_t * const g_io_port_map[IO_PORT_COUNT] = { 7 | NRF_P0, 8 | #if IO_PORT_COUNT > 1 9 | NRF_P1, 10 | #endif 11 | }; 12 | -------------------------------------------------------------------------------- /ports/nrf52/src/port_impl/led.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/led.h" 5 | 6 | WEAK void led_init(void) { 7 | } 8 | 9 | WEAK void led_testing_set(uint8_t led_num, uint8_t state) { 10 | } 11 | 12 | WEAK void led_testing_toggle(uint8_t led_num) { 13 | } 14 | -------------------------------------------------------------------------------- /ports/nrf52/src/serial_num.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "serial_num.h" 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "nrf_drv_usbd.h" 11 | #include "nrf_log.h" 12 | 13 | #include "usb/descriptors.h" 14 | 15 | serial_num_t g_nrf52_serial_number; 16 | 17 | uint16_t g_nrf52_serial_usb_desc[SERIAL_NUMBER_STRING_SIZE+1]; 18 | 19 | void nrf52_init_serial_number(void) { 20 | char serial_number_string[SERIAL_NUMBER_STRING_SIZE + 1]; 21 | 22 | // The masking makes the address match the Random Static BLE address. 23 | g_nrf52_serial_number.high = (uint16_t)NRF_FICR->DEVICEADDR[1] | 0xC000, 24 | g_nrf52_serial_number.low = NRF_FICR->DEVICEADDR[0], 25 | 26 | (void)snprintf(serial_number_string, 27 | SERIAL_NUMBER_STRING_SIZE + 1, 28 | "%04hX%08lX", 29 | g_nrf52_serial_number.high, 30 | g_nrf52_serial_number.low); 31 | 32 | // USB string descriptors are encoded as utf-16le, with no null terminator 33 | g_nrf52_serial_usb_desc[0] = USB_STRING_DESC_SIZE((SERIAL_NUMBER_STRING_SIZE+1)*sizeof(uint16_t)); 34 | 35 | for (int i = 0; i < SERIAL_NUMBER_STRING_SIZE; ++i) { 36 | g_nrf52_serial_usb_desc[i+1] = serial_number_string[i]; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ports/nrf52/src/serial_num.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #define SERIAL_NUMBER_STRING_SIZE (12) 7 | 8 | typedef struct serial_num_t { 9 | uint16_t high; 10 | uint32_t low; 11 | } serial_num_t; 12 | 13 | void nrf52_init_serial_number(void); 14 | 15 | extern serial_num_t g_nrf52_serial_number; 16 | extern uint16_t g_nrf52_serial_usb_desc[SERIAL_NUMBER_STRING_SIZE+1]; 17 | -------------------------------------------------------------------------------- /ports/nrf52/src/usb_user_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | // TODO: 7 | 8 | // #define USB_EP0_IN_BUF 0 9 | // #define USB_EP0_IN_WRITE(x) usb_ep0_in(x) 10 | // #define USB_EP0_HSNAK() 11 | // #define USB_EP0_STALL() usb_ep0_stall() 12 | -------------------------------------------------------------------------------- /ports/xmega/.gitignore: -------------------------------------------------------------------------------- 1 | *.fuse 2 | -------------------------------------------------------------------------------- /ports/xmega/boards/alpha_split/board_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | // This file lists pins that have function locked at compile time. 5 | 6 | // Alpha split: 7 | // Locked pins are: 8 | // 9 | // C1: VBUS pin 10 | // E3: OE_RIGHT_PORT 11 | // R0: OE_LEFT_PORT 12 | // R1: USB_OE 13 | 14 | #define IO_USABLE_PINS { \ 15 | PORT_A_USABLE_PINS, \ 16 | PORT_B_USABLE_PINS, \ 17 | PORT_C_USABLE_PINS & (~PIN1_bm), \ 18 | PORT_D_USABLE_PINS, \ 19 | PORT_E_USABLE_PINS & (~PIN3_bm), \ 20 | PORT_R_USABLE_PINS & (~PIN0_bm) & (~PIN1_bm), \ 21 | } 22 | -------------------------------------------------------------------------------- /ports/xmega/boards/alpha_split/config.mk: -------------------------------------------------------------------------------- 1 | # Build settings for alpha_split 2 | 3 | ifndef MCU 4 | MCU = atxmega64a4u 5 | endif 6 | 7 | # C_SRC += boards/alpha_split/alpha_split_util.c 8 | 9 | CDEFS += -DVBUS_PIN_PORT=C 10 | CDEFS += -DVBUS_PIN_NUM=1 11 | CDEFS += -DVBUS_PIN_INT_NUM=1 12 | 13 | CDEFS += -DNRF24_IRQ_PIN_PORT=B 14 | CDEFS += -DNRF24_IRQ_PIN_NUM=3 15 | CDEFS += -DNRF24_IRQ_INT_NUM=1 16 | 17 | # VBUS_CHECK pin on pin C1 18 | # CDEFS += -DI2C_LEFT_PORT=PORTR 19 | # CDEFS += -DI2C_LEFT_PIN=PIN0_bm 20 | 21 | # CDEFS += -DI2C_RIGHT_PORT=PORTE 22 | # CDEFS += -DI2C_RIGHT_PIN=PIN3_bm 23 | 24 | # CDEFS += -DUSB_SEL_PORT=PORTE 25 | # CDEFS += -DUSB_SEL_PIN=PIN2_bm 26 | 27 | # CDEFS += -DUSB_OE_PORT=PORTR 28 | # CDEFS += -DUSB_OE_PIN=PIN1_bm 29 | 30 | #### v2 31 | # Note: USB_SEL is connected to I2C_OE_LEFT 32 | 33 | DUAL_USB := 1 34 | 35 | CDEFS += -DALPHA_SPLIT_V2 36 | CDEFS += -DI2C_OE_LEFT_PORT=PORTR 37 | CDEFS += -DI2C_OE_LEFT_PIN=PIN0_bm 38 | 39 | CDEFS += -DI2C_OE_RIGHT_PORT=PORTE 40 | CDEFS += -DI2C_OE_RIGHT_PIN=PIN3_bm 41 | 42 | CDEFS += -DUSB_OE_PORT=PORTR 43 | CDEFS += -DUSB_OE_PIN=PIN1_bm 44 | 45 | CDEFS += -DNRF24_CE_PORT=PORTB 46 | CDEFS += -DNRF24_CE_PIN=PIN2_bm 47 | 48 | USE_CHECK_PIN := 1 49 | USE_USB := 1 50 | USE_SCANNER := 1 51 | USE_NRF24 := 1 52 | USE_I2C := 1 53 | USE_HARDWARE_SPECIFIC_SCAN := 0 54 | -------------------------------------------------------------------------------- /ports/xmega/boards/default/board_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | // This file lists pins that have function locked at compile time. 5 | 6 | #define IO_USABLE_PINS { \ 7 | PORT_A_USABLE_PINS, \ 8 | PORT_B_USABLE_PINS, \ 9 | PORT_C_USABLE_PINS, \ 10 | PORT_D_USABLE_PINS, \ 11 | PORT_E_USABLE_PINS, \ 12 | PORT_R_USABLE_PINS, \ 13 | } 14 | -------------------------------------------------------------------------------- /ports/xmega/boards/default/config.mk: -------------------------------------------------------------------------------- 1 | ifndef MCU 2 | MCU = atxmega32a4u 3 | endif 4 | 5 | ifndef LAYOUT_FILE 6 | LAYOUT_FILE=../../layouts/small_split_test.yaml 7 | endif 8 | 9 | C_SRC += # extra includes 10 | 11 | # vbus check pin 12 | CDEFS += -DVBUS_PIN_PORT=E 13 | CDEFS += -DVBUS_PIN_NUM=2 14 | CDEFS += -DVBUS_PIN_INT_NUM=1 15 | 16 | # nrf24 pins 17 | CDEFS += -DNRF24_CE_PORT=PORTR 18 | CDEFS += -DNRF24_CE_PIN=PIN0_bm 19 | 20 | CDEFS += -DNRF24_IRQ_PIN_PORT=R 21 | CDEFS += -DNRF24_IRQ_PIN_NUM=1 22 | CDEFS += -DNRF24_IRQ_INT_NUM=1 23 | 24 | USE_USB := 1 25 | USE_SCANNER := 1 26 | USE_NRF24 := 1 27 | USE_CHECK_PIN := 1 28 | USE_I2C := 1 29 | USE_HARDWARE_SPECIFIC_SCAN := 0 30 | -------------------------------------------------------------------------------- /ports/xmega/boards/keyplus_mini/board_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | // This file lists pins that have function locked at compile time. 5 | 6 | // The locked pins are: 7 | // E2: vbus check 8 | 9 | #define IO_USABLE_PINS { \ 10 | PORT_A_USABLE_PINS, \ 11 | PORT_B_USABLE_PINS, \ 12 | PORT_C_USABLE_PINS, \ 13 | PORT_D_USABLE_PINS, \ 14 | PORT_E_USABLE_PINS & (~PIN2_bm), \ 15 | PORT_R_USABLE_PINS, \ 16 | } 17 | -------------------------------------------------------------------------------- /ports/xmega/boards/keyplus_mini/config.mk: -------------------------------------------------------------------------------- 1 | # keyplus_mini build settings 2 | 3 | ifndef MCU 4 | MCU = atxmega32a4u 5 | endif 6 | 7 | C_SRC += # extra includes 8 | 9 | # vbus check pin 10 | CDEFS += -DVBUS_PIN_PORT=E 11 | CDEFS += -DVBUS_PIN_NUM=2 12 | CDEFS += -DVBUS_PIN_INT_NUM=1 13 | 14 | # nrf24 pins 15 | CDEFS += -DNRF24_CE_PORT=PORTR 16 | CDEFS += -DNRF24_CE_PIN=PIN0_bm 17 | 18 | CDEFS += -DNRF24_IRQ_PIN_PORT=R 19 | CDEFS += -DNRF24_IRQ_PIN_NUM=1 20 | CDEFS += -DNRF24_IRQ_INT_NUM=1 21 | 22 | USE_USB := 1 23 | USE_SCANNER := 1 24 | USE_NRF24 := 1 25 | USE_UNIFYING := 1 26 | USE_CHECK_PIN := 1 27 | USE_I2C := 1 28 | USE_HARDWARE_SPECIFIC_SCAN := 0 29 | -------------------------------------------------------------------------------- /ports/xmega/boards/old_test_board/config.mk: -------------------------------------------------------------------------------- 1 | # old test board build settings 2 | 3 | ifndef MCU 4 | MCU = atxmega32a4u 5 | endif 6 | 7 | C_SRC += # extra includes 8 | 9 | # vbus check pin 10 | CDEFS += -DVBUS_PIN_PORT=R 11 | CDEFS += -DVBUS_PIN_NUM=1 12 | CDEFS += -DVBUS_PIN_INT_NUM=0 13 | 14 | # nrf24 pins 15 | CDEFS += -DNRF24_CE_PORT=PORTR 16 | CDEFS += -DNRF24_CE_PIN=PIN0_bm 17 | 18 | # old test board doesn't have IRQ pin connected 19 | CDEFS += -DRF_POLLING=1 20 | # CDEFS += -DNRF24_IRQ_PIN_PORT=R 21 | # CDEFS += -DNRF24_IRQ_PIN_NUM=1 22 | # CDEFS += -DNRF24_IRQ_INT_NUM=1 23 | 24 | USE_USB := 1 25 | USE_SCANNER := 1 26 | USE_NRF24 := 1 27 | USE_CHECK_PIN := 1 28 | USE_I2C := 1 29 | USE_HARDWARE_SPECIFIC_SCAN := 0 30 | -------------------------------------------------------------------------------- /ports/xmega/boards/plain/board_config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | // This file lists pins that have function locked at compile time. 5 | 6 | // Use all the default values 7 | -------------------------------------------------------------------------------- /ports/xmega/boards/plain/config.mk: -------------------------------------------------------------------------------- 1 | # Build 2 | 3 | ifndef MCU 4 | MCU = atxmega32a4u 5 | endif 6 | 7 | C_SRC += # extra includes 8 | 9 | USE_USB := 1 10 | USE_SCANNER := 1 11 | USE_NRF24 := 0 12 | USE_UNIFYING := 0 13 | USE_CHECK_PIN := 0 14 | USE_I2C := 0 15 | USE_HARDWARE_SPECIFIC_SCAN := 0 16 | -------------------------------------------------------------------------------- /ports/xmega/doxygen.md: -------------------------------------------------------------------------------- 1 | @dir ports/xmega 2 | 3 | ## Feature support 4 | 5 | * USB 6 | * I2C wired split 7 | * nRF24 wireless transmitter 8 | * nRF24 wireless receiver 9 | * battery operation 10 | -------------------------------------------------------------------------------- /ports/xmega/scripts/flash_hex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | keyplus_cmd=../host-software/keyplus-cli 6 | xusb_cmd=./xusb-boot/scripts/bin/xusbboot-cli 7 | 8 | if [[ $# -ne 2 ]]; then 9 | echo "Usage: $0 hex_file" 10 | fi 11 | 12 | $keyplus_cmd bootloader -d 6666:1111 13 | sleep 1.5 14 | $xusb_cmd -d 6666:b007 -f $1 -mcu $2 15 | -------------------------------------------------------------------------------- /ports/xmega/scripts/fuse_hex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | if [[ $# -ne 1 ]]; then 6 | echo "usage: $0 fuses.hex" 7 | fi 8 | 9 | file=$1 10 | bytes=$(grep ":060020" $file) 11 | for i in 0 1 2 4 5; do 12 | b0=$(($i*2+10)) 13 | b1=$(($i*2+11)) 14 | fusex=$(echo $bytes | cut -c $b0-$b1 ) 15 | echo FUSE${i}=${fusex} 16 | done 17 | -------------------------------------------------------------------------------- /ports/xmega/scripts/get_fuses.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2017 jem@seethis.link 3 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 4 | 5 | cmd="" 6 | tmp_file=`mktemp` 7 | tmp_file2=`mktemp` 8 | for i in 0 1 2 4 5; do 9 | # cmd="$cmd -U fuse$i:r:$tmp_file:h" 10 | cmd="-U fuse$i:r:$tmp_file:h" 11 | avrdude-pdi -C ~/local/etc/avrdude-pdi.conf -c usbasp -p x32a4 $cmd 12 | echo -n "FUSE$i=" >> $tmp_file2 13 | cat $tmp_file >> $tmp_file2 14 | done 15 | cat $tmp_file2 16 | -------------------------------------------------------------------------------- /ports/xmega/scripts/prod_flash.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RED='\033[0;31m' 4 | GREEN='\033[0;32m' 5 | NC='\033[0m' # No Color 6 | function test_cmd { 7 | "$@" 8 | local status=$? 9 | if [ $status -ne 0 ]; then 10 | echo -e "${RED}##############################${NC}" >&2 11 | echo -e "${RED}##########CMD FAILED##########${NC}" >&2 12 | echo -e "${RED}##############################${NC}" >&2 13 | echo -e "${RED}error:${NC} command failed to execute $1" >&2 14 | exit 1 15 | fi 16 | return $status 17 | } 18 | 19 | test_cmd make MCU=atxmega32a4u BOARD=keyplus_mini LAYOUT_FILE=../layouts/matrix_col_tester.yaml program-boot-2; 20 | 21 | echo -e "${GREEN}######################################${NC}" >&2 22 | echo -e "${GREEN}##########PROGRAM SUCCESSFUL##########${NC}" >&2 23 | echo -e "${GREEN}######################################${NC}" >&2 24 | -------------------------------------------------------------------------------- /ports/xmega/scripts/prod_loop.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function count_down() { 4 | iter=$1 5 | while (( $iter > 0)); do 6 | echo $iter 7 | iter=$(( $iter - 1 )) 8 | sleep 1 9 | done 10 | echo 0 11 | } 12 | 13 | while true; do 14 | scripts/prod_flash.sh 15 | count_down 1 16 | done 17 | -------------------------------------------------------------------------------- /ports/xmega/src/aes.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/aes.h" 5 | 6 | #include "xmega_hardware/aes.h" 7 | 8 | #include 9 | 10 | static XRAM aes_key_t aes_ekey; 11 | static XRAM aes_key_t aes_dkey; 12 | 13 | void aes_key_init(const uint8_t *ekey, const uint8_t *dkey) { 14 | memcpy(aes_ekey, ekey, AES_KEY_SIZE); 15 | memcpy(aes_dkey, dkey, AES_KEY_SIZE); 16 | } 17 | 18 | void aes_encrypt(uint8_t *block) { 19 | xmega_aes_crypt(block, block, aes_ekey, XMEGA_AES_ENCRYPT); 20 | } 21 | 22 | void aes_decrypt(uint8_t *block) { 23 | xmega_aes_crypt(block, block, aes_dkey, XMEGA_AES_DECRYPT); 24 | } 25 | -------------------------------------------------------------------------------- /ports/xmega/src/avr_util.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define DEF_AVR_PORT_a(x) PORT ## x 7 | #define DEF_AVR_PORT_b(x) DEF_AVR_PORT_a(x) 8 | #define DEF_AVR_PORT(x) DEF_AVR_PORT_b(x) 9 | 10 | #define DEF_AVR_PIN_MASK_a(x) PIN ## x ## _bm 11 | #define DEF_AVR_PIN_MASK(x) DEF_AVR_PIN_MASK_a(x) 12 | 13 | #define DEF_AVR_INT_INTMASK_a(port, int_num) PORT ## port . INT ## int_num ## MASK 14 | #define DEF_AVR_INT_INTMASK(port, int_num) DEF_AVR_INT_INTMASK_a(port, int_num) 15 | 16 | #define DEF_AVR_INT_LVL_a(int_num, lvl) PORT_INT ## int_num ## LVL_ ## lvl ## _gc 17 | #define DEF_AVR_INT_LVL(int_num, lvl) DEF_AVR_INT_LVL_a(int_num, lvl) 18 | 19 | #define DEF_AVR_INT_LVL_MASK_a(int_num) PORT_INT ## int_num ## LVL_gm 20 | #define DEF_AVR_INT_LVL_MASK(int_num) DEF_AVR_INT_LVL_MASK_a(int_num) 21 | 22 | #define DEF_AVR_INT_VECT_a(port, int_num) \ 23 | PORT ## port ## _ ## INT ## int_num ## _vect 24 | #define DEF_AVR_INT_VECT(port, int_num) DEF_AVR_INT_VECT_a(port, int_num) 25 | -------------------------------------------------------------------------------- /ports/xmega/src/config.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #ifndef USB_VID 7 | #define USB_VID 0x1209 8 | #endif 9 | 10 | #ifndef USB_PID 11 | #define USB_PID 0xBB00 12 | #endif 13 | 14 | #ifndef DEVICE_ID 15 | #define DEVICE_ID 0 16 | #endif 17 | 18 | #ifndef USB_DEVICE_VERSION 19 | #define USB_DEVICE_VERSION 0x0000 20 | #endif 21 | 22 | #if !defined(BOOTLOADER_VID) && !defined(BOOTLOADER_PID) 23 | #define BOOTLOADER_VID 0x1209 24 | #define BOOTLOADER_PID 0xBB01 25 | #endif 26 | 27 | // TODO: move to settings 28 | // TODO: an option to enter deep sleep when there has been no change in the matrix 29 | // state for a long time 30 | #define DEEP_SLEEP_TIME 3000 31 | 32 | #define SCANNER_MATRIX_DELTA 1 33 | 34 | #define INTERNAL_SCAN_METHOD (MATRIX_SCANNER_INTERNAL_FAST_ROW_COL) 35 | #define RF_POLLING 0 36 | 37 | #ifndef MAX_NUM_ROWS 38 | #define MAX_NUM_ROWS 18 39 | #endif 40 | 41 | // Use the SPI handling provided by core/nrf24.c 42 | #define NRF24_INBUILT_SPI_HANDLING 1 43 | -------------------------------------------------------------------------------- /ports/xmega/src/dual_usb.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | // Turn bus switch on or off. 9 | // Note: OE lines on FUSB42 are active LO 10 | #define SET_BUS_SWITCH(name, value) do { \ 11 | if (value) {name##_PORT.OUTCLR = name##_PIN;} /*enable*/ \ 12 | else {name##_PORT.OUTSET = name##_PIN;} /*disable*/ \ 13 | } while (0); 14 | 15 | #define GET_BUS_SWITCH(name) ((~name##_PORT.OUT) & name##_PIN) 16 | 17 | void init_bus_switches(void); 18 | void init_bus_switch_toggle(void); 19 | void bus_switch_toggle_usb(void); 20 | 21 | uint8_t usb_find_port(void); 22 | -------------------------------------------------------------------------------- /ports/xmega/src/eeprom_map.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include 7 | 8 | // NOTE: we store each nonce value in a different page, to reduce the chance 9 | // that all the values get corrupted at once. 10 | #define EEPROM_NONCE_0 (uint16_t*)(EEPROM_PAGE_SIZE*1 + 0) 11 | #define EEPROM_NONCE_1 (uint16_t*)(EEPROM_PAGE_SIZE*2 + 0) 12 | #define EEPROM_NONCE_2 (uint16_t*)(EEPROM_PAGE_SIZE*3 + 0) 13 | -------------------------------------------------------------------------------- /ports/xmega/src/port_impl/hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "board_config.h" 11 | #include "xmega_hardware.h" 12 | 13 | #define static_delay_us(x) _delay_us(x) 14 | #define static_delay_ms(x) _delay_ms(x) 15 | 16 | #define enable_interrupts() do { \ 17 | sei(); \ 18 | } while(0); 19 | 20 | #define disable_interrupts() do { \ 21 | cli(); \ 22 | } while(0); 23 | 24 | 25 | #define PAGE_SIZE APP_SECTION_PAGE_SIZE 26 | 27 | // define flash pointer sizes 28 | #if MCU_FLASH_SIZE <= 64 29 | typedef uint16_t flash_ptr_t; 30 | typedef uint16_t flash_addr_t; 31 | typedef uint32_t flash_size_t; 32 | #else 33 | typedef uint16_t flash_ptr_t; 34 | typedef uint32_t flash_addr_t; 35 | typedef uint32_t flash_size_t; 36 | #define XMEGA_FAR_FLASH 37 | #endif 38 | 39 | #define MCU_BITNESS 8 40 | 41 | typedef PORT_t io_port_t; 42 | 43 | #if XMEGA_PIN_COUNT == 44 44 | #include "io_map/xio44.h" 45 | #elif XMEGA_PIN_COUNT == 64 46 | #include "io_map/xio64.h" 47 | #elif XMEGA_PIN_COUNT == 100 48 | #include "io_map/xio100.h" 49 | #else 50 | #error "Message unsupported XMEGA_PIN_COUNT" 51 | #endif 52 | -------------------------------------------------------------------------------- /ports/xmega/src/port_impl/io_map.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/io_map.h" 5 | 6 | #if XMEGA_PIN_COUNT == 44 7 | 8 | io_port_t * const g_io_port_map[IO_PORT_COUNT] = { 9 | &PORTA, 10 | &PORTB, 11 | &PORTC, 12 | &PORTD, 13 | &PORTE, 14 | &PORTR, 15 | }; 16 | 17 | #elif XMEGA_PIN_COUNT == 64 18 | 19 | io_port_t * const g_io_port_map[IO_PORT_COUNT] = { 20 | &PORTA, 21 | &PORTB, 22 | &PORTC, 23 | &PORTD, 24 | &PORTE, 25 | &PORTF, 26 | &PORTR, 27 | }; 28 | 29 | #elif XMEGA_PIN_COUNT == 100 30 | 31 | io_port_t * const g_io_port_map[IO_PORT_COUNT] = { 32 | &PORTA, 33 | &PORTB, 34 | &PORTC, 35 | &PORTD, 36 | &PORTE, 37 | &PORTF, 38 | &PORTH, 39 | &PORTJ, 40 | &PORTK, 41 | &PORTQ, 42 | &PORTR, 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /ports/xmega/src/port_impl/led.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/led.h" 5 | 6 | #include 7 | 8 | void led_init(void) { 9 | } 10 | 11 | void led_testing_set(uint8_t led_num, uint8_t state) { 12 | } 13 | 14 | void led_testing_toggle(uint8_t led_num) { 15 | } 16 | -------------------------------------------------------------------------------- /ports/xmega/src/power.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #if USE_CHECK_PIN 10 | 11 | #include "avr_util.h" 12 | 13 | #ifndef VBUS_PORT 14 | #define VBUS_PORT DEF_AVR_PORT(VBUS_PIN_PORT) 15 | #define VBUS_PIN_MASK DEF_AVR_PIN_MASK(VBUS_PIN_NUM) 16 | #define VBUS_INT_LVL DEF_AVR_INT_LVL(VBUS_PIN_INT_NUM, HI) 17 | #define VBUS_INT_LVL_MASK DEF_AVR_INT_LVL_MASK(VBUS_PIN_INT_NUM) 18 | #define VBUS_INT_INTMASK DEF_AVR_INT_INTMASK(VBUS_PIN_PORT, VBUS_PIN_INT_NUM) 19 | #define VBUS_INT_VECT DEF_AVR_INT_VECT(VBUS_PIN_PORT, VBUS_PIN_INT_NUM) 20 | #endif 21 | 22 | #endif 23 | 24 | typedef enum { 25 | MODE_BATTERY, 26 | MODE_WIRED, 27 | MODE_USB, 28 | MODE_INIT, 29 | } power_mode_t; 30 | 31 | void set_power_mode(power_mode_t mode); 32 | power_mode_t get_power_mode(void); 33 | 34 | void vbus_pin_init(void); 35 | bool has_vbus_power(void); 36 | void check_pins_init(void); 37 | 38 | void battery_mode_clock_init(void); 39 | void enter_sleep_mode(uint8_t sleep_mode); 40 | void deep_sleep(void); 41 | -------------------------------------------------------------------------------- /ports/xmega/src/usb_user_impl.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "xmega/usb_xmega.h" 7 | 8 | #define USB_EP0_IN_BUF 0 9 | #define USB_EP0_IN_WRITE(x) usb_ep0_in(x) 10 | #define USB_EP0_HSNAK() 11 | #define USB_EP0_STALL() usb_ep0_stall() 12 | -------------------------------------------------------------------------------- /ports/xmega/src/wired.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "core/util.h" 7 | 8 | #define WIRED_PACKET_ADDRESS_BYTE 0 9 | #define WIRED_PACKET_CONTROL_BYTE 1 10 | 11 | #define WIRED_ADDRESS_DEVICE_ID_OFFSET 32 12 | 13 | #define I2C_GENERAL_CALL_ADDRESS 0x00 14 | #define I2C_BUFFER_COUNT 8 15 | #define I2C_BROADCAST_MAX_SIZE 16 16 | 17 | #define CPU_SPEED F_CPU 18 | #define BAUDRATE 400000 19 | /* #define BAUDRATE 800000 */ 20 | /* #define BAUDRATE 1600000 */ 21 | /* #define BAUDRATE 1000000 */ 22 | #define TWI_BAUDSETTING TWI_BAUD(CPU_SPEED, BAUDRATE) 23 | 24 | #define i2c_address_to_device_id(i2c_addr) (i2c_addr - WIRED_ADDRESS_DEVICE_ID_OFFSET) 25 | #define device_id_to_i2c_address(dev_id) (dev_id + WIRED_ADDRESS_DEVICE_ID_OFFSET) 26 | 27 | void wired_init(void); 28 | void wired_send_matrix_packet(uint8_t type, uint8_t *data); 29 | 30 | void i2c_buffer_advance(void); 31 | uint8_t *i2c_get_buffer(void); 32 | void i2c_init(void); 33 | uint8_t i2c_broadcast(const uint8_t* data, uint8_t size); 34 | uint8_t i2c_get_active_address(void); 35 | uint8_t i2c_calculate_checksum(uint8_t *buffer, uint8_t length); 36 | -------------------------------------------------------------------------------- /ports/xmega/src/ws2812.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Josh Levine 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | // Source: https://github.com/bigjosh/SimpleNeoPixelDemo 4 | 5 | #pragma once 6 | 7 | // These values depend on which pin your string is connected to and what board you are using 8 | // More info on how to find these at http://www.arduino.cc/en/Reference/PortManipulation 9 | 10 | // These values are for digital pin 8 on an Arduino Yun or digital pin 12 on a DueMilinove 11 | // Note that you could also include the DigitalWriteFast header file to not need to to this lookup. 12 | 13 | /* #define PIXEL_PORT PORTB // Port of the pin the pixels are connected to */ 14 | /* #define PIXEL_DDR DDRB // Port of the pin the pixels are connected to */ 15 | /* #define PIXEL_BIT 4 // Bit of the pin the pixels are connected to */ 16 | 17 | #define PIXEL_PORT PORTE // Port of the pin the pixels are connected to 18 | #define PIXEL_BIT (1 << 3) // Bit of the pin the pixels are connected to 19 | 20 | void ledsetup(void); 21 | void sendPixel( unsigned char r, unsigned char g , unsigned char b ); 22 | void show(void); 23 | -------------------------------------------------------------------------------- /ports/xmega/src/ws2812_config.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2015 Josh Levine 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | // Source: https://github.com/bigjosh/SimpleNeoPixelDemo 4 | 5 | /* 6 | * light_ws2812_config.h 7 | * 8 | * v2.4 - Nov 27, 2016 9 | * 10 | * User Configuration file for the light_ws2812_lib 11 | * 12 | */ 13 | 14 | 15 | #ifndef WS2812_CONFIG_H_ 16 | #define WS2812_CONFIG_H_ 17 | 18 | /////////////////////////////////////////////////////////////////////// 19 | // Define Reset time in µs. 20 | // 21 | // This is the time the library spends waiting after writing the data. 22 | // 23 | // WS2813 needs 300 µs reset time 24 | // WS2812 and clones only need 50 µs 25 | // 26 | /////////////////////////////////////////////////////////////////////// 27 | 28 | #define ws2812_resettime 300 29 | 30 | /////////////////////////////////////////////////////////////////////// 31 | // Define I/O pin 32 | /////////////////////////////////////////////////////////////////////// 33 | 34 | 35 | /* #define ws2812_port B // Data port */ 36 | /* #define ws2812_pin 2 // Data out pin */ 37 | 38 | #define ws2812_port E // Data port 39 | #define ws2812_pin 2 // Data out pin 40 | 41 | #endif /* WS2812_CONFIG_H_ */ 42 | -------------------------------------------------------------------------------- /ports/xmega/src/xmega_hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | void rtc_ulp_init(void); 7 | void impl_idle_sleep(void); 8 | -------------------------------------------------------------------------------- /ports/xmega/src/xmega_hardware/aes.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "xmega_hardware/aes.h" 5 | 6 | #include 7 | 8 | void xmega_aes_crypt(aes_block_t out_block, aes_block_t in_block, const aes_key_t key, xmega_aes_mode_t mode) { 9 | AES.CTRL = AES_RESET_bm; 10 | 11 | if (mode) { 12 | AES.CTRL |= AES_DECRYPT_bm; 13 | } else { 14 | AES.CTRL &= ~AES_DECRYPT_bm; 15 | } 16 | 17 | for (int i = 0; i < AES_BUF_LEN; ++i) { 18 | AES.KEY = key[i]; 19 | } 20 | for (int i = 0; i < AES_BUF_LEN; ++i) { 21 | AES.STATE = in_block[i]; 22 | } 23 | AES.CTRL |= AES_START_bm; 24 | while (!(AES.STATUS & AES_SRIF_bm)); 25 | for (int i = 0; i < AES_BUF_LEN; ++i) { 26 | out_block[i] = AES.STATE; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /ports/xmega/src/xmega_hardware/xmega_hardware.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | XMEGA_HARDWARE_PATH = xmega_hardware 5 | 6 | ifeq ($(USE_I2C), 1) 7 | C_SRC += $(XMEGA_HARDWARE_PATH)/twi_slave_driver.c 8 | C_SRC += $(XMEGA_HARDWARE_PATH)/twi_master_driver.c 9 | endif 10 | 11 | ifeq ($(USE_NRF24), 1) 12 | C_SRC += $(XMEGA_HARDWARE_PATH)/aes.c 13 | endif 14 | INC_PATHS += -I $(XMEGA_HARDWARE_PATH) 15 | -------------------------------------------------------------------------------- /ports/xmega/src/xusb/makefile: -------------------------------------------------------------------------------- 1 | SRC_USB += $(XMEGA_PATH)/xusb/usb_requests.c 2 | USB_OPTS += -I $(XMEGA_PATH)/xusb 3 | -------------------------------------------------------------------------------- /ports/xmega/src/xusb/xmega/makefile: -------------------------------------------------------------------------------- 1 | SRC_USB += $(XMEGA_PATH)/xusb/xmega/usb_xmega.c 2 | USB_OPTS += -I $(XMEGA_PATH)/xusb/xmega 3 | -------------------------------------------------------------------------------- /src/arch/8051/hardware.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define MCU_BITNESS 8 7 | #define IO_PORT_SIZE 8 8 | typedef uint8_t io_port_t; 9 | 10 | // flash pointer defines 11 | typedef uint16_t flash_ptr_t; 12 | typedef uint16_t flash_addr_t; 13 | typedef uint16_t flash_size_t; 14 | -------------------------------------------------------------------------------- /src/arch/README.md: -------------------------------------------------------------------------------- 1 | @dir src/arch 2 | @brief Provides shared implementations for CPU architectures. 3 | -------------------------------------------------------------------------------- /src/arch/avr/avr.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | ARCH_AVR_PATH = arch/avr 5 | 6 | ifeq ($(USE_NRF24), 1) 7 | C_SRC += \ 8 | $(ARCH_AVR_PATH)/nonce.c 9 | endif 10 | -------------------------------------------------------------------------------- /src/arch/avr/eeprom_map.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include 5 | 6 | #include 7 | 8 | #ifndef EEPROM_PAGE_SIZE 9 | #define EEPROM_PAGE_SIZE 32 10 | #endif 11 | 12 | // NOTE: we store each nonce value in a different page, to reduce the chance 13 | // that all the values get corrupted at once. 14 | #define EEPROM_NONCE_0 (uint16_t*)(EEPROM_PAGE_SIZE*1 + 0) 15 | #define EEPROM_NONCE_1 (uint16_t*)(EEPROM_PAGE_SIZE*2 + 0) 16 | #define EEPROM_NONCE_2 (uint16_t*)(EEPROM_PAGE_SIZE*3 + 0) 17 | -------------------------------------------------------------------------------- /src/arch/avr/matrix_scanner.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #if F_CPU == 48000000UL 9 | #define PARASITIC_DISCHARGE_DELAY_FAST_CLOCK(x) do {\ 10 | _delay_loop_1(x); \ 11 | _delay_loop_1(x); \ 12 | _delay_loop_1(x); \ 13 | } while(0) 14 | #elif F_CPU == 32000000UL 15 | #define PARASITIC_DISCHARGE_DELAY_FAST_CLOCK(x) do {\ 16 | _delay_loop_1(x); \ 17 | _delay_loop_1(x); \ 18 | } while(0) 19 | #elif F_CPU == 16000000UL 20 | #define PARASITIC_DISCHARGE_DELAY_FAST_CLOCK(x) do {\ 21 | _delay_loop_1(x); \ 22 | } while(0) 23 | #elif F_CPU == 8000000UL 24 | #define PARASITIC_DISCHARGE_DELAY_FAST_CLOCK(x) do {\ 25 | _delay_loop_1(x/2); \ 26 | } while(0) 27 | #elif F_CPU == 4000000UL 28 | #define PARASITIC_DISCHARGE_DELAY_FAST_CLOCK(x) do {\ 29 | _delay_loop_1(x/4); \ 30 | } while(0) 31 | #elif F_CPU == 2000000UL 32 | #define PARASITIC_DISCHARGE_DELAY_FAST_CLOCK(x) do {\ 33 | _delay_loop_1(x/8); \ 34 | } while(0) 35 | #elif F_CPU == 1000000UL 36 | #define PARASITIC_DISCHARGE_DELAY_FAST_CLOCK(x) do {\ 37 | _delay_loop_1(x/16); \ 38 | } while(0) 39 | #else 40 | #error "Unsupported clock speed for PARASITIC_DISCHARGE_DELAY" 41 | #endif 42 | 43 | #define PARASITIC_DISCHARGE_DELAY_SLOW_CLOCK(x) do {\ 44 | _delay_loop_1(x); \ 45 | } while(0) 46 | -------------------------------------------------------------------------------- /src/core/README.md: -------------------------------------------------------------------------------- 1 | @dir src/core 2 | # Overview of code layout 3 | 4 | Important components: 5 | 6 | 7 | | module | function | 8 | |--------|----------| 9 | | `core/matrix_interpret.c`| The main keyboard logic module. This module is responsible for merging the matrices received from RF and Wired devices and generating the key press and release events based on the matrix state. | 10 | | `core/rf.c` | wireless stuff | 11 | | `core/matrix_scanner.c` | The module responsible for debouncing and generating key matrix packets. | 12 | -------------------------------------------------------------------------------- /src/core/bootloader.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | void bootloader_jmp(void); 7 | void bootloader_jmp_2(void); 8 | -------------------------------------------------------------------------------- /src/core/crc.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | /// @file core/crc.h 4 | /// 5 | /// CRC functions used for RF packets and verifying the settings section. 6 | 7 | #pragma once 8 | 9 | #include "core/util.h" 10 | 11 | uint16_t crc16_step(uint16_t crc, uint8_t data, uint8_t num_bits); 12 | bit_t crc_check_nrf24_raw_packet(XRAM const uint8_t *addr, XRAM uint8_t *raw_packet, uint8_t payload_len); 13 | uint16_t crc16_buffer(const uint8_t *buf_ptr, uint8_t length); 14 | uint16_t crc16_flash_buffer(flash_addr_t flash_ptr, uint8_t length); 15 | -------------------------------------------------------------------------------- /src/core/debug.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | /// @file core/debug.h 4 | /// 5 | /// Utility macros and functions for debugging. 6 | /// 7 | /// The `DEBUG_LEVEL` macro can be used to set the amount of debug features 8 | /// compiled into the code (passed from make command). If it is not defined 9 | /// or 0, debug features are disabled. 10 | 11 | #pragma once 12 | 13 | #include "core/util.h" 14 | #include 15 | 16 | #if defined(DEBUG_LEVEL) && DEBUG_LEVEL >= 2 17 | /// Initialize debug code 18 | void init_debug(void); 19 | 20 | /// Toggle the state of a debug pin for reading with logic analyzer or LED 21 | void debug_toggle(uint8_t x); 22 | 23 | /// Set the state of a debug pin for reading with logic analyzer or LED 24 | void debug_set(uint8_t x, uint8_t val); 25 | #else 26 | #define init_debug() ((void) 0) 27 | #define debug_toggle(x) ((void) 0) 28 | #define debug_set(x, y) ((void) 0) 29 | #endif 30 | 31 | #if defined(DEBUG_LEVEL) && DEBUG_LEVEL >= 4 32 | #define assert(x) ((x) ? (void)0 : assert_fail(__LINE__)) 33 | /// Hang the CPU when an assertion fails. 34 | /// 35 | /// Will try to print the cause of the hang if a mechanism is provided on 36 | /// the given firmware port. 37 | void assert_fail(uint16_t line_num) NO_RETURN_ATTR; 38 | #else 39 | #define assert(x) ((void)0) 40 | #endif 41 | -------------------------------------------------------------------------------- /src/core/error.c: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/error.h" 5 | 6 | #include 7 | 8 | XRAM uint8_t g_error_code_table[SIZE_ERROR_CODE_TABLE]; 9 | 10 | static XRAM uint8_t s_has_critical_error; 11 | 12 | void init_error_system(void) { 13 | memset(g_error_code_table, 0, SIZE_ERROR_CODE_TABLE); 14 | s_has_critical_error = false; 15 | } 16 | 17 | bit_t has_critical_error(void) { 18 | return s_has_critical_error; 19 | } 20 | 21 | void register_error(uint8_t code) { 22 | if (code >= CRITICAL_ERROR_START) { 23 | s_has_critical_error = true; 24 | } 25 | 26 | g_error_code_table[code / 8] = 27 | g_error_code_table[code / 8] | (1 << (code % 8)); 28 | } 29 | 30 | void unregister_error(uint8_t code) { 31 | uint8_t i; 32 | uint8_t critical_errors = 0; 33 | 34 | g_error_code_table[code / 8] &= (1 << (code % 8)); 35 | 36 | for (i = 0; i < CRITICAL_ERROR_START/8; ++i) { 37 | critical_errors |= g_error_code_table[i]; 38 | } 39 | 40 | if (!critical_errors) { 41 | s_has_critical_error = false; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/core/hardware.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/hardware.h" 5 | #include "core/aes.h" 6 | #include "core/rf.h" 7 | #include "core/settings.h" 8 | #include "core/matrix_scanner.h" 9 | #include "core/led.h" 10 | #include "core/usb_commands.h" 11 | #include "core/error.h" 12 | 13 | #include "hid_reports/hid_reports.h" 14 | 15 | #if USE_I2C 16 | #include "wired.h" 17 | #endif 18 | 19 | bit_t g_slow_clock_mode = 1; 20 | 21 | #if (USE_I2C || USE_NRF24) && USE_USB 22 | bit_t g_has_usb_port; 23 | #endif 24 | 25 | void software_reset(void) { 26 | init_error_system(); 27 | settings_load_from_flash(); 28 | #if USE_SCANNER 29 | io_map_init(); 30 | matrix_scanner_init(); 31 | #endif 32 | #if USE_NRF24 33 | aes_key_init(g_rf_settings.ekey, g_rf_settings.dkey); 34 | 35 | if (!g_runtime_settings.feature.ctrl.rf_disabled) { 36 | rf_init_receive(); 37 | } 38 | #endif 39 | #if USE_I2C 40 | if (g_has_usb_port && !g_runtime_settings.feature.ctrl.wired_disabled) { 41 | i2c_init(); 42 | } 43 | #endif 44 | led_init(); 45 | #if USE_USB 46 | reset_usb_reports(); 47 | #else 48 | reset_hid_reports(); 49 | #endif 50 | keyboards_init(); 51 | } 52 | -------------------------------------------------------------------------------- /src/core/keycode.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/keycode.h" 5 | 6 | #include 7 | 8 | #include "core/error.h" 9 | 10 | XRAM flash_addr_t g_ekc_storage_ptr; 11 | XRAM uint32_t g_ekc_storage_size; 12 | 13 | keycode_t get_ekc_type(keycode_t kc) { 14 | if (kc & KC_EXTERNAL_FLAG) { 15 | keycode_t result; 16 | uint16_t addr = EKC_ADDR(kc); 17 | get_ekc_data((uint8_t*)&result, addr, sizeof(keycode_t)); 18 | return result; 19 | } else { 20 | return kc; 21 | } 22 | } 23 | 24 | uint8_t get_ekc_data(void *dest, uint16_t offset, uint16_t size) REENT { 25 | if (is_valid_storage_pos((flash_addr_t)g_ekc_storage_ptr + offset) && 26 | is_valid_storage_pos((flash_addr_t)g_ekc_storage_ptr + offset + size - 1) 27 | ) { 28 | flash_read(dest, g_ekc_storage_ptr + offset, size); 29 | return 0; 30 | } else { 31 | register_error(ERROR_EKC_OUT_OF_BOUNDS_ACCESS); 32 | memset(dest, 0, size); 33 | return 1; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/core/led.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/led.h" 5 | 6 | // TODO: add handling for keyboard indicator leds 7 | -------------------------------------------------------------------------------- /src/core/led.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "core/util.h" 7 | 8 | void led_init(void); 9 | void led_testing_set(uint8_t led_number, uint8_t state); 10 | void led_testing_toggle(uint8_t led_num); 11 | -------------------------------------------------------------------------------- /src/core/mods.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "core/keycode.h" 9 | #include "core/util.h" 10 | 11 | void add_pure_mods(uint8_t mods); 12 | void del_pure_mods(uint8_t mods); 13 | void add_fake_mods(uint8_t mods); 14 | void del_fake_mods(uint8_t mods); 15 | 16 | void reset_mods(void); 17 | uint8_t get_mods(void); 18 | uint8_t has_pure_mods(void); 19 | void apply_mods(void); 20 | -------------------------------------------------------------------------------- /src/core/nonce.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/nonce.h" 5 | 6 | #include "core/util.h" 7 | 8 | typedef struct uid_state_t { 9 | uint16_t counter; 10 | uint16_t session_id; 11 | } uid_state_t; 12 | 13 | static XRAM uid_state_t uid_state; 14 | static XRAM uint8_t sid_is_loaded = false; 15 | 16 | /* TODO: For master ID, make sure it updates the session ID 17 | * when uid_counter overflows. */ 18 | uint32_t uid_generate(void) { 19 | if (!sid_is_loaded) { 20 | uid_state.session_id = increment_session_id(); 21 | sid_is_loaded = true; 22 | } else { 23 | if (uid_state.counter == UINT16_MAX) { 24 | uid_state.session_id = increment_session_id(); 25 | } 26 | uid_state.counter++; 27 | } 28 | return (((uint32_t)uid_state.session_id) << 16) | uid_state.counter; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /src/core/nonce.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | uint32_t uid_generate(void); 9 | 10 | // implementation specific 11 | uint16_t load_session_id(void); 12 | uint16_t increment_session_id(void); 13 | -------------------------------------------------------------------------------- /src/core/nrf52_esb.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/util.h" 5 | 6 | #include "nrf_esb.h" 7 | 8 | void rf_nrf52_load_sync_ack_payload(uint8_t device_id); 9 | void rf_esb_write_ack_payload(nrf_esb_payload_t *esb); 10 | 11 | void nrf52_esb_hw_init(void); 12 | uint32_t nrf52_esb_init_rx(void); 13 | uint32_t nrf52_esb_init_tx(void); 14 | 15 | #if USE_UNIFYING 16 | uint32_t nrf52_esb_init_unifying_pair( 17 | const XRAM uint8_t *unifying_pairing_addr, 18 | const XRAM uint8_t *target_addr, 19 | uint8_t addr_lsb 20 | ); 21 | #endif 22 | -------------------------------------------------------------------------------- /src/core/packet.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/packet.h" 5 | 6 | #include "core/settings.h" 7 | 8 | uint8_t get_packet_type(const packet_t *packet) { 9 | return packet->gen.type; 10 | } 11 | 12 | void set_packet_type(packet_t *packet, uint8_t type) { 13 | packet->gen.type = type; 14 | } 15 | 16 | bool is_matrix_packet(packet_t *packet) { 17 | uint8_t type = packet->gen.type >> PACKET_MATRIX_TYPE_BIT_POS; 18 | return type <= PACKET_MATRIX_DELTA_LIST; 19 | } 20 | 21 | /* void set_packet_uid(void) { */ 22 | /* packet->gen.device_id = g_settings.device_id; */ 23 | /* packet->gen.is_master = 0; /1* TODO: load based on *1/ */ 24 | /* packet->gen.packet_id = get_unique_pid(); */ 25 | /* } */ 26 | -------------------------------------------------------------------------------- /src/core/ring_buf.c: -------------------------------------------------------------------------------- 1 | #include "core/ring_buf.h" 2 | 3 | DEFINE_BODY_RING_BUF_VARIANT(127, uint8_t, uint8_t, ring_buf128) 4 | -------------------------------------------------------------------------------- /src/core/timer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "core/util.h" 7 | 8 | void timer_init(void); 9 | void timer_disable(void); 10 | void timer_adjust(int32_t adj); 11 | 12 | uint8_t timer_read8_ms(void); 13 | uint16_t timer_read16_ms(void); 14 | uint32_t timer_read_ms(void); 15 | 16 | // Check to see if we have passed a given time. 17 | // NOTE: To handle the wrapping nature of unsigned integers, we can only correctly 18 | // check times that are less than half the size of data type. If difference is 19 | // greater, it is assumed that this is a result of the `end_time` wrapping 20 | // around instead of the timer expiring. 21 | #define has_passed_time8(current_time, end_time) (\ 22 | (current_time > end_time) && ((uint8_t)(current_time - end_time) < UINT8_MAX/2) \ 23 | ) 24 | 25 | #define has_passed_time16(current_time, end_time) (\ 26 | (current_time > end_time) && ((uint16_t)(current_time - end_time) < UINT16_MAX/2) \ 27 | ) 28 | 29 | #define has_passed_time32(current_time, end_time) (\ 30 | (current_time > end_time) && ((uint32_t)(current_time - end_time) < UINT32_MAX/2) \ 31 | ) 32 | -------------------------------------------------------------------------------- /src/core/util.c: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "core/util.h" 5 | 6 | #ifdef __SDCC_mcs51 7 | ROM const uint8_t bit_mask_lookup_table[8] = { 8 | (1 << 0), 9 | (1 << 1), 10 | (1 << 2), 11 | (1 << 3), 12 | (1 << 4), 13 | (1 << 5), 14 | (1 << 6), 15 | (1 << 7), 16 | }; 17 | 18 | bit_t is_bitn_set(uint8_t byte, uint8_t n) { 19 | return (byte & bit_mask_lookup_table[n]); 20 | } 21 | 22 | uint8_t bitn_mask(uint8_t n) { 23 | return bit_mask_lookup_table[n]; 24 | } 25 | 26 | bit_t bitmap_get_bit(uint8_t *array, uint8_t n) { 27 | return is_bitn_set(array[n / 8], n%8); 28 | } 29 | 30 | void bitmap_set_bit(uint8_t *array, uint8_t n) { 31 | array[n / 8] |= (bitn_mask(n % 8)); 32 | } 33 | 34 | void bitmap_clear_bit(uint8_t *array, uint8_t n) { 35 | array[n / 8] &= ~(bitn_mask(n % 8)); 36 | } 37 | #endif 38 | -------------------------------------------------------------------------------- /src/core/version.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define KEYPLUS_VERSION_MAJOR 0 7 | #define KEYPLUS_VERSION_MINOR 4 8 | #define KEYPLUS_VERSION_PATCH 0 9 | 10 | // Only set this to 1 for release builds 11 | #define KEYPLUS_VERSION_IS_STABLE 0 12 | -------------------------------------------------------------------------------- /src/hid_reports/README.md: -------------------------------------------------------------------------------- 1 | @dir src/hid_reports 2 | @brief Provides a hardware abstraction layer between HID reports and the HID 3 | transport protocol (i.e. USB/BLE) 4 | 5 | # Overview of code layout 6 | 7 | The mcu ports should implement the functions in `hid_reports/usb_reports.h`. 8 | The rest of the code in this module, uses that interface to provide the various 9 | USB/BLE functions 10 | 11 | | module | function | 12 | |--------|----------| 13 | | `hid_reports/usb_reports.h` | USB abstraction layer | 14 | | `hid_reports/keyboard_report.c` | Implements 6KRO and NKRO USB reports | 15 | | `hid_reports/media_report.c` | Implements HID media controls| 16 | | `hid_reports/mouse_report.c` | Implements HID mouse | 17 | | `hid_reports/vendor_report.c` | Implements a RAW HID report for sending arbitrary data to and from the host | 18 | -------------------------------------------------------------------------------- /src/hid_reports/ble_reports.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | /// API used to send HID reports over BLE 5 | /// 6 | 7 | #include 8 | #include "kp_ble/hid.h" 9 | 10 | void kp_ble_hids_input_report_send( 11 | uint8_t report_index, 12 | uint8_t report_size, 13 | uint8_t* data 14 | ); 15 | 16 | bool kp_ble_hids_output_has_data(uint8_t report_index); 17 | 18 | void kp_ble_hids_output_report_read( 19 | uint8_t report_index, 20 | uint8_t report_size, 21 | uint8_t* data 22 | ); 23 | -------------------------------------------------------------------------------- /src/hid_reports/hid_reports.c: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "hid_reports/hid_reports.h" 5 | 6 | #if USE_VIRTUAL_MODE 7 | #include "hid_reports/virtual_reports.h" 8 | #endif 9 | 10 | void reset_hid_reports(void) { 11 | reset_keyboard_reports(); 12 | reset_mouse_report(); 13 | reset_media_report(); 14 | #if USE_VIRTUAL_MODE 15 | // don't support vendor report 16 | #else 17 | reset_vendor_report(); 18 | #endif 19 | 20 | #if USE_VIRTUAL_MODE 21 | kp_virtual_hid_reports_reset(); 22 | #endif 23 | } 24 | 25 | void send_hid_reports(void) { 26 | send_keyboard_report(); 27 | send_mouse_report(); 28 | send_media_report(); 29 | #if USE_VIRTUAL_MODE 30 | // don't support vendor report 31 | #else 32 | send_vendor_report(); 33 | #endif 34 | } 35 | -------------------------------------------------------------------------------- /src/hid_reports/hid_reports.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #include "hid_reports/keyboard_report.h" 5 | #include "hid_reports/media_report.h" 6 | #include "hid_reports/mouse_report.h" 7 | #include "hid_reports/vendor_report.h" 8 | 9 | // Functions 10 | void reset_hid_reports(void); 11 | void send_hid_reports(void); 12 | -------------------------------------------------------------------------------- /src/hid_reports/hid_reports.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2018 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | 5 | HID_REPORTS_PATH = $(KEYPLUS_PATH)/hid_reports 6 | 7 | ifeq ($(USE_HID), 1) 8 | C_SRC += \ 9 | $(HID_REPORTS_PATH)/keyboard_report.c \ 10 | $(HID_REPORTS_PATH)/media_report.c \ 11 | $(HID_REPORTS_PATH)/vendor_report.c \ 12 | $(HID_REPORTS_PATH)/mouse_report.c \ 13 | $(HID_REPORTS_PATH)/hid_reports.c \ 14 | 15 | CDEFS += -DHAS_MOUSE_SUPPORT 16 | endif 17 | -------------------------------------------------------------------------------- /src/hid_reports/media_report.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "core/util.h" 8 | 9 | #if defined(USE_USB) && USE_USB 10 | #include "usb/descriptors.h" 11 | #else 12 | #define REPORT_ID_SYSTEM 1 13 | #define REPORT_ID_CONSUMER 2 14 | #endif 15 | 16 | #include "usb/util/hut_consumer.h" 17 | #include "usb/util/hut_desktop.h" 18 | typedef struct hid_report_media_t { 19 | uint8_t report_id; 20 | uint16_t code; 21 | } hid_report_media_t; 22 | 23 | extern XRAM hid_report_media_t g_media_report; 24 | extern bit_t g_report_pending_media; 25 | 26 | void reset_media_report(void); 27 | void touch_media_report(void); 28 | 29 | bit_t send_media_report(void); 30 | -------------------------------------------------------------------------------- /src/hid_reports/mouse_report.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "core/util.h" 7 | 8 | /* TODO: move this to a flash settings */ 9 | #ifndef MOUSE_SMOOTH_SCROOL 10 | #define MOUSE_SMOOTH_SCROLL 0 11 | #endif 12 | 13 | #if USE_USB 14 | #include "usb/descriptors.h" 15 | #endif 16 | 17 | // TODO: Should probably make this compatiable with a HID boot mouse 18 | 19 | // this is what the data that we send to the host is comprised of 20 | typedef struct hid_report_mouse_t { 21 | #ifdef SHARED_HID_DESCRIPTOR 22 | uint8_t report_id; 23 | #endif 24 | uint8_t buttons_1; 25 | uint8_t buttons_2; 26 | int16_t x; 27 | int16_t y; 28 | int8_t wheel_y; 29 | int8_t wheel_x; 30 | } ATTR_PACKED hid_report_mouse_t; 31 | 32 | extern XRAM hid_report_mouse_t g_mouse_report; 33 | extern bit_t g_report_pending_mouse; 34 | 35 | void reset_mouse_report(void); 36 | void touch_mouse_report(void); 37 | 38 | int16_t sign_extend_12(uint16_t x); 39 | int16_t sign_extend_8(uint8_t x); 40 | 41 | bit_t is_ready_mouse_report(void); 42 | bit_t send_mouse_report(void); 43 | -------------------------------------------------------------------------------- /src/hid_reports/usb_reports.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | /// @file 4 | /// @brief USB endpoint abstraction layer. 5 | /// 6 | /// These functions need to be implemented for each microcontroller port for 7 | /// USB access. 8 | 9 | #pragma once 10 | 11 | #include "core/util.h" 12 | 13 | /// Checks if a USB IN endpoint is ready to take more data 14 | bit_t is_in_endpoint_ready(uint8_t endpoint_num); 15 | 16 | /// Checks if a USB OUT endpoint has data 17 | bit_t is_out_endpoint_ready(uint8_t endpoint_num); 18 | 19 | /// Write to a USB IN endpoint 20 | void usb_write_in_endpoint( 21 | uint8_t endpoint_num, 22 | const XRAM uint8_t *data, 23 | uint8_t length 24 | ); 25 | 26 | /// Read from a USB OUT endpoint 27 | void usb_read_out_endpoint( 28 | uint8_t endpoint_num, 29 | XRAM uint8_t *dest, 30 | uint8_t *length 31 | ); 32 | -------------------------------------------------------------------------------- /src/hid_reports/virtual_reports.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | void kp_virtual_hid_reports_reset(void); 5 | 6 | void kp_virtual_hid_boot_keyboard_report_send(void); 7 | void kp_virtual_hid_nkro_keyboard_report_send(void); 8 | void kp_virtual_hid_mouse_report_send(void); 9 | void kp_virtual_hid_media_report_send(void); 10 | -------------------------------------------------------------------------------- /src/key_handlers/README.md: -------------------------------------------------------------------------------- 1 | @dir src/key_handlers 2 | @brief Key handlers provide the implementation for keycodes. 3 | 4 | -------------------------------------------------------------------------------- /src/key_handlers/key_custom.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "key_handlers/key_handlers.h" 7 | 8 | extern XRAM keycode_callbacks_t custom_keycodes; 9 | -------------------------------------------------------------------------------- /src/key_handlers/key_handlers.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2017 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | MAKEFILE_INC += $(KEYPLUS_PATH)/key_handlers/key_handlers.mk 5 | 6 | KEY_HANDLERS_PATH = $(KEYPLUS_PATH)/key_handlers 7 | 8 | C_SRC += \ 9 | $(KEY_HANDLERS_PATH)/key_custom.c \ 10 | $(KEY_HANDLERS_PATH)/key_handlers.c \ 11 | $(KEY_HANDLERS_PATH)/key_hold.c \ 12 | $(KEY_HANDLERS_PATH)/key_media.c \ 13 | $(KEY_HANDLERS_PATH)/key_mouse.c \ 14 | $(KEY_HANDLERS_PATH)/key_normal.c \ 15 | 16 | 17 | ifeq ($(SUPPORT_MACRO), 1) 18 | C_SRC += $(KEY_HANDLERS_PATH)/key_macro.c 19 | endif 20 | -------------------------------------------------------------------------------- /src/key_handlers/key_hold.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "key_handlers/key_handlers.h" 7 | 8 | #define MAX_NUM_HOLD_KEYS 4 9 | 10 | // hold key settings in external keycode table 11 | #define HOLD_KEY_ACTIVATE_DELAY (1 << 0) 12 | #define HOLD_KEY_ACTIVATE_OTHER_KEY (1 << 1) 13 | 14 | // NOTE: since we use `uint16_t` for `end_time`, we are limit to a hold duration 15 | // of (UINT16_MAX/2) ms ≈ 32s 16 | typedef struct { 17 | uint16_t ekc_addr; 18 | uint16_t end_time; 19 | uint8_t kb_id; 20 | uint8_t activate_on_delay: 1; 21 | uint8_t activate_on_other_key: 1; 22 | uint8_t has_been_held: 1; 23 | uint8_t has_been_tapped: 1; 24 | uint8_t has_generated_event: 1; 25 | uint8_t reserved: 5; 26 | } hold_event_t; 27 | 28 | extern XRAM keycode_callbacks_t hold_keycodes; 29 | 30 | bool hold_key_task(uint8_t other_key_pressed); 31 | bit_t hold_key_buffer_other_keys(void); 32 | -------------------------------------------------------------------------------- /src/key_handlers/key_macro.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "key_handlers/key_handlers.h" 7 | #include "core/util.h" 8 | 9 | extern XRAM keycode_callbacks_t macro_keycodes; 10 | -------------------------------------------------------------------------------- /src/key_handlers/key_media.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "key_handlers/key_handlers.h" 7 | 8 | #include "core/util.h" 9 | 10 | extern XRAM keycode_callbacks_t media_keycodes; 11 | -------------------------------------------------------------------------------- /src/key_handlers/key_mouse.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "key_handlers/key_handlers.h" 7 | #include "core/util.h" 8 | 9 | extern XRAM keycode_callbacks_t mouse_keycodes; 10 | 11 | bool mouse_key_task(void); 12 | -------------------------------------------------------------------------------- /src/key_handlers/key_normal.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include "key_handlers/key_handlers.h" 7 | 8 | extern XRAM keycode_callbacks_t modkey_keycodes; 9 | extern XRAM keycode_callbacks_t layer_keycodes; 10 | -------------------------------------------------------------------------------- /src/key_handlers/key_tap.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/src/key_handlers/key_tap.c -------------------------------------------------------------------------------- /src/key_handlers/key_tap.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ahtn/keyplus/b0e29ab4de92c09d7ef7ad43fbe32adfb3f6c874/src/key_handlers/key_tap.h -------------------------------------------------------------------------------- /src/usb/README.md: -------------------------------------------------------------------------------- 1 | @dir src/usb 2 | @brief USB descriptors and USB defines and utilities 3 | 4 | -------------------------------------------------------------------------------- /src/usb/common.h: -------------------------------------------------------------------------------- 1 | // Copyright 2017 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | void usb_init(void); 7 | -------------------------------------------------------------------------------- /src/usb/desc/common.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #define USB_VERSION_ACCESS_TYPE_bp (12) 7 | #define USB_VERSION_ACCESS_TYPE_MASK (0xf000) 8 | #define USB_VERSION_HID_INTERFACE_3 (0 << USB_VERSION_ACCESS_TYPE_bp) 9 | #define USB_VERSION_HID_INTERFACE_2 (1 << USB_VERSION_ACCESS_TYPE_bp) 10 | #define USB_VERSION_HID_INTERFACE_1 (2 << USB_VERSION_ACCESS_TYPE_bp) 11 | #define USB_VERSION_HID_INTERFACE_0 (3 << USB_VERSION_ACCESS_TYPE_bp) 12 | 13 | -------------------------------------------------------------------------------- /src/usb/descriptors.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | enum { 7 | USB_DESCRIPTORS_NORMAL = 0, 8 | USB_DESCRIPTORS_COMPACT = 1, 9 | }; 10 | 11 | #include "usb/desc/common.h" 12 | 13 | #if USB_DESCRIPTOR_ARRANGEMENT == 0 14 | # include "usb/desc/normal/descriptors.h" 15 | #elif USB_DESCRIPTOR_ARRANGEMENT == 1 16 | # include "usb/desc/compact/descriptors.h" 17 | #else 18 | # error "USB_DESCRIPTOR_ARRANGEMENT not defined" 19 | #endif 20 | -------------------------------------------------------------------------------- /src/usb/usb.mk: -------------------------------------------------------------------------------- 1 | # Copyright 2017 jem@seethis.link 2 | # Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | MAKEFILE_INC += $(KEYPLUS_PATH)/usb/usb.mk 5 | 6 | USB_HID_PATH = $(KEYPLUS_PATH)/usb 7 | 8 | ifeq ($(USB_DESCRIPTOR_ARRANGEMENT), normal) 9 | C_SRC += $(USB_HID_PATH)/desc/normal/descriptors.c 10 | CDEFS += -DUSB_DESCRIPTOR_ARRANGEMENT=0 11 | else ifeq ($(USB_DESCRIPTOR_ARRANGEMENT), compact) 12 | C_SRC += $(USB_HID_PATH)/desc/compact/descriptors.c 13 | CDEFS += -DUSB_DESCRIPTOR_ARRANGEMENT=1 14 | else 15 | $(error "USB_DESCRIPTOR_ARRANGEMENT not set") 16 | endif 17 | -------------------------------------------------------------------------------- /src/usb/util/webusb.h: -------------------------------------------------------------------------------- 1 | // Copyright 2018 jem@seethis.link 2 | // Licensed under the MIT license (http://opensource.org/licenses/MIT) 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | // webusb descriptor 9 | typedef struct usb_webusb_desc_t { 10 | uint8_t bLength; 11 | uint8_t bDescriptorType; 12 | uint8_t bDevCapabilityType; 13 | uint8_t bReserved; 14 | uint8_t PlatformCapabilityUUID[16]; 15 | uint16_t bcdVersion; 16 | uint8_t bVendorCode; 17 | uint8_t iLandingPage; 18 | } usb_webusb_desc_t; 19 | 20 | #define WEBUSB_UUID { \ 21 | 0x34,0x08,0xb6,0x38,0x09,0xa9,0x47,0xa0,0x8b,0xfd,0xa0,0x76,0x88,0x15,0xb6,0x65 } 22 | #define WEBUSB_BCDVERSION 0x0100 23 | 24 | #define WEBUSB_URL 3 25 | 26 | #define WEBUSB_SCHEME_HTTP 0 27 | #define WEBUSB_SCHEME_HTTPS 1 28 | #define WEBUSB_SCHEME_RAW 255 29 | --------------------------------------------------------------------------------