MT2523 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 
201 #else
202 
341 #endif
342 
343 #ifdef HAL_I2C_MASTER_FEATURE_EXTENDED_DMA
344 
420 #endif
421 
429 #ifdef __cplusplus
430 extern "C" {
431 #endif
432 
433 
434 /*****************************************************************************
435 * Enums
436 *****************************************************************************/
437 
445 typedef enum {
451 
452 
454 typedef enum {
461 
463 typedef enum {
467 
469 typedef enum {
478 
483 /*****************************************************************************
484 * Structures
485 *****************************************************************************/
486 
493 typedef struct {
494  hal_i2c_frequency_t frequency;
496 
498 typedef struct {
501 
502 #ifdef HAL_I2C_MASTER_FEATURE_SEND_TO_RECEIVE
503 
504 typedef struct {
505  uint8_t slave_address;
506  const uint8_t *send_data;
507  uint32_t send_length;
508  uint8_t *receive_buffer;
509  uint32_t receive_length;
511 #endif
512 
513 #ifdef HAL_I2C_MASTER_FEATURE_EXTENDED_DMA
514 
518 typedef struct {
519  uint8_t slave_address;
520  const uint8_t *send_data;
524 
528 typedef struct {
529  uint8_t slave_address;
530  uint8_t *receive_buffer;
534 
538 typedef struct {
539  uint8_t slave_address;
540  const uint8_t *send_data;
541  uint8_t *receive_buffer;
547 
548 #endif
549 
550 
570 typedef void (*hal_i2c_callback_t)(uint8_t slave_address, hal_i2c_callback_event_t event, void *user_data);
571 
576 /*****************************************************************************
577 * Functions
578 *****************************************************************************/
579 
580 
624 
625 
637 
638 
653 hal_i2c_status_t hal_i2c_master_set_frequency(hal_i2c_port_t i2c_port, hal_i2c_frequency_t frequency);
654 
655 
656 
657 
673 
674 
692 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);
693 
694 
712 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);
713 
714 
732 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);
733 
734 
735 
753 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);
754 
755 
756 #ifdef HAL_I2C_MASTER_FEATURE_SEND_TO_RECEIVE
757 
774 
775 
776 
793 
794 #endif /* #ifdef HAL_I2C_MASTER_FEATURE_SEND_TO_RECEIVE */
795 
796 #ifdef HAL_I2C_MASTER_FEATURE_EXTENDED_DMA
797 
814 
831 
848 
849 #endif
850 
851 
866 
867 
868 #ifdef __cplusplus
869 }
870 #endif
871 
876 #endif /*HAL_I2C_MASTER_MODULE_ENABLED*/
877 #endif /* __HAL_I2C_MASTER_H__ */
878 
879 
hal_i2c_callback_event_t
This enum defines the transaction result event.
Definition: hal_i2c_master.h:445
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:570
uint8_t * receive_buffer
The receive data buffer.
Definition: hal_i2c_master.h:541
This structure defines the configuration settings for send_to_receive transaction format...
Definition: hal_i2c_master.h:504
An ACK error occurred during transaction.
Definition: hal_i2c_master.h:446
The I2C bus is idle.
Definition: hal_i2c_master.h:464
uint32_t receive_packet_length
The packet length.
Definition: hal_i2c_master.h:531
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:456
50kbps.
Definition: hal_i2c_master.h:470
hal_i2c_status_t
This enum defines the HAL interface return value.
Definition: hal_i2c_master.h:454
uint32_t send_bytes_in_one_packet
The number of bytes in one packet.
Definition: hal_i2c_master.h:543
This structure defines the configuration parameters for extended DMA send to receive transaction form...
Definition: hal_i2c_master.h:538
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:499
An error occurred and the transaction has failed.
Definition: hal_i2c_master.h:455
A NACK error occurred during transaction.
Definition: hal_i2c_master.h:447
uint8_t slave_address
The slave device address.
Definition: hal_i2c_master.h:539
uint8_t * receive_buffer
The receive data buffer.
Definition: hal_i2c_master.h:508
const uint8_t * send_data
The send data buffer.
Definition: hal_i2c_master.h:506
uint32_t send_packet_length
The packet length.
Definition: hal_i2c_master.h:521
uint32_t send_length
The length of data to send.
Definition: hal_i2c_master.h:507
A timeout error occurred during transaction.
Definition: hal_i2c_master.h:448
The I2C bus is busy.
Definition: hal_i2c_master.h:465
The total number of supported I2C frequencies (invalid I2C frequency).
Definition: hal_i2c_master.h:476
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.
uint8_t slave_address
The slave device address.
Definition: hal_i2c_master.h:529
uint32_t receive_bytes_in_one_packet
The number of bytes in one packet.
Definition: hal_i2c_master.h:545
400kbps.
Definition: hal_i2c_master.h:474
200kbps.
Definition: hal_i2c_master.h:472
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)
This function sends data to and then receives data from I2C slave in a extended DMA mode...
hal_i2c_running_type_t
This enum defines the I2C bus status.
Definition: hal_i2c_master.h:463
uint8_t slave_address
The slave device address.
Definition: hal_i2c_master.h:519
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:494
This structure defines the configuration parameters for extended DMA receive transaction format...
Definition: hal_i2c_master.h:528
This structure defines the configuration settings to initialize the I2C master.
Definition: hal_i2c_master.h:493
uint32_t receive_length
The length of data to receive.
Definition: hal_i2c_master.h:509
uint32_t receive_packet_length
The receive packet length.
Definition: hal_i2c_master.h:544
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:471
This structure defines the I2C bus status.
Definition: hal_i2c_master.h:498
300kbps.
Definition: hal_i2c_master.h:473
uint8_t slave_address
The slave device address.
Definition: hal_i2c_master.h:505
hal_i2c_status_t hal_i2c_master_send_dma_ex(hal_i2c_port_t i2c_port, hal_i2c_send_config_t *i2c_send_config)
This function sends data to I2C slave in DMA mode.
hal_i2c_frequency_t
This enum defines the I2C transaction speed.
Definition: hal_i2c_master.h:469
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.
uint8_t * receive_buffer
The receive data buffer.
Definition: hal_i2c_master.h:530
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.
const uint8_t * send_data
The send data buffer.
Definition: hal_i2c_master.h:520
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.
This structure defines the configuration parameters for extended DMA send transaction format...
Definition: hal_i2c_master.h:518
A wrong parameter is given.
Definition: hal_i2c_master.h:458
The transaction completed wihtout any error.
Definition: hal_i2c_master.h:449
hal_i2c_port_t
This enum defines the I2C port.
Definition: hal_platform.h:302
1mbps.
Definition: hal_i2c_master.h:475
No error occurred during the function call.
Definition: hal_i2c_master.h:459
const uint8_t * send_data
The send data buffer.
Definition: hal_i2c_master.h:540
uint32_t send_bytes_in_one_packet
The number of bytes in one packet.
Definition: hal_i2c_master.h:522
hal_i2c_status_t hal_i2c_master_receive_dma_ex(hal_i2c_port_t i2c_port, hal_i2c_receive_config_t *i2c_receive_config)
This function receives data from I2C slave in a extended DMA mode.
uint32_t send_packet_length
The send packet length.
Definition: hal_i2c_master.h:542
A wrong port number is given.
Definition: hal_i2c_master.h:457
uint32_t receive_bytes_in_one_packet
The bytes in one packet.
Definition: hal_i2c_master.h:532