qmk_firmware

QMK firmware for my keyboards (Corne, Sweep Ferris) and trackball (Ploopy Adept)
Log | Files | Refs | Submodules | LICENSE

connection.h (2506B)


      1 // Copyright 2025 QMK
      2 // SPDX-License-Identifier: GPL-2.0-or-later
      3 #pragma once
      4 
      5 #include <stdint.h>
      6 
      7 #include "compiler_support.h"
      8 #include "util.h"
      9 
     10 /**
     11  * \enum connection_host_t
     12  *
     13  * An enumeration of the possible hosts.
     14  */
     15 typedef enum connection_host_t {
     16     CONNECTION_HOST_AUTO,
     17 
     18     CONNECTION_HOST_NONE,
     19     CONNECTION_HOST_USB,
     20     CONNECTION_HOST_BLUETOOTH,
     21     CONNECTION_HOST_2P4GHZ
     22 } connection_host_t;
     23 
     24 /**
     25  * \union connection_config_t
     26  *
     27  * Configuration structure for the connection subsystem.
     28  */
     29 typedef union connection_config_t {
     30     uint8_t           raw;
     31     connection_host_t desired_host : 8;
     32 } PACKED connection_config_t;
     33 
     34 STATIC_ASSERT(sizeof(connection_config_t) == sizeof(uint8_t), "Connection EECONFIG out of spec.");
     35 
     36 /**
     37  * \brief Initialize the subsystem.
     38  *
     39  * This function must be called only once, before any of the below functions can be called.
     40  */
     41 void connection_init(void);
     42 
     43 /**
     44  * \brief Get currently configured host. Does not resolve 'CONNECTION_HOST_AUTO'.
     45  *
     46  * \return 'connection_host_t' of the configured host.
     47  */
     48 connection_host_t connection_get_host_raw(void);
     49 
     50 /**
     51  * \brief Get current active host.
     52  *
     53  * \return 'connection_host_t' of the configured host.
     54  */
     55 connection_host_t connection_auto_detect_host(void);
     56 
     57 /**
     58  * \brief Get currently configured host. Resolves 'CONNECTION_HOST_AUTO' using 'connection_auto_detect_host()'.
     59  *
     60  * \return 'connection_host_t' of the configured host.
     61  */
     62 connection_host_t connection_get_host(void);
     63 
     64 /**
     65  * \brief Get current host. New state is not written to EEPROM.
     66  *
     67  * \param host The host to configure.
     68  */
     69 void connection_set_host_noeeprom(connection_host_t host);
     70 
     71 /**
     72  * \brief Get current host.
     73  *
     74  * \param host The host to configure.
     75  */
     76 void connection_set_host(connection_host_t host);
     77 
     78 /**
     79  * \brief Move to the next potential host. New state is not written to EEPROM.
     80  *
     81  */
     82 void connection_next_host_noeeprom(void);
     83 
     84 /**
     85  * \brief Move to the next potential host.
     86  *
     87  */
     88 void connection_next_host(void);
     89 
     90 /**
     91  * \brief Move to the previous potential host. New state is not written to EEPROM.
     92  *
     93  */
     94 void connection_prev_host_noeeprom(void);
     95 
     96 /**
     97  * \brief Move to the previous potential host.
     98  *
     99  */
    100 void connection_prev_host(void);
    101 
    102 /**
    103  * \brief user hook called when changing configured host
    104  *
    105  */
    106 void connection_host_changed_user(connection_host_t host);
    107 
    108 /**
    109  * \brief keyboard hook called when changing configured host
    110  *
    111  */
    112 void connection_host_changed_kb(connection_host_t host);