MAX1472 RF Transmitter demo code

Dependencies:   max32630fthr USBDevice

Committer:
tlyp
Date:
Fri Sep 04 18:04:36 2020 +0000
Revision:
10:d46390b7aa64
initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tlyp 10:d46390b7aa64 1 /*******************************************************************************
tlyp 10:d46390b7aa64 2 * Copyright (C) Maxim Integrated Products, Inc., All Rights Reserved.
tlyp 10:d46390b7aa64 3 *
tlyp 10:d46390b7aa64 4 * Permission is hereby granted, free of charge, to any person obtaining a
tlyp 10:d46390b7aa64 5 * copy of this software and associated documentation files (the "Software"),
tlyp 10:d46390b7aa64 6 * to deal in the Software without restriction, including without limitation
tlyp 10:d46390b7aa64 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
tlyp 10:d46390b7aa64 8 * and/or sell copies of the Software, and to permit persons to whom the
tlyp 10:d46390b7aa64 9 * Software is furnished to do so, subject to the following conditions:
tlyp 10:d46390b7aa64 10 *
tlyp 10:d46390b7aa64 11 * The above copyright notice and this permission notice shall be included
tlyp 10:d46390b7aa64 12 * in all copies or substantial portions of the Software.
tlyp 10:d46390b7aa64 13 *
tlyp 10:d46390b7aa64 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
tlyp 10:d46390b7aa64 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
tlyp 10:d46390b7aa64 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
tlyp 10:d46390b7aa64 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
tlyp 10:d46390b7aa64 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
tlyp 10:d46390b7aa64 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
tlyp 10:d46390b7aa64 20 * OTHER DEALINGS IN THE SOFTWARE.
tlyp 10:d46390b7aa64 21 *
tlyp 10:d46390b7aa64 22 * Except as contained in this notice, the name of Maxim Integrated
tlyp 10:d46390b7aa64 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
tlyp 10:d46390b7aa64 24 * Products, Inc. Branding Policy.
tlyp 10:d46390b7aa64 25 *
tlyp 10:d46390b7aa64 26 * The mere transfer of this software does not imply any licenses
tlyp 10:d46390b7aa64 27 * of trade secrets, proprietary technology, copyrights, patents,
tlyp 10:d46390b7aa64 28 * trademarks, maskwork rights, or any other form of intellectual
tlyp 10:d46390b7aa64 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
tlyp 10:d46390b7aa64 30 * ownership rights.
tlyp 10:d46390b7aa64 31 *******************************************************************************
tlyp 10:d46390b7aa64 32 */
tlyp 10:d46390b7aa64 33
tlyp 10:d46390b7aa64 34
tlyp 10:d46390b7aa64 35 #include "MAX30208.h"
tlyp 10:d46390b7aa64 36
tlyp 10:d46390b7aa64 37
tlyp 10:d46390b7aa64 38 //******************************************************************************
tlyp 10:d46390b7aa64 39 MAX30208::MAX30208(I2C &i2c, uint8_t slaveAddress):
tlyp 10:d46390b7aa64 40 m_i2c(i2c), m_writeAddress(slaveAddress << 1),
tlyp 10:d46390b7aa64 41 m_readAddress((slaveAddress << 1) | 1)
tlyp 10:d46390b7aa64 42 {
tlyp 10:d46390b7aa64 43 }
tlyp 10:d46390b7aa64 44
tlyp 10:d46390b7aa64 45
tlyp 10:d46390b7aa64 46 //******************************************************************************
tlyp 10:d46390b7aa64 47 MAX30208::~MAX30208(void) {
tlyp 10:d46390b7aa64 48 //empty block
tlyp 10:d46390b7aa64 49 }
tlyp 10:d46390b7aa64 50
tlyp 10:d46390b7aa64 51 //******************************************************************************
tlyp 10:d46390b7aa64 52 int32_t MAX30208::writeInterruptRegister(Configuration_InterruptEnable config) {
tlyp 10:d46390b7aa64 53 return(writeRegister(MAX30208::Interrupt_Enable,(config.all << 8),2));
tlyp 10:d46390b7aa64 54 }
tlyp 10:d46390b7aa64 55
tlyp 10:d46390b7aa64 56 //******************************************************************************
tlyp 10:d46390b7aa64 57 int32_t MAX30208::readInterruptRegister(Configuration_InterruptEnable &config) {
tlyp 10:d46390b7aa64 58 uint16_t data;
tlyp 10:d46390b7aa64 59 int32_t status;
tlyp 10:d46390b7aa64 60 status = readRegister(MAX30208::Interrupt_Enable, data, 1);
tlyp 10:d46390b7aa64 61 if(status == 0) {
tlyp 10:d46390b7aa64 62 config.all = data;
tlyp 10:d46390b7aa64 63 }
tlyp 10:d46390b7aa64 64 return(status);
tlyp 10:d46390b7aa64 65 }
tlyp 10:d46390b7aa64 66
tlyp 10:d46390b7aa64 67 //******************************************************************************
tlyp 10:d46390b7aa64 68 int32_t MAX30208::readStatus(uint16_t &value) {
tlyp 10:d46390b7aa64 69 return(readRegister(MAX30208::Status,value, 1));
tlyp 10:d46390b7aa64 70 }
tlyp 10:d46390b7aa64 71
tlyp 10:d46390b7aa64 72 //******************************************************************************
tlyp 10:d46390b7aa64 73 int32_t MAX30208::readWritePointer(uint16_t &value) {
tlyp 10:d46390b7aa64 74 return (readRegister(MAX30208::FIFO_Write_Pointer,value, 1));
tlyp 10:d46390b7aa64 75 }
tlyp 10:d46390b7aa64 76
tlyp 10:d46390b7aa64 77 //******************************************************************************
tlyp 10:d46390b7aa64 78 int32_t MAX30208::readReadPointer(uint16_t &value) {
tlyp 10:d46390b7aa64 79 return (readRegister(MAX30208::FIFO_Read_Pointer,value,1));
tlyp 10:d46390b7aa64 80 }
tlyp 10:d46390b7aa64 81
tlyp 10:d46390b7aa64 82 //******************************************************************************
tlyp 10:d46390b7aa64 83 int32_t MAX30208::writeReadPointer(uint8_t config) {
tlyp 10:d46390b7aa64 84 return(writeRegister(MAX30208::FIFO_Read_Pointer, (config << 8),2));
tlyp 10:d46390b7aa64 85 }
tlyp 10:d46390b7aa64 86
tlyp 10:d46390b7aa64 87 //******************************************************************************
tlyp 10:d46390b7aa64 88 int32_t MAX30208::readOverflow(uint16_t &value) {
tlyp 10:d46390b7aa64 89 return(readRegister(MAX30208::FIFO_Overflow_Counter,value, 1));
tlyp 10:d46390b7aa64 90 }
tlyp 10:d46390b7aa64 91
tlyp 10:d46390b7aa64 92 //******************************************************************************
tlyp 10:d46390b7aa64 93 int32_t MAX30208::readDataCounter(uint16_t &value) {
tlyp 10:d46390b7aa64 94 return(readRegister(MAX30208::FIFO_Data_Counter,value, 1));
tlyp 10:d46390b7aa64 95 }
tlyp 10:d46390b7aa64 96
tlyp 10:d46390b7aa64 97 //******************************************************************************
tlyp 10:d46390b7aa64 98 int32_t MAX30208::readData(uint16_t &value) {
tlyp 10:d46390b7aa64 99 return(readRegister(MAX30208::FIFO_Data,value, 2));
tlyp 10:d46390b7aa64 100 }
tlyp 10:d46390b7aa64 101
tlyp 10:d46390b7aa64 102 //******************************************************************************
tlyp 10:d46390b7aa64 103 int32_t MAX30208::takeDataMeasurment() {
tlyp 10:d46390b7aa64 104 return(writeRegister(MAX30208::Temp_Sensor_Setup,0xFF00,2));
tlyp 10:d46390b7aa64 105 }
tlyp 10:d46390b7aa64 106
tlyp 10:d46390b7aa64 107 //******************************************************************************
tlyp 10:d46390b7aa64 108 int32_t MAX30208::readFIFOConfig1(uint16_t &value) {
tlyp 10:d46390b7aa64 109 return (readRegister(MAX30208::FIFO_Config1,value, 1));
tlyp 10:d46390b7aa64 110 }
tlyp 10:d46390b7aa64 111
tlyp 10:d46390b7aa64 112 //******************************************************************************
tlyp 10:d46390b7aa64 113 int32_t MAX30208::writeFIFOConfig1(uint8_t config) {
tlyp 10:d46390b7aa64 114 return(writeRegister(MAX30208::FIFO_Config1,(config << 8),2));
tlyp 10:d46390b7aa64 115 }
tlyp 10:d46390b7aa64 116
tlyp 10:d46390b7aa64 117 //******************************************************************************
tlyp 10:d46390b7aa64 118 int32_t MAX30208::readFIFOConfig2(Configuration_FIFOConfig2 &config) {
tlyp 10:d46390b7aa64 119 uint16_t data;
tlyp 10:d46390b7aa64 120 int32_t status;
tlyp 10:d46390b7aa64 121 status = readRegister(MAX30208::FIFO_Config2, data, 1);
tlyp 10:d46390b7aa64 122 if(status == 0){
tlyp 10:d46390b7aa64 123 config.all = data;
tlyp 10:d46390b7aa64 124 }
tlyp 10:d46390b7aa64 125 return(status);
tlyp 10:d46390b7aa64 126 }
tlyp 10:d46390b7aa64 127
tlyp 10:d46390b7aa64 128 //******************************************************************************
tlyp 10:d46390b7aa64 129 int32_t MAX30208::writeFIFOConfig2(Configuration_FIFOConfig2 config) {
tlyp 10:d46390b7aa64 130 return(writeRegister(MAX30208::FIFO_Config2,(config.all << 8),2));
tlyp 10:d46390b7aa64 131 }
tlyp 10:d46390b7aa64 132
tlyp 10:d46390b7aa64 133 //******************************************************************************
tlyp 10:d46390b7aa64 134 int32_t MAX30208::resetDevice() {
tlyp 10:d46390b7aa64 135 return(writeRegister(MAX30208::System_Control,(0x01 << 8),2));
tlyp 10:d46390b7aa64 136 }
tlyp 10:d46390b7aa64 137
tlyp 10:d46390b7aa64 138 //******************************************************************************
tlyp 10:d46390b7aa64 139 int32_t MAX30208::readAlarmHigh(uint16_t &temp) {
tlyp 10:d46390b7aa64 140 return readRegister(MAX30208::Alarm_High_MSB,temp, 2);
tlyp 10:d46390b7aa64 141 }
tlyp 10:d46390b7aa64 142
tlyp 10:d46390b7aa64 143 //******************************************************************************
tlyp 10:d46390b7aa64 144 int32_t MAX30208::writeAlarmHigh(uint16_t temp) {
tlyp 10:d46390b7aa64 145 return(writeRegister(MAX30208::Alarm_High_MSB, temp, 3));
tlyp 10:d46390b7aa64 146 }
tlyp 10:d46390b7aa64 147
tlyp 10:d46390b7aa64 148 //******************************************************************************
tlyp 10:d46390b7aa64 149 int32_t MAX30208::readAlarmLow(uint16_t &value) {
tlyp 10:d46390b7aa64 150 return (readRegister(MAX30208::Alarm_Low_MSB,value, 2));
tlyp 10:d46390b7aa64 151 }
tlyp 10:d46390b7aa64 152
tlyp 10:d46390b7aa64 153 //******************************************************************************
tlyp 10:d46390b7aa64 154 int32_t MAX30208::writeAlarmLow(uint16_t temp) {
tlyp 10:d46390b7aa64 155 return(writeRegister(MAX30208::Alarm_Low_MSB,temp,3));
tlyp 10:d46390b7aa64 156 }
tlyp 10:d46390b7aa64 157
tlyp 10:d46390b7aa64 158 //******************************************************************************
tlyp 10:d46390b7aa64 159 int32_t MAX30208::readGPIOSetup(Configuration_GPIOSetup &config) {
tlyp 10:d46390b7aa64 160 uint16_t data;
tlyp 10:d46390b7aa64 161 int32_t status;
tlyp 10:d46390b7aa64 162 status = readRegister(MAX30208::GPIO_Setup, data, 1);
tlyp 10:d46390b7aa64 163 if(status == 0) {
tlyp 10:d46390b7aa64 164 config.all = data;
tlyp 10:d46390b7aa64 165 }
tlyp 10:d46390b7aa64 166 return(status);
tlyp 10:d46390b7aa64 167 }
tlyp 10:d46390b7aa64 168
tlyp 10:d46390b7aa64 169 //******************************************************************************
tlyp 10:d46390b7aa64 170 int32_t MAX30208::writeGPIOSetup(Configuration_GPIOSetup config) {
tlyp 10:d46390b7aa64 171 return(writeRegister(MAX30208::GPIO_Setup,(config.all << 8),2));
tlyp 10:d46390b7aa64 172 }
tlyp 10:d46390b7aa64 173
tlyp 10:d46390b7aa64 174 //******************************************************************************
tlyp 10:d46390b7aa64 175 int32_t MAX30208::readGPIOControl(Configuration_GPIOControl &config) {
tlyp 10:d46390b7aa64 176 uint16_t data;
tlyp 10:d46390b7aa64 177 int32_t status;
tlyp 10:d46390b7aa64 178 status = readRegister(MAX30208::GPIO_Control, data, 1);
tlyp 10:d46390b7aa64 179 if(status == 0) {
tlyp 10:d46390b7aa64 180 config.all = data;
tlyp 10:d46390b7aa64 181 }
tlyp 10:d46390b7aa64 182 return(status);
tlyp 10:d46390b7aa64 183 }
tlyp 10:d46390b7aa64 184
tlyp 10:d46390b7aa64 185 //******************************************************************************
tlyp 10:d46390b7aa64 186 int32_t MAX30208::writeGPIOControl(Configuration_GPIOControl config) {
tlyp 10:d46390b7aa64 187 return(writeRegister(MAX30208::GPIO_Control,(config.all << 8),2));
tlyp 10:d46390b7aa64 188 }
tlyp 10:d46390b7aa64 189
tlyp 10:d46390b7aa64 190 //******************************************************************************
tlyp 10:d46390b7aa64 191 float MAX30208::toCelsius(uint16_t rawTemp) {
tlyp 10:d46390b7aa64 192 float celsius;
tlyp 10:d46390b7aa64 193 celsius = 0.005*rawTemp;
tlyp 10:d46390b7aa64 194 return celsius;
tlyp 10:d46390b7aa64 195 }
tlyp 10:d46390b7aa64 196
tlyp 10:d46390b7aa64 197 //******************************************************************************
tlyp 10:d46390b7aa64 198 float MAX30208::toFahrenheit(float temperatureC) {
tlyp 10:d46390b7aa64 199 float temperatureF;
tlyp 10:d46390b7aa64 200 temperatureF = (temperatureC * 1.8F) + 32.0f;
tlyp 10:d46390b7aa64 201 return temperatureF;
tlyp 10:d46390b7aa64 202 }
tlyp 10:d46390b7aa64 203
tlyp 10:d46390b7aa64 204 //******************************************************************************
tlyp 10:d46390b7aa64 205 int32_t MAX30208::writeRegister(Registers_e reg, uint16_t value, int bytesWritten) {
tlyp 10:d46390b7aa64 206
tlyp 10:d46390b7aa64 207 int32_t ret;
tlyp 10:d46390b7aa64 208
tlyp 10:d46390b7aa64 209 uint8_t hi = ((value >> 8) & 0xFF);
tlyp 10:d46390b7aa64 210 uint8_t lo = (value & 0xFF);
tlyp 10:d46390b7aa64 211 char val[3] = {reg, hi, lo};
tlyp 10:d46390b7aa64 212
tlyp 10:d46390b7aa64 213 ret = m_i2c.write(m_writeAddress, val, bytesWritten, false);
tlyp 10:d46390b7aa64 214 return (ret);
tlyp 10:d46390b7aa64 215 }
tlyp 10:d46390b7aa64 216
tlyp 10:d46390b7aa64 217 //******************************************************************************
tlyp 10:d46390b7aa64 218 int32_t MAX30208::readRegister(Registers_e reg, uint16_t &value, int bytesRead) {
tlyp 10:d46390b7aa64 219
tlyp 10:d46390b7aa64 220 int32_t ret;
tlyp 10:d46390b7aa64 221 char cmdata[1] = {reg};
tlyp 10:d46390b7aa64 222 char dataRead[2];
tlyp 10:d46390b7aa64 223
tlyp 10:d46390b7aa64 224 ret = m_i2c.write(m_readAddress,cmdata,1,true);
tlyp 10:d46390b7aa64 225 if (ret == 0) {
tlyp 10:d46390b7aa64 226 ret = m_i2c.read(m_readAddress,dataRead,bytesRead,false);
tlyp 10:d46390b7aa64 227 if(ret == 0 && bytesRead == 2){
tlyp 10:d46390b7aa64 228 value = ((dataRead[0]<<8)+ dataRead[1]);
tlyp 10:d46390b7aa64 229 }
tlyp 10:d46390b7aa64 230 else if (ret == 0 && bytesRead == 1){
tlyp 10:d46390b7aa64 231 value = dataRead[0];
tlyp 10:d46390b7aa64 232 }
tlyp 10:d46390b7aa64 233 }
tlyp 10:d46390b7aa64 234 return(ret);
tlyp 10:d46390b7aa64 235 }