Browse Source

Added hsv2rgb test.

Vladimir N. Shilov 3 years ago
parent
commit
b7d90be1f0
7 changed files with 264 additions and 254 deletions
  1. 78 40
      Inc/board.h
  2. 1 16
      Inc/main.h
  3. 0 2
      Inc/sensor.h
  4. 1 0
      Makefile
  5. 161 0
      Src/board.c
  6. 20 193
      Src/main.c
  7. 3 3
      Src/sensor.c

+ 78 - 40
Inc/board.h

@@ -4,49 +4,51 @@
 #define _BOARD_H
 
 /* Includes */
-#include "stm32g0xx.h"
+#include "main.h"
 #include "gpio.h"
 
 /* Exported macros */
-#define LATCH_DOWN    GPIOC->BRR = 0x40
-#define LATCH_UP      GPIOC->BSRR = 0x40
-
-#define TUBE_PWR_ON   GPIOA->BRR = 0x10
-#define TUBE_PWR_OFF  GPIOA->BSRR = 0x10
-
-#define TUBE_A_ON     TIM1->CCER |= (TIM_CCER_CC1E)
-#define TUBE_B_ON     TIM3->CCER |= (TIM_CCER_CC4E)
-#define TUBE_C_ON     TIM3->CCER |= (TIM_CCER_CC3E)
-#define TUBE_D_ON     TIM3->CCER |= (TIM_CCER_CC2E)
-#define TUBE_E_ON     TIM3->CCER |= (TIM_CCER_CC1E)
-#define TUBE_BCDE_ON	 TIM3->CCER |= (TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E)
-#define TUBE_ALL_ON		 TUBE_A_ON; TUBE_BCDE_ON
-
-#define TUBE_A_OFF    TIM1->CCER &= ~(TIM_CCER_CC1E)
-#define TUBE_B_OFF    TIM3->CCER &= ~(TIM_CCER_CC4E)
-#define TUBE_C_OFF    TIM3->CCER &= ~(TIM_CCER_CC3E)
-#define TUBE_D_OFF    TIM3->CCER &= ~(TIM_CCER_CC2E)
-#define TUBE_E_OFF    TIM3->CCER &= ~(TIM_CCER_CC1E)
-
-#define IN15_P        GPIOA->BSRR = 0x1
-#define IN15_Plus     GPIOA->BSRR = 0x2
-#define IN15_Minus    GPIOA->BSRR = 0x4
-#define IN15_Percent  GPIOA->BSRR = 0x8
-#define IN15_OFF      GPIOA->BRR = 0xF
-
-#define COLOR_R(x)    TIM1->CCR2 = x
-#define COLOR_G(x)    TIM1->CCR3 = x
-#define COLOR_B(x)    TIM1->CCR4 = x
+#define LATCH_DOWN      GPIOC->BRR = 0x40
+#define LATCH_UP        GPIOC->BSRR = 0x40
+
+#define TUBE_PWR_ON     GPIOA->BRR = 0x10
+#define TUBE_PWR_OFF    GPIOA->BSRR = 0x10
+
+#define TUBE_A_ON       TIM1->CCER |= (TIM_CCER_CC1E)
+#define TUBE_B_ON       TIM3->CCER |= (TIM_CCER_CC4E)
+#define TUBE_C_ON       TIM3->CCER |= (TIM_CCER_CC3E)
+#define TUBE_D_ON       TIM3->CCER |= (TIM_CCER_CC2E)
+#define TUBE_E_ON       TIM3->CCER |= (TIM_CCER_CC1E)
+#define TUBE_BCDE_ON    TIM3->CCER |= (TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E)
+#define TUBE_ALL_ON		TUBE_A_ON; TUBE_BCDE_ON
+
+#define TUBE_A_OFF      TIM1->CCER &= ~(TIM_CCER_CC1E)
+#define TUBE_B_OFF      TIM3->CCER &= ~(TIM_CCER_CC4E)
+#define TUBE_C_OFF      TIM3->CCER &= ~(TIM_CCER_CC3E)
+#define TUBE_D_OFF      TIM3->CCER &= ~(TIM_CCER_CC2E)
+#define TUBE_E_OFF      TIM3->CCER &= ~(TIM_CCER_CC1E)
+#define TUBE_BCDE_OFF   TIM3->CCER &= ~(TIM_CCER_CC1E | TIM_CCER_CC2E | TIM_CCER_CC3E | TIM_CCER_CC4E)
+#define TUBE_ALL_OFF	TUBE_A_OFF; TUBE_BCDE_OFF
+
+#define IN15_P          GPIOA->BSRR = 0x1
+#define IN15_Plus       GPIOA->BSRR = 0x2
+#define IN15_Minus      GPIOA->BSRR = 0x4
+#define IN15_Percent    GPIOA->BSRR = 0x8
+#define IN15_OFF        GPIOA->BRR = 0xF
+
+#define COLOR_R(x)      TIM1->CCR2 = x
+#define COLOR_G(x)      TIM1->CCR3 = x
+#define COLOR_B(x)      TIM1->CCR4 = x
 
 /* Constants */
