initial commit, reads dev id
Revision 0:77ee0ceb503a, committed 2018-08-10
- Comitter:
- phonemacro
- Date:
- Fri Aug 10 04:54:06 2018 +0000
- Child:
- 1:7ae9b934ee55
- Commit message:
- start of max86140 driver
Changed in this revision
| MAX8614X.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MAX8614X.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX8614X.cpp Fri Aug 10 04:54:06 2018 +0000
@@ -0,0 +1,96 @@
+/*******************************************************************************
+* Author: Ihsan Mert Ozcelik, Ihsan.Ozcelik@maximintegrated.com
+* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+*/
+#include "MAX8614X.h"
+
+#define pr_err(fmt, args...) if(1) printf(fmt " (%s:%d)\n", ##args, __func__, __LINE__)
+#define pr_info(fmt, args...) if(1) printf(fmt " (%s:%d)\n", ##args, __func__, __LINE__)
+#define pr_debug(fmt, args...) if(0) printf(fmt " (%s:%d)\n", ##args, __func__, __LINE__)
+
+#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
+
+MAX8614X::MAX8614X(SPI &spiBus, DigitalOut &cs, PinName pin)
+:m_spiBus(spiBus), m_cs(cs)
+{
+ m_cs = 1;
+}
+
+int MAX8614X::readRegister(uint8_t reg, uint8_t *data, int len)
+{
+ m_cs = 0;
+
+ m_spiBus.write(reg);
+ m_spiBus.write(0x80);
+
+ int i = 0;
+ for(; i < len; i++) { /*TODO: make len unsigned*/
+ data[i] = m_spiBus.write(0x00);
+ }
+
+ m_cs = 1;
+ return 0; /*TODO: handle error cases*/
+}
+
+int MAX8614X::writeRegister(uint8_t reg, const uint8_t data)
+{
+ m_cs = 0;
+
+ m_spiBus.write(reg);
+ m_spiBus.write(0x00);
+ m_spiBus.write(data);
+
+ m_cs = 1;
+
+ return 0; /*TODO: handle error cases*/
+}
+
+int MAX8614X::writeBlock(const RegisterMap reg_block[], unsigned int size)
+{
+ unsigned int i;
+ int ret = 0;
+
+ for (i = 0; i < size; i++) {
+ ret = writeRegister((Registers) reg_block[i].addr,
+ reg_block[i].val);
+ if (ret < 0) {
+ pr_err("writeRegister failed. ret: %d", ret);
+ return ret;
+ }
+ }
+
+ return ret;
+}
+MAX8614X::~MAX8614X(void)
+{
+ //empty block
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MAX8614X.h Fri Aug 10 04:54:06 2018 +0000
@@ -0,0 +1,212 @@
+/*******************************************************************************
+* Author: Ihsan Mert Ozcelik, Ihsan.Ozcelik@maximintegrated.com
+* Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated
+* Products, Inc. shall not be used except as stated in the Maxim Integrated
+* Products, Inc. Branding Policy.
+*
+* The mere transfer of this software does not imply any licenses
+* of trade secrets, proprietary technology, copyrights, patents,
+* trademarks, maskwork rights, or any other form of intellectual
+* property whatsoever. Maxim Integrated Products, Inc. retains all
+* ownership rights.
+*******************************************************************************
+*/
+
+#ifndef _MAX8614X_H_
+#define _MAX8614X_H_
+
+#include "mbed.h"
+//#include "queue.h"
+//#include "MaximSensor.h"
+
+/**
+@brief The MAX8614X
+ */
+
+/**
+@brief MAX8614X - supports MAX8614X object with SPI interface
+ */
+class MAX8614X
+{
+public:
+ /* PUBLIC CONST VARIABLES */
+
+ /* Return codes */
+ static const int8_t RTN_NO_ERROR = 0;
+ static const int8_t RTN_ERR_UNSOPPORTED_PART = -1;
+ static const int8_t RTN_ERR_WRONG_DATA_TYPE = -2;
+ static const int8_t RTN_ERR_NOT_8614x = -3;
+ static const int8_t RTN_ERR_MEM_ALLOC_FAIL = -4;
+ static const int8_t RTN_ERR_QUEUE_INIT = -5;
+ static const int8_t RTN_ERR_QUEUE_EMPTY = -6;
+
+ /* MAX8614X Registers */
+ enum Registers
+ {
+ MAX8614X_INT_STATUS1_REG = 0x00,
+ MAX8614X_INT_STATUS2_REG,
+ MAX8614X_INT_ENABLE1_REG,
+ MAX8614X_INT_ENABLE2_REG,
+ MAX8614X_FIFO_WR_PTR_REG,
+ MAX8614X_FIFO_RD_PTR_REG,
+ MAX8614X_OVF_CNT_REG,
+ MAX8614X_FIFO_DATA_CNT_REG,
+ MAX8614X_FIFO_DATA_REG,
+ MAX8614X_FIFO_CFG1_REG,
+ MAX8614X_FIFO_CFG2_REG, //0x0A
+ MAX8614X_SYSTEM_CTRL_REG = 0x0D,
+ MAX8614X_PPG_SYNC_CTRL_REG = 0x10,
+ MAX8614X_PPG_CFG1_REG,
+ MAX8614X_PPG_CFG2_REG,
+ MAX8614X_PPG_CFG3_REG,
+ MAX8614X_PROX_INT_THRES_REG,
+ MAX8614X_PHOTO_DIODE_BIAS_REG,
+ MAX8614X_FICKET_FENCE_REG, //0x16
+ MAX8614X_LED_SEQ1_REG = 0x20,
+ MAX8614X_LED_SEQ2_REG,
+ MAX8614X_LED_SEQ3_REG,
+ MAX8614X_LED1_PA_REG,
+ MAX8614X_LED2_PA_REG,
+ MAX8614X_LED3_PA_REG,
+ MAX8614X_LED4_PA_REG,
+ MAX8614X_LED5_PA_REG,
+ MAX8614X_LED6_PA_REG,
+ MAX8614X_LED_PILOT_PA_REG,
+ MAX8614X_LED_RANGE1_REG,
+ MAX8614X_LED_RANGE2_REG, //0x2B
+ MAX8614X_DIE_TEMP_CFG_REG = 0x40,
+ MAX8614X_DIE_TEMP_INT_REG,
+ MAX8614X_DIE_TEMP_FRAC_REG,
+ MAX8614X_SHA_CMD_REG = 0xF0,
+ MAX8614X_SHA_CFG_REG,
+ MAX8614X_MEMORY_CONTROL_REG,
+ MAX8614X_MEMORY_INDEX_REG,
+ MAX8614X_MEMORY_DATA_REG,
+ MAX8614X_REV_ID_REG = 0xFE,
+ MAX8614X_PART_ID_REG,
+
+ };
+
+ /*System Control*/
+ static const uint8_t MAX8614X_SYSTEM_RESET_MASK = (0x01 << 0);
+ static const uint8_t MAX8614X_SYSTEM_SHDN_MASK = (0x01 << 1);
+ static const uint8_t MAX8614X_SYSTEM_LP_BOOST = (0x01 << 2);
+
+ /* Die Temperature */
+ static const uint8_t MAX8614X_DIE_TEMP_EN = (0x1 << 0);
+ static const uint8_t MAX8614X_DIE_TEMP_FRAC_MASK = (0xF << 0);
+
+ /* Sample rates */
+ static const uint8_t MAX8614X_PPG_SR_25_SPS = (0x00 << 3);
+ static const uint8_t MAX8614X_PPG_SR_50_SPS = (0x01 << 3);
+ static const uint8_t MAX8614X_PPG_SR_84_SPS = (0x02 << 3);
+ static const uint8_t MAX8614X_PPG_SR_100_SPS = (0x03 << 3);
+ static const uint8_t MAX8614X_PPG_SR_200_SPS = (0x04 << 3);
+ static const uint8_t MAX8614X_PPG_SR_400_SPS = (0x05 << 3);
+
+ /* LED Pulse Amplitude */
+ static const uint8_t MAX8614X_LED1_RGE_MASK = (0x3 << 0);
+ static const uint8_t MAX8614X_LED2_RGE_MASK = (0x3 << 2);
+ static const uint8_t MAX8614X_LED3_RGE_MASK = (0x3 << 4);
+
+ static const uint8_t MAX8614X_LED4_RGE_MASK = (0x3 << 0);
+ static const uint8_t MAX8614X_LED5_RGE_MASK = (0x3 << 2);
+ static const uint8_t MAX8614X_LED6_RGE_MASK = (0x3 << 4);
+
+ static const uint8_t MAX8614X_LED1_RGE_25mA_MASK = (0x0 << 0);
+ static const uint8_t MAX8614X_LED1_RGE_50mA_MASK = (0x1 << 0);
+ static const uint8_t MAX8614X_LED1_RGE_75mA_MASK = (0x2 << 0);
+ static const uint8_t MAX8614X_LED1_RGE_100mA_MASK = (0x3 << 0);
+
+ static const uint8_t MAX8614X_LED2_RGE_25mA_MASK = (0x0 << 2);
+ static const uint8_t MAX8614X_LED2_RGE_50mA_MASK = (0x1 << 2);
+ static const uint8_t MAX8614X_LED2_RGE_75mA_MASK = (0x2 << 2);
+ static const uint8_t MAX8614X_LED2_RGE_100mA_MASK = (0x3 << 2);
+
+ static const uint8_t MAX8614X_LED3_RGE_25mA_MASK = (0x0 << 4);
+ static const uint8_t MAX8614X_LED3_RGE_50mA_MASK = (0x1 << 4);
+ static const uint8_t MAX8614X_LED3_RGE_75mA_MASK = (0x2 << 4);
+ static const uint8_t MAX8614X_LED3_RGE_100mA_MASK = (0x3 << 4);
+
+ /* PPG PW */
+ static const uint8_t MAX8614X_PPG_LED_PW_14_4_US_MASK = (0 << 0);
+ static const uint8_t MAX8614X_PPG_LED_PW_28_8_US_MASK = (1 << 0);
+ static const uint8_t MAX8614X_PPG_LED_PW_57_6_US_MASK = (2 << 0);
+ static const uint8_t MAX8614X_PPG_LED_PW_115_2_US_MASK = (3 << 0);
+
+ /* PPG Range */
+ static const uint8_t MAX8614X_PPG1_ADC_RGE_4096_MASK = (0 << 2);
+ static const uint8_t MAX8614X_PPG1_ADC_RGE_8192_MASK = (1 << 2);
+ static const uint8_t MAX8614X_PPG1_ADC_RGE_16384_MASK = (2 << 2);
+ static const uint8_t MAX8614X_PPG1_ADC_RGE_32768_MASK = (3 << 2);
+
+ static const uint8_t MAX8614X_PPG2_ADC_RGE_4096_MASK = (0 << 4);
+ static const uint8_t MAX8614X_PPG2_ADC_RGE_8192_MASK = (1 << 4);
+ static const uint8_t MAX8614X_PPG2_ADC_RGE_16384_MASK = (2 << 4);
+ static const uint8_t MAX8614X_PPG2_ADC_RGE_32768_MASK = (3 << 4);
+
+ /* FIFO */
+ static const uint8_t MAX8614X_FIFO_WR_PTR_MASK = (0x7F << 0);
+ static const uint8_t MAX8614X_FIFO_RD_PTR_MASK = (0x7F << 0);
+ static const uint8_t MAX8614X_OVF_CNT_MASK = (0x7F << 0);
+ static const uint8_t MAX8614X_FIFO_A_FULL_MASK = (0x7F << 0);
+ static const uint8_t MAX8614X_FIFO_EN_MASK = (0x01 << 0);
+ static const uint8_t MAX8614X_FIFO_RO_MASK = (0x01 << 1);
+ static const uint8_t MAX8614X_A_FULL_TYPE_MASK = (0x01 << 2);
+ static const uint8_t MAX8614X_A_FULL_RPT = (0x00 << 2);
+ static const uint8_t MAX8614X_A_FULL_ONCE = (0x01 << 2);
+ static const uint8_t MAX8614X_FIFO_STAT_CLR_MASK = (0x01 << 3);
+ static const uint8_t MAX8614X_FLUSH_FIFO_MASK = (0x01 << 4);
+
+ /* Status */
+ static const uint8_t MAX8614X_INT1_EN_A_FULL_MASK = (0x1 << 7);
+ static const uint8_t MAX8614X_INT1_EN_DATA_RDY_MASK = (0x1 << 6);
+ static const uint8_t MAX8614X_INT1_EN_DIE_TEMP_MASK = (0x1 << 2);
+ static const uint8_t MAX8614X_INT1_EN_VDD_OOR_MASK = (0x1 << 1);
+
+ /* PUBLIC TYPE DEFINITIONS */
+ typedef struct RegisterMap {
+ uint8_t addr;
+ uint8_t val;
+ } RegisterMap_t;
+
+ /* PUBLIC FUNCTION DECLARATIONS */
+
+ MAX8614X(SPI &spiBus, DigitalOut &cs, PinName intPin);
+ ~MAX8614X();
+
+ int readRegister(uint8_t reg, uint8_t *data, int len);
+
+ int writeRegister(uint8_t reg, const uint8_t data);
+
+ int writeBlock(const RegisterMap reg_block[], unsigned int size);
+private:
+
+ /* PRIVATE VARIABLES */
+ SPI &m_spiBus;
+ DigitalOut &m_cs;
+
+ /* PRIVATE FUNCTION DECLARATIONS */
+};
+
+#endif /* _MAX8614X_H_ */