initial commit, reads dev id
MAX8614X.h
- Committer:
- phonemacro
- Date:
- 2018-08-11
- Revision:
- 2:11e0b5b86e1e
- Parent:
- 1:7ae9b934ee55
- Child:
- 3:ad8f1059a0c5
File content as of revision 2:11e0b5b86e1e:
/*******************************************************************************
* 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);
/*SHA256 Control*/
static const uint8_t MAX8614X_IE_SHA_DONE_EN = (0x01 << 0);
static const uint8_t MAX8614X_SHACMD_SHA_START = (0x01 << 0);
static const uint8_t MAX8614X_SHACMD_SHA_EN = (0x01 << 1);
static const uint8_t MAX8614X_MEMCNTRL_BANK0_MASK = (0);
static const uint8_t MAX8614X_MEMCNTRL_BANK1_MASK = (1);
static const uint8_t MAX8614X_MEMCNTRL_WR_DIS_MASK = (0x01 << 0);
static const uint8_t MAX8614X_MEMCNTRL_WR_EN_MASK = (0x01 << 1);
/* PUBLIC TYPE DEFINITIONS */
typedef struct RegisterMap {
uint8_t addr;
uint8_t val;
} RegisterMap_t;
typedef union {
struct {
struct {
unsigned char pwr_rdy:1;
unsigned char vdd_oor:1;
unsigned char die_temp_rdy:1;
unsigned char led_compb:1;
unsigned char prox_int:1;
unsigned char alc_ovf:1;
unsigned char data_rdy:1;
unsigned char a_full:1;
};
struct {
unsigned char:7;
unsigned char sha_done:1;
};
};
uint8_t val[2];
} int_status_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);
void irq_handler(void);
bool isShaComplete(void);
void clearShaComplete(void);
/* PUBLIC VARIABLES */
InterruptIn m_ir;
private:
/* PRIVATE VARIABLES */
SPI &m_spiBus;
DigitalOut &m_cs;
bool shaComplete;
/* PRIVATE FUNCTION DECLARATIONS */
};
#endif /* _MAX8614X_H_ */