initial commit, reads dev id
Embed:
(wiki syntax)
Show/hide line numbers
MAX8614X.h
00001 /******************************************************************************* 00002 * Author: Ihsan Mert Ozcelik, Ihsan.Ozcelik@maximintegrated.com 00003 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved. 00004 * 00005 * Permission is hereby granted, free of charge, to any person obtaining a 00006 * copy of this software and associated documentation files (the "Software"), 00007 * to deal in the Software without restriction, including without limitation 00008 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00009 * and/or sell copies of the Software, and to permit persons to whom the 00010 * Software is furnished to do so, subject to the following conditions: 00011 * 00012 * The above copyright notice and this permission notice shall be included 00013 * in all copies or substantial portions of the Software. 00014 * 00015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00016 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00017 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00018 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00019 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00020 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00021 * OTHER DEALINGS IN THE SOFTWARE. 00022 * 00023 * Except as contained in this notice, the name of Maxim Integrated 00024 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00025 * Products, Inc. Branding Policy. 00026 * 00027 * The mere transfer of this software does not imply any licenses 00028 * of trade secrets, proprietary technology, copyrights, patents, 00029 * trademarks, maskwork rights, or any other form of intellectual 00030 * property whatsoever. Maxim Integrated Products, Inc. retains all 00031 * ownership rights. 00032 ******************************************************************************* 00033 */ 00034 00035 #ifndef _MAX8614X_H_ 00036 #define _MAX8614X_H_ 00037 00038 #include "mbed.h" 00039 #include "queue.h" 00040 #include "MaximSensor.h" 00041 00042 /** 00043 @brief The MAX8614X 00044 */ 00045 00046 /** 00047 @brief MAX8614X - supports MAX8614X object with SPI interface 00048 */ 00049 class MAX8614X: public MaximSensor 00050 { 00051 public: 00052 /* PUBLIC CONST VARIABLES */ 00053 00054 /* Return codes */ 00055 static const int8_t RTN_NO_ERROR = 0; 00056 static const int8_t RTN_ERR_UNSOPPORTED_PART = -1; 00057 static const int8_t RTN_ERR_WRONG_DATA_TYPE = -2; 00058 static const int8_t RTN_ERR_NOT_8614x = -3; 00059 static const int8_t RTN_ERR_MEM_ALLOC_FAIL = -4; 00060 static const int8_t RTN_ERR_QUEUE_INIT = -5; 00061 static const int8_t RTN_ERR_QUEUE_EMPTY = -6; 00062 00063 /* MAX8614X Registers */ 00064 enum Registers 00065 { 00066 MAX8614X_INT_STATUS1_REG = 0x00, 00067 MAX8614X_INT_STATUS2_REG, 00068 MAX8614X_INT_ENABLE1_REG, 00069 MAX8614X_INT_ENABLE2_REG, 00070 MAX8614X_FIFO_WR_PTR_REG, 00071 MAX8614X_FIFO_RD_PTR_REG, 00072 MAX8614X_OVF_CNT_REG, 00073 MAX8614X_FIFO_DATA_CNT_REG, 00074 MAX8614X_FIFO_DATA_REG, 00075 MAX8614X_FIFO_CFG1_REG, 00076 MAX8614X_FIFO_CFG2_REG, //0x0A 00077 MAX8614X_SYSTEM_CTRL_REG = 0x0D, 00078 MAX8614X_PPG_SYNC_CTRL_REG = 0x10, 00079 MAX8614X_PPG_CFG1_REG, 00080 MAX8614X_PPG_CFG2_REG, 00081 MAX8614X_PPG_CFG3_REG, 00082 MAX8614X_PROX_INT_THRES_REG, 00083 MAX8614X_PHOTO_DIODE_BIAS_REG, 00084 MAX8614X_FICKET_FENCE_REG, //0x16 00085 MAX8614X_LED_SEQ1_REG = 0x20, 00086 MAX8614X_LED_SEQ2_REG, 00087 MAX8614X_LED_SEQ3_REG, 00088 MAX8614X_LED1_PA_REG, 00089 MAX8614X_LED2_PA_REG, 00090 MAX8614X_LED3_PA_REG, 00091 MAX8614X_LED4_PA_REG, 00092 MAX8614X_LED5_PA_REG, 00093 MAX8614X_LED6_PA_REG, 00094 MAX8614X_LED_PILOT_PA_REG, 00095 MAX8614X_LED_RANGE1_REG, 00096 MAX8614X_LED_RANGE2_REG, //0x2B 00097 MAX8614X_DIE_TEMP_CFG_REG = 0x40, 00098 MAX8614X_DIE_TEMP_INT_REG, 00099 MAX8614X_DIE_TEMP_FRAC_REG, 00100 MAX8614X_SHA_CMD_REG = 0xF0, 00101 MAX8614X_SHA_CFG_REG, 00102 MAX8614X_MEMORY_CONTROL_REG, 00103 MAX8614X_MEMORY_INDEX_REG, 00104 MAX8614X_MEMORY_DATA_REG, 00105 MAX8614X_REV_ID_REG = 0xFE, 00106 MAX8614X_PART_ID_REG, 00107 00108 }; 00109 00110 /*System Control*/ 00111 static const uint8_t MAX8614X_SYSTEM_RESET_MASK = (0x01 << 0); 00112 static const uint8_t MAX8614X_SYSTEM_SHDN_MASK = (0x01 << 1); 00113 static const uint8_t MAX8614X_SYSTEM_LP_BOOST = (0x01 << 2); 00114 00115 /* Die Temperature */ 00116 static const uint8_t MAX8614X_DIE_TEMP_EN = (0x1 << 0); 00117 static const uint8_t MAX8614X_DIE_TEMP_FRAC_MASK = (0xF << 0); 00118 00119 /* Sample rates */ 00120 static const uint8_t MAX8614X_PPG_SR_25_SPS = (0x00 << 3); 00121 static const uint8_t MAX8614X_PPG_SR_50_SPS = (0x01 << 3); 00122 static const uint8_t MAX8614X_PPG_SR_84_SPS = (0x02 << 3); 00123 static const uint8_t MAX8614X_PPG_SR_100_SPS = (0x03 << 3); 00124 static const uint8_t MAX8614X_PPG_SR_200_SPS = (0x04 << 3); 00125 static const uint8_t MAX8614X_PPG_SR_400_SPS = (0x05 << 3); 00126 00127 /* LED Pulse Amplitude */ 00128 static const uint8_t MAX8614X_LED1_RGE_MASK = (0x3 << 0); 00129 static const uint8_t MAX8614X_LED2_RGE_MASK = (0x3 << 2); 00130 static const uint8_t MAX8614X_LED3_RGE_MASK = (0x3 << 4); 00131 00132 static const uint8_t MAX8614X_LED4_RGE_MASK = (0x3 << 0); 00133 static const uint8_t MAX8614X_LED5_RGE_MASK = (0x3 << 2); 00134 static const uint8_t MAX8614X_LED6_RGE_MASK = (0x3 << 4); 00135 00136 static const uint8_t MAX8614X_LED1_RGE_25mA_MASK = (0x0 << 0); 00137 static const uint8_t MAX8614X_LED1_RGE_50mA_MASK = (0x1 << 0); 00138 static const uint8_t MAX8614X_LED1_RGE_75mA_MASK = (0x2 << 0); 00139 static const uint8_t MAX8614X_LED1_RGE_100mA_MASK = (0x3 << 0); 00140 00141 static const uint8_t MAX8614X_LED2_RGE_25mA_MASK = (0x0 << 2); 00142 static const uint8_t MAX8614X_LED2_RGE_50mA_MASK = (0x1 << 2); 00143 static const uint8_t MAX8614X_LED2_RGE_75mA_MASK = (0x2 << 2); 00144 static const uint8_t MAX8614X_LED2_RGE_100mA_MASK = (0x3 << 2); 00145 00146 static const uint8_t MAX8614X_LED3_RGE_25mA_MASK = (0x0 << 4); 00147 static const uint8_t MAX8614X_LED3_RGE_50mA_MASK = (0x1 << 4); 00148 static const uint8_t MAX8614X_LED3_RGE_75mA_MASK = (0x2 << 4); 00149 static const uint8_t MAX8614X_LED3_RGE_100mA_MASK = (0x3 << 4); 00150 00151 /* PPG PW */ 00152 static const uint8_t MAX8614X_PPG_LED_PW_14_4_US_MASK = (0 << 0); 00153 static const uint8_t MAX8614X_PPG_LED_PW_28_8_US_MASK = (1 << 0); 00154 static const uint8_t MAX8614X_PPG_LED_PW_57_6_US_MASK = (2 << 0); 00155 static const uint8_t MAX8614X_PPG_LED_PW_115_2_US_MASK = (3 << 0); 00156 00157 /* PPG Range */ 00158 static const uint8_t MAX8614X_PPG1_ADC_RGE_4096_MASK = (0 << 2); 00159 static const uint8_t MAX8614X_PPG1_ADC_RGE_8192_MASK = (1 << 2); 00160 static const uint8_t MAX8614X_PPG1_ADC_RGE_16384_MASK = (2 << 2); 00161 static const uint8_t MAX8614X_PPG1_ADC_RGE_32768_MASK = (3 << 2); 00162 00163 static const uint8_t MAX8614X_PPG2_ADC_RGE_4096_MASK = (0 << 4); 00164 static const uint8_t MAX8614X_PPG2_ADC_RGE_8192_MASK = (1 << 4); 00165 static const uint8_t MAX8614X_PPG2_ADC_RGE_16384_MASK = (2 << 4); 00166 static const uint8_t MAX8614X_PPG2_ADC_RGE_32768_MASK = (3 << 4); 00167 00168 /* FIFO */ 00169 static const uint8_t MAX8614X_FIFO_WR_PTR_MASK = (0x7F << 0); 00170 static const uint8_t MAX8614X_FIFO_RD_PTR_MASK = (0x7F << 0); 00171 static const uint8_t MAX8614X_OVF_CNT_MASK = (0x7F << 0); 00172 static const uint8_t MAX8614X_FIFO_A_FULL_MASK = (0x7F << 0); 00173 static const uint8_t MAX8614X_FIFO_EN_MASK = (0x01 << 0); 00174 static const uint8_t MAX8614X_FIFO_RO_MASK = (0x01 << 1); 00175 static const uint8_t MAX8614X_A_FULL_TYPE_MASK = (0x01 << 2); 00176 static const uint8_t MAX8614X_A_FULL_RPT = (0x00 << 2); 00177 static const uint8_t MAX8614X_A_FULL_ONCE = (0x01 << 2); 00178 static const uint8_t MAX8614X_FIFO_STAT_CLR_MASK = (0x01 << 3); 00179 static const uint8_t MAX8614X_FLUSH_FIFO_MASK = (0x01 << 4); 00180 00181 /* Status */ 00182 static const uint8_t MAX8614X_INT1_EN_A_FULL_MASK = (0x1 << 7); 00183 static const uint8_t MAX8614X_INT1_EN_DATA_RDY_MASK = (0x1 << 6); 00184 static const uint8_t MAX8614X_INT1_EN_DIE_TEMP_MASK = (0x1 << 2); 00185 static const uint8_t MAX8614X_INT1_EN_VDD_OOR_MASK = (0x1 << 1); 00186 00187 /*SHA256 Control*/ 00188 static const uint8_t MAX8614X_IE_SHA_DONE_EN = (0x01 << 0); 00189 static const uint8_t MAX8614X_SHACFG_SHA_START = (0x01 << 0); 00190 static const uint8_t MAX8614X_SHACFG_SHA_EN = (0x01 << 1); 00191 static const uint8_t MAX8614X_MEMCNTRL_BANK0_MASK = (0); 00192 static const uint8_t MAX8614X_MEMCNTRL_BANK1_MASK = (1); 00193 static const uint8_t MAX8614X_MEMCNTRL_WR_DIS_MASK = (0x01 << 0); 00194 static const uint8_t MAX8614X_MEMCNTRL_WR_EN_MASK = (0x01 << 1); 00195 static const uint8_t MAX8614X_SHACMD_MAC_ROM_ID = (0x35); 00196 static const uint8_t MAX8614X_SHACMD_MAC_NO_ROM_ID = (0x36); 00197 00198 /* PUBLIC TYPE DEFINITIONS */ 00199 typedef struct RegisterMap { 00200 uint8_t addr; 00201 uint8_t val; 00202 } RegisterMap_t; 00203 00204 /* PUBLIC FUNCTION DECLARATIONS */ 00205 00206 MAX8614X(SPI &spiBus, DigitalOut &cs, PinName intPin); 00207 00208 int readRegister(uint8_t reg, uint8_t *data, int len); 00209 00210 int writeRegister(uint8_t reg, const uint8_t data); 00211 00212 int writeBlock(const RegisterMap reg_block[], unsigned int size); 00213 00214 int dequeue_from_fifo_queue(uint32_t *ir, uint32_t *red, uint32_t *green); 00215 00216 int get_part_info(uint8_t *part_id, uint8_t *rev_id); 00217 00218 int init(); 00219 00220 const char *get_sensor_part_name(); 00221 00222 const char *get_sensor_name(); 00223 00224 int sensor_enable(int enable); 00225 00226 int agc_enable(int agc_enable); 00227 00228 int dump_registers(); 00229 bool isShaComplete(void); 00230 void clearShaComplete(void); 00231 00232 /* PUBLIC VARIABLES */ 00233 InterruptIn m_ir; 00234 00235 private: 00236 /* PRIVATE CONST VARIABLES */ 00237 static const uint32_t MAX8614X_DATA_WORD_SIZE = 3; 00238 static const uint32_t MAX8614X_MAX_FIFO_DEPTH = 128; 00239 static const uint32_t MAX8614X_DATA_TYPE_MASK = (0x1F << 19); 00240 static const uint32_t MAX8614X_DRIVER_FIFO_SZ = (MAX8614X_MAX_FIFO_DEPTH * 4); 00241 00242 /* PRIVATE TYPE DEFINITIONS */ 00243 enum LedSequence 00244 { 00245 DATA_SEQ_NONE, 00246 DATA_SEQ_LED1, 00247 DATA_SEQ_LED2, 00248 DATA_SEQ_LED3, 00249 DATA_SEQ_LED1_LED2, 00250 DATA_SEQ_LED1_LED3, 00251 DATA_SEQ_LED2_LED3, 00252 DATA_SEQ_LED1_LED2_LED3, 00253 DATA_SEQ_PILOT_LED1, 00254 DATA_SEQ_AMBIENT, 00255 DATA_SEQ_LED4_EXT_MUX, 00256 DATA_SEQ_LED5_EXT_MUX, 00257 DATA_SEQ_LED6_EXT_MUX, 00258 }; 00259 00260 enum DataTypes 00261 { 00262 DATA_TYPE_PPG1_LEDC1 = 0x01, 00263 DATA_TYPE_PPG1_LEDC2, 00264 DATA_TYPE_PPG1_LEDC3, 00265 DATA_TYPE_PPG1_LEDC4, 00266 DATA_TYPE_PPG1_LEDC5, 00267 DATA_TYPE_PPG1_LEDC6, 00268 DATA_TYPE_PPG2_LEDC1, 00269 DATA_TYPE_PPG2_LEDC2, 00270 DATA_TYPE_PPG2_LEDC3, 00271 DATA_TYPE_PPG2_LEDC4, 00272 DATA_TYPE_PPG2_LEDC5, 00273 DATA_TYPE_PPG2_LEDC6, 00274 DATA_TYPE_PPF1_LEDC1, 00275 DATA_TYPE_PPF1_LEDC2, 00276 DATA_TYPE_PPF1_LEDC3, 00277 DATA_TYPE_PPF2_LEDC1 = 0x13, 00278 DATA_TYPE_PPF3_LEDC2, 00279 DATA_TYPE_PPF3_LEDC3, 00280 DATA_TYPE_PROX1 = 0x19, 00281 DATA_TYPE_PROX2, 00282 DATA_TYPE_INVALID_DATA = 0x1E, 00283 DATA_TYPE_TIME_STAMP, 00284 }; 00285 00286 enum PartIDs 00287 { 00288 MAX86140_PART_ID_VAL = 0x24, 00289 MAX86141_PART_ID_VAL, 00290 MAX86142_PART_ID_VAL, 00291 MAX86143_PART_ID_VAL, 00292 }; 00293 00294 enum LedRanges 00295 { 00296 LED_RANGE_0_50, 00297 LED_RANGE_50_100, 00298 LED_RANGE_100_150, 00299 LED_RANGE_150_200, 00300 }; 00301 00302 enum LedRangeSteps 00303 { 00304 LED_RANGE_STEP_25uA = 120, 00305 LED_RANGE_STEP_50uA = 240, 00306 LED_RANGE_STEP_75uA = 360, 00307 LED_RANGE_STEP_100uA = 480, 00308 }; 00309 00310 typedef enum { 00311 LED_1 = 0, 00312 LED_2, 00313 LED_3, 00314 LED_4, 00315 LED_5, 00316 LED_6, 00317 NUM_OF_LED, 00318 } max8614x_led_t; 00319 00320 enum LED_CTRL_SM { 00321 LED_PROX = 1, 00322 LED_DATA_ACQ, 00323 }; 00324 00325 typedef union { 00326 struct { 00327 uint32_t val:19; 00328 uint32_t type:5; 00329 uint32_t:8; 00330 }; 00331 uint32_t raw; 00332 } fifo_data_t; 00333 00334 typedef union { 00335 uint16_t val; 00336 struct { 00337 uint8_t tint; 00338 uint8_t frac:4; 00339 uint8_t:4; 00340 }; 00341 } die_temp_t; 00342 00343 typedef union { 00344 struct { 00345 struct { 00346 unsigned char pwr_rdy:1; 00347 unsigned char vdd_oor:1; 00348 unsigned char die_temp_rdy:1; 00349 unsigned char led_compb:1; 00350 unsigned char prox_int:1; 00351 unsigned char alc_ovf:1; 00352 unsigned char data_rdy:1; 00353 unsigned char a_full:1; 00354 }; 00355 struct { 00356 unsigned char:7; 00357 unsigned char sha_done:1; 00358 }; 00359 }; 00360 uint8_t val[2]; 00361 } int_status_t; 00362 00363 union led_range { 00364 struct { 00365 uint8_t led1:2; 00366 uint8_t led2:2; 00367 uint8_t led3:2; 00368 uint8_t:2; 00369 uint8_t led4:2; 00370 uint8_t led5:2; 00371 uint8_t led6:2; 00372 uint8_t:2; 00373 }; 00374 uint8_t val[2]; 00375 }; 00376 00377 typedef struct { 00378 uint32_t green; 00379 uint32_t ir; 00380 uint32_t red; 00381 } ppg_data_t; 00382 00383 struct led_control { 00384 uint32_t diode_sum[NUM_OF_LED]; 00385 uint32_t state; 00386 uint32_t prox_sum; 00387 uint32_t prox_sample_cnt; 00388 int32_t led_current[NUM_OF_LED]; 00389 uint32_t default_current[NUM_OF_LED]; 00390 int32_t agc_led_out_percent; 00391 int32_t agc_corr_coeff; 00392 int32_t agc_min_num_samples; 00393 int32_t agc_sensitivity_percent; 00394 int32_t change_by_percent_of_range[NUM_OF_LED]; 00395 int32_t change_by_percent_of_current_setting[NUM_OF_LED]; 00396 int32_t change_led_by_absolute_count[NUM_OF_LED]; 00397 uint32_t sample_cnt; 00398 union led_range led_range_settings; 00399 uint8_t led_ranges; 00400 uint8_t agc_is_enabled; 00401 uint8_t lpm_is_enabled; 00402 }; 00403 00404 /* PRIVATE VARIABLES */ 00405 SPI m_spiBus; 00406 DigitalOut m_cs; 00407 struct queue_t queue; 00408 struct led_control led_ctrl; 00409 int vdd_oor_cnt; 00410 die_temp_t die_temp; 00411 bool shaComplete; 00412 00413 /* PRIVATE FUNCTION DECLARATIONS */ 00414 int reset(); 00415 00416 int poweroff(); 00417 00418 void irq_handler(); 00419 00420 int enable_die_temp(); 00421 00422 int read_die_temp(); 00423 00424 int get_num_samples_in_fifo(); 00425 00426 void fifo_irq_handler(); 00427 00428 int read_fifo_data(uint8_t *fifo_data, int num_samples); 00429 00430 /* AGC functions */ 00431 int max8614x_update_led_range(int new_range, uint8_t led_num, 00432 union led_range *led_range_settings); 00433 00434 int max8614x_update_led_current(union led_range *led_range_settings, 00435 int led_new_val, max8614x_led_t led_num); 00436 00437 void ppg_auto_gain_ctrl(struct led_control *led_ctrl, 00438 uint32_t sample_cnt, int diode_data, max8614x_led_t led_num); 00439 00440 void max8614x_agc_handler(struct led_control *led_ctrl, 00441 int *samples); 00442 00443 int led_control_sm(struct led_control *led_ctrl, 00444 int diode_data, char lpm); 00445 00446 void led_control_reset(struct led_control *led_ctrl); 00447 00448 int led_prox_init(struct led_control *led_ctrl, char lpm); 00449 00450 int led_daq_init(struct led_control *led_ctrl, char lpm); 00451 00452 void led_control_init(struct led_control *led_ctrl); 00453 }; 00454 00455 #endif /* _MAX8614X_H_ */
Generated on Fri Sep 2 2022 22:34:53 by
1.7.2