MT7687 API Reference  LinkIt SDK v4
hal_i2c_master.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2016 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 #ifndef __HAL_I2C_MASTER_H__
35 #define __HAL_I2C_MASTER_H__
36 #include "hal_platform.h"
37 
38 #ifdef HAL_I2C_MASTER_MODULE_ENABLED
39 #ifdef HAL_I2C_MASTER_FEATURE_EXTENDED_DMA
40 
202 #else
203 
342 #endif
343 
344 #ifdef HAL_I2C_MASTER_FEATURE_EXTENDED_DMA
345 
421 #endif
422 
430 #ifdef __cplusplus
431 extern "C" {
432 #endif
433 
434 
435 /*****************************************************************************
436 * Enums
437 *****************************************************************************/
438 
446 typedef enum {
452 
453 
455 typedef enum {
462 
464 typedef enum {
468 
470 typedef enum {
479 
484 /*****************************************************************************
485 * Structures
486 *****************************************************************************/
487 
494 typedef struct {
495  hal_i2c_frequency_t frequency;
497 
499 typedef struct {
502 
503 #ifdef HAL_I2C_MASTER_FEATURE_SEND_TO_RECEIVE
504 
505 typedef struct {
506  uint8_t slave_address;
507  const uint8_t *send_data;
508  uint32_t send_length;
509  uint8_t *receive_buffer;
510  uint32_t receive_length;
512 #endif
513 
514 #ifdef HAL_I2C_MASTER_FEATURE_EXTENDED_DMA
515 
519 typedef struct {
520  uint8_t slave_address;
521  const uint8_t *send_data;
522  uint32_t send_packet_length;
523  uint32_t send_bytes_in_one_packet;
524 } hal_i2c_send_config_t;
525 
529 typedef struct {
530  uint8_t slave_address;
531  uint8_t *receive_buffer;
532  uint32_t receive_packet_length;
533  uint32_t receive_bytes_in_one_packet;
534 } hal_i2c_receive_config_t;
535 
539 typedef struct {
540  uint8_t slave_address;
541  const uint8_t *send_data;
542  uint8_t *receive_buffer;
543  uint32_t send_packet_length;
544  uint32_t send_bytes_in_one_packet;
545  uint32_t receive_packet_length;
546  uint32_t receive_bytes_in_one_packet;
547 } hal_i2c_send_to_receive_config_ex_t;
548 
549 #endif
550 
551 
571 typedef void (*hal_i2c_callback_t)(uint8_t slave_address, hal_i2c_callback_event_t event, void *user_data);
572 
577 /*****************************************************************************
578 * Functions
579 *****************************************************************************/
580 
581 
625 
626 
638 
639 
654 hal_i2c_status_t hal_i2c_master_set_frequency(hal_i2c_port_t i2c_port, hal_i2c_frequency_t frequency);
655 
656 
657 
658 
674 
675 
693 hal_i2c_status_t hal_i2c_master_send_polling(hal_i2c_port_t i2c_port, uint8_t slave_address, const uint8_t *data, uint32_t size);
694 
695 
713 hal_i2c_status_t hal_i2c_master_send_dma(hal_i2c_port_t i2c_port, uint8_t slave_address, const uint8_t *data, uint32_t size);
714 
715 
733 hal_i2c_status_t hal_i2c_master_receive_polling(hal_i2c_port_t i2c_port, uint8_t slave_address, uint8_t *buffer, uint32_t size);
734 
735 
736 
754 hal_i2c_status_t hal_i2c_master_receive_dma(hal_i2c_port_t i2c_port, uint8_t slave_address, uint8_t *buffer, uint32_t size);
755 
756 
757 #ifdef HAL_I2C_MASTER_FEATURE_SEND_TO_RECEIVE
758 
775 
776 
777 
794 
795 #endif /* #ifdef HAL_I2C_MASTER_FEATURE_SEND_TO_RECEIVE */
796 
797 #ifdef HAL_I2C_MASTER_FEATURE_EXTENDED_DMA
798 
814 hal_i2c_status_t hal_i2c_master_send_dma_ex(hal_i2c_port_t i2c_port, hal_i2c_send_config_t *i2c_send_config);
815 
831 hal_i2c_status_t hal_i2c_master_receive_dma_ex(hal_i2c_port_t i2c_port, hal_i2c_receive_config_t *i2c_receive_config);
832 
848 hal_i2c_status_t hal_i2c_master_send_to_receive_dma_ex(hal_i2c_port_t i2c_port, hal_i2c_send_to_receive_config_ex_t *i2c_send_to_receive_config_ex);
849 
850 #endif
851 
852 
867 
868 
869 #ifdef __cplusplus
870 }
871 #endif
872 
877 #endif /*HAL_I2C_MASTER_MODULE_ENABLED*/
878 #endif /* __HAL_I2C_MASTER_H__ */
879 
880 
hal_i2c_callback_event_t
This enum defines the transaction result event.
Definition: hal_i2c_master.h:446
hal_i2c_status_t hal_i2c_master_receive_dma(hal_i2c_port_t i2c_port, uint8_t slave_address, uint8_t *buffer, uint32_t size)
This function receives data from I2C slave in a DMA mode.
void(* hal_i2c_callback_t)(uint8_t slave_address, hal_i2c_callback_event_t event, void *user_data)
This defines the callback function prototype.
Definition: hal_i2c_master.h:571
This structure defines the configuration settings for send_to_receive transaction format...
Definition: hal_i2c_master.h:505
An ACK error occurred during transaction.
Definition: hal_i2c_master.h:447
The I2C bus is idle.
Definition: hal_i2c_master.h:465
hal_i2c_status_t hal_i2c_master_send_to_receive_dma(hal_i2c_port_t i2c_port, hal_i2c_send_to_receive_config_t *i2c_send_to_receive_config)
This function sends data to and then receives data from I2C slave in a DMA mode.
The I2C bus is busy, an error occurred.
Definition: hal_i2c_master.h:457
50kbps.
Definition: hal_i2c_master.h:471
hal_i2c_status_t
This enum defines the HAL interface return value.
Definition: hal_i2c_master.h:455
hal_i2c_status_t hal_i2c_master_register_callback(hal_i2c_port_t i2c_port, hal_i2c_callback_t i2c_callback, void *user_data)
This function registers a callback function while using DMA mode.
hal_i2c_running_type_t running_status
The running status is defined in hal_i2c_running_type_t.
Definition: hal_i2c_master.h:500
An error occurred and the transaction has failed.
Definition: hal_i2c_master.h:456
A NACK error occurred during transaction.
Definition: hal_i2c_master.h:448
uint8_t * receive_buffer
The receive data buffer.
Definition: hal_i2c_master.h:509
const uint8_t * send_data
The send data buffer.
Definition: hal_i2c_master.h:507
uint32_t send_length
The length of data to send.
Definition: hal_i2c_master.h:508
A timeout error occurred during transaction.
Definition: hal_i2c_master.h:449
The I2C bus is busy.
Definition: hal_i2c_master.h:466
The total number of supported I2C frequencies (invalid I2C frequency).
Definition: hal_i2c_master.h:477
hal_i2c_status_t hal_i2c_master_set_frequency(hal_i2c_port_t i2c_port, hal_i2c_frequency_t frequency)
This function sets the transaction speed.
hal_i2c_status_t hal_i2c_master_get_running_status(hal_i2c_port_t i2c_port, hal_i2c_running_status_t *running_status)
This function gets running status of the I2C master.
400kbps.
Definition: hal_i2c_master.h:475
200kbps.
Definition: hal_i2c_master.h:473
hal_i2c_running_type_t
This enum defines the I2C bus status.
Definition: hal_i2c_master.h:464
hal_i2c_status_t hal_i2c_master_send_polling(hal_i2c_port_t i2c_port, uint8_t slave_address, const uint8_t *data, uint32_t size)
This function sends data to I2C slave in polling mode.
hal_i2c_frequency_t frequency
The transfer speed.
Definition: hal_i2c_master.h:495
This structure defines the configuration settings to initialize the I2C master.
Definition: hal_i2c_master.h:494
uint32_t receive_length
The length of data to receive.
Definition: hal_i2c_master.h:510
hal_i2c_status_t hal_i2c_master_send_dma(hal_i2c_port_t i2c_port, uint8_t slave_address, const uint8_t *data, uint32_t size)
This function sends data to I2C slave in DMA mode.
hal_i2c_status_t hal_i2c_master_init(hal_i2c_port_t i2c_port, hal_i2c_config_t *i2c_config)
This function initializes the I2C master before starting a transaction.
100kbps.
Definition: hal_i2c_master.h:472
This structure defines the I2C bus status.
Definition: hal_i2c_master.h:499
300kbps.
Definition: hal_i2c_master.h:474
uint8_t slave_address
The slave device address.
Definition: hal_i2c_master.h:506
hal_i2c_frequency_t
This enum defines the I2C transaction speed.
Definition: hal_i2c_master.h:470
hal_i2c_status_t hal_i2c_master_receive_polling(hal_i2c_port_t i2c_port, uint8_t slave_address, uint8_t *buffer, uint32_t size)
This function receives data from I2C slave in a polling mode.
hal_i2c_status_t hal_i2c_master_send_to_receive_polling(hal_i2c_port_t i2c_port, hal_i2c_send_to_receive_config_t *i2c_send_to_receive_config)
This function sends data to and then receives data from I2C slave in a polling mode.
hal_i2c_status_t hal_i2c_master_deinit(hal_i2c_port_t i2c_port)
This function releases the I2C master after the transaction is over.
A wrong parameter is given.
Definition: hal_i2c_master.h:459
The transaction completed wihtout any error.
Definition: hal_i2c_master.h:450
hal_i2c_port_t
This enum define the i2c port.
Definition: hal_platform.h:214
1mbps.
Definition: hal_i2c_master.h:476
No error occurred during the function call.
Definition: hal_i2c_master.h:460
A wrong port number is given.
Definition: hal_i2c_master.h:458