Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
OpenBCI_32bit_Library.h
00001 /* 00002 insert header here 00003 00004 */ 00005 #ifndef _____OpenBCI_32bit__ 00006 #define _____OpenBCI_32bit__ 00007 00008 00009 //#include <DSPI.h> // MBED: not needed 00010 //#include <Arduino.h> // MBED: not needed 00011 #include "PlatformDefs.h" // MBED: arduino hardware emulation 00012 #include "Definitions.h" 00013 00014 void __USER_ISR ADS_DRDY_Service(void); 00015 class OpenBCI_32bit_Library { 00016 00017 public: 00018 00019 // Start up functions 00020 OpenBCI_32bit_Library(); 00021 boolean accelHasNewData(void); 00022 void accelUpdateAxisData(void); 00023 void accelWriteAxisData(void); 00024 void begin(void); 00025 void beginDebug(void); 00026 boolean beginSecondarySerial(void); 00027 char getCharSerial0(void); 00028 char getCharSerial1(void); 00029 boolean hasDataSerial0(void); 00030 boolean hasDataSerial1(void); 00031 00032 00033 void writeSerial(char *data, int len); 00034 00035 boolean isADSDataAvailable(void); 00036 00037 00038 00039 void writeTimeCurrent(void); 00040 void writeZeroAux(void); 00041 void activateAllChannelsToTestCondition(byte testInputCode, byte amplitudeCode, byte freqCode); 00042 00043 void channelSettingsArraySetForAll(void); 00044 void channelSettingsArraySetForChannel(byte N); 00045 void channelSettingsSetForChannel(byte channelNumber, byte powerDown, byte gain, byte inputType, byte bias, byte srb2, byte srb1); 00046 00047 void leadOffConfigureSignalForAll(byte amplitudeCode, byte freqCode); 00048 void leadOffConfigureSignalForTargetSS(byte targetSS, byte amplitudeCode, byte freqCode); 00049 00050 void leadOffSetForAllChannels(void); 00051 void leadOffSetForChannel(byte channelNumber, byte pInput, byte nInput); 00052 00053 boolean processChar(char character); 00054 void processIncomingBoardMode(char character); 00055 void processIncomingChannelSettings(char character); 00056 void processIncomingLeadOffSettings(char character); 00057 00058 void resetChannelSettingsArrayToDefault(byte channelSettingsArray[][OPENBCI_NUMBER_OF_CHANNEL_SETTINGS]); 00059 void resetLeadOffArrayToDefault(byte leadOffArray[][OPENBCI_NUMBER_OF_LEAD_OFF_SETTINGS]); 00060 00061 void sendChannelDataWithAccel(void); 00062 void sendChannelDataWithRawAux(void); 00063 void sendChannelDataWithTimeAndAccel(void); 00064 void sendChannelDataWithTimeAndRawAux(void); 00065 00066 void streamSafeChannelDeactivate(byte channelNumber); 00067 void streamSafeChannelActivate(byte channelNumber); 00068 void streamSafeChannelSettingsForChannel(byte channelNumber, byte powerDown, byte gain, byte inputType, byte bias, byte srb2, byte srb1); 00069 void streamSafeSetAllChannelsToDefault(void); 00070 void streamSafeReportAllChannelDefaults(void); 00071 void streamSafeLeadOffSetForChannel(byte channelNumber, byte pInput, byte nInput); 00072 void streamSafeTimeSendSyncSetPacket(void); 00073 void streamStart(void); 00074 void streamStop(void); 00075 00076 // OLD CODE REVERT 00077 void writeChannelSettings(); 00078 void writeChannelSettings(byte N); 00079 void changeChannelLeadOffDetect(); 00080 void changeChannelLeadOffDetect(byte N); 00081 void configureLeadOffDetection(byte amplitudeCode, byte freqCode); 00082 00083 boolean waitForNewChannelData(void); 00084 00085 // Variables 00086 boolean daisy; 00087 boolean sniffMode; 00088 boolean streaming; 00089 boolean timeSynced; 00090 boolean sendTimeSyncUpPacket; 00091 boolean isProcessingIncomingSettingsChannel; 00092 boolean isProcessingIncomingSettingsLeadOff; 00093 boolean settingBoardMode; 00094 volatile boolean channelDataAvailable; 00095 00096 boolean isProcessingMultibyteMsg(void); 00097 boolean isValidBoardType(char c); 00098 00099 uint8_t curBoardMode; 00100 00101 int numberOfIncomingSettingsProcessedChannel; 00102 int numberOfIncomingSettingsProcessedLeadOff; 00103 char streamPacketType; 00104 char currentChannelSetting; 00105 00106 // Getters 00107 char getChannelCommandForAsciiChar(char asciiChar); 00108 char getConstrainedChannelNumber(byte channelNumber); 00109 byte getDefaultChannelSettingForSetting(byte setting); 00110 char getDefaultChannelSettingForSettingAscii(byte setting); 00111 char getGainForAsciiChar(char asciiChar); 00112 char getNumberForAsciiChar(char asciiChar); 00113 char getTargetSSForConstrainedChannelNumber(byte channelNumber); 00114 char getYesOrNoForAsciiChar(char asciiChar); 00115 00116 DSPI0 spi; // use DSPI library 00117 00118 // BOARD 00119 boolean useAccel; 00120 boolean useAux; 00121 void initialize(void); 00122 void initializeVariables(void); 00123 void printAllRegisters(void); 00124 void sendChannelData(void); // send the current data with sample number 00125 00126 00127 // ADS1299 00128 void initialize_ads(void); 00129 void setChannelsToDefault(void); 00130 void reportDefaultChannelSettings(void); 00131 void printADSregisters(int); 00132 void WAKEUP(int); // get out of low power mode 00133 void STANDBY(int); // go into low power mode 00134 void RESET(int); // set all register values to default 00135 void START(int); // start data acquisition 00136 void STOP(int); // stop data acquisition 00137 void RDATAC(int); // go into read data continuous mode 00138 void SDATAC(int); // get out of read data continuous mode 00139 void RDATA(int); // read data one-shot 00140 byte RREG(byte,int); // read one ADS register 00141 void RREGS(byte,byte,int); // read multiple ADS registers 00142 void WREG(byte,byte,int); // write one ADS register 00143 void WREGS(byte,byte,int); // write multiple ADS registers 00144 byte ADS_getDeviceID(int); 00145 void printRegisterName(byte); // used for verbosity 00146 void printHex(byte); // used for verbosity 00147 void updateChannelData(void); // retrieve data from ADS 00148 void updateBoardData(void); 00149 void updateDaisyData(void); 00150 byte xfer(byte); // SPI Transfer function 00151 void resetADS(int); // reset all the ADS1299's settings 00152 void startADS(void); 00153 void stopADS(void); 00154 void activateChannel(byte); // enable the selected channel 00155 void deactivateChannel(byte); // disable given channel 1-8(16) 00156 void configureInternalTestSignal(byte,byte); 00157 00158 void changeInputType(byte); 00159 00160 void ADS_writeChannelData(void); 00161 // void ADS_printDeviceID(int); // 00162 boolean smellDaisy(void); 00163 void removeDaisy(void); 00164 void attachDaisy(void); 00165 void writeAuxData(void); 00166 00167 short auxData[3]; // This is user faceing 00168 byte regData[24]; // array is used to mirror register data 00169 byte lastBoardDataRaw[24]; 00170 byte boardChannelDataRaw[24]; // array to hold raw channel data 00171 byte meanBoardDataRaw[24]; 00172 byte lastDaisyDataRaw[24]; 00173 byte daisyChannelDataRaw[24]; 00174 byte meanDaisyDataRaw[24]; 00175 int boardStat; // used to hold the status register 00176 int daisyStat; 00177 int boardChannelDataInt[8]; // array used when reading channel data as ints 00178 int lastBoardChannelDataInt[8]; 00179 int meanBoardChannelDataInt[8]; 00180 int daisyChannelDataInt[8]; // array used when reading channel data as ints 00181 int lastDaisyChannelDataInt[8]; 00182 int meanDaisyChannelDataInt[8]; 00183 int numChannels; 00184 byte channelSettings[OPENBCI_NUMBER_OF_CHANNELS_DAISY][OPENBCI_NUMBER_OF_CHANNEL_SETTINGS]; // array to hold current channel settings 00185 byte defaultChannelSettings[OPENBCI_NUMBER_OF_CHANNEL_SETTINGS]; // default channel settings 00186 byte leadOffSettings[OPENBCI_NUMBER_OF_CHANNELS_DAISY][OPENBCI_NUMBER_OF_LEAD_OFF_SETTINGS]; // used to control on/off of impedance measure for P and N side of each channel 00187 boolean useInBias[OPENBCI_NUMBER_OF_CHANNELS_DAISY]; // used to remember if we were included in Bias before channel power down 00188 boolean useSRB2[OPENBCI_NUMBER_OF_CHANNELS_DAISY]; 00189 boolean boardUseSRB1; // used to keep track of if we are using SRB1 00190 boolean daisyUseSRB1; 00191 boolean verbosity; // turn on/off Serial verbosity 00192 boolean daisyPresent; 00193 boolean firstDataPacket; 00194 byte sampleCounter; 00195 00196 // LIS3DH 00197 short axisData[3]; 00198 void initialize_accel(byte); // initialize 00199 void enable_accel(byte); // start acceleromoeter with default settings 00200 void disable_accel(void); // stop data acquisition and go into low power mode 00201 byte LIS3DH_getDeviceID(void); 00202 byte LIS3DH_read(byte); // read a register on LIS3DH 00203 void LIS3DH_write(byte,byte); // write a register on LIS3DH 00204 int LIS3DH_read16(byte); // read two bytes, used to get axis data 00205 int getX(void); 00206 int getY(void); 00207 int getZ(void); 00208 boolean LIS3DH_DataReady(void); // check LIS3DH_DRDY pin 00209 boolean LIS3DH_DataAvailable(void); // check LIS3DH STATUS_REG2 00210 void LIS3DH_readAllRegs(void); 00211 void LIS3DH_writeAxisData(void); 00212 void LIS3DH_writeAxisDataForAxis(uint8_t axis); 00213 void LIS3DH_updateAxisData(void); 00214 00215 void csLow(int); 00216 void csHigh(int); 00217 00218 // 00219 boolean boardBegin(void); 00220 boolean boardBeginDebug(void); 00221 boolean boardBeginDebug(int); 00222 void boardReset(void); 00223 void ledFlash(int numberOfFlashes); 00224 void sendEOT(void); 00225 00226 char buffer[1]; 00227 00228 // ADS1299 00229 boolean isRunning; 00230 // LIS3DH 00231 int DRDYpinValue; 00232 int lastDRDYpinValue; 00233 00234 // Time sync Variables 00235 unsigned long timeOffset; 00236 unsigned long timeSetCharArrived; 00237 unsigned long timeComputer; 00238 unsigned long timeCurrent; 00239 // Time sync Methods 00240 // unsigned long timeGet(void); 00241 // void timeSet(char character); 00242 void timeSendSyncSetPacket(void); 00243 00244 }; 00245 00246 // This let's us call into the class from within the library if necessary 00247 extern OpenBCI_32bit_Library board; 00248 00249 #endif
Generated on Wed Jul 20 2022 12:01:51 by
1.7.2