forked from ossw/ossw-firmware-s120
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spi.h
83 lines (66 loc) · 3.31 KB
/
spi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef SPI_H
#define SPI_H
#include <stdbool.h>
#include <stdint.h>
#include "nrf_gpio.h"
/** @file
* @brief Software controlled SPI Master driver.
*
*
* @defgroup lib_driver_spi_master Software controlled SPI Master driver
* @{
* @ingroup nrf_drivers
* @brief Software controlled SPI Master driver.
*
* Supported features:
* - Operate two SPI masters independently or in parallel.
* - Transmit and Receive given size of data through SPI.
* - configure each SPI module separately through @ref spi_master_init.
*/
/**
* SPI master operating frequency
*/
typedef enum
{
Freq_125Kbps = 0, /*!< drive SClk with frequency 125Kbps */
Freq_250Kbps, /*!< drive SClk with frequency 250Kbps */
Freq_500Kbps, /*!< drive SClk with frequency 500Kbps */
Freq_1Mbps, /*!< drive SClk with frequency 1Mbps */
Freq_2Mbps, /*!< drive SClk with frequency 2Mbps */
Freq_4Mbps, /*!< drive SClk with frequency 4Mbps */
Freq_8Mbps /*!< drive SClk with frequency 8Mbps */
} SPIFrequency_t;
/**
* SPI master module number
*/
typedef enum
{
SPI0 = 0, /*!< SPI module 0 */
SPI1 /*!< SPI module 1 */
} SPIModuleNumber;
/**
* SPI mode
*/
typedef enum
{
//------------------------Clock polarity 0, Clock starts with level 0-------------------------------------------
SPI_MODE0 = 0, /*!< Sample data at rising edge of clock and shift serial data at falling edge */
SPI_MODE1, /*!< sample data at falling edge of clock and shift serial data at rising edge */
//------------------------Clock polarity 1, Clock starts with level 1-------------------------------------------
SPI_MODE2, /*!< sample data at falling edge of clock and shift serial data at rising edge */
SPI_MODE3 /*!< Sample data at rising edge of clock and shift serial data at falling edge */
} SPIMode;
void spi_init(void);
bool spi_master_tx_rx(uint32_t *spi_base_address, uint32_t device, uint16_t transfer_size, const uint8_t *tx_data, uint8_t *rx_data);
bool spi_master_tx(uint32_t *spi_base_address, uint32_t device, const uint8_t* command, uint16_t command_size);
bool spi_master_tx_data(uint32_t *spi_base_address, uint32_t device, const uint8_t* command, uint16_t command_size, const uint8_t* tx_data, uint32_t tx_data_size);
bool spi_master_tx_data_no_cs(uint32_t *spi_base, const uint8_t* tx_data, uint32_t tx_data_size);
bool spi_master_rx_data(uint32_t *spi_base_address, uint32_t device, const uint8_t* command, uint16_t command_size, uint8_t* rx_data, uint32_t rx_data_size, bool* has_changed);
bool spi_master_rx_text(uint32_t *spi_base_address, uint32_t device, const uint8_t* command, uint16_t command_size, uint8_t* rx_data, uint32_t max_rx_data_size, bool* has_changed);
bool spi_master_rx_data_no_cs(uint32_t *spi_base, uint8_t* rx_data, uint32_t rx_data_size, bool stop_on_zero, bool* has_changed);
bool spi_master_rx_to_tx_no_cs(uint32_t *src_spi_base, uint32_t *dest_spi_base, uint32_t data_size, bool revert);
bool spi_master_tx_value(uint32_t *spi_base_address, uint32_t device, const uint8_t* command, uint16_t command_size, uint8_t value, uint32_t tx_data_size);
/**
*@}
**/
#endif /* SPI_H */