diff options
author | Ryan <fauxpark@gmail.com> | 2022-11-13 10:28:11 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-12 23:28:11 +0000 |
commit | 6cc9513ab0cd5e21354c51ab83a89af9f2eb517e (patch) | |
tree | f997df9ea4a7e066b049c2e906ccb2529db6b5b7 /quantum | |
parent | 8cecf7fad8614de2defd43f225250186cc517f38 (diff) |
Digitizer feature improvements (#19034)
Diffstat (limited to 'quantum')
-rw-r--r-- | quantum/digitizer.c | 64 | ||||
-rw-r--r-- | quantum/digitizer.h | 67 | ||||
-rw-r--r-- | quantum/keyboard.c | 7 | ||||
-rw-r--r-- | quantum/quantum.h | 4 |
4 files changed, 111 insertions, 31 deletions
diff --git a/quantum/digitizer.c b/quantum/digitizer.c index 7925129d0c..f1b926181e 100644 --- a/quantum/digitizer.c +++ b/quantum/digitizer.c @@ -13,26 +13,64 @@ * 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 "digitizer.h" -digitizer_t digitizerReport = {.tipswitch = 0, .inrange = 0, .id = 0, .x = 0, .y = 0, .status = DZ_INITIALIZED}; +digitizer_t digitizer_state = { + .in_range = false, + .tip = false, + .barrel = false, + .x = 0, + .y = 0, + .dirty = false, +}; -__attribute__((weak)) void digitizer_send(void) { - if (digitizerReport.status & DZ_UPDATED) { - host_digitizer_send(&digitizerReport); - digitizerReport.status &= ~DZ_UPDATED; +void digitizer_flush(void) { + if (digitizer_state.dirty) { + host_digitizer_send(&digitizer_state); + digitizer_state.dirty = false; } } -__attribute__((weak)) void digitizer_task(void) { - digitizer_send(); +void digitizer_in_range_on(void) { + digitizer_state.in_range = true; + digitizer_state.dirty = true; + digitizer_flush(); +} + +void digitizer_in_range_off(void) { + digitizer_state.in_range = false; + digitizer_state.dirty = true; + digitizer_flush(); +} + +void digitizer_tip_switch_on(void) { + digitizer_state.tip = true; + digitizer_state.dirty = true; + digitizer_flush(); } -digitizer_t digitizer_get_report(void) { - return digitizerReport; +void digitizer_tip_switch_off(void) { + digitizer_state.tip = false; + digitizer_state.dirty = true; + digitizer_flush(); } -void digitizer_set_report(digitizer_t newDigitizerReport) { - digitizerReport = newDigitizerReport; - digitizerReport.status |= DZ_UPDATED; -}
\ No newline at end of file +void digitizer_barrel_switch_on(void) { + digitizer_state.barrel = true; + digitizer_state.dirty = true; + digitizer_flush(); +} + +void digitizer_barrel_switch_off(void) { + digitizer_state.barrel = false; + digitizer_state.dirty = true; + digitizer_flush(); +} + +void digitizer_set_position(float x, float y) { + digitizer_state.x = x; + digitizer_state.y = y; + digitizer_state.dirty = true; + digitizer_flush(); +} diff --git a/quantum/digitizer.h b/quantum/digitizer.h index cef551567e..b826ba8ac8 100644 --- a/quantum/digitizer.h +++ b/quantum/digitizer.h @@ -17,25 +17,70 @@ #include "quantum.h" +#include <stdbool.h> #include <stdint.h> -enum digitizer_status { DZ_INITIALIZED = 1, DZ_UPDATED = 2 }; +/** + * \defgroup digitizer + * + * HID Digitizer + * \{ + */ typedef struct { - int8_t tipswitch; - int8_t inrange; - uint8_t id; - float x; - float y; - uint8_t status : 2; + bool in_range : 1; + bool tip : 1; + bool barrel : 1; + float x; + float y; + bool dirty; } digitizer_t; -extern digitizer_t digitizer; +extern digitizer_t digitizer_state; -digitizer_t digitizer_get_report(void); +/** + * \brief Send the digitizer report to the host if it is marked as dirty. + */ +void digitizer_flush(void); -void digitizer_set_report(digitizer_t newDigitizerReport); +/** + * \brief Assert the "in range" indicator, and flush the report. + */ +void digitizer_in_range_on(void); -void digitizer_task(void); +/** + * \brief Deassert the "in range" indicator, and flush the report. + */ +void digitizer_in_range_off(void); + +/** + * \brief Assert the tip switch, and flush the report. + */ +void digitizer_tip_switch_on(void); + +/** + * \brief Deassert the tip switch, and flush the report. + */ +void digitizer_tip_switch_off(void); + +/** + * \brief Assert the barrel switch, and flush the report. + */ +void digitizer_barrel_switch_on(void); + +/** + * \brief Deassert the barrel switch, and flush the report. + */ +void digitizer_barrel_switch_off(void); + +/** + * \brief Set the absolute X and Y position of the digitizer contact, and flush the report. + * + * \param x The X value of the contact position, from 0 to 1. + * \param y The Y value of the contact position, from 0 to 1. + */ +void digitizer_set_position(float x, float y); void host_digitizer_send(digitizer_t *digitizer); + +/** \} */ diff --git a/quantum/keyboard.c b/quantum/keyboard.c index eb5e4b583a..83ade7829a 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c @@ -90,9 +90,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. #if defined(CRC_ENABLE) # include "crc.h" #endif -#ifdef DIGITIZER_ENABLE -# include "digitizer.h" -#endif #ifdef VIRTSER_ENABLE # include "virtser.h" #endif @@ -662,10 +659,6 @@ void keyboard_task(void) { joystick_task(); #endif -#ifdef DIGITIZER_ENABLE - digitizer_task(); -#endif - #ifdef BLUETOOTH_ENABLE bluetooth_task(); #endif diff --git a/quantum/quantum.h b/quantum/quantum.h index 4192b3fb16..c8dfdeca75 100644 --- a/quantum/quantum.h +++ b/quantum/quantum.h @@ -207,6 +207,10 @@ extern layer_state_t layer_state; # include "joystick.h" #endif +#ifdef DIGITIZER_ENABLE +# include "digitizer.h" +#endif + #ifdef VIA_ENABLE # include "via.h" #endif |