Skip to content

Commit

Permalink
working setup, user init, pin abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossless committed May 26, 2024
1 parent 9c5491c commit fb2de67
Show file tree
Hide file tree
Showing 27 changed files with 599 additions and 619 deletions.
8 changes: 6 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,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',
Expand All @@ -56,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
Expand All @@ -80,14 +81,17 @@ 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',
]

Expand Down
60 changes: 3 additions & 57 deletions src/keyboards/example/kbdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,19 @@

#include "sh68f90a.h"

#define MATRIX_ROWS 5
#define MATRIX_COLS 16
#define MATRIX_ROWS 1
#define MATRIX_COLS 1

// 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

// 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

#endif
60 changes: 8 additions & 52 deletions src/keyboards/example/layouts/default/layout.c
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#include "kbdef.h"
#include "layout.h"
#include "user_layout.h"
#include "report.h"
#include <stdint.h>

// 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 \
) { \
{ 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 } \
}

// Each layer gets a name for readability, which is then used in the keymap matrix below.
Expand All @@ -26,50 +19,13 @@
#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|
* `---'
*/
[_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
)
};
19 changes: 19 additions & 0 deletions src/keyboards/eyooso-z11/kbdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@
#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
Expand All @@ -69,4 +85,7 @@
// KC_CAPS LED Pin
#define LED_CAPS P0_3

// KC_CAPS LED Pin Bit
#define LED_CAPS_P0_3 _P0_3

#endif
95 changes: 85 additions & 10 deletions src/keyboards/eyooso-z11/layouts/default/indicators.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
#include "indicators.h"
#include "sh68f90a.h"
#include "pwm.h"
#include "kbdef.h"
#include "pwm.h"
#include <stdlib.h>

// 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);

pwm_disable();
indicators_pwm_disable();
}

bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step)
Expand All @@ -28,15 +44,10 @@ bool indicators_update_step(keyboard_state_t *keyboard, uint8_t current_step)

intensity = 1024 - (uint16_t)abs((int16_t)((current_cycle + 1024) % 2048) - 1024);

// caps_lock
if (!(keyboard->led_state & (1 << 1))) {
LED_CAPS = 1;
} else {
LED_CAPS = 0;
}
LED_CAPS = !(keyboard->led_state & (1 << 1));

// set pwm duty cycles to expected colors
pwm_set_all_columns(intensity);
indicators_pwm_set_all_columns(intensity);

return false;
}
Expand All @@ -46,5 +57,69 @@ 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);
}

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;
}
Loading

0 comments on commit fb2de67

Please sign in to comment.