![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
UCLA CSM119 "How to Approach New Hardware Demo"
main.cpp
- Committer:
- xihan94
- Date:
- 2018-05-30
- Revision:
- 0:33686dd26bf9
- Child:
- 1:ad1b075585bc
File content as of revision 0:33686dd26bf9:
#include "mbed.h" #include "mbed_events.h" #include "MAX30101.h" #define FIFO_DATA_MAX 288 DigitalOut pwr1v8(PTA29); DigitalOut pwr3v3b(PTB12); I2C i2c0(PTB1, PTB0); InterruptIn maximInterrupt(PTB18); Serial pc(USBTX, USBRX); EventQueue evqueue(32 * EVENTS_EVENT_SIZE); Thread t; MAX30101 hr(i2c0); void interruptHandlerQueued() { MAX30101::InterruptBitField_u interruptStatus; hr.getInterruptStatus(interruptStatus); printf("Interrupt Status: 0x%02x\r\n", interruptStatus.all); if (interruptStatus.bits.pwr_rdy == 0x1) { printf("Powered on\r\n"); // Configure FIFO MAX30101::FIFO_Configuration_u fifoConf; hr.getFIFOConfiguration(fifoConf); pc.printf("FIFO Configuration: 0x%02x\r\n", fifoConf.all); // Set LED power hr.setLEDPulseAmplitude(MAX30101::LED1_PA, 0xFF); pc.printf("LED set\r\n"); MAX30101::SpO2Configuration_u spo2Conf; hr.getSpO2Configuration(spo2Conf); pc.printf("SpO2 Configuration: 0x%02x\r\n", spo2Conf.all); // Enable HR mode MAX30101::ModeConfiguration_u modeConf; modeConf.all = 0; modeConf.bits.mode = MAX30101::HeartRateMode; hr.setModeConfiguration(modeConf); printf("Mode set\r\n"); } if (interruptStatus.bits.ppg_rdy == 0x1) { printf("PPG Ready.\r\n"); maximInterrupt.disable_irq(); while (true) { hr.getInterruptStatus(interruptStatus); printf("Interrupt Status: 0x%02x\r\n", interruptStatus.all); if (interruptStatus.bits.ppg_rdy == 0x1) { uint8_t byte; hr.readRegister(MAX30101::FIFO_DataRegister, byte); printf("Read byte: %hhu\r\n", byte); hr.readRegister(MAX30101::FIFO_DataRegister, byte); printf("Read byte: %hhu\r\n", byte); hr.readRegister(MAX30101::FIFO_DataRegister, byte); printf("Read byte: %hhu\r\n", byte); } } } if (interruptStatus.bits.a_full == 0x1) { printf("FIFO Almost Full.\r\n"); // uint8_t data[FIFO_DATA_MAX]; // uint16_t readBytes = 0; // hr.readFIFO(MAX30101::OneLedChannel, data, readBytes); // printf("FIFO has %hu bytes of data\r\n", readBytes); // // for (uint16_t i = 0; i < readBytes; i += 3) { // uint8_t sample[4] = {0}; // memcpy(sample, data + i, 3); // printf("Read data: %u\r\n", *(uint32_t *) sample); // } } interruptStatus.all = 0xFF; hr.enableInterrupts(interruptStatus); } void interruptHandler() { evqueue.call(interruptHandlerQueued); } // main() runs in its own thread in the OS int main() { printf("Hello world.\r\n"); t.start(callback(&evqueue, &EventQueue::dispatch_forever)); pwr1v8 = 1; pwr3v3b = 1; maximInterrupt.fall(interruptHandler); maximInterrupt.enable_irq(); MAX30101::InterruptBitField_u interruptStatus; interruptStatus.all = 0xFF; hr.enableInterrupts(interruptStatus); // MAX30101::FIFO_Configuration_u fifoConf; // hr.getFIFOConfiguration(fifoConf); // pc.printf("FIFO Configuration: 0x%02x\r\n", fifoConf.all); // // MAX30101::ModeConfiguration_u modeConf; // hr.getModeConfiguration(modeConf); // pc.printf("Mode Configuration: 0x%02x\r\n", modeConf.all); // // while (true) { // wait(1); // printf("%d\r\n", maximInterrupt.read()); // } return 0; }