ezusbthamway.h
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #include "chardevicedriver.h"
15 #include "charinterface.h"
16 #include <vector>
17 
18 #define DEV_ADDR_PROT 0x6
19 
20 //! interfaces chameleon USB, found at http://optimize.ath.cx/cusb
22 public:
23  XWinCUSBInterface(const char *name, bool runtime, const shared_ptr<XDriver> &driver, uint8_t addr_offset, const char* id);
24  virtual ~XWinCUSBInterface();
25 
26  virtual void open() throw (XInterfaceError &);
27  //! This can be called even if has already closed.
28  virtual void close() throw (XInterfaceError &);
29 
30  void deferWritings();
31  void writeToRegister8(unsigned int addr, uint8_t data);
32  void writeToRegister16(unsigned int addr, uint16_t data);
33  void bulkWriteStored();
34  void resetBulkWrite();
35 
36  void burstRead(unsigned int addr, uint8_t *buf, unsigned int cnt);
37  uint8_t singleRead(unsigned int addr);
38  uint16_t readRegister8(unsigned int addr) {return singleRead(addr);}
39  uint16_t readRegister16(unsigned int addr);
40 
41  XString getIDN(int maxlen = 255) {return getIDN(m_handle, maxlen); }
42 
43  void lock() {m_mutex->lock();} //!<overrides XInterface::lock().
44  void unlock() {m_mutex->unlock();}
45  bool isLocked() const {return m_mutex->isLockedByCurrentThread();}
46 
47  virtual void send(const char *str) throw (XCommError &);
48  virtual void receive() throw (XCommError &);
49 
50  virtual bool isOpened() const {return m_handle != 0;}
51 protected:
52 private:
53  XString getIDN(void *handle, int maxlen = 255) {
54  XString str = getIDN(handle, maxlen, m_addrOffset);
55  if(str.empty() || (str.find(m_idString,0) != 0))
56  return XString();
57  return str;
58  }
59  static void setLED(void *handle, uint8_t data);
60  static uint8_t readDIPSW(void *handle);
61  static uint8_t singleRead(void *handle, unsigned int addr, unsigned int addroffset);
62  static XMutex s_mutex;
63  struct USBDevice {
64  shared_ptr<XRecursiveMutex> mutex;
65  void *handle;
66  int addr;
67  };
68  static std::deque<USBDevice> s_devices;
69  static int s_refcnt;
70  static void openAllEZUSBdevices();
71  static void setWave(void *handle, const uint8_t *wave);
72  static void closeAllEZUSBdevices();
73  static XString getIDN(void *handle, int maxlen, int offsetaddr);
74  void* m_handle;
75  shared_ptr<XRecursiveMutex> m_mutex;
76  XString m_idString;
77  uint8_t m_addrOffset;
78  bool m_bBurstWrite;
79  std::vector<uint8_t> m_buffer; //writing buffer for a burst write.
80 };

Generated for KAME4 by  doxygen 1.8.3