USB Host Shield 2.0
BTHID.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 Kristian Lauszus, TKJ Electronics. All rights reserved.
2 
3  This software may be distributed and modified under the terms of the GNU
4  General Public License version 2 (GPL2) as published by the Free Software
5  Foundation and appearing in the file GPL2.TXT included in the packaging of
6  this file. Please note that GPL2 Section 2[b] requires that all works based
7  on this software must also be made publicly available under the terms of
8  the GPL2 ("Copyleft").
9 
10  Contact information
11  -------------------
12 
13  Kristian Lauszus, TKJ Electronics
14  Web : http://www.tkjelectronics.com
15  e-mail : kristianl@tkjelectronics.com
16  */
17 
18 #ifndef _bthid_h_
19 #define _bthid_h_
20 
21 #include "BTD.h"
22 #include "hidboot.h"
23 
24 #define KEYBOARD_PARSER_ID 0
25 #define MOUSE_PARSER_ID 1
26 #define NUM_PARSERS 2
27 
29 class BTHID : public BluetoothService {
30 public:
37  BTHID(BTD *p, bool pair = false, const char *pin = "0000");
38 
41  void disconnect();
50  if (id >= NUM_PARSERS)
51  return NULL;
52  return pRptParser[id];
53  };
54 
61  bool SetReportParser(uint8_t id, HIDReportParser *prs) {
62  if (id >= NUM_PARSERS)
63  return false;
64  pRptParser[id] = prs;
65  return true;
66  };
67 
72  void setProtocolMode(uint8_t mode) {
73  protocolMode = mode;
74  };
75 
80  void setLeds(uint8_t data);
81 
83  bool connected;
84 
86  void pair(void) {
87  if(pBtd)
88  pBtd->pairWithHID();
89  };
90 
91 protected:
97  void ACLData(uint8_t* ACLData);
99  void Run();
101  void Reset();
107  void onInit() {
108  if(pFuncOnInit)
109  pFuncOnInit(); // Call the user function
110  OnInitBTHID();
111  };
120  virtual void ParseBTHIDData(uint8_t len, uint8_t *buf) {
121  return;
122  };
124  virtual void OnInitBTHID() {
125  return;
126  };
128  virtual void ResetBTHID() {
129  return;
130  }
134  uint8_t control_scid[2];
135 
137  uint8_t interrupt_scid[2];
138 
139 private:
140  HIDReportParser *pRptParser[NUM_PARSERS]; // Pointer to HIDReportParsers.
141 
143  void setProtocol();
144  uint8_t protocolMode;
145 
146  void L2CAP_task(); // L2CAP state machine
147 
148  bool activeConnection; // Used to indicate if it already has established a connection
149 
150  /* Variables used for L2CAP communication */
151  uint8_t control_dcid[2]; // L2CAP device CID for HID_Control - Always 0x0070
152  uint8_t interrupt_dcid[2]; // L2CAP device CID for HID_Interrupt - Always 0x0071
153  uint8_t l2cap_state;
154 };
155 #endif
virtual void OnInitBTHID()
Definition: BTHID.h:124
void ACLData(uint8_t *ACLData)
Definition: BTHID.cpp:56
Definition: BTD.h:198
uint8_t interrupt_scid[2]
Definition: BTHID.h:137
bool connected
Definition: BTHID.h:83
void Run()
Definition: BTHID.cpp:344
virtual void ResetBTHID()
Definition: BTHID.h:128
void Reset()
Definition: BTHID.cpp:41
uint8_t control_scid[2]
Definition: BTHID.h:134
void pairWithHID()
Definition: BTD.h:480
void disconnect()
Definition: BTHID.cpp:49
HIDReportParser * GetReportParser(uint8_t id)
Definition: BTHID.h:49
void setLeds(uint8_t data)
Definition: BTHID.cpp:393
virtual void ParseBTHIDData(uint8_t len, uint8_t *buf)
Definition: BTHID.h:120
void(* pFuncOnInit)(void)
Definition: BTD.h:603
BTD * pBtd
Definition: BTD.h:606
#define NUM_PARSERS
Definition: BTHID.h:26
void onInit()
Definition: BTHID.h:107
Definition: BTHID.h:29
void setProtocolMode(uint8_t mode)
Definition: BTHID.h:72
BTHID(BTD *p, bool pair=false, const char *pin="0000")
Definition: BTHID.cpp:23
void pair(void)
Definition: BTHID.h:86
bool SetReportParser(uint8_t id, HIDReportParser *prs)
Definition: BTHID.h:61