summaryrefslogtreecommitdiff
path: root/keyboards/nullbitsco
diff options
context:
space:
mode:
authorJay Greco <jayv.greco@gmail.com>2023-01-27 00:03:57 -0800
committerGitHub <noreply@github.com>2023-01-27 08:03:57 +0000
commitb3dca4bb36d0c08e8145f6f25649aaf61b513fdd (patch)
treeefa1166c6bae58dc30fd8f2d4157c64a1fbb4837 /keyboards/nullbitsco
parent6e42b5854902963469a4016abeca48a9df5c1c46 (diff)
Add RP2040 SCRAMBLE v2 (#19489)
Diffstat (limited to 'keyboards/nullbitsco')
-rw-r--r--keyboards/nullbitsco/scramble/rules.mk21
-rw-r--r--keyboards/nullbitsco/scramble/scramble.c22
-rw-r--r--keyboards/nullbitsco/scramble/scramble.h17
-rw-r--r--keyboards/nullbitsco/scramble/v1/config.h (renamed from keyboards/nullbitsco/scramble/config.h)2
-rw-r--r--keyboards/nullbitsco/scramble/v1/rules.mk21
-rw-r--r--keyboards/nullbitsco/scramble/v1/v1.c25
-rw-r--r--keyboards/nullbitsco/scramble/v1/v1.h18
-rw-r--r--keyboards/nullbitsco/scramble/v2/config.h42
-rw-r--r--keyboards/nullbitsco/scramble/v2/halconf.h9
-rw-r--r--keyboards/nullbitsco/scramble/v2/mcuconf.h14
-rw-r--r--keyboards/nullbitsco/scramble/v2/rules.mk21
-rw-r--r--keyboards/nullbitsco/scramble/v2/v2.c84
-rw-r--r--keyboards/nullbitsco/scramble/v2/v2.h43
13 files changed, 288 insertions, 51 deletions
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 <http://www.gnu.org/licenses/>.
*/
#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/config.h b/keyboards/nullbitsco/scramble/v1/config.h
index 4333d94d37..b249b99851 100644
--- a/keyboards/nullbitsco/scramble/config.h
+++ b/keyboards/nullbitsco/scramble/v1/config.h
@@ -15,6 +15,8 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+/* NOTE: This config file is specific to AVR builds. */
+
#pragma once
#include "config_common.h"
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 <http://www.gnu.org/licenses/>.
+*/
+
+/* 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 <halconf.h>
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 <mcuconf.h>
+
+#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; i<NUM_RGB_IDX; i++) {
+ palSetPadMode(PAL_PORT(led->pin[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 <hal.h>
+
+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