当前位置: 首页>>代码示例>>C++>>正文


C++ pin_mode函数代码示例

本文整理汇总了C++中pin_mode函数的典型用法代码示例。如果您正苦于以下问题:C++ pin_mode函数的具体用法?C++ pin_mode怎么用?C++ pin_mode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了pin_mode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: serial_init

void serial_init(serial_t *obj, PinName tx, PinName rx) {
    int is_stdio_uart = 0;
    
    // determine the UART to use
    UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
    UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);
    UARTName uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
    if ((int)uart == NC) {
        error("Serial pinout mapping failed");
    }
    
    obj->uart = (LPC_UART_TypeDef *)uart;
    // enable power
    switch (uart) {
        case UART_0: LPC_SC->PCONP |= 1 <<  3; break;
        case UART_1: LPC_SC->PCONP |= 1 <<  4; break;
        case UART_2: LPC_SC->PCONP |= 1 << 24; break;
        case UART_3: LPC_SC->PCONP |= 1 << 25; break;
    }
    
    // enable fifos and default rx trigger level
    obj->uart->FCR = 1 << 0  // FIFO Enable - 0 = Disables, 1 = Enabled
                   | 0 << 1  // Rx Fifo Reset
                   | 0 << 2  // Tx Fifo Reset
                   | 0 << 6; // Rx irq trigger level - 0 = 1 char, 1 = 4 chars, 2 = 8 chars, 3 = 14 chars

    // disable irqs
    obj->uart->IER = 0 << 0  // Rx Data available irq enable
                   | 0 << 1  // Tx Fifo empty irq enable
                   | 0 << 2; // Rx Line Status irq enable
    
    // set default baud rate and format
    serial_baud  (obj, 9600);
    serial_format(obj, 8, ParityNone, 1);
    
    // pinout the chosen uart
    pinmap_pinout(tx, PinMap_UART_TX);
    pinmap_pinout(rx, PinMap_UART_RX);
    
    // set rx/tx pins in PullUp mode
    pin_mode(tx, PullUp);
    pin_mode(rx, PullUp);
    
    switch (uart) {
        case UART_0: obj->index = 0; break;
        case UART_1: obj->index = 1; break;
        case UART_2: obj->index = 2; break;
        case UART_3: obj->index = 3; break;
    }
    uart_data[obj->index].sw_rts.pin = NC;
    uart_data[obj->index].sw_cts.pin = NC;
    serial_set_flow_control(obj, FlowControlNone, NC, NC);
    
    is_stdio_uart = (uart == STDIO_UART) ? (1) : (0);
    
    if (is_stdio_uart) {
        stdio_uart_inited = 1;
        memcpy(&stdio_uart, obj, sizeof(serial_t));
    }
}
开发者ID:jbkim,项目名称:mbed,代码行数:60,代码来源:serial_api.c

示例2: serial_init

void serial_init(serial_t *obj, PinName tx, PinName rx)
{
    uint32_t uart_tx = pinmap_peripheral(tx, PinMap_UART_TX);
    uint32_t uart_rx = pinmap_peripheral(rx, PinMap_UART_RX);
    obj->index = pinmap_merge(uart_tx, uart_rx);
    MBED_ASSERT((int)obj->index != NC);

    serial_setup_clock();

    lpuart_config_t config;
    LPUART_GetDefaultConfig(&config);
    config.baudRate_Bps = 9600;
    config.enableTx = false;
    config.enableRx = false;

    LPUART_Init(uart_addrs[obj->index], &config, serial_get_clock());

    pinmap_pinout(tx, PinMap_UART_TX);
    pinmap_pinout(rx, PinMap_UART_RX);

    if (tx != NC) {
        LPUART_EnableTx(uart_addrs[obj->index], true);
        pin_mode(tx, PullDefault);
    }
    if (rx != NC) {
        LPUART_EnableRx(uart_addrs[obj->index], true);
        pin_mode(rx, PullDefault);
    }

    if (obj->index == STDIO_UART) {
        stdio_uart_inited = 1;
        memcpy(&stdio_uart, obj, sizeof(serial_t));
    }
}
开发者ID:pan-,项目名称:mbed,代码行数:34,代码来源:serial_api.c

