/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file : main.c
* @brief : Main program body
******************************************************************************
* @attention
*
*
© Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* USER CODE END Header */
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
typedef enum {
Tube_A = 3,
Tube_B = 2,
Tube_D = 1,
Tube_E = 0
} tube_pos_t;
/* USER CODE END PTD */
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
#define SPI_BUFFER_SIZE 5
/* Display timeout, sec */
#define DISP_WDT_TIME 10
/* USER CODE END PD */
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
/* USER CODE END PM */
/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */
static LL_RCC_ClocksTypeDef rcc_clocks;
/**
* Nixi Tube cathodes map in Byte Array:
* {E0 E9 E8 E7 E6 E5 E4 E3}
* {E2 E1 D0 D9 D8 D7 D6 D5}
* {D4 D3 D2 D1 B0 B9 B8 B7}
* {B6 B5 B4 B3 B2 B1 A0 A9}
* {A8 A7 A6 A5 A4 A3 A2 A1}
*
* Shift register bit map in Tube cathodes (from 0 to 1):
* {5.7 5.6 5.5 5.4 5.3 5.2 5.1 5.0 4.7 4.6} VL5/E
* {4.5 4.4 4.3 4.2 4.1 4.0 3.7 3.6 3.5 3.4} VL4/D
* {3.3 3.2 3.1 3.0 2.7 2.6 2.5 2.4 2.3 2.2} VL2/B
* {2.1 2.0 1.7 1.6 1.5 1.4 1.3 1.2 1.1 1.0} VL1/A
*/
static const uint16_t nixieCathodeMap[4][10] = {
{0x8000, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000},
{0x2000, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000},
{0x0800, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400},
{0x0200, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100}
};
static const uint8_t nixieCathodeMask[4][2] = {{0x00, 0x3f}, {0xc0, 0x0f}, {0xf0, 0x03}, {0xc0, 0x00}};
static uint8_t tubesBuffer[SPI_BUFFER_SIZE] = {0};
static rtc_t Clock;
static struct bme280_dev SensorDev;
static struct bme280_data SensorData;
static int8_t Humidity, Temperature;
static nt16_t Pressure;
static btn_t Button[BTN_NUM] = {
{0, evBTN1Pressed, evBTN1Holded, BTN1_PIN},
{0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
{0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN},
{0, evBTN4Pressed, evBTN4Holded, BTN4_PIN}
};
static volatile uint8_t dispWDT = 0;
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_DMA_Init(void);
static void MX_I2C1_Init(void);
static void MX_SPI1_Init(void);
static void MX_TIM3_Init(void);
static void MX_TIM14_Init(void);
static void MX_TIM16_Init(void);
static void MX_TIM17_Init(void);
/* USER CODE BEGIN PFP */
static void showDigit(tube_pos_t pos, uint8_t dig);
static void tubes_Refresh(void);
int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len);
int8_t i2c_check_err(void);
static void sensorStartMeasure(void);
static void sensorGetData(void);
static void btnProcess(void);
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
/* System interrupt init*/
/* Peripheral interrupt init*/
/* RCC_IRQn interrupt configuration */
NVIC_SetPriority(RCC_IRQn, 0);
NVIC_EnableIRQ(RCC_IRQn);
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
LL_LPM_EnableSleep();
LL_LPM_DisableSleepOnExit();
LL_RCC_GetSystemClocksFreq(&rcc_clocks);
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_I2C1_Init();
MX_SPI1_Init();
MX_TIM3_Init();
MX_TIM14_Init();
MX_TIM16_Init();
MX_TIM17_Init();
/* USER CODE BEGIN 2 */
RTOS_Init();
/* Initialize Event State Machine */
ES_Init(stShowTime);
/* Start RGB PWM */
LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH1);
LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH2);
LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH3);
LL_TIM_EnableCounter(TIM3);
/* Start Tube PWR PWM */
LL_TIM_CC_EnableChannel(TIM14, LL_TIM_CHANNEL_CH1);
LL_TIM_EnableCounter(TIM14);
/* Enable tube power */
TUBE_PWR_ON;
/* Set DMA source and destination addresses. */
/* Source: Address of the SPI buffer. */
DMA1_Channel1->CMAR = (uint32_t)&tubesBuffer;
/* Destination: SPI1 data register. */
DMA1_Channel1->CPAR = (uint32_t)&(SPI1->DR);
/* Set DMA data transfer length (SPI buffer length). */
DMA1_Channel1->CNDTR = SPI_BUFFER_SIZE;
/* Enable SPI+DMA transfer */
SPI1->CR2 |= SPI_CR2_TXDMAEN;
SPI1->CR1 |= SPI_CR1_SPE;
tubes_Refresh();
IN15_OFF;
RTC_Init();
int8_t rsltSensor;
SensorDev.dev_id = (BME280_I2C_ADDR_PRIM << 1);
SensorDev.intf = BME280_I2C_INTF;
SensorDev.read = user_i2c_read;
SensorDev.write = user_i2c_write;
SensorDev.delay_ms = tdelay_ms;
rsltSensor = bme280_init(&SensorDev);
if (rsltSensor == BME280_OK) {
Flag.BME280 = 1;
}
/* Set tasks for Sheduler */
RTOS_SetTask(btnProcess, 1, BTN_SCAN_PERIOD);
/* USER CODE END 2 */
/* USER CODE BEGIN WHILE */
RTC_ReadAll(&Clock);
if (Flag.BME280 != 0) {
/* BME280 Recommended mode of operation: Indoor navigation */
SensorDev.settings.osr_h = BME280_OVERSAMPLING_1X;
SensorDev.settings.osr_p = BME280_OVERSAMPLING_16X;
SensorDev.settings.osr_t = BME280_OVERSAMPLING_2X;
SensorDev.settings.filter = BME280_FILTER_COEFF_16;
rsltSensor = bme280_set_sensor_settings((BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL), &SensorDev);
RTOS_SetTask(sensorStartMeasure, 103, 1000);
RTOS_SetTask(sensorGetData, 603, 1000);
}
es_event_t event = eventNull;
COLOR_RGB(0xFF, 0x12, 0x0); // Nixie color. FF7E00 or FFBF00
showTime();
/* Infinite loop */
while (1)
{
/* new second interrupt from RTC */
if (Flag.RTC_IRQ != 0) {
Flag.RTC_IRQ = 0;
RTC_ReadAll(&Clock);
ES_PlaceEvent(evNewSecond);
if (dispWDT != 0) {
dispWDT --;
if (dispWDT == 0) {
ES_PlaceEvent(evDisplayWDT);
}
}
} /* end of New second */
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
event = ES_GetEvent();
if (event) {
ES_Dispatch(event);
}
RTOS_DispatchTask();
__WFI();
}
/* USER CODE END 3 */
}
/**
* @brief Launch SPI transaction.
* @retval None
*/
static void tubes_Refresh(void) {
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
}
/**
* @brief Check I2C fjr errors.
* @retval I2C return code
*/
int8_t i2c_check_err(void) {
int8_t r = I2C_RET_OK;
if ((I2C1->ISR & I2C_ISR_NACKF) != 0) {
/* device not present */
r = I2C_RET_NACK;
} else if ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR)) != 0) {
/* other error */
r = I2C_RET_ERR;
}
if (r != I2C_RET_OK) {
/* restart I2C and clear flags */
I2C1->CR1 &= ~I2C_CR1_PE;
while ((I2C1->CR1 & I2C_CR1_PE) != 0) {};
I2C1->CR1 |= I2C_CR1_PE;
}
return r;
}
/**
* @brief Read len bytes from I2C bus to data by reg_addr.
* @retval I2C return code
*/
int8_t user_i2c_read(const uint8_t id, const uint8_t reg_addr, uint8_t *data, const uint16_t len) {
int8_t r = I2C_RET_OK;
Flag.I2C_RX_End = 0;
Flag.I2C_RX_Err = 0;
Flag.I2C_TX_Err = 0;
/* wait for i2c */
while ( I2C1->ISR & I2C_ISR_BUSY ) { __NOP(); };
/* prepare i2c for sending reg addr */
I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
I2C1->CR2 |= ( id | 1 << I2C_CR2_NBYTES_Pos );
/* gen START */
I2C1->CR2 |= ( I2C_CR2_START );
/* wait for byte request or any error */
while ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR | I2C_ISR_NACKF | I2C_ISR_TXE)) == 0) { __NOP(); };
if ((I2C2->ISR & I2C_ISR_TXE) != 0) {
/* device ok, send reg addr */
I2C1->TXDR = reg_addr;
} else {
r = i2c_check_err();
if (r != I2C_RET_OK) {
Flag.I2C_TX_Err = 1;
return r;
}
}
/* wait for i2c or any error */
while (((I2C1->ISR & I2C_ISR_BUSY) != 0) && ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR | I2C_ISR_NACKF)) == 0)) { __NOP(); };
r = i2c_check_err();
if (r != I2C_RET_OK) {
Flag.I2C_TX_Err = 1;
return r;
}
/* prepare dma channel for receiving data */
DMA1_Channel2->CMAR = (uint32_t)data;
DMA1_Channel2->CPAR = (uint32_t)&(I2C1->RXDR);
DMA1_Channel2->CNDTR = len;
DMA1_Channel2->CCR |= DMA_CCR_EN;
/* prepare i2c for receiving data */
I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
I2C1->CR2 |= ( id | len << I2C_CR2_NBYTES_Pos | I2C_CR2_RD_WRN);
/* launch receiving */
I2C1->CR1 |= ( I2C_CR1_RXDMAEN );
I2C1->CR2 |= ( I2C_CR2_START );
/* wait for receiving data */
while ((Flag.I2C_RX_End == 0) && (Flag.I2C_RX_Err == 0)) { __NOP(); };
return r;
}
/**
* @brief Write len bytes to I2C bus from data by reg_addr.
* @retval I2C return code
*/
int8_t user_i2c_write(const uint8_t id, const uint8_t reg_addr, uint8_t *data, const uint16_t len) {
int8_t r = I2C_RET_OK;
Flag.I2C_TX_End = 0;
Flag.I2C_TX_Err = 0;
DMA1_Channel3->CMAR = (uint32_t)data;
DMA1_Channel3->CPAR = (uint32_t)&(I2C1->TXDR);
DMA1_Channel3->CNDTR = len;
while ( I2C1->ISR & I2C_ISR_BUSY ) {};
I2C1->CR2 &= ~( I2C_CR2_SADD | I2C_CR2_NBYTES | I2C_CR2_RD_WRN);
I2C1->CR2 |= ( id | (len + 1) << I2C_CR2_NBYTES_Pos );
I2C1->CR2 |= ( I2C_CR2_START );
while ((I2C1->ISR & (I2C_ISR_ARLO | I2C_ISR_BERR | I2C_ISR_NACKF | I2C_ISR_TXE)) == 0) { __NOP(); };
if ((I2C2->ISR & I2C_ISR_TXE) != 0) {
I2C1->TXDR = reg_addr;
} else {
r = i2c_check_err();
if (r != I2C_RET_OK) {
Flag.I2C_TX_Err = 1;
return r;
}
}
DMA1_Channel3->CCR |= DMA_CCR_EN;
I2C1->CR1 |= ( I2C_CR1_TXDMAEN );
return r;
}
/**
* Sensor
*/
static void sensorStartMeasure(void) {
bme280_set_sensor_mode(BME280_FORCED_MODE, &SensorDev);
}
static void sensorGetData(void) {
bme280_get_sensor_data(BME280_ALL, &SensorData, &SensorDev);
int32_t tmp;
tmp = SensorData.humidity + 512;
Humidity = (int8_t)(tmp / 1024);
tmp = SensorData.temperature + 50;
Temperature = (int8_t)(tmp / 100);
/* in 32-bit arithmetics pressure in Pa */
tmp = SensorData.pressure * 1000;
tmp += 66661;
tmp /= 133322;
/* pressure in mmHg */
Pressure.s16.u8H = (uint8_t)(tmp / 100);
Pressure.s16.u8L = (uint8_t)(tmp % 100);
}
/**
* @brief System Clock Configuration
* @retval None
*/
void SystemClock_Config(void)
{
/* HSI configuration and activation */
LL_RCC_HSI_Enable();
while(LL_RCC_HSI_IsReady() != 1)
{
}
/* Main PLL configuration and activation */
LL_RCC_PLL_ConfigDomain_SYS(LL_RCC_PLLSOURCE_HSI, LL_RCC_PLLM_DIV_2, 9, LL_RCC_PLLR_DIV_3);
LL_RCC_PLL_Enable();
LL_RCC_PLL_EnableDomain_SYS();
while(LL_RCC_PLL_IsReady() != 1)
{
}
/* Set AHB prescaler*/
LL_RCC_SetAHBPrescaler(LL_RCC_SYSCLK_DIV_1);
/* Sysclk activation on the main PLL */
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_PLL);
while(LL_RCC_GetSysClkSource() != LL_RCC_SYS_CLKSOURCE_STATUS_PLL)
{
}
/* Set APB1 prescaler*/
LL_RCC_SetAPB1Prescaler(LL_RCC_APB1_DIV_1);
LL_Init1msTick(24000000);
/* Update CMSIS variable (which can be updated also through SystemCoreClockUpdate function) */
LL_SetSystemCoreClock(24000000);
LL_RCC_SetI2CClockSource(LL_RCC_I2C1_CLKSOURCE_HSI);
}
/**
* @brief I2C1 Initialization Function
* @param None
* @retval None
*/
static void MX_I2C1_Init(void)
{
/* USER CODE BEGIN I2C1_Init 0 */
/* USER CODE END I2C1_Init 0 */
LL_I2C_InitTypeDef I2C_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
/**I2C1 GPIO Configuration
PB6 ------> I2C1_SCL
PB7 ------> I2C1_SDA
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_7;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
GPIO_InitStruct.Alternate = LL_GPIO_AF_6;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
/* I2C1 DMA Init */
/* I2C1_RX Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_2, LL_DMAMUX_REQ_I2C1_RX);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_2, LL_DMA_DIRECTION_PERIPH_TO_MEMORY);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PRIORITY_MEDIUM);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_2, LL_DMA_MDATAALIGN_BYTE);
/* I2C1_TX Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_3, LL_DMAMUX_REQ_I2C1_TX);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_3, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PRIORITY_MEDIUM);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_3, LL_DMA_MDATAALIGN_BYTE);
/* I2C1 interrupt Init */
/* USER CODE BEGIN I2C1_Init 1 */
/* Enable DMA transfer complete/error interrupts */
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_2);
LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_2);
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_3);
LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_3);
/* USER CODE END I2C1_Init 1 */
/** I2C Initialization
*/
I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
I2C_InitStruct.Timing = 0x0010061A;
I2C_InitStruct.AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE;
I2C_InitStruct.DigitalFilter = 0;
I2C_InitStruct.OwnAddress1 = 0;
I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
LL_I2C_EnableAutoEndMode(I2C1);
LL_I2C_SetOwnAddress2(I2C1, 0, LL_I2C_OWNADDRESS2_NOMASK);
LL_I2C_DisableOwnAddress2(I2C1);
LL_I2C_DisableGeneralCall(I2C1);
LL_I2C_DisableClockStretching(I2C1);
LL_I2C_Init(I2C1, &I2C_InitStruct);
/* USER CODE BEGIN I2C1_Init 2 */
/* USER CODE END I2C1_Init 2 */
}
/**
* @brief SPI1 Initialization Function
* @param None
* @retval None
*/
static void MX_SPI1_Init(void)
{
/* USER CODE BEGIN SPI1_Init 0 */
/* USER CODE END SPI1_Init 0 */
LL_SPI_InitTypeDef SPI_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SPI1);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
/**SPI1 GPIO Configuration
PB3 ------> SPI1_SCK
PB5 ------> SPI1_MOSI
*/
GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/* SPI1 DMA Init */
/* SPI1_TX Init */
LL_DMA_SetPeriphRequest(DMA1, LL_DMA_CHANNEL_1, LL_DMAMUX_REQ_SPI1_TX);
LL_DMA_SetDataTransferDirection(DMA1, LL_DMA_CHANNEL_1, LL_DMA_DIRECTION_MEMORY_TO_PERIPH);
LL_DMA_SetChannelPriorityLevel(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PRIORITY_HIGH);
LL_DMA_SetMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MODE_CIRCULAR);
LL_DMA_SetPeriphIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PERIPH_NOINCREMENT);
LL_DMA_SetMemoryIncMode(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MEMORY_INCREMENT);
LL_DMA_SetPeriphSize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_PDATAALIGN_BYTE);
LL_DMA_SetMemorySize(DMA1, LL_DMA_CHANNEL_1, LL_DMA_MDATAALIGN_BYTE);
/* SPI1 interrupt Init */
NVIC_SetPriority(SPI1_IRQn, 0);
NVIC_EnableIRQ(SPI1_IRQn);
/* USER CODE BEGIN SPI1_Init 1 */
/* Enable DMA transfer complete/error interrupts */
LL_DMA_EnableIT_TC(DMA1, LL_DMA_CHANNEL_1);
LL_DMA_EnableIT_TE(DMA1, LL_DMA_CHANNEL_1);
/* USER CODE END SPI1_Init 1 */
/* SPI1 parameter configuration*/
SPI_InitStruct.TransferDirection = LL_SPI_FULL_DUPLEX;
SPI_InitStruct.Mode = LL_SPI_MODE_MASTER;
SPI_InitStruct.DataWidth = LL_SPI_DATAWIDTH_8BIT;
SPI_InitStruct.ClockPolarity = LL_SPI_POLARITY_LOW;
SPI_InitStruct.ClockPhase = LL_SPI_PHASE_1EDGE;
SPI_InitStruct.NSS = LL_SPI_NSS_SOFT;
SPI_InitStruct.BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV16;
SPI_InitStruct.BitOrder = LL_SPI_MSB_FIRST;
SPI_InitStruct.CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE;
SPI_InitStruct.CRCPoly = 7;
LL_SPI_Init(SPI1, &SPI_InitStruct);
LL_SPI_SetStandard(SPI1, LL_SPI_PROTOCOL_MOTOROLA);
LL_SPI_DisableNSSPulseMgt(SPI1);
/* USER CODE BEGIN SPI1_Init 2 */
/* USER CODE END SPI1_Init 2 */
}
/**
* @brief TIM3 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM3_Init(void)
{
/* USER CODE BEGIN TIM3_Init 0 */
/* USER CODE END TIM3_Init 0 */
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_TIM3);
/* USER CODE BEGIN TIM3_Init 1 */
/* USER CODE END TIM3_Init 1 */
TIM_InitStruct.Prescaler = 94;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 255;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM3, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM3);
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH1);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 25;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH1);
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH2);
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH2, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH2);
LL_TIM_OC_EnablePreload(TIM3, LL_TIM_CHANNEL_CH3);
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
LL_TIM_OC_Init(TIM3, LL_TIM_CHANNEL_CH3, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM3, LL_TIM_CHANNEL_CH3);
LL_TIM_SetTriggerOutput(TIM3, LL_TIM_TRGO_RESET);
LL_TIM_DisableMasterSlaveMode(TIM3);
/* USER CODE BEGIN TIM3_Init 2 */
/* USER CODE END TIM3_Init 2 */
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
/**TIM3 GPIO Configuration
PA6 ------> TIM3_CH1
PA7 ------> TIM3_CH2
PB0 ------> TIM3_CH3
*/
GPIO_InitStruct.Pin = PWM_R_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
LL_GPIO_Init(PWM_R_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PWM_G_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
LL_GPIO_Init(PWM_G_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PWM_B_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
GPIO_InitStruct.Alternate = LL_GPIO_AF_1;
LL_GPIO_Init(PWM_B_GPIO_Port, &GPIO_InitStruct);
}
/**
* @brief TIM14 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM14_Init(void)
{
/* USER CODE BEGIN TIM14_Init 0 */
/* USER CODE END TIM14_Init 0 */
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM14);
/* TIM14 interrupt Init */
NVIC_SetPriority(TIM14_IRQn, 0);
NVIC_EnableIRQ(TIM14_IRQn);
/* USER CODE BEGIN TIM14_Init 1 */
/* USER CODE END TIM14_Init 1 */
TIM_InitStruct.Prescaler = 240;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 1000;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
LL_TIM_Init(TIM14, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM14);
LL_TIM_OC_EnablePreload(TIM14, LL_TIM_CHANNEL_CH1);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 750;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
LL_TIM_OC_Init(TIM14, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM14, LL_TIM_CHANNEL_CH1);
/* USER CODE BEGIN TIM14_Init 2 */
/* USER CODE END TIM14_Init 2 */
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
/**TIM14 GPIO Configuration
PB1 ------> TIM14_CH1
*/
GPIO_InitStruct.Pin = PWM_T_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
GPIO_InitStruct.Alternate = LL_GPIO_AF_0;
LL_GPIO_Init(PWM_T_GPIO_Port, &GPIO_InitStruct);
}
/**
* @brief TIM16 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM16_Init(void)
{
/* USER CODE BEGIN TIM16_Init 0 */
/* USER CODE END TIM16_Init 0 */
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM16);
/* TIM16 interrupt Init */
NVIC_SetPriority(TIM16_IRQn, 0);
NVIC_EnableIRQ(TIM16_IRQn);
/* USER CODE BEGIN TIM16_Init 1 */
/* USER CODE END TIM16_Init 1 */
TIM_InitStruct.Prescaler = 24;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 1000;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
TIM_InitStruct.RepetitionCounter = 0;
LL_TIM_Init(TIM16, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM16);
LL_TIM_OC_EnablePreload(TIM16, LL_TIM_CHANNEL_CH1);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 0;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
LL_TIM_OC_Init(TIM16, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM16, LL_TIM_CHANNEL_CH1);
TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
TIM_BDTRInitStruct.DeadTime = 0;
TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
LL_TIM_BDTR_Init(TIM16, &TIM_BDTRInitStruct);
/* USER CODE BEGIN TIM16_Init 2 */
/* USER CODE END TIM16_Init 2 */
}
/**
* @brief TIM17 Initialization Function
* @param None
* @retval None
*/
static void MX_TIM17_Init(void)
{
/* USER CODE BEGIN TIM17_Init 0 */
/* USER CODE END TIM17_Init 0 */
LL_TIM_InitTypeDef TIM_InitStruct = {0};
LL_TIM_OC_InitTypeDef TIM_OC_InitStruct = {0};
LL_TIM_BDTR_InitTypeDef TIM_BDTRInitStruct = {0};
/* Peripheral clock enable */
LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_TIM17);
/* TIM17 interrupt Init */
NVIC_SetPriority(TIM17_IRQn, 0);
NVIC_EnableIRQ(TIM17_IRQn);
/* USER CODE BEGIN TIM17_Init 1 */
/* USER CODE END TIM17_Init 1 */
TIM_InitStruct.Prescaler = 240;
TIM_InitStruct.CounterMode = LL_TIM_COUNTERMODE_UP;
TIM_InitStruct.Autoreload = 1000;
TIM_InitStruct.ClockDivision = LL_TIM_CLOCKDIVISION_DIV1;
TIM_InitStruct.RepetitionCounter = 100;
LL_TIM_Init(TIM17, &TIM_InitStruct);
LL_TIM_EnableARRPreload(TIM17);
LL_TIM_OC_EnablePreload(TIM17, LL_TIM_CHANNEL_CH1);
TIM_OC_InitStruct.OCMode = LL_TIM_OCMODE_PWM1;
TIM_OC_InitStruct.OCState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.OCNState = LL_TIM_OCSTATE_DISABLE;
TIM_OC_InitStruct.CompareValue = 0;
TIM_OC_InitStruct.OCPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCNPolarity = LL_TIM_OCPOLARITY_HIGH;
TIM_OC_InitStruct.OCIdleState = LL_TIM_OCIDLESTATE_LOW;
TIM_OC_InitStruct.OCNIdleState = LL_TIM_OCIDLESTATE_LOW;
LL_TIM_OC_Init(TIM17, LL_TIM_CHANNEL_CH1, &TIM_OC_InitStruct);
LL_TIM_OC_DisableFast(TIM17, LL_TIM_CHANNEL_CH1);
TIM_BDTRInitStruct.OSSRState = LL_TIM_OSSR_DISABLE;
TIM_BDTRInitStruct.OSSIState = LL_TIM_OSSI_DISABLE;
TIM_BDTRInitStruct.LockLevel = LL_TIM_LOCKLEVEL_OFF;
TIM_BDTRInitStruct.DeadTime = 0;
TIM_BDTRInitStruct.BreakState = LL_TIM_BREAK_DISABLE;
TIM_BDTRInitStruct.BreakPolarity = LL_TIM_BREAK_POLARITY_HIGH;
TIM_BDTRInitStruct.BreakFilter = LL_TIM_BREAK_FILTER_FDIV1;
TIM_BDTRInitStruct.AutomaticOutput = LL_TIM_AUTOMATICOUTPUT_DISABLE;
LL_TIM_BDTR_Init(TIM17, &TIM_BDTRInitStruct);
/* USER CODE BEGIN TIM17_Init 2 */
/* USER CODE END TIM17_Init 2 */
}
/**
* Enable DMA controller clock
*/
static void MX_DMA_Init(void)
{
/* Init with LL driver */
/* DMA controller clock enable */
LL_AHB1_GRP1_EnableClock(LL_AHB1_GRP1_PERIPH_DMA1);
/* DMA interrupt init */
/* DMA1_Channel1_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel1_IRQn, 0);
NVIC_EnableIRQ(DMA1_Channel1_IRQn);
/* DMA1_Channel2_3_IRQn interrupt configuration */
NVIC_SetPriority(DMA1_Channel2_3_IRQn, 0);
NVIC_EnableIRQ(DMA1_Channel2_3_IRQn);
}
/**
* @brief GPIO Initialization Function
* @param None
* @retval None
*/
static void MX_GPIO_Init(void)
{
LL_EXTI_InitTypeDef EXTI_InitStruct = {0};
LL_GPIO_InitTypeDef GPIO_InitStruct = {0};
/* GPIO Ports Clock Enable */
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOB);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOC);
LL_IOP_GRP1_EnableClock(LL_IOP_GRP1_PERIPH_GPIOA);
/**/
LL_GPIO_ResetOutputPin(LC0_GPIO_Port, LC0_Pin);
/**/
LL_GPIO_ResetOutputPin(LC1_GPIO_Port, LC1_Pin);
/**/
LL_GPIO_ResetOutputPin(LC2_GPIO_Port, LC2_Pin);
/**/
LL_GPIO_ResetOutputPin(LC3_GPIO_Port, LC3_Pin);
/**/
LL_GPIO_ResetOutputPin(SHDN_GPIO_Port, SHDN_Pin);
/**/
LL_GPIO_ResetOutputPin(Latch_GPIO_Port, Latch_Pin);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_14;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LC0_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO_Init(LC0_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LC1_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO_Init(LC1_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LC2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO_Init(LC2_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LC3_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO_Init(LC3_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = SHDN_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
GPIO_InitStruct.Pull = LL_GPIO_PULL_DOWN;
LL_GPIO_Init(SHDN_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_5;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_2;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = BTN1_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(BTN1_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = BTN2_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(BTN2_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_6;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = BTN3_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(BTN3_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = BTN4_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(BTN4_GPIO_Port, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_12;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = LL_GPIO_PIN_15;
GPIO_InitStruct.Mode = LL_GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/**/
GPIO_InitStruct.Pin = Latch_Pin;
GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
GPIO_InitStruct.Pull = LL_GPIO_PULL_NO;
LL_GPIO_Init(Latch_GPIO_Port, &GPIO_InitStruct);
/**/
LL_EXTI_SetEXTISource(LL_EXTI_CONFIG_PORTB, LL_EXTI_CONFIG_LINE8);
/**/
EXTI_InitStruct.Line_0_31 = LL_EXTI_LINE_8;
EXTI_InitStruct.LineCommand = ENABLE;
EXTI_InitStruct.Mode = LL_EXTI_MODE_IT;
EXTI_InitStruct.Trigger = LL_EXTI_TRIGGER_RISING;
LL_EXTI_Init(&EXTI_InitStruct);
/**/
LL_GPIO_SetPinPull(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_PULL_UP);
/**/
LL_GPIO_SetPinMode(IRQ_GPIO_Port, IRQ_Pin, LL_GPIO_MODE_INPUT);
/* EXTI interrupt init*/
NVIC_SetPriority(EXTI4_15_IRQn, 0);
NVIC_EnableIRQ(EXTI4_15_IRQn);
}
/* USER CODE BEGIN 4 */
/**
* S U B R O U T I N E S
*/
/* Feel byte with tube position by digit.
* If digit == 0xf, then tube is off -- clear all bits.
*/
static void showDigit(tube_pos_t pos, uint8_t dig)
{
if (dig > 9) {
if (dig != 0xf) {
dig = 0;
}
}
switch (pos) {
case Tube_E:
tubesBuffer[0] = 0;
tubesBuffer[1] &= nixieCathodeMask[Tube_E][1];
if (Tube_E != 0xf) {
tubesBuffer[0] = (uint8_t)(nixieCathodeMap[Tube_E][dig] >> 8);
tubesBuffer[1] |= (uint8_t)(nixieCathodeMap[Tube_E][dig]);
}
break;
case Tube_D:
tubesBuffer[1] &= nixieCathodeMask[Tube_D][0];
tubesBuffer[2] &= nixieCathodeMask[Tube_D][1];
if (Tube_D != 0xf) {
tubesBuffer[1] |= (uint8_t)(nixieCathodeMap[Tube_D][dig] >> 8);
tubesBuffer[2] |= (uint8_t)(nixieCathodeMap[Tube_D][dig]);
}
break;
case Tube_B:
tubesBuffer[2] &= nixieCathodeMask[Tube_B][0];
tubesBuffer[3] &= nixieCathodeMask[Tube_B][1];
if (Tube_B != 0xf) {
tubesBuffer[2] |= (uint8_t)(nixieCathodeMap[Tube_B][dig] >> 8);
tubesBuffer[3] |= (uint8_t)(nixieCathodeMap[Tube_B][dig]);
}
break;
case Tube_A:
tubesBuffer[3] &= nixieCathodeMask[Tube_A][0];
tubesBuffer[4] = 0;
if (Tube_A != 0xf) {
tubesBuffer[3] |= (uint8_t)(nixieCathodeMap[Tube_A][dig] >> 8);
tubesBuffer[4] = (uint8_t)(nixieCathodeMap[Tube_A][dig]);
}
break;
default:
break;
}
}
/**
* @brief Обработка кнопок.
* @param : None
* @retval : None
*/
static void btnProcess(void) {
/* get pin state */
uint32_t pins = BTN_PORT->IDR & BTN_PINS;
int i;
for (i=0; i= (BTN_TIME_HOLDED/BTN_SCAN_PERIOD)) {
Button[i].time -= (BTN_TIME_REPEATED/BTN_SCAN_PERIOD);
if (Button[i].holded == Button[i].pressed) {
/* if pressed and holded - same function, then button pressed auto repeat */
ES_PlaceEvent(Button[i].pressed);
}
}
} else if (Button[i].time != 0) {
/* button released */
if (Button[i].time >= ((BTN_TIME_HOLDED - BTN_TIME_REPEATED)/BTN_SCAN_PERIOD)) {
/* process long press */
ES_PlaceEvent(Button[i].holded);
} else if (Button[i].time >= (BTN_TIME_PRESSED/BTN_SCAN_PERIOD)) {
/* process short press */
ES_PlaceEvent(Button[i].pressed);
}
Button[i].time = 0;
RTOS_SetTask(btnProcess, BTN_SCAN_PAUSE, BTN_SCAN_PERIOD);
}
} /* end FOR */
}
void in15Off(void) {
IN15_OFF;
}
void in15Minus(void) {
IN15_OFF;
IN15_Minus;
}
void in15Plus(void) {
IN15_OFF;
IN15_Plus;
}
void in15Percent(void) {
IN15_OFF;
IN15_Percent;
}
void in15P(void) {
IN15_OFF;
IN15_P;
}
void showTime(void) {
in15Minus();
RTOS_SetTask(in15Off, 500, 0);
showDigit(Tube_A, Clock.Hr >> 4);
showDigit(Tube_B, Clock.Hr & 0xf);
showDigit(Tube_D, Clock.Min >> 4);
showDigit(Tube_E, Clock.Min & 0xf);
tubes_Refresh();
}
void showWD(void) {
dispWDT = DISP_WDT_TIME;
IN15_OFF;
showDigit(Tube_A, 0xf);
showDigit(Tube_B, Clock.WD & 0xf);
showDigit(Tube_D, 0xf);
showDigit(Tube_E, 0xf);
tubes_Refresh();
}
void showDay(void) {
dispWDT = DISP_WDT_TIME;
IN15_OFF;
showDigit(Tube_A, Clock.Day >> 4);
showDigit(Tube_B, Clock.Day & 0xf);
showDigit(Tube_D, 0xf);
showDigit(Tube_E, 0xf);
tubes_Refresh();
}
void showMonth(void) {
dispWDT = DISP_WDT_TIME;
IN15_OFF;
showDigit(Tube_A, 0xf);
showDigit(Tube_B, 0xf);
showDigit(Tube_D, Clock.Mon >> 4);
showDigit(Tube_E, Clock.Mon & 0xf);
tubes_Refresh();
}
void showDayMon(void) {
dispWDT = DISP_WDT_TIME;
IN15_OFF;
showDigit(Tube_A, Clock.Day >> 4);
showDigit(Tube_B, Clock.Day & 0xf);
showDigit(Tube_D, Clock.Mon >> 4);
showDigit(Tube_E, Clock.Mon & 0xf);
tubes_Refresh();
}
void showYear(void) {
dispWDT = DISP_WDT_TIME;
IN15_OFF;
showDigit(Tube_A, 2);
showDigit(Tube_B, 0);
showDigit(Tube_D, Clock.Year >> 4);
showDigit(Tube_E, Clock.Year & 0xf);
tubes_Refresh();
}
void showHumidity(void) {
dispWDT = DISP_WDT_TIME;
in15Percent();
showDigit(Tube_A, Humidity >> 4);
showDigit(Tube_B, Humidity & 0xf);
showDigit(Tube_D, 0xf);
showDigit(Tube_E, 0xf);
tubes_Refresh();
}
void showTemperature(void) {
dispWDT = DISP_WDT_TIME;
in15Plus();
showDigit(Tube_A, 0xf);
showDigit(Tube_B, 0xf);
showDigit(Tube_D, Temperature >> 4);
showDigit(Tube_E, Temperature & 0xf);
tubes_Refresh();
}
void showPressure(void) {
dispWDT = DISP_WDT_TIME;
in15P();
showDigit(Tube_A, 0xf);
showDigit(Tube_B, Pressure.s16.u8H & 0xf);
showDigit(Tube_D, Pressure.s16.u8L >> 4);
showDigit(Tube_E, Pressure.s16.u8L & 0xf);
tubes_Refresh();
}
/* Simple function for cyclic show all sensor data */
void showSensorData(void) {
ES_SetState(stShowSensorData);
showTemperature();
tdelay_ms(3000);
showHumidity();
tdelay_ms(3000);
showPressure();
tdelay_ms(3000);
ES_SetState(stShowTime);
showTime();
}
/* USER CODE END 4 */
/**
* @brief This function is executed in case of error occurrence.
* @retval None
*/
void Error_Handler(void)
{
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
while (1)
{
}
/* USER CODE END Error_Handler_Debug */
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* USER CODE END 6 */
}
#endif /* USE_FULL_ASSERT */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/