MT7687 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 {
486  HAL_SPI_MASTER_LITTLE_ENDIAN = 0,
487  HAL_SPI_MASTER_BIG_ENDIAN = 1
488 } hal_spi_master_byte_order_t;
489 
490 
492 typedef enum {
493  HAL_SPI_MASTER_CHIP_SELECT_LOW = 0,
494  HAL_SPI_MASTER_CHIP_SELECT_HIGH = 1
495 } hal_spi_master_chip_select_polarity_t;
496 
497 
499 typedef enum {
500  HAL_SPI_MASTER_NO_GET_TICK_MODE = 0,
501  HAL_SPI_MASTER_GET_TICK_DELAY1 = 1,
502  HAL_SPI_MASTER_GET_TICK_DELAY2 = 2,
503  HAL_SPI_MASTER_GET_TICK_DELAY3 = 3,
504  HAL_SPI_MASTER_GET_TICK_DELAY4 = 4,
505  HAL_SPI_MASTER_GET_TICK_DELAY5 = 5,
506  HAL_SPI_MASTER_GET_TICK_DELAY6 = 6,
507  HAL_SPI_MASTER_GET_TICK_DELAY7 = 7
508 } hal_spi_master_get_tick_mode_t;
509 
510 
512 typedef enum {
513  HAL_SPI_MASTER_SAMPLE_POSITIVE = 0,
514  HAL_SPI_MASTER_SAMPLE_NEGATIVE = 1
515 } hal_spi_master_sample_select_t;
516 #endif
517 
518 
519 #ifdef HAL_SPI_MASTER_FEATURE_DEASSERT_CONFIG
520 
521 typedef enum {
522  HAL_SPI_MASTER_DEASSERT_DISABLE = 0,
523  HAL_SPI_MASTER_DEASSERT_ENABLE = 1
524 } hal_spi_master_deassert_t;
525 #endif
526 
527 
528 #ifdef HAL_SPI_MASTER_FEATURE_MACRO_CONFIG
529 
530 typedef enum {
531  HAL_SPI_MASTER_MACRO_GROUP_A = 0,
532  HAL_SPI_MASTER_MACRO_GROUP_B = 1,
533  HAL_SPI_MASTER_MACRO_GROUP_C = 2
534 } hal_spi_master_macro_select_t;
535 #endif
536 
537 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
538 
539 typedef enum {
540  HAL_SPI_MASTER_EVENT_SEND_FINISHED = 0,
541  HAL_SPI_MASTER_EVENT_RECEIVE_FINISHED = 1
542 } hal_spi_master_callback_event_t;
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 {
581  hal_spi_master_byte_order_t byte_order;
582  hal_spi_master_chip_select_polarity_t chip_polarity;
583  hal_spi_master_get_tick_mode_t get_tick;
584  hal_spi_master_sample_select_t sample_select;
585 } hal_spi_master_advanced_config_t;
586 #endif
587 
588 
589 #ifdef HAL_SPI_MASTER_FEATURE_CHIP_SELECT_TIMING
590 
591 typedef struct {
592  uint32_t chip_select_setup_count;
596  uint32_t chip_select_hold_count;
599  uint32_t chip_select_idle_count;
602 } hal_spi_master_chip_select_timing_t;
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 
721 hal_spi_master_status_t hal_spi_master_set_advanced_config(hal_spi_master_port_t master_port,
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 
762 hal_spi_master_status_t hal_spi_master_send_dma(hal_spi_master_port_t master_port,
763  uint8_t *data,
764  uint32_t size);
765 
780 hal_spi_master_status_t hal_spi_master_send_dma_blocking(hal_spi_master_port_t master_port,
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 
833 hal_spi_master_status_t hal_spi_master_send_and_receive_dma(hal_spi_master_port_t master_port,
834  hal_spi_master_send_and_receive_config_t *spi_send_and_receive_config);
835 
854 hal_spi_master_status_t hal_spi_master_send_and_receive_dma_blocking(hal_spi_master_port_t master_port,
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 
890 hal_spi_master_status_t hal_spi_master_set_chip_select_timing(hal_spi_master_port_t master_port,
891  hal_spi_master_chip_select_timing_t chip_select_timing);
892 #endif
893 
894 
895 #ifdef HAL_SPI_MASTER_FEATURE_DEASSERT_CONFIG
896 
910 hal_spi_master_status_t hal_spi_master_set_deassert(hal_spi_master_port_t master_port,
911  hal_spi_master_deassert_t deassert);
912 #endif
913 
914 
915 #ifdef HAL_SPI_MASTER_FEATURE_MACRO_CONFIG
916 
929 hal_spi_master_status_t hal_spi_master_set_macro_selection(hal_spi_master_port_t master_port,
930  hal_spi_master_macro_select_t macro_select);
931 #endif
932 
933 #ifdef HAL_SPI_MASTER_FEATURE_DMA_MODE
934 
947 hal_spi_master_status_t hal_spi_master_register_callback(hal_spi_master_port_t master_port,
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:465
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
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
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:472
hal_spi_master_slave_port_t slave_port
SPI slave device selection.
Definition: hal_spi_master.h:572
hal_spi_master_slave_port_t
selection of spi slave device connected to which cs pin of spi master
Definition: hal_platform.h:458
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
SPI master is busy.
Definition: hal_spi_master.h:557
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:479
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
SPI master status.
Definition: hal_spi_master.h:546
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.
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.
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
SPI master is busy.
Definition: hal_spi_master.h:548
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:451
hal_spi_master_bit_order_t bit_order
SPI master bit order setting.
Definition: hal_spi_master.h:573
uint32_t receive_length
The valid number of bytes received with the number of bytes to send.
Definition: hal_spi_master.h:611
SPI master invalid port.
Definition: hal_spi_master.h:549
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.