diff --git a/README.md b/README.md index 206cd84..844c054 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ # SMK - Small (device) Mechanical Keyboard Firmware -This is a keyboard firmware similar to [QMK](https://github.com/qmk/qmk_firmware), but targeting 8051-based devices like the Sinowealth SH68F90A (labeled as BYK916). It's aimed to be at least partially compatible with QMK configurations. +This is a keyboard firmware similar to [QMK](https://github.com/qmk/qmk_firmware), but targeting 8051-based devices like the Sinowealth SH68F90A (labeled as BYK916 or BYK901). It's aimed to be at least partially compatible with QMK configurations. The S (Small) in SMK comes from this firmware using [SDCC](https://sdcc.sourceforge.net/) to build itself. @@ -18,7 +18,8 @@ You can very easily end up with a bricked device if the written firmware can't j | Keyboard | MCU | ISP | USB | Wireless | Details | | -------- | --- | --- | --- | -------- | ------- | -| [NuPhy Air60 v1](https://nuphy.com/products/air60) | SH68F90A / BYK916 | ✅ | ✅ | TBD | [Details](docs/nuphy-air60.md) | +| [NuPhy Air60 v1](https://nuphy.com/products/air60) | SH68F90A / BYK916 | ✅ | ✅ | TBD | [Details](docs/keyboards/nuphy-air60.md) | +| E-YOOSO Z11 | SH68F90A / BYK901 | ✅ | ✅ | N/A | [Details](docs/keyboards/nuphy-air60.md) | ## Acknowledgements diff --git a/docs/nuphy-air60.md b/docs/keyboards/eyooso-z11.md similarity index 62% rename from docs/nuphy-air60.md rename to docs/keyboards/eyooso-z11.md index dd11bc7..2bd948f 100644 --- a/docs/nuphy-air60.md +++ b/docs/keyboards/eyooso-z11.md @@ -1,35 +1,26 @@ -# NuPhy Air60 Support +# E-YOOSO Z11 -## MCU +## Specs -- [x] 3.3V LDO -- [x] CPU Clock (use 24Mhz as SYSCLK) -- [x] GPIO -- [x] UART - - [x] Transmit - - [ ] Receive -- [x] PWM -- [x] USB -- [ ] SPI +- MCU: BYK901(-0997A) (SH68F90A) +- Backlight: Single Color LEDs (Yellow) +- Indicators: Single CAPS_LOCK LED +- Wireless: None -## Keyboard +## Pictures + +| PCB | MCU | JTAG Setup | +| --- | --- | ---------- | +| ![e-yooso-z11-pcb](https://github.com/carlossless/smk/assets/498906/8335b453-d8ef-45ce-ae17-d5c9ffe432c1) | ![e-yooso-z11-mcu](https://github.com/carlossless/smk/assets/498906/ce7b8f84-7359-4c8d-a012-b90a1927bc6a) | ![e-yooso-z11-jtag](https://github.com/carlossless/smk/assets/498906/a872b662-24c5-47f8-98af-09b74ef02885) | + +## SMK Supported Features -- [x] ISP (jump) - [x] Key Scan -- [x] RGB Matrix - - [ ] Debouncing -- [x] USB HID - - [x] USB Keyboard - - [ ] Status LEDs - - [ ] Extra Keys (System / Consumer) - - [ ] NKRO -- [~] QMK Compatibility - - [~] Layouts -- [ ] Wireless +- [x] LED Matrix ## Code Options -This firmware requires the following (stock) code options for SH68F90A +This firmware requires the following (stock) code options that are programmed on the BYK901 (SH68F90A) in the E-YOOSO Z11 ``` Code Option String: A4E063C00F000088 diff --git a/docs/keyboards/nuphy-air60.md b/docs/keyboards/nuphy-air60.md new file mode 100644 index 0000000..35b27a6 --- /dev/null +++ b/docs/keyboards/nuphy-air60.md @@ -0,0 +1,71 @@ +# NuPhy Air60 + +## Specs + +- MCU: BYK916 (SH68F90A) +- Backlight: RGB LEDs +- Indicators: 2x5 RGB LEDs (on each side, part of the RGB backlight matrix) +- Switches: + - 2-state switch to control OS mode (win/mac) + - 3-state switch to control power and usb/wireless mode (off/usb/wireless) +- Wireless: BK3632 (supports BT and 2.4G) + +## Pictures + +| PCB | MCU | Wireless IC | +| --- | --- | ----------- | +| ![top](https://github.com/carlossless/smk/assets/498906/43ad50b2-6666-424d-94f8-ca8e9207eb7b) | ![mcu](https://github.com/carlossless/smk/assets/498906/295a8904-d131-45e1-a5dd-d2938b1a116b) | ![wireless-ic](https://github.com/carlossless/smk/assets/498906/ab980bf1-6123-4947-b05b-c006d6e41ef0) | + +## SMK Supported Features + +- [x] Key Scan +- [x] RGB Matrix +- [ ] Wireless + +## Code Options + +This firmware requires the following (stock) code options that are programmed on the BYK916 (SH68F90A) in the E-YOOSO Z11 + +``` +Code Option String: A4E063C00F000088 +Code Option Number: 0x8800000fc063e0a4 + +Byte 0 - A4 +OP_OSCDRIVE 2 - 4MHz crystal or 8~12MHz crystal with external capacitance(C1=C2)<20pF +OP_RST 1 - P0.2 used as IO pin +OP_WMT 0 - longest warm up time +OP_SCMEN 1 - Disable SCM +OP_OSCRFB 0 - 150K + +Byte 1 - E0 +OP_LVREN 1 - Enable LVR function +OP_LVRLEVEL 3 - 2.1V LVR level4 +OP_SCM 0 - SCM is invalid in warm up period +OP_OSC2SEL 0 - OSC2 select 12M RC +OP_IOV1 0 - P7.1/P7.2/P7.3/P7.4 input/output level is VUSB(5V) +OP_IOV0 0 - P5.5/P5.6 input/output level is VUSB(5V) + +Byte 2 - 63 +OP_SCMSEL 3 - 8MHz +OP_OSC 3 - Oscillator1 is internal 128KHz RC, oscillator2 is internal 24MHz RC + +Byte 3 - C0 +OP_ISP 1 - Disable ISP function +OP_ISPPIN 1 - Enter ISP mode only when P6.3 and P6.4 are connected to GND, simultaneously +OP_WDT 0 - Enable WDT function +OP_WDTPD 0 - Disable WDT function in Power-Down mode + +Byte 4 - 0F +OP_SINK1 3 - Port6[5:0] sink ability largest mode(380mA) +OP_SINK0 3 - P4.7/Port7[7:5] sink ability largest mode(50mA) + +Byte 5 - 00 +OP_BOPTP 0 - (1+21%)tr min +OP_BOPTN 0 - (1+21%)tf min + +Byte 6 - 00 +Unused + +Byte 7 - 88 +OP_ISPSIZE 8 - 0Bytes +``` diff --git a/docs/platforms/sh68f90a.md b/docs/platforms/sh68f90a.md new file mode 100644 index 0000000..8c70bf1 --- /dev/null +++ b/docs/platforms/sh68f90a.md @@ -0,0 +1,14 @@ +# SH68F90A (BYK901 / BYK916) Support + +## MCU + +- [x] 3.3V LDO +- [x] CPU Clock (use 24Mhz as SYSCLK) +- [x] GPIO +- [x] UART + - [x] Transmit + - [x] Receive +- [x] PWM +- [x] USB +- [ ] SPI +- [x] ISP (jump) diff --git a/docs/smk.md b/docs/smk.md new file mode 100644 index 0000000..e0d6e88 --- /dev/null +++ b/docs/smk.md @@ -0,0 +1,15 @@ +# SMK Supported Features + +- [x] Debug printf (via UART) +- [x] Key Scan + - [ ] Debouncing +- [x] Indicators (Backlight) +- [x] USB HID + - [x] ISP Command + - [x] USB Keyboard + - [x] Status LEDs + - [ ] Extra Keys (System / Consumer) + - [ ] NKRO +- [~] QMK Compatibility + - [~] Layouts +- [ ] Wireless diff --git a/flake.lock b/flake.lock index b35cffb..6d9248a 100644 --- a/flake.lock +++ b/flake.lock @@ -38,11 +38,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1714076141, - "narHash": "sha256-Drmja/f5MRHZCskS6mvzFqxEaZMeciScCTFxWVLqWEY=", + "lastModified": 1715534503, + "narHash": "sha256-5ZSVkFadZbFP1THataCaSf0JH2cAH3S29hU9rrxTEqk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "7bb2ccd8cdc44c91edba16c48d2c8f331fb3d856", + "rev": "2057814051972fa1453ddfb0d98badbea9b83c06", "type": "github" }, "original": { @@ -132,11 +132,11 @@ "utils": "utils" }, "locked": { - "lastModified": 1714293602, - "narHash": "sha256-njvLXXfcO+tdmNYthwwRe40eFyT/zchZacYJ7zUsSLA=", + "lastModified": 1715631942, + "narHash": "sha256-T57/xF9/m9RuOFNCxtHa16rf7ECwz+niYViQwZakarM=", "owner": "carlossless", "repo": "sinowealth-kb-tool", - "rev": "9e6c26a63ddf8e0af3149fbbcb1289eaba67bcca", + "rev": "03119a3143d5feb05f1f5f52a2671a9019919266", "type": "github" }, "original": { diff --git a/meson.build b/meson.build index 80f6c04..aeb65ee 100644 --- a/meson.build +++ b/meson.build @@ -17,6 +17,7 @@ default_options = { parts = [ ['example', 'sh68f90a', ['default'], {}], ['nuphy-air60', 'sh68f90a', ['default'], { 'vendor_id': '0x05ac', 'product_id': '0x024f' }], + ['eyooso-z11', 'sh68f90a', ['default'], { 'vendor_id': '0x258a', 'product_id': '0x002a' }], ] # SMK @@ -35,12 +36,15 @@ src_smk = [ 'src/smk/host.c', 'src/smk/matrix.c', 'src/smk/report.c', + 'src/smk/keyboard.c', ] # USER DEFAULTS src_user = [ + 'src/user/user_init.c', 'src/user/layout_process_record.c', + 'src/user/indicators_start.c', 'src/user/indicators_pre_update.c', 'src/user/indicators_update_step.c', 'src/user/indicators_post_update.c', @@ -55,13 +59,11 @@ inc_platform_sh68f90a = [ src_platform_sh68f90a = [ 'src/platform/sh68f90a/clock.c', 'src/platform/sh68f90a/delay.c', - 'src/platform/sh68f90a/gpio.c', 'src/platform/sh68f90a/isp.c', 'src/platform/sh68f90a/ldo.c', 'src/platform/sh68f90a/pwm.c', 'src/platform/sh68f90a/uart.c', 'src/platform/sh68f90a/usb.c', - 'src/platform/sh68f90a/keyboard.c', ] # USER KEYBOARDS @@ -79,7 +81,18 @@ inc_user_nuphy_air60 = [ ] src_user_nuphy_air60 = [ + 'src/keyboards/nuphy-air60/user_init.c', 'src/keyboards/nuphy-air60/user_matrix.c', + 'src/keyboards/nuphy-air60/user_keyboard.c', +] + +inc_user_eyooso_z11 = [ + 'src/keyboards/eyooso-z11', +] + +src_user_eyooso_z11 = [ + 'src/keyboards/eyooso-z11/user_init.c', + 'src/keyboards/eyooso-z11/user_matrix.c', ] # USER LAYOUTS @@ -93,6 +106,11 @@ src_user_nuphy_air60_default = [ 'src/keyboards/nuphy-air60/layouts/default/layout.c', ] +src_user_eyooso_z11_default = [ + 'src/keyboards/eyooso-z11/layouts/default/indicators.c', + 'src/keyboards/eyooso-z11/layouts/default/layout.c', +] + cc_base_args = [ '--Werror', '--std-c2x', @@ -154,19 +172,26 @@ foreach part : parts error('unsupported platform: @0@'.format(platform)) endif - if keyboard == 'nuphy-air60' + if keyboard == 'example' + src_main += src_user_example + inc_dirs += inc_user_example + + if layout == 'default' + src_main += src_user_example_default + endif + elif keyboard == 'nuphy-air60' src_main += src_user_nuphy_air60 inc_dirs += inc_user_nuphy_air60 if layout == 'default' src_main += src_user_nuphy_air60_default endif - elif keyboard == 'example' - src_main += src_user_example - inc_dirs += inc_user_example + elif keyboard == 'eyooso-z11' + src_main += src_user_eyooso_z11 + inc_dirs += inc_user_eyooso_z11 if layout == 'default' - src_main += src_user_example_default + src_main += src_user_eyooso_z11_default endif else error('unsupported keyboard: @0@'.format(keyboard)) diff --git a/src/keyboards/example/kbdef.h b/src/keyboards/example/kbdef.h index 9b50058..c5632aa 100644 --- a/src/keyboards/example/kbdef.h +++ b/src/keyboards/example/kbdef.h @@ -3,73 +3,21 @@ #include "sh68f90a.h" -#define MATRIX_ROWS 5 -#define MATRIX_COLS 16 +#define MATRIX_ROWS 1 +#define MATRIX_COLS 2 // Row Pins Bits #define KB_R0_P7_1 _P7_1 -#define KB_R1_P7_2 _P7_2 -#define KB_R2_P7_3 _P7_3 -#define KB_R2_P5_3 _P5_3 -#define KB_R2_P5_4 _P5_4 // Row Pins -// TODO +#define KB_R0 P7_1 // Column Pins Bits -#define KB_C0_P5_0 _P5_0 -#define KB_C1_P5_1 _P5_1 -#define KB_C2_P5_2 _P5_2 -#define KB_C3_P3_5 _P3_5 -#define KB_C4_P3_4 _P3_4 -#define KB_C5_P3_3 _P3_3 -#define KB_C6_P3_2 _P3_2 -#define KB_C7_P3_1 _P3_1 -#define KB_C8_P3_0 _P3_0 -#define KB_C9_P2_5 _P2_5 -#define KB_C10_P2_4 _P2_4 -#define KB_C11_P2_3 _P2_3 -#define KB_C12_P2_2 _P2_2 -#define KB_C13_P2_1 _P2_1 -#define KB_C14_P2_0 _P2_0 -#define KB_C15_P1_5 _P1_5 +#define KB_C0_P5_0 _P5_0 +#define KB_C1_P5_1 _P5_1 // Column Pins -#define KB_C0 P5_0 -#define KB_C1 P5_1 -#define KB_C2 P5_2 -#define KB_C3 P3_5 -#define KB_C4 P3_4 -#define KB_C5 P3_3 -#define KB_C6 P3_2 -#define KB_C7 P3_1 -#define KB_C8 P3_0 -#define KB_C9 P2_5 -#define KB_C10 P2_4 -#define KB_C11 P2_3 -#define KB_C12 P2_2 -#define KB_C13 P2_1 -#define KB_C14 P2_0 -#define KB_C15 P1_5 - -// RGB Row Pins -#define RGB_R0R_P0_4 _P0_4 -#define RGB_R0G_P6_1 _P6_1 -#define RGB_R0B_P0_3 _P0_3 -#define RGB_R1R_P6_7 _P6_7 -#define RGB_R1G_P6_2 _P6_2 -#define RGB_R1B_P6_6 _P6_6 -#define RGB_R2R_P0_2 _P0_2 -#define RGB_R2G_P6_3 _P6_3 -#define RGB_R2B_P5_7 _P5_7 -#define RGB_R3R_P4_5 _P4_5 -#define RGB_R3G_P6_4 _P6_4 -#define RGB_R3B_P4_6 _P4_6 -#define RGB_R4R_P4_4 _P4_4 -#define RGB_R4G_P6_5 _P6_5 -#define RGB_R4B_P4_3 _P4_3 -#define RGB_ULR_P1_1 _P1_1 -#define RGB_ULG_P1_2 _P1_2 -#define RGB_ULB_P1_3 _P1_3 +#define KB_C0 P5_0 +#define KB_C1 P5_1 #endif diff --git a/src/keyboards/example/layouts/default/layout.c b/src/keyboards/example/layouts/default/layout.c index f8a483a..b662168 100644 --- a/src/keyboards/example/layouts/default/layout.c +++ b/src/keyboards/example/layouts/default/layout.c @@ -1,21 +1,15 @@ #include "kbdef.h" #include "layout.h" +#include "user_layout.h" +#include "report.h" #include // clang-format off #define LAYOUT_60( \ - K00_0, K01_0, K02_0, K03_0, K04_0, K05_0, K06_0, K07_0, K08_0, K09_0, K10_0, K11_0, K12_0, K13_0, \ - K00_1, K01_1, K02_1, K03_1, K04_1, K05_1, K06_1, K07_1, K08_1, K09_1, K10_1, K11_1, K12_1, K13_1, \ - K00_2, K01_2, K02_2, K03_2, K04_2, K05_2, K06_2, K07_2, K08_2, K09_2, K10_2, K11_2, K13_2, \ - K00_3, K01_3, K02_3, K03_3, K04_3, K05_3, K06_3, K07_3, K08_3, K09_3, K10_3, K13_3, K14_3, K15_3, \ - K00_4, K01_4, K02_4, K05_4, K08_4, K09_4, K10_4, K13_4, K14_4 \ + K00_0, K01_0 \ ) { \ - { K00_0, K01_0, K02_0, K03_0, K04_0, K05_0, K06_0, K07_0, K08_0, K09_0, K10_0, K11_0, K12_0, K13_0, KC_NO, KC_NO }, \ - { K00_1, K01_1, K02_1, K03_1, K04_1, K05_1, K06_1, K07_1, K08_1, K09_1, K10_1, K11_1, K12_1, K13_1, KC_NO, KC_NO }, \ - { K00_2, K01_2, K02_2, K03_2, K04_2, K05_2, K06_2, K07_2, K08_2, K09_2, K10_2, K11_2, KC_NO, K13_2, KC_NO, KC_NO }, \ - { K00_3, K01_3, K02_3, K03_3, K04_3, K05_3, K06_3, K07_3, K08_3, K09_3, K10_3, KC_NO, KC_NO, K13_3, K14_3, K15_3 }, \ - { K00_4, K01_4, K02_4, KC_NO, KC_NO, K05_4, KC_NO, KC_NO, K08_4, K09_4, K10_4, KC_NO, KC_NO, K13_4, K14_4, KC_NO } \ + { K00_0, K01_0 } \ } // Each layer gets a name for readability, which is then used in the keymap matrix below. @@ -23,52 +17,14 @@ // Layer names don't all need to be of the same length, obviously, and you can also skip them // entirely and just use numbers. #define _BL 0 -#define _FL 1 - -enum custom_keycodes { - SFT_ESC = SAFE_RANGE -}; const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { /* Keymap _BL: (Base Layer) Default Layer - * ,------------------------------------------------------------. - * |Esc| 1| 2| 3| 4| 5| 6| 7| 8| 9| 0| -| =| Backsp| - * |------------------------------------------------------------| - * |Tab | Q| W| E| R| T| Y| U| I| O| P| [| ]| \| - * |------------------------------------------------------------| - * |CAPS | A| S| D| F| G| H| J| K| L| ;| '| Return| - * |------------------------------------------------------------| - * |Shift | Z| X| C| V| B| N| M| ,| .| /|Shi| Up|Del| - * |------------------------------------------------------------| - * |Ctrl|Alt |Gui | Space |Gui|Fn |Lef|Dow|Rig| - * `------------------------------------------------------------' + * ,-------. + * |Esc|Ent| + * `-------' */ [_BL] = LAYOUT_60( - SFT_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, - KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, - KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, - KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_DEL, - KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_LGUI, MO(_FL), KC_LEFT, KC_DOWN, KC_RIGHT - ), - - /* Keymap _FL: (Base Layer) Function Layer - * ,------------------------------------------------------------. - * | ~ | F1| F2| F3| F4| F5| F6| F7| F8| F9|F10|F11|F12| Del | - * |------------------------------------------------------------| - * | | | | | | | | | | | | | | | - * |------------------------------------------------------------| - * | | | | | | | | | | | | | | - * |------------------------------------------------------------| - * | | | | | | | | | | | | | | | - * |------------------------------------------------------------| - * | | | | | | | | | | - * `------------------------------------------------------------' - */ - [_FL] = LAYOUT_60( - KC_GRV, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_DEL, - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, - _______, _______, _______, _______, _______, _______, _______, _______, _______ - ), + KC_ESC, KC_ENT + ) }; diff --git a/src/keyboards/eyooso-z11/kbdef.h b/src/keyboards/eyooso-z11/kbdef.h new file mode 100644 index 0000000..c1b7717 --- /dev/null +++ b/src/keyboards/eyooso-z11/kbdef.h @@ -0,0 +1,91 @@ +#ifndef KBDEF_H +#define KBDEF_H + +#include "sh68f90a.h" + +#define MATRIX_ROWS 5 +#define MATRIX_COLS 14 + +// Row Pin Bits +#define KB_R0_P7_1 _P7_1 +#define KB_R1_P7_2 _P7_2 +#define KB_R2_P7_3 _P7_3 +#define KB_R3_P5_3 _P5_3 +#define KB_R4_P5_4 _P5_4 + +// Row Pins +#define KB_R0 P7_1 +#define KB_R1 P7_2 +#define KB_R2 P7_3 +#define KB_R3 P5_3 +#define KB_R4 P5_4 + +// Column Pin Bits +#define KB_C0_P1_4 _P1_4 +#define KB_C1_P1_5 _P1_5 +#define KB_C2_P2_0 _P2_0 +#define KB_C3_P2_1 _P2_1 +#define KB_C4_P2_2 _P2_2 +#define KB_C5_P2_3 _P2_3 +#define KB_C6_P2_4 _P2_4 +#define KB_C7_P2_5 _P2_5 +#define KB_C8_P3_0 _P3_0 +#define KB_C9_P3_1 _P3_1 +#define KB_C10_P3_2 _P3_2 +#define KB_C11_P3_3 _P3_3 +#define KB_C12_P3_4 _P3_4 +#define KB_C13_P3_5 _P3_5 + +// Column Pins +#define KB_C0 P1_4 +#define KB_C1 P1_5 +#define KB_C2 P2_0 +#define KB_C3 P2_1 +#define KB_C4 P2_2 +#define KB_C5 P2_3 +#define KB_C6 P2_4 +#define KB_C7 P2_5 +#define KB_C8 P3_0 +#define KB_C9 P3_1 +#define KB_C10 P3_2 +#define KB_C11 P3_3 +#define KB_C12 P3_4 +#define KB_C13 P3_5 + +// LED PWM Registers +#define LED_PWM_C0 PWM24 +#define LED_PWM_C1 PWM25 +#define LED_PWM_C2 PWM10 +#define LED_PWM_C3 PWM11 +#define LED_PWM_C4 PWM12 +#define LED_PWM_C5 PWM13 +#define LED_PWM_C6 PWM14 +#define LED_PWM_C7 PWM15 +#define LED_PWM_C8 PWM00 +#define LED_PWM_C9 PWM01 +#define LED_PWM_C10 PWM02 +#define LED_PWM_C11 PWM03 +#define LED_PWM_C12 PWM04 +#define LED_PWM_C13 PWM05 + +// LED Row Pin Bits +#define LED_R0_P6_1 _P6_1 +#define LED_R1_P6_2 _P6_2 +#define LED_R2_P6_3 _P6_3 +#define LED_R3_P6_4 _P6_4 +#define LED_R4_P6_5 _P6_5 + +// LED Row Pins +#define LED_R0 P6_1 +#define LED_R1 P6_2 +#define LED_R2 P6_3 +#define LED_R3 P6_4 +#define LED_R4 P6_5 + +// KC_CAPS LED Pin +#define LED_CAPS P0_3 + +// KC_CAPS LED Pin Bit +#define LED_CAPS_P0_3 _P0_3 + +#endif diff --git a/src/keyboards/eyooso-z11/layouts/default/indicators.c b/src/keyboards/eyooso-z11/layouts/default/indicators.c new file mode 100644 index 0000000..962125c --- /dev/null +++ b/src/keyboards/eyooso-z11/layouts/default/indicators.c @@ -0,0 +1,125 @@ +#include "indicators.h" +#include "sh68f90a.h" +#include "kbdef.h" +#include "pwm.h" +#include + +// TODO: move these defines out +#define PWM_CLK_DIV 0b010 // PWM_CLK = SYS_CLK / 4 +#define PWM_SS_BIT (1 << 3) +#define PWM_MOD_BIT (1 << 4) +#define PWM_INT_ENABLE_BIT (1 << 6) +#define PWM_MODE_ENABLE_BIT (1 << 7) + +void indicators_pwm_set_all_columns(uint16_t intensity); +void indicators_pwm_enable(); +void indicators_pwm_disable(); + +void indicators_start() +{ + indicators_pwm_enable(); +} + +void indicators_pre_update() +{ + // set all rgb sinks to low (animation step will enable needed ones) + P6 &= ~(LED_R0_P6_1 | LED_R1_P6_2 | LED_R2_P6_3 | LED_R3_P6_4 | LED_R4_P6_5); + + indicators_pwm_disable(); +} + +bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) +{ + static uint16_t current_cycle = 0; + + if (current_step == 0) { + if (current_cycle < 2048) { + current_cycle++; + } else { + current_cycle = 0; + } + } + + uint16_t intensity = 0; + + intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle + 1024) % 2048) - 1024); + + LED_CAPS = !(keyboard->led_state & (1 << 1)); + + // set pwm duty cycles to expected colors + indicators_pwm_set_all_columns(intensity); + + return false; +} + +void indicators_post_update() +{ + // clear pwm isr flag + PWM00CON &= ~(1 << 5); + + indicators_pwm_enable(); +} + +void indicators_pwm_set_all_columns(uint16_t intensity) +{ + uint16_t adjusted = 0x0400 - intensity; + + SET_PWM_DUTY_2(LED_PWM_C0, adjusted); + SET_PWM_DUTY_2(LED_PWM_C1, adjusted); + SET_PWM_DUTY_2(LED_PWM_C2, adjusted); + SET_PWM_DUTY_2(LED_PWM_C3, adjusted); + SET_PWM_DUTY_2(LED_PWM_C4, adjusted); + SET_PWM_DUTY_2(LED_PWM_C5, adjusted); + SET_PWM_DUTY_2(LED_PWM_C6, adjusted); + SET_PWM_DUTY_2(LED_PWM_C7, adjusted); + SET_PWM_DUTY_2(LED_PWM_C8, adjusted); + SET_PWM_DUTY_2(LED_PWM_C9, adjusted); + SET_PWM_DUTY_2(LED_PWM_C10, adjusted); + SET_PWM_DUTY_2(LED_PWM_C11, adjusted); + SET_PWM_DUTY_2(LED_PWM_C12, adjusted); + SET_PWM_DUTY_2(LED_PWM_C13, adjusted); +} + +void indicators_pwm_enable() +{ + // TODO: try abstracting individual banks away + PWM00CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_INT_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM01CON = PWM_SS_BIT; + PWM02CON = PWM_SS_BIT; + PWM03CON = PWM_SS_BIT; + PWM04CON = PWM_SS_BIT; + PWM05CON = PWM_SS_BIT; + + PWM10CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM11CON = PWM_SS_BIT; + PWM12CON = PWM_SS_BIT; + PWM13CON = PWM_SS_BIT; + PWM14CON = PWM_SS_BIT; + PWM15CON = PWM_SS_BIT; + + PWM20CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM24CON = PWM_SS_BIT; + PWM25CON = PWM_SS_BIT; +} + +void indicators_pwm_disable() +{ + // TODO: try abstracting individual banks away + PWM00CON = (uint8_t)(PWM_CLK_DIV); + PWM01CON = 0; + PWM02CON = 0; + PWM03CON = 0; + PWM04CON = 0; + PWM05CON = 0; + + PWM10CON = (uint8_t)(PWM_CLK_DIV); + PWM11CON = 0; + PWM12CON = 0; + PWM13CON = 0; + PWM14CON = 0; + PWM15CON = 0; + + PWM20CON = (uint8_t)(PWM_CLK_DIV); + PWM24CON = 0; + PWM25CON = 0; +} diff --git a/src/keyboards/eyooso-z11/layouts/default/layout.c b/src/keyboards/eyooso-z11/layouts/default/layout.c new file mode 100644 index 0000000..68cac19 --- /dev/null +++ b/src/keyboards/eyooso-z11/layouts/default/layout.c @@ -0,0 +1,41 @@ +#include "kbdef.h" +#include "layout.h" +#include "user_layout.h" +#include "report.h" +#include + +// clang-format off + +#define LAYOUT_60( \ + K00_0, K01_0, K02_0, K03_0, K04_0, K05_0, K06_0, K07_0, K08_0, K09_0, K10_0, K11_0, K12_0, K13_0, \ + K00_1, K01_1, K02_1, K03_1, K04_1, K05_1, K06_1, K07_1, K08_1, K09_1, K10_1, K11_1, K12_1, K13_1, \ + K00_2, K01_2, K02_2, K03_2, K04_2, K05_2, K06_2, K07_2, K08_2, K09_2, K10_2, K11_2, K13_2, \ + K00_3, K01_3, K02_3, K03_3, K04_3, K05_3, K06_3, K07_3, K08_3, K09_3, K10_3, K12_3, \ + K00_4, K01_4, K02_4, K05_4, K08_4, K09_4, K10_4, K11_4 \ + ) { \ + { K00_0, K01_0, K02_0, K03_0, K04_0, K05_0, K06_0, K07_0, K08_0, K09_0, K10_0, K11_0, K12_0, K13_0 }, \ + { K00_1, K01_1, K02_1, K03_1, K04_1, K05_1, K06_1, K07_1, K08_1, K09_1, K10_1, K11_1, K12_1, K13_1 }, \ + { K00_2, K01_2, K02_2, K03_2, K04_2, K05_2, K06_2, K07_2, K08_2, K09_2, K10_2, K11_2, KC_NO, K13_2 }, \ + { K00_3, K01_3, K02_3, K03_3, K04_3, K05_3, K06_3, K07_3, K08_3, K09_3, K10_3, KC_NO, K12_3, KC_NO }, \ + { K00_4, K01_4, K02_4, KC_NO, KC_NO, K05_4, KC_NO, KC_NO, K08_4, K09_4, K10_4, K11_4, KC_NO, KC_NO } \ +} + +#define _BL 0 +#define _FL 1 + +const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { + [_BL] = LAYOUT_60( + KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC, + KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, + KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, + KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, + KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(_FL), KC_APP , KC_RCTL + ), + [_FL] = LAYOUT_60( + _______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, + _______, _______, KC_UP , _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_HOME, KC_END, _______, + _______, KC_LEFT, KC_DOWN, KC_RGHT, _______, _______, _______, _______, _______, _______, KC_PGUP, KC_PGDN, _______, + _______, _______, _______, _______, _______, _______, _______, _______, _______, KC_INS, KC_DEL, _______, + _______, _______, _______, _______, _______, _______, _______, _______ + ) +}; diff --git a/src/keyboards/eyooso-z11/user_init.c b/src/keyboards/eyooso-z11/user_init.c new file mode 100644 index 0000000..8362f4e --- /dev/null +++ b/src/keyboards/eyooso-z11/user_init.c @@ -0,0 +1,78 @@ +#include "kbdef.h" +#include "user_init.h" +#include "pwm.h" + +// TODO: move these defines out +#define PWM_PERD 0x0400 // 1024 / PWM_CLK ~= 43 us + +#define PWM_DUTY1 (uint16_t) PWM_PERD +#define PWM_DUTY2 (uint16_t)0 + +#define PWM_PERDH_INIT ((uint8_t)(PWM_PERD >> 8)) +#define PWM_PERDL_INIT ((uint8_t)(PWM_PERD)) + +void user_gpio_init(); +void user_pwm_init(); + +void user_init() +{ + user_gpio_init(); + user_pwm_init(); + + IEN1 |= (1 << 1); // EPWM0 +} + +void user_gpio_init() +{ + // configure driving capabilities + DRVCON = 0x05; // allow P1 to be changed + P1DRV = 0x00; // 25mA + + DRVCON = 0x45; // allow P2 to be changed + P2DRV = 0x00; // 25mA + + DRVCON = 0x85; // allow P3 to be changed + P3DRV = 0x00; // 25mA + + DRVCON = 0; + + P0CR = (uint8_t)(LED_CAPS_P0_3); + P1CR = (uint8_t)(KB_C0_P1_4 | KB_C1_P1_5); + P2CR = (uint8_t)(KB_C2_P2_0 | KB_C3_P2_1 | KB_C4_P2_2 | KB_C5_P2_3 | KB_C6_P2_4 | KB_C7_P2_5); + P3CR = (uint8_t)(KB_C8_P3_0 | KB_C9_P3_1 | KB_C10_P3_2 | KB_C11_P3_3 | KB_C12_P3_4 | KB_C13_P3_5); + P6CR = (uint8_t)(LED_R0_P6_1 | LED_R1_P6_2 | LED_R2_P6_3 | LED_R3_P6_4 | LED_R4_P6_5); + + P5PCR = (uint8_t)(KB_R3_P5_3 | KB_R4_P5_4); + // P6PCR = (uint8_t)(LED_R0_P6_1 | LED_R1_P6_2 | LED_R2_P6_3 | LED_R3_P6_4 | LED_R4_P6_5); + P7PCR = (uint8_t)(KB_R0_P7_1 | KB_R1_P7_2 | KB_R2_P7_3); + + P0 = (uint8_t)(LED_CAPS_P0_3); + P6 = (uint8_t)(LED_R0_P6_1 | LED_R1_P6_2 | LED_R2_P6_3 | LED_R3_P6_4 | LED_R4_P6_5); +} + +void user_pwm_init() +{ + PWM0PERDH = PWM_PERDH_INIT; + PWM0PERDL = PWM_PERDL_INIT; + + PWM1PERDH = PWM_PERDH_INIT; + PWM1PERDL = PWM_PERDL_INIT; + + PWM2PERDH = PWM_PERDH_INIT; + PWM2PERDL = PWM_PERDL_INIT; + + SET_PWM_DUTY(LED_PWM_C0, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C1, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C2, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C3, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C4, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C5, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C6, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C7, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C8, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C9, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C10, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C11, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C12, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C13, PWM_DUTY1, PWM_DUTY2); +} diff --git a/src/keyboards/eyooso-z11/user_matrix.c b/src/keyboards/eyooso-z11/user_matrix.c new file mode 100644 index 0000000..369e4e8 --- /dev/null +++ b/src/keyboards/eyooso-z11/user_matrix.c @@ -0,0 +1,89 @@ +#include "kbdef.h" +#include "user_matrix.h" + +void user_matrix_pre_scan(uint8_t col) +{ + // set all columns to high + P1 |= (uint8_t)(KB_C0_P1_4 | KB_C1_P1_5); + P2 |= (uint8_t)(KB_C2_P2_0 | KB_C3_P2_1 | KB_C4_P2_2 | KB_C5_P2_3 | KB_C6_P2_4 | KB_C7_P2_5); + P3 |= (uint8_t)(KB_C8_P3_0 | KB_C9_P3_1 | KB_C10_P3_2 | KB_C11_P3_3 | KB_C12_P3_4 | KB_C13_P3_5); + + // set current (!) column to low + switch (col) { + case 0: + KB_C0 = 0; + break; + + case 1: + KB_C1 = 0; + break; + + case 2: + KB_C2 = 0; + break; + + case 3: + KB_C3 = 0; + break; + + case 4: + KB_C4 = 0; + break; + + case 5: + KB_C5 = 0; + break; + + case 6: + KB_C6 = 0; + break; + + case 7: + KB_C7 = 0; + break; + + case 8: + KB_C8 = 0; + break; + + case 9: + KB_C9 = 0; + break; + + case 10: + KB_C10 = 0; + break; + + case 11: + KB_C11 = 0; + break; + + case 12: + KB_C12 = 0; + break; + + case 13: + KB_C13 = 0; + break; + } +} + +uint8_t user_matrix_scan_col(uint8_t col) +{ + col; + // grab key for the column state + // P7_1 - R0 + // P7_2 - R1 + // P7_3 - R2 + // P5_3 - R3 + // P5_4 - R4 + return (((P7 >> 1) & 0x07) | (P5 & 0x18)) | 0xe0; +} + +void user_matrix_post_scan() +{ + // set all columns down to low + P1 &= (uint8_t) ~(KB_C0_P1_4 | KB_C1_P1_5); + P2 &= (uint8_t) ~(KB_C2_P2_0 | KB_C3_P2_1 | KB_C4_P2_2 | KB_C5_P2_3 | KB_C6_P2_4 | KB_C7_P2_5); + P3 &= (uint8_t) ~(KB_C8_P3_0 | KB_C9_P3_1 | KB_C10_P3_2 | KB_C11_P3_3 | KB_C12_P3_4 | KB_C13_P3_5); +} diff --git a/src/keyboards/nuphy-air60/kbdef.h b/src/keyboards/nuphy-air60/kbdef.h index 9b50058..a45c6a7 100644 --- a/src/keyboards/nuphy-air60/kbdef.h +++ b/src/keyboards/nuphy-air60/kbdef.h @@ -6,17 +6,21 @@ #define MATRIX_ROWS 5 #define MATRIX_COLS 16 -// Row Pins Bits +// Row Pin Bits #define KB_R0_P7_1 _P7_1 #define KB_R1_P7_2 _P7_2 #define KB_R2_P7_3 _P7_3 -#define KB_R2_P5_3 _P5_3 -#define KB_R2_P5_4 _P5_4 +#define KB_R3_P5_3 _P5_3 +#define KB_R4_P5_4 _P5_4 // Row Pins -// TODO +#define KB_R0 P7_1 +#define KB_R1 P7_2 +#define KB_R2 P7_3 +#define KB_R3 P5_3 +#define KB_R4 P5_4 -// Column Pins Bits +// Column Pin Bits #define KB_C0_P5_0 _P5_0 #define KB_C1_P5_1 _P5_1 #define KB_C2_P5_2 _P5_2 @@ -52,7 +56,45 @@ #define KB_C14 P2_0 #define KB_C15 P1_5 +// LED PWM Registers +#define LED_PWM_C0 PWM40 +#define LED_PWM_C1 PWM41 +#define LED_PWM_C2 PWM42 +#define LED_PWM_C3 PWM05 +#define LED_PWM_C4 PWM04 +#define LED_PWM_C5 PWM03 +#define LED_PWM_C6 PWM02 +#define LED_PWM_C7 PWM01 +#define LED_PWM_C8 PWM00 +#define LED_PWM_C9 PWM15 +#define LED_PWM_C10 PWM14 +#define LED_PWM_C11 PWM13 +#define LED_PWM_C12 PWM12 +#define LED_PWM_C13 PWM11 +#define LED_PWM_C14 PWM10 +#define LED_PWM_C15 PWM25 + // RGB Row Pins +#define RGB_R0R P0_4 +#define RGB_R0G P6_1 +#define RGB_R0B P0_3 +#define RGB_R1R P6_7 +#define RGB_R1G P6_2 +#define RGB_R1B P6_6 +#define RGB_R2R P0_2 +#define RGB_R2G P6_3 +#define RGB_R2B P5_7 +#define RGB_R3R P4_5 +#define RGB_R3G P6_4 +#define RGB_R3B P4_6 +#define RGB_R4R P4_4 +#define RGB_R4G P6_5 +#define RGB_R4B P4_3 +#define RGB_ULR P1_1 +#define RGB_ULG P1_2 +#define RGB_ULB P1_3 + +// RGB Row Pin Bits #define RGB_R0R_P0_4 _P0_4 #define RGB_R0G_P6_1 _P6_1 #define RGB_R0B_P0_3 _P0_3 @@ -72,4 +114,12 @@ #define RGB_ULG_P1_2 _P1_2 #define RGB_ULB_P1_3 _P1_3 +// Config Switch Pins +#define CONN_MODE_SWITCH P5_5 // 1 - USB, 0 - RF +#define OS_MODE_SWITCH P5_6 // 1 - MAC, 0 - WIN + +// Config Switch Pin Bits +#define CONN_MODE_SWITCH_P5_5 _P5_5 // 1 - USB, 0 - RF +#define OS_MODE_SWITCH_P5_6 _P5_6 // 1 - MAC, 0 - WIN + #endif diff --git a/src/keyboards/nuphy-air60/layouts/default/indicators.c b/src/keyboards/nuphy-air60/layouts/default/indicators.c index 813600e..7b68687 100644 --- a/src/keyboards/nuphy-air60/layouts/default/indicators.c +++ b/src/keyboards/nuphy-air60/layouts/default/indicators.c @@ -1,18 +1,34 @@ #include "indicators.h" -#include "sh68f90a.h" +#include "kbdef.h" #include "pwm.h" #include +// TODO: move these defines out +#define PWM_CLK_DIV 0b010 // PWM_CLK = SYS_CLK / 4 +#define PWM_SS_BIT (1 << 3) +#define PWM_MOD_BIT (1 << 4) +#define PWM_INT_ENABLE_BIT (1 << 6) +#define PWM_MODE_ENABLE_BIT (1 << 7) + +void indicators_pwm_set_all_columns(uint16_t intensity); +void indicators_pwm_enable(); +void indicators_pwm_disable(); + +void indicators_start() +{ + indicators_pwm_enable(); +} + void indicators_pre_update() { // set all rgb sinks to low (animation step will enable needed ones) - P0 &= ~(_P0_2 | _P0_3 | _P0_4); - P1 &= ~(_P1_1 | _P1_2 | _P1_3); - P4 &= ~(_P4_3 | _P4_4 | _P4_5 | _P4_6); - P5 &= ~(_P5_7); - P6 &= ~(_P6_1 | _P6_2 | _P6_3 | _P6_4 | _P6_5 | _P6_6 | _P6_7); + P0 &= ~(RGB_R2R_P0_2 | RGB_R0B_P0_3 | RGB_R0R_P0_4); + P1 &= ~(RGB_ULR_P1_1 | RGB_ULG_P1_2 | RGB_ULB_P1_3); + P4 &= ~(RGB_R4B_P4_3 | RGB_R4R_P4_4 | RGB_R3R_P4_5 | RGB_R3B_P4_6); + P5 &= ~(RGB_R2B_P5_7); + P6 &= ~(RGB_R0G_P6_1 | RGB_R1G_P6_2 | RGB_R2G_P6_3 | RGB_R3G_P6_4 | RGB_R4G_P6_5 | RGB_R1B_P6_6 | RGB_R1R_P6_7); - pwm_disable(); + indicators_pwm_disable(); } bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) @@ -58,34 +74,34 @@ bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) switch (current_step % 3) { case 0: // red - P0_4 = 1; - P6_7 = 1; - P0_2 = 1; - P4_5 = 1; - P4_4 = 1; - P1_1 = 1; + RGB_R0R = 1; + RGB_R1R = 1; + RGB_R2R = 1; + RGB_R3R = 1; + RGB_R4R = 1; + RGB_ULR = 1; color_intensity = red_intensity; break; case 1: // green - P6_1 = 1; - P6_2 = 1; - P6_3 = 1; - P6_4 = 1; - P6_5 = 1; - P1_2 = 1; + RGB_R0G = 1; + RGB_R1G = 1; + RGB_R2G = 1; + RGB_R3G = 1; + RGB_R4G = 1; + RGB_ULG = 1; color_intensity = green_intensity; break; case 2: // blue - P0_3 = 1; - P6_6 = 1; - P5_7 = 1; - P4_6 = 1; - P4_3 = 1; - P1_3 = 1; + RGB_R0B = 1; + RGB_R1B = 1; + RGB_R2B = 1; + RGB_R3B = 1; + RGB_R4B = 1; + RGB_ULB = 1; color_intensity = blue_intensity; break; @@ -97,7 +113,7 @@ bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step) } // set pwm duty cycles to expected colors - pwm_set_all_columns(color_intensity); + indicators_pwm_set_all_columns(color_intensity); return false; } @@ -107,5 +123,79 @@ void indicators_post_update() // clear pwm isr flag PWM00CON &= ~(1 << 5); - pwm_enable(); + indicators_pwm_enable(); +} + +void indicators_pwm_set_all_columns(uint16_t intensity) +{ + uint16_t adjusted = 0x0400 - intensity; + + SET_PWM_DUTY_2(LED_PWM_C0, adjusted); + SET_PWM_DUTY_2(LED_PWM_C1, adjusted); + SET_PWM_DUTY_2(LED_PWM_C2, adjusted); + SET_PWM_DUTY_2(LED_PWM_C3, adjusted); + SET_PWM_DUTY_2(LED_PWM_C4, adjusted); + SET_PWM_DUTY_2(LED_PWM_C5, adjusted); + SET_PWM_DUTY_2(LED_PWM_C6, adjusted); + SET_PWM_DUTY_2(LED_PWM_C7, adjusted); + SET_PWM_DUTY_2(LED_PWM_C8, adjusted); + SET_PWM_DUTY_2(LED_PWM_C9, adjusted); + SET_PWM_DUTY_2(LED_PWM_C10, adjusted); + SET_PWM_DUTY_2(LED_PWM_C11, adjusted); + SET_PWM_DUTY_2(LED_PWM_C12, adjusted); + SET_PWM_DUTY_2(LED_PWM_C13, adjusted); + SET_PWM_DUTY_2(LED_PWM_C14, adjusted); + SET_PWM_DUTY_2(LED_PWM_C15, adjusted); +} + +void indicators_pwm_enable() +{ + // TODO: try abstracting individual banks away + PWM00CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_INT_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM01CON = PWM_SS_BIT; + PWM02CON = PWM_SS_BIT; + PWM03CON = PWM_SS_BIT; + PWM04CON = PWM_SS_BIT; + PWM05CON = PWM_SS_BIT; + + PWM10CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM11CON = PWM_SS_BIT; + PWM12CON = PWM_SS_BIT; + PWM13CON = PWM_SS_BIT; + PWM14CON = PWM_SS_BIT; + PWM15CON = PWM_SS_BIT; + + PWM20CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + // PWM24CON = PWM_SS_BIT; + PWM25CON = PWM_SS_BIT; + + PWM40CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); + PWM41CON = PWM_SS_BIT; + PWM42CON = PWM_SS_BIT; +} + +void indicators_pwm_disable() +{ + // TODO: try abstracting individual banks away + PWM00CON = (uint8_t)(PWM_CLK_DIV); + PWM01CON = 0; + PWM02CON = 0; + PWM03CON = 0; + PWM04CON = 0; + PWM05CON = 0; + + PWM10CON = (uint8_t)(PWM_CLK_DIV); + PWM11CON = 0; + PWM12CON = 0; + PWM13CON = 0; + PWM14CON = 0; + PWM15CON = 0; + + PWM20CON = (uint8_t)(PWM_CLK_DIV); + // PWM24CON = 0; + PWM25CON = 0; + + PWM40CON = (uint8_t)(PWM_CLK_DIV); + PWM41CON = 0; + PWM42CON = 0; } diff --git a/src/keyboards/nuphy-air60/layouts/default/layout.c b/src/keyboards/nuphy-air60/layouts/default/layout.c index 1182486..17316f5 100644 --- a/src/keyboards/nuphy-air60/layouts/default/layout.c +++ b/src/keyboards/nuphy-air60/layouts/default/layout.c @@ -1,5 +1,6 @@ #include "kbdef.h" #include "layout.h" +#include "user_layout.h" #include "report.h" #include @@ -49,7 +50,7 @@ const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS, KC_CAPS, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_ENT, KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_RSFT, KC_UP, KC_DEL, - KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_LGUI, MO(_FL), KC_LEFT, KC_DOWN, KC_RIGHT + KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, KC_LGUI, MO(_FL), KC_LEFT, KC_DOWN, KC_RGHT ), /* Keymap _FL: (Base Layer) Function Layer diff --git a/src/keyboards/nuphy-air60/user_init.c b/src/keyboards/nuphy-air60/user_init.c new file mode 100644 index 0000000..2fb9f17 --- /dev/null +++ b/src/keyboards/nuphy-air60/user_init.c @@ -0,0 +1,84 @@ +#include "kbdef.h" +#include "user_init.h" +#include "pwm.h" + +// TODO: move these defines out +#define PWM_PERD 0x0400 // 1024 / PWM_CLK ~= 43 us + +#define PWM_DUTY1 (uint16_t) PWM_PERD +#define PWM_DUTY2 (uint16_t)0 + +#define PWM_PERDH_INIT ((uint8_t)(PWM_PERD >> 8)) +#define PWM_PERDL_INIT ((uint8_t)(PWM_PERD)) + +void user_gpio_init(); +void user_pwm_init(); + +void user_init() +{ + user_gpio_init(); + user_pwm_init(); + + IEN1 |= (1 << 1); // EPWM0 +} + +void user_gpio_init() +{ + // configure driving capabilities + DRVCON = 0x05; // allow P1 to be changed + P1DRV = 0x00; // 25mA + + DRVCON = 0x45; // allow P2 to be changed + P2DRV = 0x00; // 25mA + + DRVCON = 0x85; // allow P3 to be changed + P3DRV = 0x00; // 25mA + + DRVCON = 0xc5; // allow P5 to be changed + P5DRV = 0x00; // 25mA + + DRVCON = 0; + + P0CR = (uint8_t)(RGB_R2R_P0_2 | RGB_R0B_P0_3 | RGB_R0R_P0_4); + P1CR = (uint8_t)(RGB_ULR_P1_1 | RGB_ULG_P1_2 | RGB_ULB_P1_3 | KB_C15_P1_5); + P2CR = (uint8_t)(KB_C14_P2_0 | KB_C13_P2_1 | KB_C12_P2_2 | KB_C11_P2_3 | KB_C10_P2_4 | KB_C9_P2_5); + P3CR = (uint8_t)(KB_C8_P3_0 | KB_C7_P3_1 | KB_C6_P3_2 | KB_C5_P3_3 | KB_C4_P3_4 | KB_C3_P3_5); + P4CR = (uint8_t)(RGB_R4B_P4_3 | RGB_R4R_P4_4 | RGB_R3R_P4_5 | RGB_R3B_P4_6); + P5CR = (uint8_t)(KB_C0_P5_0 | KB_C1_P5_1 | KB_C2_P5_2 | RGB_R2B_P5_7); + P6CR = (uint8_t)(RGB_R0G_P6_1 | RGB_R1G_P6_2 | RGB_R2G_P6_3 | RGB_R3G_P6_4 | RGB_R4G_P6_5 | RGB_R1B_P6_6 | RGB_R1R_P6_7); + + P5PCR = (uint8_t)(KB_R3_P5_3 | KB_R4_P5_4 | CONN_MODE_SWITCH_P5_5 | OS_MODE_SWITCH_P5_6); + P7PCR = (uint8_t)(KB_R0_P7_1 | KB_R1_P7_2 | KB_R2_P7_3); +} + +void user_pwm_init() +{ + PWM0PERDH = PWM_PERDH_INIT; + PWM0PERDL = PWM_PERDL_INIT; + + PWM1PERDH = PWM_PERDH_INIT; + PWM1PERDL = PWM_PERDL_INIT; + + PWM2PERDH = PWM_PERDH_INIT; + PWM2PERDL = PWM_PERDL_INIT; + + PWM4PERDH = PWM_PERDH_INIT; + PWM4PERDL = PWM_PERDL_INIT; + + SET_PWM_DUTY(LED_PWM_C0, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C1, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C2, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C3, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C4, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C5, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C6, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C7, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C8, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C9, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C10, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C11, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C12, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C13, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C14, PWM_DUTY1, PWM_DUTY2); + SET_PWM_DUTY(LED_PWM_C15, PWM_DUTY1, PWM_DUTY2); +} diff --git a/src/keyboards/nuphy-air60/user_keyboard.c b/src/keyboards/nuphy-air60/user_keyboard.c new file mode 100644 index 0000000..d7ba55f --- /dev/null +++ b/src/keyboards/nuphy-air60/user_keyboard.c @@ -0,0 +1,53 @@ +#include "kbdef.h" +#include "keyboard.h" +#include "debug.h" + +typedef enum { + KEYBOARD_CONN_MODE_RF = 0, + KEYBOARD_CONN_MODE_USB = 1, +} user_keyboard_conn_mode_t; + +typedef enum { + KEYBOARD_OS_MODE_WIN = 0, + KEYBOARD_OS_MODE_MAC = 1, +} user_keyboard_os_mode_t; + +typedef struct { + user_keyboard_conn_mode_t conn_mode; + user_keyboard_os_mode_t os_mode; +} user_keyboard_state_t; + +volatile __xdata user_keyboard_state_t user_keyboard_state; + +void user_keyboard_init() +{ + user_keyboard_state.conn_mode = CONN_MODE_SWITCH; + user_keyboard_state.os_mode = OS_MODE_SWITCH; +} + +void user_keyboard_update_switches() +{ + if (user_keyboard_state.conn_mode != CONN_MODE_SWITCH) { + user_keyboard_state.conn_mode = CONN_MODE_SWITCH; + switch (user_keyboard_state.conn_mode) { + case KEYBOARD_CONN_MODE_USB: + dprintf("USB_MODE\r\n"); + break; + case KEYBOARD_CONN_MODE_RF: + dprintf("RF_MODE\r\n"); + break; + } + } + + if (user_keyboard_state.os_mode != OS_MODE_SWITCH) { + user_keyboard_state.os_mode = OS_MODE_SWITCH; + switch (user_keyboard_state.os_mode) { + case KEYBOARD_OS_MODE_MAC: + dprintf("MAC_MODE\r\n"); + break; + case KEYBOARD_OS_MODE_WIN: + dprintf("WIN_MODE\r\n"); + break; + } + } +} diff --git a/src/keyboards/nuphy-air60/user_matrix.c b/src/keyboards/nuphy-air60/user_matrix.c index d0e5608..3699d7c 100644 --- a/src/keyboards/nuphy-air60/user_matrix.c +++ b/src/keyboards/nuphy-air60/user_matrix.c @@ -4,10 +4,10 @@ void user_matrix_pre_scan(uint8_t col) { // set all columns to high - P1 |= (uint8_t)(_P1_5); - P2 |= (uint8_t)(_P2_0 | _P2_1 | _P2_2 | _P2_3 | _P2_4 | _P2_5); - P3 |= (uint8_t)(_P3_0 | _P3_1 | _P3_2 | _P3_3 | _P3_4 | _P3_5); - P5 |= (uint8_t)(_P5_0 | _P5_1 | _P5_2); + P1 |= (uint8_t)(KB_C15_P1_5); + P2 |= (uint8_t)(KB_C14_P2_0 | KB_C13_P2_1 | KB_C12_P2_2 | KB_C11_P2_3 | KB_C10_P2_4 | KB_C9_P2_5); + P3 |= (uint8_t)(KB_C8_P3_0 | KB_C7_P3_1 | KB_C6_P3_2 | KB_C5_P3_3 | KB_C4_P3_4 | KB_C3_P3_5); + P5 |= (uint8_t)(KB_C0_P5_0 | KB_C1_P5_1 | KB_C2_P5_2); // set current (!) column to low switch (col) { @@ -92,8 +92,8 @@ uint8_t user_matrix_scan_col(uint8_t col) void user_matrix_post_scan() { // set all columns down to low - P1 &= (uint8_t) ~(_P1_5); - P2 &= (uint8_t) ~(_P2_0 | _P2_1 | _P2_2 | _P2_3 | _P2_4 | _P2_5); - P3 &= (uint8_t) ~(_P3_0 | _P3_1 | _P3_2 | _P3_3 | _P3_4 | _P3_5); - P5 &= (uint8_t) ~(_P5_0 | _P5_1 | _P5_2); + P1 &= (uint8_t) ~(KB_C15_P1_5); + P2 &= (uint8_t) ~(KB_C14_P2_0 | KB_C13_P2_1 | KB_C12_P2_2 | KB_C11_P2_3 | KB_C10_P2_4 | KB_C9_P2_5); + P3 &= (uint8_t) ~(KB_C8_P3_0 | KB_C7_P3_1 | KB_C6_P3_2 | KB_C5_P3_3 | KB_C4_P3_4 | KB_C3_P3_5); + P5 &= (uint8_t) ~(KB_C0_P5_0 | KB_C1_P5_1 | KB_C2_P5_2); } diff --git a/src/main.c b/src/main.c index ae4454a..0491e14 100644 --- a/src/main.c +++ b/src/main.c @@ -1,16 +1,18 @@ -#include "platform/sh68f90a/clock.h" -#include "platform/sh68f90a/ldo.h" -#include "platform/sh68f90a/watchdog.h" -#include "platform/sh68f90a/delay.h" -#include "platform/sh68f90a/isp.h" -#include "platform/sh68f90a/uart.h" -#include "platform/sh68f90a/gpio.h" -#include "platform/sh68f90a/pwm.h" -#include "platform/sh68f90a/usb.h" -#include "smk/debug.h" -#include "smk/matrix.h" -#include "smk/utils.h" -#include "smk/keyboard.h" +#include "clock.h" +#include "ldo.h" +#include "watchdog.h" +#include "delay.h" +#include "isp.h" +#include "uart.h" +#include "usb.h" +#include "debug.h" +#include "matrix.h" +#include "utils.h" +#include "keyboard.h" +#include "user_init.h" +#include "indicators.h" + +#include "pwm.h" // TODO: interrupt is defined here and need to be imported in main, centralise interupt definitions #include @@ -18,20 +20,27 @@ void init() { ldo_init(); clock_init(); - gpio_init(); +#if DEBUG == 1 uart_init(); - pwm_init(); - usb_init(); +#endif + + // platform_init(); + user_init(); + // smk_init(); + matrix_init(); keyboard_init(); + usb_init(); // usb interupt priority - 3 IPH1 |= (1 << 6); IPL1 |= (1 << 6); +#if DEBUG == 1 // uart interupt priority - 2 IPH1 |= (1 << 6); IPL1 |= (0 << 6); +#endif EA = 1; // enable interrupts } @@ -42,14 +51,9 @@ void main() dprintf("SMK v" TOSTRING(SMK_VERSION) "\r\n"); dprintf("DEVICE vId:" TOSTRING(USB_VID) " pId:" TOSTRING(USB_PID) "\n\r"); - dprintf("OS: 0x%x, CONN: 0x%x\n\r", keyboard_state.os_mode, keyboard_state.conn_mode); - - // if (keyboard_state.os_mode == KEYBOARD_OS_MODE_WIN) { - // isp_jump(); - // } // enable pwm and interrupt (driving matrix scan) - pwm_enable(); + indicators_start(); delay_ms(1000); diff --git a/src/platform/sh68f90a/gpio.c b/src/platform/sh68f90a/gpio.c deleted file mode 100644 index de3d5a9..0000000 --- a/src/platform/sh68f90a/gpio.c +++ /dev/null @@ -1,118 +0,0 @@ -#include "gpio.h" -#include "sh68f90a.h" -#include - -/* -# Rows -P7_1 - R0 -P7_2 - R1 -P7_3 - R2 -P5_3 - R3 -P5_4 - R4 - -# Columns -P5_0 - C0 -P5_1 - C1 -P5_2 - C2 -P3_5 - C3 -P3_4 - C4 -P3_3 - C5 -P3_2 - C6 -P3_1 - C7 -P3_0 - C8 -P2_5 - C9 -P2_4 - C10 -P2_3 - C11 (UL 0) -P2_2 - C12 (UL 1) -P2_1 - C13 (UL 2) -P2_0 - C14 (UL 3) -P1_5 - C15 (UL 4) - -# LEDs -P0_4 - R0 R -P6_1 - R0 G -P0_3 - R0 B - -P6_7 - R1 R -P6_2 - R1 G -P6_6 - R1 B - -P0_2 - R2 R -P6_3 - R2 G -P5_7 - R2 B - -P4_5 - R3 R -P6_4 - R3 G -P4_6 - R3 B - -P4_4 - R4 R -P6_5 - R4 G -P4_3 - R4 B - -P1_1 - UL R -P1_2 - UL G -P1_3 - UL B -*/ - -void gpio_init() -{ - P1CR = (uint8_t)(_P1_1 | _P1_2 | _P1_3 | _P1_5); - P2CR = (uint8_t)(_P2_0 | _P2_1 | _P2_2 | _P2_3 | _P2_4 | _P2_5); - P3CR = (uint8_t)(_P3_0 | _P3_1 | _P3_2 | _P3_3 | _P3_4 | _P3_5); - P5CR = (uint8_t)(_P5_0 | _P5_1 | _P5_2 | _P5_7); - - P1PCR = (uint8_t)(_P1_1 | _P1_2 | _P1_3 | _P1_5); - P2PCR = (uint8_t)(_P2_0 | _P2_1 | _P2_2 | _P2_3 | _P2_4 | _P2_5); - P3PCR = (uint8_t)(_P3_0 | _P3_1 | _P3_2 | _P3_3 | _P3_4 | _P3_5); - P5PCR = (uint8_t)(_P5_0 | _P5_1 | _P5_2 | _P5_3 | _P5_4 | _P5_5 | _P5_6 | _P5_7); - P7PCR = (uint8_t)(_P7_1 | _P1_2 | _P1_3); - - // P1_1 - UL R - // P1_2 - UL G - // P1_3 - UL B - // P5_7 - R1 B - P1 = (uint8_t)(_P1_1 | _P1_2 | _P1_3 | _P1_5); - P2 = (uint8_t)(_P2_0 | _P2_1 | _P2_2 | _P2_3 | _P2_4 | _P2_5); - P3 = (uint8_t)(_P4_0 | _P3_1 | _P3_2 | _P3_3 | _P3_4 | _P3_5); - P5 = (uint8_t)(_P5_0 | _P5_1 | _P5_2 | _P5_7); - P7 = (uint8_t)(_P7_1); - - // P6_1 - R0 G - // P6_2 - R1 G - // P6_3 - R2 G - // P6_4 - R3 G - // P6_5 - R4 G - // P6_6 - R1 B - // P6_7 - R1 R - P6CR = (uint8_t)(_P6_1 | _P6_2 | _P6_3 | _P6_4 | _P6_5 | _P6_6 | _P6_7); - P6PCR = (uint8_t)(_P6_1 | _P6_2 | _P6_3 | _P6_4 | _P6_5 | _P6_6 | _P6_7); - P6 = (uint8_t)(_P6_1 | _P6_2 | _P6_3 | _P6_4 | _P6_5 | _P6_6 | _P6_7); - - // P4_3 - R4 B - // P4_4 - R4 R - // P4_5 - R3 R - // P4_6 - R3 B - P4CR = (uint8_t)(_P4_3 | _P4_4 | _P4_5 | _P4_6); - P4PCR = (uint8_t)(_P4_3 | _P4_4 | _P4_5 | _P4_6); - P4 = (uint8_t)(_P4_3 | _P4_4 | _P4_5 | _P4_6); - - // P0_2 - R2 R - // P0_3 - R0 B - // P0_4 - R0 R - P0CR = (uint8_t)(_P0_2 | _P0_3 | _P0_4); - P0PCR = (uint8_t)(_P0_2 | _P0_3 | _P0_4); - P0 = (uint8_t)(_P0_2 | _P0_3 | _P0_4); - - // configure driving capabilities - DRVCON = 0x05; // allow P1 to be changed - P1DRV = 0x00; // 25mA - - DRVCON = 0x45; // allow P2 to be changed - P2DRV = 0x00; // 25mA - - DRVCON = 0x85; // allow P3 to be changed - P3DRV = 0x00; // 25mA - - DRVCON = 0xc5; // allow P5 to be changed - P5DRV = 0x00; // 25mA -} diff --git a/src/platform/sh68f90a/gpio.h b/src/platform/sh68f90a/gpio.h deleted file mode 100644 index be71885..0000000 --- a/src/platform/sh68f90a/gpio.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef GPIO_H -#define GPIO_H - -void gpio_init(); - -#endif diff --git a/src/platform/sh68f90a/keyboard.c b/src/platform/sh68f90a/keyboard.c deleted file mode 100644 index 3819a98..0000000 --- a/src/platform/sh68f90a/keyboard.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "sh68f90a.h" -#include "keyboard.h" -#include "debug.h" - -__xdata keyboard_state_t keyboard_state; - -void keyboard_init() -{ - keyboard_state.led_state = 0x00; - keyboard_state.conn_mode = P5_5; - keyboard_state.os_mode = P5_6; -} - -void keyboard_update_switches() -{ - if (keyboard_state.conn_mode != P5_5) { - keyboard_state.conn_mode = P5_5; - switch (keyboard_state.conn_mode) { - case KEYBOARD_CONN_MODE_USB: - dprintf("USB_MODE\r\n"); - break; - case KEYBOARD_CONN_MODE_RF: - dprintf("RF_MODE\r\n"); - break; - } - } - - if (keyboard_state.os_mode != P5_6) { - keyboard_state.os_mode = P5_6; - switch (keyboard_state.os_mode) { - case KEYBOARD_OS_MODE_MAC: - dprintf("MAC_MODE\r\n"); - break; - case KEYBOARD_OS_MODE_WIN: - dprintf("WIN_MODE\r\n"); - break; - } - } -} diff --git a/src/platform/sh68f90a/pwm.c b/src/platform/sh68f90a/pwm.c index 8938fba..6e2558d 100644 --- a/src/platform/sh68f90a/pwm.c +++ b/src/platform/sh68f90a/pwm.c @@ -3,229 +3,6 @@ #include #include "matrix.h" -/* -# Columns -P5_0 - PWM40 - C0 -P5_1 - PWM41 - C1 -P5_2 - PWM42 - C2 -P3_5 - PWM05 - C3 -P3_4 - PWM04 - C4 -P3_3 - PWM03 - C5 -P3_2 - PWM02 - C6 -P3_1 - PWM01 - C7 -P3_0 - PWM00 - C8 -P2_5 - PWM15 - C9 -P2_4 - PWM14 - C10 -P2_3 - PWM13 - C11 -P2_2 - PMM12 - C12 -P2_1 - PWM11 - C13 -P2_0 - PWM10 - C14 -P1_5 - PWM25 - C15 -*/ - -#define PWM_CLK_DIV 0b010 // PWM_CLK = SYS_CLK / 4 -#define PWM_SS_BIT (1 << 3) -#define PWM_MOD_BIT (1 << 4) -#define PWM_INT_ENABLE_BIT (1 << 6) -#define PWM_MODE_ENABLE_BIT (1 << 7) - -#define PWM_PERD 0x0400 // 1024 / PWM_CLK ~= 43 us - -#define PWM_DUTY1 PWM_PERD -#define PWM_DUTY2 0 - -#define PWM_PERDH_INIT ((uint8_t)(PWM_PERD >> 8)) -#define PWM_PERDL_INIT ((uint8_t)(PWM_PERD)) - -#define PWM_DUTY1H_INIT ((uint8_t)(PWM_DUTY1 >> 8)) -#define PWM_DUTY1L_INIT ((uint8_t)(PWM_DUTY1)) -#define PWM_DUTY2H_INIT ((uint8_t)(PWM_DUTY2 >> 8)) -#define PWM_DUTY2L_INIT ((uint8_t)(PWM_DUTY2)) - -void pwm_init() -{ - PWM0PERDH = PWM_PERDH_INIT; - PWM0PERDL = PWM_PERDL_INIT; - - PWM1PERDH = PWM_PERDH_INIT; - PWM1PERDL = PWM_PERDL_INIT; - - PWM2PERDH = PWM_PERDH_INIT; - PWM2PERDL = PWM_PERDL_INIT; - - PWM4PERDH = PWM_PERDH_INIT; - PWM4PERDL = PWM_PERDL_INIT; - - PWM00DUTY1H = PWM_DUTY1H_INIT; - PWM00DUTY1L = PWM_DUTY1L_INIT; - PWM00DUTY2H = PWM_DUTY2H_INIT; - PWM00DUTY2L = PWM_DUTY2L_INIT; - - PWM01DUTY1H = PWM_DUTY1H_INIT; - PWM01DUTY1L = PWM_DUTY1L_INIT; - PWM01DUTY2H = PWM_DUTY2H_INIT; - PWM01DUTY2L = PWM_DUTY2L_INIT; - - PWM02DUTY1H = PWM_DUTY1H_INIT; - PWM02DUTY1L = PWM_DUTY1L_INIT; - PWM02DUTY2H = PWM_DUTY2H_INIT; - PWM02DUTY2L = PWM_DUTY2L_INIT; - - PWM03DUTY1H = PWM_DUTY1H_INIT; - PWM03DUTY1L = PWM_DUTY1L_INIT; - PWM03DUTY2H = PWM_DUTY2H_INIT; - PWM03DUTY2L = PWM_DUTY2L_INIT; - - PWM04DUTY1H = PWM_DUTY1H_INIT; - PWM04DUTY1L = PWM_DUTY1L_INIT; - PWM04DUTY2H = PWM_DUTY2H_INIT; - PWM04DUTY2L = PWM_DUTY2L_INIT; - - PWM05DUTY1H = PWM_DUTY1H_INIT; - PWM05DUTY1L = PWM_DUTY1L_INIT; - PWM05DUTY2H = PWM_DUTY2H_INIT; - PWM05DUTY2L = PWM_DUTY2L_INIT; - - PWM10DUTY1H = PWM_DUTY1H_INIT; - PWM10DUTY1L = PWM_DUTY1L_INIT; - PWM10DUTY2H = PWM_DUTY2H_INIT; - PWM10DUTY2L = PWM_DUTY2L_INIT; - - PWM11DUTY1H = PWM_DUTY1H_INIT; - PWM11DUTY1L = PWM_DUTY1L_INIT; - PWM11DUTY2H = PWM_DUTY2H_INIT; - PWM11DUTY2L = PWM_DUTY2L_INIT; - - PWM12DUTY1H = PWM_DUTY1H_INIT; - PWM12DUTY1L = PWM_DUTY1L_INIT; - PWM12DUTY2H = PWM_DUTY2H_INIT; - PWM12DUTY2L = PWM_DUTY2L_INIT; - - PWM13DUTY1H = PWM_DUTY1H_INIT; - PWM13DUTY1L = PWM_DUTY1L_INIT; - PWM13DUTY2H = PWM_DUTY2H_INIT; - PWM13DUTY2L = PWM_DUTY2L_INIT; - - PWM14DUTY1H = PWM_DUTY1H_INIT; - PWM14DUTY1L = PWM_DUTY1L_INIT; - PWM14DUTY2H = PWM_DUTY2H_INIT; - PWM14DUTY2L = PWM_DUTY2L_INIT; - - PWM15DUTY1H = PWM_DUTY1H_INIT; - PWM15DUTY1L = PWM_DUTY1L_INIT; - PWM15DUTY2H = PWM_DUTY2H_INIT; - PWM15DUTY2L = PWM_DUTY2L_INIT; - - PWM25DUTY1H = PWM_DUTY1H_INIT; - PWM25DUTY1L = PWM_DUTY1L_INIT; - PWM25DUTY2H = PWM_DUTY2H_INIT; - PWM25DUTY2L = PWM_DUTY2L_INIT; - - PWM40DUTY1H = PWM_DUTY1H_INIT; - PWM40DUTY1L = PWM_DUTY1L_INIT; - PWM40DUTY2H = PWM_DUTY2H_INIT; - PWM40DUTY2L = PWM_DUTY2L_INIT; - - PWM41DUTY1H = PWM_DUTY1H_INIT; - PWM41DUTY1L = PWM_DUTY1L_INIT; - PWM41DUTY2H = PWM_DUTY2H_INIT; - PWM41DUTY2L = PWM_DUTY2L_INIT; - - PWM42DUTY1H = PWM_DUTY1H_INIT; - PWM42DUTY1L = PWM_DUTY1L_INIT; - PWM42DUTY2H = PWM_DUTY2H_INIT; - PWM42DUTY2L = PWM_DUTY2L_INIT; - - IEN1 |= (1 << 1); // EPWM0 -} - -void pwm_enable() -{ - PWM00CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_INT_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); - PWM01CON = PWM_SS_BIT; - PWM02CON = PWM_SS_BIT; - PWM03CON = PWM_SS_BIT; - PWM04CON = PWM_SS_BIT; - PWM05CON = PWM_SS_BIT; - - PWM10CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); - PWM11CON = PWM_SS_BIT; - PWM12CON = PWM_SS_BIT; - PWM13CON = PWM_SS_BIT; - PWM14CON = PWM_SS_BIT; - PWM15CON = PWM_SS_BIT; - - PWM20CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); - PWM25CON = PWM_SS_BIT; - - PWM40CON = (uint8_t)(PWM_MODE_ENABLE_BIT | PWM_SS_BIT | PWM_CLK_DIV); - - PWM41CON = PWM_SS_BIT; - PWM42CON = PWM_SS_BIT; -} - -void pwm_disable() -{ - PWM00CON = (uint8_t)(PWM_CLK_DIV); - PWM01CON = 0; - PWM02CON = 0; - PWM03CON = 0; - PWM04CON = 0; - PWM05CON = 0; - - PWM10CON = (uint8_t)(PWM_CLK_DIV); - PWM11CON = 0; - PWM12CON = 0; - PWM13CON = 0; - PWM14CON = 0; - PWM15CON = 0; - - PWM20CON = (uint8_t)(PWM_CLK_DIV); - PWM25CON = 0; - - PWM40CON = (uint8_t)(PWM_CLK_DIV); - PWM41CON = 0; - PWM42CON = 0; -} - -void pwm_set_all_columns(uint16_t intensity) -{ - uint16_t adjusted = 0x0400 - intensity; - - PWM00DUTY2H = adjusted >> 8; - PWM00DUTY2L = adjusted; - PWM01DUTY2H = adjusted >> 8; - PWM01DUTY2L = adjusted; - PWM02DUTY2H = adjusted >> 8; - PWM02DUTY2L = adjusted; - PWM03DUTY2H = adjusted >> 8; - PWM03DUTY2L = adjusted; - PWM04DUTY2H = adjusted >> 8; - PWM04DUTY2L = adjusted; - PWM05DUTY2H = adjusted >> 8; - PWM05DUTY2L = adjusted; - PWM10DUTY2H = adjusted >> 8; - PWM10DUTY2L = adjusted; - PWM11DUTY2H = adjusted >> 8; - PWM11DUTY2L = adjusted; - PWM12DUTY2H = adjusted >> 8; - PWM12DUTY2L = adjusted; - PWM13DUTY2H = adjusted >> 8; - PWM13DUTY2L = adjusted; - PWM14DUTY2H = adjusted >> 8; - PWM14DUTY2L = adjusted; - PWM15DUTY2H = adjusted >> 8; - PWM15DUTY2L = adjusted; - PWM25DUTY2H = adjusted >> 8; - PWM25DUTY2L = adjusted; - PWM40DUTY2H = adjusted >> 8; - PWM40DUTY2L = adjusted; - PWM41DUTY2H = adjusted >> 8; - PWM41DUTY2L = adjusted; - PWM42DUTY2H = adjusted >> 8; - PWM42DUTY2L = adjusted; -} - void pwm_interrupt_handler() __interrupt(_INT_PWM0) { matrix_scan_step(); diff --git a/src/platform/sh68f90a/pwm.h b/src/platform/sh68f90a/pwm.h index bcf7445..2f228e5 100644 --- a/src/platform/sh68f90a/pwm.h +++ b/src/platform/sh68f90a/pwm.h @@ -4,10 +4,23 @@ #include "sh68f90a.h" #include -void pwm_init(); -void pwm_enable(); -void pwm_disable(); -void pwm_set_all_columns(uint16_t intensity); +#define PWM_DUTY_REG(pwm, duty, bit) pwm##DUTY##duty##bit +#define SET_PWM_DUTY_1(pwm, value) \ + do { \ + PWM_DUTY_REG(pwm, 1, H) = (uint8_t)(value >> 8); \ + PWM_DUTY_REG(pwm, 1, L) = (uint8_t)(value); \ + } while (0) +#define SET_PWM_DUTY_2(pwm, value) \ + do { \ + PWM_DUTY_REG(pwm, 2, H) = (uint8_t)(value >> 8); \ + PWM_DUTY_REG(pwm, 2, L) = (uint8_t)(value); \ + } while (0) +#define SET_PWM_DUTY(pwm, duty1, duty2) \ + do { \ + SET_PWM_DUTY_1(pwm, duty1); \ + SET_PWM_DUTY_2(pwm, duty2); \ + } while (0) + void pwm_interrupt_handler() __interrupt(_INT_PWM0); #endif diff --git a/src/smk/keyboard.c b/src/smk/keyboard.c new file mode 100644 index 0000000..c3aa290 --- /dev/null +++ b/src/smk/keyboard.c @@ -0,0 +1,9 @@ +#include "keyboard.h" +#include "debug.h" + +volatile __xdata keyboard_state_t keyboard_state; + +void keyboard_init() +{ + keyboard_state.led_state = 0x00; +} diff --git a/src/smk/keyboard.h b/src/smk/keyboard.h index de3f099..2abec0a 100644 --- a/src/smk/keyboard.h +++ b/src/smk/keyboard.h @@ -3,25 +3,12 @@ #include -typedef enum { - KEYBOARD_CONN_MODE_RF = 0, - KEYBOARD_CONN_MODE_USB = 1, -} keyboard_conn_mode_t; - -typedef enum { - KEYBOARD_OS_MODE_WIN = 0, - KEYBOARD_OS_MODE_MAC = 1, -} keyboard_os_mode_t; - typedef struct { - keyboard_conn_mode_t conn_mode; - keyboard_os_mode_t os_mode; - uint8_t led_state; + uint8_t led_state; } keyboard_state_t; -extern __xdata keyboard_state_t keyboard_state; +extern volatile __xdata keyboard_state_t keyboard_state; void keyboard_init(); -void keyboard_update_switches(); #endif diff --git a/src/smk/layout.h b/src/smk/layout.h new file mode 100644 index 0000000..6d31a52 --- /dev/null +++ b/src/smk/layout.h @@ -0,0 +1,9 @@ +#ifndef LAYOUT_H +#define LAYOUT_H + +#include "kbdef.h" +#include + +extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; + +#endif diff --git a/src/smk/matrix.c b/src/smk/matrix.c index 37534de..b58184d 100644 --- a/src/smk/matrix.c +++ b/src/smk/matrix.c @@ -2,8 +2,10 @@ #include "report.h" #include "debug.h" #include "layout.h" +#include "user_layout.h" #include "indicators.h" #include "user_matrix.h" +#include "kbdef.h" #include #include @@ -31,17 +33,17 @@ void matrix_init() } } -inline matrix_col_t matrix_get_col(uint8_t col) +matrix_col_t matrix_get_col(uint8_t col) { return matrix[col]; } -inline matrix_col_t matrix_can_read() +matrix_col_t matrix_can_read() { return matrix_updated; } -inline void process_key_state(uint8_t row, uint8_t col, bool pressed) +void process_key_state(uint8_t row, uint8_t col, bool pressed) { uint16_t qcode = keymaps[0][row][col]; @@ -98,7 +100,7 @@ inline void process_key_state(uint8_t row, uint8_t col, bool pressed) dprintf("UNRECOGNIZED KEY: 0x%04x\r\n", qcode); } -inline uint8_t matrix_task() +uint8_t matrix_task() { if (!matrix_can_read()) { return false; @@ -141,7 +143,7 @@ inline uint8_t matrix_task() return matrix_changed; } -inline void matrix_scan_step() +void matrix_scan_step() { indicators_pre_update(); @@ -155,7 +157,7 @@ inline void matrix_scan_step() matrix[current_step] = ~column_state; - keyboard_update_switches(); + // keyboard_update_switches(); } // rgb led matrix animation diff --git a/src/smk/matrix.h b/src/smk/matrix.h index 593d574..868e885 100644 --- a/src/smk/matrix.h +++ b/src/smk/matrix.h @@ -3,11 +3,8 @@ #include -#define MATRIX_COLS 16 -#define MATRIX_ROWS 5 - -inline void matrix_init(); -inline uint8_t matrix_task(); -inline void matrix_scan_step(); +void matrix_init(); +uint8_t matrix_task(); +void matrix_scan_step(); #endif diff --git a/src/smk/report.c b/src/smk/report.c index 81a559b..18d64be 100644 --- a/src/smk/report.c +++ b/src/smk/report.c @@ -1,6 +1,7 @@ #include "report.h" #include "host.h" #include "layout.h" +#include "keycodes.h" #include static uint8_t real_mods = 0; diff --git a/src/user/indicators.h b/src/user/indicators.h index c9fec7f..475a46d 100644 --- a/src/user/indicators.h +++ b/src/user/indicators.h @@ -5,6 +5,7 @@ #include #include +void indicators_start(); void indicators_pre_update(); bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step); void indicators_post_update(); diff --git a/src/user/indicators_start.c b/src/user/indicators_start.c new file mode 100644 index 0000000..6238ca8 --- /dev/null +++ b/src/user/indicators_start.c @@ -0,0 +1 @@ +void indicators_start() {} diff --git a/src/user/layout_process_record.c b/src/user/layout_process_record.c index 1820940..499b825 100644 --- a/src/user/layout_process_record.c +++ b/src/user/layout_process_record.c @@ -1,4 +1,4 @@ -#include "layout.h" +#include "user_layout.h" bool layout_process_record(uint16_t keycode, bool key_pressed) { diff --git a/src/user/user_init.c b/src/user/user_init.c new file mode 100644 index 0000000..05431ec --- /dev/null +++ b/src/user/user_init.c @@ -0,0 +1 @@ +void user_init() {} diff --git a/src/user/user_init.h b/src/user/user_init.h new file mode 100644 index 0000000..0a5f07e --- /dev/null +++ b/src/user/user_init.h @@ -0,0 +1,8 @@ +#ifndef USER_INIT_H +#define USER_INIT_H + +#include + +void user_init(); + +#endif diff --git a/src/user/layout.h b/src/user/user_layout.h similarity index 65% rename from src/user/layout.h rename to src/user/user_layout.h index 826f3d2..0b3f477 100644 --- a/src/user/layout.h +++ b/src/user/user_layout.h @@ -1,12 +1,10 @@ -#ifndef LAYOUT_H -#define LAYOUT_H +#ifndef USER_LAYOUT_H +#define USER_LAYOUT_H -#include "matrix.h" #include "keycodes.h" +#include #include -extern const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; - /* returns a boolean value to instruct whether further key process should continue or end here */