feat: generic I2C and PCA95xx driver (#5233)
Co-authored-by: Peter Feerick <peter.feerick@gmail.com>
This commit is contained in:
co-authored by
Peter Feerick
parent
08c90dc39c
commit
b71d2a0228
@@ -25,6 +25,7 @@
|
||||
#include "stm32_gpio_driver.h"
|
||||
|
||||
#include "hal.h"
|
||||
#include "hal/i2c_driver.h"
|
||||
#include "hal/eeprom_driver.h"
|
||||
|
||||
static void init_wp_pin()
|
||||
@@ -47,8 +48,7 @@ static void init_wp_pin()
|
||||
|
||||
void eepromInit()
|
||||
{
|
||||
stm32_i2c_deinit(EEPROM_I2C_BUS);
|
||||
stm32_i2c_init(EEPROM_I2C_BUS, I2C_B1_CLK_RATE);
|
||||
i2c_init(EEPROM_I2C_BUS);
|
||||
init_wp_pin();
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void eepromInit()
|
||||
*/
|
||||
static bool I2C_EE_WaitEepromStandbyState(void)
|
||||
{
|
||||
if (stm32_i2c_is_dev_ready(EEPROM_I2C_BUS, EEPROM_I2C_ADDRESS, 20 /* 20ms */) < 0)
|
||||
if (i2c_dev_ready(EEPROM_I2C_BUS, EEPROM_I2C_ADDRESS) < 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
@@ -2456,13 +2456,11 @@
|
||||
|
||||
#if defined(PCBXLITE) || defined(PCBX9LITE) || defined(PCBX7ACCESS) || \
|
||||
defined(RADIO_ZORRO) || defined(RADIO_POCKET) || defined(RADIO_X9DP2019)
|
||||
#define I2C_B1_GPIO GPIOB
|
||||
#define I2C_B1_SDA_GPIO_PIN LL_GPIO_PIN_9 // PB.09
|
||||
#define I2C_B1_SCL_GPIO_PIN LL_GPIO_PIN_8 // PB.08
|
||||
#define I2C_B1_SCL_GPIO GPIO_PIN(GPIOB, 8) // PB.08
|
||||
#define I2C_B1_SDA_GPIO GPIO_PIN(GPIOB, 9) // PB.09
|
||||
#else
|
||||
#define I2C_B1_GPIO GPIOB
|
||||
#define I2C_B1_SCL_GPIO_PIN LL_GPIO_PIN_6 // PB.06
|
||||
#define I2C_B1_SDA_GPIO_PIN LL_GPIO_PIN_7 // PB.07
|
||||
#define I2C_B1_SCL_GPIO GPIO_PIN(GPIOB, 6) // PB.06
|
||||
#define I2C_B1_SDA_GPIO GPIO_PIN(GPIOB, 7) // PB.07
|
||||
#endif
|
||||
|
||||
// EEPROM
|
||||
@@ -2500,16 +2498,13 @@
|
||||
// Second I2C Bus: IMU
|
||||
#if defined(PCBXLITES)
|
||||
#define I2C_B2 I2C3
|
||||
#define I2C_B2_SCL_GPIO GPIOA
|
||||
#define I2C_B2_SCL_GPIO_PIN LL_GPIO_PIN_8 // PA.08
|
||||
#define I2C_B2_SDA_GPIO GPIOC
|
||||
#define I2C_B2_SDA_GPIO_PIN LL_GPIO_PIN_9 // PC.09
|
||||
#define I2C_B2_SCL_GPIO GPIO_PIN(GPIOA, 8) // PA.08
|
||||
#define I2C_B2_SDA_GPIO GPIO_PIN(GPIOC, 9) // PC.09
|
||||
#define I2C_B2_GPIO_AF LL_GPIO_AF_4
|
||||
#define I2C_B2_SPEED 400000
|
||||
#define I2C_B2_CLK_RATE 400000
|
||||
|
||||
#define IMU_I2C_BUS I2C_Bus_2
|
||||
#define IMU_I2C_ADDRESS 0x6B
|
||||
#define IMU_I2C_CLK_RATE I2C_B2_SPEED
|
||||
#endif
|
||||
|
||||
// SD - SPI2
|
||||
|
||||
@@ -21,7 +21,9 @@
|
||||
|
||||
#if !defined(SOFTWARE_VOLUME)
|
||||
|
||||
#include "hal/i2c_driver.h"
|
||||
#include "stm32_i2c_driver.h"
|
||||
|
||||
#include "board.h"
|
||||
|
||||
static const uint8_t volumeScale[VOLUME_LEVEL_MAX+1] = {
|
||||
@@ -32,7 +34,7 @@ static const uint8_t volumeScale[VOLUME_LEVEL_MAX+1] = {
|
||||
int32_t getVolume()
|
||||
{
|
||||
uint8_t value = 0;
|
||||
if (stm32_i2c_read(VOLUME_I2C_BUS, VOLUME_I2C_ADDRESS, 0, 1, &value, 1, 10) < 0)
|
||||
if (i2c_read(VOLUME_I2C_BUS, VOLUME_I2C_ADDRESS, 0, 1, &value, 1) < 0)
|
||||
return -1;
|
||||
|
||||
return value;
|
||||
@@ -40,8 +42,8 @@ int32_t getVolume()
|
||||
|
||||
void setVolume(uint8_t volume)
|
||||
{
|
||||
stm32_i2c_init(VOLUME_I2C_BUS, I2C_B1_CLK_RATE);
|
||||
stm32_i2c_write(VOLUME_I2C_BUS, VOLUME_I2C_ADDRESS, 0, 1, &volume, 1, 10);
|
||||
i2c_init(VOLUME_I2C_BUS);
|
||||
i2c_write(VOLUME_I2C_BUS, VOLUME_I2C_ADDRESS, 0, 1, &volume, 1);
|
||||
}
|
||||
|
||||
void setScaledVolume(uint8_t volume)
|
||||
|
||||
Reference in New Issue
Block a user