mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 189:f392fc9709a3 1
AnnaBridge 189:f392fc9709a3 2 /** \addtogroup hal */
AnnaBridge 189:f392fc9709a3 3 /** @{*/
AnnaBridge 189:f392fc9709a3 4 /* mbed Microcontroller Library
AnnaBridge 189:f392fc9709a3 5 * Copyright (c) 2017 ARM Limited
AnnaBridge 189:f392fc9709a3 6 * SPDX-License-Identifier: Apache-2.0
AnnaBridge 189:f392fc9709a3 7 *
AnnaBridge 189:f392fc9709a3 8 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 189:f392fc9709a3 9 * you may not use this file except in compliance with the License.
AnnaBridge 189:f392fc9709a3 10 * You may obtain a copy of the License at
AnnaBridge 189:f392fc9709a3 11 *
AnnaBridge 189:f392fc9709a3 12 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 189:f392fc9709a3 13 *
AnnaBridge 189:f392fc9709a3 14 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 189:f392fc9709a3 15 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 189:f392fc9709a3 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 189:f392fc9709a3 17 * See the License for the specific language governing permissions and
AnnaBridge 189:f392fc9709a3 18 * limitations under the License.
AnnaBridge 189:f392fc9709a3 19 */
AnnaBridge 189:f392fc9709a3 20 #ifndef MBED_QSPI_API_H
AnnaBridge 189:f392fc9709a3 21 #define MBED_QSPI_API_H
AnnaBridge 189:f392fc9709a3 22
AnnaBridge 189:f392fc9709a3 23 #include "device.h"
AnnaBridge 189:f392fc9709a3 24 #include <stdbool.h>
AnnaBridge 189:f392fc9709a3 25
AnnaBridge 189:f392fc9709a3 26 #if DEVICE_QSPI
AnnaBridge 189:f392fc9709a3 27
AnnaBridge 189:f392fc9709a3 28 #ifdef __cplusplus
AnnaBridge 189:f392fc9709a3 29 extern "C" {
AnnaBridge 189:f392fc9709a3 30 #endif
AnnaBridge 189:f392fc9709a3 31
AnnaBridge 189:f392fc9709a3 32 /**
AnnaBridge 189:f392fc9709a3 33 * \defgroup hal_qspi QSPI HAL
AnnaBridge 189:f392fc9709a3 34 * @{
AnnaBridge 189:f392fc9709a3 35 */
AnnaBridge 189:f392fc9709a3 36
AnnaBridge 189:f392fc9709a3 37 /** QSPI HAL object
AnnaBridge 189:f392fc9709a3 38 */
AnnaBridge 189:f392fc9709a3 39 typedef struct qspi_s qspi_t;
AnnaBridge 189:f392fc9709a3 40
AnnaBridge 189:f392fc9709a3 41 /** QSPI Bus width
AnnaBridge 189:f392fc9709a3 42 *
AnnaBridge 189:f392fc9709a3 43 * Some parts of commands provide variable bus width
AnnaBridge 189:f392fc9709a3 44 */
AnnaBridge 189:f392fc9709a3 45 typedef enum qspi_bus_width {
AnnaBridge 189:f392fc9709a3 46 QSPI_CFG_BUS_SINGLE,
AnnaBridge 189:f392fc9709a3 47 QSPI_CFG_BUS_DUAL,
AnnaBridge 189:f392fc9709a3 48 QSPI_CFG_BUS_QUAD,
AnnaBridge 189:f392fc9709a3 49 } qspi_bus_width_t;
AnnaBridge 189:f392fc9709a3 50
AnnaBridge 189:f392fc9709a3 51 /** Address size in bits
AnnaBridge 189:f392fc9709a3 52 */
AnnaBridge 189:f392fc9709a3 53 typedef enum qspi_address_size {
AnnaBridge 189:f392fc9709a3 54 QSPI_CFG_ADDR_SIZE_8,
AnnaBridge 189:f392fc9709a3 55 QSPI_CFG_ADDR_SIZE_16,
AnnaBridge 189:f392fc9709a3 56 QSPI_CFG_ADDR_SIZE_24,
AnnaBridge 189:f392fc9709a3 57 QSPI_CFG_ADDR_SIZE_32,
AnnaBridge 189:f392fc9709a3 58 } qspi_address_size_t;
AnnaBridge 189:f392fc9709a3 59
AnnaBridge 189:f392fc9709a3 60 /** Alternative size in bits
AnnaBridge 189:f392fc9709a3 61 */
AnnaBridge 189:f392fc9709a3 62 typedef enum qspi_alt_size {
AnnaBridge 189:f392fc9709a3 63 QSPI_CFG_ALT_SIZE_8,
AnnaBridge 189:f392fc9709a3 64 QSPI_CFG_ALT_SIZE_16,
AnnaBridge 189:f392fc9709a3 65 QSPI_CFG_ALT_SIZE_24,
AnnaBridge 189:f392fc9709a3 66 QSPI_CFG_ALT_SIZE_32,
AnnaBridge 189:f392fc9709a3 67 } qspi_alt_size_t;
AnnaBridge 189:f392fc9709a3 68
AnnaBridge 189:f392fc9709a3 69 /** QSPI command
AnnaBridge 189:f392fc9709a3 70 *
AnnaBridge 189:f392fc9709a3 71 * Defines a frame format. It consists of instruction, address, alternative, dummy count and data
AnnaBridge 189:f392fc9709a3 72 */
AnnaBridge 189:f392fc9709a3 73 typedef struct qspi_command {
AnnaBridge 189:f392fc9709a3 74 struct {
AnnaBridge 189:f392fc9709a3 75 qspi_bus_width_t bus_width; /**< Bus width for the instruction >*/
AnnaBridge 189:f392fc9709a3 76 uint8_t value; /**< Instruction value >*/
AnnaBridge 189:f392fc9709a3 77 bool disabled; /**< Instruction phase skipped if disabled is set to true >*/
AnnaBridge 189:f392fc9709a3 78 } instruction;
AnnaBridge 189:f392fc9709a3 79 struct {
AnnaBridge 189:f392fc9709a3 80 qspi_bus_width_t bus_width; /**< Bus width for the address >*/
AnnaBridge 189:f392fc9709a3 81 qspi_address_size_t size; /**< Address size >*/
AnnaBridge 189:f392fc9709a3 82 uint32_t value; /**< Address value >*/
AnnaBridge 189:f392fc9709a3 83 bool disabled; /**< Address phase skipped if disabled is set to true >*/
AnnaBridge 189:f392fc9709a3 84 } address;
AnnaBridge 189:f392fc9709a3 85 struct {
AnnaBridge 189:f392fc9709a3 86 qspi_bus_width_t bus_width; /**< Bus width for alternative >*/
AnnaBridge 189:f392fc9709a3 87 qspi_alt_size_t size; /**< Alternative size >*/
AnnaBridge 189:f392fc9709a3 88 uint32_t value; /**< Alternative value >*/
AnnaBridge 189:f392fc9709a3 89 bool disabled; /**< Alternative phase skipped if disabled is set to true >*/
AnnaBridge 189:f392fc9709a3 90 } alt;
AnnaBridge 189:f392fc9709a3 91 uint8_t dummy_count; /**< Dummy cycles count >*/
AnnaBridge 189:f392fc9709a3 92 struct {
AnnaBridge 189:f392fc9709a3 93 qspi_bus_width_t bus_width; /**< Bus width for data >*/
AnnaBridge 189:f392fc9709a3 94 } data;
AnnaBridge 189:f392fc9709a3 95 } qspi_command_t;
AnnaBridge 189:f392fc9709a3 96
AnnaBridge 189:f392fc9709a3 97 /** QSPI return status
AnnaBridge 189:f392fc9709a3 98 */
AnnaBridge 189:f392fc9709a3 99 typedef enum qspi_status {
AnnaBridge 189:f392fc9709a3 100 QSPI_STATUS_ERROR = -1, /**< Generic error >*/
AnnaBridge 189:f392fc9709a3 101 QSPI_STATUS_INVALID_PARAMETER = -2, /**< The parameter is invalid >*/
AnnaBridge 189:f392fc9709a3 102 QSPI_STATUS_OK = 0, /**< Function executed sucessfully >*/
AnnaBridge 189:f392fc9709a3 103 } qspi_status_t;
AnnaBridge 189:f392fc9709a3 104
AnnaBridge 189:f392fc9709a3 105 /** Initialize QSPI peripheral.
AnnaBridge 189:f392fc9709a3 106 *
AnnaBridge 189:f392fc9709a3 107 * It should initialize QSPI pins (io0-io3, sclk and ssel), set frequency, clock polarity and phase mode. The clock for the peripheral should be enabled
AnnaBridge 189:f392fc9709a3 108 *
AnnaBridge 189:f392fc9709a3 109 * @param obj QSPI object
AnnaBridge 189:f392fc9709a3 110 * @param io0 Data pin 0
AnnaBridge 189:f392fc9709a3 111 * @param io1 Data pin 1
AnnaBridge 189:f392fc9709a3 112 * @param io2 Data pin 2
AnnaBridge 189:f392fc9709a3 113 * @param io3 Data pin 3
AnnaBridge 189:f392fc9709a3 114 * @param sclk The clock pin
AnnaBridge 189:f392fc9709a3 115 * @param ssel The chip select pin
AnnaBridge 189:f392fc9709a3 116 * @param hz The bus frequency
AnnaBridge 189:f392fc9709a3 117 * @param mode Clock polarity and phase mode (0 - 3)
AnnaBridge 189:f392fc9709a3 118 * @return QSPI_STATUS_OK if initialisation successfully executed
AnnaBridge 189:f392fc9709a3 119 QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
AnnaBridge 189:f392fc9709a3 120 QSPI_STATUS_ERROR otherwise
AnnaBridge 189:f392fc9709a3 121 */
AnnaBridge 189:f392fc9709a3 122 qspi_status_t qspi_init(qspi_t *obj, PinName io0, PinName io1, PinName io2, PinName io3, PinName sclk, PinName ssel, uint32_t hz, uint8_t mode);
AnnaBridge 189:f392fc9709a3 123
AnnaBridge 189:f392fc9709a3 124 /** Deinitilize QSPI peripheral
AnnaBridge 189:f392fc9709a3 125 *
AnnaBridge 189:f392fc9709a3 126 * It should release pins that are associated with the QSPI object, and disable clocks for QSPI peripheral module that was associated with the object
AnnaBridge 189:f392fc9709a3 127 *
AnnaBridge 189:f392fc9709a3 128 * @param obj QSPI object
AnnaBridge 189:f392fc9709a3 129 * @return QSPI_STATUS_OK if deinitialisation successfully executed
AnnaBridge 189:f392fc9709a3 130 QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
AnnaBridge 189:f392fc9709a3 131 QSPI_STATUS_ERROR otherwise
AnnaBridge 189:f392fc9709a3 132 */
AnnaBridge 189:f392fc9709a3 133 qspi_status_t qspi_free(qspi_t *obj);
AnnaBridge 189:f392fc9709a3 134
AnnaBridge 189:f392fc9709a3 135 /** Set the QSPI baud rate
AnnaBridge 189:f392fc9709a3 136 *
AnnaBridge 189:f392fc9709a3 137 * Actual frequency may differ from the desired frequency due to available dividers and the bus clock
AnnaBridge 189:f392fc9709a3 138 * Configures the QSPI peripheral's baud rate
AnnaBridge 189:f392fc9709a3 139 * @param obj The SPI object to configure
AnnaBridge 189:f392fc9709a3 140 * @param hz The baud rate in Hz
AnnaBridge 189:f392fc9709a3 141 * @return QSPI_STATUS_OK if frequency was set
AnnaBridge 189:f392fc9709a3 142 QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
AnnaBridge 189:f392fc9709a3 143 QSPI_STATUS_ERROR otherwise
AnnaBridge 189:f392fc9709a3 144 */
AnnaBridge 189:f392fc9709a3 145 qspi_status_t qspi_frequency(qspi_t *obj, int hz);
AnnaBridge 189:f392fc9709a3 146
AnnaBridge 189:f392fc9709a3 147 /** Send a command and block of data
AnnaBridge 189:f392fc9709a3 148 *
AnnaBridge 189:f392fc9709a3 149 * @param obj QSPI object
AnnaBridge 189:f392fc9709a3 150 * @param command QSPI command
AnnaBridge 189:f392fc9709a3 151 * @param data TX buffer
AnnaBridge 189:f392fc9709a3 152 * @param[in,out] length in - TX buffer length in bytes, out - number of bytes written
AnnaBridge 189:f392fc9709a3 153 * @return QSPI_STATUS_OK if the data has been succesfully sent
AnnaBridge 189:f392fc9709a3 154 QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
AnnaBridge 189:f392fc9709a3 155 QSPI_STATUS_ERROR otherwise
AnnaBridge 189:f392fc9709a3 156 */
AnnaBridge 189:f392fc9709a3 157 qspi_status_t qspi_write(qspi_t *obj, const qspi_command_t *command, const void *data, size_t *length);
AnnaBridge 189:f392fc9709a3 158
AnnaBridge 189:f392fc9709a3 159 /** Send a command (and optionally data) and get the response. Can be used to send/receive device specific commands
AnnaBridge 189:f392fc9709a3 160 *
AnnaBridge 189:f392fc9709a3 161 * @param obj QSPI object
AnnaBridge 189:f392fc9709a3 162 * @param command QSPI command
AnnaBridge 189:f392fc9709a3 163 * @param tx_data TX buffer
AnnaBridge 189:f392fc9709a3 164 * @param tx_size TX buffer length in bytes
AnnaBridge 189:f392fc9709a3 165 * @param rx_data RX buffer
AnnaBridge 189:f392fc9709a3 166 * @param rx_size RX buffer length in bytes
AnnaBridge 189:f392fc9709a3 167 * @return QSPI_STATUS_OK if the data has been succesfully sent
AnnaBridge 189:f392fc9709a3 168 QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
AnnaBridge 189:f392fc9709a3 169 QSPI_STATUS_ERROR otherwise
AnnaBridge 189:f392fc9709a3 170 */
AnnaBridge 189:f392fc9709a3 171 qspi_status_t qspi_command_transfer(qspi_t *obj, const qspi_command_t *command, const void *tx_data, size_t tx_size, void *rx_data, size_t rx_size);
AnnaBridge 189:f392fc9709a3 172
AnnaBridge 189:f392fc9709a3 173 /** Receive a command and block of data
AnnaBridge 189:f392fc9709a3 174 *
AnnaBridge 189:f392fc9709a3 175 * @param obj QSPI object
AnnaBridge 189:f392fc9709a3 176 * @param command QSPI command
AnnaBridge 189:f392fc9709a3 177 * @param data RX buffer
AnnaBridge 189:f392fc9709a3 178 * @param[in,out] length in - RX buffer length in bytes, out - number of bytes read
AnnaBridge 189:f392fc9709a3 179 * @return QSPI_STATUS_OK if data has been succesfully received
AnnaBridge 189:f392fc9709a3 180 QSPI_STATUS_INVALID_PARAMETER if invalid parameter found
AnnaBridge 189:f392fc9709a3 181 QSPI_STATUS_ERROR otherwise
AnnaBridge 189:f392fc9709a3 182 */
AnnaBridge 189:f392fc9709a3 183 qspi_status_t qspi_read(qspi_t *obj, const qspi_command_t *command, void *data, size_t *length);
AnnaBridge 189:f392fc9709a3 184
AnnaBridge 189:f392fc9709a3 185 /**@}*/
AnnaBridge 189:f392fc9709a3 186
AnnaBridge 189:f392fc9709a3 187 #ifdef __cplusplus
AnnaBridge 189:f392fc9709a3 188 }
AnnaBridge 189:f392fc9709a3 189 #endif
AnnaBridge 189:f392fc9709a3 190
AnnaBridge 189:f392fc9709a3 191 #endif
AnnaBridge 189:f392fc9709a3 192
AnnaBridge 189:f392fc9709a3 193 #endif
AnnaBridge 189:f392fc9709a3 194
AnnaBridge 189:f392fc9709a3 195 /** @}*/