added k60d100m project
[adk-bluetooth-test.git] / adk-stack / ADK.h
blobc10772b92a4683ab99c4f5e2201a48a6549bb322
1 /*
2 * Copyright (C) 2012 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 #ifndef _ADK_H_
17 #define _ADK_H_
19 #include <stdint.h>
20 #include "btL2CAP.h"
21 #include "btSDP.h"
22 #include "btRFCOMM.h"
24 #define NUM_LEDS 64
25 #define NUM_DIGITS 6
26 #define NUM_ICONS 8
28 #define DMA_CHANNEL_LEDS 0 //we use channel 0. you want it? sucks to be you! get an IDE that supports a reasonable build system!
30 typedef void (*adkPutcharF)(char c);
32 typedef char (*adkBtConnectionRequestF)(const uint8_t* mac, uint32_t devClass, uint8_t linkType); //return 1 to accept
33 typedef char (*adkBtLinkKeyRequestF)(const uint8_t* mac, uint8_t* buf); //retrieve link key, fill buffer with it, return 1. if no key -> return 0
34 typedef void (*adkBtLinkKeyCreatedF)(const uint8_t* mac, const uint8_t* buf); //link key was just created, save it if you want it later
35 typedef char (*adkBtPinRequestF)(const uint8_t* mac, uint8_t* buf); //fill buff with PIN code, return num bytes used (16 max) return 0 to decline
36 typedef char (*adkBtDiscoveryResultF)(const uint8_t* mac, uint8_t PSRM, uint8_t PSPM, uint8_t PSM, uint16_t CO, uint32_t devClass); //return 0 to stop scan immediately
37 typedef void (*adkBtSspDisplayF)(const uint8_t* mac, uint32_t val);
39 #define ADK_BT_SSP_DONE_VAL 0x0FF00000
41 #define BLUETOOTH_MAC_SIZE 6 //bytes
42 #define BLUETOOTH_LINK_KEY_SIZE 16 //bytes
43 #define BLUETOOTH_MAX_PIN_SIZE 16 //bytes
44 #define BLUETOOTH_MAX_NAME_LEN 248 //bytes
45 #define ADK_UNIQUE_ID_LEN 4 //4 32-bit values
47 /* keep in sync with Audio.h */
48 #define AUDIO_NULL 0
49 #define AUDIO_USB 1
50 #define AUDIO_BT 2
51 #define AUDIO_ALARM 3
53 #define AUDIO_MAX_SOURCE 3
55 /* --- structure(s) and types reference ---
57 typedef struct{
59 uint8_t flags;
61 void* (*serviceInstanceAllocate)(uint16_t conn, uint16_t chan, uint16_t remChan);
62 void (*serviceInstanceFree)(void* service);
64 void (*serviceRx)(void* service, const uint8_t* data, uint16_t size);
66 }L2capService;
69 typedef void (*BtRfcommPortOpenF)(void* port, uint8_t dlci);
70 typedef void (*BtRfcommPortCloseF)(void* port, uint8_t dlci);
71 typedef void (*BtRfcommPortRxF)(void* port, uint8_t dlci, const uint8_t* buf, uint16_t sz);
76 struct FatFile;
77 struct FatDir;
78 typedef struct FatFile* FatFileP;
79 typedef struct FatDir* FatDirP;
80 #define FATFS_READ 1
81 #define FATFS_WRITE 2
82 #define FATFS_CREATE 4
83 #define FATFS_TRUNCATE 8
85 #define FATFS_START 0
86 #define FATFS_CUR 1
87 #define FATFS_END 2
89 typedef struct{
91 uint32_t fsize;
92 uint8_t attrib;
93 char name[13]; //short name
94 char* longName; //you make this point somewhere
95 uint32_t nameSz;
97 }FatFileInfo;
101 //generic
102 void ADK_adkInit(void);
103 void ADK_adkDeinit(void);
104 void ADK_adkSetPutchar(adkPutcharF f);
105 void ADK_adkEventProcess(void); //call this often
106 void ADK_getUniqueId(uint32_t* id);
107 uint64_t ADK_getUptime(void); //in ms
109 //LEDS
110 //raw LED write
111 void ADK_ledWrite(uint8_t led_id, uint8_t r, uint8_t g, uint8_t b);
112 //draw an icon
113 void ADK_ledDrawIcon(uint8_t icon, uint8_t r, uint8_t g, uint8_t b);
114 //draw a letter
115 void ADK_ledDrawLetter(char letter, uint8_t val, uint8_t r, uint8_t g, uint8_t b);
116 //flush the backbuffer to the display (call often)
117 void ADK_ledUpdate(void);
118 //on-board debug led
119 void ADK_ledDbgState(char on);
121 //RAW Audio
122 void ADK_audioOn(int source, uint32_t samplerate);
123 void ADK_audioOff(int source);
124 void ADK_audioAddBuffer(int source, const uint16_t* samples, uint32_t numSamples); //if buffers full, will block until they arent...
125 int ADK_audioTryAddBuffer(int source, const uint16_t* samples, uint32_t numSamples); //0 if failed
127 //OGG Audio
128 void ADK_playOgg(const char* path);
129 void ADK_playOggBackground(const char* path, char *complete, char *abort);
130 void ADK_setVolume(uint8_t vol);
131 uint8_t ADK_getVolume(void);
133 //BT
134 void ADK_btEnable(adkBtConnectionRequestF crF, adkBtLinkKeyRequestF krF, adkBtLinkKeyCreatedF kcF, adkBtPinRequestF prF, adkBtDiscoveryResultF drF);
135 char ADK_btSetLocalName(const char* name);
136 char ADK_btGetRemoteName(const uint8_t* mac, uint8_t PSRM, uint8_t PSM, uint16_t co, char* nameBuf);
137 void ADK_btScan(void);
138 char ADK_btDiscoverable(char on);
139 char ADK_btConnectable(char on);
140 char ADK_btSetDeviceClass(uint32_t cls);
142 //advanced BT
143 //ACL
144 void ADK_l2capServiceTx(uint16_t conn, uint16_t remChan, const uint8_t* data, uint32_t size); //send data over L2CAP
145 void ADK_l2capServiceCloseConn(uint16_t conn, uint16_t chan);
146 char ADK_l2capServiceRegister(uint16_t PSM, const L2capService* svcData);
147 char ADK_l2capServiceUnregister(uint16_t PSM);
149 //SDP
150 void ADK_btSdpServiceDescriptorAdd(const uint8_t* descriptor, uint16_t descrLen); //a copy will NOT be made do not include handle
151 void ADK_btSdpServiceDescriptorDel(const uint8_t* descriptor);
153 //RFCOMM
154 void ADK_btRfcommRegisterPort(uint8_t dlci, BtRfcommPortOpenF oF, BtRfcommPortCloseF cF, BtRfcommPortRxF rF);
155 void ADK_btRfcommPortTx(void* port, uint8_t dlci, const uint8_t* data, uint16_t size); //makes a copy of your buffer
156 uint8_t ADK_btRfcommReserveDlci(uint8_t preference); //return dlci if success, zero if fail
157 void ADK_btRfcommReleaseDlci(uint8_t dlci);
159 //SSP
160 void ADK_btSetSspCallback(adkBtSspDisplayF pdF);
163 //Sensors
164 char ADK_hygroRead(int32_t *temp, int32_t *humidity); //return 0 on failure
165 void ADK_baroRead(uint8_t oss, long* kPa, long* decicelcius);
166 uint8_t ADK_capSenseSlider(void);
167 uint16_t ADK_capSenseButtons(void);
168 uint16_t ADK_capSenseIcons(void);
169 void ADK_capSenseDump(void);
170 void ADK_alsRead(uint16_t* prox, uint16_t* clear, uint16_t* R, uint16_t* G, uint16_t* B, uint16_t* IR, uint16_t* temp);
171 void ADK_accelRead(int16_t* x, int16_t* y, int16_t* z);
172 void ADK_magRead(int16_t* x, int16_t* y, int16_t* z);
174 //RTC
175 void ADK_rtcGet(uint16_t* yearP, uint8_t* monthP, uint8_t* dayP, uint8_t* hourP, uint8_t* minuteP, uint8_t* secondP);
176 void ADK_rtcSet(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);
178 //FATFS (retrn 0 on success)
179 char ADK_fatfsMount(void); // Mount/Unmount a logical drive
180 char ADK_fatfsOpen(struct FatFile**, const char* path, uint8_t mode); // Open or create a file
181 char ADK_fatfsRead(struct FatFile*, void* buf, uint32_t num, uint32_t* numDone); // Read data from a file
182 char ADK_fatfsWrite(struct FatFile*, void* buf, uint32_t num, uint32_t* numDone); // Write data to a file
183 char ADK_fatfsSeek(struct FatFile*, uint8_t whence, int32_t pos); // Move file pointer of a file object
184 char ADK_fatfsClose(struct FatFile*); // Close an open file object
185 char ADK_fatfsTruncate(struct FatFile*); // Truncate file
186 char ADK_fatfsSync(struct FatFile*); // Flush cached data of a writing file
188 char ADK_fatfsOpenDir(struct FatDir**, const char* path); // Open an existing directory
189 char ADK_fatfsReadDir(struct FatDir*, FatFileInfo*); // Read a directory item
190 char ADK_fatfsCloseDir(struct FatDir*); // Close a directory
192 char ADK_fatfsStat(const char* path, FatFileInfo*); // Get file status
193 char ADK_fatfsGetFree(const char* path, uint64_t* freeSize); // Get number of free space on the drive
194 char ADK_fatfsUnlink(const char* path); // Delete an existing file or directory
195 char ADK_fatfsMkdir(const char* path); // Create a new directory
196 char ADK_fatfsChmod(const char* path, uint8_t val, uint8_t mask); // Change attributes of the file/dir
197 char ADK_fatfsRename(const char* path, const char* newPath); // Rename/Move a file or directory
198 char ADK_fatfsMkfs(void); // Create a file system on the drive
200 //USB
201 void ADK_usbStart(void);
202 void ADK_usbSetAccessoryStringVendor(const char *str);
203 void ADK_usbSetAccessoryStringName(const char *str);
204 void ADK_usbSetAccessoryStringLongname(const char *str);
205 void ADK_usbSetAccessoryStringVersion(const char *str);
206 void ADK_usbSetAccessoryStringUrl(const char *str);
207 void ADK_usbSetAccessoryStringSerial(const char *str);
209 //USB accessory
210 int ADK_accessoryConnected(void);
211 int ADK_accessorySend(const void *buf, unsigned int len);
212 int ADK_accessoryReceive(void *buf, unsigned int len);
216 #endif