示例3: i2c_init

void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
    // determine the SPI to use
    I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
    I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
    obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
    MBED_ASSERT((int)obj->i2c != NC);
    
    // enable power
    i2c_power_enable(obj);
    
    // set default frequency at 100k
    i2c_frequency(obj, 100000);
    i2c_conclr(obj, 1, 1, 1, 1);
    i2c_interface_enable(obj);
    
    pinmap_pinout(sda, PinMap_I2C_SDA);
    pinmap_pinout(scl, PinMap_I2C_SCL);

    // OpenDrain must explicitly be enabled for p0.0 and p0.1
    if (sda == P0_0) {
        pin_mode(sda, OpenDrain);
    }
    if (scl == P0_1) {
        pin_mode(scl, OpenDrain);
    }

}
开发者ID:AlessandroA,项目名称:mbed,代码行数:27,代码来源:i2c_api.c

示例4: i2c_init

void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
    // Determine the I2C to use
    I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
    I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);

    obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);
    MBED_ASSERT(obj->i2c != (I2CName)NC);

    // Enable I2C clock
    if (obj->i2c == I2C_1) {
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
        RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK);
    }
    if (obj->i2c == I2C_2) {
        RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
    }

    // Configure I2C pins
    pinmap_pinout(scl, PinMap_I2C_SCL);
    pin_mode(scl, OpenDrain);
    pinmap_pinout(sda, PinMap_I2C_SDA);
    pin_mode(sda, OpenDrain);

    // Reset to clear pending flags if any
    i2c_reset(obj);

    // I2C configuration
    i2c_frequency(obj, 100000); // 100 kHz per default
}
开发者ID:23chrischen,项目名称:mbed,代码行数:29,代码来源:i2c_api.c

示例5: i2c_init

void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
    // determine the SPI to use
    I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
    I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);
    obj->i2c = (I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl);
    MBED_ASSERT((int)obj->i2c != NC);

    // enable power
    i2c_power_enable(obj);

    pinmap_pinout(sda, PinMap_I2C_SDA);
    pinmap_pinout(scl, PinMap_I2C_SCL);

    pin_mode(sda, OpenDrain);
    pin_mode(scl, OpenDrain);

    // Force reset if the bus is stuck in the BUSY state
    if (obj->i2c->SR2 & I2C_SR2_BUSY) {
        obj->i2c->CR1 |= I2C_CR1_SWRST;
        obj->i2c->CR1 &= ~I2C_CR1_SWRST;
    }

    // Set the peripheral clock frequency
    obj->i2c->CR2 |= 42;

    // set default frequency at 100k
    i2c_frequency(obj, 100000);
    i2c_interface_enable(obj);
}
开发者ID:1deus,项目名称:tmk_keyboard,代码行数:29,代码来源:i2c_api.c

示例6: serial_set_flow_control

void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
{

    if (type == FlowControlRTSCTS || type == FlowControlRTS) {
        NRF_GPIO->DIR |= (1<<rxflow);
        pin_mode(rxflow, PullUp);
        obj->uart->PSELRTS = rxflow;

        obj->uart->CONFIG |= 0x01; // Enable HWFC
    }

    if (type == FlowControlRTSCTS || type == FlowControlCTS) {
        NRF_GPIO->DIR &= ~(1<<txflow);
        pin_mode(txflow, PullUp);
        obj->uart->PSELCTS = txflow;

        obj->uart->CONFIG |= 0x01; // Enable HWFC;
    }

    if (type == FlowControlNone) {
        obj->uart->PSELRTS = 0xFFFFFFFF; // Disable RTS
        obj->uart->PSELCTS = 0xFFFFFFFF; // Disable CTS

        obj->uart->CONFIG &= ~0x01; // Enable HWFC;
    }
}
开发者ID:AlessandroA,项目名称:mbed-hal-nrf51822-mcu,代码行数:26,代码来源:serial_api.c

