Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Keyboard] Add MIIIW BlackIO83 #21970

Merged
merged 7 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions keyboards/miiiw/blackio83/blackio83.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/* Copyright 2023 ArthurCyy <https://github.com/ArthurCyy>
*
* 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/>.
*/

#include "blackio83.h"
#include "usb_main.h"
#include "usb_util.h"

#define LOOP_10HZ_PERIOD 100
deferred_token loop10hz_token = INVALID_DEFERRED_TOKEN;
uint32_t loop_10Hz(uint32_t trigger_time, void *cb_arg);

static const SerialConfig mwproto_uart_config = {
.speed = MWPROTO_BITRATE,
};

static void POWER_EnterSleep(void) {
/* Clear Wake-up flag */
PWR->CR |= PWR_CR_CWUF | PWR_CR_CSBF;
/* Select Sleep mode */
/* PWR->CR |= PWR_CR_PDDS | PWR_CR_LPDS; */
/* Set SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR |= SCB_SCR_SLEEPDEEP_Msk;
/* Request Wait For Interrupt */
__WFI();
/* Reset SLEEPDEEP bit of Cortex System Control Register */
SCB->SCR &= ~SCB_SCR_SLEEPDEEP_Msk;
NVIC_SystemReset();
}

extern void ws2812_poweron(void);
extern void ws2812_poweroff(void);

void keyboard_pre_init_kb() {
keyboard_pre_init_user();

setPinInputLow(MWPROTO_STATUS_PIN);
setPinOutput(MWPROTO_WAKEUP_PIN);
writePinLow(MWPROTO_WAKEUP_PIN);
wait_ms(2);
writePinHigh(MWPROTO_WAKEUP_PIN);

palSetLineMode(MWPROTO_TX_PIN, PAL_MODE_ALTERNATE(MWPROTO_TX_PAL_MODE) | PAL_OUTPUT_TYPE_OPENDRAIN);
sdStart(&MWPROTO_DRIVER, &mwproto_uart_config);
}

void keyboard_post_init_kb(void) {
keyboard_post_init_user();

print(/* clang-format off */
"\n<--QMK Keyboard-->\n"
"Vendor: " STR(MANUFACTURER) "(" STR(VENDOR_ID) ")\n"
"Product: " STR(PRODUCT) " (" STR(PRODUCT_ID) ")\n"
"Version: " STR(DEVICE_VER) "\n"
"BUILD: " __DATE__ "\n"
); /* clang-format on */

writePinLow(MWPROTO_WAKEUP_PIN);
wait_ms(50);
sdPutI(&MWPROTO_DRIVER, 0xA5);
sdPutI(&MWPROTO_DRIVER, 0x12);
sdPutI(&MWPROTO_DRIVER, 0x01);
sdPutI(&MWPROTO_DRIVER, 0x02);
sdPutI(&MWPROTO_DRIVER, 0xB4);
writePinHigh(MWPROTO_WAKEUP_PIN);

ws2812_poweron();
loop10hz_token = defer_exec(LOOP_10HZ_PERIOD, loop_10Hz, NULL);
}

