API HAL: takeover i2c initialization and abstraction. Update I2C drivers to match new api. Back port API HAL to bootloader and enable light support for F5. (#356)

Co-authored-by: coreglitch <mail@s3f.ru>
This commit is contained in:
あく
2021-03-02 14:45:47 +03:00
committed by GitHub
parent 056e6ffa9c
commit 38011e88f3
26 changed files with 388 additions and 444 deletions

View File

@@ -1,54 +0,0 @@
/**
******************************************************************************
* @file i2c.h
* @brief This file contains all the function prototypes for
* the i2c.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __I2C_H__
#define __I2C_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
extern I2C_HandleTypeDef hi2c1;
/* USER CODE BEGIN Private defines */
#define POWER_I2C hi2c1
/* USER CODE END Private defines */
void MX_I2C1_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /* __I2C_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -97,8 +97,6 @@ void Error_Handler(void);
#define RFID_PULL_Pin GPIO_PIN_8
#define RFID_PULL_GPIO_Port GPIOA
#define RFID_PULL_EXTI_IRQn EXTI9_5_IRQn
#define I2C_SCL_Pin GPIO_PIN_9
#define I2C_SCL_GPIO_Port GPIOA
#define CC1101_G0_Pin GPIO_PIN_4
#define CC1101_G0_GPIO_Port GPIOC
#define RFID_RF_IN_Pin GPIO_PIN_5
@@ -129,8 +127,6 @@ void Error_Handler(void);
#define SPI_D_MOSI_GPIO_Port GPIOB
#define DISPLAY_DI_Pin GPIO_PIN_6
#define DISPLAY_DI_GPIO_Port GPIOC
#define I2C_SDA_Pin GPIO_PIN_10
#define I2C_SDA_GPIO_Port GPIOA
#define DISPLAY_BACKLIGHT_Pin GPIO_PIN_15
#define DISPLAY_BACKLIGHT_GPIO_Port GPIOA
#define PC10_Pin GPIO_PIN_10

View File

@@ -1,120 +0,0 @@
/**
******************************************************************************
* @file i2c.c
* @brief This file provides code for the configuration
* of the I2C instances.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* Includes ------------------------------------------------------------------*/
#include "i2c.h"
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
I2C_HandleTypeDef hi2c1;
/* I2C1 init function */
void MX_I2C1_Init(void)
{
hi2c1.Instance = I2C1;
hi2c1.Init.Timing = 0x10707DBC;
hi2c1.Init.OwnAddress1 = 0;
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
hi2c1.Init.OwnAddress2 = 0;
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
{
Error_Handler();
}
/** Configure Analogue filter
*/
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
{
Error_Handler();
}
/** Configure Digital filter
*/
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
{
Error_Handler();
}
}
void HAL_I2C_MspInit(I2C_HandleTypeDef* i2cHandle)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
if(i2cHandle->Instance==I2C1)
{
/* USER CODE BEGIN I2C1_MspInit 0 */
/* USER CODE END I2C1_MspInit 0 */
__HAL_RCC_GPIOA_CLK_ENABLE();
/**I2C1 GPIO Configuration
PA9 ------> I2C1_SCL
PA10 ------> I2C1_SDA
*/
GPIO_InitStruct.Pin = I2C_SCL_Pin|I2C_SDA_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* I2C1 clock enable */
__HAL_RCC_I2C1_CLK_ENABLE();
/* USER CODE BEGIN I2C1_MspInit 1 */
/* USER CODE END I2C1_MspInit 1 */
}
}
void HAL_I2C_MspDeInit(I2C_HandleTypeDef* i2cHandle)
{
if(i2cHandle->Instance==I2C1)
{
/* USER CODE BEGIN I2C1_MspDeInit 0 */
/* USER CODE END I2C1_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_I2C1_CLK_DISABLE();
/**I2C1 GPIO Configuration
PA9 ------> I2C1_SCL
PA10 ------> I2C1_SDA
*/
HAL_GPIO_DeInit(I2C_SCL_GPIO_Port, I2C_SCL_Pin);
HAL_GPIO_DeInit(I2C_SDA_GPIO_Port, I2C_SDA_Pin);
/* USER CODE BEGIN I2C1_MspDeInit 1 */
/* USER CODE END I2C1_MspDeInit 1 */
}
}
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@@ -5,7 +5,6 @@
#include "aes.h"
#include "comp.h"
#include "crc.h"
#include "i2c.h"
#include "pka.h"
#include "rf.h"
#include "rng.h"
@@ -31,7 +30,6 @@ int main(void)
MX_GPIO_Init();
MX_ADC1_Init();
MX_I2C1_Init();
MX_RTC_Init();
MX_SPI1_Init();
MX_SPI2_Init();

View File

@@ -1,4 +1,5 @@
#include <api-hal-i2c.h>
#include <stm32wbxx_ll_i2c.h>
#include <furi.h>
osMutexId_t api_hal_i2c_mutex = NULL;
@@ -8,6 +9,35 @@ void api_hal_i2c_init() {
furi_check(api_hal_i2c_mutex);
}
void api_hal_i2c_tx(I2C_TypeDef* instance, uint8_t address, const uint8_t *data, uint8_t size) {
LL_I2C_HandleTransfer(instance, address, LL_I2C_ADDRSLAVE_7BIT, size, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_WRITE);
while (!LL_I2C_IsActiveFlag_STOP(instance)) {
if (LL_I2C_IsActiveFlag_TXIS(instance)) {
LL_I2C_TransmitData8(instance, (*data++));
}
}
LL_I2C_ClearFlag_STOP(instance);
}
void api_hal_i2c_rx(I2C_TypeDef* instance, uint8_t address, uint8_t *data, uint8_t size) {
LL_I2C_HandleTransfer(instance, address, LL_I2C_ADDRSLAVE_7BIT, size, LL_I2C_MODE_AUTOEND, LL_I2C_GENERATE_START_READ);
while (!LL_I2C_IsActiveFlag_STOP(instance)) {
if (LL_I2C_IsActiveFlag_RXNE(instance)) {
*data++ = LL_I2C_ReceiveData8(instance);
}
}
LL_I2C_ClearFlag_STOP(instance);
}
void api_hal_i2c_trx(I2C_TypeDef* instance, uint8_t address, const uint8_t *tx_data, uint8_t tx_size, uint8_t *rx_data, uint8_t rx_size) {
api_hal_i2c_tx(instance, address, tx_data, tx_size);
api_hal_i2c_rx(instance, address, rx_data, rx_size);
}
void api_hal_i2c_lock() {
furi_check(osMutexAcquire(api_hal_i2c_mutex, osWaitForever) == osOK);
}

View File

@@ -3,10 +3,20 @@
#include "main.h"
#include <furi.h>
#include <stm32wbxx.h>
#include <stm32wbxx_ll_gpio.h>
#ifdef __cplusplus
extern "C" {
#endif
#define I2C_SCL_Pin LL_GPIO_PIN_9
#define I2C_SCL_GPIO_Port GPIOA
#define I2C_SDA_Pin LL_GPIO_PIN_10
#define I2C_SDA_GPIO_Port GPIOA
#define POWER_I2C I2C1
/* Input Related Constants */
#define INPUT_DEBOUNCE_TICKS 20