Commit 200821fe authored by Dean Camera's avatar Dean Camera
Browse files

Added new LEDs_ToggleLEDs() function to the Board LEDs driver.

parent 3991c94b
...@@ -156,10 +156,7 @@ void ReadNextReport(void) ...@@ -156,10 +156,7 @@ void ReadNextReport(void)
if (KeyboardReport.KeyCode) if (KeyboardReport.KeyCode)
{ {
/* Toggle status LED to indicate keypress */ /* Toggle status LED to indicate keypress */
if (LEDs_GetLEDs() & LEDS_LED2) LEDs_ToggleLEDs(LEDS_LED2);
LEDs_TurnOffLEDs(LEDS_LED2);
else
LEDs_TurnOnLEDs(LEDS_LED2);
char PressedKey = 0; char PressedKey = 0;
......
...@@ -250,10 +250,7 @@ void ProcessKeyboardReport(uint8_t* KeyboardReport) ...@@ -250,10 +250,7 @@ void ProcessKeyboardReport(uint8_t* KeyboardReport)
if (KeyCode) if (KeyCode)
{ {
/* Toggle status LED to indicate keypress */ /* Toggle status LED to indicate keypress */
if (LEDs_GetLEDs() & LEDS_LED2) LEDs_ToggleLEDs(LEDS_LED2);
LEDs_TurnOffLEDs(LEDS_LED2);
else
LEDs_TurnOnLEDs(LEDS_LED2);
char PressedKey = 0; char PressedKey = 0;
......
...@@ -86,24 +86,29 @@ ...@@ -86,24 +86,29 @@
// TODO: Add code to initialize LED port pins as outputs here // TODO: Add code to initialize LED port pins as outputs here
} }
static inline void LEDs_TurnOnLEDs(const uint8_t LedMask) static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
{ {
// TODO: Add code to turn on LEDs given in the LedMask mask here, leave others as-is // TODO: Add code to turn on LEDs given in the LEDMask mask here, leave others as-is
} }
static inline void LEDs_TurnOffLEDs(const uint8_t LedMask) static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
{ {
// TODO: Add code to turn off LEDs given in the LedMask mask here, leave others as-is // TODO: Add code to turn off LEDs given in the LEDMask mask here, leave others as-is
} }
static inline void LEDs_SetAllLEDs(const uint8_t LedMask) static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
{ {
// TODO: Add code to turn on only LEDs given in the LedMask mask here, all others off // TODO: Add code to turn on only LEDs given in the LEDMask mask here, all others off
} }
static inline void LEDs_ChangeLEDs(const uint8_t LedMask, const uint8_t ActiveMask) static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask)
{ {
// TODO: Add code to set the Leds in the given LedMask to the status given in ActiveMask here // TODO: Add code to set the Leds in the given LEDMask to the status given in ActiveMask here
}
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
{
// TODO: Add code to toggle the Leds in the given LEDMask, ignoring all others
} }
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
......
...@@ -110,6 +110,11 @@ ...@@ -110,6 +110,11 @@
{ {
PORTD = ((PORTD & ~(LEDMask & LEDS_ALL_LEDS)) | (ActiveMask & LEDS_ALL_LEDS)); PORTD = ((PORTD & ~(LEDMask & LEDS_ALL_LEDS)) | (ActiveMask & LEDS_ALL_LEDS));
} }
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
{
PORTD = (PORTD ^ (LEDMask & LEDS_ALL_LEDS));
}
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
static inline uint8_t LEDs_GetLEDs(void) static inline uint8_t LEDs_GetLEDs(void)
......
...@@ -142,6 +142,12 @@ ...@@ -142,6 +142,12 @@
* \param[in] ActiveMask Mask of whether the LEDs in the LED mask should be turned on or off * \param[in] ActiveMask Mask of whether the LEDs in the LED mask should be turned on or off
*/ */
static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask); static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask);
/** Toggles all LEDs in the LED mask, leaving all others in their current states.
*
* \param[in] LEDMask Mask of the board LEDs to manipulate (see board-specific LEDs.h driver file)
*/
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask);
/** Returns the status of all the board LEDs; set LED masks in the return value indicate that the /** Returns the status of all the board LEDs; set LED masks in the return value indicate that the
* corresponding LED is on. * corresponding LED is on.
......
...@@ -131,6 +131,12 @@ ...@@ -131,6 +131,12 @@
~((ActiveMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT)); ~((ActiveMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT));
} }
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
{
PORTD = (PORTD ^ (LEDMask & LEDS_PORTD_LEDS));
PORTE = (PORTE ^ ((LEDMask & LEDS_PORTE_LEDS) << LEDS_PORTE_MASK_SHIFT));
}
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
static inline uint8_t LEDs_GetLEDs(void) static inline uint8_t LEDs_GetLEDs(void)
{ {
......
...@@ -88,26 +88,31 @@ ...@@ -88,26 +88,31 @@
PORTD &= ~LEDS_ALL_LEDS; PORTD &= ~LEDS_ALL_LEDS;
} }
static inline void LEDs_TurnOnLEDs(const uint8_t LedMask) static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
{ {
PORTD |= LedMask; PORTD |= LEDMask;
} }
static inline void LEDs_TurnOffLEDs(const uint8_t LedMask) static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
{ {
PORTD &= ~LedMask; PORTD &= ~LEDMask;
} }
static inline void LEDs_SetAllLEDs(const uint8_t LedMask) static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
{ {
PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LedMask); PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);
} }
static inline void LEDs_ChangeLEDs(const uint8_t LedMask, const uint8_t ActiveMask) static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask)
{ {
PORTD = ((PORTD & ~LedMask) | ActiveMask); PORTD = ((PORTD & ~LEDMask) | ActiveMask);
} }
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
{
PORTD = (PORTD ^ (LEDMask & LEDS_ALL_LEDS));
}
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
static inline uint8_t LEDs_GetLEDs(void) static inline uint8_t LEDs_GetLEDs(void)
{ {
......
...@@ -88,24 +88,29 @@ ...@@ -88,24 +88,29 @@
PORTD &= ~LEDS_ALL_LEDS; PORTD &= ~LEDS_ALL_LEDS;
} }
static inline void LEDs_TurnOnLEDs(const uint8_t LedMask) static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
{ {
PORTD |= LedMask; PORTD |= LEDMask;
} }
static inline void LEDs_TurnOffLEDs(const uint8_t LedMask) static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
{ {
PORTD &= ~LedMask; PORTD &= ~LEDMask;
} }
static inline void LEDs_SetAllLEDs(const uint8_t LedMask) static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
{ {
PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LedMask); PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);
} }
static inline void LEDs_ChangeLEDs(const uint8_t LedMask, const uint8_t ActiveMask) static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask)
{ {
PORTD = ((PORTD & ~LedMask) | ActiveMask); PORTD = ((PORTD & ~(LEDMask & LEDS_ALL_LEDS)) | (ActiveMask & LEDS_ALL_LEDS));
}
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
{
PORTD = (PORTD ^ (LEDMask & LEDS_ALL_LEDS));
} }
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
......
...@@ -88,24 +88,29 @@ ...@@ -88,24 +88,29 @@
PORTD &= ~LEDS_ALL_LEDS; PORTD &= ~LEDS_ALL_LEDS;
} }
static inline void LEDs_TurnOnLEDs(const uint8_t LedMask) static inline void LEDs_TurnOnLEDs(const uint8_t LEDMask)
{ {
PORTD |= LedMask; PORTD |= LEDMask;
} }
static inline void LEDs_TurnOffLEDs(const uint8_t LedMask) static inline void LEDs_TurnOffLEDs(const uint8_t LEDMask)
{ {
PORTD &= ~LedMask; PORTD &= ~LEDMask;
} }
static inline void LEDs_SetAllLEDs(const uint8_t LedMask) static inline void LEDs_SetAllLEDs(const uint8_t LEDMask)
{ {
PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LedMask); PORTD = ((PORTD & ~LEDS_ALL_LEDS) | LEDMask);
} }
static inline void LEDs_ChangeLEDs(const uint8_t LedMask, const uint8_t ActiveMask) static inline void LEDs_ChangeLEDs(const uint8_t LEDMask, const uint8_t ActiveMask)
{ {
PORTD = ((PORTD & ~LedMask) | ActiveMask); PORTD = ((PORTD & ~LEDMask) | ActiveMask);
}
static inline void LEDs_ToggleLEDs(const uint8_t LEDMask)
{
PORTD = (PORTD ^ (LEDMask & LEDS_ALL_LEDS));
} }
static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT; static inline uint8_t LEDs_GetLEDs(void) ATTR_WARN_UNUSED_RESULT;
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
* - Added new USB_DeviceState variable to keep track of the current Device mode USB state * - Added new USB_DeviceState variable to keep track of the current Device mode USB state
* - Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers * - Added new Endpoint_ClearStatusStage() convenience function to assist with the status stages of control transfers
* - Added new Benito Arduino Programmer project * - Added new Benito Arduino Programmer project
* - Added new LEDs_ToggleLEDs() function to the LEDs driver
* *
* <b>Changed:</b> * <b>Changed:</b>
* - Deprecated psuedo-scheduler and removed dynamic memory allocator from the library (first no longer needed and second unused) * - Deprecated psuedo-scheduler and removed dynamic memory allocator from the library (first no longer needed and second unused)
......
...@@ -107,7 +107,7 @@ int main(void) ...@@ -107,7 +107,7 @@ int main(void)
/* Check if the LEDs should be ping-ponging (during enumeration) */ /* Check if the LEDs should be ping-ponging (during enumeration) */
if (PingPongMSRemaining && !(--PingPongMSRemaining)) if (PingPongMSRemaining && !(--PingPongMSRemaining))
{ {
LEDs_ChangeLEDs(LEDMASK_BUSY, (~LEDs_GetLEDs() & LEDMASK_BUSY)); LEDs_ToggleLEDs(LEDMASK_BUSY);
PingPongMSRemaining = PING_PONG_LED_PULSE_MS; PingPongMSRemaining = PING_PONG_LED_PULSE_MS;
} }
......
...@@ -173,7 +173,7 @@ void Send_Command(uint8_t* Command) ...@@ -173,7 +173,7 @@ void Send_Command(uint8_t* Command)
if ((CmdState == CMD_STOP && Command != CMD_STOP) || if ((CmdState == CMD_STOP && Command != CMD_STOP) ||
(CmdState != CMD_STOP && Command == CMD_STOP)) (CmdState != CMD_STOP && Command == CMD_STOP))
{ {
LEDs_ChangeLEDs(LEDS_LED4, ~LEDs_GetLEDs() & LEDS_LED4); LEDs_ToggleLEDs(LEDS_LED4);
Send_Command_Report(CMD_INITA, 8); Send_Command_Report(CMD_INITA, 8);
Send_Command_Report(CMD_INITB, 8); Send_Command_Report(CMD_INITB, 8);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment