本文整理汇总了C++中device_get_binding函数的典型用法代码示例。如果您正苦于以下问题:C++ device_get_binding函数的具体用法?C++ device_get_binding怎么用?C++ device_get_binding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了device_get_binding函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: __uart_stm32_get_clock
static inline void __uart_stm32_get_clock(struct device *dev)
{
struct uart_stm32_data *data = DEV_DATA(dev);
struct device *clk =
device_get_binding(STM32_CLOCK_CONTROL_NAME);
__ASSERT_NO_MSG(clk);
data->clock = clk;
}
示例2: cmd_test
static int cmd_test(const struct shell *shell, size_t argc, char *argv[])
{
struct device *flash_dev;
u32_t repeat;
int result;
u32_t addr;
u32_t size;
flash_dev = device_get_binding(FLASH_DEV_NAME);
if (!flash_dev) {
error(shell, "Flash driver was not found!");
return -ENODEV;
}
if (argc != 4) {
error(shell, "3 parameters reqired.");
return -EINVAL;
}
addr = strtoul(argv[1], NULL, 16);
size = strtoul(argv[2], NULL, 16);
repeat = strtoul(argv[3], NULL, 16);
if (size > TEST_ARR_SIZE) {
error(shell, "<size> must be at most 0x%x.", TEST_ARR_SIZE);
return -EINVAL;
}
flash_write_protection_set(flash_dev, 0);
for (u32_t i = 0; i < size; i++) {
test_arr[i] = (u8_t)i;
}
while (repeat--) {
result = flash_erase(flash_dev, addr, size);
if (result) {
error(shell, "Erase Failed, code %d.", result);
return -EIO;
}
print(shell, "Erase OK.");
if (flash_write(flash_dev, addr, test_arr, size) != 0) {
error(shell, "Write internal ERROR!");
return -EIO;
}
print(shell, "Write OK.");
}
print(shell, "Erase-Write test done.");
return 0;
}
示例3: uart_nrf5_init
/**
* @brief Initialize UART channel
*
* This routine is called to reset the chip in a quiescent state.
* It is assumed that this function is called only once per UART.
*
* @param dev UART device struct
*
* @return 0 on success
*/
static int uart_nrf5_init(struct device *dev)
{
volatile struct _uart *uart = UART_STRUCT(dev);
struct device *gpio_dev;
gpio_dev = device_get_binding(CONFIG_GPIO_NRF5_P0_DEV_NAME);
(void) gpio_pin_configure(gpio_dev,
CONFIG_UART_NRF5_GPIO_TX_PIN,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
CONFIG_UART_NRF5_GPIO_RX_PIN,
(GPIO_DIR_IN));
uart->PSELTXD = CONFIG_UART_NRF5_GPIO_TX_PIN;
uart->PSELRXD = CONFIG_UART_NRF5_GPIO_RX_PIN;
#ifdef CONFIG_UART_NRF5_FLOW_CONTROL
(void) gpio_pin_configure(gpio_dev,
CONFIG_UART_NRF5_GPIO_RTS_PIN,
(GPIO_DIR_OUT | GPIO_PUD_PULL_UP));
(void) gpio_pin_configure(gpio_dev,
CONFIG_UART_NRF5_GPIO_CTS_PIN,
(GPIO_DIR_IN));
uart->PSELRTS = CONFIG_UART_NRF5_GPIO_RTS_PIN;
uart->PSELCTS = CONFIG_UART_NRF5_GPIO_CTS_PIN;
uart->CONFIG = (UART_CONFIG_HWFC_Enabled << UART_CONFIG_HWFC_Pos);
#endif /* CONFIG_UART_NRF5_FLOW_CONTROL */
DEV_DATA(dev)->baud_rate = CONFIG_UART_NRF5_BAUD_RATE;
DEV_CFG(dev)->sys_clk_freq = CONFIG_UART_NRF5_CLK_FREQ;
/* Set baud rate */
baudrate_set(dev, DEV_DATA(dev)->baud_rate,
DEV_CFG(dev)->sys_clk_freq);
/* Enable receiver and transmitter */
uart->ENABLE = (UART_ENABLE_ENABLE_Enabled << UART_ENABLE_ENABLE_Pos);
uart->EVENTS_TXDRDY = 0;
uart->EVENTS_RXDRDY = 0;
uart->TASKS_STARTTX = 1;
uart->TASKS_STARTRX = 1;
dev->driver_api = &uart_nrf5_driver_api;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
DEV_CFG(dev)->irq_config_func(dev);
#endif
return 0;
}
示例4: lis2dw12_init_interrupt
int lis2dw12_init_interrupt(struct device *dev)
{
struct lis2dw12_data *lis2dw12 = dev->driver_data;
const struct lis2dw12_device_config *cfg = dev->config->config_info;
int ret;
/* setup data ready gpio interrupt (INT1 or INT2) */
lis2dw12->gpio = device_get_binding(cfg->int_gpio_port);
if (lis2dw12->gpio == NULL) {
LOG_DBG("Cannot get pointer to %s device",
cfg->int_gpio_port);
return -EINVAL;
}
#if defined(CONFIG_LIS2DW12_TRIGGER_OWN_THREAD)
k_sem_init(&lis2dw12->gpio_sem, 0, UINT_MAX);
k_thread_create(&lis2dw12->thread, lis2dw12->thread_stack,
CONFIG_LIS2DW12_THREAD_STACK_SIZE,
(k_thread_entry_t)lis2dw12_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LIS2DW12_THREAD_PRIORITY),
0, 0);
#elif defined(CONFIG_LIS2DW12_TRIGGER_GLOBAL_THREAD)
lis2dw12->work.handler = lis2dw12_work_cb;
lis2dw12->dev = dev;
#endif /* CONFIG_LIS2DW12_TRIGGER_OWN_THREAD */
ret = gpio_pin_configure(lis2dw12->gpio, cfg->int_gpio_pin,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
if (ret < 0) {
LOG_DBG("Could not configure gpio");
return ret;
}
gpio_init_callback(&lis2dw12->gpio_cb,
lis2dw12_gpio_callback,
BIT(cfg->int_gpio_pin));
if (gpio_add_callback(lis2dw12->gpio, &lis2dw12->gpio_cb) < 0) {
LOG_DBG("Could not set gpio callback");
return -EIO;
}
/* enable interrupt on int1/int2 in pulse mode */
if (lis2dw12->hw_tf->update_reg(lis2dw12, LIS2DW12_CTRL3_ADDR,
LIS2DW12_LIR_MASK, LIS2DW12_DIS_BIT)) {
return -EIO;
}
return gpio_pin_enable_callback(lis2dw12->gpio, cfg->int_gpio_pin);
}
示例5: setup_aon_gpio
static void setup_aon_gpio(void)
{
gpio_dev = device_get_binding("GPIO_1");
if (!gpio_dev) {
printk("gpio device not found.\n");
return;
}
gpio_pin_configure(gpio_dev, GPIO_INTERRUPT_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
}
示例6: cmd_write
static int cmd_write(const struct shell *shell, size_t argc, char *argv[])
{
u32_t check_array[BUF_ARRAY_CNT];
u32_t buf_array[BUF_ARRAY_CNT];
struct device *flash_dev;
u32_t w_addr;
int j = 0;
flash_dev = device_get_binding(FLASH_DEV_NAME);
if (!flash_dev) {
error(shell, "Flash driver was not found!");
return -ENODEV;
}
if (argc < 2) {
error(shell, "Missing address.");
return -EINVAL;
}
if (argc <= 2) {
error(shell, "Type data to be written.");
return -EINVAL;
}
for (int i = 2; i < argc && i < BUF_ARRAY_CNT; i++) {
buf_array[j] = strtoul(argv[i], NULL, 16);
check_array[j] = ~buf_array[j];
j++;
}
flash_write_protection_set(flash_dev, 0);
w_addr = strtoul(argv[1], NULL, 16);
if (flash_write(flash_dev, w_addr, buf_array,
sizeof(buf_array[0]) * j) != 0) {
error(shell, "Write internal ERROR!");
return -EIO;
}
print(shell, "Write OK.");
flash_read(flash_dev, w_addr, check_array, sizeof(buf_array[0]) * j);
if (memcmp(buf_array, check_array, sizeof(buf_array[0]) * j) == 0) {
print(shell, "Verified.");
} else {
error(shell, "Verification ERROR!");
return -EIO;
}
return 0;
}
示例7: uart_pipe_register
void uart_pipe_register(uint8_t *buf, size_t len, uart_pipe_recv_cb cb)
{
recv_buf = buf;
recv_buf_len = len;
app_cb = cb;
uart_pipe_dev = device_get_binding(CONFIG_UART_PIPE_ON_DEV_NAME);
if (uart_pipe_dev != NULL) {
uart_pipe_setup(uart_pipe_dev);
}
}
示例8: _gpio_dw_clock_config
static inline void _gpio_dw_clock_config(struct device *port)
{
char *drv = CONFIG_GPIO_DW_CLOCK_GATE_DRV_NAME;
struct device *clk;
clk = device_get_binding(drv);
if (clk) {
struct gpio_dw_runtime *context = port->driver_data;
context->clock = clk;
}
}
示例9: lsm6dsl_init_interrupt
int lsm6dsl_init_interrupt(struct device *dev)
{
struct lsm6dsl_data *drv_data = dev->driver_data;
/* setup data ready gpio interrupt */
drv_data->gpio = device_get_binding(CONFIG_LSM6DSL_GPIO_DEV_NAME);
if (drv_data->gpio == NULL) {
SYS_LOG_ERR("Cannot get pointer to %s device.",
CONFIG_LSM6DSL_GPIO_DEV_NAME);
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio, CONFIG_LSM6DSL_GPIO_PIN_NUM,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_HIGH | GPIO_INT_DEBOUNCE);
gpio_init_callback(&drv_data->gpio_cb,
lsm6dsl_gpio_callback,
BIT(CONFIG_LSM6DSL_GPIO_PIN_NUM));
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
SYS_LOG_ERR("Could not set gpio callback.");
return -EIO;
}
/* enable data-ready interrupt */
if (drv_data->hw_tf->update_reg(drv_data,
LSM6DSL_REG_INT1_CTRL,
LSM6DSL_SHIFT_INT1_CTRL_DRDY_XL |
LSM6DSL_SHIFT_INT1_CTRL_DRDY_G,
(1 << LSM6DSL_SHIFT_INT1_CTRL_DRDY_XL) |
(1 << LSM6DSL_SHIFT_INT1_CTRL_DRDY_G)) < 0) {
SYS_LOG_ERR("Could not enable data-ready interrupt.");
return -EIO;
}
#if defined(CONFIG_LSM6DSL_TRIGGER_OWN_THREAD)
k_sem_init(&drv_data->gpio_sem, 0, UINT_MAX);
k_thread_create(&drv_data->thread, drv_data->thread_stack,
CONFIG_LSM6DSL_THREAD_STACK_SIZE,
(k_thread_entry_t)lsm6dsl_thread, dev,
0, NULL, K_PRIO_COOP(CONFIG_LSM6DSL_THREAD_PRIORITY),
0, 0);
#elif defined(CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD)
drv_data->work.handler = lsm6dsl_work_cb;
drv_data->dev = dev;
#endif
gpio_pin_enable_callback(drv_data->gpio, CONFIG_LSM6DSL_GPIO_PIN_NUM);
return 0;
}
示例10: main
void main(void)
{
struct device *dev = device_get_binding("MCP9808");
if (dev == NULL) {
printf("device not found. aborting test.\n");
return;
}
#ifdef DEBUG
printf("dev %p\n", dev);
printf("dev %p name %s\n", dev, dev->config->name);
#endif
#ifdef CONFIG_MCP9808_TRIGGER
struct sensor_value val;
struct sensor_trigger trig;
val.type = SENSOR_VALUE_TYPE_INT_PLUS_MICRO;
val.val1 = 26;
val.val2 = 0;
sensor_attr_set(dev, SENSOR_CHAN_TEMP,
SENSOR_ATTR_UPPER_THRESH, &val);
trig.type = SENSOR_TRIG_THRESHOLD;
trig.chan = SENSOR_CHAN_TEMP;
sensor_trigger_set(dev, &trig, trigger_handler);
#endif
while (1) {
struct sensor_value temp;
int rc;
rc = sensor_sample_fetch(dev);
if (rc != 0) {
printf("sensor_sample_fetch error: %d\n", rc);
break;
}
rc = sensor_channel_get(dev, SENSOR_CHAN_TEMP, &temp);
if (rc != 0) {
printf("sensor_channel_get error: %d\n", rc);
break;
}
printf("temp: %d.%06d\n", temp.val1, temp.val2);
k_sleep(2000);
}
}
示例11: stm32_setup_pins
/**
* @brief setup pins according to their assignments
*
* @param pinconf board pin configuration array
* @param pins array size
*/
void stm32_setup_pins(const struct pin_config *pinconf,
size_t pins)
{
struct device *clk;
int i;
clk = device_get_binding(STM32_CLOCK_CONTROL_NAME);
for (i = 0; i < pins; i++) {
_pinmux_stm32_set(pinconf[i].pin_num,
pinconf[i].mode, clk);
}
}
示例12: _bt_uart_init
static int _bt_uart_init(struct device *unused)
{
ARG_UNUSED(unused);
h4_dev = device_get_binding(CONFIG_BLUETOOTH_UART_ON_DEV_NAME);
if (!h4_dev) {
return -EINVAL;
}
bt_driver_register(&drv);
return 0;
}
示例13: _bt_spi_init
static int _bt_spi_init(struct device *unused)
{
ARG_UNUSED(unused);
spi_dev = device_get_binding(CONFIG_BLUETOOTH_SPI_DEV_NAME);
if (!spi_dev) {
BT_ERR("Failed to initialize SPI driver: %s",
CONFIG_BLUETOOTH_SPI_DEV_NAME);
return -EIO;
}
#if defined(CONFIG_BLUETOOTH_SPI_BLUENRG)
cs_dev = device_get_binding(CONFIG_BLUETOOTH_SPI_CHIP_SELECT_DEV_NAME);
if (!cs_dev) {
BT_ERR("Failed to initialize GPIO driver: %s",
CONFIG_BLUETOOTH_SPI_CHIP_SELECT_DEV_NAME);
return -EIO;
}
#endif /* CONFIG_BLUETOOTH_SPI_BLUENRG */
irq_dev = device_get_binding(CONFIG_BLUETOOTH_SPI_IRQ_DEV_NAME);
if (!irq_dev) {
BT_ERR("Failed to initialize GPIO driver: %s",
CONFIG_BLUETOOTH_SPI_IRQ_DEV_NAME);
return -EIO;
}
rst_dev = device_get_binding(CONFIG_BLUETOOTH_SPI_RESET_DEV_NAME);
if (!rst_dev) {
BT_ERR("Failed to initialize GPIO driver: %s",
CONFIG_BLUETOOTH_SPI_RESET_DEV_NAME);
return -EIO;
}
bt_hci_driver_register(&drv);
return 0;
}
示例14: mpxxdtyy_initialize
static int mpxxdtyy_initialize(struct device *dev)
{
struct mpxxdtyy_data *const data = DEV_DATA(dev);
data->comm_master = device_get_binding(DT_ST_MPXXDTYY_0_BUS_NAME);
if (data->comm_master == NULL) {
LOG_ERR("master %s not found", DT_ST_MPXXDTYY_0_BUS_NAME);
return -EINVAL;
}
data->state = DMIC_STATE_INITIALIZED;
return 0;
}
示例15: ak8975_init
int ak8975_init(struct device *dev)
{
struct ak8975_data *drv_data = dev->driver_data;
u8_t id;
drv_data->i2c = device_get_binding(CONFIG_AK8975_I2C_MASTER_DEV_NAME);
if (drv_data->i2c == NULL) {
SYS_LOG_ERR("Failed to get pointer to %s device!",
CONFIG_AK8975_I2C_MASTER_DEV_NAME);
return -EINVAL;
}
#ifdef CONFIG_MPU9150
/* wake up MPU9150 chip */
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
MPU9150_REG_PWR_MGMT1, MPU9150_SLEEP_EN,
0) < 0) {
SYS_LOG_ERR("Failed to wake up MPU9150 chip.");
return -EIO;
}
/* enable MPU9150 pass-though to have access to AK8975 */
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
MPU9150_REG_BYPASS_CFG, MPU9150_I2C_BYPASS_EN,
MPU9150_I2C_BYPASS_EN) < 0) {
SYS_LOG_ERR("Failed to enable pass-through mode for MPU9150.");
return -EIO;
}
#endif
/* check chip ID */
if (i2c_reg_read_byte(drv_data->i2c, CONFIG_AK8975_I2C_ADDR,
AK8975_REG_CHIP_ID, &id) < 0) {
SYS_LOG_ERR("Failed to read chip ID.");
return -EIO;
}
if (id != AK8975_CHIP_ID) {
SYS_LOG_ERR("Invalid chip ID.");
return -EINVAL;
}
if (ak8975_read_adjustment_data(drv_data) < 0) {
return -EIO;
}
dev->driver_api = &ak8975_driver_api;
return 0;
}