1 /*
2  * @brief LPC15XX I2C ROM API declarations and functions
3  *
4  * @note
5  * Copyright(C) NXP Semiconductors, 2013
6  * All rights reserved.
7  *
8  * @par
9  * Software that is described herein is for illustrative purposes only
10  * which provides customers with programming information regarding the
11  * LPC products.  This software is supplied "AS IS" without any warranties of
12  * any kind, and NXP Semiconductors and its licensor disclaim any and
13  * all warranties, express or implied, including all implied warranties of
14  * merchantability, fitness for a particular purpose and non-infringement of
15  * intellectual property rights.  NXP Semiconductors assumes no responsibility
16  * or liability for the use of the software, conveys no license or rights under any
17  * patent, copyright, mask work right, or any other intellectual property rights in
18  * or to any products. NXP Semiconductors reserves the right to make changes
19  * in the software without notification. NXP Semiconductors also makes no
20  * representation or warranty that such application will be suitable for the
21  * specified use without further testing or modification.
22  *
23  * @par
24  * Permission to use, copy, modify, and distribute this software and its
25  * documentation is hereby granted, under NXP Semiconductors' and its
26  * licensor's relevant copyrights in the software, without fee, provided that it
27  * is used in conjunction with NXP Semiconductors microcontrollers.  This
28  * copyright, permission, and disclaimer notice must appear in all copies of
29  * this code.
30  */
31 
32 #ifndef __ROM_I2C_15XX_H_
33 #define __ROM_I2C_15XX_H_
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /** @defgroup CHIP_I2CROM_15XX CHIP: LPC15xx I2C ROM API declarations and functions
40  * @ingroup ROMAPI_15XX
41  * @{
42  */
43 
44 /**
45  * @brief LPC15XX I2C ROM driver handle structure
46  */
47 typedef void *I2C_HANDLE_T;
48 
49 /**
50  * @brief LPC15XX I2C ROM driver callback function
51  */
52 typedef void  (*I2C_CALLBK_T)(uint32_t err_code, uint32_t n);
53 
54 /**
55  * LPC15XX I2C ROM driver parameter structure
56  */
57 typedef struct I2C_PARAM {
58 	uint32_t        num_bytes_send;		/*!< No. of bytes to send */
59 	uint32_t        num_bytes_rec;		/*!< No. of bytes to receive */
60 	uint8_t         *buffer_ptr_send;	/*!< Pointer to send buffer */
61 	uint8_t         *buffer_ptr_rec;	/*!< Pointer to receive buffer */
62 	I2C_CALLBK_T    func_pt;			/*!< Callback function */
63 	uint8_t         stop_flag;			/*!< Stop flag */
64 	uint8_t         dummy[3];
65 } I2C_PARAM_T;
66 
67 /**
68  * LPC15XX I2C ROM driver result structure
69  */
70 typedef struct I2C_RESULT {
71 	uint32_t n_bytes_sent;	/*!< No. of bytes sent */
72 	uint32_t n_bytes_recd;	/*!< No. of bytes received */
73 } I2C_RESULT_T;
74 
75 /**
76  * LPC15XX I2C ROM driver modes enum
77  */
78 typedef enum CHIP_I2C_MODE {
79 	IDLE,			/*!< IDLE state */
80 	MASTER_SEND,	/*!< Master send state */
81 	MASTER_RECEIVE,	/*!< Master Receive state */
82 	SLAVE_SEND,		/*!< Slave send state */
83 	SLAVE_RECEIVE	/*!< Slave receive state */
84 } CHIP_I2C_MODE_T;
85 
86 /**
87  * LPC15XX I2C ROM driver APIs structure
88  */
89 typedef struct  I2CD_API {
90 	/*!< Interrupt Support Routine */
91 	void (*i2c_isr_handler)(I2C_HANDLE_T *handle);
92 	/*!< MASTER functions */
93 	ErrorCode_t (*i2c_master_transmit_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
94 	ErrorCode_t (*i2c_master_receive_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
95 	ErrorCode_t (*i2c_master_tx_rx_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
96 	ErrorCode_t (*i2c_master_transmit_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
97 	ErrorCode_t (*i2c_master_receive_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
98 	ErrorCode_t (*i2c_master_tx_rx_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
99 
100 	/*!< SLAVE functions */
101 	ErrorCode_t (*i2c_slave_receive_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
102 	ErrorCode_t (*i2c_slave_transmit_poll)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
103 	ErrorCode_t (*i2c_slave_receive_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
104 	ErrorCode_t (*i2c_slave_transmit_intr)(I2C_HANDLE_T *handle, I2C_PARAM_T *param, I2C_RESULT_T *result);
105 	ErrorCode_t (*i2c_set_slave_addr)(I2C_HANDLE_T *handle, uint32_t slave_addr_0_3, uint32_t slave_mask_0_3);
106 
107 	/*!< OTHER support functions */
108 	uint32_t (*i2c_get_mem_size)(void);
109 	I2C_HANDLE_T *(*i2c_setup)(uint32_t  i2c_base_addr, uint32_t * start_of_ram);
110 	ErrorCode_t (*i2c_set_bitrate)(I2C_HANDLE_T *handle, uint32_t  p_clk_in_hz, uint32_t bitrate_in_bps);
111 	uint32_t (*i2c_get_firmware_version)(void);
112 	CHIP_I2C_MODE_T (*i2c_get_status)(I2C_HANDLE_T *handle);
113 	ErrorCode_t (*i2c_set_timeout)(I2C_HANDLE_T *handle, uint32_t timeout);
114 } I2CD_API_T;
115 
116 /**
117  * @}
118  */
119 
120 #ifdef __cplusplus
121 }
122 #endif
123 
124 #endif /* __ROM_I2C_15XX_H_ */
125