initial commit, reads dev id
MAX8614X.cpp@1:7ae9b934ee55, 2018-08-11 (annotated)
- Committer:
- phonemacro
- Date:
- Sat Aug 11 00:37:58 2018 +0000
- Revision:
- 1:7ae9b934ee55
- Parent:
- 0:77ee0ceb503a
- Child:
- 2:11e0b5b86e1e
update for CS; P5_3
Who changed what in which revision?
| User | Revision | Line number | New 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 | 1:7ae9b934ee55 | 43 | :m_ir(pin), 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 | int i = 0; |
| phonemacro | 0:77ee0ceb503a | 55 | for(; i < len; i++) { /*TODO: make len unsigned*/ |
| phonemacro | 0:77ee0ceb503a | 56 | data[i] = m_spiBus.write(0x00); |
| phonemacro | 0:77ee0ceb503a | 57 | } |
| phonemacro | 0:77ee0ceb503a | 58 | |
| phonemacro | 0:77ee0ceb503a | 59 | m_cs = 1; |
| phonemacro | 0:77ee0ceb503a | 60 | return 0; /*TODO: handle error cases*/ |
| phonemacro | 0:77ee0ceb503a | 61 | } |
| phonemacro | 0:77ee0ceb503a | 62 | |
| phonemacro | 0:77ee0ceb503a | 63 | int MAX8614X::writeRegister(uint8_t reg, const uint8_t data) |
| phonemacro | 0:77ee0ceb503a | 64 | { |
| phonemacro | 0:77ee0ceb503a | 65 | m_cs = 0; |
| phonemacro | 0:77ee0ceb503a | 66 | |
| phonemacro | 0:77ee0ceb503a | 67 | m_spiBus.write(reg); |
| phonemacro | 0:77ee0ceb503a | 68 | m_spiBus.write(0x00); |
| phonemacro | 0:77ee0ceb503a | 69 | m_spiBus.write(data); |
| phonemacro | 0:77ee0ceb503a | 70 | |
| phonemacro | 0:77ee0ceb503a | 71 | m_cs = 1; |
| phonemacro | 0:77ee0ceb503a | 72 | |
| phonemacro | 0:77ee0ceb503a | 73 | return 0; /*TODO: handle error cases*/ |
| phonemacro | 0:77ee0ceb503a | 74 | } |
| phonemacro | 0:77ee0ceb503a | 75 | |
| phonemacro | 0:77ee0ceb503a | 76 | int MAX8614X::writeBlock(const RegisterMap reg_block[], unsigned int size) |
| phonemacro | 0:77ee0ceb503a | 77 | { |
| phonemacro | 0:77ee0ceb503a | 78 | unsigned int i; |
| phonemacro | 0:77ee0ceb503a | 79 | int ret = 0; |
| phonemacro | 0:77ee0ceb503a | 80 | |
| phonemacro | 0:77ee0ceb503a | 81 | for (i = 0; i < size; i++) { |
| phonemacro | 0:77ee0ceb503a | 82 | ret = writeRegister((Registers) reg_block[i].addr, |
| phonemacro | 0:77ee0ceb503a | 83 | reg_block[i].val); |
| phonemacro | 0:77ee0ceb503a | 84 | if (ret < 0) { |
| phonemacro | 0:77ee0ceb503a | 85 | pr_err("writeRegister failed. ret: %d", ret); |
| phonemacro | 0:77ee0ceb503a | 86 | return ret; |
| phonemacro | 0:77ee0ceb503a | 87 | } |
| phonemacro | 0:77ee0ceb503a | 88 | } |
| phonemacro | 0:77ee0ceb503a | 89 | |
| phonemacro | 0:77ee0ceb503a | 90 | return ret; |
| phonemacro | 0:77ee0ceb503a | 91 | } |
| phonemacro | 1:7ae9b934ee55 | 92 | void MAX8614X::irq_handler(void) |
| phonemacro | 1:7ae9b934ee55 | 93 | { |
| phonemacro | 1:7ae9b934ee55 | 94 | int ret; |
| phonemacro | 1:7ae9b934ee55 | 95 | int_status_t status; |
| phonemacro | 1:7ae9b934ee55 | 96 | |
| phonemacro | 1:7ae9b934ee55 | 97 | ret = readRegister(MAX8614X_INT_STATUS1_REG, status.val, 2); |
| phonemacro | 1:7ae9b934ee55 | 98 | if (ret < 0) { |
| phonemacro | 1:7ae9b934ee55 | 99 | printf("readRegister failed. ret: %d", ret); |
| phonemacro | 1:7ae9b934ee55 | 100 | } |
| phonemacro | 1:7ae9b934ee55 | 101 | printf("Status reg: %X %X \n\r", status.val[0], status.val[1]); |
| phonemacro | 1:7ae9b934ee55 | 102 | |
| phonemacro | 1:7ae9b934ee55 | 103 | if (status.sha_done) { |
| phonemacro | 1:7ae9b934ee55 | 104 | printf("sha interrupt\n\r"); |
| phonemacro | 1:7ae9b934ee55 | 105 | } |
| phonemacro | 1:7ae9b934ee55 | 106 | } |
| phonemacro | 1:7ae9b934ee55 | 107 | |
| phonemacro | 0:77ee0ceb503a | 108 | MAX8614X::~MAX8614X(void) |
| phonemacro | 0:77ee0ceb503a | 109 | { |
| phonemacro | 0:77ee0ceb503a | 110 | //empty block |
| phonemacro | 0:77ee0ceb503a | 111 | } |