Skip to content

Commit

Permalink
add cocot46
Browse files Browse the repository at this point in the history
  • Loading branch information
hash committed Nov 28, 2021
1 parent 37b63c5 commit 67ec33b
Show file tree
Hide file tree
Showing 13 changed files with 1,135 additions and 0 deletions.
121 changes: 121 additions & 0 deletions keyboards/cocot46/cocot46.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* Copyright 2021 aki27
*
* 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 "cocot46.h"
#include <string.h>
#include "debug.h"

#include QMK_KEYBOARD_H
#include "matrix.h"
#include "bmp.h"
#include "bmp_matrix.h"
#include "spi.h"
#include "paw3204.h"

#include "report.h"

void keyboard_post_init_kb() { debug_enable = false; }

void create_user_file() {
// static const char qmk_configurator[] =
// "<meta http-equiv=\"refresh\" "
// "content=\"0;URL=\'https://sekigon-gonnoc.github.io/qmk_configurator/#/"
// "kugel/LAYOUT\'\"/>";
// BMPAPI->usb.create_file("MAP_EDITHTM", (uint8_t *)qmk_configurator,
// strlen(qmk_configurator));

// static const char build_guide[] =
// "<meta http-equiv=\"refresh\" "
// "content=\"0;URL=\'https://github.com/sekigon-gonnoc/Kugel-doc\'\"/>";
// BMPAPI->usb.create_file("BLDGUIDEHTM", (uint8_t *)build_guide,
// strlen(build_guide));
}

// static void create_status_file() {
// static char status_str[128];
// // clang-format off
// tfp_sprintf(status_str,
// "Trackball:%s\r\n",
// trackball_init_flag == TRACKBALL_BTO ? " BTO" : "NO");
// // clang-format on
// BMPAPI->usb.create_file("STATUS TXT", (uint8_t *)status_str,
// strlen(status_str));
// }

void matrix_scan_kb() {

static float voltage = -1;
if (!is_usb_connected()) {
static uint32_t battery_check_cnt = 0;
static uint32_t low_battery_cnt = 0;

if (voltage < 0) {
// first measurement
voltage = BMPAPI->app.get_vcc_mv();
battery_check_cnt = timer_read32();
} else if (timer_elapsed32(battery_check_cnt) > 1000) {
battery_check_cnt = timer_read32();
uint32_t v_mes = BMPAPI->app.get_vcc_mv();

if (v_mes > voltage) {
voltage = (0.7f) * voltage + (0.3f) * v_mes;
} else {
if (voltage - v_mes > 100) {
} else {
voltage = (0.95f) * voltage + (0.05f) * v_mes;
}
}

if (voltage < 1000.0f - 100.0f) { // 100mV offset by series resistance
low_battery_cnt++;
}

if (low_battery_cnt > 30) {
sleep_enter_counter = 1;
}
}
} else {
voltage = -1;
}

matrix_scan_user();
}

// void bmp_before_sleep() {
// //// setPinInputHigh(16);
// //// setPinInputHigh(14);
// // setPinInputHigh(CS_PIN_TB);
// //// writePinHigh(TB_POW);
// }

// bool bmp_config_overwrite(bmp_api_config_t const *const config_on_storage,
// bmp_api_config_t *const keyboard_config) {
// // get vcc from a3
// BMPAPI->adc.config_vcc_channel(3, 1200, 700);
// // wait until voltage become stable
// for (int i = 0; i < 40000; i++) {
// BMPAPI->app.get_vcc_percent();
// }

// // User can overwrite partial settings
// keyboard_config->startup = config_on_storage->startup;
// keyboard_config->matrix.debounce = config_on_storage->matrix.debounce;
// keyboard_config->param_central = config_on_storage->param_central;
// keyboard_config->param_peripheral = config_on_storage->param_peripheral;
// keyboard_config->keymap = config_on_storage->keymap;
// keyboard_config->reserved[2] = config_on_storage->reserved[2];
// return true;
// }
40 changes: 40 additions & 0 deletions keyboards/cocot46/cocot46.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* Copyright 2021 aki27
*
* 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"

/* This is a shortcut to help you visually see your layout.
*
* The first section contains all of the arguments representing the physical
* layout of the board and position of the keys.
*
* The second converts the arguments into a two-dimensional array which
* represents the switch matrix.
*/
#define LAYOUT( \
ka00, ka01, ka02, ka03, ka04, ka05, ka08, ka09, ka10, ka11, ka12, ka13, \
kb00, kb01, kb02, kb03, kb04, kb05, kb08, kb09, kb10, kb11, kb12, kb13, \
kc00, kc01, kc02, kc03, kc04, kc05, ka06, ka07, kc08, kc09, kc10, kc11, kc12, kc13, \
kd02, kd03, kd04, kd05, kc06, kb06, kd06, kd08, kd09, kd10, kd11 \
) { \
{ ka00, ka01, ka02, ka03, ka04, ka05, ka06, ka13, ka12, ka11, ka10, ka09, ka08, ka07 }, \
{ kb00, kb01, kb02, kb03, kb04, kb05, kb06, kb13, kb12, kb11, kb10, kb09, kb08, KC_NO }, \
{ kc00, kc01, kc02, kc03, kc04, kc05, kc06, kc13, kc12, kc11, kc10, kc09, kc08, KC_NO }, \
{ KC_NO, KC_NO, kd02, kd03, kd04, kd05, kd06, KC_NO, KC_NO, kd11, kd10, kd09, kd08, KC_NO } \
}

Loading

0 comments on commit 67ec33b

Please sign in to comment.