Beispiel #1
0
/***    bool WS2812::begin(uint32_t cDevices, uint8_t * pPatternBuffer, uint32_t cbPatternBuffer, bool fInvert)
 *
 *    Parameters:
 *          cDevices:   The number of devices in the WS2812 string / chain
 *
 *          pPatternBuffer: A pointer to the pattern buffer for the DMA to use
 *                          The application allocates this and should be 
 *                          CBWS2812PATBUF(__cDevices) bytes long.
 *
 *          cbPatternBuffer: This should be CBWS2812PATBUF(__cDevices) or larger
 *
 *          fInvert:        Because the WS2812 does not have a VinH <= 3.3 when Vcc >= 4.7v
 *                          External hardware may be needed to level shift the 3.3v SDO output
 *                          to a higher Data in signal to the WS2812. This level shifter may
 *                          be a simple transistor tied to 5v - 7v. The transistor will invert
 *                          the SDO output signal and to maintain the correct signal polarity
 *                          to the WS2812 you would need to invert the signal coming out of SDO.
 *                          If fInvert is true, the SDO output signal will be inverted from what
 *                          the WS2812 would normally take. By default, the is "false".
 *
 *    Return Values:
 *          True if the WS2812 library was successfully initialized
 *          False if it was not. Probably because the pattern buffer was not the correct size
 *                  or because there were no open slots in the CoreTimer Service Routines.
 *
 *    Description:
 *
 *      Initializes the WS2812 library and starts streaming a refresh cycle out on SDO
 *
 * ------------------------------------------------------------ */
bool WS2812::begin(uint32_t cDevices, uint8_t * pPatternBuffer, uint32_t cbPatternBuffer, bool fInvert)
{
    if(_fInit)
    {
        return(true);
    }

    if(cDevices == 0 || pPatternBuffer == NULL || cbPatternBuffer < CBWS2812PATBUF(cDevices))
    {
        return(false);
    }

    init();
    _cDevices           =   cDevices;
     _pPatternBuffer    =   pPatternBuffer;
    _cbPatternBuffer    =   cbPatternBuffer;
    _fInit              =   InitWS2812(pPatternBuffer, cbPatternBuffer, fInvert);
    _fInvert            =   fInvert;

    if(!_fInit)
    {
        end();
    }

    return(_fInit);
}
Beispiel #2
0
int LinxChipkit::WS2812Open(unsigned short numLeds, unsigned char dataChan)
{
	#ifdef _BOARD_WF32_ | _BOARD_MEGA_
		m_numPixels = numLeds;
		m_WS2812Buffer = (WS2812::GRB*)malloc(numLeds * sizeof(WS2812::GRB));
		m_rgbPatternBuffer = (uint8_t*)malloc(CBWS2812PATBUF(numLeds));

		
		
		//Check If Memory Was Allocated Successfully
		if(m_WS2812Buffer == 0 || m_rgbPatternBuffer == 0)
		{
			return 0x81;
		}
		else
		{
			m_ws2812.begin(numLeds, m_rgbPatternBuffer, CBWS2812PATBUF(numLeds), false);
		}
		
		return L_OK;
	#else
		return L_FUNCTION_NOT_SUPPORTED;
	#endif
}