void shutdown_user(void) {
drashna marked this conversation as resolved.
Show resolved Hide resolved
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_set_suspend_state(true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever. Though, this would only work if suspend is enabled for rgb matrix, in general. If it's not... then it won't do anything.

#endif // RGB_MATRIX_ENABLE
wait_ms(10);
ws2812_poweroff();
}

#ifdef DIP_SWITCH_ENABLE
bool dip_switch_update_mask_kb(uint32_t state) {
if (!dip_switch_update_mask_user(state)) { return false; }

if(state & 0x01) {
led_suspend();
usbDisconnectBus(&USB_DRIVER);
usbStop(&USB_DRIVER);
shutdown_user();
setPinInputHigh(POWER_SWITCH_PIN);
palEnableLineEvent(POWER_SWITCH_PIN, PAL_EVENT_MODE_RISING_EDGE);
POWER_EnterSleep();
}

return true;
}
#endif

uint32_t loop_10Hz(uint32_t trigger_time, void *cb_arg) {

if(last_input_activity_elapsed() > 1000) {
static uint32_t pmu_timer = 0;
if(timer_elapsed32(pmu_timer) > 3000) {
pmu_timer = timer_read32();
writePinLow(MWPROTO_WAKEUP_PIN);
if(readPin(MWPROTO_STATUS_PIN))
wait_us(500);
else
wait_us(1500);
sdPutI(&MWPROTO_DRIVER, 0xA5);
sdPutI(&MWPROTO_DRIVER, 0x28);
sdPutI(&MWPROTO_DRIVER, 0x00);
sdPutI(&MWPROTO_DRIVER, 0x8D);
writePinHigh(MWPROTO_WAKEUP_PIN);
}
}

extern matrix_row_t matrix[MATRIX_ROWS];
static uint32_t restore_tick = 0;
if(matrix[0] == 0x4000 && matrix[1] == 0 &&
matrix[2] == 0 && matrix[3] == 0 && matrix[4] == 0 && matrix[5] == 0x201) {
if(restore_tick++ > 50) {
restore_tick = 0;
writePinLow(MWPROTO_WAKEUP_PIN);
if(readPin(MWPROTO_STATUS_PIN))
wait_us(500);
else
wait_us(1500);
sdPutI(&MWPROTO_DRIVER, 0xA5);
sdPutI(&MWPROTO_DRIVER, 0x1F);
sdPutI(&MWPROTO_DRIVER, 0x01);
sdPutI(&MWPROTO_DRIVER, 0x0F);
sdPutI(&MWPROTO_DRIVER, 0xB4);
writePinHigh(MWPROTO_WAKEUP_PIN);
wait_ms(50);
eeconfig_init();
#ifdef RGB_MATRIX_ENABLE
extern void rgb_matrix_update_pwm_buffers(void);
for(int i = 0; i < 5; i++) {
rgb_matrix_set_color_all(RGB_WHITE);
rgb_matrix_update_pwm_buffers();
wait_ms(500);
rgb_matrix_set_color_all(RGB_OFF);
rgb_matrix_update_pwm_buffers();
wait_ms(500);
}
#endif
wait_ms(500);
soft_reset_keyboard();
}
} else {
restore_tick = 0;
}

static uint32_t debug_tick = 0;
if (debug_tick++ > 9 ) {
dprintf("trigger %d\n", trigger_time);
debug_tick = 0;
}

return LOOP_10HZ_PERIOD;
}
36 changes: 36 additions & 0 deletions keyboards/miiiw/blackio83/blackio83.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Copyright 2023 ArthurCyy <https://github.com/ArthurCyy>
*
* 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/>.
*/

#pragma once

#include "quantum.h"

#define XXX KC_NO

enum custom_keycodes {
#ifdef VIA_ENABLE
DEV_BT1 = SAFE_RANGE,
#endif
drashna marked this conversation as resolved.
Show resolved Hide resolved
DEV_BT2,
DEV_BT3,
DEV_RF24,
ALT_TAB,
RGB_RST,
NEW_SAFE_RANGE
};

#undef SAFE_RANGE
#define SAFE_RANGE NEW_SAFE_RANGE
drashna marked this conversation as resolved.
Show resolved Hide resolved
92 changes: 92 additions & 0 deletions keyboards/miiiw/blackio83/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* Copyright 2023 ArthurCyy <https://github.com/ArthurCyy>
*
* 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/>.
*/

#pragma once

/* key matrix size */
#define MATRIX_ROWS 6
#define MATRIX_COLS 16
ArthurCyy marked this conversation as resolved.
Show resolved Hide resolved

// EEPROM i2c chip
#define EEPROM_I2C_24LC256

/* RGB Matrix */
#ifdef RGB_MATRIX_ENABLE
drashna marked this conversation as resolved.
Show resolved Hide resolved
# define RGB_MATRIX_KEYPRESSES // reacts to keypresses
drashna marked this conversation as resolved.
Show resolved Hide resolved
# define RGB_MATRIX_FRAMEBUFFER_EFFECTS
# define RGB_MATRIX_LED_FLUSH_LIMIT 26
//# define RGB_DISABLE_AFTER_TIMEOUT 0 // number of ticks to wait until disabling effects
# define RGB_DISABLE_WHEN_USB_SUSPENDED // turn off effects when suspended
# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 160 // limits maximum brightness of LEDs to 150 out of 255. Higher may cause the controller to crash.
# define RGB_MATRIX_HUE_STEP 36
# define RGB_MATRIX_SAT_STEP 8
# define RGB_MATRIX_VAL_STEP 32
# define RGB_MATRIX_SPD_STEP 60
# define RGB_MATRIX_DEFAULT_HUE 170
# define RGB_MATRIX_DEFAULT_SPD (RGB_MATRIX_SPD_STEP + 15)

/* Disable the animations you don't want/need. You will need to disable a good number of these *
* because they take up a lot of space. Disable until you can successfully compile your firmware. */
// RGB Matrix Animation modes. Explicitly enabled
// For full list of effects, see:
// https://docs.qmk.fm/#/feature_rgb_matrix?id=rgb-matrix-effects
// # define ENABLE_RGB_MATRIX_ALPHAS_MODS
# define ENABLE_RGB_MATRIX_GRADIENT_UP_DOWN
# define ENABLE_RGB_MATRIX_GRADIENT_LEFT_RIGHT
# define ENABLE_RGB_MATRIX_BREATHING
# define ENABLE_RGB_MATRIX_BAND_SAT
# define ENABLE_RGB_MATRIX_BAND_VAL
# define ENABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
# define ENABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
# define ENABLE_RGB_MATRIX_BAND_SPIRAL_SAT
# define ENABLE_RGB_MATRIX_BAND_SPIRAL_VAL
# define ENABLE_RGB_MATRIX_CYCLE_ALL
# define ENABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
# define ENABLE_RGB_MATRIX_CYCLE_UP_DOWN
# define ENABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN
# define ENABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
# define ENABLE_RGB_MATRIX_CYCLE_PINWHEEL
# define ENABLE_RGB_MATRIX_CYCLE_SPIRAL
# define ENABLE_RGB_MATRIX_DUAL_BEACON
# define ENABLE_RGB_MATRIX_RAINBOW_BEACON
# define ENABLE_RGB_MATRIX_RAINBOW_PINWHEELS
# define ENABLE_RGB_MATRIX_RAINDROPS
# define ENABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
# define ENABLE_RGB_MATRIX_HUE_BREATHING
# define ENABLE_RGB_MATRIX_HUE_PENDULUM
# define ENABLE_RGB_MATRIX_HUE_WAVE
# define ENABLE_RGB_MATRIX_PIXEL_RAIN
# define ENABLE_RGB_MATRIX_PIXEL_FLOW
# define ENABLE_RGB_MATRIX_PIXEL_FRACTAL
// enabled only if RGB_MATRIX_FRAMEBUFFER_EFFECTS is defined
# define ENABLE_RGB_MATRIX_TYPING_HEATMAP
# define ENABLE_RGB_MATRIX_DIGITAL_RAIN
// enabled only of RGB_MATRIX_KEYPRESSES or RGB_MATRIX_KEYRELEASES is defined
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
# define ENABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
# define ENABLE_RGB_MATRIX_SPLASH
# define ENABLE_RGB_MATRIX_MULTISPLASH
# define ENABLE_RGB_MATRIX_SOLID_SPLASH
# define ENABLE_RGB_MATRIX_SOLID_MULTISPLASH
#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR
#endif
drashna marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 33 additions & 0 deletions keyboards/miiiw/blackio83/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Copyright 2020 QMK
*
* 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/>.
*/

/*
* This file was auto-generated by:
* `qmk chibios-confmigrate -i keyboards/geekboards/macropad_v2/halconf.h -r platforms/chibios/common/configs/halconf.h`
*/

#pragma once

#define HAL_USE_SERIAL TRUE

#define HAL_USE_I2C TRUE

// This enables interrupt-driven mode
#define PAL_USE_WAIT TRUE
#define USB_USE_WAIT TRUE

#include_next <halconf.h>

Loading