mikroSDK Reference Manual
drv_spi_master.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2023 MikroElektronika d.o.o.
4 ** Contact: https://www.mikroe.com/contact
5 **
6 ** This file is part of the mikroSDK package
7 **
8 ** Commercial License Usage
9 **
10 ** Licensees holding valid commercial NECTO compilers AI licenses may use this
11 ** file in accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The MikroElektronika Company.
14 ** For licensing terms and conditions see
15 ** https://www.mikroe.com/legal/software-license-agreement.
16 ** For further information use the contact form at
17 ** https://www.mikroe.com/contact.
18 **
19 **
20 ** GNU Lesser General Public License Usage
21 **
22 ** Alternatively, this file may be used for
23 ** non-commercial projects under the terms of the GNU Lesser
24 ** General Public License version 3 as published by the Free Software
25 ** Foundation: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** The above copyright notice and this permission notice shall be
28 ** included in all copies or substantial portions of the Software.
29 **
30 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31 ** OF MERCHANTABILITY, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
32 ** TO THE WARRANTIES FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
34 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
35 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36 ** OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 **
38 ****************************************************************************/
44 #ifndef _DRV_SPI_MASTER_H_
45 #define _DRV_SPI_MASTER_H_
46 
47 #ifdef __cplusplus
48 extern "C"{
49 #endif
50 
51 #include "drv_name.h"
52 #include "generic_pointer.h"
53 #include "drv_digital_out.h"
54 #include "hal_spi_master.h"
55 
59 typedef enum
60 {
64 
70 typedef enum {
78 
82 typedef enum
83 {
88 
90  SPI_MASTER_CHIP_SELECT_DEFAULT_POLARITY = SPI_MASTER_CHIP_SELECT_POLARITY_ACTIVE_LOW
92 
125 typedef struct
126 {
131  uint32_t speed;
134 
141 typedef struct
142 {
143  handle_t handle;
145 } spi_master_t;
146 
197 
251 
267 void spi_master_select_device( pin_name_t chip_select );
268 
284 void spi_master_deselect_device( pin_name_t chip_select );
285 
300 
325 err_t spi_master_set_default_write_data( spi_master_t *obj, uint8_t default_write_data );
326 
353 err_t spi_master_set_speed( spi_master_t *obj, uint32_t speed );
354 
382 
423 err_t spi_master_write( spi_master_t *obj, uint8_t * __generic_ptr write_data_buffer,
424  size_t write_data_length );
425 
460 err_t spi_master_read( spi_master_t *obj, uint8_t *read_data_buffer,
461  size_t read_data_length );
462 
513 err_t spi_master_write_then_read( spi_master_t *obj, uint8_t *write_data_buffer,
514  size_t length_write_data,
515  uint8_t *read_data_buffer,
516  size_t length_read_data );
517 
542  // drvspigroup // drvgroup // pergroup
546 
547 #ifdef __cplusplus
548 }
549 #endif
550 
551 #endif // _DRV_SPI_MASTER_H_
552 // ------------------------------------------------------------------------- END
SPI_MASTER_MODE_2
Definition: drv_spi_master.h:73
drv_name.h
Pin and port name type definitions.
spi_master_config_t::default_write_data
uint8_t default_write_data
Definition: drv_spi_master.h:127
spi_master_t
The SPI Master driver context structure.
Definition: drv_spi_master.h:141
spi_master_config_t::mode
spi_master_mode_t mode
Definition: drv_spi_master.h:132
spi_master_set_speed
err_t spi_master_set_speed(spi_master_t *obj, uint32_t speed)
Set SPI Master driver communication speed.
SPI_MASTER_MODE_DEFAULT
Definition: drv_spi_master.h:76
SPI_MASTER_MODE_0
Definition: drv_spi_master.h:71
spi_master_write
err_t spi_master_write(spi_master_t *obj, uint8_t *__generic_ptr write_data_buffer, size_t write_data_length)
Write byte to SPI bus.
spi_master_config_t::miso
pin_name_t miso
Definition: drv_spi_master.h:129
spi_master_err_t
spi_master_err_t
Definition: drv_spi_master.h:59
spi_master_config_t
The SPI Master driver configuration structure.
Definition: drv_spi_master.h:125
SPI_MASTER_CHIP_SELECT_POLARITY_ACTIVE_LOW
Definition: drv_spi_master.h:85
spi_master_config_t::speed
uint32_t speed
Definition: drv_spi_master.h:131
spi_master_close
err_t spi_master_close(spi_master_t *obj)
Close SPI Master Driver context object.
spi_master_select_device
void spi_master_select_device(pin_name_t chip_select)
Select SPI Slave device.
SPI_MASTER_ERROR
Definition: drv_spi_master.h:62
spi_master_deselect_device
void spi_master_deselect_device(pin_name_t chip_select)
Deselect SPI Slave device.
SPI_MASTER_SUCCESS
Definition: drv_spi_master.h:61
spi_master_t::config
spi_master_config_t config
Definition: drv_spi_master.h:144
spi_master_set_mode
err_t spi_master_set_mode(spi_master_t *obj, spi_master_mode_t mode)
Set SPI Master driver communication mode.
spi_master_t::handle
handle_t handle
Definition: drv_spi_master.h:143
spi_master_set_chip_select_polarity
void spi_master_set_chip_select_polarity(spi_master_chip_select_polarity_t polarity)
Set desired SPI Master chip select polarity.
SPI_MASTER_MODE_3
Definition: drv_spi_master.h:74
spi_master_open
err_t spi_master_open(spi_master_t *obj, spi_master_config_t *config)
Open the SPI Master driver object on selected pins.
spi_master_read
err_t spi_master_read(spi_master_t *obj, uint8_t *read_data_buffer, size_t read_data_length)
Read byte from SPI bus.
spi_master_configure_default
void spi_master_configure_default(spi_master_config_t *config)
Configure SPI Master configuration structure.
SPI_MASTER_CHIP_SELECT_POLARITY_ACTIVE_HIGH
Definition: drv_spi_master.h:87
pin_name_t
hal_pin_name_t pin_name_t
Definition: drv_name.h:73
spi_master_mode_t
spi_master_mode_t
Definition: drv_spi_master.h:70
drv_digital_out.h
API for Digital output driver.
spi_master_write_then_read
err_t spi_master_write_then_read(spi_master_t *obj, uint8_t *write_data_buffer, size_t length_write_data, uint8_t *read_data_buffer, size_t length_read_data)
Perform a sequence of SPI Master writes immediately followed by a SPI Master read.
spi_master_config_t::sck
pin_name_t sck
Definition: drv_spi_master.h:128
err_t
int32_t err_t
Definition: hal_target.h:63
SPI_MASTER_MODE_1
Definition: drv_spi_master.h:72
spi_master_config_t::mosi
pin_name_t mosi
Definition: drv_spi_master.h:130
spi_master_set_default_write_data
err_t spi_master_set_default_write_data(spi_master_t *obj, uint8_t default_write_data)
Set SPI Master driver default ( dummy ) write data.
hal_spi_master.h
API for SPI Master HAL layer.
spi_master_chip_select_polarity_t
spi_master_chip_select_polarity_t
Definition: drv_spi_master.h:82