-#define PWM_LED_INIT_VAL    500
-#define PWM_TUBE_INIT_VAL   500
-
-#define TIM1_PSC            (120 - 1)
-#define TIM1_ARR            (1000 - 1)
-
-#define TIM3_PSC            (120 - 1)
-#define TIM3_ARR            (1000 - 1)
+/* PWM Timers for 250 Hz */
+#define TIM1_PSC            (375 - 1)
+#define TIM1_ARR            (256 - 1)
+#define TIM3_PSC            (375 - 1)
+#define TIM3_ARR            (256 - 1)
+#define PWM_TUBE_INIT_VAL   127
+#define PWM_LED_INIT_VAL    127
+#define PWM_LED_MAX_VAL     TIM3_ARR
 
 #define TIM14_PSC            (24000 - 1)
 #define TIM14_ARR            (1000 - 1)
@@ -107,15 +109,51 @@
 #define UART_ST_GPIO_Port GPIOA
 #define UART_ST_Pin GPIO_PIN_15
 
+/* BTNs */
+#define BTN_NUM             4
+#define BTN1_PIN            GPIO_IDR_ID2
+#define BTN2_PIN            GPIO_IDR_ID12
+#define BTN3_PIN            GPIO_IDR_ID4
+#define BTN4_PIN            GPIO_IDR_ID5
+#define BTN1_STATE          (BTN1_GPIO_Port->IDR & BTN1_PIN)
+#define BTN2_STATE          (BTN2_GPIO_Port->IDR & BTN2_PIN)
+#define BTN3_STATE          (BTN3_GPIO_Port->IDR & BTN3_PIN)
+#define BTN4_STATE          (BTN4_GPIO_Port->IDR & BTN4_PIN)
+#define BTNS1_STATE         (GPIOB->IDR & (BTN1_PIN | BTN3_PIN))
+#define BTNS2_STATE         (GPIOA->IDR & (BTN2_PIN | BTN4_PIN))
+#define BTNS_STATE          (BTNS1_STATE | BTNS2_STATE)
+
 /* Variables */
 #ifndef __ARMCC_VERSION
 uint32_t SystemCoreClock;
 #endif
 
-/* Expoted funcions */
+/* Type Defs */
+typedef enum {
+  Tube_A = 3,
+  Tube_B = 2,
+  Tube_D = 1,
+  Tube_E = 0
+} tube_pos_t;
+
+typedef struct {
+    uint8_t r;
+    uint8_t g;
+    uint8_t b;
+} RGB_t;
+
+typedef struct {
+    uint8_t h;
+    uint8_t s;
+    uint8_t v;
+} HSV_t;
+
+/* Exported funcions */
 void SystemClock_Config(void);
 void Board_Init();
 void Blink_Start(void);
 void Blink_Stop(void);
