-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from shinhub/led_simplify
Led simplify
- Loading branch information
Showing
7 changed files
with
63 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,51 @@ | ||
#include <stdbool.h> | ||
#include <avr/io.h> | ||
#include <avr/pgmspace.h> | ||
#include "LED.h" | ||
|
||
uint8_t LEDLowPulseMask = 0, LEDHighPulseMask = 0; | ||
|
||
inline | ||
void LEDMode(void) { | ||
LEDHighSetOff(LED_ONE); | ||
LEDHighSetOff(LED_TWO); | ||
LEDHighSetOff(LED_THREE); | ||
LEDHighSetOff(LED_FOUR); | ||
LEDLowSetOff(LED_FIVE); | ||
LEDLowSetOff(LED_SIX); | ||
LEDLowSetOff(LED_SEVEN); | ||
LEDLowSetOff(LED_EIGHT); | ||
|
||
switch(GlobalSettings.ActiveSetting) { | ||
case 0: LEDHighSetOn(LED_ONE); break; | ||
case 1: LEDHighSetOn(LED_TWO); break; | ||
case 2: LEDHighSetOn(LED_THREE); break; | ||
case 3: LEDHighSetOn(LED_FOUR); break; | ||
case 4: LEDLowSetOn(LED_FIVE); break; | ||
case 5: LEDLowSetOn(LED_SIX); break; | ||
case 6: LEDLowSetOn(LED_SEVEN); break; | ||
case 7: LEDLowSetOn(LED_EIGHT); break; | ||
default: break; | ||
} | ||
#include "Settings.h" | ||
#include "Common.h" | ||
|
||
static const LedPining_t LEDPiningTable[] PROGMEM = { | ||
[LED_ONE] = { .ledPort = &LED_HIGH_PORT, .ledPin = PIN5_bm }, | ||
[LED_TWO] = { .ledPort = &LED_HIGH_PORT, .ledPin = PIN4_bm }, | ||
[LED_THREE] = { .ledPort = &LED_HIGH_PORT, .ledPin = PIN3_bm }, | ||
[LED_FOUR] = { .ledPort = &LED_HIGH_PORT, .ledPin = PIN2_bm }, | ||
[LED_FIVE] = { .ledPort = &LED_LOW_PORT, .ledPin = PIN3_bm }, | ||
[LED_SIX] = { .ledPort = &LED_LOW_PORT, .ledPin = PIN2_bm }, | ||
[LED_SEVEN] = { .ledPort = &LED_LOW_PORT, .ledPin = PIN1_bm }, | ||
[LED_EIGHT] = { .ledPort = &LED_LOW_PORT, .ledPin = PIN0_bm } | ||
}; | ||
|
||
INLINE void LEDAllOff(void) { | ||
LED_HIGH_PORT.OUTCLR = LED_HIGH_MASK; | ||
LED_LOW_PORT.OUTCLR = LED_LOW_MASK; | ||
} | ||
|
||
void LEDInit(void) { | ||
LED_LOW_PORT.DIRSET = LED_LOW_MASK; | ||
LED_HIGH_PORT.DIRSET = LED_HIGH_MASK; | ||
INLINE void LEDMode(void) { | ||
LEDAllOff(); | ||
LEDSetOn(GlobalSettings.ActiveSetting); | ||
} | ||
|
||
inline | ||
void LEDTick(void) { | ||
LED_HIGH_PORT.OUTCLR = LEDLowPulseMask; | ||
LEDLowPulseMask = 0; | ||
LED_LOW_PORT.OUTCLR = LEDHighPulseMask; | ||
LEDHighPulseMask = 0; | ||
LEDMode(); | ||
LED_HIGH_PORT.OUTCLR = LED_LOW_PULSE_MASK; | ||
LED_LOW_PORT.OUTCLR = LED_HIGH_PULSE_MASK; | ||
LEDMode(); | ||
} | ||
|
||
inline | ||
void LEDHighSetOn(uint8_t Mask) { | ||
LED_HIGH_PORT.OUTSET = Mask; | ||
void LEDInit(void) { | ||
LED_LOW_PORT.DIRSET = LED_LOW_MASK; | ||
LED_HIGH_PORT.DIRSET = LED_HIGH_MASK; | ||
} | ||
|
||
inline | ||
void LEDLowSetOn(uint8_t Mask) { | ||
LED_LOW_PORT.OUTSET = Mask; | ||
INLINE void LEDSet(Led LedId, bool on) { | ||
PORT_t * ledPort = ( (PORT_t *)pgm_read_ptr( &(LEDPiningTable[LedId].ledPort) ) ); | ||
uint8_t ledPin = ( (uint8_t)pgm_read_byte( &(LEDPiningTable[LedId].ledPin) ) ); | ||
(on) ? (ledPort->OUTSET = ledPin) : (ledPort->OUTCLR = ledPin); | ||
} | ||
|
||
inline | ||
void LEDHighSetOff(uint8_t Mask) { | ||
LED_HIGH_PORT.OUTCLR = Mask; | ||
void LEDSetOn(Led LedId) { | ||
LEDSet(LedId, true); | ||
} | ||
|
||
inline | ||
void LEDLowSetOff(uint8_t Mask) { | ||
LED_LOW_PORT.OUTCLR = Mask; | ||
void LEDSetOff(Led LedId) { | ||
LEDSet(LedId, false); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
|
||
#include "System.h" | ||
#include "LED.h" | ||
|
||
ISR(BADISR_vect) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters