int sif_anout_init(void) { vsn_sif.tim3 = stm32_tim_init(3); vsn_sif.tim8 = stm32_tim_init(8); if (!vsn_sif.tim3 || !vsn_sif.tim8) return ERROR; // Use the TIM3 as PWM modulated analogue output STM32_TIM_SETPERIOD(vsn_sif.tim3, 5); STM32_TIM_SETCOMPARE(vsn_sif.tim3, GPIO_OUT_PWM_TIM3_CH, 3); STM32_TIM_SETCLOCK(vsn_sif.tim3, 36e6); STM32_TIM_SETMODE(vsn_sif.tim3, STM32_TIM_MODE_UP); STM32_TIM_SETCHANNEL(vsn_sif.tim3, GPIO_OUT_PWM_TIM3_CH, STM32_TIM_CH_OUTPWM | STM32_TIM_CH_POLARITY_NEG); // Use the TIM8 to drive the upper power mosfet STM32_TIM_SETISR(vsn_sif.tim8, sif_anout_isr, 0); STM32_TIM_ENABLEINT(vsn_sif.tim8, 0); STM32_TIM_SETPERIOD(vsn_sif.tim8, 4096); STM32_TIM_SETCOMPARE(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, 5000); STM32_TIM_SETCLOCK(vsn_sif.tim8, 36e6); STM32_TIM_SETMODE(vsn_sif.tim8, STM32_TIM_MODE_UP); //STM32_TIM_SETCHANNEL(vsn_sif.tim8, GPIO_OUT_PWRPWM_TIM8_CH, STM32_TIM_CH_OUTPWM | STM32_TIM_CH_POLARITY_NEG); vsn_sif.i2c1 = up_i2cinitialize(1); vsn_sif.i2c2 = up_i2cinitialize(2); vsn_sif.spi2 = up_spiinitialize(2); return OK; }
alc_i2c_t *alc5658_i2c_initialize(void) { alc_i2c_t *i2c; int i; int ret; i2c_dev = up_i2cinitialize(CONFIG_ALC5658_I2C_PORT); if (i2c_dev == NULL) { i2cerr("ALC5658 up_i2cinitialize(port: %d) failed\n", CONFIG_ALC5658_I2C_PORT); return NULL; } configs.frequency = CONFIG_ALC5658_I2C_FREQ; configs.address = ALC5658_ADDR; configs.addrlen = CONFIG_ALC5658_I2C_ADDRLEN; i2c = &alc5658_i2c; for (i = 0; i < sizeof(codec_init_script) / sizeof(t_codec_init_script_entry); i++) { ret = i2c->modify(codec_init_script[i].addr, codec_init_script[i].val, 0xFFFF); audvdbg("ALC %x <- %x\n", codec_init_script[i].addr, ret); delay(codec_init_script[i].delay); } return i2c; }
int kxtj9_driver_init(){ int ret = 0; if (g_data != NULL) goto init_done; g_data = kmm_malloc(sizeof(struct kxtj9_data)); memset(g_data, 0, sizeof(struct kxtj9_data)); g_data->i2c = up_i2cinitialize(CONFIG_SENSOR_KXTJ9_I2C_BUS); if (!g_data->i2c) { dbg("failed to init i2c\n"); ret = -ENODEV; goto init_done; } ret = I2C_SETADDRESS(g_data->i2c, KXTJ9_I2C_ADDR, 7); if (ret) { dbg("failed to set i2c address\n"); goto init_done; } I2C_SETFREQUENCY(g_data->i2c, CONFIG_SENSOR_KXTJ9_I2C_BUS_SPEED); init_done: return ret; }
static int io_expander_init(void) { void *driver_data; struct i2c_dev_s *dev; dev = up_i2cinitialize(0); if (!dev) { lowsyslog("%s(): Failed to get I/O Expander I2C bus 0\n", __func__); return -ENODEV; } else { if (tca64xx_init(&driver_data, TCA6408_PART, dev, TCA6408_U72, TCA6408_U72_RST_GPIO, TCA6408_U72_INT_GPIO, TCA6408_GPIO_BASE) < 0) { lowsyslog("%s(): Failed to register I/O Expander(0x%02x)\n", __func__, TCA6408_U72); up_i2cuninitialize(dev); return -ENODEV; } } return 0; }
static void at24xxx_attach(void) { /* find the right I2C */ struct i2c_dev_s *i2c = up_i2cinitialize(PX4_I2C_BUS_ONBOARD); /* this resets the I2C bus, set correct bus speed again */ I2C_SETFREQUENCY(i2c, 400000); if (i2c == NULL) errx(1, "failed to locate I2C bus"); /* start the MTD driver, attempt 5 times */ for (int i = 0; i < 5; i++) { mtd_dev = at24c_initialize(i2c); if (mtd_dev) { /* abort on first valid result */ if (i > 0) { warnx("warning: EEPROM needed %d attempts to attach", i+1); } break; } } /* if last attempt is still unsuccessful, abort */ if (mtd_dev == NULL) errx(1, "failed to initialize EEPROM driver"); attached = true; }
int stm32_lm75initialize(FAR const char *devpath) { FAR struct i2c_dev_s *i2c; int ret; /* Configure PB.5 as Input pull-up. This pin can be used as a temperature * sensor interrupt (not fully implemented). */ stm32_configgpio(GPIO_LM75_OSINT); /* Get an instance of the I2C1 interface */ i2c = up_i2cinitialize(1); if (!i2c) { return -ENODEV; } /* Then register the temperature sensor */ ret = lm75_register(devpath, i2c, 0x48); if (ret < 0) { (void)up_i2cuninitialize(i2c); } return ret; }
int i2c_main(int argc, char *argv[]) { /* find the right I2C */ i2c = up_i2cinitialize(I2C_BUS); if (i2c == NULL) errx(1, "failed to locate I2C bus"); usleep(100000); #ifdef PX4_I2C_OBDEV_PX4IO uint8_t buf[] = { 0, 4}; int ret = transfer(PX4_I2C_OBDEV_PX4IO, buf, sizeof(buf), NULL, 0); if (ret) errx(1, "send failed - %d", ret); uint32_t val; ret = transfer(PX4_I2C_OBDEV_PX4IO, NULL, 0, (uint8_t *)&val, sizeof(val)); if (ret) errx(1, "recive failed - %d", ret); errx(0, "got 0x%08x", val); #endif }
int stm32_bmp180initialize(FAR const char *devpath) { FAR struct i2c_dev_s *i2c; int ret; sndbg("Initializing BMP180!\n"); /* Initialize I2C */ i2c = up_i2cinitialize(BMP180_I2C_PORTNO); if (!i2c) { return -ENODEV; } /* Then register the barometer sensor */ ret = bmp180_register(devpath, i2c); if (ret < 0) { sndbg("Error registering BM180\n"); } return ret; }
/* * Initialize the communication from SVC * Allocates internal structs etc. To be done once. */ inline int i2c_init_comm(uint8_t bus) { /* Initialize I2C internal structs */ sw_exp_dev = up_i2cinitialize(bus); if (!sw_exp_dev) { dbg_error("%s(): Failed to get bus %d\n", __func__, I2C_SW_BUS); return ERROR; } return 0; }
/** * @brief Initialize the power measurement HW and SW library. * To be called once, before any other call to the library. * @return 0 on success, standard error codes otherwise. * @param[in] current_lsb_uA: current measurement precision (LSB) in uA * @param[in] ct: sampling conversion time to be used * @param[in] avg_count: averaging sample count (>0) */ int bdbpm_init(uint32_t current_lsb_uA, ina230_conversion_time ct, ina230_avg_count avg_count) { dbg_verbose("%s(): Initializing with options lsb=%uuA, ct=%u, avg_count=%u...\n", __func__, current_lsb_uA, ct, avg_count); /* Initialize I2C internal structs */ i2c_dev = up_i2cinitialize(PWRM_I2C_BUS); if (!i2c_dev) { dbg_error("%s(): Failed to get I2C bus %u\n", __func__, PWRM_I2C_BUS); return -ENXIO; } bdbpm_current_lsb = current_lsb_uA; if (ct >= ina230_ct_count) { dbg_error("%s(): invalid conversion time! (%u)\n", __func__, ct); up_i2cuninitialize(i2c_dev); return -EINVAL; } if (avg_count >= ina230_avg_count_max) { dbg_error("%s(): invalid average count! (%u)\n", __func__, avg_count); up_i2cuninitialize(i2c_dev); return -EINVAL; } bdbpm_ct = ct; bdbpm_avg_count = avg_count; current_dev = -1; /* * Setup I/O selection pins on U135 * * Note: U135 is registered to gpio_chip from the board code */ gpio_direction_out(I2C_INA230_SEL1_A, 1); gpio_direction_out(I2C_INA230_SEL1_B, 1); gpio_direction_out(I2C_INA230_SEL1_INH, 1); gpio_direction_out(I2C_INA230_SEL2_A, 1); gpio_direction_out(I2C_INA230_SEL2_B, 1); gpio_direction_out(I2C_INA230_SEL2_INH, 1); dbg_verbose("%s(): done.\n", __func__); return OK; }
int i2ccmd_bus(FAR struct i2ctool_s *i2ctool, int argc, char **argv) { FAR struct i2c_dev_s *dev; int i; i2ctool_printf(i2ctool, " BUS EXISTS?\n"); for (i = CONFIG_I2CTOOL_MINBUS; i <= CONFIG_I2CTOOL_MAXBUS; i++) { dev = up_i2cinitialize(i); if (dev) { i2ctool_printf(i2ctool, "Bus %d: YES\n", i); (void)up_i2cuninitialize(dev); } else { i2ctool_printf(i2ctool, "Bus %d: NO\n", i); } } return OK; }
int display_init(void) { struct i2c_dev_s *dev; dev = up_i2cinitialize(0); if (!dev) { lowsyslog("%s(): Failed to get I/O Expander I2C bus 0\n", __func__); return -ENODEV; } gb_i2c_set_dev(dev); pwm_enable(); lg4892_gpio_init(); lg4892_enable(1); dsi_initialize(&lg4892_panel, TSB_CDSI0, TSB_CDSI_TX); return 0; }
int I2C::init() { int ret = OK; /* attach to the i2c bus */ _dev = up_i2cinitialize(_bus); if (_dev == nullptr) { debug("failed to init I2C"); ret = -ENOENT; goto out; } // call the probe function to check whether the device is present ret = probe(); if (ret != OK) { debug("probe failed"); goto out; } // do base class init, which will create device node, etc ret = CDev::init(); if (ret != OK) { debug("cdev init failed"); goto out; } // tell the world where we are log("on I2C bus %d at 0x%02x", _bus, _address); out: return ret; }
int nsh_archinitialize(void) { int result; /* INIT 1 Lowest level NuttX initialization has been done at this point, LEDs and UARTs are configured */ /* INIT 2 Configuring PX4 low-level peripherals, these will be always needed */ /* configure the high-resolution time/callout interface */ #ifdef CONFIG_HRT_TIMER hrt_init(); #endif /* configure CPU load estimation */ #ifdef CONFIG_SCHED_INSTRUMENTATION cpuload_initialize_once(); #endif /* set up the serial DMA polling */ #ifdef SERIAL_HAVE_DMA { static struct hrt_call serial_dma_call; struct timespec ts; /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. */ ts.tv_sec = 0; ts.tv_nsec = 1000000; hrt_call_every(&serial_dma_call, ts_to_abstime(&ts), ts_to_abstime(&ts), (hrt_callout)stm32_serial_dma_poll, NULL); } #endif message("\r\n"); up_ledoff(LED_BLUE); up_ledoff(LED_AMBER); up_ledon(LED_BLUE); /* Configure user-space led driver */ px4fmu_led_init(); i2c2 = up_i2cinitialize(2); if (!i2c2) { message("[boot] FAILED to initialize I2C bus 3\r\n"); up_ledon(LED_AMBER); return -ENODEV; } /* set I2C3 speed */ I2C_SETFREQUENCY(i2c2, 400000); /* try to attach, don't fail if device is not responding */ (void)eeprom_attach(i2c2, FMU_BASEBOARD_EEPROM_ADDRESS, FMU_BASEBOARD_EEPROM_TOTAL_SIZE_BYTES, FMU_BASEBOARD_EEPROM_PAGE_SIZE_BYTES, FMU_BASEBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/baseboard_eeprom", 1); int eeprom_attempts = 0; int eeprom_fail; while (eeprom_attempts < 5) { /* try to attach, fail if device does not respond */ eeprom_fail = eeprom_attach(i2c2, FMU_ONBOARD_EEPROM_ADDRESS, FMU_ONBOARD_EEPROM_TOTAL_SIZE_BYTES, FMU_ONBOARD_EEPROM_PAGE_SIZE_BYTES, FMU_ONBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/eeprom", 1); eeprom_attempts++; if (eeprom_fail == OK) break; up_udelay(1000); } if (eeprom_fail) message("[boot] FAILED to attach FMU EEPROM\r\n"); /* Report back sensor status */ if (eeprom_fail) { up_ledon(LED_AMBER); } #if defined(CONFIG_STM32_SPI3) /* Get the SPI port */ message("[boot] Initializing SPI port 3\r\n"); spi3 = up_spiinitialize(3); if (!spi3) { message("[boot] FAILED to initialize SPI port 3\r\n"); up_ledon(LED_AMBER); return -ENODEV; } message("[boot] Successfully initialized SPI port 3\r\n"); /* Now bind the SPI interface to the MMCSD driver */ result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3); if (result != OK) { message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\r\n"); up_ledon(LED_AMBER); return -ENODEV; } message("[boot] Successfully bound SPI port 3 to the MMCSD driver\r\n"); #endif /* SPI3 */ /* INIT 3: MULTIPORT-DEPENDENT INITIALIZATION */ /* Get board information if available */ /* Initialize the user GPIOs */ px4fmu_gpio_init(); #ifdef CONFIG_ADC int adc_state = adc_devinit(); if (adc_state != OK) { /* Try again */ adc_state = adc_devinit(); if (adc_state != OK) { /* Give up */ message("[boot] FAILED adc_devinit: %d\r\n", adc_state); return -ENODEV; } } #endif /* configure the tone generator */ #ifdef CONFIG_TONE_ALARM tone_alarm_init(); #endif return OK; }
struct ara_board_info *board_init(void) { int i; int rc; /* Disable the I/O expanders for now. */ stm32_configgpio(SVC_RST_IOEXP1_GPIO); stm32_configgpio(SVC_RST_IOEXP2_GPIO); stm32_gpiowrite(SVC_RST_IOEXP1_GPIO, false); stm32_gpiowrite(SVC_RST_IOEXP2_GPIO, false); /* * Register STM32 GPIOs to GPIO chip framework. This has to happen * before the following configuration, which depends on STM32 GPIO * pin numbers. */ stm32_gpio_init(); /* Register the TCA64xx I/O Expanders to the gpio chip core. */ for (i = 0; i < evt1_board_info.nr_io_expanders; i++) { struct io_expander_info *io_exp = &evt1_board_info.io_expanders[i]; io_exp->i2c_dev = up_i2cinitialize(io_exp->i2c_bus); if (!io_exp->i2c_dev) { dbg_error("%s(): Failed to get I/O Expander I2C bus %u\n", __func__, io_exp->i2c_bus); board_exit(); return NULL; } if (tca64xx_init(&io_exp->io_exp_driver_data, io_exp->part, io_exp->i2c_dev, io_exp->i2c_addr, io_exp->reset, io_exp->irq, io_exp->gpio_base) < 0) { dbg_error("%s(): Failed to register I/O Expander(0x%02x)\n", __func__, io_exp->i2c_addr); board_exit(); return NULL; } } /* For now, just always enable REFCLK_MAIN and the buffers. */ rc = vreg_config(&refclk_main_vreg) || vreg_get(&refclk_main_vreg); if (rc) { dbg_error("%s: can't start REFCLK_MAIN: %d\n", __func__, rc); board_exit(); return NULL; } /* Configure the switch power supply lines. */ rc = vreg_config(&sw_vreg); if (rc) { dbg_error("%s: can't configure switch regulators: %d\n", __func__, rc); board_exit(); return NULL; } stm32_configgpio(evt1_board_info.sw_data.gpio_reset); up_udelay(POWER_SWITCH_OFF_STAB_TIME_US); /* Configure the wake/detect lines. */ stm32_configgpio(WD_1_DET_IN_GPIO); stm32_configgpio(WD_2_DET_IN_GPIO); stm32_configgpio(WD_3A_DET_IN_GPIO); stm32_configgpio(WD_3B_DET_IN_GPIO); stm32_configgpio(WD_4A_DET_IN_GPIO); stm32_configgpio(WD_4B_DET_IN_GPIO); stm32_configgpio(WD_5_DET_IN_GPIO); stm32_configgpio(WD_8A_DET_IN_GPIO); stm32_configgpio(WD_8B_DET_IN_GPIO); /* Configure the ARA key. */ stm32_configgpio(ARA_KEY_GPIO); /* * (Module hotplug pins unconfigured. TODO, part of SW-1942.) */ return &evt1_board_info; }
int nsh_archinitialize(void) { int result; /* INIT 1 Lowest level NuttX initialization has been done at this point, LEDs and UARTs are configured */ /* INIT 2 Configuring PX4 low-level peripherals, these will be always needed */ /* configure the high-resolution time/callout interface */ #ifdef CONFIG_HRT_TIMER hrt_init(); #endif /* configure CPU load estimation */ #ifdef CONFIG_SCHED_INSTRUMENTATION cpuload_initialize_once(); #endif /* set up the serial DMA polling */ #ifdef SERIAL_HAVE_DMA { static struct hrt_call serial_dma_call; struct timespec ts; /* * Poll at 1ms intervals for received bytes that have not triggered * a DMA event. */ ts.tv_sec = 0; ts.tv_nsec = 1000000; hrt_call_every(&serial_dma_call, ts_to_abstime(&ts), ts_to_abstime(&ts), (hrt_callout)stm32_serial_dma_poll, NULL); } #endif message("\r\n"); up_ledoff(LED_BLUE); up_ledoff(LED_AMBER); up_ledon(LED_BLUE); /* Configure user-space led driver */ px4fmu_led_init(); /* Configure SPI-based devices */ spi1 = up_spiinitialize(1); if (!spi1) { message("[boot] FAILED to initialize SPI port 1\r\n"); up_ledon(LED_AMBER); return -ENODEV; } // Setup 10 MHz clock (maximum rate the BMA180 can sustain) SPI_SETFREQUENCY(spi1, 10000000); SPI_SETBITS(spi1, 8); SPI_SETMODE(spi1, SPIDEV_MODE3); SPI_SELECT(spi1, PX4_SPIDEV_GYRO, false); SPI_SELECT(spi1, PX4_SPIDEV_ACCEL, false); SPI_SELECT(spi1, PX4_SPIDEV_MPU, false); up_udelay(20); message("[boot] Successfully initialized SPI port 1\r\n"); /* initialize SPI peripherals redundantly */ int gyro_attempts = 0; int gyro_fail = 0; while (gyro_attempts < 5) { gyro_fail = l3gd20_attach(spi1, PX4_SPIDEV_GYRO); gyro_attempts++; if (gyro_fail == 0) break; up_udelay(1000); } if (gyro_fail) message("[boot] FAILED to attach L3GD20 gyro\r\n"); int acc_attempts = 0; int acc_fail = 0; while (acc_attempts < 5) { acc_fail = bma180_attach(spi1, PX4_SPIDEV_ACCEL); acc_attempts++; if (acc_fail == 0) break; up_udelay(1000); } if (acc_fail) message("[boot] FAILED to attach BMA180 accelerometer\r\n"); int mpu_attempts = 0; int mpu_fail = 0; while (mpu_attempts < 1) { mpu_fail = mpu6000_attach(spi1, PX4_SPIDEV_MPU); mpu_attempts++; if (mpu_fail == 0) break; up_udelay(200); } if (mpu_fail) message("[boot] FAILED to attach MPU 6000 gyro/acc\r\n"); /* initialize I2C2 bus */ i2c2 = up_i2cinitialize(2); if (!i2c2) { message("[boot] FAILED to initialize I2C bus 2\r\n"); up_ledon(LED_AMBER); return -ENODEV; } /* set I2C2 speed */ I2C_SETFREQUENCY(i2c2, 400000); i2c3 = up_i2cinitialize(3); if (!i2c3) { message("[boot] FAILED to initialize I2C bus 3\r\n"); up_ledon(LED_AMBER); return -ENODEV; } /* set I2C3 speed */ I2C_SETFREQUENCY(i2c3, 400000); int mag_attempts = 0; int mag_fail = 0; while (mag_attempts < 5) { mag_fail = hmc5883l_attach(i2c2); mag_attempts++; if (mag_fail == 0) break; up_udelay(1000); } if (mag_fail) message("[boot] FAILED to attach HMC5883L magnetometer\r\n"); int baro_attempts = 0; int baro_fail = 0; while (baro_attempts < 5) { baro_fail = ms5611_attach(i2c2); baro_attempts++; if (baro_fail == 0) break; up_udelay(1000); } if (baro_fail) message("[boot] FAILED to attach MS5611 baro at addr #1 or #2 (0x76 or 0x77)\r\n"); /* try to attach, don't fail if device is not responding */ (void)eeprom_attach(i2c3, FMU_BASEBOARD_EEPROM_ADDRESS, FMU_BASEBOARD_EEPROM_TOTAL_SIZE_BYTES, FMU_BASEBOARD_EEPROM_PAGE_SIZE_BYTES, FMU_BASEBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/baseboard_eeprom", 1); int eeprom_attempts = 0; int eeprom_fail; while (eeprom_attempts < 5) { /* try to attach, fail if device does not respond */ eeprom_fail = eeprom_attach(i2c2, FMU_ONBOARD_EEPROM_ADDRESS, FMU_ONBOARD_EEPROM_TOTAL_SIZE_BYTES, FMU_ONBOARD_EEPROM_PAGE_SIZE_BYTES, FMU_ONBOARD_EEPROM_PAGE_WRITE_TIME_US, "/dev/eeprom", 1); eeprom_attempts++; if (eeprom_fail == OK) break; up_udelay(1000); } if (eeprom_fail) message("[boot] FAILED to attach FMU EEPROM\r\n"); /* Report back sensor status */ if (acc_fail || gyro_fail || mag_fail || baro_fail || eeprom_fail) { up_ledon(LED_AMBER); } #if defined(CONFIG_STM32_SPI3) /* Get the SPI port */ message("[boot] Initializing SPI port 3\r\n"); spi3 = up_spiinitialize(3); if (!spi3) { message("[boot] FAILED to initialize SPI port 3\r\n"); up_ledon(LED_AMBER); return -ENODEV; } message("[boot] Successfully initialized SPI port 3\r\n"); /* Now bind the SPI interface to the MMCSD driver */ result = mmcsd_spislotinitialize(CONFIG_NSH_MMCSDMINOR, CONFIG_NSH_MMCSDSLOTNO, spi3); if (result != OK) { message("[boot] FAILED to bind SPI port 3 to the MMCSD driver\r\n"); up_ledon(LED_AMBER); return -ENODEV; } message("[boot] Successfully bound SPI port 3 to the MMCSD driver\r\n"); #endif /* SPI3 */ /* initialize I2C1 bus */ i2c1 = up_i2cinitialize(1); if (!i2c1) { message("[boot] FAILED to initialize I2C bus 1\r\n"); up_ledon(LED_AMBER); return -ENODEV; } /* set I2C1 speed */ I2C_SETFREQUENCY(i2c1, 400000); /* INIT 3: MULTIPORT-DEPENDENT INITIALIZATION */ /* Get board information if available */ /* Initialize the user GPIOs */ px4fmu_gpio_init(); #ifdef CONFIG_ADC int adc_state = adc_devinit(); if (adc_state != OK) { /* Try again */ adc_state = adc_devinit(); if (adc_state != OK) { /* Give up */ message("[boot] FAILED adc_devinit: %d\r\n", adc_state); return -ENODEV; } } #endif /* configure the tone generator */ #ifdef CONFIG_TONE_ALARM tone_alarm_init(); #endif return OK; }
struct ara_board_info *board_init(void) { int i; /* Pretty lights */ stm32_configgpio(SVC_LED_GREEN); stm32_gpiowrite(SVC_LED_GREEN, false); /* Disable these for now */ stm32_configgpio(SVC_RST_IOEXP); stm32_gpiowrite(SVC_RST_IOEXP, false); /* * Register the STM32 GPIOs to Gpio Chip * * This needs to happen before the I/O Expanders registration, which * uses some STM32 pins */ stm32_gpio_init(); /* * Configure the switch and I/O Expander reset and power supply lines. * Hold all the lines low while we turn on the power rails. */ vreg_config(&ioexp_vreg); vreg_config(&sw_vreg); stm32_configgpio(sdb_board_info.sw_data.gpio_reset); up_udelay(POWER_SWITCH_OFF_STAB_TIME_US); /* * Enable 1P1 and 1P8, used by the I/O Expanders */ vreg_get(&ioexp_vreg); /* Register the TCA64xx I/O Expanders GPIOs to Gpio Chip */ for (i = 0; i < sdb_board_info.nr_io_expanders; i++) { struct io_expander_info *io_exp = &sdb_board_info.io_expanders[i]; io_exp->i2c_dev = up_i2cinitialize(io_exp->i2c_bus); if (!io_exp->i2c_dev) { dbg_error("%s(): Failed to get I/O Expander I2C bus %u\n", __func__, io_exp->i2c_bus); } else { if (tca64xx_init(&io_exp->io_exp_driver_data, io_exp->part, io_exp->i2c_dev, io_exp->i2c_addr, io_exp->reset, io_exp->irq, io_exp->gpio_base) < 0) { dbg_error("%s(): Failed to register I/O Expander(0x%02x)\n", __func__, io_exp->i2c_addr); up_i2cuninitialize(io_exp->i2c_dev); } } } /* Hold USB_HUB_RESET high */ gpio_direction_out(USB_HUB_RESET, 1); return &sdb_board_info; }
/* I2C drv : 4mA */ modifyreg32(PTDRVCNT0, 0x0003C000, 0x0003C000); /* Enable I2C controller */ modifyreg32(MCLKCNTAPB, 0, MCLKCNTAPB_I2C0_CLKEN); modifyreg32(MRSTCNTAPB, 0, MRSTCNTAPB_I2C0_RSTB); /* I2C SCL: push pull */ modifyreg32(I2CMODE, 0, I2CMODE0); /* Disable charge */ i2c = up_i2cinitialize(1); if (i2c) { /* Set slave address */ ret = I2C_SETADDRESS(i2c, R2A20056BM_ADDR, 7); /* Set frequency */ freq = I2C_SETFREQUENCY(i2c, R2A20056BM_SCL); /* Charge disable */ if (ret == OK && freq == R2A20056BM_SCL) {
int i2ccmd_verf(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) { FAR struct i2c_dev_s *dev; FAR char *ptr; uint16_t rdvalue; uint8_t regaddr; bool addrinaddr; long wrvalue; long repititions; int nargs; int argndx; int ret; int i; /* Parse any command line arguments */ for (argndx = 1; argndx < argc; ) { /* Break out of the look when the last option has been parsed */ ptr = argv[argndx]; if (*ptr != '-') { break; } /* Otherwise, check for common options */ nargs = common_args(i2ctool, &argv[argndx]); if (nargs < 0) { return ERROR; } argndx += nargs; } /* The options may be followed by the optional wrvalue to be written. If omitted, then * the register address will be used as the wrvalue, providing an address-in-address * test. */ addrinaddr = true; wrvalue = 0; if (argndx < argc) { wrvalue = strtol(argv[argndx], NULL, 16); if (i2ctool->width == 8) { if (wrvalue < 0 || wrvalue > 255) { i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); return ERROR; } } else if (wrvalue < 0 || wrvalue > 65535) { i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); return ERROR; } addrinaddr = false; argndx++; } /* There may be one more thing on the command line: The repitition * count. */ repititions = 1; if (argndx < argc) { repititions = strtol(argv[argndx], NULL, 16); if (repititions < 1) { i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); return ERROR; } argndx++; } if (argndx != argc) { i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); return ERROR; } /* Get a handle to the I2C bus */ dev = up_i2cinitialize(i2ctool->bus); if (!dev) { i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); return ERROR; } /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ I2C_SETFREQUENCY(dev, i2ctool->freq); I2C_SETADDRESS(dev, i2ctool->addr, 7); /* Loop for the requested number of repititions */ regaddr = i2ctool->regaddr; ret = OK; for (i = 0; i < repititions; i++) { /* If we are performing an address-in-address test, then use the register * address as the value to write. */ if (addrinaddr) { wrvalue = regaddr; } /* Write to the I2C bus */ ret = i2ctool_set(i2ctool, dev, regaddr, (uint16_t)wrvalue); if (ret == OK) { /* Read the value back from the I2C bus */ ret = i2ctool_get(i2ctool, dev, regaddr, &rdvalue); } /* Display the result */ if (ret == OK) { i2ctool_printf(i2ctool, "VERIFY Bus: %d Addr: %02x Subaddr: %02x Wrote: ", i2ctool->bus, i2ctool->addr, i2ctool->regaddr); if (i2ctool->width == 8) { i2ctool_printf(i2ctool, "%02x Read: %02x", (int)wrvalue, (int)rdvalue); } else { i2ctool_printf(i2ctool, "%04x Read: %04x", (int)wrvalue, (int)rdvalue); } if (wrvalue != rdvalue) { i2ctool_printf(i2ctool, " <<< FAILURE\n"); } else { i2ctool_printf(i2ctool, "\n"); } } else { i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); break; } /* Auto-increment the address if so configured */ if (i2ctool->autoincr) { regaddr++; } } (void)up_i2cuninitialize(dev); return ret; }
struct ara_board_info *ara_board_init(void) { int i; enum hwid hwid = board_get_hwid(); board_info = NULL; /* Check HWID, assign board_info struct and the Switch ES revision */ switch (hwid) { case HWID_DB3_0_1: board_info = &db3_board_info; dbg_info("HWID found as DB3.0/3.1\n"); break; case HWID_DB3_2: /* DB3.0/1 with ES3 Switch */ board_info = &db3_board_info; board_info->sw_data.rev = SWITCH_REV_ES3; dbg_info("HWID found as DB3.2\n"); break; case HWID_DB3_5: /* EVT1.5 + DB3.5 pwrmon + specific mapping of physical interfaces */ board_info = &evt1_5_board_info; board_info->pwrmon = &db3_5_pwrmon; board_info->interfaces = db3_5_interfaces; board_info->nr_interfaces = db3_5_nr_interfaces; dbg_info("HWID found as DB3.5\n"); break; case HWID_EVT1: board_info = &evt1_board_info; dbg_info("HWID found as EVT1\n"); break; case HWID_EVT1_5: board_info = &evt1_5_board_info; dbg_info("HWID found as EVT1.5\n"); break; case HWID_EVT1_6: board_info = &evt1_5_board_info; board_info->sw_data.rev = SWITCH_REV_ES2; dbg_info("HWID found as EVT1.6\n"); break; default: return NULL; } /* Disable the I/O Expanders for now */ for (i = 0; i < board_info->nr_io_expanders; i++) { struct io_expander_info *io_exp = &board_info->io_expanders[i]; stm32_configgpio(io_exp->reset); stm32_gpiowrite(io_exp->reset, false); } /* * Register the STM32 GPIOs to Gpio Chip * * This needs to happen before the I/O Expanders registration, which * uses some STM32 pins */ stm32_gpio_init(); /* Register the TCA64xx I/O Expanders GPIOs to Gpio Chip */ for (i = 0; i < board_info->nr_io_expanders; i++) { struct io_expander_info *io_exp = &board_info->io_expanders[i]; io_exp->i2c_dev = up_i2cinitialize(io_exp->i2c_bus); if (!io_exp->i2c_dev) { dbg_error("%s(): Failed to get I/O Expander I2C bus %u\n", __func__, io_exp->i2c_bus); goto err_deinit_gpio; } else { if (tca64xx_init(&io_exp->io_exp_driver_data, io_exp->part, io_exp->i2c_dev, io_exp->i2c_addr, io_exp->reset, io_exp->irq, io_exp->gpio_base) < 0) { dbg_error("%s(): Failed to register I/O Expander(0x%02x)\n", __func__, io_exp->i2c_addr); goto err_uninit_i2c; } } } /* Run the board specific code */ if (board_info->board_init) { if (board_info->board_init(board_info)) { dbg_error("%s(): Failed to initalize board\n", __func__); goto err_uninit_i2c; } } /* Return the board specific info */ return board_info; err_uninit_i2c: /* Done in reverse order to account for possible IRQ chaining. */ for (i = board_info->nr_io_expanders - 1; i >= 0; i--) { struct io_expander_info *io_exp = &board_info->io_expanders[i]; if (io_exp->i2c_dev) { up_i2cuninitialize(io_exp->i2c_dev); } } err_deinit_gpio: stm32_gpio_deinit(); /* Leave the I/O expanders in reset here. */ return NULL; }
int i2ccmd_get(FAR struct i2ctool_s *i2ctool, int argc, FAR char **argv) { FAR struct i2c_dev_s *dev; FAR char *ptr; uint16_t result; uint8_t regaddr; long repititions; int nargs; int argndx; int ret; int i; /* Parse any command line arguments */ for (argndx = 1; argndx < argc; ) { /* Break out of the look when the last option has been parsed */ ptr = argv[argndx]; if (*ptr != '-') { break; } /* Otherwise, check for common options */ nargs = common_args(i2ctool, &argv[argndx]); if (nargs < 0) { return ERROR; } argndx += nargs; } /* There may be one more thing on the command line: The repitition * count. */ repititions = 1; if (argndx < argc) { repititions = strtol(argv[argndx], NULL, 16); if (repititions < 1) { i2ctool_printf(i2ctool, g_i2cargrange, argv[0]); return ERROR; } argndx++; } if (argndx != argc) { i2ctool_printf(i2ctool, g_i2ctoomanyargs, argv[0]); return ERROR; } /* Get a handle to the I2C bus */ dev = up_i2cinitialize(i2ctool->bus); if (!dev) { i2ctool_printf(i2ctool, "Failed to get bus %d\n", i2ctool->bus); return ERROR; } /* Set the frequency and the address (NOTE: Only 7-bit address supported now) */ I2C_SETFREQUENCY(dev, i2ctool->freq); I2C_SETADDRESS(dev, i2ctool->addr, 7); /* Loop for the requested number of repititions */ regaddr = i2ctool->regaddr; ret = OK; for (i = 0; i < repititions; i++) { /* Read from the I2C bus */ ret = i2ctool_get(i2ctool, dev, regaddr, &result); /* Display the result */ if (ret == OK) { i2ctool_printf(i2ctool, "READ Bus: %d Addr: %02x Subaddr: %02x Value: ", i2ctool->bus, i2ctool->addr, i2ctool->regaddr); if (i2ctool->width == 8) { i2ctool_printf(i2ctool, "%02x\n", result); } else { i2ctool_printf(i2ctool, "%04x\n", result); } } else { i2ctool_printf(i2ctool, g_i2cxfrerror, argv[0], -ret); break; } /* Auto-increment the address if so configured */ if (i2ctool->autoincr) { regaddr++; } } (void)up_i2cuninitialize(dev); return ret; }
int I2C::init() { int ret = OK; unsigned bus_index; // attach to the i2c bus _dev = up_i2cinitialize(_bus); if (_dev == nullptr) { debug("failed to init I2C"); ret = -ENOENT; goto out; } // the above call fails for a non-existing bus index, // so the index math here is safe. bus_index = _bus - 1; // abort if the max frequency we allow (the frequency we ask) // is smaller than the bus frequency if (_bus_clocks[bus_index] > _frequency) { (void)up_i2cuninitialize(_dev); _dev = nullptr; log("FAIL: too slow for bus #%u: %u KHz, device max: %u KHz)", _bus, _bus_clocks[bus_index] / 1000, _frequency / 1000); ret = -EINVAL; goto out; } // set the bus frequency on the first access if it has // not been set yet if (_bus_clocks[bus_index] == 0) { _bus_clocks[bus_index] = _frequency; } // set frequency for this instance once to the bus speed // the bus speed is the maximum supported by all devices on the bus, // as we have to prioritize performance over compatibility. // If a new device requires a lower clock speed, this has to be // manually set via "fmu i2c <bus> <clock>" before starting any // drivers. // This is necessary as automatically lowering the bus speed // for maximum compatibility could induce timing issues on // critical sensors the adopter might be unaware of. I2C_SETFREQUENCY(_dev, _bus_clocks[bus_index]); // call the probe function to check whether the device is present ret = probe(); if (ret != OK) { debug("probe failed"); goto out; } // do base class init, which will create device node, etc ret = CDev::init(); if (ret != OK) { debug("cdev init failed"); goto out; } // tell the world where we are log("on I2C bus %d at 0x%02x (bus: %u KHz, max: %u KHz)", _bus, _address, _bus_clocks[bus_index] / 1000, _frequency / 1000); out: if ((ret != OK) && (_dev != nullptr)) { up_i2cuninitialize(_dev); _dev = nullptr; } return ret; }
static inline int ov2640_camera_initialize(void) { FAR struct i2c_dev_s *i2c; uint32_t actual; int ret; /* Get the I2C driver that interfaces with the camers (OV2640_BUS)*/ i2c = up_i2cinitialize(OV2640_BUS); if (!i2c) { gdbg("ERROR: Failed to initialize TWI%d\n", OV2640_BUS); return EXIT_FAILURE; } /* Enable clocking to the ISI peripheral */ sam_isi_enableclk(); /* Configure OV2640 pins * * ISI: * - HSYNC, VSYNC, PCK * - 8 data bits for 8-bit color * PCK * - PCK1 provides OV2640 system clock */ sam_configpio(PIO_ISI_HSYNC); sam_configpio(PIO_ISI_VSYNC); sam_configpio(PIO_ISI_PCK); sam_configpio(PIO_ISI_D0); sam_configpio(PIO_ISI_D1); sam_configpio(PIO_ISI_D2); sam_configpio(PIO_ISI_D3); sam_configpio(PIO_ISI_D4); sam_configpio(PIO_ISI_D5); sam_configpio(PIO_ISI_D6); sam_configpio(PIO_ISI_D7); sam_configpio(PIO_PMC_PCK1); /* Configure and enable the PCK1 output */ actual = sam_pck_configure(PCK1, OV2640_FREQUENCY); gvdbg("Desired PCK1 frequency: %ld Actual: %ld\n", (long)OV2640_FREQUENCY, (long)actual); sam_pck_enable(PCK1, true); /* Configure the ISI peripheral */ #warning Missing Logic /* Initialize the OV2640 camera */ ret = ov2640_initialize(i2c); if (ret < 0) { gdbg("ERROR: Failed to initialize the OV2640: %d\n", ret); return EXIT_FAILURE; } return EXIT_FAILURE; }
void board_initialize(void) { dbg("%d MHz\n", STM32_SYSCLK_FREQUENCY / 1000000); #if defined(CONFIG_GPIO_CHIP_STM32) stm32_gpio_init(); #endif #ifdef CONFIG_STM32_LPTIM1 stm32_lptim1_on(); #endif #ifdef CONFIG_STM32_SPI stm32_spiinitialize(); #endif #ifdef CONFIG_MODS_DIET mods_init(); #endif #ifndef CONFIG_BOARD_INITTHREAD # error "Must enable INITTHREAD" #endif #ifdef CONFIG_DEVICE_CORE device_table_register(&muc_device_table); #ifdef CONFIG_FUSB302 fusb302_register(GPIO_MODS_FUSB302_INT_N, GPIO_MODS_VBUS_PWR_EN); #endif #ifdef CONFIG_FUSB302_USB_EXT extern struct device_driver fusb302_usb_ext_driver; device_register_driver(&fusb302_usb_ext_driver); #endif #ifdef CONFIG_FUSB302_EXT_POWER extern struct device_driver fusb302_ext_power_driver; device_register_driver(&fusb302_ext_power_driver); #endif #ifdef CONFIG_MODS_RAW extern struct device_driver mods_raw_driver; device_register_driver(&mods_raw_driver); #endif #ifdef CONFIG_MODS_RAW_BLINKY extern struct device_driver mods_raw_blinky_driver; device_register_driver(&mods_raw_blinky_driver); #endif #ifdef CONFIG_MODS_RAW_TERMAPP extern struct device_driver mods_raw_termapp_driver; device_register_driver(&mods_raw_termapp_driver); #endif #ifdef CONFIG_MODS_RAW_TEMPERATURE extern struct device_driver mods_raw_temperature_driver; device_register_driver(&mods_raw_temperature_driver); #endif #ifdef CONFIG_GREYBUS_MODS_PTP_DEVICE extern struct device_driver mods_ptp_driver; device_register_driver(&mods_ptp_driver); #endif #ifdef CONFIG_CHARGER_DEVICE_BQ24292 extern struct device_driver bq24292_charger_driver; device_register_driver(&bq24292_charger_driver); #endif #ifdef CONFIG_CHARGER_DEVICE_BQ25896 extern struct device_driver bq25896_charger_driver; device_register_driver(&bq25896_charger_driver); #endif #ifdef CONFIG_GREYBUS_MODS_PTP_CHG_DEVICE_SWITCH extern struct device_driver switch_ptp_chg_driver; device_register_driver(&switch_ptp_chg_driver); #endif #ifdef CONFIG_MAX17050_DEVICE extern struct device_driver batt_driver; device_register_driver(&batt_driver); #endif #ifdef CONFIG_BATTERY_TEMP_DEVICE_MAX17050 extern struct device_driver max17050_battery_temp_driver; device_register_driver(&max17050_battery_temp_driver); #endif #ifdef CONFIG_BATTERY_LEVEL_DEVICE_MAX17050 extern struct device_driver max17050_battery_level_driver; device_register_driver(&max17050_battery_level_driver); #endif #ifdef CONFIG_BATTERY_VOLTAGE_DEVICE_MAX17050 extern struct device_driver max17050_battery_voltage_driver; device_register_driver(&max17050_battery_voltage_driver); #endif #ifdef CONFIG_MHB_APBE_CTRL_DEVICE extern struct device_driver apbe_pwrctrl_driver; device_register_driver(&apbe_pwrctrl_driver); #endif #ifdef CONFIG_BATTERY_GOOD_DEVICE_COMP extern struct device_driver comp_batt_good_driver; device_register_driver(&comp_batt_good_driver); #endif #ifdef CONFIG_GREYBUS_SENSORS_EXT_DUMMY_PRESSURE extern struct device_driver sensor_dummy_pressure_driver; device_register_driver(&sensor_dummy_pressure_driver); #endif #ifdef CONFIG_GREYBUS_SENSORS_EXT_DUMMY_ACCEL extern struct device_driver sensor_dummy_accel_driver; device_register_driver(&sensor_dummy_accel_driver); #endif #ifdef CONFIG_HDMI_DISPLAY extern struct device_driver hdmi_display_driver; device_register_driver(&hdmi_display_driver); #endif #ifdef CONFIG_STM32_UART_DEVICE extern struct device_driver stm32_uart_driver; device_register_driver(&stm32_uart_driver); #endif #if CONFIG_MHB_UART extern struct device_driver mhb_driver; device_register_driver(&mhb_driver); #endif #ifdef CONFIG_MHB_DSI_DISPLAY extern struct device_driver dsi_display_driver; device_register_driver(&dsi_display_driver); #endif #ifdef CONFIG_BACKLIGHT_DCS extern struct device_driver dcs_backlight_driver; device_register_driver(&dcs_backlight_driver); #endif #ifdef CONFIG_BACKLIGHT_ISL98611 extern struct device_driver isl98611_backlight_driver; device_register_driver(&isl98611_backlight_driver); #endif #ifdef CONFIG_BACKLIGHT_LM27965 extern struct device_driver lm27965_backlight_driver; device_register_driver(&lm27965_backlight_driver); #endif #if defined(CONFIG_MHB_CAMERA) extern struct device_driver cam_ext_mhb_driver; device_register_driver(&cam_ext_mhb_driver); #endif #if defined(CONFIG_CAMERA_IMX220) extern struct device_driver imx220_mhb_camera_driver; device_register_driver(&imx220_mhb_camera_driver); #endif #if defined(CONFIG_CAMERA_IMX230) extern struct device_driver imx230_mhb_camera_driver; device_register_driver(&imx230_mhb_camera_driver); #endif #ifdef CONFIG_MODS_AUDIO_TFA9890 extern struct device_driver tfa9890_i2s_direct_driver; device_register_driver(&tfa9890_i2s_direct_driver); extern struct device_driver tfa9890_audio_dev_driver; device_register_driver(&tfa9890_audio_dev_driver); #endif #ifdef CONFIG_MODS_RAW_FACTORY extern struct device_driver display_mux_driver; device_register_driver(&display_mux_driver); extern struct device_driver mods_raw_factory_driver; device_register_driver(&mods_raw_factory_driver); #endif #endif #if defined(CONFIG_CHARGER_BQ24292) (void)bq24292_driver_init(GPIO_MODS_CHG_INT_N, GPIO_MODS_CHG_PG_N); #endif #ifdef CONFIG_BATTERY_MAX17050 struct i2c_dev_s *i2c = up_i2cinitialize(MAX17050_I2C_BUS); if (i2c) { g_battery = max17050_initialize(i2c, MAX17050_I2C_FREQ, GPIO_MODS_CC_ALERT); if (!g_battery) { up_i2cuninitialize(i2c); } } # if defined(CONFIG_BATTERY_STATE) /* Must be initialized after MAX17050 core driver has been initialized */ battery_state_init(); # endif #endif #if !defined(CONFIG_GREYBUS_PTP_EXT_SUPPORTED) /* Set the power paths to be able to use USB VBUS as the system power and * to prevent applying voltage to VBUS pin on the Mod connector. Also, * prevent accepting power from the PCARD VBUS connection. */ gpio_set_value(GPIO_MODS_CHG_VINA_EN, 1); gpio_set_value(GPIO_MODS_CHG_VINB_EN, 0); #endif }