Skip to content

Commit 0566f81

Browse files
committed
update nxp mcxa driver to support frdm-mcxa346
1 parent c5f5fb4 commit 0566f81

File tree

7 files changed

+386
-66
lines changed

7 files changed

+386
-66
lines changed

bsp/nxp/mcx/mcxa/Libraries/drivers/drv_adc.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#include "fsl_lpadc.h"
1515
#include "fsl_spc.h"
1616

17+
#define DBG_TAG "drv.adc"
18+
#define DBG_LVL DBG_INFO
19+
#include <rtdbg.h>
20+
1721
#ifdef RT_USING_ADC
1822

1923
#define DEFAULT_HW_AVG (kLPADC_HardwareAverageCount4)

bsp/nxp/mcx/mcxa/Libraries/drivers/drv_i2c.c

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,27 @@
1616

1717
#ifdef RT_USING_I2C
1818

19+
#define DBG_TAG "drv.i2c"
20+
#define DBG_LVL DBG_INFO
21+
#include <rtdbg.h>
22+
1923
enum
2024
{
2125
#ifdef BSP_USING_I2C0
2226
I2C0_INDEX,
2327
#endif
28+
#ifdef BSP_USING_I2C1
29+
I2C1_INDEX,
30+
#endif
31+
#ifdef BSP_USING_I2C2
32+
I2C2_INDEX,
33+
#endif
34+
#ifdef BSP_USING_I2C3
35+
I2C3_INDEX,
36+
#endif
2437
};
2538

2639

27-
#define i2c_dbg rt_kprintf
28-
2940
struct lpc_i2c_bus
3041
{
3142
struct rt_i2c_bus_device parent;
@@ -44,12 +55,58 @@ struct lpc_i2c_bus lpc_obj[] =
4455
{
4556
.I2C = LPI2C0,
4657
.baud = 100000U,
58+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
59+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C0,
60+
#else
4761
.clock_attach_id = kFRO12M_to_LPI2C0,
62+
#endif
4863
.clock_div_name = kCLOCK_DivLPI2C0,
4964
.clock_src = kCLOCK_Fro12M,
5065
.name = "i2c0",
5166
},
5267
#endif
68+
#ifdef BSP_USING_I2C1
69+
{
70+
.I2C = LPI2C1,
71+
.baud = 100000U,
72+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
73+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C1,
74+
#else
75+
.clock_attach_id = kFRO12M_to_LPI2C1,
76+
#endif
77+
.clock_div_name = kCLOCK_DivLPI2C1,
78+
.clock_src = kCLOCK_Fro12M,
79+
.name = "i2c1",
80+
},
81+
#endif
82+
#ifdef BSP_USING_I2C2
83+
{
84+
.I2C = LPI2C2,
85+
.baud = 100000U,
86+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
87+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C2,
88+
#else
89+
.clock_attach_id = kFRO12M_to_LPI2C2,
90+
#endif
91+
.clock_div_name = kCLOCK_DivLPI2C2,
92+
.clock_src = kCLOCK_Fro12M,
93+
.name = "i2c2",
94+
},
95+
#endif
96+
#ifdef BSP_USING_I2C3
97+
{
98+
.I2C = LPI2C3,
99+
.baud = 100000U,
100+
#if (defined(CPU_MCXA346VLH) || defined(CPU_MCXA346VLL) || defined(CPU_MCXA346VLQ) || defined(CPU_MCXA346VPN))
101+
.clock_attach_id = kFRO_LF_DIV_to_LPI2C3,
102+
#else
103+
.clock_attach_id = kFRO12M_to_LPI2C3,
104+
#endif
105+
.clock_div_name = kCLOCK_DivLPI2C3,
106+
.clock_src = kCLOCK_Fro12M,
107+
.name = "i2c3",
108+
},
109+
#endif
53110
};
54111

55112
static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg msgs[], rt_uint32_t num)
@@ -80,7 +137,7 @@ static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
80137

81138
if (LPI2C_MasterTransferBlocking(lpc_i2c->I2C, &xfer) != kStatus_Success)
82139
{
83-
i2c_dbg("i2c bus read failed!\n");
140+
LOG_D("i2c bus read failed!\n");
84141
return i;
85142
}
86143
}
@@ -99,7 +156,7 @@ static rt_ssize_t lpc_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_msg
99156

100157
if (LPI2C_MasterTransferBlocking(lpc_i2c->I2C, &xfer) != kStatus_Success)
101158
{
102-
i2c_dbg("i2c bus write failed!\n");
159+
LOG_D("i2c bus write failed!\n");
103160
return i;
104161
}
105162
}

bsp/nxp/mcx/mcxa/Libraries/drivers/drv_pin.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@
1717

1818
#ifdef RT_USING_PIN
1919

20+
#define DBG_TAG "drv.pin"
21+
#define DBG_LVL DBG_INFO
22+
#include <rtdbg.h>
2023

2124
#define GET_GPIO_PORT(x) ((x) / 32)
2225
#define GET_GPIO_PIN(x) ((x) % 32)
2326

2427
static struct rt_pin_ops mcx_pin_ops;
2528

26-
static GPIO_Type *GPIO_TYPE_TBL[] = {GPIO0, GPIO1, GPIO2, GPIO3};
27-
static PORT_Type *PORT_TYPE_TBL[] = {PORT0, PORT1, PORT2, PORT3};
28-
static IRQn_Type IRQ_TYPE_TBL[] = {GPIO0_IRQn, GPIO1_IRQn, GPIO2_IRQn, GPIO3_IRQn};
29+
static GPIO_Type *GPIO_TYPE_TBL[] = GPIO_BASE_PTRS;
30+
static PORT_Type *PORT_TYPE_TBL[] = PORT_BASE_PTRS;
31+
static IRQn_Type IRQ_TYPE_TBL[] = GPIO_IRQS;
2932

3033

3134
#define PIN2GPIO(x) GPIO_TYPE_TBL[GET_GPIO_PORT(x)]
3235
#define PIN2PORT(x) PORT_TYPE_TBL[GET_GPIO_PORT(x)]
3336
#define PIN2IRQ(x) IRQ_TYPE_TBL[GET_GPIO_PORT(x)]
3437

35-
struct rt_pin_irq_hdr pin_irq_hdr_tab[32*4] = {0};
38+
struct rt_pin_irq_hdr pin_irq_hdr_tab[32*5] = {0};
3639

3740
static void mcx_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode)
3841
{
@@ -143,6 +146,11 @@ void GPIO3_IRQHandler(void)
143146
pin_irq_handler(3);
144147
}
145148

149+
void GPIO4_IRQHandler(void)
150+
{
151+
pin_irq_handler(4);
152+
}
153+
146154

147155
static rt_err_t mcx_pin_attach_irq(struct rt_device *device, rt_base_t pin, rt_uint8_t mode, void (*hdr)(void *args), void *args)
148156
{

0 commit comments

Comments
 (0)