Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file |
| 3 | * |
| 4 | * \brief SPI related functionality declaration. |
| 5 | * |
| 6 | * Copyright (c) 2015-2018 Microchip Technology Inc. and its subsidiaries. |
| 7 | * |
| 8 | * \asf_license_start |
| 9 | * |
| 10 | * \page License |
| 11 | * |
| 12 | * Subject to your compliance with these terms, you may use Microchip |
| 13 | * software and any derivatives exclusively with Microchip products. |
| 14 | * It is your responsibility to comply with third party license terms applicable |
| 15 | * to your use of third party software (including open source software) that |
| 16 | * may accompany Microchip software. |
| 17 | * |
| 18 | * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, |
| 19 | * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, |
| 20 | * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, |
| 21 | * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE |
| 22 | * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL |
| 23 | * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE |
| 24 | * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE |
| 25 | * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT |
| 26 | * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY |
| 27 | * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, |
| 28 | * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. |
| 29 | * |
| 30 | * \asf_license_stop |
| 31 | * |
| 32 | */ |
| 33 | |
| 34 | #ifndef _HPL_SPI_M_SYNC_H_INCLUDED |
| 35 | #define _HPL_SPI_M_SYNC_H_INCLUDED |
| 36 | |
| 37 | #include <hpl_spi.h> |
| 38 | #include <hpl_spi_sync.h> |
| 39 | |
| 40 | /** |
| 41 | * \addtogroup hpl_spi HPL SPI |
| 42 | * |
| 43 | *@{ |
| 44 | */ |
| 45 | |
| 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 49 | |
Harald Welte | 863ea29 | 2019-02-24 10:05:12 +0100 | [diff] [blame] | 50 | /** Uses common SPI sync device driver. */ |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 51 | #define _spi_m_sync_dev _spi_sync_dev |
| 52 | |
| 53 | /** |
Harald Welte | 863ea29 | 2019-02-24 10:05:12 +0100 | [diff] [blame] | 54 | * \name HPL functions |
| 55 | */ |
| 56 | //@{ |
| 57 | /** |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 58 | * \brief Initialize SPI for access without interrupts |
| 59 | * It will load default hardware configuration and software struct. |
| 60 | * \param[in, out] dev Pointer to the SPI device instance. |
| 61 | * \param[in] hw Pointer to the hardware base. |
| 62 | * \return Operation status. |
| 63 | * \retval ERR_INVALID_ARG Input parameter problem. |
| 64 | * \retval ERR_BUSY SPI hardware not ready (resetting). |
| 65 | * \retval ERR_DENIED SPI has been enabled. |
| 66 | * \retval 0 Operation done successfully. |
| 67 | */ |
| 68 | int32_t _spi_m_sync_init(struct _spi_m_sync_dev *dev, void *const hw); |
| 69 | |
| 70 | /** |
| 71 | * \brief Deinitialize SPI |
| 72 | * Disable, reset the hardware and the software struct. |
| 73 | * \param[in, out] dev Pointer to the SPI device instance. |
| 74 | * \return Operation status. |
| 75 | * \retval 0 Operation done successfully. |
| 76 | */ |
| 77 | int32_t _spi_m_sync_deinit(struct _spi_m_sync_dev *dev); |
| 78 | |
| 79 | /** |
| 80 | * \brief Enable SPI for access without interrupts |
| 81 | * \param[in, out] dev Pointer to the SPI device instance. |
| 82 | * \return Operation status. |
| 83 | * \retval ERR_BUSY SPI hardware not ready (resetting). |
| 84 | * \retval 0 Operation done successfully. |
| 85 | */ |
| 86 | int32_t _spi_m_sync_enable(struct _spi_m_sync_dev *dev); |
| 87 | |
| 88 | /** |
| 89 | * \brief Disable SPI for access without interrupts |
| 90 | * Disable SPI. Deactivate all CS pins if works as master. |
| 91 | * \param[in, out] dev Pointer to the SPI device instance. |
| 92 | * \return Operation status. |
| 93 | * \retval 0 Operation done successfully. |
| 94 | */ |
| 95 | int32_t _spi_m_sync_disable(struct _spi_m_sync_dev *dev); |
| 96 | |
| 97 | /** |
| 98 | * \brief Set SPI transfer mode |
| 99 | * Set SPI transfer mode (\ref spi_transfer_mode), |
| 100 | * which controls clock polarity and clock phase. |
| 101 | * Mode 0: leading edge is rising edge, data sample on leading edge. |
| 102 | * Mode 1: leading edge is rising edge, data sample on trailing edge. |
| 103 | * Mode 2: leading edge is falling edge, data sample on leading edge. |
| 104 | * Mode 3: leading edge is falling edge, data sample on trailing edge. |
| 105 | * \param[in, out] dev Pointer to the SPI device instance. |
| 106 | * \param[in] mode The SPI transfer mode. |
| 107 | * \return Operation status. |
| 108 | * \retval ERR_BUSY SPI is not ready to accept new setting. |
| 109 | * \retval 0 Operation done successfully. |
| 110 | */ |
| 111 | int32_t _spi_m_sync_set_mode(struct _spi_m_sync_dev *dev, const enum spi_transfer_mode mode); |
| 112 | |
| 113 | /** |
| 114 | * \brief Set SPI baudrate |
| 115 | * \param[in, out] dev Pointer to the SPI device instance. |
| 116 | * \param[in] baud_val The SPI baudrate value, see \ref _spi_calc_baud_val() on |
| 117 | * how it's generated. |
| 118 | * \return Operation status. |
| 119 | * \retval ERR_BUSY SPI is not ready to accept new setting. |
| 120 | * \retval 0 Operation done successfully. |
| 121 | */ |
| 122 | int32_t _spi_m_sync_set_baudrate(struct _spi_m_sync_dev *dev, const uint32_t baud_val); |
| 123 | |
| 124 | /** |
Harald Welte | 863ea29 | 2019-02-24 10:05:12 +0100 | [diff] [blame] | 125 | * \brief Set SPI char size |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 126 | * \param[in, out] dev Pointer to the SPI device instance. |
| 127 | * \param[in] char_size The character size, see \ref spi_char_size. |
| 128 | * \return Operation status. |
| 129 | * \retval ERR_INVALID_ARG The character size is not supported. |
| 130 | * \retval ERR_BUSY SPI is not ready to accept new setting. |
| 131 | * \retval 0 Operation done successfully. |
| 132 | */ |
| 133 | int32_t _spi_m_sync_set_char_size(struct _spi_m_sync_dev *dev, const enum spi_char_size char_size); |
| 134 | |
| 135 | /** |
| 136 | * \brief Set SPI data order |
| 137 | * \param[in, out] dev Pointer to the SPI device instance. |
| 138 | * \param[in] dord SPI data order (LSB/MSB first). |
| 139 | * \return Operation status. |
| 140 | * \retval ERR_INVALID_ARG The character size is not supported. |
| 141 | * \retval ERR_BUSY SPI is not ready to accept new setting. |
| 142 | * \retval 0 Operation done successfully. |
| 143 | */ |
| 144 | int32_t _spi_m_sync_set_data_order(struct _spi_m_sync_dev *dev, const enum spi_data_order dord); |
| 145 | |
| 146 | /** |
| 147 | * \brief Transfer the whole message without interrupt |
| 148 | * Transfer the message, it will keep waiting until the message finish or |
| 149 | * error. |
| 150 | * \param[in, out] dev Pointer to the SPI device instance. |
| 151 | * \param[in] msg Pointer to the message instance to process. |
| 152 | * \return Error or number of characters transferred. |
| 153 | * \retval ERR_BUSY SPI hardware is not ready to start transfer (not |
| 154 | * enabled, busy applying settings, ...). |
| 155 | * \retval SPI_ERR_OVERFLOW Overflow error. |
| 156 | * \retval >=0 Number of characters transferred. |
| 157 | */ |
| 158 | int32_t _spi_m_sync_trans(struct _spi_m_sync_dev *dev, const struct spi_msg *msg); |
Harald Welte | 863ea29 | 2019-02-24 10:05:12 +0100 | [diff] [blame] | 159 | //@} |
Kévin Redon | 4cd3f7d | 2019-01-24 17:57:13 +0100 | [diff] [blame] | 160 | |
| 161 | #ifdef __cplusplus |
| 162 | } |
| 163 | #endif |
| 164 | |
| 165 | /**@}*/ |
| 166 | #endif /* ifndef _HPL_SPI_M_SYNC_H_INCLUDED */ |