qmk_firmware/assets/features_joystick.md.CW0gZHec.js

16 lines
26 KiB
JavaScript
Raw Normal View History

import { _ as _export_sfc, c as createElementBlock, o as openBlock, a8 as createStaticVNode } from "./chunks/framework.DyMmIvSC.js";
const __pageData = JSON.parse('{"title":"Joystick","description":"","frontmatter":{},"headers":[],"relativePath":"features/joystick.md","filePath":"features/joystick.md"}');
const _sfc_main = { name: "features/joystick.md" };
const _hoisted_1 = /* @__PURE__ */ createStaticVNode('<h1 id="joystick" tabindex="-1">Joystick <a class="header-anchor" href="#joystick" aria-label="Permalink to &quot;Joystick {#joystick}&quot;"></a></h1><p>This feature provides game controller input as a joystick device supporting up to 6 axes and 32 buttons. Axes can be read either from an <a href="./../drivers/adc">ADC-capable input pin</a>, or can be virtual, so that its value is provided by your code.</p><p>An analog device such as a <a href="https://en.wikipedia.org/wiki/Potentiometer" target="_blank" rel="noreferrer">potentiometer</a> found on an analog joystick&#39;s axes is based on a voltage divider, where adjusting the movable wiper controls the output voltage which can then be read by the microcontroller&#39;s ADC.</p><h2 id="usage" tabindex="-1">Usage <a class="header-anchor" href="#usage" aria-label="Permalink to &quot;Usage {#usage}&quot;"></a></h2><p>Add the following to your <code>rules.mk</code>:</p><div class="language-make vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">make</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">JOYSTICK_ENABLE = yes</span></span></code></pre></div><p>By default the joystick driver is <code>analog</code>, but you can change this with:</p><div class="language-make vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">make</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#24292E;--shiki-dark:#E1E4E8;">JOYSTICK_DRIVER = digital</span></span></code></pre></div><h2 id="configuration" tabindex="-1">Configuration <a class="header-anchor" href="#configuration" aria-label="Permalink to &quot;Configuration {#configuration}&quot;"></a></h2><p>By default, two axes and eight buttons are defined, with a reported resolution of 8 bits (-127 to +127). This can be changed in your <code>config.h</code>:</p><div class="language-c vp-adaptive-theme"><button title="Copy Code" class="copy"></button><span class="lang">c</span><pre class="shiki shiki-themes github-light github-dark vp-code"><code><span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Min 0, max 32</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_BUTTON_COUNT</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 16</span></span>\n<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Min 0, max 6: X, Y, Z, Rx, Ry, Rz</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_AXIS_COUNT</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 3</span></span>\n<span class="line"><span style="--shiki-light:#6A737D;--shiki-dark:#6A737D;">// Min 8, max 16</span></span>\n<span class="line"><span style="--shiki-light:#D73A49;--shiki-dark:#F97583;">#define</span><span style="--shiki-light:#6F42C1;--shiki-dark:#B392F0;"> JOYSTICK_AXIS_RESOLUTION</span><span style="--shiki-light:#005CC5;--shiki-dark:#79B8FF;"> 10</span></span></code></pre></div><div class="tip custom-block"><p class="custom-block-title">TIP</p><p>You must define at least one button or axis. Also note that the maximum ADC resolution of the supported AVR MCUs is 10-bit, and 12-bit for most STM32 MCUs.</p></div><h3 id="axes" tabindex="-1">Axes <a class="header-anchor" href="#axes" aria-label="Permalink to &quot;Axes {#axes}&quot;"></a></h3><p>When defining axes for your joystick, you must provide a definition array typically in your <code>keymap.c</code>.</p><p>For instance, the below example configures two axes. The X axis is read from the <code>A4</code> pin. With the default axis resolution of 8 bits, the range of values between 900 and 575 are scaled to -127 throu
const _hoisted_59 = [
_hoisted_1
];
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return openBlock(), createElementBlock("div", null, _hoisted_59);
}
const joystick = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
export {
__pageData,
joystick as default
};