bsp/tm4c123: move i2c clk config to tm4c123_config.c

This commit is contained in:
wirano 2024-04-11 18:07:09 +08:00 committed by Meco Man
parent 5e9257fcd1
commit e88bb51fb5
3 changed files with 33 additions and 22 deletions

View File

@ -6,12 +6,14 @@
* Change Logs:
* Date Author Notes
* 2020-06-27 AHTYDHD the first version
* 2024-04-11 Astrozen add i2c support
*/
#include <rtthread.h>
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_memmap.h"
#include "driverlib/rom.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
@ -29,6 +31,9 @@
#ifdef RT_USING_SPI
#include "driverlib/ssi.h"
#endif /* RT_USING_SPI */
#ifdef RT_USING_I2C
#include "driverlib/i2c.h"
#endif /* RT_USING_I2C */
#ifdef RT_USING_SERIAL
@ -85,4 +90,26 @@ void spi_hw_config(void)
}
#endif /* RT_USING_SPI */
#ifdef RT_USING_I2C
void i2c_hw_config(void)
{
/* I2C0 */
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
ROM_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C0);
ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0));
// timeout:5ms
ROM_I2CMasterTimeoutSet(I2C0_BASE, 0x7d);
}
#endif /* RT_USING_I2C */
/************************** end of file ******************/

View File

@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2020-06-27 AHTYDHD the first version
* 2024-04-11 Astrozen add i2c support
*/
#ifndef __TM4C123GH6PZ_CONFIG_H__
@ -27,6 +28,9 @@ void pwm_hw_config(void);
#ifdef RT_USING_SPI
void spi_hw_config(void);
#endif /* RT_USING_SPI */
#ifdef RT_USING_I2C
void i2c_hw_config(void);
#endif /* RT_USING_I2C */
#ifdef __cplusplus
}

View File

@ -19,13 +19,7 @@
#include "drv_i2c.h"
#include "inc/hw_memmap.h"
#include <stdbool.h>
#include "i2c_config.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/pin_map.h"
#include "driverlib/gpio.h"
#include "driverlib/i2c.h"
enum {
#ifdef BSP_USING_I2C0
@ -184,23 +178,9 @@ static rt_ssize_t tm4c123_i2c_xfer(struct rt_i2c_bus_device *bus, struct rt_i2c_
int rt_hw_i2c_init(void) {
rt_err_t ret = RT_EOK;
i2c_hw_config();
for (uint32_t i = 0; i < sizeof(tm4c123_i2cs) / sizeof(tm4c123_i2cs[0]); i++) {
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
ROM_GPIOPinConfigure(GPIO_PB2_I2C0SCL);
ROM_GPIOPinConfigure(GPIO_PB3_I2C0SDA);
ROM_GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
ROM_GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
ROM_SysCtlPeripheralDisable(SYSCTL_PERIPH_I2C0);
ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
while (!SysCtlPeripheralReady(SYSCTL_PERIPH_I2C0));
// timeout:5ms
ROM_I2CMasterTimeoutSet(I2C0_BASE, 0x7d);
if (tm4c123_i2cs[i].clk_freq == 400000) {
ROM_I2CMasterInitExpClk(tm4c123_i2cs[i].base, ROM_SysCtlClockGet(), RT_TRUE);
} else {