USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
44  virtual void ACLData(uint8_t* ACLData);
46  virtual void Run();
48  virtual void Reset();
50  virtual void disconnect();
59  if (id >= NUM_PARSERS)
60  return NULL;
61  return pRptParser[id];
62  };
63 
70  bool SetReportParser(uint8_t id, HIDReportParser *prs) {
71  if (id >= NUM_PARSERS)
72  return false;
73  pRptParser[id] = prs;
74  return true;
75  };
76 
81  void setProtocolMode(uint8_t mode) {
82  protocolMode = mode;
83  };
84 
89  void setLeds(uint8_t data);
90 
92  bool connected;
93 
95  void pair(void) {
96  if(pBtd)
97  pBtd->pairWithHID();
98  };
99 
104  void attachOnInit(void (*funcOnInit)(void)) {
105  pFuncOnInit = funcOnInit;
106  };
107 
108 protected:
116  virtual void ParseBTHID(BTHID *bthid, uint8_t len, uint8_t *buf) {
117  return;
118  };
120  virtual void OnInitBTHID() {
121  return;
122  };
124  virtual void ResetBTHID() {
125  return;
126  }
129 private:
130  BTD *pBtd; // Pointer to BTD instance
131  HIDReportParser *pRptParser[NUM_PARSERS]; // Pointer to HIDReportParsers.
132 
134  void setProtocol();
135  uint8_t protocolMode;
136 
142  void onInit() {
143  if(pFuncOnInit)
144  pFuncOnInit(); // Call the user function
145  OnInitBTHID();
146  };
147  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
148 
149  void L2CAP_task(); // L2CAP state machine
150 
151  /* Variables filled from HCI event management */
152  uint16_t hci_handle;
153  bool activeConnection; // Used to indicate if it already has established a connection
154 
155  /* Variables used by high level L2CAP task */
156  uint8_t l2cap_state;
157  uint32_t l2cap_event_flag; // l2cap flags of received Bluetooth events
158 
159  /* L2CAP Channels */
160  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
161  uint8_t control_dcid[2]; // 0x0070
162  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
163  uint8_t interrupt_dcid[2]; // 0x0071
164  uint8_t identifier; // Identifier for connection
165 };
166 #endif
virtual void OnInitBTHID()
Definition: BTHID.h:120
virtual void ACLData(uint8_t *ACLData)
Definition: BTHID.cpp:59
Definition: BTD.h:230
bool connected
Definition: BTHID.h:92
virtual void Run()
Definition: BTHID.cpp:347
virtual void ResetBTHID()
Definition: BTHID.h:124
virtual void Reset()
Definition: BTHID.cpp:44
void attachOnInit(void(*funcOnInit)(void))
Definition: BTHID.h:104
void pairWithHID()
Definition: BTD.h:516
virtual void disconnect()
Definition: BTHID.cpp:52
virtual void ParseBTHID(BTHID *bthid, uint8_t len, uint8_t *buf)
Definition: BTHID.h:116
HIDReportParser * GetReportParser(uint8_t id)
Definition: BTHID.h:58
void setLeds(uint8_t data)
Definition: BTHID.cpp:396
#define NUM_PARSERS
Definition: BTHID.h:26
Definition: BTHID.h:29
void setProtocolMode(uint8_t mode)
Definition: BTHID.h:81
BTHID(BTD *p, bool pair=false, const char *pin="0000")
Definition: BTHID.cpp:23
void pair(void)
Definition: BTHID.h:95
bool SetReportParser(uint8_t id, HIDReportParser *prs)
Definition: BTHID.h:70