SMART_COMPONENTS_I2cPorts/I2cPorts.c

78 lines
2.3 KiB
C

//
// Created by ilya on 25.03.24.
//
#include <GpioPin.h>
#include "I2cPorts.h"
tI2cPorts I2C_PORTS;
void vI2cPorts_InitI2c3(tI2cPortArtery *env) {
gpio_init_type GPIO_InitStruct;
/* i2c periph clock enable */
crm_periph_clock_enable(CRM_I2C3_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable( CRM_GPIOC_PERIPH_CLOCK, TRUE);
/* gpio configuration */
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
/* configure i2c pins: scl */
GPIO_InitStruct.gpio_pins = GPIO_PINS_0;
gpio_init(GPIOC,&GPIO_InitStruct);
gpio_pin_mux_config(GPIOC, GPIO_PINS_SOURCE0, GPIO_MUX_4);
/* configure i2c pins: sda */
GPIO_InitStruct.gpio_pins = GPIO_PINS_1;
gpio_init(GPIOC,&GPIO_InitStruct);
gpio_pin_mux_config(GPIOC, GPIO_PINS_SOURCE1, GPIO_MUX_4);
I2cPortArtery_Init7bit(env,I2C3,I2C_SPEED_1KHz);
}
void vI2cPorts_InitI2c2(tI2cPortArtery *env) {
gpio_init_type GPIO_InitStruct;
/* i2c periph clock enable */
crm_periph_clock_enable(CRM_I2C2_PERIPH_CLOCK, TRUE);
crm_periph_clock_enable( CRM_GPIOA_PERIPH_CLOCK, TRUE);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE1, GPIO_MUX_4);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE0, GPIO_MUX_4);
/* gpio configuration */
GPIO_InitStruct.gpio_out_type = GPIO_OUTPUT_OPEN_DRAIN;
GPIO_InitStruct.gpio_pull = GPIO_PULL_NONE;
GPIO_InitStruct.gpio_mode = GPIO_MODE_MUX;
GPIO_InitStruct.gpio_drive_strength = GPIO_DRIVE_STRENGTH_MODERATE;
/* configure i2c pins: scl */
GPIO_InitStruct.gpio_pins = GPIO_PINS_0;
gpio_init(GPIOA,&GPIO_InitStruct);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE0, GPIO_MUX_4);
/* configure i2c pins: sda */
GPIO_InitStruct.gpio_pins = GPIO_PINS_1;
gpio_init(GPIOA,&GPIO_InitStruct);
gpio_pin_mux_config(GPIOA, GPIO_PINS_SOURCE1, GPIO_MUX_4);
I2cPortArtery_Init7bit(env,I2C2,0x80504C4E);
}
void I2cPorts_Init() {
vI2cPorts_InitI2c3(&I2C_PORTS.codecI2c3);
I2C_PORTS.codecI2c3_IO = I2cPortArtery_GetIO(&I2C_PORTS.codecI2c3);
vI2cPorts_InitI2c2(&I2C_PORTS.amplI2c2);
I2C_PORTS.amplI2c2_IO = I2cPortArtery_GetIO(&I2C_PORTS.amplI2c2);
}