2 * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #include "Driver_SPI.h"
21 #define ARM_SPI_DRV_VERSION ARM_DRIVER_VERSION_MAJOR_MINOR(1, 0) /* driver version */
24 static const ARM_DRIVER_VERSION DriverVersion = {
29 /* Driver Capabilities */
30 static const ARM_SPI_CAPABILITIES DriverCapabilities = {
31 0, /* Reserved (must be zero) */
32 0, /* TI Synchronous Serial Interface */
33 0, /* Microwire Interface */
34 0, /* Signal Mode Fault event: \ref ARM_SPI_EVENT_MODE_FAULT */
35 0 /* Reserved (must be zero) */
42 static ARM_DRIVER_VERSION ARM_SPI_GetVersion(void)
47 static ARM_SPI_CAPABILITIES ARM_SPI_GetCapabilities(void)
49 return DriverCapabilities;
52 static int32_t ARM_SPI_Initialize(ARM_SPI_SignalEvent_t cb_event)
56 static int32_t ARM_SPI_Uninitialize(void)
60 static int32_t ARM_SPI_PowerControl(ARM_POWER_STATE state)
76 static int32_t ARM_SPI_Send(const void *data, uint32_t num)
80 static int32_t ARM_SPI_Receive(void *data, uint32_t num)
84 static int32_t ARM_SPI_Transfer(const void *data_out, void *data_in, uint32_t num)
88 static uint32_t ARM_SPI_GetDataCount(void)
92 static int32_t ARM_SPI_Control(uint32_t control, uint32_t arg)
94 switch (control & ARM_SPI_CONTROL_Msk)
97 return ARM_DRIVER_ERROR_UNSUPPORTED;
99 case ARM_SPI_MODE_INACTIVE: // SPI Inactive
100 return ARM_DRIVER_OK;
102 case ARM_SPI_MODE_MASTER: // SPI Master (Output on MOSI, Input on MISO); arg = Bus Speed in bps
105 case ARM_SPI_MODE_SLAVE: // SPI Slave (Output on MISO, Input on MOSI)
108 case ARM_SPI_SET_BUS_SPEED: // Set Bus Speed in bps; arg = value
111 case ARM_SPI_GET_BUS_SPEED: // Get Bus Speed in bps
114 case ARM_SPI_SET_DEFAULT_TX_VALUE: // Set default Transmit value; arg = value
117 case ARM_SPI_CONTROL_SS: // Control Slave Select; arg = 0:inactive, 1:active
120 case ARM_SPI_ABORT_TRANSFER: // Abort current data transfer
125 static ARM_SPI_STATUS ARM_SPI_GetStatus(void)
129 static void ARM_SPI_SignalEvent(uint32_t event)
137 ARM_DRIVER_SPI Driver_SPI0;
138 ARM_DRIVER_SPI Driver_SPI0 = {
140 ARM_SPI_GetCapabilities,
142 ARM_SPI_Uninitialize,
143 ARM_SPI_PowerControl,
147 ARM_SPI_GetDataCount,