Alex Borisevich / Mbed 2 deprecated OpenBCI

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Definitions.h Source File

Definitions.h

00001 //
00002 //  Definitions_32.h
00003 //
00004 //
00005 //  Created by Conor Russomanno, Luke Travis, and Joel Murphy. Summer 2013.
00006 //  Modified by Joel Murphy, Summer 2014
00007 //  Joel Added Daisy Functionality Fall 2014
00008 //
00009 
00010 #ifndef _____OpenBCI_32bit_Library_Definitions_h
00011 #define _____OpenBCI_32bit_Library_Definitions_h
00012 
00013 // The default baud rate
00014 #define OPENBCI_BAUD_RATE 115200
00015 
00016 // File transmissions
00017 #define OPENBCI_BOP 'A' // Begining of stream packet
00018 #define OPENBCI_EOP_STND_ACCEL          0xC0 // End of standard stream packet
00019 #define OPENBCI_EOP_STND_RAW_AUX        0xC1 // End of stream packet with raw packet
00020 #define OPENBCI_EOP_USER_DEFINED        0xC2 // End of stream packet, user defined
00021 #define OPENBCI_EOP_ACCEL_TIME_SET      0xC3 // End of time sync up with accel stream packet
00022 #define OPENBCI_EOP_ACCEL_TIME_SYNCED   0xC4 // End of time synced stream packet
00023 #define OPENBCI_EOP_RAW_AUX_TIME_SET    0xC5 // End of time sync up stream packet
00024 #define OPENBCI_EOP_RAW_AUX_TIME_SYNCED 0xC6 // End of time synced stream packet
00025 
00026 //PIN CONNECTIONS
00027 /*
00028 // MBED: pin definitions are in PlatformDefs.h
00029 #define ADS_DRDY        9   // ADS data ready pin
00030 #define ADS_RST         4   // ADS reset pin
00031 #define BOARD_ADS       8   // ADS chip select
00032 #define DAISY_ADS       3   // ADS Daisy chip select
00033 #define BOTH_ADS        5   // Slave Select Both ADS chips
00034 #define SD_SS           2   // SD card chip select
00035 #define LIS3DH_SS       1   // LIS3DH chip select
00036 #define LIS3DH_DRDY     0   // LIS3DH data ready pin
00037 #define OPENBCI_PIN_LED 11
00038 #define OPENBCI_PIN_PGC 12
00039 */
00040 #define BOTH_ADS        5   // Slave Select Both ADS chips
00041 
00042 //ADS1299 SPI Command Definition Byte Assignments
00043 #define _WAKEUP 0x02 // Wake-up from standby mode
00044 #define _STANDBY 0x04 // Enter Standby mode
00045 #define _RESET 0x06 // Reset the device registers to default
00046 #define _START 0x08 // Start and restart (synchronize) conversions
00047 #define _STOP 0x0A // Stop conversion
00048 #define _RDATAC 0x10 // Enable Read Data Continuous mode (default mode at power-up)
00049 #define _SDATAC 0x11 // Stop Read Data Continuous mode
00050 #define _RDATA 0x12 // Read data by command supports multiple read back
00051 
00052 //ASD1299 Register Addresses
00053 #define ADS_ID  0x3E    // product ID for ADS1299
00054 #define ID_REG  0x00    // this register contains ADS_ID
00055 #define CONFIG1 0x01
00056 #define CONFIG2 0x02
00057 #define CONFIG3 0x03
00058 #define LOFF 0x04
00059 #define CH1SET 0x05
00060 #define CH2SET 0x06
00061 #define CH3SET 0x07
00062 #define CH4SET 0x08
00063 #define CH5SET 0x09
00064 #define CH6SET 0x0A
00065 #define CH7SET 0x0B
00066 #define CH8SET 0x0C
00067 #define BIAS_SENSP 0x0D
00068 #define BIAS_SENSN 0x0E
00069 #define LOFF_SENSP 0x0F
00070 #define LOFF_SENSN 0x10
00071 #define LOFF_FLIP 0x11
00072 #define LOFF_STATP 0x12
00073 #define LOFF_STATN 0x13
00074 //#define GPIO 0x14  // MBED: interfere with STM32 library
00075 static const int GPIO = 0x14;
00076 #define MISC1 0x15
00077 #define MISC2 0x16
00078 #define CONFIG4 0x17
00079 
00080 #define OUTPUT_NOTHING (0)  // quiet
00081 #define OUTPUT_8_CHAN (1)   // not using Daisy module
00082 #define OUTPUT_16_CHAN (2)  // using Daisy module
00083 #define ON_BOARD    (BOARD_ADS)           // slave address for on board ADS
00084 #define ON_DAISY    (DAISY_ADS)             // slave address for daisy ADS
00085 // CHANNEL SETTINGS 
00086 #define POWER_DOWN      (0)
00087 #define GAIN_SET        (1)
00088 #define INPUT_TYPE_SET  (2)
00089 #define BIAS_SET        (3)
00090 #define SRB2_SET        (4)
00091 #define SRB1_SET        (5)
00092 #define YES         (0x01)
00093 #define NO          (0x00)
00094 
00095 //gainCode choices
00096 #define ADS_GAIN01 (0b00000000) // 0x00
00097 #define ADS_GAIN02 (0b00010000) // 0x10
00098 #define ADS_GAIN04 (0b00100000) // 0x20
00099 #define ADS_GAIN06 (0b00110000) // 0x30
00100 #define ADS_GAIN08 (0b01000000) // 0x40
00101 #define ADS_GAIN12 (0b01010000) // 0x50
00102 #define ADS_GAIN24 (0b01100000) // 0x60
00103 
00104 //inputType choices
00105 #define ADSINPUT_NORMAL     (0b00000000)
00106 #define ADSINPUT_SHORTED    (0b00000001)
00107 #define ADSINPUT_BIAS_MEAS  (0b00000010)
00108 #define ADSINPUT_MVDD       (0b00000011)
00109 #define ADSINPUT_TEMP       (0b00000100)
00110 #define ADSINPUT_TESTSIG    (0b00000101)
00111 #define ADSINPUT_BIAS_DRP   (0b00000110)
00112 #define ADSINPUT_BIAL_DRN   (0b00000111)
00113 
00114 //test signal choices...ADS1299 datasheet page 41
00115 #define ADSTESTSIG_AMP_1X (0b00000000)
00116 #define ADSTESTSIG_AMP_2X (0b00000100)
00117 #define ADSTESTSIG_PULSE_SLOW (0b00000000)
00118 #define ADSTESTSIG_PULSE_FAST (0b00000001)
00119 #define ADSTESTSIG_DCSIG (0b00000011)
00120 #define ADSTESTSIG_NOCHANGE (0b11111111)
00121 
00122 //Lead-off signal choices
00123 #define LOFF_MAG_6NA        (0b00000000)
00124 #define LOFF_MAG_24NA       (0b00000100)
00125 #define LOFF_MAG_6UA        (0b00001000)
00126 #define LOFF_MAG_24UA       (0b00001100)
00127 #define LOFF_FREQ_DC        (0b00000000)
00128 #define LOFF_FREQ_7p8HZ     (0b00000001)
00129 #define LOFF_FREQ_31p2HZ    (0b00000010)
00130 #define LOFF_FREQ_FS_4      (0b00000011)
00131 #define PCHAN (0)
00132 #define NCHAN (1)
00133 #define OFF (0)
00134 #define ON (1)
00135 
00136 // used for channel settings
00137 #define ACTIVATE_SHORTED (2)
00138 #define ACTIVATE (1)
00139 #define DEACTIVATE (0)
00140 
00141 #define PCKT_START 0xA0 // prefix for data packet error checking
00142 #define PCKT_END 0xC0   // postfix for data packet error checking
00143 
00144 // daisy module
00145 #define CLK_EN  5
00146 
00147 //LIS3DH
00148 //#define READ_REG      0x80 // MBED: interfere with STM32 library
00149 static const int READ_REG = 0x80; 
00150 
00151 #define READ_MULTI      0x40
00152 
00153 #define STATUS_REG_AUX  0x07    // axis over-run and data available flags (see 0x27)
00154 #define OUT_ADC1_L      0x08    //
00155 #define OUT_ADC1_H      0x09    //
00156 #define OUT_ADC2_L      0x0A    //  ADC input values (check DS)
00157 #define OUT_ADC2_H      0x0B    //
00158 #define OUT_ADC3_L      0x0C    //
00159 #define OUT_ADC3_H      0x0D    //
00160 #define INT_COUNTER_REG 0x0E    // ??
00161 #define WHO_AM_I        0x0F    // DEVICE ID 0x33
00162 #define TMP_CFG_REG     0x1F    // ADC enable (0x80) Temperature sensor enable (0x40)
00163 #define CTRL_REG1       0x20    // Data Rate Power Mode X enable Y enable Z enable (on >0x10)
00164 #define CTRL_REG2       0x21    // High Pass Filter Stuph
00165 #define CTRL_REG3       0x22    // INT1 select register
00166 #define CTRL_REG4       0x23    // Block update timing endian G-force resolution self test SPI pins
00167 #define CTRL_REG5       0x24    // reboot FIFO enable latch 4D detection
00168 #define CTRL_REG6       0x25    // ??
00169 #define REFERENCE       0x26    // interrupt reference
00170 #define STATUS_REG2     0x27    // axis overrun and availale flags (see 0x07)
00171 #define OUT_X_L         0x28    //
00172 #define OUT_X_H         0x29    //
00173 #define OUT_Y_L         0x2A    //  tripple axis values (see 0x0A)
00174 #define OUT_Y_H         0x2B    //
00175 #define OUT_Z_L         0x2C    //
00176 #define OUT_Z_H         0x2D    //
00177 #define FIFO_CTRL_REG   0x2E    // FIFO mode trigger output pin select (?)
00178 #define FIFO_SRC_REG    0x2F    // ??
00179 #define INT1_CFG        0x30    // 6 degree control register
00180 #define INT1_SOURCE     0x31    // axis threshold interrupt control
00181 #define INT1_THS        0x32    // INT1 threshold
00182 #define INT1_DURATION   0x33    // INT1 duration
00183 #define CLICK_CFG       0x38    // click on axis
00184 #define CLICK_SRC       0x39    // other click
00185 #define CLICK_THS       0x3A    // more click
00186 #define TIME_LIMIT      0x3B    // click related
00187 #define TIME_LATENCY    0x3C    // and so on
00188 #define TIME_WINDOW     0x3D    // contined click
00189 
00190 #define SCALE_2G        0x00  //(b00000000) // +/- 2G sensitivity
00191 #define SCALE_4G        0x10  //(b00010000) // +/- 4G sensitivity
00192 #define SCALE_8G        0x20  //(b00100000) // +/- 8G sensitivity
00193 #define SCALE_16G       0x30  //(b00110000) // +/- 16G sensitivity
00194 #define RATE_1HZ        0x10  //(b00010000) // 1Hz sample rate in normal or low-power mode
00195 #define RATE_10HZ       0x20  //(b00100000) // 10Hz sample rate in normal or low-power mode
00196 #define RATE_25HZ       0x30  //(b00110000) // 25Hz sample rate in normal or low-power mode
00197 #define RATE_50HZ       0x40  //(b01000000) // 50Hz sample rate in normal or low-power mode
00198 #define RATE_100HZ      0x50  //(b01010000) // 100Hz sample rate in normal or low-power mode
00199 #define RATE_200HZ      0x60  //(b01100000) // 200Hz sample rate in normal or low-power mode
00200 #define RATE_400HZ      0x70  //(b01110000) // 400Hz sample rate in normal or low-power mode
00201 #define RATE_1600HZ_LP  0x80  //(b10000000) // 1600Hz sample rate in low-power mode
00202 #define RATE_1250HZ_N   0x90  //(b10010000) // 1250Hz sample rate in normal mode
00203 #define RATE_5000HZ_LP  0x90  //(b10010000) // 5000Hz sample rate in low-power mode
00204 #define ACCEL_AXIS_X    0x07 // x axis
00205 #define ACCEL_AXIS_Y    0x08 // y axis
00206 #define ACCEL_AXIS_Z    0x09 // z axis
00207 
00208 // OPENBCI_COMMANDS
00209 /** Turning channels off */
00210 #define OPENBCI_CHANNEL_OFF_1 '1'
00211 #define OPENBCI_CHANNEL_OFF_2 '2'
00212 #define OPENBCI_CHANNEL_OFF_3 '3'
00213 #define OPENBCI_CHANNEL_OFF_4 '4'
00214 #define OPENBCI_CHANNEL_OFF_5 '5'
00215 #define OPENBCI_CHANNEL_OFF_6 '6'
00216 #define OPENBCI_CHANNEL_OFF_7 '7'
00217 #define OPENBCI_CHANNEL_OFF_8 '8'
00218 #define OPENBCI_CHANNEL_OFF_9 'q'
00219 #define OPENBCI_CHANNEL_OFF_10 'w'
00220 #define OPENBCI_CHANNEL_OFF_11 'e'
00221 #define OPENBCI_CHANNEL_OFF_12 'r'
00222 #define OPENBCI_CHANNEL_OFF_13 't'
00223 #define OPENBCI_CHANNEL_OFF_14 'y'
00224 #define OPENBCI_CHANNEL_OFF_15 'u'
00225 #define OPENBCI_CHANNEL_OFF_16 'i'
00226 
00227 /** Turn channels on */
00228 #define OPENBCI_CHANNEL_ON_1 '!'
00229 #define OPENBCI_CHANNEL_ON_2 '@'
00230 #define OPENBCI_CHANNEL_ON_3 '#'
00231 #define OPENBCI_CHANNEL_ON_4 '$'
00232 #define OPENBCI_CHANNEL_ON_5 '%'
00233 #define OPENBCI_CHANNEL_ON_6 '^'
00234 #define OPENBCI_CHANNEL_ON_7 '&'
00235 #define OPENBCI_CHANNEL_ON_8 '*'
00236 #define OPENBCI_CHANNEL_ON_9 'Q'
00237 #define OPENBCI_CHANNEL_ON_10 'W'
00238 #define OPENBCI_CHANNEL_ON_11 'E'
00239 #define OPENBCI_CHANNEL_ON_12 'R'
00240 #define OPENBCI_CHANNEL_ON_13 'T'
00241 #define OPENBCI_CHANNEL_ON_14 'Y'
00242 #define OPENBCI_CHANNEL_ON_15 'U'
00243 #define OPENBCI_CHANNEL_ON_16 'I'
00244 
00245 /** Test Signal Control Commands
00246  * 1x - Voltage will be 1 * (VREFP - VREFN) / 2.4 mV
00247  * 2x - Voltage will be 2 * (VREFP - VREFN) / 2.4 mV
00248  */
00249 #define OPENBCI_TEST_SIGNAL_CONNECT_TO_DC            'p'
00250 #define OPENBCI_TEST_SIGNAL_CONNECT_TO_GROUND        '0'
00251 #define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_1X_FAST '='
00252 #define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_1X_SLOW '-'
00253 #define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_2X_FAST ']'
00254 #define OPENBCI_TEST_SIGNAL_CONNECT_TO_PULSE_2X_SLOW '['
00255 
00256 /** Channel Setting Commands */
00257 #define OPENBCI_CHANNEL_CMD_ADC_Normal      '0'
00258 #define OPENBCI_CHANNEL_CMD_ADC_Shorted     '1'
00259 #define OPENBCI_CHANNEL_CMD_ADC_BiasDRP     '6'
00260 #define OPENBCI_CHANNEL_CMD_ADC_BiasDRN     '7'
00261 #define OPENBCI_CHANNEL_CMD_ADC_BiasMethod  '2'
00262 #define OPENBCI_CHANNEL_CMD_ADC_MVDD        '3'
00263 #define OPENBCI_CHANNEL_CMD_ADC_Temp        '4'
00264 #define OPENBCI_CHANNEL_CMD_ADC_TestSig     '5'
00265 #define OPENBCI_CHANNEL_CMD_BIAS_INCLUDE    '1'
00266 #define OPENBCI_CHANNEL_CMD_BIAS_REMOVE     '0'
00267 #define OPENBCI_CHANNEL_CMD_CHANNEL_1       '1'
00268 #define OPENBCI_CHANNEL_CMD_CHANNEL_2       '2'
00269 #define OPENBCI_CHANNEL_CMD_CHANNEL_3       '3'
00270 #define OPENBCI_CHANNEL_CMD_CHANNEL_4       '4'
00271 #define OPENBCI_CHANNEL_CMD_CHANNEL_5       '5'
00272 #define OPENBCI_CHANNEL_CMD_CHANNEL_6       '6'
00273 #define OPENBCI_CHANNEL_CMD_CHANNEL_7       '7'
00274 #define OPENBCI_CHANNEL_CMD_CHANNEL_8       '8'
00275 #define OPENBCI_CHANNEL_CMD_CHANNEL_9       'Q'
00276 #define OPENBCI_CHANNEL_CMD_CHANNEL_10      'W'
00277 #define OPENBCI_CHANNEL_CMD_CHANNEL_11      'E'
00278 #define OPENBCI_CHANNEL_CMD_CHANNEL_12      'R'
00279 #define OPENBCI_CHANNEL_CMD_CHANNEL_13      'T'
00280 #define OPENBCI_CHANNEL_CMD_CHANNEL_14      'Y'
00281 #define OPENBCI_CHANNEL_CMD_CHANNEL_15      'U'
00282 #define OPENBCI_CHANNEL_CMD_CHANNEL_16      'I'
00283 #define OPENBCI_CHANNEL_CMD_GAIN_1          '0'
00284 #define OPENBCI_CHANNEL_CMD_GAIN_2          '1'
00285 #define OPENBCI_CHANNEL_CMD_GAIN_4          '2'
00286 #define OPENBCI_CHANNEL_CMD_GAIN_6          '3'
00287 #define OPENBCI_CHANNEL_CMD_GAIN_8          '4'
00288 #define OPENBCI_CHANNEL_CMD_GAIN_12         '5'
00289 #define OPENBCI_CHANNEL_CMD_GAIN_24         '6'
00290 #define OPENBCI_CHANNEL_CMD_LATCH           'X'
00291 #define OPENBCI_CHANNEL_CMD_POWER_OFF       '1'
00292 #define OPENBCI_CHANNEL_CMD_POWER_ON        '0'
00293 #define OPENBCI_CHANNEL_CMD_SET             'x'
00294 #define OPENBCI_CHANNEL_CMD_SRB1_CONNECT    '1'
00295 #define OPENBCI_CHANNEL_CMD_SRB1_DISCONNECT '0'
00296 #define OPENBCI_CHANNEL_CMD_SRB2_CONNECT    '1'
00297 #define OPENBCI_CHANNEL_CMD_SRB2_DISCONNECT '0'
00298 
00299 /** Default Channel Settings */
00300 #define OPENBCI_CHANNEL_DEFAULT_ALL_SET 'd'
00301 #define OPENBCI_CHANNEL_DEFAULT_ALL_REPORT 'D'
00302 
00303 /** LeadOff Impedance Commands */
00304 #define OPENBCI_CHANNEL_IMPEDANCE_LATCH                'Z'
00305 #define OPENBCI_CHANNEL_IMPEDANCE_SET                  'z'
00306 #define OPENBCI_CHANNEL_IMPEDANCE_TEST_SIGNAL_APPLIED    '1'
00307 #define OPENBCI_CHANNEL_IMPEDANCE_TEST_SIGNAL_APPLIED_NOT '0'
00308 
00309 /** SD card Commands */
00310 #define OPENBCI_SD_LOG_FOR_HOUR_1    'G'
00311 #define OPENBCI_SD_LOG_FOR_HOUR_2    'H'
00312 #define OPENBCI_SD_LOG_FOR_HOUR_4    'J'
00313 #define OPENBCI_SD_LOG_FOR_HOUR_12   'K'
00314 #define OPENBCI_SD_LOG_FOR_HOUR_24   'L'
00315 #define OPENBCI_SD_LOG_FOR_MIN_5     'A'
00316 #define OPENBCI_SD_LOG_FOR_MIN_15    'S'
00317 #define OPENBCI_SD_LOG_FOR_MIN_30    'F'
00318 #define OPENBCI_SD_LOG_FOR_SEC_14    'a'
00319 #define OPENBCI_SD_LOG_STOP        'j'
00320 
00321 /** Stream Data Commands */
00322 #define OPENBCI_STREAM_START  'b'
00323 #define OPENBCI_STREAM_STOP   's'
00324 
00325 /** Miscellaneous */
00326 #define OPENBCI_MISC_QUERY_REGISTER_SETTINGS '?'
00327 #define OPENBCI_MISC_SOFT_RESET              'v'
00328 
00329 /** 16 Channel Commands */
00330 #define OPENBCI_CHANNEL_MAX_NUMBER_8    'c'
00331 #define OPENBCI_CHANNEL_MAX_NUMBER_16   'C'
00332 
00333 /** Set Packet Type */
00334 #define OPENBCI_BOARD_MODE_SET '/'
00335 #define OPENBCI_BOARD_MODE_DEFAULT '0'
00336 #define OPENBCI_BOARD_MODE_DEBUG '1'
00337 #define OPENBCI_BOARD_MODE_WIFI '2'
00338 #define OPENBCI_BOARD_MODE_INPUT_ANALOG '3'
00339 #define OPENBCI_BOARD_MODE_INPUT_DIGITAL '4'
00340 
00341 /** Sync Clocks */
00342 #define OPENBCI_TIME_SET '<'
00343 #define OPENBCI_TIME_STOP '>'
00344 
00345 /** Possible number of channels */
00346 #define OPENBCI_NUMBER_OF_CHANNELS_DAISY 16
00347 #define OPENBCI_NUMBER_OF_CHANNELS_DEFAULT 8
00348 
00349 /** Helpful numbers */
00350 #define OPENBCI_NUMBER_OF_BOARD_SETTINGS 1
00351 #define OPENBCI_NUMBER_OF_CHANNEL_SETTINGS 6
00352 #define OPENBCI_NUMBER_OF_LEAD_OFF_SETTINGS 2
00353 
00354 /** Possible Sample Rates*/
00355 #define OPENBCI_SAMPLE_RATE_125 125
00356 #define OPENBCI_SAMPLE_RATE_250 250
00357 
00358 /** Packet Size */
00359 #define OPENBCI_PACKET_SIZE 33
00360 
00361 /** Impedance Calculation Variables */
00362 #define OPENBCI_LEAD_OFF_DRIVE_AMPS 0.000000006
00363 #define OPENBCI_LEAD_OFF_FREQUENCY_HZ 31
00364 
00365 /** Raw data packet types/codes */
00366 #define OPENBCI_PACKET_TYPE_V3              0 // 0000
00367 #define OPENBCI_PACKET_TYPE_TIME_SYNCED     1 // 0001
00368 #define OPENBCI_PACKET_TYPE_TIME_SET        2 // 0010
00369 #define OPENBCI_PACKET_TYPE_USER_DEFINED    3 // 0011
00370 #define OPENBCI_PACKET_TYPE_RAW_AUX         4 // 0100
00371 
00372 #define OPENBCI_TIME_OUT_MS_1 1
00373 #define OPENBCI_TIME_OUT_MS_3 3
00374 
00375 #define OPENBCI_NUMBER_OF_BYTES_SETTINGS_CHANNEL 9
00376 #define OPENBCI_NUMBER_OF_BYTES_SETTINGS_LEAD_OFF 5
00377 
00378 #define OPENBCI_NUMBER_OF_BYTES_AUX 6
00379 
00380 #define OPENBCI_FIRMWARE_VERSION_V1 1
00381 #define OPENBCI_FIRMWARE_VERSION_V2 1
00382 
00383 #endif