示例7: i2c_init

void i2c_init(i2c_t *obj, PinName sda, PinName scl) {
    // Determine the I2C to use
    I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA);
    I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL);

    obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl);

    if (obj->i2c == (I2CName)NC) {
        error("I2C error: pinout mapping failed.");
    }

    // Enable I2C clock
    if (obj->i2c == I2C_1) {
        __HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK);
        __I2C1_CLK_ENABLE();
    }
    if (obj->i2c == I2C_2) {
        __I2C2_CLK_ENABLE();
    }

    // Configure I2C pins
    pinmap_pinout(sda, PinMap_I2C_SDA);
    pinmap_pinout(scl, PinMap_I2C_SCL);
    pin_mode(sda, OpenDrain);
    pin_mode(scl, OpenDrain);

    // Reset to clear pending flags if any
    i2c_reset(obj);

    // I2C configuration
    i2c_frequency(obj, 100000); // 100 kHz per default
}
开发者ID:GvoOjeda,项目名称:mbed,代码行数:32,代码来源:i2c_api.c

示例8: gpio_pin_enable

void gpio_pin_enable(gpio_t *obj, uint8_t enable)
{
    if (enable) {
        pin_mode(obj->pin, obj->mode);
    } else {
        pin_mode(obj->pin, Disabled); // TODO_LP return mode to default value
    }
}
开发者ID:chrta,项目名称:mbed,代码行数:8,代码来源:gpio_api.c

示例9: spiflash_pins_init

void
spiflash_pins_init(void)
{
        pin_mode(PIN_PTC0, PIN_MODE_MUX_ALT2);
        pin_mode(PIN_PTC5, PIN_MODE_MUX_ALT2);
        pin_mode(PIN_PTC6, PIN_MODE_MUX_ALT2);
        pin_mode(PIN_PTC7, PIN_MODE_MUX_ALT2);
}
开发者ID:biznixcn,项目名称:mchck,代码行数:8,代码来源:spiflash.c

示例10: can_init

void can_init(can_t *obj, PinName rd, PinName td)
{
    CANName can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD);
    CANName can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD);

    obj->can = (CANName)pinmap_merge(can_rd, can_td);
    MBED_ASSERT((int)obj->can != NC);

    if (obj->can == CAN_1) {
        __HAL_RCC_CAN1_CLK_ENABLE();
        obj->index = 0;
    }
#if defined(CAN2_BASE) && (CAN_NUM == 2)
    else if (obj->can == CAN_2) {
        __HAL_RCC_CAN1_CLK_ENABLE(); // needed to set filters
        __HAL_RCC_CAN2_CLK_ENABLE();
        obj->index = 1;
    }
#endif
    else {
        return;
    }

    // Configure the CAN pins
    pinmap_pinout(rd, PinMap_CAN_RD);
    pinmap_pinout(td, PinMap_CAN_TD);
    if (rd != NC) {
        pin_mode(rd, PullUp);
    }
    if (td != NC) {
        pin_mode(td, PullUp);
    }

    CanHandle.Instance = (CAN_TypeDef *)(obj->can);

    CanHandle.Init.TTCM = DISABLE;
    CanHandle.Init.ABOM = DISABLE;
    CanHandle.Init.AWUM = DISABLE;
    CanHandle.Init.NART = DISABLE;
    CanHandle.Init.RFLM = DISABLE;
    CanHandle.Init.TXFP = DISABLE;
    CanHandle.Init.Mode = CAN_MODE_NORMAL;
    CanHandle.Init.SJW = CAN_SJW_1TQ;
    CanHandle.Init.BS1 = CAN_BS1_6TQ;
    CanHandle.Init.BS2 = CAN_BS2_8TQ;
    CanHandle.Init.Prescaler = 2;

    if (HAL_CAN_Init(&CanHandle) != HAL_OK) {
        error("Cannot initialize CAN");
    }

    // Set initial CAN frequency to 100 kb/s
    can_frequency(obj, 100000);

    uint32_t filter_number = (obj->can == CAN_1) ? 0 : 14;
    can_filter(obj, 0, 0, CANStandard, filter_number);
}
开发者ID:akselsm,项目名称:mbed,代码行数:57,代码来源:can_api.c

