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.
MAX30205.cpp
00001 #include "mbed.h" 00002 #include "MAX30205.h" 00003 00004 /** 00005 * Internal Registers 00006 * The device contains four registers, 00007 * each of which consists of 2bytes. 00008 * The configuration register contains only 1 byte of 00009 * actual data and, when read as a 2-byte register, 00010 * repeats the same data for the second byte. 00011 */ 00012 00013 #define REG_TEMP 0x00 00014 #define REG_CONF 0x01 00015 #define REG_THYST 0x02 00016 #define REG_TOS 0x03 00017 00018 MAX30205::MAX30205(PinName sda, PinName scl, int addr): m_i2c(sda, scl), m_addr(addr<<1) 00019 { 00020 // activate the peripheral 00021 } 00022 00023 MAX30205::~MAX30205() 00024 { 00025 } 00026 00027 uint16_t MAX30205::getTemp(void) 00028 { 00029 uint16_t temp ; 00030 uint8_t data[2] ; 00031 readRegs(REG_TEMP, data, 2) ; 00032 temp = (data[0] << 8) | data[1] ; 00033 return(temp) ; 00034 } 00035 00036 uint8_t MAX30205::getConf(void) 00037 { 00038 uint8_t data[2] ; 00039 readRegs(REG_CONF, data, 2) ; 00040 return(data[0]) ; 00041 } 00042 00043 void MAX30205::setConf(uint8_t conf) 00044 { 00045 uint8_t data[3] ; 00046 data[0] = REG_CONF ; 00047 data[1] = conf ; 00048 data[2] = conf ; 00049 writeRegs(data, 3) ; 00050 } 00051 00052 uint16_t MAX30205::getThyst(void) 00053 { 00054 uint16_t thyst ; 00055 uint8_t data[2] ; 00056 readRegs(REG_THYST, data, 2) ; 00057 thyst = (data[0] << 8) | data[1] ; 00058 return(thyst) ; 00059 } 00060 00061 void MAX30205::setThyst(uint16_t thyst) 00062 { 00063 uint8_t data[3] ; 00064 data[0] = REG_THYST ; 00065 data[1] = (thyst >> 8) & 0xFF ; 00066 data[2] = thyst & 0xFF ; 00067 writeRegs(data, 3) ; 00068 } 00069 00070 uint16_t MAX30205::getTos(void) 00071 { 00072 uint16_t tos ; 00073 uint8_t data[2] ; 00074 readRegs(REG_TOS, data, 2) ; 00075 tos = (data[0] << 8) | data[1] ; 00076 return(tos) ; 00077 } 00078 00079 void MAX30205::setTos(uint16_t tos) 00080 { 00081 uint8_t data[3] ; 00082 data[0] = REG_TOS ; 00083 data[1] = (tos >> 8) & 0xFF ; 00084 data[2] = tos & 0xFF ; 00085 writeRegs(data, 3) ; 00086 } 00087 00088 void MAX30205::readRegs(int addr, uint8_t * data, int len) { 00089 char t[1] = {addr}; 00090 m_i2c.write(m_addr, t, 1, true); 00091 m_i2c.read(m_addr, (char *)data, len); 00092 } 00093 00094 void MAX30205::writeRegs(uint8_t * data, int len) { 00095 m_i2c.write(m_addr, (char *)data, len); 00096 }
Generated on Tue Jul 12 2022 15:39:19 by
1.7.2