/********************************* File main.c ********************************
 * Project     : WS2812 LED String over GPIO  V003F4M6 (SSOP20)
 * Author      : wizard2001
 * Version     : V1.0.0
 * Settings    : MounRiver Studio V1.84  MCU CH32V003F4P6  NanoCH32F203_Board
 * Date        : 22.03.2023
 * Description : Control WS2812 Chain over GPIO, *** Clock 24MHz ***
 * last change : 26.03.2023  test
 ******************************************************************************/

#include "debug.h"     // USART_Printf_Init(bdrt), PD.5 = TxD,
                       // Delay_Init, Delay_Us, Delay_Ms
#include "ws2812.h"

/* Global define */

/* Global Variable */
long int val;

/*********************************************************************
 * @fn      main
 * @brief   Main program.
 * @return  none
 */
int main(void)
{
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
  Delay_Init();
  USART_Printf_Init(115200);

  printf("SystemClk:%d\r\n",SystemCoreClock);

  LED_init();
  WS2812_IO_init();
  WS_CHAIN_init();

  for (int i=1; i<Max_LED; i++)                                // for check only
  {
    WS2812_wr(i);                                          // fill strip by step
    Delay_Ms(100);
  }

//    val = rand();

  while(1)
  {
    LED1_on;                                               // Board LEDs
    LED2_off;
    WS2812_wr(Max_LED);                                    // write to strip
    WS2812_dimm();                                         // calculate new values
    Delay_Ms(2);                                         // delay about 0,3s
    LED2_on;                                               // Board LEDs
    LED1_off;
    Delay_Ms(2);                                         // timing for slow
  }
}