// INPUT CONTROLLED LEDs
#include
const uint32_t led_mask[] = {1UL << 18, 1UL << 19, 1UL << 1};
// LED #0, #1 are port B, LED #2 is port D
void IO_Config(void);
void LED_Set(void);
void LED_Clear(void);
__INLINE static void LED_On (uint32_t led);
__INLINE static void LED_Off (uint32_t led);
#define MASK(x) (1UL << (x))
int main(void)
{
// VARIABLE DECLARATION IF REQUIRED
SystemCoreClockUpdate(); // Optional- Setup SystemCoreClock variable
// Configure LED outputs
IO_Config();
while(1){ // YOUR CODE HERE
}
}
/*----------------------------------------------------------------------------
I/O pin config
*----------------------------------------------------------------------------*/
void IO_Config(void)
{
/* Enable Clock to Port B & D */
/* Pin PTB18 is GPIO */
/* Pin PTB19 is GPIO */
/* Pin PTD1 is GPIO */
/* Pin PTD0 is GPIO, Enable pull up resistor*/
/* Pin PTD2 is GPIO, Enable pull up resistor */
/* Pin PTD5 is GPIO, Enable pull up resistor */
/* switch Red/Green LED off */
/* enable PTB18/19 as Output */
/* switch Blue LED off */
/* enable PTD1 as Output */
/* enable PTD0,2,5 as Input */
return;
}
/*---------------------------------------------------------------------------
Switch on LEDs
*---------------------------------------------------------------------------*/
void LED_Set(void)
{
LED_On(0); // RED
LED_On(1); // GREEN
LED_On(2); // BLUE
return;
}
/*---------------------------------------------------------------------------
Switch off LEDs
*---------------------------------------------------------------------------*/
void LED_Clear(void)
{
LED_Off(0); // RED
LED_Off(1); // GREEN
LED_Off(2); // BLUE
return;
}
/*---------------------------------------------------------------------------
Switch on LED (just one)
*---------------------------------------------------------------------------*/
__INLINE static void LED_On (uint32_t led) {
if (led == 2) FPTD->PCOR = led_mask[led];
else FPTB->PCOR = led_mask[led];
}
/*—————————————————————————
Switch off LED (just one)
*—————————————————————————*/
__INLINE static void LED_Off (uint32_t led) {
if (led == 2) FPTD->PSOR = led_mask[led];
else FPTB->PSOR = led_mask[led];
}