diff --git a/CShiftPWM.cpp b/CShiftPWM.cpp index 726b2bc..a980107 100644 --- a/CShiftPWM.cpp +++ b/CShiftPWM.cpp @@ -33,11 +33,11 @@ CShiftPWM::CShiftPWM(int timerInUse, bool noSPI, int latchPin, int dataPin, int m_counter = 0; m_pinGrouping = 1; // Default = RGBRGBRGB... PinGrouping = 3 means: RRRGGGBBBRRRGGGBBB... - unsigned char * m_PWMValues=0; + m_PWMValues=0; } CShiftPWM::~CShiftPWM() { - if(m_PWMValues>0){ + if(m_PWMValues){ free( m_PWMValues ); } } @@ -129,7 +129,7 @@ void CShiftPWM::SetAllRGB(unsigned char r,unsigned char g,unsigned char b){ } void CShiftPWM::SetHSV(int led, unsigned int hue, unsigned int sat, unsigned int val, int offset){ - unsigned char r,g,b; + unsigned char r=0,g=0,b=0; unsigned int H_accent = hue/60; unsigned int bottom = ((255 - sat) * val)>>8; unsigned int top = val; @@ -195,7 +195,7 @@ void CShiftPWM::OneByOneFast(void){ void CShiftPWM::OneByOne_core(int delaytime){ int pin,brightness; SetAll(0); - for(int pin=0;pincounter ); } bitSet(*clockPort, clockBit); +#else + digitalWriteFast(clockBit, LOW); +#if F_CPU >= 120000000 + asm("nop"); +#endif +#if F_CPU >= 180000000 + asm("nop"); +#endif + if(ShiftPWM_invertOutputs){ + digitalWriteFast(dataBit, *(ledPtr)<=counter ); + } + else{ + digitalWriteFast(dataBit, *(ledPtr)>counter ); + } +#if F_CPU >= 96000000 + asm("nop"); +#endif +#if F_CPU >= 144000000 + asm("nop"); +#endif +#if F_CPU >= 192000000 + asm("nop"); +#endif + digitalWriteFast(clockBit, HIGH); +#if F_CPU >= 48000000 + asm("nop"); +#endif +#if F_CPU >= 72000000 + asm("nop"); +#endif +#if F_CPU >= 96000000 + asm("nop"); +#endif +#if F_CPU >= 120000000 + asm("nop"); +#endif +#if F_CPU >= 144000000 + asm("nop"); +#endif +#if F_CPU >= 168000000 + asm("nop"); +#endif +#if F_CPU >= 180000000 + asm("nop"); +#endif +#if F_CPU >= 192000000 + asm("nop"); +#endif +#if F_CPU >= 216000000 + asm("nop"); +#endif +#endif } +#if defined(__AVR__) static inline void ShiftPWM_handleInterrupt(void){ +#else +void ShiftPWM_handleInterrupt(void){ +#endif sei(); //enable interrupt nesting to prevent disturbing other interrupt functions (servo's for example). // Look up which bit of which output register corresponds to the pin. @@ -107,8 +164,10 @@ static inline void ShiftPWM_handleInterrupt(void){ // The compiler does not recognize the pins/ports as constant and sbi and cbi instructions cannot be used. + #ifndef SHIFTPWM_USE_DIGITALWRITEFAST volatile uint8_t * const latchPort = port_to_output_PGM_ct[digital_pin_to_port_PGM_ct[ShiftPWM_latchPin]]; const uint8_t latchBit = digital_pin_to_bit_PGM_ct[ShiftPWM_latchPin]; + #endif #ifdef SHIFTPWM_NOSPI volatile uint8_t * const clockPort = port_to_output_PGM_ct[digital_pin_to_port_PGM_ct[ShiftPWM_clockPin]]; @@ -123,7 +182,12 @@ static inline void ShiftPWM_handleInterrupt(void){ unsigned char * ledPtr=&ShiftPWM.m_PWMValues[ShiftPWM.m_amountOfOutputs]; // Write shift register latch clock low + #ifndef SHIFTPWM_USE_DIGITALWRITEFAST bitClear(*latchPort, latchBit); + #else + digitalWriteFast(ShiftPWM_latchPin, LOW); + #endif + unsigned char counter = ShiftPWM.m_counter; #ifndef SHIFTPWM_NOSPI @@ -169,7 +233,11 @@ static inline void ShiftPWM_handleInterrupt(void){ #endif // Write shift register latch clock high + #ifndef SHIFTPWM_USE_DIGITALWRITEFAST bitSet(*latchPort, latchBit); + #else + digitalWriteFast(ShiftPWM_latchPin, HIGH); + #endif if(ShiftPWM.m_counter