From b30a63c6ff8085c00fb463ae5cee1db8fe561d12 Mon Sep 17 00:00:00 2001 From: fpazos <30479687+fpazos@users.noreply.github.com> Date: Fri, 29 Jun 2018 14:55:13 +0200 Subject: [PATCH] Started dual color leds PWM functions and configs I started to create the PWM functions and configs based on internet examples, it doesn't compile yet --- .../stm32/boards/GENERIC_STM32_F103/board.h | 2 +- .../handwired/stm32/keymaps/spanish/keymap.c | 36 ++++++++- keyboards/handwired/stm32/stm70/config.h | 6 +- keyboards/handwired/stm32/stm70/halconf.h | 2 +- keyboards/handwired/stm32/stm70/led.c | 75 +++++++++++++------ keyboards/handwired/stm32/stm70/matrix.c | 3 + keyboards/handwired/stm32/stm70/mcuconf.h | 2 +- 7 files changed, 97 insertions(+), 29 deletions(-) diff --git a/keyboards/handwired/stm32/boards/GENERIC_STM32_F103/board.h b/keyboards/handwired/stm32/boards/GENERIC_STM32_F103/board.h index 848a7036707..75bb848fd07 100644 --- a/keyboards/handwired/stm32/boards/GENERIC_STM32_F103/board.h +++ b/keyboards/handwired/stm32/boards/GENERIC_STM32_F103/board.h @@ -50,7 +50,7 @@ /* Backlighting */ -#define GPIOC_BACKLIGHT_PIN 12 +/*#define GPIOC_BACKLIGHT_PIN 15*/ /* In case your board has a "USB enable" hardware controlled by a pin, define it here. (It could be just diff --git a/keyboards/handwired/stm32/keymaps/spanish/keymap.c b/keyboards/handwired/stm32/keymaps/spanish/keymap.c index a6151dfbe5c..6b96c55022e 100644 --- a/keyboards/handwired/stm32/keymaps/spanish/keymap.c +++ b/keyboards/handwired/stm32/keymaps/spanish/keymap.c @@ -22,15 +22,15 @@ along with this program. If not, see . // Highly Modified by Xydane const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { - KEYMAP_SETENTA( + [_NORMAL] = KEYMAP_SETENTA( KC_ESC, 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_PSCREEN,KC_HOME, KC_END, \ KC_GRAVE, 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_DELETE, \ 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_PGUP, \ 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_NUHS, KC_ENT,KC_PGDOWN, \ - KC_LSFT, KC_NUBS,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, KC_RSFT,KC_UP, F(1), \ + LSPO_KEY, KC_NUBS,KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM,KC_DOT, KC_SLSH, RSPC_KEY,KC_UP, F(1), \ KC_LCTL, KC_LGUI,KC_LALT, KC_SPC, KC_RALT,F(0), KC_RCTL, KC_LEFT, KC_DOWN, KC_RIGHT ), - KEYMAP_SETENTA( + [_FNUNO] = KEYMAP_SETENTA( KC_TRNS, KC_MPRV, KC_MSTP, KC_MPLY, KC_MNXT, KC_TRNS, KC_TRNS,KC_TRNS,KC_TRNS,KC_MUTE,KC_VOLD, KC_VOLU, KC_TRNS, KC_TRNS,KC_TRNS,KC_TRNS, \ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_P7, KC_P8, KC_P9, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_TRNS, \ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_P4, KC_P5, KC_P6, KC_PPLS, KC_TRNS, KC_TRNS, KC_TRNS, \ @@ -38,7 +38,7 @@ const uint16_t keymaps[][MATRIX_ROWS][MATRIX_COLS] = { KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_TRNS,KC_P0, KC_PDOT,KC_PENT, KC_PSLS, KC_TRNS,KC_TRNS,KC_TRNS, \ KC_TRNS, KC_TRNS, KC_TRNS, F(2), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_TRNS,KC_TRNS ), - KEYMAP_SETENTA( + [_FNDOS] = KEYMAP_SETENTA( KC_TRNS, KC_MPRV, KC_MSTP, KC_MPLY, KC_MNXT, KC_TRNS, KC_TRNS,KC_TRNS,KC_TRNS,KC_MUTE,KC_VOLD, KC_VOLU, KC_TRNS, KC_TRNS,KC_TRNS,KC_TRNS, \ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_P7, KC_P8, KC_P9, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_TRNS, \ KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,KC_P4, KC_P5, KC_P6, KC_PPLS, KC_TRNS, KC_TRNS, KC_TRNS, \ @@ -51,6 +51,7 @@ const uint16_t PROGMEM fn_actions[] = { [0] = ACTION_LAYER_MOMENTARY(1), // to Fn overlay [1] = ACTION_LAYER_TOGGLE(2), // to Fn overlay [2] = ACTION_FUNCTION(2), + [3] = ACTION_FUNCTION(3), }; void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { @@ -60,5 +61,32 @@ void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) { palTogglePad(GPIOA, 1); } break; + + // Continuar para incluir funciones propias + /*case 3: + if (record->event.pressed) { + function_led(algo); + } + break;*/ + } } + +/* Layer based ilumination, set min value to 0xFFF */ +/*uint32_t layer_state_set_user(uint32_t state) { + switch (biton32(state)) { + case _FNUNO: + custom_function1(min1, min2;) + rgblight_setrgb (0xFF, 0x00, 0x00); + break; + case _FNDOS: + custom_function2(min1, min2;) + rgblight_setrgb (0x00, 0xFF, 0x00); + break; + default: // for any other layers, or the default layer + custom_function3(min1, min2;) + rgblight_setrgb (0x00, 0xFF, 0xFF); + break; + } + return state; +}*/ \ No newline at end of file diff --git a/keyboards/handwired/stm32/stm70/config.h b/keyboards/handwired/stm32/stm70/config.h index c3da26afb7e..99400cc6024 100644 --- a/keyboards/handwired/stm32/stm70/config.h +++ b/keyboards/handwired/stm32/stm70/config.h @@ -8,7 +8,8 @@ #define PRODUCT_ID 0x6464 #define DEVICE_VER 0x0001 /* in python2: list(u"whatever".encode('utf-16-le')) */ -/* at most 32 characters or the ugly hack in usb_main.c borks */ +/* at most 32 characters or the ugly hack in usb_main.c works */ + // Modified by Xydane #define MANUFACTURER "QMK" #define USBSTR_MANUFACTURER 'T', '\x00', 'M', '\x00', 'K', '\x00', ' ', '\x00', '\xc6', '\x00' @@ -22,5 +23,8 @@ #define MATRIX_COLS 15 #define DIODE_DIRECTION COL2ROW +#define LSPO_KEY KC_8 +#define RSPC_KEY KC_9 + #endif /* STM70_CONFIG_H_ */ diff --git a/keyboards/handwired/stm32/stm70/halconf.h b/keyboards/handwired/stm32/stm70/halconf.h index 1733f581dcc..5be284cd35f 100644 --- a/keyboards/handwired/stm32/stm70/halconf.h +++ b/keyboards/handwired/stm32/stm70/halconf.h @@ -111,7 +111,7 @@ * @brief Enables the PWM subsystem. */ #if !defined(HAL_USE_PWM) || defined(__DOXYGEN__) -#define HAL_USE_PWM FALSE +#define HAL_USE_PWM TRUE #endif /** diff --git a/keyboards/handwired/stm32/stm70/led.c b/keyboards/handwired/stm32/stm70/led.c index b515a77b95a..f68676cc106 100644 --- a/keyboards/handwired/stm32/stm70/led.c +++ b/keyboards/handwired/stm32/stm70/led.c @@ -35,27 +35,60 @@ void led_set(uint8_t usb_led) } -/* New leds configuration, decided to put here */ -/*uint32_t layer_state_set_user(uint32_t state) { - switch (biton32(state)) { - case _RAISE: - rgblight_setrgb (0x00, 0x00, 0xFF); - break; - case _LOWER: - rgblight_setrgb (0xFF, 0x00, 0x00); - break; - case _PLOVER: - rgblight_setrgb (0x00, 0xFF, 0x00); - break; - case _ADJUST: - rgblight_setrgb (0x7A, 0x00, 0xFF); - break; - default: // for any other layers, or the default layer - rgblight_setrgb (0x00, 0xFF, 0xFF); - break; - } - return state; -}*/ + + +/* New awesome dual color leds functions, animations and more */ +/* Based on pwm_callback by fcayci: https://github.com/fcayci/STM32F4-ChibiOS/blob/master/pwm_callback/main.c */ + +static void pwmcb(PWMDriver *pwmp); + +static PWMConfig pwmcfg = { + 1000, // Clock frecuency (seconds) = 1/value + 100, // PWM period (ticks = clockfrecuency * pwmperiod) + pwmcb, // Callback, disable with NULL + { + {PWM_OUTPUT_ACTIVE_HIGH, NULL}, /* Enable Channel 0 */ + {PWM_OUTPUT_ACTIVE_HIGH, NULL}, /* Enable Channel 1 */ + //{PWM_OUTPUT_ACTIVE_HIGH, NULL}, /* Enable Channel 2 */ + //{PWM_OUTPUT_ACTIVE_HIGH, NULL} /* Enable Channel 3 */ + }, + 0, /* HW dependent part */ + 0 +}; + + +/* + * PWM callback. + * Each time calculate the next duty cycle. + */ +static void pwmcb(PWMDriver *pwmp) { + (void)pwmp; + + static uint16_t dir = 0, width = 0; + + if (dir == 0) {width = (width + 100);} + else {width = (width - 100);} + + if (width >= 100) {dir = 1;} + else if (width == 0) {dir = 0;} + + pwmEnableChannel(&PWMC15, 0, width); + pwmEnableChannel(&PWMC15, 1, 100-width); + //pwmEnableChannel(&PWMD4, 2, width); + //pwmEnableChannel(&PWMD4, 3, 100-width); +} + +static void iniciarluces(void) { + + palSetPadMode(GPIOC, 15, PAL_MODE_ALTERNATE(2)); /* Green */ + palSetPadMode(GPIOC, 14, PAL_MODE_ALTERNATE(2)); /* Red */ + + pwmStart(&PWMC15, &pwmCFG); + +} + + + // inline void gh60_caps_led_off(void) { DDRB &= ~(1<<2); PORTB &= ~(1<<2); } diff --git a/keyboards/handwired/stm32/stm70/matrix.c b/keyboards/handwired/stm32/stm70/matrix.c index 3ccaab0bc13..bba7995e460 100644 --- a/keyboards/handwired/stm32/stm70/matrix.c +++ b/keyboards/handwired/stm32/stm70/matrix.c @@ -78,6 +78,9 @@ void matrix_init(void) LED_ON(); wait_ms(500); LED_OFF(); + + // Start of PWM dual color leds + iniciarluces(); } uint8_t matrix_scan(void) diff --git a/keyboards/handwired/stm32/stm70/mcuconf.h b/keyboards/handwired/stm32/stm70/mcuconf.h index 276829216ee..9cced82447f 100644 --- a/keyboards/handwired/stm32/stm70/mcuconf.h +++ b/keyboards/handwired/stm32/stm70/mcuconf.h @@ -132,7 +132,7 @@ * PWM driver system settings. */ #define STM32_PWM_USE_ADVANCED FALSE -#define STM32_PWM_USE_TIM1 FALSE +#define STM32_PWM_USE_TIM1 TRUE #define STM32_PWM_USE_TIM2 FALSE #define STM32_PWM_USE_TIM3 FALSE #define STM32_PWM_USE_TIM4 FALSE