+void showDigits(uint8_t * dig);
+void HSV2LED(const int hue, const uint8_t sat, const uint8_t val);
 
-#endif
+#endif /* _BPARD_H */

+ 1 - 16
Inc/main.h

@@ -50,7 +50,7 @@ extern "C" {
 /* Private includes ----------------------------------------------------------*/
 /* USER CODE BEGIN Includes */
 #include "board.h"
-#include "gpio.h"
+#include "sensor.h"
 #include "i2c.h"
 #include "ds3231.h"
 #include "bme280.h"
@@ -137,21 +137,6 @@ void Error_Handler(void);
 
 /* Private defines -----------------------------------------------------------*/
 /* USER CODE BEGIN Private defines */
-
-/* BTNs */
-#define BTN_NUM             4
-#define BTN1_PIN            GPIO_IDR_ID2
-#define BTN2_PIN            GPIO_IDR_ID12
-#define BTN3_PIN            GPIO_IDR_ID4
-#define BTN4_PIN            GPIO_IDR_ID5
-#define BTN1_STATE          (BTN1_GPIO_Port->IDR & BTN1_PIN)
-#define BTN2_STATE          (BTN2_GPIO_Port->IDR & BTN2_PIN)
-#define BTN3_STATE          (BTN3_GPIO_Port->IDR & BTN3_PIN)
-#define BTN4_STATE          (BTN4_GPIO_Port->IDR & BTN4_PIN)
-#define BTNS1_STATE         (GPIOB->IDR & (BTN1_PIN | BTN3_PIN))
-#define BTNS2_STATE         (GPIOA->IDR & (BTN2_PIN | BTN4_PIN))
-#define BTNS_STATE          (BTNS1_STATE | BTNS2_STATE)
-
 /* time constant in ms */
 #define BTN_SCAN_PERIOD     10
 #define BTN_SCAN_PAUSE      200

+ 0 - 2
Inc/sensor.h

@@ -6,8 +6,6 @@
 #include "main.h"
 
 /* Variables */
-struct bme280_dev SensorDev;
-struct bme280_data SensorData;
 int8_t Humidity, Temperature;
 uint16_t Pressure;
 

+ 1 - 0
Makefile

@@ -41,6 +41,7 @@ BUILD_DIR = build
 C_SOURCES =  \
 Src/main.c \
 Src/board.c \
+Src/sensor.c \
 Src/stm32g0xx_it.c \
 Src/i2c.c \
 Src/ds3231.c \

+ 161 - 0
Src/board.c

@@ -1,6 +1,33 @@
 #include "board.h"
 
+/* private defines */
+#define SPI_BUFFER_SIZE 5
+
 /* private variables */
+/**
+ * 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};
+
+/* private typedef */
 
 /* private functions */
 static void GPIO_Init(void);
@@ -40,7 +67,23 @@ void Board_Init(void)
   GPIO_Init();
   DMA_Init();
   I2C1_Init();
+
   SPI1_Init();
+  /** Star SPI transfer to shift registers */
+  /* 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 transfer */
+  SPI1->CR1 |= SPI_CR1_SPE;
+  Flag.SPI_TX_End = 1;
+
+  /* Enable tube power */
+  TUBE_PWR_ON;
+  /* display work now */
 
   /* Start RGB & Tube Power PWM */
   TIM1_Init();
@@ -54,6 +97,124 @@ void Board_Init(void)
   //USART1_UART_Init();
 }
 
