- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #include <string.h>
- #include "NuMicro.h"
- #include "PSIO_ARGB2_Driver.h"
- //------------------------------------------------------------------------------
- // Global variable
- //------------------------------------------------------------------------------
- static S_PSIO_ARGB2_STRIP_CFG_T gsPSIO_ARGB2_Cfg = {0};
- static uint32_t u32TimeoutUs = 0;
- static uint32_t multipliter = 0;
- //------------------------------------------------------------------------------
- // Define functions prototype
- //------------------------------------------------------------------------------
- static void PSIO_Strip_OpenInput(uint32_t u32Switch);
- static void PSIO_Strip_OpenOutput(uint32_t u32Switch);
- //------------------------------------------------------------------------------
- void Delay_Init(void)
- {
- /* while loop takes 3 ~ 4 cycles */
- /* for 1 us delay, we need to divide with 3M */
- multipliter = (CLK_GetCPUFreq() / 12000000);
- }
- uint32_t TimeoutUsInit(uint32_t micros)
- {
- return (u32TimeoutUs = ((multipliter * (micros + 16)) - 10));
- }
- void DelayUs(uint32_t micros)
- {
- /* multiply micro with multipliter */
- micros = ((multipliter * (micros + 16)) - 10);
- /* 4 cycles for one loop */
- while (micros--);
- }
- void DelayMs(uint32_t mills)
- {
- /* multiply mills with multipliter */
- mills = multipliter * mills * 1100 - 10;
- /* 4 cycles for one loop */
- while (mills--);
- }
- void DelayS(uint32_t mills)
- {
- /* multiply mills with multipliter */
- mills = multipliter * mills * 1100000 - 10;
- /* 4 cycles for one loop */
- while (mills--);
- }
- /**
- * @brief Clear PSIO SLOT setting.
- * @param None
- * @retval None
- */
- void PSIO_ResetAllSlotSetting(void)
- {
- S_PSIO_CP_CONFIG sDataConfig = {0};
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT1SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT2SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT1ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot tick count */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 0);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 0);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 0);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT3, 0);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT4, 0);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT5, 0);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT6, 0);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT7, 0);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- }
- /**
- * @brief Send BIT0 and BIT1 to complete burst data transfer
- * @param None
- * @retval None
- */
- void PSIO_StripSendBurstData(uint32_t u32DataSize,
- uint32_t *u32Data,
- uint32_t u32DataCount)
- {
- uint32_t u32i = 0;
- S_PSIO_CP_CONFIG sDataConfig = {0};
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT1;
- sDataConfig.CKPT2SLT = PSIO_SLOT2;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT1ACT = PSIO_OUT_BUFFER;
- sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot count */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 1);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 2);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 1);
- /* Enable repeat slot0 ~ slot2 u32DataSize - 1 times */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, u32DataSize - 1, PSIO_REPEAT_DISABLE);
- /* Set out data width as u32DataSize bit */
- PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 0, u32DataSize);
- /* Set out data depth as 1 */
- PSIO_SET_OUTPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);
- for (u32i = 0; u32i < u32DataCount; u32i++)
- {
- /* Set output data to buffer */
- PSIO_SET_OUTPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, u32Data[u32i]);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- }
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot2 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- }
- /**
- * @brief Send BIT0 and BIT1 to complete the data transfer
- * @param None
- * @retval None
- */
- void PSIO_SendDataWithSize(uint32_t u32DataSize, uint32_t u32Data)
- {
- S_PSIO_CP_CONFIG sDataConfig = {0};
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT1;
- sDataConfig.CKPT2SLT = PSIO_SLOT2;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT1ACT = PSIO_OUT_BUFFER;
- sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot count */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 1);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 2);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 1);
- /* Enable repeat slot0 ~ slot2 u32DataSize - 1 times */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, u32DataSize - 1, PSIO_REPEAT_DISABLE);
- /* Set out data width as u32DataSize bit */
- PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 0, u32DataSize);
- /* Set out data depth as 1 */
- PSIO_SET_OUTPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);
- /* Set output data to buffer */
- PSIO_SET_OUTPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, u32Data);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot2 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- }
- void PSIO_StripSetupID(uint32_t u32DataSize, uint32_t u32Data)
- {
- S_PSIO_CP_CONFIG sCmdConfig = {0};
- S_PSIO_CP_CONFIG sDataConfig = {0};
- //--------------------------------------------------------------------------
- // Enable strip setup ID control
- //--------------------------------------------------------------------------
- /* Slot 0 ~ 7 */
- sCmdConfig.CKPT0SLT = PSIO_SLOT0;
- sCmdConfig.CKPT1SLT = PSIO_SLOT1;
- sCmdConfig.CKPT2SLT = PSIO_SLOT2;
- sCmdConfig.CKPT3SLT = PSIO_SLOT3;
- sCmdConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sCmdConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sCmdConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sCmdConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sCmdConfig.CKPT0ACT = PSIO_OUT_HIGH;
- sCmdConfig.CKPT1ACT = PSIO_OUT_HIGH;
- sCmdConfig.CKPT2ACT = PSIO_OUT_HIGH;
- sCmdConfig.CKPT3ACT = PSIO_OUT_LOW;
- sCmdConfig.CKPT4ACT = PSIO_NO_ACTION;
- sCmdConfig.CKPT5ACT = PSIO_NO_ACTION;
- sCmdConfig.CKPT6ACT = PSIO_NO_ACTION;
- sCmdConfig.CKPT7ACT = PSIO_NO_ACTION;
- //--------------------------------------------------------------------------
- // send strip setup command and ID
- //--------------------------------------------------------------------------
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT1;
- sDataConfig.CKPT2SLT = PSIO_SLOT2;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT1ACT = PSIO_OUT_BUFFER;
- sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- //first reset
- PSIO_StripReset();
- /* Set out data width as u32DataSize bit */
- PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 0, u32DataSize);
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sCmdConfig);
- /* Set slot 0 tick count as 4, slot 1 tick count as 4, slot 2 tick count as 7 */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 4);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 4);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 7);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT3, 12);
- /* Enable repeat slot 0 ~ slot 2 u32DataSize - 1 times*/
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, u32DataSize - 1, PSIO_REPEAT_DISABLE);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot count */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 1);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 2);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 1);
- /* Set output data to buffer */
- PSIO_SET_OUTPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, u32Data);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot2 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- }
- /**
- * @brief Receive response pulse for Y-Cable check ID function
- * @param None
- * @retval None
- */
- uint16_t PSIO_StripCheckIDFeedback(uint16_t u16WaitTime)
- {
- uint16_t u16LEDCnt = 0;
- uint32_t u32BitIndex = 0;
- int32_t i32UsTimeout = 0;
- S_PSIO_CP_CONFIG sDataConfig = {0};
- i32UsTimeout = TimeoutUsInit(u16WaitTime);
- PSIO_Strip_OpenInput(PSIO_PIN_ENABLE);
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT1;
- sDataConfig.CKPT2SLT = PSIO_SLOT2;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT1ACT = PSIO_IN_BUFFER;
- sDataConfig.CKPT2ACT = PSIO_OUT_LOW;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 3);
- /* Enable repeat slot0 ~ slot0 26 times */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, 63, PSIO_REPEAT_DISABLE);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait data buffer is full */
- while ((!PSIO_GET_TRANSFER_STATUS(PSIO, PSIO_TRANSTS_INFULL0_Msk)) && (i32UsTimeout-- >= 0));
- if (i32UsTimeout <= 0)
- {
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot0 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);
- return 0;
- }
- /* Read data from device */
- u16LEDCnt = PSIO_GET_INPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin);
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot0 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);
- return u16LEDCnt;
- }
- void PSIO_SpecifyStripID(uint8_t u8ID)
- {
- uint8_t u8Cmd = (0x40 | (u8ID & 0x0F));
- PSIO_StripSetupID(8, u8Cmd);
- PSIO_StripReset();
- }
- void PSIO_CheckStripkID(uint8_t u8ID)
- {
- uint8_t u8GetPulse = 0;
- uint8_t u8Cmd = (0x30 | (u8ID & 0x0F));
- PSIO_StripSetupID(8, u8Cmd);
- u8GetPulse = PSIO_StripCheckIDFeedback(160);
- if (u8GetPulse != 0)
- {
- printf("Get %d strip ID\r\n", u8ID);
- }
- else
- {
- printf("Not get %d strip ID\r\n", u8ID);
- }
- PSIO_StripReset();
- }
- void PSIO_ClearStripID(uint8_t u8ID)
- {
- uint8_t u8Cmd = (0x20 | (u8ID & 0x0F));
- PSIO_StripSetupID(8, u8Cmd);
- PSIO_StripReset();
- }
- void PSIO_SetStripID(uint8_t u8ID)
- {
- uint8_t u8Cmd = (0x10 | (u8ID & 0x0F));
- PSIO_StripSetupID(8, u8Cmd);
- PSIO_StripReset();
- }
- void PSIO_StripWakeupMode(void)
- {
- uint8_t u8StripCnt = 0;
- PSIO_StripReset();
- for (u8StripCnt = 0; u8StripCnt < PIXEL_NUM; u8StripCnt++)
- {
- PSIO_SendDataWithSize(24, TH20_24bits);
- DelayMs(1);
- }
- }
- void PSIO_StripSleepMode(void)
- {
- uint8_t u8StripCnt = 0;
- for (u8StripCnt = 0; u8StripCnt < PIXEL_NUM; u8StripCnt++)
- {
- PSIO_SendDataWithSize(24, 0x000000);
- }
- PSIO_SendDataWithSize(8, 0x5A);
- PSIO_StripReset();
- }
- void PSIO_StripHighLevelCMDTh20(void)
- {
- S_PSIO_CP_CONFIG sDataConfig = {0};
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT2SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT1ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot 0 tick count as 15, slot 1 tick count as 15 */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);
- /* Enable repeat slot 0 ~ slot 2 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT0, 3, PSIO_REPEAT_DISABLE);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot0 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- }
- void PSIO_StripHighLevelSetup(void)
- {
- uint8_t u8StripCnt = 0;
- uint32_t u32Data[PIXEL_NUM] = {TH20_24bits};
- for (u8StripCnt = 0; u8StripCnt < PIXEL_NUM; u8StripCnt++)
- {
- u32Data[u8StripCnt] = TH20_24bits;
- }
- PSIO_StripHighLevelCMDTh20();
- PSIO_StripReset();
- PSIO_StripSendBurstData(24, &u32Data[0], PIXEL_NUM);
- PSIO_StripReset();
- }
- /**
- * @brief Send Trst
- * @param None
- * @retval None
- */
- uint16_t PSIO_StripReadFeedBack(uint16_t u16WaitTime)
- {
- uint16_t u16LEDCnt = 0;
- uint32_t u32BitIndex = 0;
- int32_t i32UsTimeout = 0;
- S_PSIO_CP_CONFIG sDataConfig = {0};
- PSIO_Strip_OpenInput(PSIO_PIN_ENABLE);
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT1;
- sDataConfig.CKPT2SLT = PSIO_SLOT2;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT1ACT = PSIO_IN_BUFFER;
- sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot 0 tick count as 15, slot 1 tick count as 15, slot 2 tick count as 3*/
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 9);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 7);
- /* Enable repeat slot0 ~ slot2 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT2, 63, PSIO_REPEAT_DISABLE);
- for (u32BitIndex = 0; u32BitIndex < 512; u32BitIndex++)
- {
- /* Set wait pulse timeout counter */
- i32UsTimeout = TimeoutUsInit(u16WaitTime);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait data buffer is full */
- while ((!PSIO_GET_TRANSFER_STATUS(PSIO, PSIO_TRANSTS_INFULL0_Msk)) && (i32UsTimeout-- >= 0));
- if (i32UsTimeout <= 0)
- {
- break;
- }
- /* Read data from device */
- u16LEDCnt += PSIO_GET_INPUT_DATA(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin);
- }
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot2 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);
- return u16LEDCnt;
- }
- /**
- * @brief Send Trst
- * @param None
- * @retval None
- */
- void PSIO_StripFeedBackCMDTh50(void)
- {
- S_PSIO_CP_CONFIG sDataConfig = {0};
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT1;
- sDataConfig.CKPT2SLT = PSIO_SLOT2;
- sDataConfig.CKPT3SLT = PSIO_SLOT3;
- sDataConfig.CKPT4SLT = PSIO_SLOT4;
- sDataConfig.CKPT5SLT = PSIO_SLOT5;
- sDataConfig.CKPT6SLT = PSIO_SLOT6;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT1ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT2ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT3ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT4ACT = PSIO_OUT_LOW;
- sDataConfig.CKPT5ACT = PSIO_OUT_LOW;
- sDataConfig.CKPT6ACT = PSIO_OUT_HIGH;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot tick count */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT1, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT2, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT3, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT4, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT5, 15);
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT6, 15);
- /* Enable repeat slot6 ~ slot7 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT6, PSIO_SLOT6, 9, PSIO_REPEAT_DISABLE);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot0 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- }
- /**
- * @brief Send Trst
- * @param None
- * @retval None
- */
- uint16_t PSIO_StripFeedBackMode(void)
- {
- uint16_t u16LEDCnt = 0;
- uint32_t u32BitIndex = 0;
- uint32_t u32DelayCnt = 0;
- PSIO_StripReset();
- PSIO_StripFeedBackCMDTh50();
- u16LEDCnt = PSIO_StripReadFeedBack(160);
- PSIO_StripReset();
- PSIO_ResetAllSlotSetting();
- return u16LEDCnt;
- }
- /**
- * @brief Send Trst
- * @param None
- * @retval None
- */
- void PSIO_StripReset(void)
- {
- S_PSIO_CP_CONFIG sDataConfig = {0};
- /* Slot 0 ~ 7 */
- sDataConfig.CKPT0SLT = PSIO_SLOT0;
- sDataConfig.CKPT1SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT2SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT3SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT4SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT5SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT6SLT = PSIO_SLOT_DISABLE;
- sDataConfig.CKPT7SLT = PSIO_SLOT_DISABLE;
- /* Actions 0 ~ 7 */
- sDataConfig.CKPT0ACT = PSIO_OUT_LOW;
- sDataConfig.CKPT1ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT2ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT3ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT4ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT5ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT6ACT = PSIO_NO_ACTION;
- sDataConfig.CKPT7ACT = PSIO_NO_ACTION;
- /* Set check point configuration */
- PSIO_SET_CP_CONFIG(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, &sDataConfig);
- /* Set slot 0 tick count as 15, slot 1 tick count as 15 */
- PSIO_SCSLOT_SET_SLOT(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, 15);
- /* Enable repeat slot1 ~ slot1 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT0, PSIO_SLOT0, 47, PSIO_REPEAT_DISABLE);
- /* Trigger slot controller */
- PSIO_START_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Wait for slot controller is not busy */
- while (PSIO_GET_BUSY_FLAG(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl));
- /* Stop slot controller */
- PSIO_STOP_SC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl);
- /* Disable repeat slot0 ~ slot0 */
- PSIO_SET_SCCTL(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SLOT_DISABLE, PSIO_SLOT_DISABLE, 0, PSIO_REPEAT_DISABLE);
- }
- static void PSIO_Strip_OpenInput(uint32_t u32Switch)
- {
- /* PSIO UART TX PIN general setting */
- PSIO_SET_GENCTL(PSIO,
- gsPSIO_ARGB2_Cfg.u8DataPin,
- u32Switch,//PSIO_PIN_ENABLE,
- gsPSIO_ARGB2_Cfg.u8SlotCtrl,
- PSIO_INPUT_MODE,
- PSIO_LOW_LEVEL,
- PSIO_LOW_LEVEL);
- /* Set output data buffer width as 8 bit, input data width as 1 bit*/
- PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 1, 8);
- /* Set input data buffer depth as 1 */
- PSIO_SET_INPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);
- }
- static void PSIO_Strip_OpenOutput(uint32_t u32Switch)
- {
- /* PSIO UART TX PIN general setting */
- PSIO_SET_GENCTL(PSIO,
- gsPSIO_ARGB2_Cfg.u8DataPin,
- u32Switch, //PSIO_PIN_ENABLE
- gsPSIO_ARGB2_Cfg.u8SlotCtrl,
- PSIO_OUTPUT_MODE,
- PSIO_LOW_LEVEL,
- PSIO_LOW_LEVEL);
- /* Set data order ad MSB */
- PSIO_SET_ORDER(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_MSB);
- /* Set output data buffer width as 8 bit, input data width as 1 bit*/
- PSIO_SET_WIDTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, 1, 8);
- /* Set output data buffer depth as 1 */
- PSIO_SET_OUTPUT_DEPTH(PSIO, gsPSIO_ARGB2_Cfg.u8DataPin, PSIO_DEPTH1);
- /* Set slot controller trigger source as software trigger */
- PSIO_SET_TRIGSRC(PSIO, gsPSIO_ARGB2_Cfg.u8SlotCtrl, PSIO_SW_TRIGGER);
- }
- /**
- * @brief initialize ARGB2 PSIO PIN
- * @param None
- * @retval None
- */
- void PSIO_StripInit(uint8_t u8SlotCtrl, uint8_t u8DataPin)
- {
- gsPSIO_ARGB2_Cfg.u8SlotCtrl = u8SlotCtrl;
- gsPSIO_ARGB2_Cfg.u8DataPin = u8DataPin;
- PSIO_Strip_OpenOutput(PSIO_PIN_ENABLE);
- }
- //------------------------------------------------------------------------------
- /**
- * @brief Fill ALL LEDs with (0,0,0)
- * @param 24 bits data (Range: 0x000000 to 0xffffff)
- * @retval None
- */
- void PSIO_StripClear(void)
- {
- uint8_t u8i = 0;
- for (u8i = 0; u8i < PIXEL_NUM; u8i++)
- {
- PSIO_SendDataWithSize(24, 0x000000);
- }
- }
- /**
- * @brief Digital output to all LED which in ARGB2 strip
- * @param None
- * @retval None
- */
- void PSIO_StripShow(void)
- {
- uint16_t i, j;
- int32_t i32Data[PIXEL_NUM] = {0};
- S_PSIO_CP_CONFIG sDataConfig = {0};
- for (i = 0; i < PIXEL_NUM; ++i)
- {
- for (j = 0; j < GRB; ++j)
- {
- i32Data[i] |= (gsPSIO_ARGB2_Cfg.au8PixelBuffer[i][j] << (23 - j));
- //if (gsPSIO_ARGB2_Cfg.au8PixelBuffer[i][j] == BIT1_HIGH) {
- // PSIO_SendStripBit1();
- //} else {
- // PSIO_SendStripBit0();
- //}
- }
- }
- for (i = 0; i < PIXEL_NUM; ++i)
- {
- PSIO_SendDataWithSize(24, i32Data[i]);
- }
- }
- /**
- * @brief RGB color bitwise operation
- * @param red 0-255
- * green 0-255
- * blue 0-255
- * @retval None
- */
- uint32_t Strip_color(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue)
- {
- return u8Green << 16 | u8Red << 8 | u8Blue;
- }
- /**
- * @brief Input a value 0 to 255 to get a color value.
- The colours are a transition r - g - b - back to r.
- * @param None
- * @retval None
- */
- uint32_t PSIO_StripWheel(uint8_t u8WheelPos)
- {
- u8WheelPos = 255 - u8WheelPos;
- if (u8WheelPos < 85)
- {
- return Strip_color(255 - u8WheelPos * 3, 0, u8WheelPos * 3);
- }
- if (u8WheelPos < 170)
- {
- u8WheelPos -= 85;
- return Strip_color(0, u8WheelPos * 3, 255 - u8WheelPos * 3);
- }
- u8WheelPos -= 170;
- return Strip_color(u8WheelPos * 3, 255 - u8WheelPos * 3, 0);
- }
- /**
- * @brief RGB setting to all LED
- * @param n: Specify a LED
- GRBColor: Set BIT1 or BIT0
- * @retval None
- */
- void PSIO_StripSetPixelColor(uint16_t u16Num, uint32_t u32RGBColor)
- {
- uint8_t i = 0;
- if (u16Num < PIXEL_NUM)
- {
- for (i = 0; i < GRB; i++)
- {
- gsPSIO_ARGB2_Cfg.au8PixelBuffer[u16Num][i] = ((u32RGBColor << i) & 0x800000) ? BIT1_HIGH : BIT0_LOW;
- }
- }
- }
- /**
- * @brief Set GLOBAL LED brightness
- * @param[in] br Brightness [0..255]
- * [url=home.php?mod=space&uid=266161]@return[/url] #ARGB_STATE enum
- */
- void PSIO_StripSetBrightness(uint8_t u8Brightness)
- {
- gsPSIO_ARGB2_Cfg.u8Brightness = u8Brightness;
- }
- /**
- * @brief Send one data to a LED
- * @param 24 bits data (Range: 0x000000 to 0xffffff)
- * @retval None
- */
- void PSIO_StripSetRGBColor(uint8_t u8Red, uint8_t u8Green, uint8_t u8Blue)
- {
- int32_t i32Data = 0;
- u8Red /= (256 / ((uint16_t) gsPSIO_ARGB2_Cfg.u8Brightness + 1));
- u8Green /= (256 / ((uint16_t) gsPSIO_ARGB2_Cfg.u8Brightness + 1));
- u8Blue /= (256 / ((uint16_t) gsPSIO_ARGB2_Cfg.u8Brightness + 1));
- i32Data |= (u8Green << 16);
- i32Data |= (u8Red << 8);
- i32Data |= u8Blue;
- PSIO_SendDataWithSize(24, i32Data);
- }