From 3c3e55cb0a3d79ce831e9cd512c062ce6874f316 Mon Sep 17 00:00:00 2001 From: cfif Date: Mon, 2 Jun 2025 13:26:40 +0300 Subject: [PATCH] Init --- I2cPorts.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++ I2cPorts.h | 25 +++++++++++++++++ modular.json | 17 ++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 I2cPorts.c create mode 100644 I2cPorts.h create mode 100644 modular.json diff --git a/I2cPorts.c b/I2cPorts.c new file mode 100644 index 0000000..8e3c5fd --- /dev/null +++ b/I2cPorts.c @@ -0,0 +1,77 @@ +// +// Created by ilya on 25.03.24. +// +#include +#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); +} diff --git a/I2cPorts.h b/I2cPorts.h new file mode 100644 index 0000000..c594bfb --- /dev/null +++ b/I2cPorts.h @@ -0,0 +1,25 @@ +// +// Created by ilya on 25.03.24. +// + +#ifndef SMART_COMPONENTS_I2CPORTS_H +#define SMART_COMPONENTS_I2CPORTS_H + +#include "I2cPortArtery.h" +#include "I2cIO.h" + +#define I2C_SPEED_10KHz 0x8170F7F7 +#define I2C_SPEED_1KHz 0x4F20FFFF + +typedef struct { + tI2cPortArtery codecI2c3; + tI2cIO codecI2c3_IO; + + tI2cPortArtery amplI2c2; + tI2cIO amplI2c2_IO; +} tI2cPorts; + +void I2cPorts_Init(); + +extern tI2cPorts I2C_PORTS; +#endif //SMART_COMPONENTS_I2CPORTS_H diff --git a/modular.json b/modular.json new file mode 100644 index 0000000..479ce65 --- /dev/null +++ b/modular.json @@ -0,0 +1,17 @@ +{ + "dep": [ + { + "type": "git", + "provider": "Smart_Components_Aurus", + "repo": "I2cPort_ARTERY_At32f435_437_v2" + } + ], + "cmake": { + "inc_dirs": [ + "./" + ], + "srcs": [ + "./**.c" + ] + } +} \ No newline at end of file