Skip to content

Commit e3779e6

Browse files
committed
Adding MSP CMSIS-DRIVER I2C interface layer.
1 parent 3dcb8a8 commit e3779e6

File tree

2 files changed

+218
-0
lines changed

2 files changed

+218
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Copyright (C) 2024-2025 Texas Instruments Incorporated
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*!****************************************************************************
18+
* @file Driver_I2C_MSP.c
19+
******************************************************************************
20+
*/
21+
22+
#include <ti/driverlib/driverlib.h>
23+
#include <Driver_I2C_MSP_Priv.h>
24+
#include <Driver_I2C_MSP.h>
25+
26+
/* The I2Cx driver instance expansion generators are given below.
27+
* These generators are used to create the corresponding data structures and
28+
* function linkage implementations that are required by the Arm
29+
* CMSIS-Drivers specification for each individual I2C driver instance used
30+
* in an application.
31+
*/
32+
33+
#define GEN_DRIVER_I2C_MSP_STATE(inst) \
34+
DRIVER_I2C_MSP_STATE DRIVER_I2C##inst##_MSP_STATE;
35+
36+
#define GEN_DRIVER_I2C_MSP(inst) \
37+
DRIVER_I2C_MSP DRIVER_I2C##inst##_MSP = \
38+
{ \
39+
.hw = I2C##inst, \
40+
.state = &DRIVER_I2C##inst##_MSP_STATE, \
41+
.sdaPin.iomuxPinCtlMgmtRegIndex = DRIVER_I2C##inst##_SDA_PINCM, \
42+
.sdaPin.iomuxPinFunction = DRIVER_I2C##inst##_SDA_PF, \
43+
.sclPin.iomuxPinCtlMgmtRegIndex = DRIVER_I2C##inst##_SCL_PINCM, \
44+
.sclPin.iomuxPinFunction = DRIVER_I2C##inst##_SCL_PF, \
45+
.transmitDMA.hw = DRIVER_I2C##inst##_TRANSMIT_DMA_HW, \
46+
.transmitDMA.ch = DRIVER_I2C##inst##_TRANSMIT_DMA_CH, \
47+
.transmitDMA.trig = DRIVER_I2C##inst##_TRANSMIT_DMA_TRIG, \
48+
.receiveDMA.hw = DRIVER_I2C##inst##_RECEIVE_DMA_HW, \
49+
.receiveDMA.ch = DRIVER_I2C##inst##_RECEIVE_DMA_CH, \
50+
.receiveDMA.trig = DRIVER_I2C##inst##_RECEIVE_DMA_TRIG, \
51+
.clock = DRIVER_I2C##inst##_CLOCK_SEL, \
52+
.clockFreq = DRIVER_I2C##inst##_CLOCK_FREQ, \
53+
.irq = I2C##inst##_INT_IRQn \
54+
};
55+
56+
#define GEN_DRIVER_I2C_MSP_FXNS(inst) \
57+
static ARM_I2C_CAPABILITIES MSP_ARM_I2C##inst##_GetCapabilities(void) \
58+
{ \
59+
return MSP_ARM_I2C_GetCapabilities(&DRIVER_I2C##inst##_MSP); \
60+
} \
61+
static int32_t MSP_ARM_I2C##inst##_Initialize(ARM_I2C_SignalEvent_t cb_event) \
62+
{ \
63+
return MSP_ARM_I2C_Initialize(&DRIVER_I2C##inst##_MSP, cb_event); \
64+
} \
65+
static int32_t MSP_ARM_I2C##inst##_Uninitialize(void) \
66+
{ \
67+
return MSP_ARM_I2C_Uninitialize(&DRIVER_I2C##inst##_MSP); \
68+
} \
69+
static int32_t MSP_ARM_I2C##inst##_PowerControl(ARM_POWER_STATE state) \
70+
{ \
71+
return MSP_ARM_I2C_PowerControl(&DRIVER_I2C##inst##_MSP, state); \
72+
} \
73+
static int32_t MSP_ARM_I2C##inst##_MasterTransmit(uint32_t addr, \
74+
const uint8_t *data, uint32_t num, bool xfer_pending) \
75+
{ \
76+
return MSP_ARM_I2C_MasterTransmit(&DRIVER_I2C##inst##_MSP, addr, data, num, \
77+
xfer_pending); \
78+
} \
79+
static int32_t MSP_ARM_I2C##inst##_MasterReceive(uint32_t addr, uint8_t *data, \
80+
uint32_t num, bool xfer_pending) \
81+
{ \
82+
return MSP_ARM_I2C_MasterReceive(&DRIVER_I2C##inst##_MSP, addr, data, num, \
83+
xfer_pending); \
84+
} \
85+
static int32_t MSP_ARM_I2C##inst##_SlaveTransmit(const uint8_t *data, \
86+
uint32_t num) \
87+
{ \
88+
return MSP_ARM_I2C_SlaveTransmit(&DRIVER_I2C##inst##_MSP, data, num); \
89+
} \
90+
static int32_t MSP_ARM_I2C##inst##_SlaveReceive(uint8_t *data, uint32_t num) \
91+
{ \
92+
return MSP_ARM_I2C_SlaveReceive(&DRIVER_I2C##inst##_MSP, data, num); \
93+
} \
94+
static int32_t MSP_ARM_I2C##inst##_GetDataCount(void) \
95+
{ \
96+
return MSP_ARM_I2C_GetDataCount(&DRIVER_I2C##inst##_MSP); \
97+
} \
98+
static int32_t MSP_ARM_I2C##inst##_Control(uint32_t control, uint32_t arg) \
99+
{ \
100+
return MSP_ARM_I2C_Control(&DRIVER_I2C##inst##_MSP, control, arg); \
101+
} \
102+
static ARM_I2C_STATUS MSP_ARM_I2C##inst##_GetStatus(void) \
103+
{ \
104+
return MSP_ARM_I2C_GetStatus(&DRIVER_I2C##inst##_MSP); \
105+
} \
106+
107+
#define GEN_DRIVER_I2C_MSP_IF(inst) \
108+
ARM_DRIVER_I2C Driver_I2C##inst = \
109+
{ \
110+
MSP_ARM_I2C_GetVersion, \
111+
MSP_ARM_I2C##inst##_GetCapabilities, \
112+
MSP_ARM_I2C##inst##_Initialize, \
113+
MSP_ARM_I2C##inst##_Uninitialize, \
114+
MSP_ARM_I2C##inst##_PowerControl, \
115+
MSP_ARM_I2C##inst##_MasterTransmit, \
116+
MSP_ARM_I2C##inst##_MasterReceive, \
117+
MSP_ARM_I2C##inst##_SlaveTransmit, \
118+
MSP_ARM_I2C##inst##_SlaveReceive, \
119+
MSP_ARM_I2C##inst##_GetDataCount, \
120+
MSP_ARM_I2C##inst##_Control, \
121+
MSP_ARM_I2C##inst##_GetStatus, \
122+
};
123+
124+
#define GEN_DRIVER_I2C_MSP_ISR(inst) \
125+
void I2C##inst##_IRQHandler(void) \
126+
{ \
127+
MSP_ARM_I2C_IRQHandler(&DRIVER_I2C##inst##_MSP); \
128+
}
129+
130+
/* I2Cx Definitions */
131+
132+
#if defined(I2C0_BASE) && (DRIVER_CONFIG_HAS_I2C0==1)
133+
GEN_DRIVER_I2C_MSP_STATE(0)
134+
GEN_DRIVER_I2C_MSP(0)
135+
GEN_DRIVER_I2C_MSP_FXNS(0)
136+
GEN_DRIVER_I2C_MSP_IF(0)
137+
GEN_DRIVER_I2C_MSP_ISR(0)
138+
#endif
139+
140+
#if defined(I2C1_BASE) && (DRIVER_CONFIG_HAS_I2C1==1)
141+
GEN_DRIVER_I2C_MSP_STATE(1)
142+
GEN_DRIVER_I2C_MSP(1)
143+
GEN_DRIVER_I2C_MSP_FXNS(1)
144+
GEN_DRIVER_I2C_MSP_IF(1)
145+
GEN_DRIVER_I2C_MSP_ISR(1)
146+
#endif
147+
148+
#if defined(I2C2_BASE) && (DRIVER_CONFIG_HAS_I2C2==1)
149+
GEN_DRIVER_I2C_MSP_STATE(2)
150+
GEN_DRIVER_I2C_MSP(2)
151+
GEN_DRIVER_I2C_MSP_FXNS(2)
152+
GEN_DRIVER_I2C_MSP_IF(2)
153+
GEN_DRIVER_I2C_MSP_ISR(2)
154+
#endif
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (C) 2024-2025 Texas Instruments Incorporated
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/*!****************************************************************************
18+
* @file Driver_I2C_MSP.h
19+
* @brief MSP I2C CMSIS-Driver for Cortex-M based devices with
20+
* I2C peripheral instances.
21+
*
22+
* The CMSIS-Drivers I2C driver allows for simple, non-blocking I2C
23+
* transmit and receive communication via a high-level, Arm-standardized API.
24+
* This driver is developed to be compatible with the Arm CMSIS-Driver
25+
* specification.
26+
*
27+
*
28+
******************************************************************************
29+
*/
30+
31+
#ifndef DRIVER_I2C_MSP_H_
32+
#define DRIVER_I2C_MSP_H_
33+
34+
#ifdef __cplusplus
35+
extern "C"
36+
{
37+
#endif
38+
39+
#include <ti/devices/msp/msp.h>
40+
#include <Driver_I2C.h>
41+
#include "Driver_Config_MSP.h"
42+
43+
/*
44+
* The structure declarations below are the interfaces to
45+
* the driver for each respective I2C instance.
46+
*/
47+
48+
#if defined(I2C0_BASE) && defined(DRIVER_CONFIG_HAS_I2C0)
49+
extern ARM_DRIVER_I2C Driver_I2C0;
50+
#endif
51+
52+
#if defined(I2C1_BASE) && defined(DRIVER_CONFIG_HAS_I2C1)
53+
extern ARM_DRIVER_I2C Driver_I2C1;
54+
#endif
55+
56+
#if defined(I2C2_BASE) && defined(DRIVER_CONFIG_HAS_I2C2)
57+
extern ARM_DRIVER_I2C Driver_I2C2;
58+
#endif
59+
60+
#ifdef __cplusplus
61+
}
62+
#endif
63+
64+
#endif /* DRIVER_I2C_MSP_H_ */

0 commit comments

Comments
 (0)