void initGPIO() { CMU_ClockEnable(cmuClock_GPIO, true); // enable GPIO peripheral clock GPIO_PinModeSet(GPS_PORT, FIX, gpioModeInput, 0); // set FIX pin as input (no filter) GPIO_PinModeSet(GPS_PORT, ENABLE, gpioModePushPull, 0); // set ENABLE pin as output, initialize low GPIO_PinModeSet(LED_PORT, LED0_PIN, gpioModePushPull, 0); // configure LED0 pin as push-pull output with standard drive strength GPIO_PinModeSet(LED_PORT, LED1_PIN, gpioModePushPull, 0); // configure LED1 pin as push-pull output with alternate drive strength GPIO_PinModeSet(EXT_LED, RED_LED, gpioModePushPull, 0); // configure LED1 pin as push-pull output with alternate drive strength GPIO_PinModeSet(EXT_LED, YEL_LED, gpioModePushPull, 0); // configure LED1 pin as push-pull output with alternate drive strength GPIO_PinModeSet(EXT_LED, GRE_LED, gpioModePushPull, 0); // configure LED1 pin as push-pull output with alternate drive strength GPIO_DriveModeSet(LED_PORT, gpioDriveModeLowest); // set alternate drive strength to lowest setting (0.5mA) GPIO_PinOutClear(LED_PORT, LED0_PIN); // turn on LED0 GPIO_PinOutSet(LED_PORT, LED1_PIN); // turn on LED1 GPIO_PinOutClear(EXT_LED, RED_LED); GPIO_PinOutClear(EXT_LED, YEL_LED); // turn on LED1 GPIO_PinOutClear(EXT_LED, GRE_LED); GPIO_PinModeSet(BUT_PORT, LEFT_BUT, gpioModeInputPull, 1); //configure left button as input with pull-up enabled GPIO_PinModeSet(BUT_PORT, RIGHT_BUT, gpioModeInputPull, 1); //'' but with right button NVIC_EnableIRQ(GPIO_ODD_IRQn); //enable gpio_even interrupt vector in nvic GPIO_IntConfig(GPS_PORT, FIX, true, false, true); //configure FIX pin interrupt on rising }
/***************************************************************************//** * @brief * Set the mode for a GPIO pin. * * @param[in] port * The GPIO port to access. * * @param[in] pin * The pin number in the port. * * @param[in] mode * The desired pin mode. * * @param[in] out * Value to set for pin in DOUT register. The DOUT setting is important for * even some input mode configurations, determining pull-up/down direction. ******************************************************************************/ void GPIO_PinModeSet(GPIO_Port_TypeDef port, unsigned int pin, GPIO_Mode_TypeDef mode, unsigned int out) { EFM_ASSERT(GPIO_PORT_PIN_VALID(port, pin)); /* If disabling pin, do not modify DOUT in order to reduce chance for */ /* glitch/spike (may not be sufficient precaution in all use cases) */ if (mode != gpioModeDisabled) { if (out) { GPIO_PinOutSet(port, pin); } else { GPIO_PinOutClear(port, pin); } } /* There are two registers controlling the pins for each port. The MODEL * register controls pins 0-7 and MODEH controls pins 8-15. */ if (pin < 8) { BUS_RegMaskedWrite(&GPIO->P[port].MODEL, 0xF << (pin * 4), mode << (pin * 4)); } else { BUS_RegMaskedWrite(&GPIO->P[port].MODEH, 0xF << ((pin - 8) * 4), mode << ((pin - 8) * 4)); } if (mode == gpioModeDisabled) { if (out) { GPIO_PinOutSet(port, pin); } else { GPIO_PinOutClear(port, pin); } } }
/* BSP functions ===========================================================*/ void BSP_init(void) { /* NOTE: SystemInit() already called from the startup code * but SystemCoreClock needs to be updated */ SystemCoreClockUpdate(); /* configure the FPU usage by choosing one of the options... */ #if 1 /* OPTION 1: * Use the automatic FPU state preservation and the FPU lazy stacking. * * NOTE: * Use the following setting when FPU is used in more than one task or * in any ISRs. This setting is the safest and recommended, but requires * extra stack space and CPU cycles. */ FPU->FPCCR |= (1U << FPU_FPCCR_ASPEN_Pos) | (1U << FPU_FPCCR_LSPEN_Pos); #else /* OPTION 2: * Do NOT to use the automatic FPU state preservation and * do NOT to use the FPU lazy stacking. * * NOTE: * Use the following setting when FPU is used in ONE task only and not * in any ISR. This setting is very efficient, but if more than one task * (or ISR) start using the FPU, this can lead to corruption of the * FPU registers. This option should be used with CAUTION. */ FPU->FPCCR &= ~((1U << FPU_FPCCR_ASPEN_Pos) | (1U << FPU_FPCCR_LSPEN_Pos)); #endif /* enable clock for to the peripherals used by this application... */ CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(cmuClock_GPIO, true); CMU_ClockEnable(cmuClock_HFPER, true); CMU_ClockEnable(cmuClock_GPIO, true); /* configure the LEDs */ GPIO_PinModeSet(LED_PORT, LED0_PIN, gpioModePushPull, 0); GPIO_PinModeSet(LED_PORT, LED1_PIN, gpioModePushPull, 0); GPIO_PinOutClear(LED_PORT, LED0_PIN); GPIO_PinOutClear(LED_PORT, LED1_PIN); /* configure the Buttons */ GPIO_PinModeSet(PB_PORT, PB0_PIN, gpioModeInputPull, 1); GPIO_PinModeSet(PB_PORT, PB1_PIN, gpioModeInputPull, 1); }
/**************************************************************************//** * @brief Main function * Main is called from __iar_program_start, see assembly startup file *****************************************************************************/ int main(void) { /* Initialize chip */ CHIP_Init(); /* Enable clock for GPIO module */ CMU_ClockEnable(cmuClock_GPIO, true); /* Configure PD with alternate drive strength of 20mA */ GPIO_DriveModeSet(gpioPortD, gpioDriveModeHigh); /* Configure PC12 as input with filter*/ GPIO_PinModeSet(gpioPortC, 12, gpioModeInput, 0); /* Configure PD8 as push pull output */ GPIO_PinModeSet(gpioPortD, 8, gpioModePushPullDrive, 0); while(1) { /* If PC12 is high, drive high PD8, else drive low */ if(GPIO_PinInGet(gpioPortC, 12)) GPIO_PinOutSet(gpioPortD, 8); /* Drive high PD8 */ else GPIO_PinOutClear(gpioPortD, 8); /* Drive low PD8 */ } }
/*============================================================================== hal_spiSlaveSel() =============================================================================*/ uint8_t hal_spiSlaveSel(void * p_spi, bool action) { s_hal_spiDrv* p_spiHal; if (p_spi == NULL) { LOG_ERR("SPI was not initialized!"); return 0; } p_spiHal = (s_hal_spiDrv*)p_spi; if (action) { //! [select_slave] /* clear chip select pin */ hal_enterCritical(); GPIO_PinOutClear( p_spiHal->csPin.port, p_spiHal->csPin.pin ); //! [select_slave] } else { /* set chip select pin */ GPIO_PinOutSet( p_spiHal->csPin.port, p_spiHal->csPin.pin ); hal_exitCritical(); } return 1; } /* hal_spiSlaveSel() */
/********************************************************** * COG power-up sequence. **********************************************************/ void cogPowerUp(void) { measureTemperature(); GPIO_PinOutSet(EPD_PIN_PANEL_VDD); delayMs(5); pwmEnable(); delayMs(5); GPIO_PinOutSet(EPD_PIN_PANEL_ON); delayMs(10); GPIO_PinOutSet(EPD_PIN_CS); GPIO_PinOutSet(EPD_PIN_BORDER); GPIO_PinOutSet(EPD_PIN_RESET); delayMs(5); GPIO_PinOutClear(EPD_PIN_RESET); delayMs(5); GPIO_PinOutSet(EPD_PIN_RESET); delayMs(5); }
__LINK_C error_t hw_gpio_clr(pin_id_t pin_id) { if(!(gpio_pins_configured[pin_id.port] & (1<<pin_id.pin))) return EOFF; GPIO_PinOutClear(pin_id.port, pin_id.pin); return SUCCESS; }
static uint16_t SpiBcAccess(uint8_t addr, uint8_t rw, uint16_t data) { uint16_t tmp; /* Enable CS */ GPIO_PinOutClear(BSP_PORT_SPI_CS, BSP_PIN_SPI_CS); /* Write SPI address MSB */ USART_Tx(BSP_SPI_USART_USED, (addr & 0x3) | rw << 3); /* Just ignore data read back */ USART_Rx(BSP_SPI_USART_USED); /* Write SPI address LSB */ USART_Tx(BSP_SPI_USART_USED, data & 0xFF); tmp = (uint16_t) USART_Rx(BSP_SPI_USART_USED); /* SPI data MSB */ USART_Tx(BSP_SPI_USART_USED, data >> 8); tmp |= (uint16_t) USART_Rx(BSP_SPI_USART_USED) << 8; /* Disable CS */ GPIO_PinOutSet(BSP_PORT_SPI_CS, BSP_PIN_SPI_CS); return tmp; }
void debug_led (u1_t val) { if (val) GPIO_PinOutSet(PORT_SPK, PIN_SPK); else GPIO_PinOutClear(PORT_SPK, PIN_SPK); }
static inline void set_analog_switch(analog_switch_t as, bool value) { if (value) GPIO_PinOutClear(analog_switches[as].port, analog_switches[as].pin); else GPIO_PinOutSet(analog_switches[as].port, analog_switches[as].pin); }
/***************************************************************************//** * @brief * RxTimer, Timer0 IRQHandler. ******************************************************************************/ void TIMER0_IRQHandler(void) { uint32_t irqFlags; irqFlags = TIMER_IntGet(HIJACK_RX_TIMER); TIMER_IntClear(HIJACK_RX_TIMER, irqFlags); if (TIMER_IF_CC0 & irqFlags) { cur_stamp = TIMER_CaptureGet(HIJACK_RX_TIMER, 0); /* Check what transition it was. */ if(ACMP0->STATUS & ACMP_STATUS_ACMPOUT) { cur_edge = rising; //BSP_LedSet( 0 ); GPIO_PinOutSet(gpioPortD, 5); //Debug_Print( "%d ", cur_stamp ) ; } else { cur_edge = falling; //BSP_LedClear( 0 ); GPIO_PinOutClear(gpioPortD, 5); //Debug_Print( "%d ", cur_stamp ) ; } decode_machine(); } }
/* * Access multiple registers */ uint8_t CC1101_Radio::multi_register_access( uint8_t address, uint8_t access_mode, uint8_t* data, uint8_t length ) { uint8_t reg; uint8_t status; uint8_t count; GPIO_PinOutClear( _CC1101_SPI_CS_PIN ); USART_Tx( _CC1101_USART, address | access_mode ); status = USART_Rx( _CC1101_USART ); for ( count = 0; count < length; count++ ) { if ( ( access_mode == CC1101_READ_SINGLE ) || ( access_mode == CC1101_READ_BURST ) ) { USART_Tx( _CC1101_USART, CC1101_SNOP ); reg = USART_Rx( _CC1101_USART ); data[count] = ( uint8_t )reg; } else { USART_Tx( _CC1101_USART, data[count] ); status = USART_Rx( _CC1101_USART ); } } GPIO_PinOutSet( _CC1101_SPI_CS_PIN ); return status; }
/***************************************************************************//** * @brief * Set a single pin in GPIO data out port register to 0. * * @note * In order for the setting to take effect on the output pad, the pin must * have been configured properly. If not, it will take effect whenever the * pin has been properly configured. * * @param[in] port * The GPIO port to access. * * @param[in] pin * The pin to set. ******************************************************************************/ EMSTATUS PAL_GpioPinOutClear(unsigned int port, unsigned int pin) { EMSTATUS status = PAL_EMSTATUS_OK; GPIO_PinOutClear((GPIO_Port_TypeDef) port, pin); return status; }
/********************************************************** * Performs a pin reset on the target **********************************************************/ void hardResetTarget(void) { GPIO_PinOutClear((GPIO_Port_TypeDef)RESET_PORT, RESET_PIN); delayMs(50); GPIO_PinOutSet((GPIO_Port_TypeDef)RESET_PORT, RESET_PIN); }
int BSP_LedClear(int ledNo) { if ((ledNo >= 0) && (ledNo < BSP_NO_OF_LEDS)) { GPIO_PinOutClear(ledArray[ledNo].port, ledArray[ledNo].pin); return BSP_STATUS_OK; } return BSP_STATUS_ILLEGAL_PARAM; }
void main(void) { fd_hal_processor_initialize(); fd_binary_unit_tests(); fd_detour_unit_tests(); fd_storage_unit_tests(); fd_storage_buffer_unit_tests(); storage_erase(); fd_sync_unit_tests(); if (fd_log_did_log) { GPIO_PinOutClear(LED5_PORT_PIN); GPIO_PinOutSet(LED6_PORT_PIN); } else { GPIO_PinOutSet(LED5_PORT_PIN); GPIO_PinOutClear(LED6_PORT_PIN); } }
void gpio_write(gpio_t pin, int value) { if (value) { GPIO_PinOutSet(_port_num(pin), _pin_num(pin)); } else { GPIO_PinOutClear(_port_num(pin), _pin_num(pin)); } }
/*============================================================================== hal_pinClr() =============================================================================*/ void hal_pinClr(void * p_pin) { s_hal_gpio_pin_t* p_gpioPin; if( p_pin != NULL ) { p_gpioPin = (s_hal_gpio_pin_t*)p_pin; p_gpioPin->val = 0; GPIO_PinOutClear( p_gpioPin->port, p_gpioPin->pin ); } } /* hal_pinClr() */
void TIMER3_IRQHandler(void) { uint32_t timer_if = TIMER_IntGet(TIMER3) & (TIMER_IF_CC1 | TIMER_IF_OF); TIMER_IntClear(TIMER3, TIMER_IF_CC1 | TIMER_IF_OF); if (timer_if & TIMER_IF_OF) { GPIO_PinOutSet(LED5_PORT_PIN); } else { GPIO_PinOutClear(LED5_PORT_PIN); } }
/********************************************************** * Performs AAP Window Expansion. This function will reset * target, send the AAP expansion sequence, initialize the * debug interface and verify that AAP can be accessed. * It will try several delays between reset is released * and reading the AAP in case the reset line has a slow * ramp-up. * * After this function completes the AAP registers are * available. If it fails to access the AAP, it will * throw an exception. * **********************************************************/ void performAapExpansion(void) { uint32_t dpId, apId; int i,j; bool success = false; for ( i=0; i<AAP_EXPANSION_RETRY_COUNT; i++ ) { /* Pull reset pin low */ GPIO_PinOutClear((GPIO_Port_TypeDef)RESET_PORT, RESET_PIN); SWCLK_CLR(); delayMs(50); /* Send the AAP Window expansion sequence */ aapExtensionSequence(); /* Release reset */ delayUs(10); GPIO_PinOutSet((GPIO_Port_TypeDef)RESET_PORT, RESET_PIN); /* Try different delays in case of slow reset ramp */ for ( j=0; j<i; j++ ) { delayUs(10); } /* Connect to SW-DP */ TRY dpId = initDp(); apId = readApId(); if ( verifyDpId(dpId) && apId == EFM32_AAP_ID ) { /* Success! AAP registers can now be accessed. * We cannot return in the middle of a TRY block. * Set flag here and return after ENDTRY */ success = true; } CATCH /* Do nothing in case of error. We retry. */ ENDTRY /* Return if we found the AAP registers*/ if ( success ) { printf("AAP registers found\n"); return; } } /* Failed to get access to AAP registers. Raise an error. */ RAISE(SWD_ERROR_AAP_EXTENSION_FAILED); }
void Spi_ClearNsel(eSpi_Nsel qiSelect) { switch (qiSelect) { case eSpi_Nsel_RF: GPIO_PinOutClear(SPI_CS_PORT, SPI_CS_PIN); break; default: break; } }
void fd_lp55231_power_off(void) { /* // !!! reset before power off, just in case we power back on before the voltage has dropped low enough for a power on reset -denis bool result = fd_i2c1_register_write(ADDRESS, RESET_REGISTER, RESET_VALUE); if (!result) { fd_log_assert_fail(""); } */ GPIO_PinOutClear(LED_EN_PORT_PIN); }
/* * Send a strobe command */ uint8_t CC1101_Radio::strobe( uint8_t l_strobe ) { uint8_t reg = 0; GPIO_PinOutClear( _CC1101_SPI_CS_PIN ); USART_Tx( _CC1101_USART, l_strobe ); // Write strobe command reg = USART_Rx( _CC1101_USART ); // Read reply GPIO_PinOutSet( _CC1101_SPI_CS_PIN ); return reg; }
void motor_stop(void *ptr) { TIMER_CompareBufSet(TIMER2, 0, 0); GPIO_PinOutClear(gpioPortA, 8); light_state &= ~MOTOR_ON; if(light_state == 0) { TIMER_Enable(TIMER2,false); CMU_ClockEnable(cmuClock_TIMER2, false); } }
/***************************************************************************//** * @brief * SPI transfer function * * @details * Performs one SPI transaction. Fundamentally SPI does a write and read of the * same length (byte count) at the same time. Often only a few bytes are to be * written, and the data returned while those bytes are written is to be * discarded. This can be done using the "half_duplex" flag. The data to be * written may optionally be split into two separate buffers in order to handle * discontiguous data. Set tx_len or tx_len2 to 0 if the corresponding buffer * is not used. Will block if NULL passed for completion function; otherwise * will call completion function passing ref argument. Note that completion * function may be called either before or after the function returns. * * @param[in] tx_len * Number of bytes to transfer from tx buffer * @param[in] *tx_data * Pointer to data to be transferred/TX'd * @param[in] tx2_len * Number of bytes to transfer from tx2 buffer * @param[in] *tx2_data * Pointer to data to be transferred from tx2 buffer. * @param[in] hold_cs_active * TRUE/FALSE, Determines whether to hold CS active * @param[in] *completion * Completion state machine callback function * @param[in] *completion_ref * Argument to be passed to completion callback * ******************************************************************************/ void spi_xfer(size_t tx_len, const uint8_t *tx_data, size_t tx2_len, const uint8_t *tx2_data, bool half_duplex, size_t rx_len, uint8_t *rx_data, bool hold_cs_active, spi_completion_fn_t *completion, void *completion_ref) { spi_rx_len = rx_len; spi_rx_data = rx_data; spi_tx_len = tx_len; spi_tx_data = tx_data; spi_tx2_len = tx2_len; spi_tx2_data = tx2_data; spi_tx_post_padding_len = 0; spi_rx_pre_padding_len = 0; spi_rx_post_padding_len = 0; spi_hold_cs_active = hold_cs_active; if (half_duplex) { spi_rx_pre_padding_len = tx_len + tx2_len; spi_tx_post_padding_len = spi_rx_len; } else if ((tx_len + tx2_len) < rx_len) spi_tx_post_padding_len = rx_len - (tx_len + tx2_len); else spi_rx_post_padding_len = (tx_len + tx2_len) - rx_len; //printf("tx: %d, tx2: %d, tx_post: %d\r\n", tx_len, tx2_len, spi_tx_post_padding_len); //printf("rx_pre: %d, rx: %d, rx_post: %d\r\n", spi_rx_pre_padding_len, rx_len, spi_rx_post_padding_len); spi_completion = completion; spi_completion_ref = completion_ref; spi_busy = true; GPIO_PinOutClear(CS_PORT, CS_PIN); // assert CS // enable interrupts to start transfer SPI_PORT->IEN |= (USART_IEN_TXBL | USART_IEN_RXDATAV); if (! completion) while (spi_busy) EMU_EnterEM1(); }
int BSP_LedsSet(uint32_t leds) { int i; uint32_t mask; for ( i=0, mask=0x1; i<BSP_NO_OF_LEDS; i++, mask <<= 1 ) { if ( leds & mask ) GPIO_PinOutSet(ledArray[i].port, ledArray[i].pin); else GPIO_PinOutClear(ledArray[i].port, ledArray[i].pin); } return BSP_STATUS_OK; }
void qk_gpio_set_pin(qk_gpio_pin pin, bool state) { if(state) { GPIO_PinOutSet((GPIO_Port_TypeDef) _QK_GPIO_PORT(pin), (unsigned int) _QK_GPIO_BIT(pin)); } else { GPIO_PinOutClear((GPIO_Port_TypeDef) _QK_GPIO_PORT(pin), (unsigned int) _QK_GPIO_BIT(pin)); } }
/* * SPI register access */ uint8_t CC1101_Radio::register_access_SPI( uint8_t address, uint8_t access_mode, uint8_t data ) { uint8_t reg = 0; GPIO_PinOutClear( _CC1101_SPI_CS_PIN ); USART_Tx( _CC1101_USART, address | access_mode ); // write the address byte USART_Rx( _CC1101_USART ); // read reply USART_Tx( _CC1101_USART, data ); // write the data byte(s) reg = USART_Rx( _CC1101_USART ); // read and save the reply GPIO_PinOutSet( _CC1101_SPI_CS_PIN ); return reg; }
/***************************************************************************//** * @brief * Set/Clear chip select * * @details * * @note * * @param[in] enable * Chip select pin setting ******************************************************************************/ static void efm32_spiLcd_cs(rt_uint8_t enable) { if (!lcdAutoCs) { if (enable) { GPIO_PinOutClear(LCD_CS_PORT, LCD_CS_PIN); } else { GPIO_PinOutSet(LCD_CS_PORT, LCD_CS_PIN); } } }
/***************************************************************************//** * @brief * Parser AT extension function for user. * * @param[in] token * The token to parse. * * @return * The parse result. ******************************************************************************/ static int8_t user_parse(uint8_t token) { int8_t result = AT_OK; int value; switch (token) { case AT_USER_LED: if (AT_argc == 1) { value = AT_atoll(AT_argv[0]); if (value == 1) { // Turn on the LED GPIO_PinOutSet(LED_PORT, LED_BIT); } else if (value == 0) { // Turn off the LED GPIO_PinOutClear(LED_PORT, LED_BIT); } else { result = AT_ERROR; } } else { result = AT_ERROR; } break; case AT_USER_TEMPERATURE: if (AT_argc == 0) { value = TD_MEASURE_TemperatureExtended(); AT_printf("%d.%d\r\n", value / 10, value % 10); } else { result = AT_ERROR; } break; case AT_USER_VOLTAGE: if (AT_argc == 0) { value = TD_MEASURE_VoltageExtended(); AT_printf("%d.%03d\r\n", value / 1000, value % 1000); } else { result = AT_ERROR; } break; default: result = AT_NOTHING; break; } return result; }