forked from OpenBCI/OpenBCI_Cyton_Library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpenBCI_32bit_Library_Definitions.h
396 lines (347 loc) · 13.6 KB
/
OpenBCI_32bit_Library_Definitions.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
//
// Definitions_32.h
//
//
// Created by Conor Russomanno, Luke Travis, and Joel Murphy. Summer 2013.
// Modified by Joel Murphy, Summer 2014
// Joel Added Daisy Functionality Fall 2014
//
#ifndef _____OpenBCI_32bit_Library_Definitions_h
#define _____OpenBCI_32bit_Library_Definitions_h
// Baud rates
#define OPENBCI_BAUD_RATE 115200
#define OPENBCI_BAUD_RATE_BLE 9600
#define OPENBCI_BAUD_RATE_MIN_NO_AVG 200000
// File transmissions
#define OPENBCI_BOP 'A' // Begining of stream packet
//PIN CONNECTIONS
#define ADS_DRDY 9 // ADS data ready pin
#define ADS_RST 4 // ADS reset pin
#define BOARD_ADS 8 // ADS chip select
#define DAISY_ADS 3 // ADS Daisy chip select
#define BOTH_ADS 5 // Slave Select Both ADS chips
#define SD_SS 2 // SD card chip select
#define LIS3DH_SS 1 // LIS3DH chip select
#define LIS3DH_DRDY 0 // LIS3DH data ready pin
// #define WIFI_SS 13 // Wifi Chip Select
#define OPENBCI_PIN_LED 11
#define OPENBCI_PIN_PGC 12
// #define WIFI_RESET 18
#define OPENBCI_PIN_SERIAL1_TX 11
#define OPENBCI_PIN_SERIAL1_RX 12
//ADS1299 SPI Command Definition Byte Assignments
#define _WAKEUP 0x02 // Wake-up from standby mode
#define _STANDBY 0x04 // Enter Standby mode
#define _RESET 0x06 // Reset the device registers to default
#define _START 0x08 // Start and restart (synchronize) conversions
#define _STOP 0x0A // Stop conversion
#define _RDATAC 0x10 // Enable Read Data Continuous mode (default mode at power-up)
#define _SDATAC 0x11 // Stop Read Data Continuous mode
#define _RDATA 0x12 // Read data by command supports multiple read back
//ASD1299 Register Addresses
#define ADS_ID 0x3E // product ID for ADS1299
#define ID_REG 0x00 // this register contains ADS_ID
#define CONFIG1 0x01
#define CONFIG2 0x02
#define CONFIG3 0x03
#define LOFF 0x04
#define CH1SET 0x05
#define CH2SET 0x06
#define CH3SET 0x07
#define CH4SET 0x08
#define CH5SET 0x09
#define CH6SET 0x0A
#define CH7SET 0x0B
#define CH8SET 0x0C
#define BIAS_SENSP 0x0D
#define BIAS_SENSN 0x0E
#define LOFF_SENSP 0x0F
#define LOFF_SENSN 0x10
#define LOFF_FLIP 0x11
#define LOFF_STATP 0x12
#define LOFF_STATN 0x13
#define GPIO 0x14
#define MISC1 0x15
#define MISC2 0x16
#define CONFIG4 0x17
#define OUTPUT_NOTHING (0) // quiet
#define OUTPUT_8_CHAN (1) // not using Daisy module
#define OUTPUT_16_CHAN (2) // using Daisy module
#define ON_BOARD (8) // slave address for on board ADS
#define ON_DAISY (3) // slave address for daisy ADS
// CHANNEL SETTINGS
#define POWER_DOWN (0)
#define GAIN_SET (1)
#define INPUT_TYPE_SET (2)
#define BIAS_SET (3)
#define SRB2_SET (4)
#define SRB1_SET (5)
#define YES (0x01)
#define NO (0x00)
//gainCode choices
#define ADS_GAIN01 (0b00000000) // 0x00
#define ADS_GAIN02 (0b00010000) // 0x10
#define ADS_GAIN04 (0b00100000) // 0x20
#define ADS_GAIN06 (0b00110000) // 0x30
#define ADS_GAIN08 (0b01000000) // 0x40
#define ADS_GAIN12 (0b01010000) // 0x50
#define ADS_GAIN24 (0b01100000) // 0x60
//inputType choices
#define ADSINPUT_NORMAL (0b00000000)
#define ADSINPUT_SHORTED (0b00000001)
#define ADSINPUT_BIAS_MEAS (0b00000010)
#define ADSINPUT_MVDD (0b00000011)
#define ADSINPUT_TEMP (0b00000100)
#define ADSINPUT_TESTSIG (0b00000101)
#define ADSINPUT_BIAS_DRP (0b00000110)
#define ADSINPUT_BIAL_DRN (0b00000111)
//test signal choices...ADS1299 datasheet page 41
#define ADSTESTSIG_AMP_1X (0b00000000)
#define ADSTESTSIG_AMP_2X (0b00000100)
#define ADSTESTSIG_PULSE_SLOW (0b00000000)
#define ADSTESTSIG_PULSE_FAST (0b00000001)
#define ADSTESTSIG_DCSIG (0b00000011)
#define ADSTESTSIG_NOCHANGE (0b11111111)
#define ADS1299_CONFIG1_DAISY (0b10110000)
#define ADS1299_CONFIG1_DAISY_NOT (0b10010000)
//Lead-off signal choices
#define LOFF_MAG_6NA (0b00000000)
#define LOFF_MAG_24NA (0b00000100)
#define LOFF_MAG_6UA (0b00001000)
#define LOFF_MAG_24UA (0b00001100)
#define LOFF_FREQ_DC (0b00000000)
#define LOFF_FREQ_7p8HZ (0b00000001)
#define LOFF_FREQ_31p2HZ (0b00000010)
#define LOFF_FREQ_FS_4 (0b00000011)
#define PCHAN (0)
#define NCHAN (1)
#define OFF (0)
#define ON (1)
// used for channel settings
#define ACTIVATE_SHORTED (2)
#define ACTIVATE (1)
#define DEACTIVATE (0)
#define PCKT_START 0xA0 // prefix for data packet error checking
#define PCKT_END 0xC0 // postfix for data packet error checking
// daisy module
#define CLK_EN 5
//LIS3DH
#define READ_REG 0x80
#define READ_MULTI 0x40
#define STATUS_REG_AUX 0x07 // axis over-run and data available flags (see 0x27)
#define OUT_ADC1_L 0x08 //
#define OUT_ADC1_H 0x09 //
#define OUT_ADC2_L 0x0A // ADC input values (check DS)
#define OUT_ADC2_H 0x0B //
#define OUT_ADC3_L 0x0C //
#define OUT_ADC3_H 0x0D //
#define INT_COUNTER_REG 0x0E // ??
#define WHO_AM_I 0x0F // DEVICE ID 0x33
#define TMP_CFG_REG 0x1F // ADC enable (0x80) Temperature sensor enable (0x40)
#define CTRL_REG1 0x20 // Data Rate Power Mode X enable Y enable Z enable (on >0x10)
#define CTRL_REG2 0x21 // High Pass Filter Stuph
#define CTRL_REG3 0x22 // INT1 select register
#define CTRL_REG4 0x23 // Block update timing endian G-force resolution self test SPI pins
#define CTRL_REG5 0x24 // reboot FIFO enable latch 4D detection
#define CTRL_REG6 0x25 // ??
#define REFERENCE 0x26 // interrupt reference
#define STATUS_REG2 0x27 // axis overrun and availale flags (see 0x07)
#define OUT_X_L 0x28 //
#define OUT_X_H 0x29 //
#define OUT_Y_L 0x2A // tripple axis values (see 0x0A)
#define OUT_Y_H 0x2B //
#define OUT_Z_L 0x2C //
#define OUT_Z_H 0x2D //
#define FIFO_CTRL_REG 0x2E // FIFO mode trigger output pin select (?)
#define FIFO_SRC_REG 0x2F // ??
#define INT1_CFG 0x30 // 6 degree control register
#define INT1_SOURCE 0x31 // axis threshold interrupt control
#define INT1_THS 0x32 // INT1 threshold
#define INT1_DURATION 0x33 // INT1 duration
#define CLICK_CFG 0x38 // click on axis
#define CLICK_SRC 0x39 // other click
#define CLICK_THS 0x3A // more click
#define TIME_LIMIT 0x3B // click related
#define TIME_LATENCY 0x3C // and so on
#define TIME_WINDOW 0x3D // contined click
#define SCALE_2G 0x00 //(b00000000) // +/- 2G sensitivity
#define SCALE_4G 0x10 //(b00010000) // +/- 4G sensitivity
#define SCALE_8G 0x20 //(b00100000) // +/- 8G sensitivity
#define SCALE_16G 0x30 //(b00110000) // +/- 16G sensitivity
#define RATE_1HZ 0x10 //(b00010000) // 1Hz sample rate in normal or low-power mode
#define RATE_10HZ 0x20 //(b00100000) // 10Hz sample rate in normal or low-power mode
#define RATE_25HZ 0x30 //(b00110000) // 25Hz sample rate in normal or low-power mode
#define RATE_50HZ 0x40 //(b01000000) // 50Hz sample rate in normal or low-power mode
#define RATE_100HZ 0x50 //(b01010000) // 100Hz sample rate in normal or low-power mode
#define RATE_200HZ 0x60 //(b01100000) // 200Hz sample rate in normal or low-power mode
#define RATE_400HZ 0x70 //(b01110000) // 400Hz sample rate in normal or low-power mode
#define RATE_1600HZ_LP 0x80 //(b10000000) // 1600Hz sample rate in low-power mode
#define RATE_1250HZ_N 0x90 //(b10010000) // 1250Hz sample rate in normal mode
#define RATE_5000HZ_LP 0x90 //(b10010000) // 5000Hz sample rate in low-power mode
#define ACCEL_AXIS_X 0x07 // x axis
#define ACCEL_AXIS_Y 0x08 // y axis
#define ACCEL_AXIS_Z 0x09 // z axis
// OPENBCI_COMMANDS
/** Turning channels off */
#define OPENBCI_CHANNEL_OFF_1 '1'
#define OPENBCI_CHANNEL_OFF_2 '2'
#define OPENBCI_CHANNEL_OFF_3 '3'
#define OPENBCI_CHANNEL_OFF_4 '4'
#define OPENBCI_CHANNEL_OFF_5 '5'
#define OPENBCI_CHANNEL_OFF_6 '6'
#define OPENBCI_CHANNEL_OFF_7 '7'
#define OPENBCI_CHANNEL_OFF_8 '8'
#define OPENBCI_CHANNEL_OFF_9 'q'
#define OPENBCI_CHANNEL_OFF_10 'w'
#define OPENBCI_CHANNEL_OFF_11 'e'
#define OPENBCI_CHANNEL_OFF_12 'r'
#define OPENBCI_CHANNEL_OFF_13 't'
#define OPENBCI_CHANNEL_OFF_14 'y'
#define OPENBCI_CHANNEL_OFF_15 'u'
#define OPENBCI_CHANNEL_OFF_16 'i'
/** Turn channels on */
#define OPENBCI_CHANNEL_ON_1 '!'
#define OPENBCI_CHANNEL_ON_2 '@'
#define OPENBCI_CHANNEL_ON_3 '#'
#define OPENBCI_CHANNEL_ON_4 '$'
#define OPENBCI_CHANNEL_ON_5 '%'
#define OPENBCI_CHANNEL_ON_6 '^'
#define OPENBCI_CHANNEL_ON_7 '&'
#define OPENBCI_CHANNEL_ON_8 '*'
#define OPENBCI_CHANNEL_ON_9 'Q'
#define OPENBCI_CHANNEL_ON_10 'W'
#define OPENBCI_CHANNEL_ON_11 'E'
#define OPENBCI_CHANNEL_ON_12 'R'
#define OPENBCI_CHANNEL_ON_13 'T'
#define OPENBCI_CHANNEL_ON_14 'Y'
#define OPENBCI_CHANNEL_ON_15 'U'
#define OPENBCI_CHANNEL_ON_16 'I'
/** Test Signal Control Commands
* 1x - Voltage will be 1 * (VREFP - VREFN) / 2.4 mV
* 2x - Voltage will be 2 * (VREFP - VREFN) / 2.4 mV
*/
#define OPENBCI_TEST_SIGNAL_CONNECT_TO_DC 'p'
#define OPENBCI_TEST_SIGNAL_CONNECT_TO_GROUND '0'
#define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_1X_FAST '='
#define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_1X_SLOW '-'
#define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_2X_FAST ']'
#define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_2X_SLOW '['
/** Channel Setting Commands */
#define OPENBCI_CHANNEL_CMD_ADC_Normal '0'
#define OPENBCI_CHANNEL_CMD_ADC_Shorted '1'
#define OPENBCI_CHANNEL_CMD_ADC_BiasDRP '6'
#define OPENBCI_CHANNEL_CMD_ADC_BiasDRN '7'
#define OPENBCI_CHANNEL_CMD_ADC_BiasMethod '2'
#define OPENBCI_CHANNEL_CMD_ADC_MVDD '3'
#define OPENBCI_CHANNEL_CMD_ADC_Temp '4'
#define OPENBCI_CHANNEL_CMD_ADC_TestSig '5'
#define OPENBCI_CHANNEL_CMD_BIAS_INCLUDE '1'
#define OPENBCI_CHANNEL_CMD_BIAS_REMOVE '0'
#define OPENBCI_CHANNEL_CMD_CHANNEL_1 '1'
#define OPENBCI_CHANNEL_CMD_CHANNEL_2 '2'
#define OPENBCI_CHANNEL_CMD_CHANNEL_3 '3'
#define OPENBCI_CHANNEL_CMD_CHANNEL_4 '4'
#define OPENBCI_CHANNEL_CMD_CHANNEL_5 '5'
#define OPENBCI_CHANNEL_CMD_CHANNEL_6 '6'
#define OPENBCI_CHANNEL_CMD_CHANNEL_7 '7'
#define OPENBCI_CHANNEL_CMD_CHANNEL_8 '8'
#define OPENBCI_CHANNEL_CMD_CHANNEL_9 'Q'
#define OPENBCI_CHANNEL_CMD_CHANNEL_10 'W'
#define OPENBCI_CHANNEL_CMD_CHANNEL_11 'E'
#define OPENBCI_CHANNEL_CMD_CHANNEL_12 'R'
#define OPENBCI_CHANNEL_CMD_CHANNEL_13 'T'
#define OPENBCI_CHANNEL_CMD_CHANNEL_14 'Y'
#define OPENBCI_CHANNEL_CMD_CHANNEL_15 'U'
#define OPENBCI_CHANNEL_CMD_CHANNEL_16 'I'
#define OPENBCI_CHANNEL_CMD_GAIN_1 '0'
#define OPENBCI_CHANNEL_CMD_GAIN_2 '1'
#define OPENBCI_CHANNEL_CMD_GAIN_4 '2'
#define OPENBCI_CHANNEL_CMD_GAIN_6 '3'
#define OPENBCI_CHANNEL_CMD_GAIN_8 '4'
#define OPENBCI_CHANNEL_CMD_GAIN_12 '5'
#define OPENBCI_CHANNEL_CMD_GAIN_24 '6'
#define OPENBCI_CHANNEL_CMD_LATCH 'X'
#define OPENBCI_CHANNEL_CMD_POWER_OFF '1'
#define OPENBCI_CHANNEL_CMD_POWER_ON '0'
#define OPENBCI_CHANNEL_CMD_SET 'x'
#define OPENBCI_CHANNEL_CMD_SRB1_CONNECT '1'
#define OPENBCI_CHANNEL_CMD_SRB1_DISCONNECT '0'
#define OPENBCI_CHANNEL_CMD_SRB2_CONNECT '1'
#define OPENBCI_CHANNEL_CMD_SRB2_DISCONNECT '0'
/** Default Channel Settings */
#define OPENBCI_CHANNEL_DEFAULT_ALL_SET 'd'
#define OPENBCI_CHANNEL_DEFAULT_ALL_REPORT 'D'
/** LeadOff Impedance Commands */
#define OPENBCI_CHANNEL_IMPEDANCE_LATCH 'Z'
#define OPENBCI_CHANNEL_IMPEDANCE_SET 'z'
#define OPENBCI_CHANNEL_IMPEDANCE_TEST_SIGNAL_APPLIED '1'
#define OPENBCI_CHANNEL_IMPEDANCE_TEST_SIGNAL_APPLIED_NOT '0'
/** SD card Commands */
#define OPENBCI_SD_LOG_FOR_HOUR_1 'G'
#define OPENBCI_SD_LOG_FOR_HOUR_2 'H'
#define OPENBCI_SD_LOG_FOR_HOUR_4 'J'
#define OPENBCI_SD_LOG_FOR_HOUR_12 'K'
#define OPENBCI_SD_LOG_FOR_HOUR_24 'L'
#define OPENBCI_SD_LOG_FOR_MIN_5 'A'
#define OPENBCI_SD_LOG_FOR_MIN_15 'S'
#define OPENBCI_SD_LOG_FOR_MIN_30 'F'
#define OPENBCI_SD_LOG_FOR_SEC_14 'a'
#define OPENBCI_SD_LOG_STOP 'j'
/** Stream Data Commands */
#define OPENBCI_STREAM_START 'b'
#define OPENBCI_STREAM_STOP 's'
/** Miscellaneous */
#define OPENBCI_MISC_QUERY_REGISTER_SETTINGS '?'
#define OPENBCI_MISC_SOFT_RESET 'v'
/** 16 Channel Commands */
#define OPENBCI_CHANNEL_MAX_NUMBER_8 'c'
#define OPENBCI_CHANNEL_MAX_NUMBER_16 'C'
#define OPENBCI_BOARD_MODE_SET '/'
#define OPENBCI_GET_VERSION 'V'
/** Set sample rate */
#define OPENBCI_SAMPLE_RATE_SET '~'
/** Insert marker into the stream */
#define OPENBCI_INSERT_MARKER '`'
/** Sync Clocks */
#define OPENBCI_TIME_SET '<'
#define OPENBCI_TIME_STOP '>'
/** Wifi Stuff */
#define OPENBCI_WIFI_ATTACH '{'
#define OPENBCI_WIFI_REMOVE '}'
#define OPENBCI_WIFI_STATUS ':'
#define OPENBCI_WIFI_RESET ';'
/** Possible number of channels */
#define OPENBCI_NUMBER_OF_CHANNELS_DAISY 16
#define OPENBCI_NUMBER_OF_CHANNELS_DEFAULT 8
/** Helpful numbers */
#define OPENBCI_NUMBER_OF_BOARD_SETTINGS 1
#define OPENBCI_NUMBER_OF_CHANNEL_SETTINGS 6
#define OPENBCI_NUMBER_OF_LEAD_OFF_SETTINGS 2
/** Possible Sample Rates*/
#define OPENBCI_SAMPLE_RATE_125 125
#define OPENBCI_SAMPLE_RATE_250 250
/** Time out for multi char commands **/
#define MULTI_CHAR_COMMAND_TIMEOUT_MS 1000
/** Packet Size */
#define OPENBCI_PACKET_SIZE 33
#define OPENBCI_NUMBER_BYTES_PER_ADS_SAMPLE 24
#define OPENBCI_NUMBER_CHANNELS_PER_ADS_SAMPLE 24
/** Impedance Calculation Variables */
#define OPENBCI_LEAD_OFF_DRIVE_AMPS 0.000000006
#define OPENBCI_LEAD_OFF_FREQUENCY_HZ 31
#define OPENBCI_TIME_OUT_MS_1 1
#define OPENBCI_TIME_OUT_MS_3 3
#define OPENBCI_NUMBER_OF_BYTES_SETTINGS_CHANNEL 9
#define OPENBCI_NUMBER_OF_BYTES_SETTINGS_LEAD_OFF 5
#define OPENBCI_NUMBER_OF_BYTES_AUX 6
#define OPENBCI_FIRMWARE_VERSION_V1 1
#define OPENBCI_FIRMWARE_VERSION_V2 1
#define OPENBCI_ADS_BYTES_PER_CHAN 3
#define OPENBCI_ADS_CHANS_PER_BOARD 8
/** BLE Packet Information */
#define BLE_BYTES_PER_PACKET 20
#define BLE_BYTES_PER_SAMPLE 6
#define BLE_SAMPLES_PER_PACKET 3
#define BLE_TOTAL_DATA_BYTES 18
#define BLE_RING_BUFFER_SIZE 50
#endif