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.
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 */
53 #define AUDIO_MAX_SOURCE 3
55 /* --- structure(s) and types reference ---
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);
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);
78 typedef struct FatFile
* FatFileP
;
79 typedef struct FatDir
* FatDirP
;
82 #define FATFS_CREATE 4
83 #define FATFS_TRUNCATE 8
93 char name
[13]; //short name
94 char* longName
; //you make this point somewhere
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
111 void ADK_ledWrite(uint8_t led_id
, uint8_t r
, uint8_t g
, uint8_t b
);
113 void ADK_ledDrawIcon(uint8_t icon
, uint8_t r
, uint8_t g
, uint8_t b
);
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);
119 void ADK_ledDbgState(char on
);
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
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);
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
);
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
);
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
);
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
);
160 void ADK_btSetSspCallback(adkBtSspDisplayF pdF
);
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
);
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
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
);
210 int ADK_accessoryConnected(void);
211 int ADK_accessorySend(const void *buf
, unsigned int len
);
212 int ADK_accessoryReceive(void *buf
, unsigned int len
);