Analog Devices / ADMX2001
Committer:
nsheth
Date:
Wed Oct 27 07:36:03 2021 +0000
Revision:
8:ca65a811c522
Convert platform drivers away from library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nsheth 8:ca65a811c522 1 /***************************************************************************//**
nsheth 8:ca65a811c522 2 * @file spi.h
nsheth 8:ca65a811c522 3 * @author DBogdan (dragos.bogdan@analog.com)
nsheth 8:ca65a811c522 4 ********************************************************************************
nsheth 8:ca65a811c522 5 * Copyright 2019(c) Analog Devices, Inc.
nsheth 8:ca65a811c522 6 *
nsheth 8:ca65a811c522 7 * All rights reserved.
nsheth 8:ca65a811c522 8 *
nsheth 8:ca65a811c522 9 * Redistribution and use in source and binary forms, with or without
nsheth 8:ca65a811c522 10 * modification, are permitted provided that the following conditions are met:
nsheth 8:ca65a811c522 11 * - Redistributions of source code must retain the above copyright
nsheth 8:ca65a811c522 12 * notice, this list of conditions and the following disclaimer.
nsheth 8:ca65a811c522 13 * - Redistributions in binary form must reproduce the above copyright
nsheth 8:ca65a811c522 14 * notice, this list of conditions and the following disclaimer in
nsheth 8:ca65a811c522 15 * the documentation and/or other materials provided with the
nsheth 8:ca65a811c522 16 * distribution.
nsheth 8:ca65a811c522 17 * - Neither the name of Analog Devices, Inc. nor the names of its
nsheth 8:ca65a811c522 18 * contributors may be used to endorse or promote products derived
nsheth 8:ca65a811c522 19 * from this software without specific prior written permission.
nsheth 8:ca65a811c522 20 * - The use of this software may or may not infringe the patent rights
nsheth 8:ca65a811c522 21 * of one or more patent holders. This license does not release you
nsheth 8:ca65a811c522 22 * from the requirement that you obtain separate licenses from these
nsheth 8:ca65a811c522 23 * patent holders to use this software.
nsheth 8:ca65a811c522 24 * - Use of the software either in source or binary form, must be run
nsheth 8:ca65a811c522 25 * on or directly connected to an Analog Devices Inc. component.
nsheth 8:ca65a811c522 26 *
nsheth 8:ca65a811c522 27 * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
nsheth 8:ca65a811c522 28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
nsheth 8:ca65a811c522 29 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
nsheth 8:ca65a811c522 30 * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
nsheth 8:ca65a811c522 31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nsheth 8:ca65a811c522 32 * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
nsheth 8:ca65a811c522 33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nsheth 8:ca65a811c522 34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nsheth 8:ca65a811c522 35 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nsheth 8:ca65a811c522 36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nsheth 8:ca65a811c522 37 *******************************************************************************/
nsheth 8:ca65a811c522 38
nsheth 8:ca65a811c522 39 #ifndef SPI_H_
nsheth 8:ca65a811c522 40 #define SPI_H_
nsheth 8:ca65a811c522 41
nsheth 8:ca65a811c522 42 /******************************************************************************/
nsheth 8:ca65a811c522 43 /***************************** Include Files **********************************/
nsheth 8:ca65a811c522 44 /******************************************************************************/
nsheth 8:ca65a811c522 45
nsheth 8:ca65a811c522 46 #include <stdint.h>
nsheth 8:ca65a811c522 47
nsheth 8:ca65a811c522 48 /******************************************************************************/
nsheth 8:ca65a811c522 49 /********************** Macros and Constants Definitions **********************/
nsheth 8:ca65a811c522 50 /******************************************************************************/
nsheth 8:ca65a811c522 51
nsheth 8:ca65a811c522 52 #define SPI_CPHA 0x01
nsheth 8:ca65a811c522 53 #define SPI_CPOL 0x02
nsheth 8:ca65a811c522 54
nsheth 8:ca65a811c522 55 /******************************************************************************/
nsheth 8:ca65a811c522 56 /*************************** Types Declarations *******************************/
nsheth 8:ca65a811c522 57 /******************************************************************************/
nsheth 8:ca65a811c522 58
nsheth 8:ca65a811c522 59 typedef enum spi_mode {
nsheth 8:ca65a811c522 60 SPI_MODE_0 = (0 | 0),
nsheth 8:ca65a811c522 61 SPI_MODE_1 = (0 | SPI_CPHA),
nsheth 8:ca65a811c522 62 SPI_MODE_2 = (SPI_CPOL | 0),
nsheth 8:ca65a811c522 63 SPI_MODE_3 = (SPI_CPOL | SPI_CPHA)
nsheth 8:ca65a811c522 64 } spi_mode;
nsheth 8:ca65a811c522 65
nsheth 8:ca65a811c522 66 typedef struct spi_init_param {
nsheth 8:ca65a811c522 67 uint32_t max_speed_hz;
nsheth 8:ca65a811c522 68 uint8_t chip_select;
nsheth 8:ca65a811c522 69 enum spi_mode mode;
nsheth 8:ca65a811c522 70 void *extra;
nsheth 8:ca65a811c522 71 } spi_init_param;
nsheth 8:ca65a811c522 72
nsheth 8:ca65a811c522 73 typedef struct spi_desc {
nsheth 8:ca65a811c522 74 uint32_t max_speed_hz;
nsheth 8:ca65a811c522 75 uint8_t chip_select;
nsheth 8:ca65a811c522 76 enum spi_mode mode;
nsheth 8:ca65a811c522 77 void *extra;
nsheth 8:ca65a811c522 78 } spi_desc;
nsheth 8:ca65a811c522 79
nsheth 8:ca65a811c522 80 /******************************************************************************/
nsheth 8:ca65a811c522 81 /************************ Functions Declarations ******************************/
nsheth 8:ca65a811c522 82 /******************************************************************************/
nsheth 8:ca65a811c522 83
nsheth 8:ca65a811c522 84 /* Initialize the SPI communication peripheral. */
nsheth 8:ca65a811c522 85 int32_t spi_init(struct spi_desc **desc,
nsheth 8:ca65a811c522 86 const struct spi_init_param *param);
nsheth 8:ca65a811c522 87
nsheth 8:ca65a811c522 88 /* Free the resources allocated by spi_init(). */
nsheth 8:ca65a811c522 89 int32_t spi_remove(struct spi_desc *desc);
nsheth 8:ca65a811c522 90
nsheth 8:ca65a811c522 91 /* Write and read data to/from SPI. */
nsheth 8:ca65a811c522 92 int32_t spi_write_and_read(struct spi_desc *desc,
nsheth 8:ca65a811c522 93 uint8_t *data,
nsheth 8:ca65a811c522 94 uint16_t bytes_number);
nsheth 8:ca65a811c522 95
nsheth 8:ca65a811c522 96 #endif // SPI_H_