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();
51 
60  if (id >= NUM_PARSERS)
61  return NULL;
62  return pRptParser[id];
63  };
64 
71  bool SetReportParser(uint8_t id, HIDReportParser *prs) {
72  if (id >= NUM_PARSERS)
73  return false;
74  pRptParser[id] = prs;
75  return true;
76  };
77 
82  void setProtocolMode(uint8_t mode) {
83  protocolMode = mode;
84  };
85 
90  void setLeds(uint8_t data);
91 
93  bool connected;
94 
96  void pair(void) {
97  if(pBtd)
98  pBtd->pairWithHID();
99  };
100 
105  void attachOnInit(void (*funcOnInit)(void)) {
106  pFuncOnInit = funcOnInit;
107  };
108 
109 private:
110  BTD *pBtd; // Pointer to BTD instance
111 
112  HIDReportParser *pRptParser[NUM_PARSERS]; // Pointer to HIDReportParsers.
113 
115  void setProtocol();
116  uint8_t protocolMode;
117 
123  void onInit() {
124  if(pFuncOnInit)
125  pFuncOnInit(); // Call the user function
126  };
127  void (*pFuncOnInit)(void); // Pointer to function called in onInit()
128 
129  void L2CAP_task(); // L2CAP state machine
130 
131  /* Variables filled from HCI event management */
132  uint16_t hci_handle;
133  bool activeConnection; // Used to indicate if it already has established a connection
134 
135  /* Variables used by high level L2CAP task */
136  uint8_t l2cap_state;
137  uint32_t l2cap_event_flag; // l2cap flags of received Bluetooth events
138 
139  /* L2CAP Channels */
140  uint8_t control_scid[2]; // L2CAP source CID for HID_Control
141  uint8_t control_dcid[2]; // 0x0070
142  uint8_t interrupt_scid[2]; // L2CAP source CID for HID_Interrupt
143  uint8_t interrupt_dcid[2]; // 0x0071
144  uint8_t identifier; // Identifier for connection
145 };
146 #endif
virtual void ACLData(uint8_t *ACLData)
Definition: BTHID.cpp:58
Definition: BTD.h:230
bool connected
Definition: BTHID.h:93
virtual void Run()
Definition: BTHID.cpp:347
virtual void Reset()
Definition: BTHID.cpp:44
void attachOnInit(void(*funcOnInit)(void))
Definition: BTHID.h:105
void pairWithHID()
Definition: BTD.h:516
virtual void disconnect()
Definition: BTHID.cpp:51
HIDReportParser * GetReportParser(uint8_t id)
Definition: BTHID.h:59
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:82
BTHID(BTD *p, bool pair=false, const char *pin="0000")
Definition: BTHID.cpp:23
void pair(void)
Definition: BTHID.h:96
bool SetReportParser(uint8_t id, HIDReportParser *prs)
Definition: BTHID.h:71