BlueUSB with USB-> SERIAL (CP210x) GPIO pins working.

Dependencies:   mbed

Committer:
tecnosys
Date:
Fri Apr 23 05:04:28 2010 +0000
Revision:
0:a14eaa2e1445

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tecnosys 0:a14eaa2e1445 1 /*
tecnosys 0:a14eaa2e1445 2 Copyright (c) 2010 Peter Barrett
tecnosys 0:a14eaa2e1445 3
tecnosys 0:a14eaa2e1445 4 Permission is hereby granted, free of charge, to any person obtaining a copy
tecnosys 0:a14eaa2e1445 5 of this software and associated documentation files (the "Software"), to deal
tecnosys 0:a14eaa2e1445 6 in the Software without restriction, including without limitation the rights
tecnosys 0:a14eaa2e1445 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
tecnosys 0:a14eaa2e1445 8 copies of the Software, and to permit persons to whom the Software is
tecnosys 0:a14eaa2e1445 9 furnished to do so, subject to the following conditions:
tecnosys 0:a14eaa2e1445 10
tecnosys 0:a14eaa2e1445 11 The above copyright notice and this permission notice shall be included in
tecnosys 0:a14eaa2e1445 12 all copies or substantial portions of the Software.
tecnosys 0:a14eaa2e1445 13
tecnosys 0:a14eaa2e1445 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
tecnosys 0:a14eaa2e1445 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
tecnosys 0:a14eaa2e1445 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
tecnosys 0:a14eaa2e1445 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
tecnosys 0:a14eaa2e1445 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
tecnosys 0:a14eaa2e1445 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
tecnosys 0:a14eaa2e1445 20 THE SOFTWARE.
tecnosys 0:a14eaa2e1445 21 */
tecnosys 0:a14eaa2e1445 22
tecnosys 0:a14eaa2e1445 23 #ifndef SOCKET_H_INCLUDED
tecnosys 0:a14eaa2e1445 24 #define SOCKET_H_INCLUDED
tecnosys 0:a14eaa2e1445 25
tecnosys 0:a14eaa2e1445 26 #define SOCKET_HCI 1
tecnosys 0:a14eaa2e1445 27 #define SOCKET_L2CAP 2
tecnosys 0:a14eaa2e1445 28 #define SOCKET_RFCOM 3
tecnosys 0:a14eaa2e1445 29
tecnosys 0:a14eaa2e1445 30 typedef struct
tecnosys 0:a14eaa2e1445 31 {
tecnosys 0:a14eaa2e1445 32 u8 AddressSpecific[0]; // BDADDR,psm etc
tecnosys 0:a14eaa2e1445 33 } SocketAddrHdr;
tecnosys 0:a14eaa2e1445 34
tecnosys 0:a14eaa2e1445 35 enum SocketState
tecnosys 0:a14eaa2e1445 36 {
tecnosys 0:a14eaa2e1445 37 SocketState_Unknown,
tecnosys 0:a14eaa2e1445 38 SocketState_Opening,
tecnosys 0:a14eaa2e1445 39 SocketState_Open,
tecnosys 0:a14eaa2e1445 40 SocketState_Closing,
tecnosys 0:a14eaa2e1445 41 SocketState_Closed
tecnosys 0:a14eaa2e1445 42 };
tecnosys 0:a14eaa2e1445 43
tecnosys 0:a14eaa2e1445 44 typedef void (*SocketCallback)(int socket, SocketState state, const u8* data, int len, void* userData);
tecnosys 0:a14eaa2e1445 45
tecnosys 0:a14eaa2e1445 46 int Socket_Open(int type, SocketAddrHdr* addr, SocketCallback callback, void* userData); // Open a socket
tecnosys 0:a14eaa2e1445 47 int Socket_Send(int socket, const u8* data, int len);
tecnosys 0:a14eaa2e1445 48 int Socket_State(int socket);
tecnosys 0:a14eaa2e1445 49 int Socket_Close(int socket);
tecnosys 0:a14eaa2e1445 50
tecnosys 0:a14eaa2e1445 51 //===========================================================================
tecnosys 0:a14eaa2e1445 52 //===========================================================================
tecnosys 0:a14eaa2e1445 53 // Don't need to look at or use anything below this line:
tecnosys 0:a14eaa2e1445 54 // Internal representation of socket
tecnosys 0:a14eaa2e1445 55
tecnosys 0:a14eaa2e1445 56 class SocketHandler;
tecnosys 0:a14eaa2e1445 57 class SocketInternal
tecnosys 0:a14eaa2e1445 58 {
tecnosys 0:a14eaa2e1445 59 public:
tecnosys 0:a14eaa2e1445 60
tecnosys 0:a14eaa2e1445 61 u8 ID;
tecnosys 0:a14eaa2e1445 62 u8 State;
tecnosys 0:a14eaa2e1445 63 u8 Type;
tecnosys 0:a14eaa2e1445 64 u8 B0;
tecnosys 0:a14eaa2e1445 65 SocketCallback Callback;
tecnosys 0:a14eaa2e1445 66 void* userData;
tecnosys 0:a14eaa2e1445 67 u8 Data[0]; // Extra socket data starts here
tecnosys 0:a14eaa2e1445 68
tecnosys 0:a14eaa2e1445 69 void Recv(const u8* data, int len)
tecnosys 0:a14eaa2e1445 70 {
tecnosys 0:a14eaa2e1445 71 Callback(ID,(SocketState)State,data,len,userData);
tecnosys 0:a14eaa2e1445 72 }
tecnosys 0:a14eaa2e1445 73
tecnosys 0:a14eaa2e1445 74 void SetState(SocketState state)
tecnosys 0:a14eaa2e1445 75 {
tecnosys 0:a14eaa2e1445 76 State = state;
tecnosys 0:a14eaa2e1445 77 Callback(ID,(SocketState)State,0,0,userData);
tecnosys 0:a14eaa2e1445 78 }
tecnosys 0:a14eaa2e1445 79 };
tecnosys 0:a14eaa2e1445 80
tecnosys 0:a14eaa2e1445 81 class SocketHandler
tecnosys 0:a14eaa2e1445 82 {
tecnosys 0:a14eaa2e1445 83 public:
tecnosys 0:a14eaa2e1445 84 virtual int Open(SocketInternal* sock, SocketAddrHdr* addr) = 0;
tecnosys 0:a14eaa2e1445 85 virtual int Send(SocketInternal* sock, const u8* data, int len) = 0;
tecnosys 0:a14eaa2e1445 86 virtual int Close(SocketInternal* sock) = 0;
tecnosys 0:a14eaa2e1445 87 };
tecnosys 0:a14eaa2e1445 88
tecnosys 0:a14eaa2e1445 89 int RegisterSocketHandler(int type, SocketHandler* handler);
tecnosys 0:a14eaa2e1445 90 SocketInternal* GetSocketInternal(int socket);
tecnosys 0:a14eaa2e1445 91
tecnosys 0:a14eaa2e1445 92 #define ERR_SOCKET_TYPE_NOT_FOUND -200
tecnosys 0:a14eaa2e1445 93 #define ERR_SOCKET_NOT_FOUND -201
tecnosys 0:a14eaa2e1445 94 #define ERR_SOCKET_NONE_LEFT -202
tecnosys 0:a14eaa2e1445 95
tecnosys 0:a14eaa2e1445 96 #endif // SOCKET_H_INCLUDED