瀏覽代碼

Function reorder.

Vladimir N. Shilov 2 年之前
父節點
當前提交
42d02e6b63
共有 5 個文件被更改,包括 309 次插入346 次删除
  1. 9 13
      inc/board.h
  2. 13 0
      inc/display.h
  3. 5 333
      src/board.c
  4. 280 0
      src/display.c
  5. 2 0
      src/main.c

+ 9 - 13
inc/board.h

@@ -17,26 +17,22 @@ typedef enum {
 #define BUZER_ON    TIM1->CR1 |= TIM_CR1_CEN
 #define BUZER_OFF   TIM1->CR1 &= ~TIM_CR1_CEN
 
-/* Exported constants */
-#define DISPLAY_COLUMNS   24
-
-/* Variables */
-extern uint8_t display_Buffer[];
+/* Display macros */
+#define HT1632C_CS_ON     GPIOA->BRR = (1<<15)
+#define HT1632C_CS_OFF    GPIOA->BSRR = (1<<15)
+#define HT1632C_WR_LOW    GPIOB->BRR = (1<<3)
+#define HT1632C_WR_HGH    GPIOB->BSRR = (1<<3)
+#define HT1632C_DATA_0    GPIOB->BRR = (1<<5)
+#define HT1632C_DATA_1    GPIOB->BSRR = (1<<5)
 
 /* Exported funcions */
 void Board_Init(void);
-void display_Init(void);
-void display_WriteData(const uint8_t * data, uint8_t addr, uint8_t len);
-void display_WriteBuffer(void);
-void display_PWM(uint8_t pwm);
-void display_BlinkState(dis_en_t state);
-void display_LedState(dis_en_t state);
-void display_Fill(uint8_t pattern);
 void EXTI4_15_IRQHandler(void);
 void DMA1_Channel2_3_IRQHandler(void);
 void I2C1_IRQHandler(void);
-void display_test(void);
 void buzer_On(void);
 void buzer_Off(void);
+void GPIO_SPI_SW(void);
+void GPIO_SPI_HW(void);
 
 #endif /* _BOARD_H_ */

+ 13 - 0
inc/display.h

@@ -5,7 +5,20 @@
 /* Includes */
 #include "main.h"
 
+/* Exported constants */
+#define DISPLAY_COLUMNS   24
+
+/* Variables */
+extern uint8_t display_Buffer[];
+
 /* Exported function prototypes */
+void display_Init(void);
+void display_WriteData(const uint8_t * data, uint8_t addr, uint8_t len);
+void display_WriteBuffer(void);
+void display_PWM(uint8_t pwm);
+void display_BlinkState(dis_en_t state);
+void display_LedState(dis_en_t state);
+void display_Fill(uint8_t pattern);
 void display_Char(const uint8_t symb, uint8_t column);
 
 #endif /* _DISPLAY_H_ */

+ 5 - 333
src/board.c

@@ -1,34 +1,16 @@
 #include "main.h"
 
-/* private defines */
-#define FRAMEBUFFER_ROTATE
-
-/* private macros */
-#define HT1632C_CS_ON     GPIOA->BRR = (1<<15)
-#define HT1632C_CS_OFF    GPIOA->BSRR = (1<<15)
-#define HT1632C_WR_LOW    GPIOB->BRR = (1<<3)
-#define HT1632C_WR_HGH    GPIOB->BSRR = (1<<3)
-#define HT1632C_DATA_0    GPIOB->BRR = (1<<5)
-#define HT1632C_DATA_1    GPIOB->BSRR = (1<<5)
-
-/* private variables */
-uint8_t display_Buffer[DISPLAY_COLUMNS] = {0};
-
 /* private typedef */
 /* private functions */
 static void GPIO_Init(void);
 static void I2C1_Init(void);
 static void SPI1_Init(void);
-static void GPIO_SPI_SW(void);
-static void GPIO_SPI_HW(void);
 static void TIM1_Init(void);
 //static void TIM3_Init(void);
 //static void TIM14_Init(void);
 //static void TIM16_Init(void);
 static void TIM17_Init(void);
 //static void USART1_UART_Init(void);
-static void _display_WriteBits(uint16_t data, uint16_t nbits);
-static void _delay_c(uint32_t cycle);
 
 /* Board perephireal Configuration  */
 void Board_Init(void)
@@ -51,9 +33,9 @@ void Board_Init(void)
   NVIC_EnableIRQ(RCC_IRQn);
 
   /* Initialize all configured peripherals */
-  HT1632C_CS_OFF;
-  HT1632C_WR_HGH;
-  HT1632C_DATA_1;
+  //HT1632C_CS_OFF;
+  //HT1632C_WR_HGH;
+  //HT1632C_DATA_1;
   GPIO_Init();
 
   /* DMA interrupt init */
@@ -77,46 +59,6 @@ void Board_Init(void)
 //  TIM16_Init();
   TIM17_Init();
 //  USART1_UART_Init();
-
-  display_Init();
-}
-
-/* output 'L', 'G', '5' */
-void display_test(void) {
-  // prepare buffer
-// 1
-  display_Buffer[0] = 0x01;
-  display_Buffer[1] = 0x40;
-  display_Buffer[2] = 0x7e;
-  display_Buffer[3] = 0x40;
-  display_Buffer[4] = 0x01;
-// 2
-  display_Buffer[5] = 0x00;
-  display_Buffer[6] = 0x01;
-  display_Buffer[7] = 0x7c;
-  display_Buffer[8] = 0x41;
-  display_Buffer[9] = 0x00;
-// :
-  display_Buffer[10] = 0x00;
-  display_Buffer[11] = 0x36;
-  display_Buffer[12] = 0x36;
-  display_Buffer[13] = 0x00;
-// 3
-  display_Buffer[14] = 0x3e;
-  display_Buffer[15] = 0x49;
-  display_Buffer[16] = 0x49;
-  display_Buffer[17] = 0x41;
-  display_Buffer[18] = 0x22;
-// 4
-  display_Buffer[19] = 0x00;
-  display_Buffer[20] = 0x38;
-  display_Buffer[21] = 0x54;
-  display_Buffer[22] = 0x44;
-  display_Buffer[23] = 0x28;
-
-//  display_WriteData(display_Buffer, 0x0, DISPLAY_COLUMNS);
-//  tdelay_ms(1000);
-  display_WriteBuffer();
 }
 
 /**
@@ -186,7 +128,7 @@ static void GPIO_Init(void)
 /**
   * @brief Configure SPI pin for software mode
   */
-static void GPIO_SPI_SW(void) {
+void GPIO_SPI_SW(void) {
   // GPIO pin mode
   GPIOB->MODER &= ~(GPIO_MODER_MODER3 | GPIO_MODER_MODER5);
   GPIOB->MODER |= (GPIO_MODER_MODER3_0 | GPIO_MODER_MODER5_0);
@@ -195,7 +137,7 @@ static void GPIO_SPI_SW(void) {
 /**
   * @brief Configure SPI pin for hardware mode
   */
-static void GPIO_SPI_HW(void) {
+void GPIO_SPI_HW(void) {
   // SPI pin mode
   GPIOB->MODER &= ~(GPIO_MODER_MODER3 | GPIO_MODER_MODER5);
   GPIOB->MODER |= (GPIO_MODER_MODER3_1 | GPIO_MODER_MODER5_1);
@@ -244,27 +186,6 @@ static void SPI1_Init(void)
   SPI1->CR2 = (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0 | SPI_CR2_TXDMAEN);
 }
 
-/**
- * @brief Initialization HT1632C
- */
-void display_Init(void) {
-  /* Wait for SPI */
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-
-  GPIO_SPI_SW();
-  HT1632C_CS_ON;
-
-  // Turn on system oscillator
-  _display_WriteBits(0x802, 0x800);
-  // Turn on LED duty cycle generator
-  _display_WriteBits(0x6, 0x100);
-
-  HT1632C_CS_OFF;
-  GPIO_SPI_HW();
-
-  display_Fill(0x0);
-}
-
 /**
   * @brief TIM1 Initialization Function
   * @param None
@@ -303,255 +224,6 @@ static void TIM17_Init(void)
   TIM17->EGR = TIM_EGR_UG; // force timer update
 }
 
-/**
- * @brief Set HT1632C PWM Value
- * @param pwm value in 0-15
- */
-void display_PWM(uint8_t pwm) {
-  // check value
-  if (pwm > 15) {
-    pwm = 15;
-  }
-  // align value
-  pwm <<= 1;
-
-  /* Wait for SPI */
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-
-  GPIO_SPI_SW();
-
-  HT1632C_CS_ON;
-  _display_WriteBits((0x940|pwm), 0x800);
-  HT1632C_CS_OFF;
-
-  GPIO_SPI_HW();
-}
-
-/**
- * @brief Set HT1632C Blink state
- * @param state 0 for off, any other value for on
- */
-void display_BlinkState(dis_en_t state) {
-  /* Wait for SPI */
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-
-  GPIO_SPI_SW();
-
-  HT1632C_CS_ON;
-  if (state == Disable) {
-    _display_WriteBits(0x810, 0x800); // Blink off
-  } else {
-    _display_WriteBits(0x812, 0x800); // Blink on
-  }
-  HT1632C_CS_OFF;
-
-  GPIO_SPI_HW();
-}
-
-/**
- * @brief Set HT1632C Led state
- * @param state 0 for off, any other value for on
- */
-void display_LedState(dis_en_t state) {
-  /* Wait for SPI */
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-
-  GPIO_SPI_SW();
-
-  HT1632C_CS_ON;
-  if (state == Disable) {
-    _display_WriteBits(0x804, 0x800); // Led off
-  } else {
-    _display_WriteBits(0x806, 0x800); // Led on
-  }
-  HT1632C_CS_OFF;
-
-  GPIO_SPI_HW();
-}
-
-/**
- * @brief Primitive delay
- */
-static void _delay_c(uint32_t cycle) {
-  while (cycle) {
-    __NOP();
-    cycle --;
-  }
-}
-
-/**
- * @brief Write <nbits> bit of data to selected HT1632Cs
- * @param data words to write
- * @param nbits num of bits (1<<(num-1))
- */
-void _display_WriteBits(const uint16_t data, uint16_t nbits) {
-  _delay_c(2);
-  do {
-    HT1632C_WR_LOW;
-
-    if (data & nbits) {
-      HT1632C_DATA_1;
-    } else {
-      HT1632C_DATA_0;
-    }
-    _delay_c(5);
-    HT1632C_WR_HGH;
-    _delay_c(5);
-  } while (nbits >>= 1);
-}
-
-/**
- * @brief Write Data to display buffer, no transfer to HT1632.
- * @param data pointer to data array
- * @param addr begin address
- * @param len bytes to write
- */
-void display_WriteData(const uint8_t * data, uint8_t addr, uint8_t len) {
-  /* check given values */
-  if (len == 0) {
-    return;
-  }
-  if (addr >= DISPLAY_COLUMNS) {
-    addr = DISPLAY_COLUMNS - 1;
-  }
-  if ((addr + len) > DISPLAY_COLUMNS) {
-    len = DISPLAY_COLUMNS - addr;
-  }
-
-#ifdef FRAMEBUFFER_ROTATE
-  /* Copy given data to framebuffer */
-  int i, a;
-  for (i=0; i<len; i++) {
-    a = addr + i;
-    display_Buffer[a] = data[i];
-  }
-  //display_WriteBuffer();
-
-#else
-  // without dma - pool mode
-  int i;
-
-  GPIO_SPI_SW();
-  HT1632C_CS_ON;
-  i = (0x280 | addr);
-  // write addr
-  _display_WriteBits(i, 0x200);
-
-  GPIO_SPI_HW();
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-  for (i=0; i<len; i++) {
-    while ((SPI1->SR & SPI_SR_TXE) == 0) { __NOP(); }
-    SPI1->DR = data[i];
-  }
-  // wait for end of transmission
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-  HT1632C_CS_OFF;
-
-  // with dam
-  uint16_t a = 0x280 | addr;
-
-  /* Wait for SPI */
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-
-  /* DMA Source addr: Address of the SPI buffer. */
-  DMA1_Channel3->CMAR = data;
-  /* Set DMA data transfer length (SPI buffer length). */
-  DMA1_Channel3->CNDTR = len;
-
-  GPIO_SPI_SW();
-
-  HT1632C_CS_ON;
-  _display_WriteBits(a, 0x200);
-
-  GPIO_SPI_HW();
-
-  // start transfer
-  SPI1->CR2 |= (SPI_CR2_TXDMAEN);
-  DMA1_Channel3->CCR |= DMA_CCR_EN;
-  // End of transaction in DMA1_Channel2_3_IRQHandler()
-#endif /* FRAMEBUFFER_ROTATE */
-}
-
-/**
- * @brief Write all buffer to HT1632C
- */
-void display_WriteBuffer(void) {
-  /* Wait for SPI */
-  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
-
-#ifdef FRAMEBUFFER_ROTATE
-  uint8_t spi_buf[DISPLAY_COLUMNS] = {0};
-
-  /* Rotate display buffer */
-  uint8_t i, j, p = 0x01;
-  for (i=0; i<8; i++) {
-    if ((display_Buffer[0] & p) != 0) { spi_buf[i] |= 0x01; }
-    if ((display_Buffer[1] & p) != 0) { spi_buf[i] |= 0x02; }
-    if ((display_Buffer[2] & p) != 0) { spi_buf[i] |= 0x04; }
-    if ((display_Buffer[3] & p) != 0) { spi_buf[i] |= 0x08; }
-    if ((display_Buffer[4] & p) != 0) { spi_buf[i] |= 0x10; }
-    if ((display_Buffer[5] & p) != 0) { spi_buf[i] |= 0x20; }
-    if ((display_Buffer[6] & p) != 0) { spi_buf[i] |= 0x40; }
-    if ((display_Buffer[7] & p) != 0) { spi_buf[i] |= 0x80; }
-
-    j = i + 8;
-    if ((display_Buffer[8] & p) != 0)  { spi_buf[j] |= 0x01; }
-    if ((display_Buffer[9] & p) != 0)  { spi_buf[j] |= 0x02; }
-    if ((display_Buffer[10] & p) != 0) { spi_buf[j] |= 0x04; }
-    if ((display_Buffer[11] & p) != 0) { spi_buf[j] |= 0x08; }
-    if ((display_Buffer[12] & p) != 0) { spi_buf[j] |= 0x10; }
-    if ((display_Buffer[13] & p) != 0) { spi_buf[j] |= 0x20; }
-    if ((display_Buffer[14] & p) != 0) { spi_buf[j] |= 0x40; }
-    if ((display_Buffer[15] & p) != 0) { spi_buf[j] |= 0x80; }
-
-    j = i + 16;
-    if ((display_Buffer[16] & p) != 0) { spi_buf[j] |= 0x01; }
-    if ((display_Buffer[17] & p) != 0) { spi_buf[j] |= 0x02; }
-    if ((display_Buffer[18] & p) != 0) { spi_buf[j] |= 0x04; }
-    if ((display_Buffer[19] & p) != 0) { spi_buf[j] |= 0x08; }
-    if ((display_Buffer[20] & p) != 0) { spi_buf[j] |= 0x10; }
-    if ((display_Buffer[21] & p) != 0) { spi_buf[j] |= 0x20; }
-    if ((display_Buffer[22] & p) != 0) { spi_buf[j] |= 0x40; }
-    if ((display_Buffer[23] & p) != 0) { spi_buf[j] |= 0x80; }
-
-    p <<= 1;
-  }
-
-  /* DMA Source addr: Address of the SPI buffer. */
-  DMA1_Channel3->CMAR = (uint32_t)&spi_buf[0];
-#else
-  /* DMA Source addr: Address of the SPI buffer. */
-  DMA1_Channel3->CMAR = (uint32_t)&display_Buffer[0];
-#endif /* FRAMEBUFFER_ROTATE */
-
-  /* Set DMA data transfer length (SPI buffer length). */
-  DMA1_Channel3->CNDTR = DISPLAY_COLUMNS;
-
-  GPIO_SPI_SW();
-
-  HT1632C_CS_ON;
-  _display_WriteBits(0x280, 0x200);
-
-  GPIO_SPI_HW();
-
-  /* start transfer */
-  SPI1->CR2 |= SPI_CR2_TXDMAEN;
-  DMA1_Channel3->CCR |= DMA_CCR_EN;
-  /* End of transaction in DMA1_Channel2_3_IRQHandler() */
-}
-
-/**
- * @brief Fill display.
- * @param pattern for filling
- */
-void display_Fill(uint8_t pattern) {
-  int i;
-  for (i=0; i<DISPLAY_COLUMNS; i++) {
-    display_Buffer[i] = 0x0;
-  }
-  display_WriteBuffer();
-}
-
 /**
  * @brief Buzzer control: On.
  */

+ 280 - 0
src/display.c

@@ -1,12 +1,44 @@
 #include "main.h"
 #include "font.h"
 
+/* Private defines */
+#define FRAMEBUFFER_ROTATE
+
 /* Private constants */
 #define MAX_COLUMN    (DISPLAY_COLUMNS - 1)
 #define FONT_WIDTH    8
 
+/* private macros */
 /* Private variables */
+uint8_t display_Buffer[DISPLAY_COLUMNS] = {0};
+
+/* Privae fuctions */
+static void _display_WriteBits(uint16_t data, uint16_t nbits);
+static void _delay_c(uint32_t cycle);
+
 /* Exported fuctions */
+
+/**
+ * @brief Initialization HT1632C
+ */
+void display_Init(void) {
+  /* Wait for SPI */
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+
+  GPIO_SPI_SW();
+  HT1632C_CS_ON;
+
+  // Turn on system oscillator
+  _display_WriteBits(0x802, 0x800);
+  // Turn on LED duty cycle generator
+  _display_WriteBits(0x6, 0x100);
+
+  HT1632C_CS_OFF;
+  GPIO_SPI_HW();
+
+  display_Fill(0x0);
+}
+
 /**
  * @brief Out ot display one symbol in specified column
  * 
@@ -27,3 +59,251 @@ void display_Char(const uint8_t symb, const uint8_t column) {
   }
 }
 
+/**
+ * @brief Set HT1632C PWM Value
+ * @param pwm value in 0-15
+ */
+void display_PWM(uint8_t pwm) {
+  // check value
+  if (pwm > 15) {
+    pwm = 15;
+  }
+  // align value
+  pwm <<= 1;
+
+  /* Wait for SPI */
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+
+  GPIO_SPI_SW();
+
+  HT1632C_CS_ON;
+  _display_WriteBits((0x940|pwm), 0x800);
+  HT1632C_CS_OFF;
+
+  GPIO_SPI_HW();
+}
+
+/**
+ * @brief Set HT1632C Blink state
+ * @param state 0 for off, any other value for on
+ */
+void display_BlinkState(dis_en_t state) {
+  /* Wait for SPI */
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+
+  GPIO_SPI_SW();
+
+  HT1632C_CS_ON;
+  if (state == Disable) {
+    _display_WriteBits(0x810, 0x800); // Blink off
+  } else {
+    _display_WriteBits(0x812, 0x800); // Blink on
+  }
+  HT1632C_CS_OFF;
+
+  GPIO_SPI_HW();
+}
+
+/**
+ * @brief Set HT1632C Led state
+ * @param state 0 for off, any other value for on
+ */
+void display_LedState(dis_en_t state) {
+  /* Wait for SPI */
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+
+  GPIO_SPI_SW();
+
+  HT1632C_CS_ON;
+  if (state == Disable) {
+    _display_WriteBits(0x804, 0x800); // Led off
+  } else {
+    _display_WriteBits(0x806, 0x800); // Led on
+  }
+  HT1632C_CS_OFF;
+
+  GPIO_SPI_HW();
+}
+
+/**
+ * @brief Primitive delay
+ */
+static void _delay_c(uint32_t cycle) {
+  while (cycle) {
+    __NOP();
+    cycle --;
+  }
+}
+
+/**
+ * @brief Write <nbits> bit of data to selected HT1632Cs
+ * @param data words to write
+ * @param nbits num of bits (1<<(num-1))
+ */
+void _display_WriteBits(const uint16_t data, uint16_t nbits) {
+  _delay_c(2);
+  do {
+    HT1632C_WR_LOW;
+
+    if (data & nbits) {
+      HT1632C_DATA_1;
+    } else {
+      HT1632C_DATA_0;
+    }
+    _delay_c(5);
+    HT1632C_WR_HGH;
+    _delay_c(5);
+  } while (nbits >>= 1);
+}
+
+/**
+ * @brief Write Data to display buffer, no transfer to HT1632.
+ * @param data pointer to data array
+ * @param addr begin address
+ * @param len bytes to write
+ */
+void display_WriteData(const uint8_t * data, uint8_t addr, uint8_t len) {
+  /* check given values */
+  if (len == 0) {
+    return;
+  }
+  if (addr >= DISPLAY_COLUMNS) {
+    addr = DISPLAY_COLUMNS - 1;
+  }
+  if ((addr + len) > DISPLAY_COLUMNS) {
+    len = DISPLAY_COLUMNS - addr;
+  }
+
+#ifdef FRAMEBUFFER_ROTATE
+  /* Copy given data to framebuffer */
+  int i, a;
+  for (i=0; i<len; i++) {
+    a = addr + i;
+    display_Buffer[a] = data[i];
+  }
+  //display_WriteBuffer();
+
+#else
+  // without dma - pool mode
+  int i;
+
+  GPIO_SPI_SW();
+  HT1632C_CS_ON;
+  i = (0x280 | addr);
+  // write addr
+  _display_WriteBits(i, 0x200);
+
+  GPIO_SPI_HW();
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+  for (i=0; i<len; i++) {
+    while ((SPI1->SR & SPI_SR_TXE) == 0) { __NOP(); }
+    SPI1->DR = data[i];
+  }
+  // wait for end of transmission
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+  HT1632C_CS_OFF;
+
+  // with dam
+  uint16_t a = 0x280 | addr;
+
+  /* Wait for SPI */
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+
+  /* DMA Source addr: Address of the SPI buffer. */
+  DMA1_Channel3->CMAR = data;
+  /* Set DMA data transfer length (SPI buffer length). */
+  DMA1_Channel3->CNDTR = len;
+
+  GPIO_SPI_SW();
+
+  HT1632C_CS_ON;
+  _display_WriteBits(a, 0x200);
+
+  GPIO_SPI_HW();
+
+  // start transfer
+  SPI1->CR2 |= (SPI_CR2_TXDMAEN);
+  DMA1_Channel3->CCR |= DMA_CCR_EN;
+  // End of transaction in DMA1_Channel2_3_IRQHandler()
+#endif /* FRAMEBUFFER_ROTATE */
+}
+
+/**
+ * @brief Write all buffer to HT1632C
+ */
+void display_WriteBuffer(void) {
+  /* Wait for SPI */
+  while ((SPI1->SR & SPI_SR_BSY) != 0) { __NOP(); }
+
+#ifdef FRAMEBUFFER_ROTATE
+  uint8_t spi_buf[DISPLAY_COLUMNS] = {0};
+
+  /* Rotate display buffer */
+  uint8_t i, j, p = 0x01;
+  for (i=0; i<8; i++) {
+    if ((display_Buffer[0] & p) != 0) { spi_buf[i] |= 0x01; }
+    if ((display_Buffer[1] & p) != 0) { spi_buf[i] |= 0x02; }
+    if ((display_Buffer[2] & p) != 0) { spi_buf[i] |= 0x04; }
+    if ((display_Buffer[3] & p) != 0) { spi_buf[i] |= 0x08; }
+    if ((display_Buffer[4] & p) != 0) { spi_buf[i] |= 0x10; }
+    if ((display_Buffer[5] & p) != 0) { spi_buf[i] |= 0x20; }
+    if ((display_Buffer[6] & p) != 0) { spi_buf[i] |= 0x40; }
+    if ((display_Buffer[7] & p) != 0) { spi_buf[i] |= 0x80; }
+
+    j = i + 8;
+    if ((display_Buffer[8] & p) != 0)  { spi_buf[j] |= 0x01; }
+    if ((display_Buffer[9] & p) != 0)  { spi_buf[j] |= 0x02; }
+    if ((display_Buffer[10] & p) != 0) { spi_buf[j] |= 0x04; }
+    if ((display_Buffer[11] & p) != 0) { spi_buf[j] |= 0x08; }
+    if ((display_Buffer[12] & p) != 0) { spi_buf[j] |= 0x10; }
+    if ((display_Buffer[13] & p) != 0) { spi_buf[j] |= 0x20; }
+    if ((display_Buffer[14] & p) != 0) { spi_buf[j] |= 0x40; }
+    if ((display_Buffer[15] & p) != 0) { spi_buf[j] |= 0x80; }
+
+    j = i + 16;
+    if ((display_Buffer[16] & p) != 0) { spi_buf[j] |= 0x01; }
+    if ((display_Buffer[17] & p) != 0) { spi_buf[j] |= 0x02; }
+    if ((display_Buffer[18] & p) != 0) { spi_buf[j] |= 0x04; }
+    if ((display_Buffer[19] & p) != 0) { spi_buf[j] |= 0x08; }
+    if ((display_Buffer[20] & p) != 0) { spi_buf[j] |= 0x10; }
+    if ((display_Buffer[21] & p) != 0) { spi_buf[j] |= 0x20; }
+    if ((display_Buffer[22] & p) != 0) { spi_buf[j] |= 0x40; }
+    if ((display_Buffer[23] & p) != 0) { spi_buf[j] |= 0x80; }
+
+    p <<= 1;
+  }
+
+  /* DMA Source addr: Address of the SPI buffer. */
+  DMA1_Channel3->CMAR = (uint32_t)&spi_buf[0];
+#else
+  /* DMA Source addr: Address of the SPI buffer. */
+  DMA1_Channel3->CMAR = (uint32_t)&display_Buffer[0];
+#endif /* FRAMEBUFFER_ROTATE */
+
+  /* Set DMA data transfer length (SPI buffer length). */
+  DMA1_Channel3->CNDTR = DISPLAY_COLUMNS;
+
+  GPIO_SPI_SW();
+
+  HT1632C_CS_ON;
+  _display_WriteBits(0x280, 0x200);
+
+  GPIO_SPI_HW();
+
+  /* start transfer */
+  SPI1->CR2 |= SPI_CR2_TXDMAEN;
+  DMA1_Channel3->CCR |= DMA_CCR_EN;
+  /* End of transaction in DMA1_Channel2_3_IRQHandler() */
+}
+
+/**
+ * @brief Fill display.
+ * @param pattern for filling
+ */
+void display_Fill(uint8_t pattern) {
+  int i;
+  for (i=0; i<DISPLAY_COLUMNS; i++) {
+    display_Buffer[i] = 0x0;
+  }
+  display_WriteBuffer();
+}

+ 2 - 0
src/main.c

@@ -39,6 +39,8 @@ int main(void)
   /* Initialize Scheduler */
   RTOS_Init();
 
+  display_Init();
+
   buzer_On();
   tdelay_ms(50);
   buzer_Off();