SAM Serial Peripheral Interface Driver.
Copyright (c) 2012-2020 Microchip Technology Inc. and its subsidiaries.
#include "spi.h"
Functions | |
static enum status_code | _spi_check_config (struct spi_module *const module, const struct spi_config *const config) |
static void | _spi_clear_tx_complete_flag (struct spi_module *const module) |
static enum status_code | _spi_set_config (struct spi_module *const module, const struct spi_config *const config) |
enum status_code | spi_init (struct spi_module *const module, Sercom *const hw, const struct spi_config *const config) |
Initializes the SERCOM SPI module. More... | |
enum status_code | spi_read_buffer_wait (struct spi_module *const module, uint8_t *rx_data, uint16_t length, uint16_t dummy) |
Reads buffer of length SPI characters. More... | |
void | spi_reset (struct spi_module *const module) |
Resets the SPI module. More... | |
enum status_code | spi_select_slave (struct spi_module *const module, struct spi_slave_inst *const slave, const bool select) |
Selects slave device. More... | |
enum status_code | spi_set_baudrate (struct spi_module *const module, uint32_t baudrate) |
Set the baudrate of the SPI module. More... | |
enum status_code | spi_transceive_buffer_wait (struct spi_module *const module, uint8_t *tx_data, uint8_t *rx_data, uint16_t length) |
Sends and receives a buffer of length SPI characters. More... | |
enum status_code | spi_transceive_wait (struct spi_module *const module, uint16_t tx_data, uint16_t *rx_data) |
Sends and reads a single SPI character. More... | |
enum status_code | spi_write_buffer_wait (struct spi_module *const module, const uint8_t *tx_data, uint16_t length) |
Sends a buffer of length SPI characters. More... | |
|
static |
Checks an SPI config against current set config
This function will check that the config does not alter the configuration of the module. If the new config changes any setting, the initialization will be discarded.
[in] | module | Pointer to the software instance struct |
[in] | config | Pointer to the configuration struct |
STATUS_ERR_INVALID_ARG | If invalid argument(s) were provided |
STATUS_ERR_DENIED | If configuration was different from previous |
STATUS_OK | If the configuration was written |
References _sercom_get_default_pad(), _sercom_get_sync_baud_val(), spi_slave_config::address, spi_slave_config::address_mask, spi_slave_config::address_mode, Assert, spi_master_config::baudrate, spi_config::character_size, spi_config::data_order, spi_slave_config::frame_format, spi_config::master, spi_config::master_slave_select_enable, spi_config::mode, spi_config::mode_specific, spi_config::mux_setting, NULL, PINMUX_DEFAULT, spi_config::pinmux_pad0, spi_config::pinmux_pad1, spi_config::pinmux_pad2, spi_config::pinmux_pad3, PINMUX_UNUSED, spi_slave_config::preload_enable, spi_config::receiver_enable, spi_config::run_in_standby, spi_config::select_slave_low_detect_enable, SERCOM_GCLK_ID, spi_config::slave, SPI_MODE_MASTER, SPI_MODE_SLAVE, STATUS_ERR_DENIED, STATUS_ERR_INVALID_ARG, STATUS_OK, system_gclk_chan_get_hz(), system_pinmux_pin_get_mux_position(), and spi_config::transfer_mode.
Referenced by spi_init().
|
static |
Clears the Transmit Complete interrupt flag.
[in] | module | Pointer to the software instance struct |
References Assert, and SPI_INTERRUPT_FLAG_TX_COMPLETE.
Referenced by spi_read_buffer_wait(), spi_transceive_buffer_wait(), and spi_write_buffer_wait().
|
static |
Writes an SPI SERCOM configuration to the hardware module.
This function will write out a given configuration to the hardware module. Can only be done when the module is disabled.
[in] | module | Pointer to the software instance struct |
[in] | config | Pointer to the configuration struct |
STATUS_ERR_INVALID_ARG | If invalid argument(s) were provided |
STATUS_OK | If the configuration was written |
References _sercom_get_default_pad(), _sercom_get_sercom_inst_index(), _sercom_get_sync_baud_val(), spi_slave_config::address, spi_slave_config::address_mask, spi_slave_config::address_mode, Assert, spi_master_config::baudrate, spi_config::character_size, spi_config::data_order, system_pinmux_config::direction, spi_slave_config::frame_format, system_pinmux_config::input_pull, spi_config::master, spi_config::master_slave_select_enable, spi_config::mode, spi_config::mode_specific, system_pinmux_config::mux_position, spi_config::mux_setting, PINMUX_DEFAULT, spi_config::pinmux_pad0, spi_config::pinmux_pad1, spi_config::pinmux_pad2, spi_config::pinmux_pad3, PINMUX_UNUSED, spi_slave_config::preload_enable, spi_config::receiver_enable, spi_config::run_in_standby, spi_config::select_slave_low_detect_enable, spi_config::slave, SPI_MODE_MASTER, SPI_MODE_SLAVE, STATUS_ERR_INVALID_ARG, STATUS_OK, system_gclk_chan_get_hz(), system_is_debugger_present(), system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_INPUT, SYSTEM_PINMUX_PIN_PULL_NONE, system_pinmux_pin_set_config(), and spi_config::transfer_mode.
Referenced by spi_init().