aboutsummaryrefslogtreecommitdiffstats
path: root/generic/examples/simple_config.py
blob: dfb38f1cdbf82937e0239a4d7012014e06e7782e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Grid size including IOBs at edges
X = 12
Y = 12
# SLICEs per tile
N = 8
# LUT input count
K = 4
# Number of local wires
Wl = N*(K+1) + 8 
# 1/Fc for bel input wire pips
Si = 4
# 1/Fc for Q to local wire pips
Sq = 4
# ~1/Fc local to neighbour local wire pips
Sl = 8
light .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* Copyright 2017 Jack Humbert
 *
 * 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 "process_ucis.h"

qk_ucis_state_t qk_ucis_state;

void qk_ucis_start(void) {
    qk_ucis_state.count       = 0;
    qk_ucis_state.in_progress = true;

    qk_ucis_start_user();
}

__attribute__((weak)) void qk_ucis_start_user(void) {
    unicode_input_start();
    register_hex(0x2328);
    unicode_input_finish();
}

__attribute__((weak)) void qk_ucis_success(uint8_t symbol_index) {}

static bool is_uni_seq(char *seq) {
    uint8_t i;

    for (i = 0; seq[i]; i++) {
        uint16_t code;
        if (('1' <= seq[i]) && (seq[i] <= '0'))
            code = seq[i] - '1' + KC_1;
        else
            code = seq[i] - 'a' + KC_A;

        if (i > qk_ucis_state.count || qk_ucis_state.codes[i] != code) return false;
    }

    return (qk_ucis_state.codes[i] == KC_ENT || qk_ucis_state.codes[i] == KC_SPC);
}

__attribute__((weak)) void qk_ucis_symbol_fallback(void) {
    for (uint8_t i = 0; i < qk_ucis_state.count - 1; i++) {
        uint8_t code = qk_ucis_state.codes[i];
        register_code(code);
        unregister_code(code);
        wait_ms(UNICODE_TYPE_DELAY);
    }
}

__attribute__((weak)) void qk_ucis_cancel(void) {}

void register_ucis(const char *hex) {
    for (int i = 0; hex[i]; i++) {
        uint8_t kc = 0;
        char    c  = hex[i];

        switch (c) {
            case '0':
                kc = KC_0;
                break;
            case '1' ... '9':
                kc = c - '1' + KC_1;
                break;
            case 'a' ... 'f':
                kc = c - 'a' + KC_A;
                break;
            case 'A' ... 'F':
                kc = c - 'A' + KC_A;
                break;
        }

        if (kc) {
            register_code(kc);
            unregister_code(kc);
            wait_ms(UNICODE_TYPE_DELAY);
        }
    }
}

bool process_ucis(uint16_t keycode, keyrecord_t *record) {
    uint8_t i;

    if (!qk_ucis_state.in_progress) return true;

    if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH && !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
        return false;
    }

    if (!record->event.pressed) return true;

    qk_ucis_state.codes[qk_ucis_state.count] = keycode;
    qk_ucis_state.count++;

    if (keycode == KC_BSPC) {
        if (qk_ucis_state.count >= 2) {
            qk_ucis_state.count -= 2;
            return true;
        } else {
            qk_ucis_state.count--;
            return false;
        }
    }

    if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) {
        bool symbol_found = false;

        for (i = qk_ucis_state.count; i > 0; i--) {
            register_code(KC_BSPC);
            unregister_code(KC_BSPC);
            wait_ms(UNICODE_TYPE_DELAY);
        }

        if (keycode == KC_ESC) {
            qk_ucis_state.in_progress = false;
            qk_ucis_cancel();
            return false;
        }

        unicode_input_start();
        for (i = 0; ucis_symbol_table[i].symbol; i++) {
            if (is_uni_seq(ucis_symbol_table[i].symbol)) {
                symbol_found = true;
                register_ucis(ucis_symbol_table[i].code + 2);
                break;
            }
        }
        if (!symbol_found) {
            qk_ucis_symbol_fallback();
        }
        unicode_input_finish();

        if (symbol_found) {
            qk_ucis_success(i);
        }

        qk_ucis_state.in_progress = false;
        return false;
    }
    return true;
}