From b3dca4bb36d0c08e8145f6f25649aaf61b513fdd Mon Sep 17 00:00:00 2001 From: Jay Greco Date: Fri, 27 Jan 2023 00:03:57 -0800 Subject: Add RP2040 SCRAMBLE v2 (#19489) --- keyboards/nullbitsco/scramble/config.h | 34 ------------ keyboards/nullbitsco/scramble/rules.mk | 21 ++------ keyboards/nullbitsco/scramble/scramble.c | 22 -------- keyboards/nullbitsco/scramble/scramble.h | 17 +++--- keyboards/nullbitsco/scramble/v1/config.h | 36 +++++++++++++ keyboards/nullbitsco/scramble/v1/rules.mk | 21 ++++++++ keyboards/nullbitsco/scramble/v1/v1.c | 25 +++++++++ keyboards/nullbitsco/scramble/v1/v1.h | 18 +++++++ keyboards/nullbitsco/scramble/v2/config.h | 42 +++++++++++++++ keyboards/nullbitsco/scramble/v2/halconf.h | 9 ++++ keyboards/nullbitsco/scramble/v2/mcuconf.h | 14 +++++ keyboards/nullbitsco/scramble/v2/rules.mk | 21 ++++++++ keyboards/nullbitsco/scramble/v2/v2.c | 84 ++++++++++++++++++++++++++++++ keyboards/nullbitsco/scramble/v2/v2.h | 43 +++++++++++++++ 14 files changed, 322 insertions(+), 85 deletions(-) delete mode 100644 keyboards/nullbitsco/scramble/config.h create mode 100644 keyboards/nullbitsco/scramble/v1/config.h create mode 100644 keyboards/nullbitsco/scramble/v1/rules.mk create mode 100644 keyboards/nullbitsco/scramble/v1/v1.c create mode 100644 keyboards/nullbitsco/scramble/v1/v1.h create mode 100644 keyboards/nullbitsco/scramble/v2/config.h create mode 100644 keyboards/nullbitsco/scramble/v2/halconf.h create mode 100644 keyboards/nullbitsco/scramble/v2/mcuconf.h create mode 100644 keyboards/nullbitsco/scramble/v2/rules.mk create mode 100644 keyboards/nullbitsco/scramble/v2/v2.c create mode 100644 keyboards/nullbitsco/scramble/v2/v2.h diff --git a/keyboards/nullbitsco/scramble/config.h b/keyboards/nullbitsco/scramble/config.h deleted file mode 100644 index 4333d94d37..0000000000 --- a/keyboards/nullbitsco/scramble/config.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2021 Jay Greco - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#pragma once - -#include "config_common.h" - -/* key matrix size */ -#define MATRIX_ROWS 2 -#define MATRIX_COLS 3 - -#define DIRECT_PINS {{D4,D5,B1}, {C3,C2,C1}} - -/* Set 0 if debouncing isn't needed */ -#define DEBOUNCE 10 - -/* Optional encoder pins */ -#define ENCODERS_PAD_A { D6 } -#define ENCODERS_PAD_B { D7 } -#define TAP_CODE_DELAY 10 diff --git a/keyboards/nullbitsco/scramble/rules.mk b/keyboards/nullbitsco/scramble/rules.mk index e6d789691b..6f83796e9f 100644 --- a/keyboards/nullbitsco/scramble/rules.mk +++ b/keyboards/nullbitsco/scramble/rules.mk @@ -1,19 +1,4 @@ -# MCU name -MCU = atmega328p +# NOTE: This file is shared and only exists to set the default build +# The real build rules are set in the v1/v2 directories -# Bootloader selection -BOOTLOADER = usbasploader - -# Build Options -# change yes to no to disable -# -BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite -MOUSEKEY_ENABLE = yes # Mouse keys -EXTRAKEY_ENABLE = yes # Audio control and System control -CONSOLE_ENABLE = no # Console for debug -COMMAND_ENABLE = no # Commands for debug and configuration -NKRO_ENABLE = no # Enable N-Key Rollover -BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality -RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow -AUDIO_ENABLE = no # Audio output -ENCODER_ENABLE = yes # Use rotary encoder +DEFAULT_FOLDER = nullbitsco/scramble/v2 diff --git a/keyboards/nullbitsco/scramble/scramble.c b/keyboards/nullbitsco/scramble/scramble.c index f9f28d2c31..c8a55e0d48 100644 --- a/keyboards/nullbitsco/scramble/scramble.c +++ b/keyboards/nullbitsco/scramble/scramble.c @@ -16,25 +16,3 @@ along with this program. If not, see . */ #include QMK_KEYBOARD_H - -// place overrides here -void set_scramble_LED(uint8_t mode) { - switch(mode) { - case LED_ON: - setPinOutput(PIN_LED); - writePin(PIN_LED, GPIO_STATE_HIGH); - break; - - case LED_DIM: - setPinInput(PIN_LED); - break; - - case LED_OFF: - setPinOutput(PIN_LED); - writePin(PIN_LED, GPIO_STATE_LOW); - break; - - default: - break; - } -} diff --git a/keyboards/nullbitsco/scramble/scramble.h b/keyboards/nullbitsco/scramble/scramble.h index 101645e51d..22c112040b 100644 --- a/keyboards/nullbitsco/scramble/scramble.h +++ b/keyboards/nullbitsco/scramble/scramble.h @@ -18,18 +18,13 @@ #include "quantum.h" -// Indication LED settings -#define LED_ON 2 -#define LED_DIM 1 -#define LED_OFF 0 - -#define GPIO_STATE_LOW 0 -#define GPIO_STATE_HIGH 1 - -#define PIN_LED B2 - -void set_scramble_LED(uint8_t mode); +#if defined(KEYBOARD_nullbitsco_scramble_v1) + #include "v1.h" +#elif defined(KEYBOARD_nullbitsco_scramble_v2) + #include "v2.h" +#endif +// Layout is the same in all revisions #define LAYOUT( \ K01, K02, K03, \ K11, K12, K13 \ diff --git a/keyboards/nullbitsco/scramble/v1/config.h b/keyboards/nullbitsco/scramble/v1/config.h new file mode 100644 index 0000000000..b249b99851 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v1/config.h @@ -0,0 +1,36 @@ +/* +Copyright 2021 Jay Greco + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* NOTE: This config file is specific to AVR builds. */ + +#pragma once + +#include "config_common.h" + +/* key matrix size */ +#define MATRIX_ROWS 2 +#define MATRIX_COLS 3 + +#define DIRECT_PINS {{D4,D5,B1}, {C3,C2,C1}} + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCE 10 + +/* Optional encoder pins */ +#define ENCODERS_PAD_A { D6 } +#define ENCODERS_PAD_B { D7 } +#define TAP_CODE_DELAY 10 diff --git a/keyboards/nullbitsco/scramble/v1/rules.mk b/keyboards/nullbitsco/scramble/v1/rules.mk new file mode 100644 index 0000000000..c1cf175c64 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v1/rules.mk @@ -0,0 +1,21 @@ +# NOTE: This file is specific to AVR builds. + +# MCU name +MCU = atmega328p + +# Bootloader selection +BOOTLOADER = usbasploader + +# Build Options +# change yes to no to disable +# +BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = no # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration +NKRO_ENABLE = no # Enable N-Key Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow +AUDIO_ENABLE = no # Audio output +ENCODER_ENABLE = yes # Use rotary encoder diff --git a/keyboards/nullbitsco/scramble/v1/v1.c b/keyboards/nullbitsco/scramble/v1/v1.c new file mode 100644 index 0000000000..4b5e8e3e67 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v1/v1.c @@ -0,0 +1,25 @@ +// Copyright 2022 Jay Greco +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "v1.h" + +void set_scramble_LED(uint8_t mode) { + switch(mode) { + case LED_ON: + setPinOutput(PIN_LED); + writePin(PIN_LED, GPIO_STATE_HIGH); + break; + + case LED_DIM: + setPinInput(PIN_LED); + break; + + case LED_OFF: + setPinOutput(PIN_LED); + writePin(PIN_LED, GPIO_STATE_LOW); + break; + + default: + break; + } +} diff --git a/keyboards/nullbitsco/scramble/v1/v1.h b/keyboards/nullbitsco/scramble/v1/v1.h new file mode 100644 index 0000000000..5dc6d4a0e8 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v1/v1.h @@ -0,0 +1,18 @@ +// Copyright 2022 Jay Greco +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "scramble.h" + +// Indication LED settings +#define LED_ON 2 +#define LED_DIM 1 +#define LED_OFF 0 + +#define GPIO_STATE_LOW 0 +#define GPIO_STATE_HIGH 1 + +#define PIN_LED B2 + +void set_scramble_LED(uint8_t mode); diff --git a/keyboards/nullbitsco/scramble/v2/config.h b/keyboards/nullbitsco/scramble/v2/config.h new file mode 100644 index 0000000000..a2eb9712f9 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v2/config.h @@ -0,0 +1,42 @@ +/* +Copyright 2021 Jay Greco + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +/* NOTE: This config file is specific to RP2040 builds. */ + +#pragma once + +#include "config_common.h" + +/* key matrix size */ +#define MATRIX_ROWS 2 +#define MATRIX_COLS 3 + +#define DIRECT_PINS {{GP6,GP8,GP10}, {GP29,GP28,GP22}} + +/* Set 0 if debouncing isn't needed */ +#define DEBOUNCE 10 + +/* Optional encoder pins */ +#define ENCODERS_PAD_A { GP24 } +#define ENCODERS_PAD_B { GP25 } +#define TAP_CODE_DELAY 10 + +/* RP2040-specific defines*/ +#define RP2040_FLASH_GENERIC_03H +#define I2C1_SDA_PIN GP26 +#define I2C1_SCL_PIN GP27 +#define I2C_DRIVER I2CD2 diff --git a/keyboards/nullbitsco/scramble/v2/halconf.h b/keyboards/nullbitsco/scramble/v2/halconf.h new file mode 100644 index 0000000000..2cc40eaa91 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v2/halconf.h @@ -0,0 +1,9 @@ +// Copyright 2022 Jay Greco +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#define HAL_USE_I2C TRUE +#define HAL_USE_PWM TRUE + +#include_next diff --git a/keyboards/nullbitsco/scramble/v2/mcuconf.h b/keyboards/nullbitsco/scramble/v2/mcuconf.h new file mode 100644 index 0000000000..9646c6b702 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v2/mcuconf.h @@ -0,0 +1,14 @@ +// Copyright 2022 Jay Greco +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include_next + +#undef RP_I2C_USE_I2C1 +#define RP_I2C_USE_I2C1 TRUE + +#undef RP_PWM_USE_PWM1 +#define RP_PWM_USE_PWM1 TRUE +#undef RP_PWM_USE_PWM2 +#define RP_PWM_USE_PWM2 TRUE diff --git a/keyboards/nullbitsco/scramble/v2/rules.mk b/keyboards/nullbitsco/scramble/v2/rules.mk new file mode 100644 index 0000000000..f93963285b --- /dev/null +++ b/keyboards/nullbitsco/scramble/v2/rules.mk @@ -0,0 +1,21 @@ +# NOTE: This file is is specific to RP2040 builds. + +# MCU name +MCU = RP2040 + +# Bootloader selection +BOOTLOADER = rp2040 + +# Build Options +# change yes to no to disable +# +BOOTMAGIC_ENABLE = no # Enable Bootmagic Lite +MOUSEKEY_ENABLE = yes # Mouse keys +EXTRAKEY_ENABLE = yes # Audio control and System control +CONSOLE_ENABLE = no # Console for debug +COMMAND_ENABLE = no # Commands for debug and configuration +NKRO_ENABLE = no # Enable N-Key Rollover +BACKLIGHT_ENABLE = no # Enable keyboard backlight functionality +RGBLIGHT_ENABLE = no # Enable keyboard RGB underglow +AUDIO_ENABLE = no # Audio output +ENCODER_ENABLE = yes # Use rotary encoder diff --git a/keyboards/nullbitsco/scramble/v2/v2.c b/keyboards/nullbitsco/scramble/v2/v2.c new file mode 100644 index 0000000000..9b0a088855 --- /dev/null +++ b/keyboards/nullbitsco/scramble/v2/v2.c @@ -0,0 +1,84 @@ +// Copyright 2022 Jay Greco +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "v2.h" + +// SCRAMBLE PWM LED config +pwm_led_t scramble_rgb = { + {GP18, GP19, GP20}, + {&PWMD1, &PWMD1, &PWMD2}, + {0, 1, 0}, + PWM_OUTPUT_ACTIVE_LOW, + 0 +}; + +// Internal PWM init +// only runs once per PWM LED +void _init_pwm(pwm_led_t* led) { + if (!led->init_complete) { + for (int i=0; ipin[i]), PAL_PAD(led->pin[i]), PWM_PAL_MODE); + + static PWMConfig pwmCFG = { + .frequency = PWM_PWM_COUNTER_FREQUENCY, + .period = PWM_PWM_PERIOD, + }; + + // Channels are always configured as active low + // If active high is needed, pwm is inverted in _set_led_pwm() + pwmCFG.channels[0].mode = PWM_OUTPUT_ACTIVE_LOW; + pwmCFG.channels[1].mode = PWM_OUTPUT_ACTIVE_LOW; + pwmStart(led->driver[i], &pwmCFG); + + // Start LEDs in the OFF state + uint8_t pwm = led->mode == PWM_OUTPUT_ACTIVE_HIGH ? 100 : 0; + pwmEnableChannel(led->driver[i], led->channel[i], PWM_FRACTION_TO_WIDTH(led->driver[i], 99, pwm)); + } + + led->init_complete = 1; + } +} + +// Internal generic PWM setter +void _set_led_pwm(uint8_t pwm, pwm_led_t* led, uint8_t channel) { + if (pwm > 100) pwm = 100; + if (led->mode == PWM_OUTPUT_ACTIVE_HIGH) pwm = (100 - pwm); + + _init_pwm(led); + pwmEnableChannel(led->driver[channel], led->channel[channel], PWM_FRACTION_TO_WIDTH(led->driver[channel], 99, pwm)); +} + +// SCRAMBLE +void set_scramble_LED(uint8_t mode) { + switch(mode) { + case LED_ON: + set_scramble_LED_rgb_pwm(65, 100, 95); + break; + + case LED_DIM: + set_scramble_LED_rgb_pwm(3, 9, 3); + break; + + default: //LED_OFF + set_scramble_LED_rgb_pwm(0, 0, 0); + break; + } +} + +void set_scramble_LED_rgb_pwm(uint8_t r_pwm, uint8_t g_pwm, uint8_t b_pwm) { + _set_led_pwm(r_pwm, &scramble_rgb, RED); + _set_led_pwm(g_pwm, &scramble_rgb, GREEN); + _set_led_pwm(b_pwm, &scramble_rgb, BLUE); +} + +void set_scramble_LED_r_pwm(uint8_t pwm) { + _set_led_pwm(pwm, &scramble_rgb, RED); +} + +void set_scramble_LED_g_pwm(uint8_t pwm) { + _set_led_pwm(pwm, &scramble_rgb, GREEN); +} + +void set_scramble_LED_b_pwm(uint8_t pwm) { + _set_led_pwm(pwm, &scramble_rgb, BLUE); +} diff --git a/keyboards/nullbitsco/scramble/v2/v2.h b/keyboards/nullbitsco/scramble/v2/v2.h new file mode 100644 index 0000000000..d278c0a86a --- /dev/null +++ b/keyboards/nullbitsco/scramble/v2/v2.h @@ -0,0 +1,43 @@ +// Copyright 2022 Jay Greco +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "scramble.h" +#include + +enum led_mode { + LED_OFF = 0, + LED_DIM, + LED_ON, + NUM_LED_MODE +}; + +enum rgb_idx { + RED = 0, + GREEN, + BLUE, + NUM_RGB_IDX +}; + +typedef struct pwm_led_t { + uint32_t pin[3]; + PWMDriver* driver[3]; + uint8_t channel[3]; + uint8_t mode; + uint8_t init_complete; +} pwm_led_t; + +#define PWM_PAL_MODE (PAL_MODE_ALTERNATE_PWM | PAL_RP_PAD_DRIVE12 | PAL_RP_GPIO_OE) +#define PWM_PWM_COUNTER_FREQUENCY 1000000 +#define PWM_PWM_PERIOD PWM_PWM_COUNTER_FREQUENCY / 1000 + +// RP2040 adds HW PWM control! +// PWM values are in percent, 0-100 +void + set_scramble_LED(uint8_t mode), + set_scramble_LED_rgb_pwm(uint8_t r_pwm, uint8_t g_pwm, uint8_t b_pwm), + set_scramble_LED_r_pwm(uint8_t pwm), + set_scramble_LED_g_pwm(uint8_t pwm), + set_scramble_LED_b_pwm(uint8_t pwm); + \ No newline at end of file -- cgit v1.2.3