MT2523 API Reference  LinkIt SDK v4
hal_spi_master.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2017 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __HAL_SPI_MASTER_H__
36 #define __HAL_SPI_MASTER_H__
37 #include "hal_platform.h"
38 
39 #ifdef HAL_SPI_MASTER_MODULE_ENABLED
40 
41 
69 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
70 
90 #else
91 
108 #endif
109 
124 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
125 
145 #endif
146 
157 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
158 
170 #endif
171 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
172 
369 #else
370 
438 #endif
439 
440 #ifdef HAL_GPIO_FEATURE_SET_DRIVING
441 
466 #endif
467 
475 #ifdef __cplusplus
476 extern "C" {
477 #endif
478 
483 #ifdef HAL_SPI_MASTER_FEATURE_ADVANCED_CONFIG
484 
489 typedef enum {
493 
494 
496 typedef enum {
500 
501 
503 typedef enum {
513 
514 
516 typedef enum {
520 #endif
521 
522 
523 #ifdef HAL_SPI_MASTER_FEATURE_DEASSERT_CONFIG
524 
525 typedef enum {
529 #endif
530 
531 
532 #ifdef HAL_SPI_MASTER_FEATURE_MACRO_CONFIG
533 
534 typedef enum {
539 #endif
540 
541 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
542 
543 typedef enum {
547 #endif
548 
550 typedef enum {
557 
558 
560 typedef enum {
564 
574 typedef struct {
575  uint32_t clock_frequency;
581 
582 #ifdef HAL_SPI_MASTER_FEATURE_ADVANCED_CONFIG
583 
584 typedef struct {
590 #endif
591 
592 
593 #ifdef HAL_SPI_MASTER_FEATURE_CHIP_SELECT_TIMING
594 
595 typedef struct {
607 #endif
608 
609 
611 typedef struct {
612  uint8_t *send_data;
613  uint32_t send_length;
614  uint8_t *receive_buffer;
615  uint32_t receive_length;
617 
618 
622 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
623 
636 typedef void (*hal_spi_master_callback_t)(hal_spi_master_callback_event_t event, void *user_data);
637 
641 #endif
642 
690  hal_spi_master_config_t *spi_config);
691 
702 
703 #ifdef HAL_SPI_MASTER_FEATURE_ADVANCED_CONFIG
704 
726  hal_spi_master_advanced_config_t *advanced_config);
727 #endif
728 
729 
747  uint8_t *data,
748  uint32_t size);
749 
750 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
751 
767  uint8_t *data,
768  uint32_t size);
769 
785  uint8_t *data,
786  uint32_t size);
787 #endif
788 
815  hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config);
816 
817 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
818 
838  hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config);
839 
859  hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config);
860 #endif
861 
876  hal_spi_master_running_status_t *running_status);
877 
878 
879 #ifdef HAL_SPI_MASTER_FEATURE_CHIP_SELECT_TIMING
880 
895  hal_spi_master_chip_select_timing_t chip_select_timing);
896 #endif
897 
898 
899 #ifdef HAL_SPI_MASTER_FEATURE_DEASSERT_CONFIG
900 
915  hal_spi_master_deassert_t deassert);
916 #endif
917 
918 
919 #ifdef HAL_SPI_MASTER_FEATURE_MACRO_CONFIG
920 
934  hal_spi_master_macro_select_t macro_select);
935 #endif
936 
937 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
938 
952  hal_spi_master_callback_t callback,
953  void *user_data);
954 #endif
955 
956 #ifdef HAL_SPI_MASTER_FEATURE_DUAL_QUAD_MODE
957 
968 hal_spi_master_status_t hal_spi_master_set_mode(hal_spi_master_port_t master_port,
969  hal_spi_master_mode_t mode);
970 
982 hal_spi_master_status_t hal_spi_master_set_dummy_bits(hal_spi_master_port_t master_port,
983  uint8_t dummy_bits);
984 
996 hal_spi_master_status_t hal_spi_master_set_command_bytes(hal_spi_master_port_t master_port,
997  uint8_t command_bytes);
998 #endif
999 
1000 
1001 #ifdef __cplusplus
1002 }
1003 #endif
1004 
1005 
1010 #endif /*HAL_SPI_MASTER_MODULE_ENABLED*/
1011 #endif /* __HAL_SPI_MASTER_H__ */
1012 
hal_spi_master_clock_polarity_t
SPI master clock polarity definition.
Definition: hal_platform.h:597
Delay 7 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:511
SPI master send and receive configuration structure.
Definition: hal_spi_master.h:611
uint8_t * send_data
Data buffer to send, this parameter cannot be NULL.
Definition: hal_spi_master.h:612
Delay 3 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:507
Timing tolerance ability not used.
Definition: hal_spi_master.h:504
hal_spi_master_chip_select_polarity_t chip_polarity
SPI master chip select active polarity setting.
Definition: hal_spi_master.h:586
hal_spi_master_status_t hal_spi_master_init(hal_spi_master_port_t master_port, hal_spi_master_config_t *spi_config)
This function is mainly used to initialize the SPI master and set user defined common parameters like...
hal_spi_master_clock_phase_t phase
SPI master clock phase setting.
Definition: hal_spi_master.h:579
Chip select polarity active high.
Definition: hal_spi_master.h:498
Chip select deassert is disabled.
Definition: hal_spi_master.h:526
uint32_t chip_select_idle_count
SPI master chip select idle count setting.
Definition: hal_spi_master.h:603
Delay 5 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:509
Both send and receive data use Big-Endian format.
Definition: hal_spi_master.h:491
hal_spi_master_status_t hal_spi_master_set_deassert(hal_spi_master_port_t master_port, hal_spi_master_deassert_t deassert)
SPI master chip select de-assertion mode configuration.
SPI use PAD group A.
Definition: hal_spi_master.h:535
uint32_t clock_frequency
SPI master clock frequency setting.
Definition: hal_spi_master.h:575
hal_spi_master_clock_phase_t
SPI master clock format definition.
Definition: hal_platform.h:604
hal_spi_master_slave_port_t slave_port
SPI slave device selection.
Definition: hal_spi_master.h:576
hal_spi_master_slave_port_t
This enum defines the options to connect the SPI slave device to the SPI master's CS pins...
Definition: hal_platform.h:590
hal_spi_master_status_t hal_spi_master_set_macro_selection(hal_spi_master_port_t master_port, hal_spi_master_macro_select_t macro_select)
SPI master macro group configuration.
SPI master invalid input parameter.
Definition: hal_spi_master.h:554
uint8_t * receive_buffer
Received data buffer, this parameter cannot be NULL.
Definition: hal_spi_master.h:614
Delay 6 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:510
SPI master is busy.
Definition: hal_spi_master.h:561
SPI master advanced configuration structure.
Definition: hal_spi_master.h:584
hal_spi_master_status_t hal_spi_master_send_dma(hal_spi_master_port_t master_port, uint8_t *data, uint32_t size)
This function is used to send data asynchronously with DMA mode.
Chip select polarity active low.
Definition: hal_spi_master.h:497
hal_spi_master_get_tick_mode_t get_tick
SPI clock timing tolerance setting.
Definition: hal_spi_master.h:587
hal_spi_master_status_t hal_spi_master_set_advanced_config(hal_spi_master_port_t master_port, hal_spi_master_advanced_config_t *advanced_config)
SPI master advanced configuration function.
SPI master operation completed successfully.
Definition: hal_spi_master.h:555
SPI master function error occurred.
Definition: hal_spi_master.h:551
hal_spi_master_bit_order_t
SPI master transaction bit order definition.
Definition: hal_platform.h:611
SPI master send operation completed.
Definition: hal_spi_master.h:544
hal_spi_master_status_t hal_spi_master_deinit(hal_spi_master_port_t master_port)
This function resets the SPI master, gates its clock, disables interrupts.
hal_spi_master_status_t hal_spi_master_send_dma_blocking(hal_spi_master_port_t master_port, uint8_t *data, uint32_t size)
This function is used to send data synchronously with DMA mode.
hal_spi_master_status_t
SPI master status.
Definition: hal_spi_master.h:550
hal_spi_master_byte_order_t byte_order
SPI master byte order setting.
Definition: hal_spi_master.h:585
Delay 2 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:506
Sample edge of MISO is at the negative edge.
Definition: hal_spi_master.h:518
hal_spi_master_byte_order_t
SPI master data transfer byte order definition.
Definition: hal_spi_master.h:489
hal_spi_master_status_t hal_spi_master_get_running_status(hal_spi_master_port_t master_port, hal_spi_master_running_status_t *running_status)
This function gets current running status of the SPI master.
hal_spi_master_sample_select_t sample_select
SPI MISO sample edge setting.
Definition: hal_spi_master.h:588
hal_spi_master_macro_select_t
SPI master pad macro select definition.
Definition: hal_spi_master.h:534
hal_spi_master_sample_select_t
SPI master sample edge of MISO definition.
Definition: hal_spi_master.h:516
SPI master configuration structure.
Definition: hal_spi_master.h:574
uint32_t send_length
The number of bytes to send, no greater than 4.
Definition: hal_spi_master.h:613
hal_spi_master_status_t hal_spi_master_send_polling(hal_spi_master_port_t master_port, uint8_t *data, uint32_t size)
This function is used to send data synchronously with FIFO mode.
Sample edge of MISO is at the positive edge.
Definition: hal_spi_master.h:517
hal_spi_master_clock_polarity_t polarity
SPI master clock polarity setting.
Definition: hal_spi_master.h:578
SPI master is idle.
Definition: hal_spi_master.h:562
uint32_t chip_select_hold_count
SPI master chip select hold count setting.
Definition: hal_spi_master.h:600
Delay 1 SPI system clock cycle for get_tick.
Definition: hal_spi_master.h:505
hal_spi_master_get_tick_mode_t
SPI master tolerance get_tick timing (based on SPI system clock) setting.
Definition: hal_spi_master.h:503
SPI master is busy.
Definition: hal_spi_master.h:552
hal_spi_master_callback_event_t
SPI master callback event definition.
Definition: hal_spi_master.h:543
uint32_t chip_select_setup_count
SPI master chip select setup count setting.
Definition: hal_spi_master.h:596
hal_spi_master_running_status_t
SPI master running status.
Definition: hal_spi_master.h:560
hal_spi_master_port_t
This enum defines the SPI master port.
Definition: hal_platform.h:580
hal_spi_master_status_t hal_spi_master_send_and_receive_dma_blocking(hal_spi_master_port_t master_port, hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config)
This function simultaneously sends and receives data in the DMA mode.
hal_spi_master_status_t hal_spi_master_send_and_receive_dma(hal_spi_master_port_t master_port, hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config)
This function is used to send and receive data asynchronously with DMA mode.
Delay 4 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:508
hal_spi_master_bit_order_t bit_order
SPI master bit order setting.
Definition: hal_spi_master.h:577
SPI use PAD group B.
Definition: hal_spi_master.h:536
Both send and receive data use Little-Endian format.
Definition: hal_spi_master.h:490
hal_spi_master_deassert_t
SPI master chip select deasert definition.
Definition: hal_spi_master.h:525
SPI master chip select configuration structure.
Definition: hal_spi_master.h:595
uint32_t receive_length
The valid number of bytes received with the number of bytes to send.
Definition: hal_spi_master.h:615
void(* hal_spi_master_callback_t)(hal_spi_master_callback_event_t event, void *user_data)
This defines the callback function prototype.
Definition: hal_spi_master.h:636
SPI master receive operation completed.
Definition: hal_spi_master.h:545
SPI use PAD group C.
Definition: hal_spi_master.h:537
hal_spi_master_status_t hal_spi_master_set_chip_select_timing(hal_spi_master_port_t master_port, hal_spi_master_chip_select_timing_t chip_select_timing)
This function is used to configure SPI master chip select timing parameter.
SPI master invalid port.
Definition: hal_spi_master.h:553
hal_spi_master_chip_select_polarity_t
SPI master chip select polarity definition.
Definition: hal_spi_master.h:496
Chip select deassert is enabled.
Definition: hal_spi_master.h:527
hal_spi_master_status_t hal_spi_master_send_and_receive_polling(hal_spi_master_port_t master_port, hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config)
This function simultaneously sends and receives data in the FIFO mode.
hal_spi_master_status_t hal_spi_master_register_callback(hal_spi_master_port_t master_port, hal_spi_master_callback_t callback, void *user_data)
This function is used to register user's callback to SPI master driver.