SPI master common service for SAM. More...
#include "compiler.h"
#include "sysclk.h"
#include "status_codes.h"
#include "spi.h"
#include "conf_spi_master.h"
Go to the source code of this file.
Classes | |
struct | spi_device |
Polled SPI device definition. More... | |
Macros | |
#define | SPI_CPHA (1 << 0) |
Clock phase. More... | |
#define | SPI_CPOL (1 << 1) |
Clock polarity. More... | |
#define | SPI_MODE_0 0 |
SPI mode 0. More... | |
#define | SPI_MODE_1 (SPI_CPHA) |
SPI mode 1. More... | |
#define | SPI_MODE_2 (SPI_CPOL) |
SPI mode 2. More... | |
#define | SPI_MODE_3 (SPI_CPOL | SPI_CPHA) |
SPI mode 3. More... | |
#define | SPI_TYPE_DEFS |
SPI Master Management Configuration | |
#define | CONFIG_SPI_MASTER_DELAY_BCS 0 |
Default Configuration of SPI Master Delay BCS. More... | |
#define | CONFIG_SPI_MASTER_BITS_PER_TRANSFER SPI_CSR_BITS_8_BIT |
Default Configuration of SPI Master Bits per Transfer Definition. More... | |
#define | CONFIG_SPI_MASTER_DELAY_BCT 0 |
Default Configuration of SPI Master Delay BCT. More... | |
#define | CONFIG_SPI_MASTER_DELAY_BS 0 |
Default Configuration of SPI Master Delay BS. More... | |
#define | CONFIG_SPI_MASTER_DUMMY 0xFF |
Default Configuration of SPI Master Dummy Field. More... | |
Typedefs | |
typedef uint32_t | board_spi_select_id_t |
Board SPI Select Id Definition. More... | |
typedef uint8_t | spi_flags_t |
SPI Flags Definition. More... | |
Functions | |
void | spi_deselect_device (Spi *p_spi, struct spi_device *device) |
Deselect the given device on the SPI bus. More... | |
void | spi_master_init (Spi *p_spi) |
Initialize the SPI in master mode. More... | |
void | spi_master_setup_device (Spi *p_spi, struct spi_device *device, spi_flags_t flags, uint32_t baud_rate, board_spi_select_id_t sel_id) |
Set up an SPI device. More... | |
status_code_t | spi_read_packet (Spi *p_spi, uint8_t *data, size_t len) |
Receive a sequence of bytes from an SPI device. More... | |
static void | spi_read_single (Spi *p_spi, uint8_t *data) |
Receive one byte from an SPI device. More... | |
void | spi_select_device (Spi *p_spi, struct spi_device *device) |
Select the given device on the SPI bus. More... | |
status_code_t | spi_transceive_packet (Spi *p_spi, uint8_t *tx_data, uint8_t *rx_data, size_t len) |
Send and receive a sequence of bytes from an SPI device. More... | |
status_code_t | spi_write_packet (Spi *p_spi, const uint8_t *data, size_t len) |
Send a sequence of bytes to an SPI device. More... | |
static void | spi_write_single (Spi *p_spi, uint8_t data) |
Write one byte to an SPI device. More... | |
SPI master common service for SAM.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
Definition in file sam_spi/spi_master.h.
#define CONFIG_SPI_MASTER_BITS_PER_TRANSFER SPI_CSR_BITS_8_BIT |
Default Configuration of SPI Master Bits per Transfer Definition.
Definition at line 64 of file sam_spi/spi_master.h.
#define CONFIG_SPI_MASTER_DELAY_BCS 0 |
Default Configuration of SPI Master Delay BCS.
Definition at line 59 of file sam_spi/spi_master.h.
#define CONFIG_SPI_MASTER_DELAY_BCT 0 |
Default Configuration of SPI Master Delay BCT.
Definition at line 69 of file sam_spi/spi_master.h.
#define CONFIG_SPI_MASTER_DELAY_BS 0 |
Default Configuration of SPI Master Delay BS.
Definition at line 74 of file sam_spi/spi_master.h.
#define CONFIG_SPI_MASTER_DUMMY 0xFF |
Default Configuration of SPI Master Dummy Field.
Definition at line 79 of file sam_spi/spi_master.h.
#define SPI_CPHA (1 << 0) |
Clock phase.
Definition at line 86 of file sam_spi/spi_master.h.
#define SPI_CPOL (1 << 1) |
Clock polarity.
Definition at line 91 of file sam_spi/spi_master.h.
#define SPI_MODE_0 0 |
SPI mode 0.
Definition at line 96 of file sam_spi/spi_master.h.
#define SPI_MODE_1 (SPI_CPHA) |
SPI mode 1.
Definition at line 100 of file sam_spi/spi_master.h.
#define SPI_MODE_2 (SPI_CPOL) |
SPI mode 2.
Definition at line 104 of file sam_spi/spi_master.h.
SPI mode 3.
Definition at line 108 of file sam_spi/spi_master.h.
#define SPI_TYPE_DEFS |
Definition at line 111 of file sam_spi/spi_master.h.
typedef uint32_t board_spi_select_id_t |
Board SPI Select Id Definition.
Definition at line 116 of file sam_spi/spi_master.h.
typedef uint8_t spi_flags_t |
SPI Flags Definition.
Definition at line 113 of file sam_spi/spi_master.h.
void spi_deselect_device | ( | Spi * | p_spi, |
struct spi_device * | device | ||
) |
Deselect the given device on the SPI bus.
Call board chip deselect.
p_spi | Base address of the SPI instance. |
device | SPI device. |
Definition at line 155 of file spi_master.c.
void spi_master_init | ( | Spi * | p_spi | ) |
Initialize the SPI in master mode.
p_spi | Base address of the SPI instance. |
Definition at line 68 of file spi_master.c.
void spi_master_setup_device | ( | Spi * | p_spi, |
struct spi_device * | device, | ||
spi_flags_t | flags, | ||
uint32_t | baud_rate, | ||
board_spi_select_id_t | sel_id | ||
) |
Set up an SPI device.
The returned device descriptor structure must be passed to the driver whenever that device should be used as current slave device.
p_spi | Base address of the SPI instance. |
device | Pointer to SPI device struct that should be initialized. |
flags | SPI configuration flags. Common flags for all implementations are the SPI modes SPI_MODE_0 ... SPI_MODE_3. |
baud_rate | Baud rate for communication with slave device in Hz. |
sel_id | Board specific select id. |
Definition at line 100 of file spi_master.c.
status_code_t spi_read_packet | ( | Spi * | p_spi, |
uint8_t * | data, | ||
size_t | len | ||
) |
Receive a sequence of bytes from an SPI device.
All bytes sent out on SPI bus are sent as value 0xff.
p_spi | Base address of the SPI instance. |
data | Data buffer to read. |
len | Length of data to be read. |
All bytes sent out on SPI bus are sent as value 0.
p_spi | Base address of the SPI instance. |
data | Data buffer to read. |
len | Length of data to be read. |
Definition at line 215 of file spi_master.c.
|
inlinestatic |
Receive one byte from an SPI device.
p_spi | Base address of the SPI instance. |
data | Data to read. |
Definition at line 204 of file sam_spi/spi_master.h.
void spi_select_device | ( | Spi * | p_spi, |
struct spi_device * | device | ||
) |
Select the given device on the SPI bus.
Set device specific setting and call board chip select.
p_spi | Base address of the SPI instance. |
device | SPI device. |
Definition at line 132 of file spi_master.c.
status_code_t spi_transceive_packet | ( | Spi * | p_spi, |
uint8_t * | tx_data, | ||
uint8_t * | rx_data, | ||
size_t | len | ||
) |
Send and receive a sequence of bytes from an SPI device.
p_spi | Base address of the SPI instance. |
tx_data | Data buffer to send. |
rx_data | Data buffer to read. |
len | Length of data to be read. |
Definition at line 256 of file spi_master.c.
status_code_t spi_write_packet | ( | Spi * | p_spi, |
const uint8_t * | data, | ||
size_t | len | ||
) |
Send a sequence of bytes to an SPI device.
Received bytes on the SPI bus are discarded.
p_spi | Base address of the SPI instance. |
data | Data buffer to write. |
len | Length of data to be written. |
Definition at line 181 of file spi_master.c.
|
inlinestatic |
Write one byte to an SPI device.
p_spi | Base address of the SPI instance. |
data | Data to write. |
Definition at line 179 of file sam_spi/spi_master.h.