+/**
+  * @brief  Out digits to SPI buffer. ON/off tube power.
+  * @param  : array with four BCD digits
+  * @retval : None
+  */
+void showDigits(uint8_t * dig)
+{
+  /* Clear buffer */
+  tubesBuffer[0] = 0;
+  tubesBuffer[1] = 0;
+  tubesBuffer[2] = 0;
+  tubesBuffer[3] = 0;
+  tubesBuffer[4] = 0;
+
+  /* check values range */
+  int i;
+  for (i=0; i<4; i++) {
+    if (dig[i] > 9) {
+      if (dig[i] != 0xf) {
+        dig[i] = 0;
+      }
+    }
+  }
+
+  /* Wait for SPI */
+  while (Flag.SPI_TX_End == 0) {};
+  Flag.SPI_TX_End = 0;
+
+  /* Feel buffer */
+  tubesBuffer[0] = (uint8_t)(nixieCathodeMap[Tube_E][dig[Tube_E]] >> 8);
+  tubesBuffer[1] = (uint8_t)((nixieCathodeMap[Tube_E][dig[Tube_E]]) | (nixieCathodeMap[Tube_D][dig[Tube_D]] >> 8));
+  tubesBuffer[2] = (uint8_t)((nixieCathodeMap[Tube_D][dig[Tube_D]]) | (nixieCathodeMap[Tube_B][dig[Tube_B]] >> 8));
+  tubesBuffer[3] = (uint8_t)((nixieCathodeMap[Tube_B][dig[Tube_B]]) | (nixieCathodeMap[Tube_A][dig[Tube_A]] >> 8));
+  tubesBuffer[4] = (uint8_t)(nixieCathodeMap[Tube_A][dig[Tube_A]]);
+
+  /* Start DMA transfer to SPI */
+  DMA1_Channel1->CCR |= DMA_CCR_EN;
+
+  /* On/Off tube power */
+  if (dig[Tube_A] == 0xf) {
+    TUBE_A_OFF;
+  } else {
+    TUBE_A_ON;
+  }
+  if (dig[Tube_B] == 0xf) {
+    TUBE_B_OFF;
+  } else {
+    TUBE_B_ON;
+  }
+  if (dig[Tube_D] == 0xf) {
+    TUBE_D_OFF;
+  } else {
+    TUBE_D_ON;
+  }
+  if (dig[Tube_E] == 0xf) {
+    TUBE_E_OFF;
+  } else {
+    TUBE_E_ON;
+  }
+
+}
+
+/**
+ * @brief  HSV to RGB convertion
+ * @param  hue: 0-359, sat: 0-255, val (lightness): 0-255
+ * @return none. RGB value out direct to LED.
+ */
+void HSV2LED(const int hue, const uint8_t sat, const uint8_t val) {
+  int r, g, b, base;
+  uint8_t colors[3];
+
+  if (sat == 0)
+  { // Achromatic color (gray).
+    colors[0] = val;
+    colors[1] = val;
+    colors[2] = val;
+  } else {
+
+    base = ((255 - sat) * val) >> 8;
+    switch (hue / 60) {
+    case 0:
+      colors[0] = val;
+      colors[1] = (((val - base) * hue) / 60) + base;
+      colors[2] = base;
+      break;
+    case 1:
+      colors[0] = (((val - base) * (60 - (hue % 60))) / 60) + base;
+      colors[1] = val;
+      colors[2] = base;
+      break;
+    case 2:
+      colors[0] = base;
+      colors[1] = val;
+      colors[2] = (((val - base) * (hue % 60)) / 60) + base;
+      break;
+    case 3:
+      colors[0] = base;
+      colors[1] = (((val - base) * (60 - (hue % 60))) / 60) + base;
+      colors[2] = val;
+      break;
+    case 4:
+      colors[0] = (((val - base) * (hue % 60)) / 60) + base;
+      colors[1] = base;
+      colors[2] = val;
+      break;
+    case 5:
+      colors[0] = val;
+      colors[1] = base;
+      colors[2] = (((val - base) * (60 - (hue % 60))) / 60) + base;
+      break;
+    }
+  }
+
+  COLOR_R(colors[0]);
+  COLOR_G(colors[1]);
+  COLOR_B(colors[2]);
+}
+
 /**
   * @brief System Clock Configuration
   * @retval None

+ 20 - 193
Src/main.c

@@ -22,25 +22,16 @@
 
 /* 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 -------------------------------------------------------------*/
