initial commit, reads dev id

Committer:
phonemacro
Date:
Fri Aug 10 04:54:06 2018 +0000
Revision:
0:77ee0ceb503a
Child:
1:7ae9b934ee55
start of max86140 driver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
phonemacro 0:77ee0ceb503a 1 /*******************************************************************************
phonemacro 0:77ee0ceb503a 2 * Author: Ihsan Mert Ozcelik, Ihsan.Ozcelik@maximintegrated.com
phonemacro 0:77ee0ceb503a 3 * Copyright (C) 2017 Maxim Integrated Products, Inc., All Rights Reserved.
phonemacro 0:77ee0ceb503a 4 *
phonemacro 0:77ee0ceb503a 5 * Permission is hereby granted, free of charge, to any person obtaining a
phonemacro 0:77ee0ceb503a 6 * copy of this software and associated documentation files (the "Software"),
phonemacro 0:77ee0ceb503a 7 * to deal in the Software without restriction, including without limitation
phonemacro 0:77ee0ceb503a 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
phonemacro 0:77ee0ceb503a 9 * and/or sell copies of the Software, and to permit persons to whom the
phonemacro 0:77ee0ceb503a 10 * Software is furnished to do so, subject to the following conditions:
phonemacro 0:77ee0ceb503a 11 *
phonemacro 0:77ee0ceb503a 12 * The above copyright notice and this permission notice shall be included
phonemacro 0:77ee0ceb503a 13 * in all copies or substantial portions of the Software.
phonemacro 0:77ee0ceb503a 14 *
phonemacro 0:77ee0ceb503a 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
phonemacro 0:77ee0ceb503a 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
phonemacro 0:77ee0ceb503a 17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
phonemacro 0:77ee0ceb503a 18 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
phonemacro 0:77ee0ceb503a 19 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
phonemacro 0:77ee0ceb503a 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
phonemacro 0:77ee0ceb503a 21 * OTHER DEALINGS IN THE SOFTWARE.
phonemacro 0:77ee0ceb503a 22 *
phonemacro 0:77ee0ceb503a 23 * Except as contained in this notice, the name of Maxim Integrated
phonemacro 0:77ee0ceb503a 24 * Products, Inc. shall not be used except as stated in the Maxim Integrated
phonemacro 0:77ee0ceb503a 25 * Products, Inc. Branding Policy.
phonemacro 0:77ee0ceb503a 26 *
phonemacro 0:77ee0ceb503a 27 * The mere transfer of this software does not imply any licenses
phonemacro 0:77ee0ceb503a 28 * of trade secrets, proprietary technology, copyrights, patents,
phonemacro 0:77ee0ceb503a 29 * trademarks, maskwork rights, or any other form of intellectual
phonemacro 0:77ee0ceb503a 30 * property whatsoever. Maxim Integrated Products, Inc. retains all
phonemacro 0:77ee0ceb503a 31 * ownership rights.
phonemacro 0:77ee0ceb503a 32 *******************************************************************************
phonemacro 0:77ee0ceb503a 33 */
phonemacro 0:77ee0ceb503a 34 #include "MAX8614X.h"
phonemacro 0:77ee0ceb503a 35
phonemacro 0:77ee0ceb503a 36 #define pr_err(fmt, args...) if(1) printf(fmt " (%s:%d)\n", ##args, __func__, __LINE__)
phonemacro 0:77ee0ceb503a 37 #define pr_info(fmt, args...) if(1) printf(fmt " (%s:%d)\n", ##args, __func__, __LINE__)
phonemacro 0:77ee0ceb503a 38 #define pr_debug(fmt, args...) if(0) printf(fmt " (%s:%d)\n", ##args, __func__, __LINE__)
phonemacro 0:77ee0ceb503a 39
phonemacro 0:77ee0ceb503a 40 #define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
phonemacro 0:77ee0ceb503a 41
phonemacro 0:77ee0ceb503a 42 MAX8614X::MAX8614X(SPI &spiBus, DigitalOut &cs, PinName pin)
phonemacro 0:77ee0ceb503a 43 :m_spiBus(spiBus), m_cs(cs)
phonemacro 0:77ee0ceb503a 44 {
phonemacro 0:77ee0ceb503a 45 m_cs = 1;
phonemacro 0:77ee0ceb503a 46 }
phonemacro 0:77ee0ceb503a 47
phonemacro 0:77ee0ceb503a 48 int MAX8614X::readRegister(uint8_t reg, uint8_t *data, int len)
phonemacro 0:77ee0ceb503a 49 {
phonemacro 0:77ee0ceb503a 50 m_cs = 0;
phonemacro 0:77ee0ceb503a 51
phonemacro 0:77ee0ceb503a 52 m_spiBus.write(reg);
phonemacro 0:77ee0ceb503a 53 m_spiBus.write(0x80);
phonemacro 0:77ee0ceb503a 54
phonemacro 0:77ee0ceb503a 55 int i = 0;
phonemacro 0:77ee0ceb503a 56 for(; i < len; i++) { /*TODO: make len unsigned*/
phonemacro 0:77ee0ceb503a 57 data[i] = m_spiBus.write(0x00);
phonemacro 0:77ee0ceb503a 58 }
phonemacro 0:77ee0ceb503a 59
phonemacro 0:77ee0ceb503a 60 m_cs = 1;
phonemacro 0:77ee0ceb503a 61 return 0; /*TODO: handle error cases*/
phonemacro 0:77ee0ceb503a 62 }
phonemacro 0:77ee0ceb503a 63
phonemacro 0:77ee0ceb503a 64 int MAX8614X::writeRegister(uint8_t reg, const uint8_t data)
phonemacro 0:77ee0ceb503a 65 {
phonemacro 0:77ee0ceb503a 66 m_cs = 0;
phonemacro 0:77ee0ceb503a 67
phonemacro 0:77ee0ceb503a 68 m_spiBus.write(reg);
phonemacro 0:77ee0ceb503a 69 m_spiBus.write(0x00);
phonemacro 0:77ee0ceb503a 70 m_spiBus.write(data);
phonemacro 0:77ee0ceb503a 71
phonemacro 0:77ee0ceb503a 72 m_cs = 1;
phonemacro 0:77ee0ceb503a 73
phonemacro 0:77ee0ceb503a 74 return 0; /*TODO: handle error cases*/
phonemacro 0:77ee0ceb503a 75 }
phonemacro 0:77ee0ceb503a 76
phonemacro 0:77ee0ceb503a 77 int MAX8614X::writeBlock(const RegisterMap reg_block[], unsigned int size)
phonemacro 0:77ee0ceb503a 78 {
phonemacro 0:77ee0ceb503a 79 unsigned int i;
phonemacro 0:77ee0ceb503a 80 int ret = 0;
phonemacro 0:77ee0ceb503a 81
phonemacro 0:77ee0ceb503a 82 for (i = 0; i < size; i++) {
phonemacro 0:77ee0ceb503a 83 ret = writeRegister((Registers) reg_block[i].addr,
phonemacro 0:77ee0ceb503a 84 reg_block[i].val);
phonemacro 0:77ee0ceb503a 85 if (ret < 0) {
phonemacro 0:77ee0ceb503a 86 pr_err("writeRegister failed. ret: %d", ret);
phonemacro 0:77ee0ceb503a 87 return ret;
phonemacro 0:77ee0ceb503a 88 }
phonemacro 0:77ee0ceb503a 89 }
phonemacro 0:77ee0ceb503a 90
phonemacro 0:77ee0ceb503a 91 return ret;
phonemacro 0:77ee0ceb503a 92 }
phonemacro 0:77ee0ceb503a 93 MAX8614X::~MAX8614X(void)
phonemacro 0:77ee0ceb503a 94 {
phonemacro 0:77ee0ceb503a 95 //empty block
phonemacro 0:77ee0ceb503a 96 }