Beispiel #1
0
BlinkLed::BlinkLed (unsigned int port, unsigned int bit, bool activeLow)
{
  fPortNumber = port;
  fBitNumber = bit;
  fIsActiveLow = activeLow;
  fBitMask = BLINK_PIN_MASK(fBitNumber);
}
Beispiel #2
0
void
BlinkLed::turnOff ()
{
  if (fIsActiveLow)
    {
      BLINK_GPIOx(fPortNumber)->BSRR = fBitMask;
    }
  else
    {
      BLINK_GPIOx(fPortNumber)->BSRR = BLINK_PIN_MASK(fBitNumber + 16);
    }
}
Beispiel #3
0
void
BlinkLed::powerUp()
{
  // Turn on clock for port module
  SIM->SCGC5 |= BLINK_SCGC5_MASKx(BLINK_PORT_NUMBER);

  // Set the pin multiplexer to GPIO mode
  BLINK_PORTx(BLINK_PORT_NUMBER)->PCR[BLINK_PIN_NUMBER] = PORT_PCR_MUX(1);

  // Set the pin as output
  BLINK_GPIOx(BLINK_PORT_NUMBER)->PDDR |= BLINK_PIN_MASK(BLINK_PIN_NUMBER);

  // Start with led turned off
  turnOff();
}
Beispiel #4
0
Gpio::Gpio(GpioDesc_t gpioDesc)
{
    if ((gpioDesc.pin == gpioPinUndef) || (gpioDesc.port == gpioPortUndef))
    {
        valid = false;
        return;
    }

    valid = true;
    pull = gpioDesc.pull;
    mode = gpioDesc.mode;
    fPortNumber = gpioDesc.port;
    fBitNumber = gpioDesc.pin;
    fIsActiveLow = gpioDesc.activeLow;
    fBitMask = BLINK_PIN_MASK(fBitNumber);
}
Beispiel #5
0
void
Gpio::turnOff ()
{
    if (false == valid)
    {
        return;
    }

    if (fIsActiveLow)
    {
      BLINK_GPIOx(fPortNumber)->BSRR = fBitMask;
    }
  else
    {
      BLINK_GPIOx(fPortNumber)->BSRR = BLINK_PIN_MASK(fBitNumber + 16);
    }
}
Beispiel #6
0
void led_init()
{
  // Enable GPIO Peripheral clock
  RCC->AHB1ENR |= BLINK_RCC_MASKx(BLINK_PORT_NUMBER);

  GPIO_InitTypeDef GPIO_InitStructure;

  // Configure pin in output push/pull mode
  GPIO_InitStructure.Pin = BLINK_PIN_MASK(BLINK_PIN_NUMBER);
  GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
  GPIO_InitStructure.Speed = GPIO_SPEED_FAST;
  GPIO_InitStructure.Pull = GPIO_PULLUP;
  HAL_GPIO_Init(BLINK_GPIOx(BLINK_PORT_NUMBER), &GPIO_InitStructure);

  // Start with led turned off
  led_on();
}
Beispiel #7
0
blink_led_off(void)
{
  HAL_GPIO_WritePin(BLINK_GPIOx(BLINK_PORT_NUMBER),
    BLINK_PIN_MASK(BLINK_PIN_NUMBER), GPIO_PIN_RESET);
}