[DemoCode下载] 使用 PSIO 实现 ARGB2 LED 灯效

[复制链接]
1713|4
 楼主| 小灵通2018 发表于 2024-5-20 21:34 | 显示全部楼层 |阅读模式
ps, RGB, LED, IO, GB
en-us--EC_M252_PSIO_ARGB2_LED_Control_V1.00.zip (2.52 MB, 下载次数: 2)
使用M252 PSIO实现ARGB2 LED时序并实现彩虹灯、跑马灯等灯效
PSIO (Programmable Serial I/O) 提供简易的方法达到各种串行传输的接收与传送,例如: HDQ、DMX512、1-wire、IR、PS/2、Microwire、Wiegand、LED等。本文描述如何使用PSIO实现ARGB2 LED灯效,并演示ARGB2 LED彩虹灯、跑马灯效果,此范例代码使用一组Timer来定时更新ARGB2 LED彩虹灯、跑马灯的颜色,一组UART来选择执行模式;其内容包含PSIO与ARGB2 LED的基本介绍、范例程序的说明以及运行结果。
44038664b515614f05.png
丰富的操作技术下载附件观看吧。
 楼主| 小灵通2018 发表于 2024-5-20 21:35 | 显示全部楼层
  1. /******************************************************************************
  2. * [url=home.php?mod=space&uid=288409]@file[/url]     PSIO_ARGB2_Driver.h
  3. * [url=home.php?mod=space&uid=247401]@brief[/url]    Nuvoton ARGB2 strip basic setting header file
  4. *
  5. * @note
  6. * Copyright (C) 2022 Nuvoton Technology Corp. All rights reserved.
  7. ******************************************************************************/
  8. #ifndef _PSIO_ARGB2_STRIP_H_
  9. #define _PSIO_ARGB2_STRIP_H_

  10. //------------------------------------------------------------------------------
  11. #include <stdint.h>

  12. //------------------------------------------------------------------------------
  13. #define PIXEL_NUM                       30         //LED's number in ARGB2 strip
  14. #define GRB                             24         //Total bits of RGB


  15. //Th20 SET Mode Setting
  16. #define TH20_24bits                     0xDF1F1F

  17. //------------------------------------------------------------------------------
  18. // Don't remove
  19. //------------------------------------------------------------------------------
  20. #define BIT1_HIGH                       1        //Denote BIT1
  21. #define BIT0_LOW                        0        //Denote BIT0

  22. //------------------------------------------------------------------------------
  23. typedef struct
  24. {
  25.     uint8_t u8SlotCtrl;
  26.     uint8_t u8DataPin;
  27.     uint8_t u8Brightness;
  28.     uint8_t u8Reserved;
  29.     uint16_t u16PulseCnt;
  30.     uint8_t au8PixelBuffer[PIXEL_NUM][GRB];
  31. } S_PSIO_ARGB2_STRIP_CFG_T;

  32. //------------------------------------------------------------------------------
  33. void Delay_Init(void);

  34. void PSIO_StripInit(uint8_t u8Slot, uint8_t u8DataPin);
  35. void PSIO_StripClear(void);
  36. void PSIO_StripReset(void);
  37. void PSIO_StripShow(void);

  38. void PSIO_StripSetRGBColor(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue);
  39. void PSIO_StripSetBrightness(uint8_t u8Brightness);
  40. uint32_t PSIO_StripWheel(uint8_t u8WheelPos);
  41. void PSIO_StripSetPixelColor(uint16_t u16Num, uint32_t u32RGBColor);
  42. uint16_t PSIO_StripFeedBackMode(void);
  43. void PSIO_StripHighLevelSetup(void);

  44. void PSIO_StripWakeupMode(void);
  45. void PSIO_StripSleepMode(void);

  46. void PSIO_SetStripID(uint8_t u8ID);
  47. void PSIO_ClearStripID(uint8_t u8ID);
  48. void PSIO_CheckStripkID(uint8_t u8ID);
  49. void PSIO_SpecifyStripID(uint8_t u8ID);

  50. #endif /* _PSIO_ARGB2_STRIP_H_ */

  51. /*** (C) COPYRIGHT 2022 Nuvoton Technology Corp. ***/
 楼主| 小灵通2018 发表于 2024-5-20 21:35 | 显示全部楼层
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <string.h>

  5. #include "NuMicro.h"
  6. #include "PSIO_ARGB2_Driver.h"

  7. //------------------------------------------------------------------------------
  8. // Global variable
  9. //------------------------------------------------------------------------------
  10. static S_PSIO_ARGB2_STRIP_CFG_T gsPSIO_ARGB2_Cfg = {0};
  11. static uint32_t u32TimeoutUs = 0;
  12. static uint32_t multipliter = 0;

  13. //------------------------------------------------------------------------------
  14. // Define functions prototype
  15. //------------------------------------------------------------------------------
  16. static void PSIO_Strip_OpenInput(uint32_t u32Switch);
  17. static void PSIO_Strip_OpenOutput(uint32_t u32Switch);

  18. //------------------------------------------------------------------------------
  19. void Delay_Init(void)
  20. {
  21.     /* while loop takes 3 ~ 4 cycles */
  22.     /* for 1 us delay, we need to divide with 3M */
  23.     multipliter = (CLK_GetCPUFreq() / 12000000);
  24. }

  25. uint32_t TimeoutUsInit(uint32_t micros)
  26. {
  27.     return (u32TimeoutUs = ((multipliter * (micros + 16)) - 10));
  28. }

  29. void DelayUs(uint32_t micros)
  30. {
  31.     /* multiply micro with multipliter */
  32.     micros = ((multipliter * (micros + 16)) - 10);

  33.     /* 4 cycles for one loop */
  34.     while (micros--);
  35. }

  36. void DelayMs(uint32_t mills)
  37. {
  38.     /* multiply mills with multipliter */
  39.     mills = multipliter * mills * 1100 - 10;

  40.     /* 4 cycles for one loop */
  41.     while (mills--);
  42. }

  43. void DelayS(uint32_t mills)
  44. {
  45.     /* multiply mills with multipliter */
  46.     mills = multipliter * mills * 1100000 - 10;

  47.     /* 4 cycles for one loop */
  48.     while (mills--);
  49. }

  50. /**
  51.   * @brief  Clear PSIO SLOT setting.
  52.   * @param  None
  53.   * @retval None
  54.   */
  55. void PSIO_ResetAllSlotSetting(void)
  56. {
  57.     S_PSIO_CP_CONFIG sDataConfig = {0};

  58.     /* Slot 0 ~ 7 */
  59.     sDataConfig.CKPT0SLT = PSIO_SLOT_DISABLE;
  60.     sDataConfig.CKPT1SLT = PSIO_SLOT_DISABLE;
  61.     sDataConfig.CKPT2SLT = PSIO_SLOT_DISABLE;
  62.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  63.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  64.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  65.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  66.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  67.     /* Actions 0 ~ 7 */
  68.     sDataConfig.CKPT0ACT = PSIO_NO_ACTION;
  69.     sDataConfig.CKPT1ACT = PSIO_NO_ACTION;
  70.     sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
  71.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  72.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  73.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  74.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  75.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  76.     /* Set check point configuration */
  77.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  78.     /* Set slot tick count */
  79.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 0);
  80.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 0);
  81.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 0);
  82.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT3, 0);
  83.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT4, 0);
  84.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT5, 0);
  85.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT6, 0);
  86.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT7, 0);

  87.     /* Trigger slot controller */
  88.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  89.     /* Wait for slot controller is not busy */
  90.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  91.     /* Stop slot controller */
  92.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
  93. }

  94. /**
  95.   * @brief  Send BIT0 and BIT1 to complete burst data transfer
  96.   * @param  None
  97.   * @retval None
  98.   */
  99. void PSIO_StripSendBurstData(uint32_t u32DataSize,
  100.                              uint32_t *u32Data,
  101.                              uint32_t u32DataCount)
  102. {
  103.     uint32_t u32i = 0;
  104.     S_PSIO_CP_CONFIG sDataConfig = {0};

  105.     /* Slot 0 ~ 7 */
  106.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  107.     sDataConfig.CKPT1SLT = PSIO_SLOT1;
  108.     sDataConfig.CKPT2SLT = PSIO_SLOT2;
  109.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  110.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  111.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  112.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  113.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  114.     /* Actions 0 ~ 7 */
  115.     sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
  116.     sDataConfig.CKPT1ACT = PSIO_OUT_BUFFER;
  117.     sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
  118.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  119.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  120.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  121.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  122.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  123.     /* Set check point configuration */
  124.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  125.     /* Set slot count */
  126.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 1);
  127.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 2);
  128.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 1);

  129.     /* Enable repeat slot0 ~ slot2 u32DataSize - 1 times */
  130.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, u32DataSize - 1, PSIO_REPEAT_DISABLE);

  131.     /* Set out data width as u32DataSize bit */
  132.     PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 0, u32DataSize);

  133.     /* Set out data depth as 1 */
  134.     PSIO_SET_OUTPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);

  135.     for (u32i = 0; u32i < u32DataCount; u32i++)
  136.     {
  137.         /* Set output data to buffer */
  138.         PSIO_SET_OUTPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, u32Data[u32i]);

  139.         /* Trigger slot controller */
  140.         PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  141.         /* Wait for slot controller is not busy */
  142.         while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
  143.     }

  144.     /* Wait for slot controller is not busy */
  145.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  146.     /* Stop slot controller */
  147.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  148.     /* Disable repeat slot0 ~ slot2 */
  149.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
  150. }

  151. /**
  152.   * @brief  Send BIT0 and BIT1 to complete the data transfer
  153.   * @param  None
  154.   * @retval None
  155.   */
  156. void PSIO_SendDataWithSize(uint32_t u32DataSize, uint32_t u32Data)
  157. {
  158.     S_PSIO_CP_CONFIG sDataConfig = {0};

  159.     /* Slot 0 ~ 7 */
  160.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  161.     sDataConfig.CKPT1SLT = PSIO_SLOT1;
  162.     sDataConfig.CKPT2SLT = PSIO_SLOT2;
  163.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  164.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  165.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  166.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  167.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  168.     /* Actions 0 ~ 7 */
  169.     sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
  170.     sDataConfig.CKPT1ACT = PSIO_OUT_BUFFER;
  171.     sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
  172.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  173.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  174.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  175.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  176.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  177.     /* Set check point configuration */
  178.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  179.     /* Set slot count */
  180.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 1);
  181.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 2);
  182.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 1);

  183.     /* Enable repeat slot0 ~ slot2 u32DataSize - 1 times */
  184.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, u32DataSize - 1, PSIO_REPEAT_DISABLE);

  185.     /* Set out data width as u32DataSize bit */
  186.     PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 0, u32DataSize);

  187.     /* Set out data depth as 1 */
  188.     PSIO_SET_OUTPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);

  189.     /* Set output data to buffer */
  190.     PSIO_SET_OUTPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, u32Data);

  191.     /* Trigger slot controller */
  192.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  193.     /* Wait for slot controller is not busy */
  194.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  195.     /* Stop slot controller */
  196.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  197.     /* Disable repeat slot0 ~ slot2 */
  198.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
  199. }

  200. void PSIO_StripSetupID(uint32_t u32DataSize, uint32_t u32Data)
  201. {
  202.     S_PSIO_CP_CONFIG sCmdConfig = {0};
  203.     S_PSIO_CP_CONFIG sDataConfig = {0};

  204.     //--------------------------------------------------------------------------
  205.     // Enable strip setup ID control
  206.     //--------------------------------------------------------------------------
  207.     /* Slot 0 ~ 7 */
  208.     sCmdConfig.CKPT0SLT = PSIO_SLOT0;
  209.     sCmdConfig.CKPT1SLT = PSIO_SLOT1;
  210.     sCmdConfig.CKPT2SLT = PSIO_SLOT2;
  211.     sCmdConfig.CKPT3SLT = PSIO_SLOT3;
  212.     sCmdConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  213.     sCmdConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  214.     sCmdConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  215.     sCmdConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  216.     /* Actions 0 ~ 7 */
  217.     sCmdConfig.CKPT0ACT = PSIO_OUT_HIGH;
  218.     sCmdConfig.CKPT1ACT = PSIO_OUT_HIGH;
  219.     sCmdConfig.CKPT2ACT = PSIO_OUT_HIGH;
  220.     sCmdConfig.CKPT3ACT = PSIO_OUT_LOW;
  221.     sCmdConfig.CKPT4ACT = PSIO_NO_ACTION;
  222.     sCmdConfig.CKPT5ACT = PSIO_NO_ACTION;
  223.     sCmdConfig.CKPT6ACT = PSIO_NO_ACTION;
  224.     sCmdConfig.CKPT7ACT = PSIO_NO_ACTION;

  225.     //--------------------------------------------------------------------------
  226.     // send strip setup command and ID
  227.     //--------------------------------------------------------------------------
  228.     /* Slot 0 ~ 7 */
  229.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  230.     sDataConfig.CKPT1SLT = PSIO_SLOT1;
  231.     sDataConfig.CKPT2SLT = PSIO_SLOT2;
  232.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  233.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  234.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  235.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  236.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  237.     /* Actions 0 ~ 7 */
  238.     sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
  239.     sDataConfig.CKPT1ACT = PSIO_OUT_BUFFER;
  240.     sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
  241.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  242.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  243.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  244.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  245.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  246.     //first reset
  247.     PSIO_StripReset();

  248.     /* Set out data width as u32DataSize bit */
  249.     PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 0, u32DataSize);

  250.     /* Set check point configuration */
  251.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sCmdConfig);

  252.     /* Set slot 0 tick count as 4, slot 1 tick count as 4, slot 2 tick count as 7 */
  253.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 4);
  254.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 4);
  255.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 7);
  256.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT3, 12);

  257.     /* Enable repeat slot 0 ~ slot 2 u32DataSize - 1 times*/
  258.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, u32DataSize - 1, PSIO_REPEAT_DISABLE);

  259.     /* Trigger slot controller */
  260.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  261.     /* Wait for slot controller is not busy */
  262.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  263.     /* Stop slot controller */
  264.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  265.     /* Set check point configuration */
  266.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  267.     /* Set slot count */
  268.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 1);
  269.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 2);
  270.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 1);

  271.     /* Set output data to buffer */
  272.     PSIO_SET_OUTPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, u32Data);

  273.     /* Trigger slot controller */
  274.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  275.     /* Wait for slot controller is not busy */
  276.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  277.     /* Stop slot controller */
  278.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  279.     /* Disable repeat slot0 ~ slot2 */
  280.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
  281. }

  282. /**
  283.   * @brief Receive response pulse for Y-Cable check ID function
  284.   * @param  None
  285.   * @retval None
  286.   */
  287. uint16_t PSIO_StripCheckIDFeedback(uint16_t u16WaitTime)
  288. {
  289.     uint16_t u16LEDCnt = 0;
  290.     uint32_t u32BitIndex = 0;
  291.     int32_t i32UsTimeout = 0;
  292.     S_PSIO_CP_CONFIG sDataConfig = {0};

  293.     i32UsTimeout = TimeoutUsInit(u16WaitTime);

  294.     PSIO_Strip_OpenInput(PSIO_PIN_ENABLE);

  295.     /* Slot 0 ~ 7 */
  296.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  297.     sDataConfig.CKPT1SLT = PSIO_SLOT1;
  298.     sDataConfig.CKPT2SLT = PSIO_SLOT2;
  299.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  300.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  301.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  302.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  303.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  304.     /* Actions 0 ~ 7 */
  305.     sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
  306.     sDataConfig.CKPT1ACT = PSIO_IN_BUFFER;
  307.     sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
  308.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  309.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  310.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  311.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  312.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  313.     /* Set check point configuration */
  314.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  315.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);
  316.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 15);
  317.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 3);

  318.     /* Enable repeat slot0 ~ slot0 26 times */
  319.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, 63, PSIO_REPEAT_DISABLE);

  320.     /* Trigger slot controller */
  321.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  322.     /* Wait data buffer is full */
  323.     while ((!PSIO_GET_TRANSFER_STATUS(PSIO, PSIO_TRANSTS_INFULL0_Msk)) && (i32UsTimeout-- >= 0));

  324.     if (i32UsTimeout <= 0)
  325.     {
  326.         /* Stop slot controller */
  327.         PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  328.         /* Disable repeat slot0 ~ slot0 */
  329.         PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);

  330.         PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);
  331.         return 0;
  332.     }

  333.     /* Read data from device */
  334.     u16LEDCnt = PSIO_GET_INPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin);

  335.     /* Stop slot controller */
  336.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  337.     /* Disable repeat slot0 ~ slot0 */
  338.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);

  339.     PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);

  340.     return u16LEDCnt;
  341. }

  342. void PSIO_SpecifyStripID(uint8_t u8ID)
  343. {
  344.     uint8_t u8Cmd = (0x40 | (u8ID & 0x0F));

  345.     PSIO_StripSetupID(8, u8Cmd);

  346.     PSIO_StripReset();
  347. }

  348. void PSIO_CheckStripkID(uint8_t u8ID)
  349. {
  350.     uint8_t u8GetPulse = 0;
  351.     uint8_t u8Cmd = (0x30 | (u8ID & 0x0F));

  352.     PSIO_StripSetupID(8, u8Cmd);

  353.     u8GetPulse = PSIO_StripCheckIDFeedback(160);

  354.     if (u8GetPulse != 0)
  355.     {
  356.         printf("Get %d strip ID\r\n", u8ID);
  357.     }
  358.     else
  359.     {
  360.         printf("Not get %d strip ID\r\n", u8ID);
  361.     }

  362.     PSIO_StripReset();
  363. }

  364. void PSIO_ClearStripID(uint8_t u8ID)
  365. {
  366.     uint8_t u8Cmd = (0x20 | (u8ID & 0x0F));

  367.     PSIO_StripSetupID(8, u8Cmd);

  368.     PSIO_StripReset();
  369. }

  370. void PSIO_SetStripID(uint8_t u8ID)
  371. {
  372.     uint8_t u8Cmd = (0x10 | (u8ID & 0x0F));

  373.     PSIO_StripSetupID(8, u8Cmd);

  374.     PSIO_StripReset();
  375. }

  376. void PSIO_StripWakeupMode(void)
  377. {
  378.     uint8_t u8StripCnt = 0;

  379.     PSIO_StripReset();

  380.     for (u8StripCnt = 0; u8StripCnt < PIXEL_NUM; u8StripCnt++)
  381.     {
  382.         PSIO_SendDataWithSize(24, TH20_24bits);
  383.         DelayMs(1);
  384.     }
  385. }

  386. void PSIO_StripSleepMode(void)
  387. {
  388.     uint8_t u8StripCnt = 0;

  389.     for (u8StripCnt = 0; u8StripCnt < PIXEL_NUM; u8StripCnt++)
  390.     {
  391.         PSIO_SendDataWithSize(24, 0x000000);
  392.     }

  393.     PSIO_SendDataWithSize(8, 0x5A);

  394.     PSIO_StripReset();
  395. }

  396. void PSIO_StripHighLevelCMDTh20(void)
  397. {
  398.     S_PSIO_CP_CONFIG sDataConfig = {0};

  399.     /* Slot 0 ~ 7 */
  400.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  401.     sDataConfig.CKPT1SLT = PSIO_SLOT_DISABLE;
  402.     sDataConfig.CKPT2SLT = PSIO_SLOT_DISABLE;
  403.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  404.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  405.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  406.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  407.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  408.     /* Actions 0 ~ 7 */
  409.     sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
  410.     sDataConfig.CKPT1ACT = PSIO_NO_ACTION;
  411.     sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
  412.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  413.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  414.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  415.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  416.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  417.     /* Set check point configuration */
  418.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  419.     /* Set slot 0 tick count as 15, slot 1 tick count as 15 */
  420.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);

  421.     /* Enable repeat slot 0 ~ slot 2 */
  422.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT0, 3, PSIO_REPEAT_DISABLE);

  423.     /* Trigger slot controller */
  424.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  425.     /* Wait for slot controller is not busy */
  426.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  427.     /* Stop slot controller */
  428.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  429.     /* Disable repeat slot0 ~ slot0 */
  430.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
  431. }

  432. void PSIO_StripHighLevelSetup(void)
  433. {
  434.     uint8_t u8StripCnt = 0;
  435.     uint32_t u32Data[PIXEL_NUM] = {TH20_24bits};

  436.     for (u8StripCnt = 0; u8StripCnt < PIXEL_NUM; u8StripCnt++)
  437.     {
  438.         u32Data[u8StripCnt] = TH20_24bits;
  439.     }

  440.     PSIO_StripHighLevelCMDTh20();

  441.     PSIO_StripReset();

  442.     PSIO_StripSendBurstData(24, &u32Data[0], PIXEL_NUM);

  443.     PSIO_StripReset();
  444. }

  445. /**
  446.   * @brief  Send Trst
  447.   * @param  None
  448.   * @retval None
  449.   */
  450. uint16_t PSIO_StripReadFeedBack(uint16_t u16WaitTime)
  451. {
  452.     uint16_t u16LEDCnt = 0;
  453.     uint32_t u32BitIndex = 0;
  454.     int32_t i32UsTimeout = 0;
  455.     S_PSIO_CP_CONFIG sDataConfig = {0};

  456.     PSIO_Strip_OpenInput(PSIO_PIN_ENABLE);

  457.     /* Slot 0 ~ 7 */
  458.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  459.     sDataConfig.CKPT1SLT = PSIO_SLOT1;
  460.     sDataConfig.CKPT2SLT = PSIO_SLOT2;
  461.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  462.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  463.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  464.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  465.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  466.     /* Actions 0 ~ 7 */
  467.     sDataConfig.CKPT0ACT = PSIO_NO_ACTION;
  468.     sDataConfig.CKPT1ACT = PSIO_IN_BUFFER;
  469.     sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
  470.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  471.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  472.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  473.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  474.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  475.     /* Set check point configuration */
  476.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  477.     /* Set slot 0 tick count as 15, slot 1 tick count as 15, slot 2 tick count as 3*/
  478.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 9);
  479.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 15);
  480.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 7);

  481.     /* Enable repeat slot0 ~ slot2 */
  482.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, 63, PSIO_REPEAT_DISABLE);

  483.     for (u32BitIndex = 0; u32BitIndex < 512; u32BitIndex++)
  484.     {
  485.         /* Set wait pulse timeout counter */
  486.         i32UsTimeout = TimeoutUsInit(u16WaitTime);

  487.         /* Trigger slot controller */
  488.         PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  489.         /* Wait data buffer is full */
  490.         while ((!PSIO_GET_TRANSFER_STATUS(PSIO, PSIO_TRANSTS_INFULL0_Msk)) && (i32UsTimeout-- >= 0));

  491.         if (i32UsTimeout <= 0)
  492.         {
  493.             break;
  494.         }

  495.         /* Read data from device */
  496.         u16LEDCnt += PSIO_GET_INPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin);
  497.     }

  498.     /* Wait for slot controller is not busy */
  499.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  500.     /* Stop slot controller */
  501.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  502.     /* Disable repeat slot0 ~ slot2 */
  503.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);

  504.     PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);

  505.     return u16LEDCnt;
  506. }

  507. /**
  508.   * @brief  Send Trst
  509.   * @param  None
  510.   * @retval None
  511.   */
  512. void PSIO_StripFeedBackCMDTh50(void)
  513. {
  514.     S_PSIO_CP_CONFIG sDataConfig = {0};

  515.     /* Slot 0 ~ 7 */
  516.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  517.     sDataConfig.CKPT1SLT = PSIO_SLOT1;
  518.     sDataConfig.CKPT2SLT = PSIO_SLOT2;
  519.     sDataConfig.CKPT3SLT = PSIO_SLOT3;
  520.     sDataConfig.CKPT4SLT = PSIO_SLOT4;
  521.     sDataConfig.CKPT5SLT = PSIO_SLOT5;
  522.     sDataConfig.CKPT6SLT = PSIO_SLOT6;
  523.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  524.     /* Actions 0 ~ 7 */
  525.     sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
  526.     sDataConfig.CKPT1ACT = PSIO_OUT_HIGH;
  527.     sDataConfig.CKPT2ACT = PSIO_OUT_HIGH;
  528.     sDataConfig.CKPT3ACT = PSIO_OUT_HIGH;
  529.     sDataConfig.CKPT4ACT = PSIO_OUT_LOW;
  530.     sDataConfig.CKPT5ACT = PSIO_OUT_LOW;
  531.     sDataConfig.CKPT6ACT = PSIO_OUT_HIGH;
  532.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  533.     /* Set check point configuration */
  534.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  535.     /* Set slot tick count */
  536.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);
  537.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 15);
  538.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 15);
  539.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT3, 15);
  540.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT4, 15);
  541.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT5, 15);
  542.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT6, 15);

  543.     /* Enable repeat slot6 ~ slot7 */
  544.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT6, PSIO_SLOT6, 9, PSIO_REPEAT_DISABLE);

  545.     /* Trigger slot controller */
  546.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  547.     /* Wait for slot controller is not busy */
  548.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  549.     /* Stop slot controller */
  550.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  551.     /* Disable repeat slot0 ~ slot0 */
  552.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
  553. }

  554. /**
  555.   * @brief  Send Trst
  556.   * @param  None
  557.   * @retval None
  558.   */
  559. uint16_t PSIO_StripFeedBackMode(void)
  560. {
  561.     uint16_t u16LEDCnt = 0;
  562.     uint32_t u32BitIndex = 0;
  563.     uint32_t u32DelayCnt = 0;

  564.     PSIO_StripReset();

  565.     PSIO_StripFeedBackCMDTh50();

  566.     u16LEDCnt = PSIO_StripReadFeedBack(160);

  567.     PSIO_StripReset();
  568.     PSIO_ResetAllSlotSetting();
  569.     return u16LEDCnt;
  570. }

  571. /**
  572.   * @brief  Send Trst
  573.   * @param  None
  574.   * @retval None
  575.   */
  576. void PSIO_StripReset(void)
  577. {
  578.     S_PSIO_CP_CONFIG sDataConfig = {0};

  579.     /* Slot 0 ~ 7 */
  580.     sDataConfig.CKPT0SLT = PSIO_SLOT0;
  581.     sDataConfig.CKPT1SLT = PSIO_SLOT_DISABLE;
  582.     sDataConfig.CKPT2SLT = PSIO_SLOT_DISABLE;
  583.     sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
  584.     sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
  585.     sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
  586.     sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
  587.     sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;

  588.     /* Actions 0 ~ 7 */
  589.     sDataConfig.CKPT0ACT = PSIO_OUT_LOW;
  590.     sDataConfig.CKPT1ACT = PSIO_NO_ACTION;
  591.     sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
  592.     sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
  593.     sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
  594.     sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
  595.     sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
  596.     sDataConfig.CKPT7ACT = PSIO_NO_ACTION;

  597.     /* Set check point configuration */
  598.     PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);

  599.     /* Set slot 0 tick count as 15, slot 1 tick count as 15 */
  600.     PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);

  601.     /* Enable repeat slot1 ~ slot1 */
  602.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT0, 47, PSIO_REPEAT_DISABLE);

  603.     /* Trigger slot controller */
  604.     PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  605.     /* Wait for slot controller is not busy */
  606.     while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));

  607.     /* Stop slot controller */
  608.     PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);

  609.     /* Disable repeat slot0 ~ slot0 */
  610.     PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
  611. }

  612. static void PSIO_Strip_OpenInput(uint32_t u32Switch)
  613. {
  614.     /* PSIO UART TX PIN general setting */
  615.     PSIO_SET_GENCTL(PSIO,
  616.                     gsPSIO_ARGB2_Cfg.u8DataPin,
  617.                     u32Switch,//PSIO_PIN_ENABLE,
  618.                     gsPSIO_ARGB2_Cfg.u8SlotCtrl,
  619.                     PSIO_INPUT_MODE,
  620.                     PSIO_LOW_LEVEL,
  621.                     PSIO_LOW_LEVEL);

  622.     /* Set output data buffer width as 8 bit, input data width as 1 bit*/
  623.     PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 1, 8);

  624.     /* Set input data buffer depth as 1 */
  625.     PSIO_SET_INPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);
  626. }

  627. static void PSIO_Strip_OpenOutput(uint32_t u32Switch)
  628. {
  629.     /* PSIO UART TX PIN general setting */
  630.     PSIO_SET_GENCTL(PSIO,
  631.                     gsPSIO_ARGB2_Cfg.u8DataPin,
  632.                     u32Switch, //PSIO_PIN_ENABLE
  633.                     gsPSIO_ARGB2_Cfg.u8SlotCtrl,
  634.                     PSIO_OUTPUT_MODE,
  635.                     PSIO_LOW_LEVEL,
  636.                     PSIO_LOW_LEVEL);

  637.     /* Set data order ad MSB */
  638.     PSIO_SET_ORDER(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_MSB);

  639.     /* Set output data buffer width as 8 bit, input data width as 1 bit*/
  640.     PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 1, 8);

  641.     /* Set output data buffer depth as 1 */
  642.     PSIO_SET_OUTPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);

  643.     /* Set slot controller trigger source as software trigger */
  644.     PSIO_SET_TRIGSRC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SW_TRIGGER);
  645. }

  646. /**
  647.   * @brief  initialize ARGB2 PSIO PIN
  648.   * @param  None
  649.   * @retval None
  650.   */
  651. void PSIO_StripInit(uint8_t u8SlotCtrl, uint8_t u8DataPin)
  652. {
  653.     gsPSIO_ARGB2_Cfg.u8SlotCtrl = u8SlotCtrl;
  654.     gsPSIO_ARGB2_Cfg.u8DataPin = u8DataPin;

  655.     PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);
  656. }

  657. //------------------------------------------------------------------------------
  658. /**
  659.   * @brief  Fill ALL LEDs with (0,0,0)
  660.     * @param  24 bits data (Range: 0x000000 to 0xffffff)
  661.   * @retval None
  662.   */
  663. void PSIO_StripClear(void)
  664. {
  665.     uint8_t u8i = 0;

  666.     for (u8i = 0; u8i < PIXEL_NUM; u8i++)
  667.     {
  668.         PSIO_SendDataWithSize(24, 0x000000);
  669.     }
  670. }

  671. /**
  672.   * @brief  Digital output to all LED which in ARGB2 strip
  673.   * @param  None
  674.   * @retval None
  675.   */
  676. void PSIO_StripShow(void)
  677. {
  678.     uint16_t i, j;
  679.     int32_t i32Data[PIXEL_NUM] = {0};
  680.     S_PSIO_CP_CONFIG sDataConfig = {0};

  681.     for (i = 0; i < PIXEL_NUM; ++i)
  682.     {
  683.         for (j = 0; j < GRB; ++j)
  684.         {
  685.             i32Data[i] |= (gsPSIO_ARGB2_Cfg.au8PixelBuffer[i][j] << (23 - j));
  686.             //if (gsPSIO_ARGB2_Cfg.au8PixelBuffer[i][j] == BIT1_HIGH) {
  687.             //    PSIO_SendStripBit1();
  688.             //} else {
  689.             //    PSIO_SendStripBit0();
  690.             //}
  691.         }
  692.     }

  693.     for (i = 0; i < PIXEL_NUM; ++i)
  694.     {
  695.         PSIO_SendDataWithSize(24, i32Data[i]);
  696.     }
  697. }

  698. /**
  699.   * @brief  RGB color bitwise operation
  700.   * @param  red     0-255
  701.     *                   green   0-255
  702.     *                   blue    0-255
  703.   * @retval None
  704.   */
  705. uint32_t Strip_color(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue)
  706. {
  707.     return u8Green << 16 | u8Red << 8 | u8Blue;
  708. }

  709. /**
  710.   * @brief  Input a value 0 to 255 to get a color value.
  711.                         The colours are a transition r - g - b - back to r.
  712.   * @param  None
  713.   * @retval None
  714.   */
  715. uint32_t PSIO_StripWheel(uint8_t u8WheelPos)
  716. {
  717.     u8WheelPos = 255 - u8WheelPos;

  718.     if (u8WheelPos < 85)
  719.     {
  720.         return Strip_color(255 - u8WheelPos * 3, 0, u8WheelPos * 3);
  721.     }

  722.     if (u8WheelPos < 170)
  723.     {
  724.         u8WheelPos -= 85;
  725.         return Strip_color(0, u8WheelPos * 3, 255 - u8WheelPos * 3);
  726.     }

  727.     u8WheelPos -= 170;

  728.     return Strip_color(u8WheelPos * 3, 255 - u8WheelPos * 3, 0);
  729. }

  730. /**
  731.   * @brief  RGB setting to all LED
  732.     * @param  n:                    Specify a LED
  733.                         GRBColor:       Set BIT1 or BIT0
  734.   * @retval None
  735.   */
  736. void PSIO_StripSetPixelColor(uint16_t u16Num, uint32_t u32RGBColor)
  737. {
  738.     uint8_t i = 0;

  739.     if (u16Num < PIXEL_NUM)
  740.     {
  741.         for (i = 0; i < GRB; i++)
  742.         {
  743.             gsPSIO_ARGB2_Cfg.au8PixelBuffer[u16Num][i] = ((u32RGBColor << i) & 0x800000) ? BIT1_HIGH : BIT0_LOW;
  744.         }
  745.     }
  746. }

  747. /**
  748. * @brief Set GLOBAL LED brightness
  749. * @param[in] br Brightness [0..255]
  750. * [url=home.php?mod=space&uid=266161]@return[/url] #ARGB_STATE enum
  751. */
  752. void PSIO_StripSetBrightness(uint8_t u8Brightness)
  753. {
  754.     gsPSIO_ARGB2_Cfg.u8Brightness = u8Brightness;
  755. }

  756. /**
  757.   * @brief  Send one data to a LED
  758.     * @param  24 bits data (Range: 0x000000 to 0xffffff)
  759.   * @retval None
  760.   */
  761. void PSIO_StripSetRGBColor(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue)
  762. {
  763.     int32_t i32Data = 0;

  764.     u8Red   /= (256 / ((uint16_t) gsPSIO_ARGB2_Cfg.u8Brightness + 1));
  765.     u8Green /= (256 / ((uint16_t) gsPSIO_ARGB2_Cfg.u8Brightness + 1));
  766.     u8Blue  /= (256 / ((uint16_t) gsPSIO_ARGB2_Cfg.u8Brightness + 1));

  767.     i32Data |= (u8Green << 16);
  768.     i32Data |= (u8Red << 8);
  769.     i32Data |= u8Blue;

  770.     PSIO_SendDataWithSize(24, i32Data);
  771. }
 楼主| 小灵通2018 发表于 2024-5-20 21:35 | 显示全部楼层
  1. /**************************************************************************//**
  2. * @file     main.c
  3. * [url=home.php?mod=space&uid=895143]@version[/url]  V1.00
  4. * @brief    Show how to use PSIO input/output to control ARGB2 strip.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0
  7. * [url=home.php?mod=space&uid=17282]@CopyRight[/url] (C) 2022 Nuvoton Technology Corp. All rights reserved.
  8. ******************************************************************************/
  9. #include "stdio.h"
  10. #include "NuMicro.h"
  11. #include "PSIO_ARGB2_Driver.h"

  12. //------------------------------------------------------------------------------
  13. uint32_t sysGetNum(void)
  14. {
  15.     uint8_t cInputTemp = 0x00, InputString[16] = {0};
  16.     uint32_t nLoop = 0;

  17.     while (cInputTemp != 0x0D)
  18.     {
  19.         cInputTemp = getchar();

  20.         if (cInputTemp == 27)   /* 27: ESC key */
  21.         {
  22.             return cInputTemp;
  23.         }

  24.         if (cInputTemp == 'x' || cInputTemp == 'X' || cInputTemp == 'f' ||
  25.                 cInputTemp == 'F' || cInputTemp == 'r' || cInputTemp == 'R')
  26.         {
  27.             return cInputTemp;
  28.         }

  29.         if (cInputTemp == '-')
  30.         {
  31.             InputString[nLoop] = cInputTemp;
  32.             printf("%c", cInputTemp);
  33.             nLoop++;
  34.         }
  35.         else if (cInputTemp >= '0' && cInputTemp <= '9')
  36.         {
  37.             InputString[nLoop] = cInputTemp;
  38.             printf("%c", cInputTemp);
  39.             nLoop++;
  40.         }
  41.     }

  42.     printf("\n");

  43.     //return atoi(InputString);
  44.     return atoi((const char *)InputString);
  45. }

  46. //------------------------------------------------------------------------------
  47. /**
  48.   * @brief  Specify a Strip ID in Y cable mode
  49.     * @param  tmpID: Specify a ID
  50.   * @retval None
  51.   */
  52. int Strip_SpecifyIDTest(void)
  53. {
  54.     PSIO_SpecifyStripID(0x05);

  55.     return 0;
  56. }

  57. /**
  58.   * @brief  Check a strip ID in Y cable function
  59.   * @param  count: Check ID count
  60.   * @retval None
  61.   */
  62. int Strip_CheckIDTest(void)
  63. {
  64.     uint8_t u8i = 0;

  65.     for (u8i = 1; u8i < 16; u8i++)
  66.     {
  67.         PSIO_CheckStripkID(u8i);
  68.     }

  69.     return 0;
  70. }

  71. /**
  72.   * @brief  Clear a Strip ID in Y cable function
  73.   * @param  count: Clear ID count
  74.   * @retval None
  75.   */
  76. int Strip_ClearIDTest(void)
  77. {
  78.     uint8_t u8i = 0;

  79.     for (u8i = 1; u8i < 16; u8i++)
  80.     {
  81.         PSIO_ClearStripID(u8i);
  82.     }

  83.     return 0;
  84. }

  85. /**
  86.   * @brief  Set a strip ID in Y cable function
  87.     * @param  count: Set ID count
  88.   * @retval None
  89.   */
  90. int Strip_SetIDTest(void)
  91. {
  92.     uint32_t u32ID = 0;

  93.     printf("Please set ID, then press the ENTER.: (Range: 1 ~ 15): ");
  94.     u32ID = sysGetNum();

  95.     if (u32ID > 15)
  96.     {
  97.         printf("Setting ID is over range. (1 ~ 15)\r\n");
  98.         printf("Leave Y Cable mode.\r\n\r\n");
  99.         return -1;
  100.     }

  101.     PSIO_SetStripID(u32ID);

  102.     return 0;
  103. }

  104. /**
  105.   * @brief  Set a strip ID in Y cable menu function
  106.     * @param  count: Set ID count
  107.   * @retval None
  108.   */
  109. int Strip_YCableSetupMenu(void)
  110. {
  111.     uint8_t u8Index = 0;
  112.     struct
  113.     {
  114.         char *chName;
  115.         int (*funcptr)(void);
  116.     } sSetStripIDMenu[] =
  117.     {
  118.         {"", NULL},
  119.         {"Set strip ID", &Strip_SetIDTest},
  120.         {"Clean strip ID", &Strip_ClearIDTest},
  121.         {"Check strip ID", &Strip_CheckIDTest},
  122.         {"Specify strip ID", &Strip_SpecifyIDTest},
  123.     };

  124.     while (1)
  125.     {
  126.         printf("\r\n\r\n");
  127.         printf("=============================================\r\n");
  128.         printf("\tEnter the select setup strip ID test: \r\n");
  129.         printf("=============================================\r\n");

  130.         for (u8Index = 1; u8Index < sizeof(sSetStripIDMenu) / sizeof(sSetStripIDMenu[0]); u8Index++)
  131.         {
  132.             printf("[%02d] %s\r\n",
  133.                    u8Index,
  134.                    sSetStripIDMenu[u8Index].chName);
  135.         }

  136.         printf("\r\n");

  137.         u8Index = sysGetNum();

  138.         if ((u8Index == 0) || (u8Index >= sizeof(sSetStripIDMenu) / sizeof(sSetStripIDMenu[0])))
  139.         {
  140.             return 0;
  141.         }

  142.         if (sSetStripIDMenu[u8Index].funcptr != NULL)
  143.         {
  144.             sSetStripIDMenu[u8Index].funcptr();
  145.         }
  146.     }

  147.     return 0;
  148. }

  149. /**
  150.   * @brief  Set a strip sleep or wakeup menu function
  151.     * @param  count: Set ID count
  152.   * @retval None
  153.   */
  154. int Strip_SleepWakeupTest(void)
  155. {
  156.     uint8_t u8Index = 0;
  157.     struct
  158.     {
  159.         char *chName;
  160.         void (*funcptr)(void);
  161.     } sSleepWakeupTest[] =
  162.     {
  163.         {"", NULL},
  164.         {"Strip Sleep", &PSIO_StripSleepMode},
  165.         {"strip Wakeup", &PSIO_StripWakeupMode},
  166.     };

  167.     while (1)
  168.     {
  169.         printf("\r\n\r\n");
  170.         printf("=============================================\r\n");
  171.         printf("\tEnter the select sleep or wakeup test: \r\n");
  172.         printf("=============================================\r\n");

  173.         for (u8Index = 1; u8Index < sizeof(sSleepWakeupTest) / sizeof(sSleepWakeupTest[0]); u8Index++)
  174.         {
  175.             printf("[%02d] %s\r\n",
  176.                    u8Index,
  177.                    sSleepWakeupTest[u8Index].chName);
  178.         }

  179.         printf("\r\n");

  180.         u8Index = sysGetNum();

  181.         if ((u8Index == 0) || (u8Index >= sizeof(sSleepWakeupTest) / sizeof(sSleepWakeupTest[0])))
  182.         {
  183.             return 0;
  184.         }

  185.         if (sSleepWakeupTest[u8Index].funcptr != NULL)
  186.         {
  187.             sSleepWakeupTest[u8Index].funcptr();
  188.         }
  189.     }

  190.     return 0;
  191. }

  192. /**
  193.   * @brief  Enable TH20 SET mode
  194.   * @param  None
  195.   * @retval None
  196.   */
  197. int Strip_Th20SetMode(void)
  198. {
  199.     PSIO_StripHighLevelSetup();

  200.     return 0;
  201. }

  202. /**
  203.   * @brief  Theatre-style crawling lights with rainbow effect
  204.   * @param  None
  205.   * @retval None
  206.   */
  207. int Strip_FeedbackMode(void)
  208. {
  209.     printf("There are %d pcs LED in the strip\n", PSIO_StripFeedBackMode());

  210.     return 0;
  211. }

  212. /**
  213.   * @brief  Theatre-style crawling lights with rainbow effect
  214.   * @param  None
  215.   * @retval None
  216.   */
  217. int Strip_TheaterChaseRainbow(void)
  218. {
  219.     uint16_t u16i = 0, u16j = 0;
  220.     uint8_t u8q = 0;

  221.     for (u16j = 0; u16j < 256; u16j++)   // cycle all 256 colors in the wheel
  222.     {
  223.         for (u8q = 0; u8q < 3; u8q++)
  224.         {
  225.             for (u16i = 0; u16i < PIXEL_NUM; u16i = u16i + 3)
  226.             {
  227.                 PSIO_StripSetPixelColor(u16i + u8q, PSIO_StripWheel((u16i + u16j) % 255));
  228.             }

  229.             PSIO_StripShow();

  230.             PSIO_StripReset();

  231.             for (u16i = 0; u16i < PIXEL_NUM; u16i = u16i + 3)
  232.             {
  233.                 PSIO_StripSetPixelColor(u16i + u8q, 0);      //turn every third pixel off
  234.             }
  235.         }
  236.     }

  237.     PSIO_StripClear();

  238.     return 0;
  239. }

  240. /**
  241.   * @brief  This makes the rainbow equally distributed throughout
  242.   * @param  None
  243.   * @retval None
  244.   */
  245. int Strip_RainbowCycle(void)
  246. {
  247.     uint16_t u16i = 0, u16j = 0;

  248.     for (u16j = 0; u16j < (256 * 5); u16j++)   // 5 cycles of all colors on wheel
  249.     {
  250.         for (u16i = 0; u16i < PIXEL_NUM; u16i++)
  251.         {
  252.             PSIO_StripSetPixelColor(u16i, PSIO_StripWheel(((u16i * 256 / PIXEL_NUM) + u16j) & 255));
  253.         }

  254.         PSIO_StripShow();

  255.         PSIO_StripReset();
  256.     }

  257.     PSIO_StripClear();

  258.     return 0;
  259. }

  260. /**
  261.   * @brief  Set strip brightness.
  262.   * @param  None
  263.   * @retval None
  264.   */
  265. int Strip_SetBrightness(void)
  266. {
  267.     uint16_t u16Biighness = 0;

  268.     printf("\nEnter a brightness level of 0 - 255: ");
  269.     u16Biighness = sysGetNum();

  270.     if (u16Biighness > 255)
  271.     {
  272.         u16Biighness = 255;
  273.     }

  274.     printf("%d\r\n", u16Biighness);

  275.     PSIO_StripSetBrightness((uint8_t)u16Biighness & 0xFF);

  276.     return 0;
  277. }

  278. /**
  279.   * @brief  GRB Loop (Red -> Green -> Blue)
  280.   * @param  None
  281.   * @retval None
  282.   */
  283. int Strip_RGBLoop(void)
  284. {
  285.     uint8_t u8i = 0;

  286.     while (kbhit())
  287.     {
  288.         for (u8i = 0; u8i < PIXEL_NUM; u8i++)
  289.         {
  290.             PSIO_StripSetRGBColor(0xFF, 0x00, 0x00);
  291.         }

  292.         TIMER_Delay(TIMER0, 100000);

  293.         for (u8i = 0; u8i < PIXEL_NUM; u8i++)
  294.         {
  295.             PSIO_StripSetRGBColor(0x00, 0xFF, 0x00);
  296.         }

  297.         TIMER_Delay(TIMER0, 100000);

  298.         for (u8i = 0; u8i < PIXEL_NUM; u8i++)
  299.         {
  300.             PSIO_StripSetRGBColor(0x00, 0x00, 0xFF);
  301.         }

  302.         TIMER_Delay(TIMER0, 100000);
  303.     }

  304.     PSIO_StripClear();

  305.     return 0;
  306. }

  307. /**
  308.   * @brief  ARGB2 Strip test menu for selecting test functions
  309.   * @param  None
  310.   * @retval None
  311.   */
  312. void ARGB2StripTestMenu(void)
  313. {
  314.     uint8_t u8Index = 0;
  315.     struct
  316.     {
  317.         char *chName;
  318.         int (*funcptr)(void);
  319.     } sMainMenu[] =
  320.     {
  321.         {"", NULL},
  322.         {"RGB Loop", &Strip_RGBLoop},
  323.         {"Rainbow cycle", &Strip_RainbowCycle},
  324.         {"Theater chase rainbow", &Strip_TheaterChaseRainbow},
  325.         {"Feedback mode", &Strip_FeedbackMode},
  326.         {"Th20 set mode", &Strip_Th20SetMode},
  327.         //{"Strip Sleep Wakeup Test", &Strip_SleepWakeupTest},
  328.         {"Y cable mode", &Strip_YCableSetupMenu},
  329.         {"Set RGB Brightness", &Strip_SetBrightness},
  330.     };

  331.     while (1)
  332.     {
  333.         printf("\r\n\r\n");
  334.         printf("=============================================\r\n");
  335.         printf("\tEnter the select test function: \r\n");
  336.         printf("=============================================\r\n");

  337.         for (u8Index = 1; u8Index < sizeof(sMainMenu) / sizeof(sMainMenu[0]); u8Index++)
  338.         {
  339.             printf("[%02d] %s\r\n",
  340.                    u8Index,
  341.                    sMainMenu[u8Index].chName);
  342.         }

  343.         printf("\r\n");

  344.         u8Index = sysGetNum();

  345.         if ((u8Index == 0) || (u8Index >= sizeof(sMainMenu) / sizeof(sMainMenu[0])))
  346.         {
  347.             continue;
  348.         }

  349.         if (sMainMenu[u8Index].funcptr != NULL)
  350.         {
  351.             sMainMenu[u8Index].funcptr();
  352.         }
  353.     }
  354. }

  355. void SYS_Init(void)
  356. {
  357.     /*---------------------------------------------------------------------------------------------------------*/
  358.     /* Init System Clock                                                                                       */
  359.     /*---------------------------------------------------------------------------------------------------------*/

  360.     /* Enable HIRC clock (Internal RC 48 MHz) */
  361.     CLK_EnableXtalRC(CLK_PWRCTL_HIRCEN_Msk);

  362.     /* Wait for HIRC clock ready */
  363.     CLK_WaitClockReady(CLK_STATUS_HIRCSTB_Msk);

  364.     /* Select HCLK clock source as HIRC and and HCLK clock divider as 1 */
  365.     CLK_SetHCLK(CLK_CLKSEL0_HCLKSEL_HIRC, CLK_CLKDIV0_HCLK(1));

  366.     /* Set XT1_OUT(PF.2) and XT1_IN(PF.3) to input mode */
  367.     PF->MODE &= ~(GPIO_MODE_MODE2_Msk | GPIO_MODE_MODE3_Msk);

  368.     /* Disable digital input path of analog pin XT1_OUT to prevent leakage */
  369.     GPIO_DISABLE_DIGITAL_PATH(PF, (1ul << 2));

  370.     /* Disable digital input path of analog pin XT1_IN to prevent leakage */
  371.     GPIO_DISABLE_DIGITAL_PATH(PF, (1ul << 3));

  372.     /* Set PCLK1 clock divider as 4 */
  373.     CLK->PCLKDIV = (CLK->PCLKDIV & ~CLK_PCLKDIV_APB1DIV_Msk) | CLK_PCLKDIV_APB1DIV_DIV4;

  374.     /* Set both PCLK0 and PCLK1 as HCLK */
  375.     //CLK->PCLKDIV = CLK_PCLKDIV_APB0DIV_DIV1 | CLK_PCLKDIV_APB1DIV_DIV1;

  376.     /* Select IP clock source */
  377.     /* Select UART0 clock source is HIRC */
  378.     CLK_SetModuleClock(UART0_MODULE, CLK_CLKSEL1_UART0SEL_HIRC, CLK_CLKDIV0_UART0(1));

  379.     /* Enable IP clock */
  380.     CLK_EnableModuleClock(GPB_MODULE);
  381.     CLK_EnableModuleClock(UART0_MODULE);
  382.     CLK_EnableModuleClock(TMR0_MODULE);
  383.     CLK_EnableModuleClock(PSIO_MODULE);

  384.     /* Select IP clock source */
  385.     CLK_SetModuleClock(TMR0_MODULE, CLK_CLKSEL1_TMR0SEL_PCLK0, 0);

  386.     /* Select PSIO module clock source as PCLK1(48Mhz/4) and PSIO module clock divider as 0x4 = 0.3125us */
  387.     CLK_SetModuleClock(PSIO_MODULE, CLK_CLKSEL2_PSIOSEL_PCLK1, CLK_CLKDIV1_PSIO(0x04));

  388.     /* Update System Core Clock */
  389.     /* User can use SystemCoreClockUpdate() to calculate PllClock, SystemCoreClock and CycylesPerUs automatically. */
  390.     SystemCoreClockUpdate();

  391.     /* PSIO multi-function pin CH0(PB.15) */
  392.     SYS->GPB_MFPH = (SYS->GPB_MFPH & ~SYS_GPB_MFPH_PB15MFP_Msk) | SYS_GPB_MFPH_PB15MFP_PSIO0_CH0;

  393.     /*----------------------------------------------------------------------*/
  394.     /* Init I/O Multi-function                                              */
  395.     /*----------------------------------------------------------------------*/
  396.     /* Set PB multi-function pins for UART0 RXD and TXD */
  397.     Uart0DefaultMPF();
  398. }

  399. /*---------------------------------------------------------------------------------------------------------*/
  400. /* Init UART0                                                                                             */
  401. /*---------------------------------------------------------------------------------------------------------*/
  402. void UART0_Init(void)
  403. {
  404.     /* Configure UART0 and set UART0 baud rate */
  405.     UART_Open(UART0, 115200);
  406. }

  407. /*---------------------------------------------------------------------------------------------------------*/
  408. /* Init TIMER0                                                                                             */
  409. /*---------------------------------------------------------------------------------------------------------*/
  410. void TIMER0_Init(void)
  411. {
  412.     /* Configure and set TIMER0 */
  413.     // Give a dummy target frequency here. Will over write prescale and compare value with macro
  414.     TIMER_Open(TIMER0, TIMER_PERIODIC_MODE, 48000000);

  415.     // Update prescale and compare value to what we need in event counter mode.
  416.     TIMER_SET_PRESCALE_VALUE(TIMER0, 0);
  417.     TIMER_SET_CMP_VALUE(TIMER0, 160);

  418.     // Counter increase on rising edge
  419.     TIMER_EnableEventCounter(TIMER0, TIMER_COUNTER_EVENT_RISING);
  420. }

  421. /*---------------------------------------------------------------------------------------------------------*/
  422. /*  Main Function                                                                                          */
  423. /*---------------------------------------------------------------------------------------------------------*/
  424. int main(void)
  425. {
  426.     /* Unlock protected registers */
  427.     SYS_UnlockReg();

  428.     /* Init System, peripheral clock and multi-function I/O */
  429.     SYS_Init();

  430.     /* Init UART0 for printf and test */
  431.     UART0_Init();

  432.     /* Lock protected registers */
  433.     SYS_LockReg();

  434.     Delay_Init();

  435.     /* Use slot control 0 and PIN 0 */
  436.     PSIO_StripInit(PSIO_SC0, PSIO_PIN0);

  437.     PSIO_StripSetBrightness(255);

  438.     ARGB2StripTestMenu();
  439. }

  440. /*** (C) COPYRIGHT 2019 Nuvoton Technology Corp. ***/
wahahaheihei 发表于 2024-5-20 23:09 | 显示全部楼层
这是一种新的单片机外设?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

158

主题

1732

帖子

4

粉丝
快速回复 在线客服 返回列表 返回顶部