mikroSDK Reference Manual
hal_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 _HAL_SPI_MASTER_H_
45 #define _HAL_SPI_MASTER_H_
46 
47 #ifdef __cplusplus
48 extern "C"{
49 #endif
50 
51 #include "hal_target.h"
52 #include "generic_pointer.h"
53 #include "hal_ll_spi_master.h"
54 #include "hal_gpio.h"
55 
64 typedef struct
65 {
68  bool init_state;
70 
74 typedef enum
75 {
83 
87 typedef enum
88 {
93 
123 typedef struct
124 {
129  uint32_t speed;
132 
146 typedef struct
147 {
148  handle_t handle;
151 
155 typedef enum {
161 
209 
257 err_t hal_spi_master_open( handle_t *handle, bool hal_obj_open_state );
258 
274 void hal_spi_master_select_device( hal_pin_name_t chip_select );
275 
292 
308 
326 void hal_spi_master_set_default_write_data( handle_t *handle,
327  hal_spi_master_config_t *config );
328 
349 err_t hal_spi_master_set_speed( handle_t *handle, hal_spi_master_config_t *config );
350 
371 err_t hal_spi_master_set_mode( handle_t *handle, hal_spi_master_config_t *config );
372 
406 err_t hal_spi_master_write( handle_t handle, uint8_t * __generic_ptr write_data_buffer,
407  size_t write_data_length );
408 
436 err_t hal_spi_master_read( handle_t handle, uint8_t *read_data_buffer,
437  size_t read_data_length );
438 
484 err_t hal_spi_master_write_then_read( handle_t handle, uint8_t *write_data_buffer,
485  size_t length_write_data,
486  uint8_t *read_data_buffer,
487  size_t length_read_data );
488 
505 err_t hal_spi_master_close( handle_t *handle );
506  // halspimastergroup // halgroup // pergroup
510 
511 #ifdef __cplusplus
512 }
513 #endif
514 
515 #endif // _HAL_SPI_MASTER_H_
516 // ------------------------------------------------------------------------- END
HAL_SPI_MASTER_CHIP_SELECT_POLARITY_ACTIVE_HIGH
Definition: hal_spi_master.h:90
hal_spi_master_t::config
hal_spi_master_config_t config
Definition: hal_spi_master.h:149
hal_spi_master_close
err_t hal_spi_master_close(handle_t *handle)
Close SPI Master HAL context object.
hal_spi_master_open
err_t hal_spi_master_open(handle_t *handle, bool hal_obj_open_state)
Open the SPI Master HAL object on selected pins.
hal_spi_master_config_t
HAL SPI Master init configuration structure, consisted of the following fields :
Definition: hal_spi_master.h:123
hal_spi_master_t
SPI master HAL context structure, consisted of the following fields :
Definition: hal_spi_master.h:146
hal_spi_master_config_t::speed
uint32_t speed
Definition: hal_spi_master.h:129
HAL_SPI_MASTER_CHIP_SELECT_POLARITY_ACTIVE_LOW
Definition: hal_spi_master.h:89
hal_spi_master_set_speed
err_t hal_spi_master_set_speed(handle_t *handle, hal_spi_master_config_t *config)
Set desired SPI communication speed.
hal_spi_master_select_device
void hal_spi_master_select_device(hal_pin_name_t chip_select)
Select SPI Slave device.
hal_spi_master_config_t::miso
hal_pin_name_t miso
Definition: hal_spi_master.h:127
hal_spi_master_mode_t
hal_spi_master_mode_t
Definition: hal_spi_master.h:74
HAL_SPI_MASTER_ERROR
Definition: hal_spi_master.h:159
HAL_SPI_MASTER_MODE_DEFAULT
Definition: hal_spi_master.h:81
hal_spi_master_write
err_t hal_spi_master_write(handle_t handle, uint8_t *__generic_ptr write_data_buffer, size_t write_data_length)
Write byte to SPI bus.
hal_spi_master_err_t
hal_spi_master_err_t
Definition: hal_spi_master.h:155
hal_spi_master_config_t::mode
hal_spi_master_mode_t mode
Definition: hal_spi_master.h:130
hal_target.h
HAL target macros and typedefs.
HAL_SPI_MASTER_MODE_3
Definition: hal_spi_master.h:79
hal_spi_master_set_mode
err_t hal_spi_master_set_mode(handle_t *handle, hal_spi_master_config_t *config)
Set desired SPI communication mode.
hal_pin_name_t
hal_ll_pin_name_t hal_pin_name_t
Definition: hal_target.h:59
hal_gpio.h
This file contains all the functions prototypes for the GPIO library.
hal_spi_master_handle_register_t::hal_spi_master_handle
handle_t * hal_spi_master_handle
Definition: hal_spi_master.h:66
HAL_SPI_MASTER_MODE_0
Definition: hal_spi_master.h:76
hal_spi_master_deselect_device
void hal_spi_master_deselect_device(hal_pin_name_t chip_select)
Deselect SPI Slave device.
HAL_SPI_MASTER_CHIP_SELECT_DEFAULT_POLARITY
Definition: hal_spi_master.h:91
HAL_SPI_MASTER_MODE_2
Definition: hal_spi_master.h:78
hal_spi_master_t::handle
handle_t handle
Definition: hal_spi_master.h:148
hal_spi_master_configure_default
void hal_spi_master_configure_default(hal_spi_master_config_t *config)
Configure SPI Master configuration structure with default values.
hal_spi_master_handle_register_t::drv_spi_master_handle
handle_t * drv_spi_master_handle
Definition: hal_spi_master.h:67
HAL_SPI_MASTER_MODULE_ERROR
Definition: hal_spi_master.h:158
HAL_SPI_MASTER_WRONG_PINS
Definition: hal_spi_master.h:157
hal_spi_master_chip_select_polarity_t
hal_spi_master_chip_select_polarity_t
Definition: hal_spi_master.h:87
hal_spi_master_set_default_write_data
void hal_spi_master_set_default_write_data(handle_t *handle, hal_spi_master_config_t *config)
Set SPI Master default ( dummy ) write data.
hal_spi_master_set_chip_select_polarity
void hal_spi_master_set_chip_select_polarity(hal_spi_master_chip_select_polarity_t polarity)
Set desired chip select polarity.
hal_spi_master_read
err_t hal_spi_master_read(handle_t handle, uint8_t *read_data_buffer, size_t read_data_length)
Read byte from SPI bus.
hal_spi_master_handle_register_t::init_state
bool init_state
Definition: hal_spi_master.h:68
hal_spi_master_config_t::sck
hal_pin_name_t sck
Definition: hal_spi_master.h:126
hal_spi_master_config_t::default_write_data
uint8_t default_write_data
Definition: hal_spi_master.h:125
HAL_SPI_MASTER_MODE_1
Definition: hal_spi_master.h:77
hal_spi_master_write_then_read
err_t hal_spi_master_write_then_read(handle_t handle, 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.
err_t
int32_t err_t
Definition: hal_target.h:63
hal_spi_master_config_t::mosi
hal_pin_name_t mosi
Definition: hal_spi_master.h:128
HAL_SPI_MASTER_SUCCESS
Definition: hal_spi_master.h:156
hal_spi_master_handle_register_t
SPI Master level handle.
Definition: hal_spi_master.h:64