| 1 | /***************************************************************************//** |
| 2 | * @file adgs5412.h |
| 3 | * @brief Header file of ADGS5412 Driver. |
| 4 | * @author DBogdan ([email protected]) |
| 5 | ******************************************************************************** |
| 6 | * Copyright 2016(c) Analog Devices, Inc. |
| 7 | * |
| 8 | * All rights reserved. |
| 9 | * |
| 10 | * Redistribution and use in source and binary forms, with or without |
| 11 | * modification, are permitted provided that the following conditions are met: |
| 12 | * - Redistributions of source code must retain the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer. |
| 14 | * - Redistributions in binary form must reproduce the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer in |
| 16 | * the documentation and/or other materials provided with the |
| 17 | * distribution. |
| 18 | * - Neither the name of Analog Devices, Inc. nor the names of its |
| 19 | * contributors may be used to endorse or promote products derived |
| 20 | * from this software without specific prior written permission. |
| 21 | * - The use of this software may or may not infringe the patent rights |
| 22 | * of one or more patent holders. This license does not release you |
| 23 | * from the requirement that you obtain separate licenses from these |
| 24 | * patent holders to use this software. |
| 25 | * - Use of the software either in source or binary form, must be run |
| 26 | * on or directly connected to an Analog Devices Inc. component. |
| 27 | * |
| 28 | * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
| 29 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
| 30 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 31 | * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 32 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | *******************************************************************************/ |
| 39 | #ifndef ADGS5412_H_ |
| 40 | #define ADGS5412_H_ |
| 41 | |
| 42 | /******************************************************************************/ |
| 43 | /********************** Macros and Constants Definitions **********************/ |
| 44 | /******************************************************************************/ |
| 45 | #define ADGS5412_REG_SW_DATA 0x01 |
| 46 | #define ADGS5412_REG_ERR_CONFIG 0x02 |
| 47 | #define ADGS5412_REG_ERR_FLAGS 0x03 |
| 48 | #define ADGS5412_REG_BURST_EN 0x05 |
| 49 | #define ADGS5412_REG_SOFT_RESETB 0x0B |
| 50 | |
| 51 | /* ADGS5412_REG_SW_DATA */ |
| 52 | #define ADGS5412_SW4_EN (1 << 3) |
| 53 | #define ADGS5412_SW3_EN (1 << 2) |
| 54 | #define ADGS5412_SW2_EN (1 << 1) |
| 55 | #define ADGS5412_SW1_EN (1 << 0) |
| 56 | |
| 57 | /* ADGS5412_REG_ERR_CONFIG */ |
| 58 | #define ADGS5412_RW_ERR_EN (1 << 2) |
| 59 | #define ADGS5412_SCLK_ERR_EN (1 << 1) |
| 60 | #define ADGS5412_CRC_ERR_EN (1 << 0) |
| 61 | |
| 62 | /* ADGS5412_REG_ERR_FLAGS */ |
| 63 | #define ADGS5412_RW_ERR_FLAG (1 << 2) |
| 64 | #define ADGS5412_SCLK_ERR_FLAG (1 << 1) |
| 65 | #define ADGS5412_CRC_ERR_FLAG (1 << 0) |
| 66 | #define ADGS5412_CLR_1 0x6C |
| 67 | #define ADGS5412_CLR_2 0xA9 |
| 68 | |
| 69 | /* ADGS5412_REG_BURST_EN */ |
| 70 | #define ADGS5412_BURST_MODE_EN (1 << 0) |
| 71 | |
| 72 | /* ADGS5412_REG_SOFT_RESETB */ |
| 73 | #define ADGS5412_SOFT_RESETB(x) (((x) & 0xFF) << 0) |
| 74 | #define ADGS5412_RESET_1 0xA3 |
| 75 | #define ADGS5412_RESET_2 0x05 |
| 76 | |
| 77 | #define ADGS5412_DAISY_CHAIN_1 0x25 |
| 78 | #define ADGS5412_DAISY_CHAIN_2 0x00 |
| 79 | |
| 80 | #define ADGS5412_ALIGNMENT 0x25 |
| 81 | |
| 82 | #define ADGS5412_CRC8_POLY 0x07 |
| 83 | |
| 84 | /******************************************************************************/ |
| 85 | /*************************** Types Declarations *******************************/ |
| 86 | /******************************************************************************/ |
| 87 | typedef enum { |
| 88 | ADGS5412_ENABLE, |
| 89 | ADGS5412_DISABLE, |
| 90 | } adgs5412_state; |
| 91 | |
| 92 | typedef struct { |
| 93 | /* SPI */ |
| 94 | spi_device spi_dev; |
| 95 | /* Device Settings */ |
| 96 | adgs5412_state crc_en; |
| 97 | adgs5412_state burst_mode_en; |
| 98 | adgs5412_state daisy_chain_en; |
| 99 | } adgs5412_dev; |
| 100 | |
| 101 | typedef struct { |
| 102 | /* SPI */ |
| 103 | uint8_t spi_chip_select; |
| 104 | spi_mode spi_mode; |
| 105 | spi_type spi_type; |
| 106 | uint32_t spi_device_id; |
| 107 | /* Device Settings */ |
| 108 | adgs5412_state crc_en; |
| 109 | adgs5412_state burst_mode_en; |
| 110 | adgs5412_state daisy_chain_en; |
| 111 | } adgs5412_init_param; |
| 112 | |
| 113 | /******************************************************************************/ |
| 114 | /************************ Functions Declarations ******************************/ |
| 115 | /******************************************************************************/ |
| 116 | /* Compute CRC8 checksum. */ |
| 117 | uint8_t adgs5412_compute_crc8(uint8_t *data, |
| 118 | uint8_t data_size); |
| 119 | /* SPI register read from device. */ |
| 120 | int32_t adgs5412_spi_reg_read(adgs5412_dev *dev, |
| 121 | uint8_t reg_addr, |
| 122 | uint8_t *reg_data); |
| 123 | /* SPI register write to device. */ |
| 124 | int32_t adgs5412_spi_reg_write(adgs5412_dev *dev, |
| 125 | uint8_t reg_addr, |
| 126 | uint8_t reg_data); |
| 127 | /* SPI register read from device using a mask. */ |
| 128 | int32_t adgs5412_spi_reg_read_mask(adgs5412_dev *dev, |
| 129 | uint8_t reg_addr, |
| 130 | uint8_t mask, |
| 131 | uint8_t *data); |
| 132 | /* SPI internal register write to device using a mask. */ |
| 133 | int32_t adgs5412_spi_reg_write_mask(adgs5412_dev *dev, |
| 134 | uint8_t reg_addr, |
| 135 | uint8_t mask, |
| 136 | uint8_t data); |
| 137 | /* Do a software reset. */ |
| 138 | int32_t adgs5412_do_soft_reset(adgs5412_dev *dev); |
| 139 | /* Clear the Error Flags Register. */ |
| 140 | int32_t adgs5412_clear_err_flags(adgs5412_dev *dev); |
| 141 | /* Enter Daisy-Chain Mode. */ |
| 142 | int32_t adgs5412_enter_daisy_chain(adgs5412_dev *dev); |
| 143 | /* Send Daisy-Chain commands. */ |
| 144 | int32_t adgs5412_send_daisy_chain_cmds(adgs5412_dev *dev, |
| 145 | uint8_t *cmds, |
| 146 | uint8_t cmds_size); |
| 147 | /* Initialize the device. */ |
| 148 | int32_t adgs5412_setup(adgs5412_dev **device, |
| 149 | adgs5412_init_param init_param); |
| 150 | #endif // ADGS5412_H_ |