summaryrefslogtreecommitdiffstats
path: root/keyboards/keychron/bluetooth/bluetooth.h
blob: 99d406223df3d053b149de1d9d9c0b49d7d767f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright 2022 @ lokher (https://www.keychron.com)
 *
 * 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/>.
 */

#pragma once

#include "bluetooth_event_type.h"
#include "action.h"

/* Low power mode */
#ifndef LOW_POWER_MODE
#    define LOW_POWER_MODE PM_STOP1
#endif

/* Wake pin used for blueooth module/controller to wake up MCU in low power mode*/
#ifndef BLUETOOTH_INT_INPUT_PIN
#    define WAKE_PIN A5
#endif

/* Type of an enumeration of the possible BT state.*/
typedef enum {
    BLUETOOTH_RESET,
    BLUETOOTH_INITIALIZED,   // 1
    BLUETOOTH_DISCONNECTED,  // 2
    BLUETOOTH_CONNECTED,     // 3
    BLUETOOTH_PARING,        // 4
    BLUETOOTH_RECONNECTING,  // 5
    BLUETOOTH_SUSPEND
} bluetooth_state_t;

extern event_listener_t bt_driver;

typedef struct {
    void (*init)(bool);
    void (*connect_ex)(uint8_t, uint16_t);
    void (*pairing_ex)(uint8_t, void *);
    void (*disconnect)(void);
    void (*send_keyboard)(uint8_t *);
    void (*send_nkro)(uint8_t *);
    void (*send_consumer)(uint16_t);
    void (*send_system)(uint16_t);
    void (*send_mouse)(uint8_t *);
    void (*task)(void);
} bluetooth_transport_t;

void bluetooth_init(void);
void bluetooth_set_transport(bluetooth_transport_t *transport);
void bluetooth_task(void);

bool bluetooth_event_queue_enqueue(bluetooth_event_t event);

void bluetooth_connect(void);
void bluetooth_connect_ex(uint8_t host_idx, uint16_t timeout);
void bluetooth_disconnect(void);

void bluetooth_pairing(void);
void bluetooth_pairing_ex(uint8_t host_idx, void *param);
bool bluetooth_is_activated(void);

void bluetooth_enter_reset_kb(uint8_t reason);
void bluetooth_enter_discoverable_kb(uint8_t host_idx);
void bluetooth_enter_reconnecting_kb(uint8_t host_idx);
void bluetooth_enter_connected_kb(uint8_t host_idx);
void bluetooth_enter_disconnected_kb(uint8_t host_idx);
void bluetooth_enter_pin_code_entry_kb(void);
void bluetooth_exit_pin_code_entry_kb(void);

void              bluetooth_task(void);
void              bluetooth_pre_task(void);
void              bluetooth_post_task(void);
bluetooth_state_t bluetooth_get_state(void);

void bluetooth_low_battery_shutdown(void);

bool process_record_kb_bt(uint16_t keycode, keyrecord_t *record);