示例11: serial_init

void serial_init(serial_t *obj, PinName tx, PinName rx)
{
    // Determine the UART to use (UART_1, UART_2, ...)
    UARTName uart_tx = (UARTName)pinmap_peripheral(tx, PinMap_UART_TX);
    UARTName uart_rx = (UARTName)pinmap_peripheral(rx, PinMap_UART_RX);

    // Get the peripheral name (UART_1, UART_2, ...) from the pin and assign it to the object
    obj->uart = (UARTName)pinmap_merge(uart_tx, uart_rx);
    MBED_ASSERT(obj->uart != (UARTName)NC);

    // Enable UART clock
    if (obj->uart == UART_1) {
    	__USART1_FORCE_RESET();
    	__USART1_RELEASE_RESET();
        __HAL_RCC_USART1_CLK_ENABLE();
        obj->index = 0;
    }
    if (obj->uart == UART_2) {
    	__USART2_FORCE_RESET();
    	__USART2_RELEASE_RESET();
        __HAL_RCC_USART2_CLK_ENABLE();
        obj->index = 1;
    }
    if (obj->uart == UART_3) {
    	__USART3_FORCE_RESET();
    	__USART3_RELEASE_RESET();
        __HAL_RCC_USART3_CLK_ENABLE();
        obj->index = 2;
    }

    // Configure UART pins
    pinmap_pinout(tx, PinMap_UART_TX);
    pinmap_pinout(rx, PinMap_UART_RX);
    if (tx != NC) {
        pin_mode(tx, PullUp);
    }
    if (rx != NC) {
        pin_mode(rx, PullUp);
    }

    // Configure UART
    obj->baudrate = 9600;
    obj->databits = UART_WORDLENGTH_8B;
    obj->stopbits = UART_STOPBITS_1;
    obj->parity   = UART_PARITY_NONE;

    obj->pin_tx = tx;
    obj->pin_rx = rx;

    init_uart(obj);

    // For stdio management
    if (obj->uart == STDIO_UART) {
        stdio_uart_inited = 1;
        memcpy(&stdio_uart, obj, sizeof(serial_t));
    }
}
开发者ID:Neuromancer2701,项目名称:mbedROS2_STF7,代码行数:57,代码来源:serial_api.c

示例12: pwmout_enable_pins

void pwmout_enable_pins(pwmout_t *obj, uint8_t enable)
{
    if (enable) {
        pin_mode(obj->pin, PushPull);
    } else {
        // TODO_LP return PinMode to the previous state
        pin_mode(obj->pin, Disabled);
    }
}
开发者ID:ARMmbed,项目名称:mbed-hal-silabs,代码行数:9,代码来源:pwmout_api.c

示例13: disable_power

static void
disable_power(void)
{
        pin_mode(EZPORT_CS, PIN_MODE_MUX_ANALOG);
        pin_mode(EZPORT_CLK, PIN_MODE_MUX_ANALOG);
        pin_mode(EZPORT_DI, PIN_MODE_MUX_ANALOG);
        pin_mode(EZPORT_DO, PIN_MODE_MUX_ANALOG);
        pin_mode(EZPORT_POWER, PIN_MODE_MUX_ANALOG);
}
开发者ID:deanrock,项目名称:mchck,代码行数:9,代码来源:ez-port-flash.c