@@ -51,33 +42,7 @@ typedef enum {
 
 /* USER CODE BEGIN PV */
 volatile flag_t Flag = {0};
-/**
- * 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},
@@ -90,12 +55,9 @@ static volatile uint8_t dispWDT = 0;
 
 /* Private function prototypes -----------------------------------------------*/
 /* USER CODE BEGIN PFP */
-static void showDigits(uint8_t * dig);
-static void sensor_Init(void);
-static void sensorStartMeasure(void);
-static void sensorGetData(void);
 static void btnProcess(void);
 static void Color_RGB(uint8_t r, uint8_t g, uint8_t b);
+static void ColorCircle(void);
 /* USER CODE END PFP */
 
 /* Private user code ---------------------------------------------------------*/
@@ -123,21 +85,6 @@ int main(void)
   ES_Init(stShowTime);
   es_event_t event = eventNull;
 
-  /* Enable tube power */
-  TUBE_PWR_ON;
-  /** Star SPI transfer to shift registers */
-  /* 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 transfer */
-  SPI1->CR1 |= SPI_CR1_SPE;
-  Flag.SPI_TX_End = 1;
-  /* display work now */
-
   /** Set tasks for Sheduler */
   RTOS_SetTask(btnProcess, 1, BTN_SCAN_PERIOD);
 
@@ -151,6 +98,7 @@ int main(void)
     /* new second interrupt from RTC */
     if (Flag.RTC_IRQ != 0) {
       Flag.RTC_IRQ = 0;
+      ColorCircle();
 
 			Blink_Start(); // !!! TODO
       RTC_ReadAll(&Clock);
@@ -179,149 +127,25 @@ int main(void)
   /* USER CODE END 3 */
 } /* End of mine() */
 
-/**
-  * Sensor
-  */
-static void sensor_Init(void) {
-  int8_t rsltSensor;
-
-  Flag.BME280 = 0;
-  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;
-
-    /* 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);
-  }
-}
-
-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);
-}
-
 /* USER CODE BEGIN 4 */
 /*************************
  * S U B R O U T I N E S *
  *************************/
-
-/**
-  * @brief  Out digits to SPI buffer. ON/off tube power.
-  * @param  : array with four BCD digits
-  * @retval : None
-  */
-static void showDigits(uint8_t * dig)
-{
-  /* Clear buffer */
-  tubesBuffer[0] = 0;
-  tubesBuffer[1] = 0;
-  tubesBuffer[2] = 0;
-  tubesBuffer[3] = 0;
-  tubesBuffer[4] = 0;
-
-  /* check values range */
-  int i;
-  for (i=0; i<4; i++) {
-    if (dig[i] > 9) {
-      if (dig[i] != 0xf) {
-        dig[i] = 0;
-      }
-    }
-  }
-
-  /* Wait for SPI */
-  while (Flag.SPI_TX_End == 0) {};
-  Flag.SPI_TX_End = 0;
-
-  /* Feel buffer */
-  tubesBuffer[0] = (uint8_t)(nixieCathodeMap[Tube_E][dig[Tube_E]] >> 8);
-  tubesBuffer[1] = (uint8_t)((nixieCathodeMap[Tube_E][dig[Tube_E]]) | (nixieCathodeMap[Tube_D][dig[Tube_D]] >> 8));
-  tubesBuffer[2] = (uint8_t)((nixieCathodeMap[Tube_D][dig[Tube_D]]) | (nixieCathodeMap[Tube_B][dig[Tube_B]] >> 8));
-  tubesBuffer[3] = (uint8_t)((nixieCathodeMap[Tube_B][dig[Tube_B]]) | (nixieCathodeMap[Tube_A][dig[Tube_A]] >> 8));
-  tubesBuffer[4] = (uint8_t)(nixieCathodeMap[Tube_A][dig[Tube_A]]);
-
-  /* Start DMA transfer to SPI */
-  DMA1_Channel1->CCR |= DMA_CCR_EN;
-
-
-  /* On/Off tube power */
-  if (dig[Tube_A] == 0xf) {
-    TUBE_A_OFF;
-  } else {
-    TUBE_A_ON;
-  }
-  if (dig[Tube_B] == 0xf) {
-    TUBE_B_OFF;
-  } else {
-    TUBE_B_ON;
-  }
-  if (dig[Tube_D] == 0xf) {
-    TUBE_D_OFF;
-  } else {
-    TUBE_D_ON;
-  }
-  if (dig[Tube_E] == 0xf) {
-    TUBE_E_OFF;
-  } else {
-    TUBE_E_ON;
-  }
-
-}
 /**
   * @brief  Вывод HEX значений цвета в таймер.
   * @param  : RGB value in range 0x00-0xFF
   * @retval : None
   */
 static void Color_RGB(uint8_t r, uint8_t g, uint8_t b) {
-  /* Более быстрый вариант, на пробу. */
-  COLOR_R(r * 4);
-  COLOR_G(g * 4);
-  COLOR_B(b * 4);
-
-  /* Предварительный обсчёт в переменные сделан для того,
-     что-бы вывести значения в таймер максимально одновременно. */
-/*
-  uint32_t val_r, val_g, val_b;
-  // * 999 + 127 / 255 ???
-  val_r = ((uint32_t)(r * 1000) + 128) / 256;
-  val_g = ((uint32_t)(g * 1000) + 128) / 256;
-  val_b = ((uint32_t)(b * 1000) + 128) / 256;
-
-  COLOR_R((uint16_t)val_r);
-  COLOR_G((uint16_t)val_g);
-  COLOR_B((uint16_t)val_b);
-*/
+  COLOR_R(r);
+  COLOR_G(g);
+  COLOR_B(b);
+}
+
+/* cheng led color by time seconds */
+static void ColorCircle(void) {
+  uint8_t hue = Clock.Sec * 6;
+  HSV2LED(hue, 255, 255);
 }
 
 /**
@@ -392,6 +216,9 @@ void in15P(void) {
   TUBE_C_ON;
 }
 
+/**
+  * Show info on tubes.
+  */
 void showTime(void) {
   in15Minus();
   RTOS_SetTask(in15Off, 500, 0);
@@ -404,9 +231,6 @@ void showTime(void) {
   showDigits(buf);
 }
 
-/**
-  * Show info on tubes.
-  */
 void showWD(void) {
   dispWDT = DISP_WDT_TIME;
   IN15_OFF;
@@ -496,16 +320,19 @@ void showPressure(void) {
   in15P();
 
   uint8_t buf[4];
+  int tmp;
   buf[Tube_A] = 0xf;
-  buf[Tube_B] = Pressure.s16.u8H & 0xf;
-  buf[Tube_D] = Pressure.s16.u8L >> 4;
-  buf[Tube_E] = Pressure.s16.u8L & 0xf;
+  buf[Tube_B] = Pressure / 100;
+  tmp = Pressure % 100;
+  buf[Tube_D] = tmp / 10;
+  buf[Tube_E] = tmp % 10;
   showDigits(buf);
 }
 
 /* Simple function for cyclic show all sensor data */
 void showSensorData(void) {
   ES_SetState(stShowSensorData);
+  RTOS_DeleteTask(in15Off);
 
   showTemperature();
   tdelay_ms(3000);

+ 3 - 3
Src/sensor.c

@@ -1,8 +1,8 @@
 #include "sensor.h"
 
-/**
-  * Sensor
-  */
+static struct bme280_dev SensorDev;
+static struct bme280_data SensorData;
+
 void sensor_Init(void) {
   int8_t rsltSensor;