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 
365 #else
366 
434 #endif
435 
436 #ifdef HAL_GPIO_FEATURE_SET_DRIVING
437 
462 #endif
463 
471 #ifdef __cplusplus
472 extern "C" {
473 #endif
474 
479 #ifdef HAL_SPI_MASTER_FEATURE_ADVANCED_CONFIG
480 
485 typedef enum {
489 
490 
492 typedef enum {
496 
497 
499 typedef enum {
509 
510 
512 typedef enum {
516 #endif
517 
518 
519 #ifdef HAL_SPI_MASTER_FEATURE_DEASSERT_CONFIG
520 
521 typedef enum {
525 #endif
526 
527 
528 #ifdef HAL_SPI_MASTER_FEATURE_MACRO_CONFIG
529 
530 typedef enum {
535 #endif
536 
537 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
538 
539 typedef enum {
543 #endif
544 
546 typedef enum {
553 
554 
556 typedef enum {
560 
570 typedef struct {
571  uint32_t clock_frequency;
577 
578 #ifdef HAL_SPI_MASTER_FEATURE_ADVANCED_CONFIG
579 
580 typedef struct {
586 #endif
587 
588 
589 #ifdef HAL_SPI_MASTER_FEATURE_CHIP_SELECT_TIMING
590 
591 typedef struct {
603 #endif
604 
605 
607 typedef struct {
608  uint8_t *send_data;
609  uint32_t send_length;
610  uint8_t *receive_buffer;
611  uint32_t receive_length;
613 
614 
618 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
619 
632 typedef void (*hal_spi_master_callback_t)(hal_spi_master_callback_event_t event, void *user_data);
633 
637 #endif
638 
686  hal_spi_master_config_t *spi_config);
687 
698 
699 #ifdef HAL_SPI_MASTER_FEATURE_ADVANCED_CONFIG
700 
722  hal_spi_master_advanced_config_t *advanced_config);
723 #endif
724 
725 
743  uint8_t *data,
744  uint32_t size);
745 
746 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
747 
763  uint8_t *data,
764  uint32_t size);
765 
781  uint8_t *data,
782  uint32_t size);
783 #endif
784 
811  hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config);
812 
813 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
814 
834  hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config);
835 
855  hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config);
856 #endif
857 
872  hal_spi_master_running_status_t *running_status);
873 
874 
875 #ifdef HAL_SPI_MASTER_FEATURE_CHIP_SELECT_TIMING
876 
891  hal_spi_master_chip_select_timing_t chip_select_timing);
892 #endif
893 
894 
895 #ifdef HAL_SPI_MASTER_FEATURE_DEASSERT_CONFIG
896 
911  hal_spi_master_deassert_t deassert);
912 #endif
913 
914 
915 #ifdef HAL_SPI_MASTER_FEATURE_MACRO_CONFIG
916 
930  hal_spi_master_macro_select_t macro_select);
931 #endif
932 
933 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
934 
948  hal_spi_master_callback_t callback,
949  void *user_data);
950 #endif
951 
952 #ifdef HAL_SPI_MASTER_FEATURE_DUAL_QUAD_MODE
953 
964 hal_spi_master_status_t hal_spi_master_set_mode(hal_spi_master_port_t master_port,
965  hal_spi_master_mode_t mode);
966 
978 hal_spi_master_status_t hal_spi_master_set_dummy_bits(hal_spi_master_port_t master_port,
979  uint8_t dummy_bits);
980 
992 hal_spi_master_status_t hal_spi_master_set_command_bytes(hal_spi_master_port_t master_port,
993  uint8_t command_bytes);
994 #endif
995 
996 
997 #ifdef __cplusplus
998 }
999 #endif
1000 
1001 
1006 #endif /*HAL_SPI_MASTER_MODULE_ENABLED*/
1007 #endif /* __HAL_SPI_MASTER_H__ */
1008 
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:507
SPI master send and receive configuration structure.
Definition: hal_spi_master.h:607
uint8_t * send_data
Data buffer to send, this parameter cannot be NULL.
Definition: hal_spi_master.h:608
Delay 3 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:503
Timing tolerance ability not used.
Definition: hal_spi_master.h:500
hal_spi_master_chip_select_polarity_t chip_polarity
SPI master chip select active polarity setting.
Definition: hal_spi_master.h:582
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:575
Chip select polarity active high.
Definition: hal_spi_master.h:494
Chip select deassert is disabled.
Definition: hal_spi_master.h:522
uint32_t chip_select_idle_count
SPI master chip select idle count setting.
Definition: hal_spi_master.h:599
Delay 5 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:505
Both send and receive data use Big-Endian format.
Definition: hal_spi_master.h:487
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:531
uint32_t clock_frequency
SPI master clock frequency setting.
Definition: hal_spi_master.h:571
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:572
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:550
uint8_t * receive_buffer
Received data buffer, this parameter cannot be NULL.
Definition: hal_spi_master.h:610
Delay 6 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:506
SPI master is busy.
Definition: hal_spi_master.h:557
SPI master advanced configuration structure.
Definition: hal_spi_master.h:580
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:493
hal_spi_master_get_tick_mode_t get_tick
SPI clock timing tolerance setting.
Definition: hal_spi_master.h:583
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:551
SPI master function error occurred.
Definition: hal_spi_master.h:547
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:540
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:546
hal_spi_master_byte_order_t byte_order
SPI master byte order setting.
Definition: hal_spi_master.h:581
Delay 2 SPI system clock cycles for get_tick.
Definition: hal_spi_master.h:502
Sample edge of MISO is at the negative edge.
Definition: hal_spi_master.h:514
hal_spi_master_byte_order_t
SPI master data transfer byte order definition.
Definition: hal_spi_master.h:485
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:584
hal_spi_master_macro_select_t
SPI master pad macro select definition.
Definition: hal_spi_master.h:530
hal_spi_master_sample_select_t
SPI master sample edge of MISO definition.
Definition: hal_spi_master.h:512
SPI master configuration structure.
Definition: hal_spi_master.h:570
uint32_t send_length
The number of bytes to send, no greater than 4.
Definition: hal_spi_master.h:609
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:513
hal_spi_master_clock_polarity_t polarity
SPI master clock polarity setting.
Definition: hal_spi_master.h:574
SPI master is idle.
Definition: hal_spi_master.h:558
uint32_t chip_select_hold_count
SPI master chip select hold count setting.
Definition: hal_spi_master.h:596
Delay 1 SPI system clock cycle for get_tick.
Definition: hal_spi_master.h:501
hal_spi_master_get_tick_mode_t
SPI master tolerance get_tick timing (based on SPI system clock) setting.
Definition: hal_spi_master.h:499
SPI master is busy.
Definition: hal_spi_master.h:548
hal_spi_master_callback_event_t
SPI master callback event definition.
Definition: hal_spi_master.h:539
uint32_t chip_select_setup_count
SPI master chip select setup count setting.
Definition: hal_spi_master.h:592
hal_spi_master_running_status_t
SPI master running status.
Definition: hal_spi_master.h:556
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:504
hal_spi_master_bit_order_t bit_order
SPI master bit order setting.
Definition: hal_spi_master.h:573
SPI use PAD group B.
Definition: hal_spi_master.h:532
Both send and receive data use Little-Endian format.
Definition: hal_spi_master.h:486
hal_spi_master_deassert_t
SPI master chip select deasert definition.
Definition: hal_spi_master.h:521
SPI master chip select configuration structure.
Definition: hal_spi_master.h:591
uint32_t receive_length
The valid number of bytes received with the number of bytes to send.
Definition: hal_spi_master.h:611
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:632
SPI master receive operation completed.
Definition: hal_spi_master.h:541
SPI use PAD group C.
Definition: hal_spi_master.h:533
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:549
hal_spi_master_chip_select_polarity_t
SPI master chip select polarity definition.
Definition: hal_spi_master.h:492
Chip select deassert is enabled.
Definition: hal_spi_master.h:523
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.