示例14: NVIC_DisableIRQ

USBHAL::USBHAL(void) {
    NVIC_DisableIRQ(OTG_FS_IRQn);
    epCallback[0] = &USBHAL::EP1_OUT_callback;
    epCallback[1] = &USBHAL::EP1_IN_callback;
    epCallback[2] = &USBHAL::EP2_OUT_callback;
    epCallback[3] = &USBHAL::EP2_IN_callback;
    epCallback[4] = &USBHAL::EP3_OUT_callback;
    epCallback[5] = &USBHAL::EP3_IN_callback;

    // Enable power and clocking
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN;

#if defined(TARGET_STM32F407VG) || defined(TARGET_STM32F401RE) || defined(TARGET_STM32F411RE) || defined(TARGET_STM32F412ZG) || defined(TARGET_STM32F429ZI)
    pin_function(PA_8, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
    pin_function(PA_9, STM_PIN_DATA(STM_MODE_INPUT, GPIO_PULLDOWN, GPIO_AF10_OTG_FS));
    pin_function(PA_10, STM_PIN_DATA(STM_MODE_AF_OD, GPIO_PULLUP, GPIO_AF10_OTG_FS));
    pin_function(PA_11, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
    pin_function(PA_12, STM_PIN_DATA(STM_MODE_AF_PP, GPIO_NOPULL, GPIO_AF10_OTG_FS));
#else
    pin_function(PA_8, STM_PIN_DATA(2, 10));
    pin_function(PA_9, STM_PIN_DATA(0, 0));
    pin_function(PA_10, STM_PIN_DATA(2, 10));
    pin_function(PA_11, STM_PIN_DATA(2, 10));
    pin_function(PA_12, STM_PIN_DATA(2, 10));

    // Set ID pin to open drain with pull-up resistor
    pin_mode(PA_10, OpenDrain);
    GPIOA->PUPDR &= ~(0x3 << 20);
    GPIOA->PUPDR |= 1 << 20;

    // Set VBUS pin to open drain
    pin_mode(PA_9, OpenDrain);
#endif

    RCC->AHB2ENR |= RCC_AHB2ENR_OTGFSEN;

    // Enable interrupts
    OTG_FS->GREGS.GAHBCFG |= (1 << 0);

    // Turnaround time to maximum value - too small causes packet loss
    OTG_FS->GREGS.GUSBCFG |= (0xF << 10);

    // Unmask global interrupts
    OTG_FS->GREGS.GINTMSK |= (1 << 3) | // SOF
                             (1 << 4) | // RX FIFO not empty
                             (1 << 12); // USB reset

    OTG_FS->DREGS.DCFG |= (0x3 << 0) | // Full speed
                          (1 << 2); // Non-zero-length status OUT handshake

    OTG_FS->GREGS.GCCFG |= (1 << 19) | // Enable VBUS sensing
                           (1 << 16); // Power Up

    instance = this;
    NVIC_SetVector(OTG_FS_IRQn, (uint32_t)&_usbisr);
    NVIC_SetPriority(OTG_FS_IRQn, 1);
}
开发者ID:Archcady,项目名称:mbed-os,代码行数:57,代码来源:USBHAL_STM32F4.cpp

示例15: enable_spi

static void
enable_spi(void)
{
        spi_init();
        pin_mode(EZPORT_CS, PIN_MODE_MUX_ALT2);
        pin_mode(EZPORT_CLK, PIN_MODE_MUX_ALT2);
        pin_mode(EZPORT_DI, PIN_MODE_MUX_ALT2);
        pin_mode(EZPORT_DO, PIN_MODE_MUX_ALT2);
}
开发者ID:deanrock,项目名称:mchck,代码行数:9,代码来源:ez-port-flash.c


注:本文中的pin_mode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。