Skip to content

Commit

Permalink
[Keyboard] Add MIIIW BlackIO83 (#21970)
Browse files Browse the repository at this point in the history
* Add MIIIW BlackIO83

* Improve the code

* Updated instructions for entering the bootloader

* Update keyboards/miiiw/blackio83/rev_0100/config.h

* Update keyboards/miiiw/blackio83/rev_0100/config.h

* Update keyboards/miiiw/blackio83/config.h

* Update config.h
  • Loading branch information
ArthurCyy committed Oct 10, 2023
1 parent 509a2b4 commit 6dafcac
Show file tree
Hide file tree
Showing 16 changed files with 1,087 additions and 0 deletions.
189 changes: 189 additions & 0 deletions keyboards/miiiw/blackio83/blackio83.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
/* 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:https://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);

static bool p_setup = false;
static bool s_init = false;
void ws2812_poweron(void) {
if(p_setup) return;
p_setup = true;
s_init = false;
setPinOutput(RGB_EN_PIN);
writePinHigh(RGB_EN_PIN);
}

void ws2812_poweroff(void) {
if(!p_setup) return;
p_setup = false;
setPinInputLow(WS2812_DI_PIN);
writePinLow(RGB_EN_PIN);
}

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

__attribute__((weak)) void shutdown_user(void) {
#ifdef RGB_MATRIX_ENABLE
rgb_matrix_set_suspend_state(true);
#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;
}
30 changes: 30 additions & 0 deletions keyboards/miiiw/blackio83/blackio83.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* 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:https://www.gnu.org/licenses/>.
*/

#pragma once

#include "quantum.h"

#define XXX KC_NO

enum custom_keycodes {
DEV_BT1 = QK_KB,
DEV_BT2,
DEV_BT3,
DEV_RF24,
ALT_TAB,
RGB_RST,
};
56 changes: 56 additions & 0 deletions keyboards/miiiw/blackio83/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* 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:https://www.gnu.org/licenses/>.
*/

#pragma once

// EEPROM i2c chip
#define EEPROM_I2C_24LC256

/* 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
#define RGB_MATRIX_DEFAULT_MODE RGB_MATRIX_SOLID_COLOR
32 changes: 32 additions & 0 deletions keyboards/miiiw/blackio83/halconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* 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:https://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

0 comments on commit 6dafcac

Please sign in to comment.