analog_joystick.h (1779B)
1 /* Copyright 2020 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com> 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #pragma once 18 19 #include <stdbool.h> 20 #include <stdint.h> 21 #include "pointing_device.h" 22 23 #ifndef ANALOG_JOYSTICK_X_AXIS_PIN 24 # error No pin specified for X Axis 25 #endif 26 #ifndef ANALOG_JOYSTICK_Y_AXIS_PIN 27 # error No pin specified for Y Axis 28 #endif 29 30 #ifndef ANALOG_JOYSTICK_AXIS_MIN 31 # define ANALOG_JOYSTICK_AXIS_MIN 0 32 #endif 33 #ifndef ANALOG_JOYSTICK_AXIS_MAX 34 # define ANALOG_JOYSTICK_AXIS_MAX 1023 35 #endif 36 #ifndef ANALOG_JOYSTICK_SPEED_REGULATOR 37 # define ANALOG_JOYSTICK_SPEED_REGULATOR 20 38 #endif 39 #ifndef ANALOG_JOYSTICK_READ_INTERVAL 40 # define ANALOG_JOYSTICK_READ_INTERVAL 10 41 #endif 42 #ifndef ANALOG_JOYSTICK_SPEED_MAX 43 # define ANALOG_JOYSTICK_SPEED_MAX 2 44 #endif 45 46 extern const pointing_device_driver_t analog_joystick_pointing_device_driver; 47 48 typedef struct { 49 int8_t x; 50 int8_t y; 51 bool button; 52 } report_analog_joystick_t; 53 report_analog_joystick_t analog_joystick_read(void); 54 bool analog_joystick_init(void); 55 report_mouse_t analog_joystick_get_report(report_mouse_t mouse_report);