void bt_init() { DEBUG("bt_init\n"); //get module type eeprom_busy_wait(); bt_module_type = eeprom_read_byte(&config_ro.bt_module_type); //init bt_uart bt_uart.InitBuffers(BUFFER_SIZE * 2, BUFFER_SIZE); //pin init GpioSetDirection(BT_EN, OUTPUT); GpioSetDirection(BT_RESET, OUTPUT); GpioSetDirection(BT_RTS, OUTPUT); //power is off GpioWrite(BT_RTS, LOW); GpioWrite(BT_EN, LOW); GpioWrite(BT_RESET, LOW); //IRQ init GpioSetDirection(BT_CTS, INPUT); GpioSetPull(BT_CTS, gpio_pull_down); GpioSetInterrupt(BT_CTS, gpio_interrupt1, gpio_rising); }
void LcdInit(LcdSpi* lcd) { uint8_t i; // 132x32 uint8_t initSeqTx[] = {0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x23, 0x81, 0x1F, 0xAC, 0x00, 0xAF}; // 128x64 //uint8_t initSeqTx[] = {0x40, 0xA1, 0xC0, 0xA6, 0xA2, 0x2F, 0xF8, 0x00, 0x27, 0x81, 0x10, 0xAC, 0x00, 0xAF}; if (!lcd) { return; } GpioExport(PIN_LCD_nRST); GpioExport(PIN_LCD_A0); GpioSetDirection(PIN_LCD_nRST, 1); GpioSetDirection(PIN_LCD_A0, 1); GpioSetValue(PIN_LCD_nRST, 0); usleep(10000); GpioSetValue(PIN_LCD_nRST, 1); usleep(10000); GpioSetValue(PIN_LCD_A0, 0); for (i = 0; i < sizeof(initSeqTx); i++) { LcdWriteByte(lcd->mS0, initSeqTx[i]); usleep(10000); } }
void gps_start() { GPS_UART_PWR_ON; gps_uart.Init(GPS_UART, 9600); gps_uart.SetInterruptPriority(MEDIUM); GpioSetDirection(GPS_EN, OUTPUT); //active high GpioWrite(GPS_EN, LOW); GpioSetDirection(GPS_TIMER, INPUT); //active low, otherwise open-drain GpioSetPull(GPS_TIMER, gpio_pull_up); GpioSetInterrupt(GPS_TIMER, gpio_interrupt1, gpio_falling); GpioSetDirection(GPS_RESET, OUTPUT); //active low GpioWrite(GPS_RESET, LOW); GpioWrite(GPS_EN, HIGH); _delay_ms(10); GpioWrite(GPS_RESET, LOW); _delay_ms(20); GpioWrite(GPS_RESET, HIGH); gps_parser_state = GPS_IDLE; fc.gps_data.valid = false; fc.gps_data.fix = 0; fc.gps_data.fix_cnt = 0; for (uint8_t i = 0; i < GPS_SAT_CNT; i++) { fc.gps_data.sat_id[i] = 0; fc.gps_data.sat_snr[i] = 0; } }
void ButtonInit(void) { GpioExport(PIN_KEY_1); GpioExport(PIN_KEY_2); GpioExport(PIN_KEY_3); GpioSetDirection(PIN_KEY_1, 0); GpioSetDirection(PIN_KEY_2, 0); GpioSetDirection(PIN_KEY_3, 0); GpioSetEdge(PIN_KEY_1, edge_falling); GpioSetEdge(PIN_KEY_2, edge_falling); GpioSetEdge(PIN_KEY_3, edge_falling); #ifdef RPI_PULLUP GpioRpiSetup(); GpioRpiSetPullUpDown(PIN_KEY_1, PUD_UP); GpioRpiSetPullUpDown(PIN_KEY_2, PUD_UP); GpioRpiSetPullUpDown(PIN_KEY_3, PUD_UP); #endif #ifdef BPI_PULLUP GpioSetPullResistor(PIN_KEY_1, pull_up); GpioSetPullResistor(PIN_KEY_2, pull_up); GpioSetPullResistor(PIN_KEY_3, pull_up); #endif }
void mems_power_init() { eeprom_busy_wait(); hw_revision = eeprom_read_byte(&config_ro.hw_revision); GpioSetDirection(MEMS_EN, OUTPUT); if (hw_revision == HW_REW_1504) { GpioSetDirection(REV_1504_MEMS_EN_2, OUTPUT); GpioSetDirection(REV_1504_I2C_EN, OUTPUT); } }
void gps_stop() { GpioSetDirection(GPS_EN, INPUT); GpioSetDirection(GPS_RESET, INPUT); fc.gps_data.valid = false; fc.gps_data.fix = 0; fc.gps_data.fix_cnt = 0; GpioSetPull(GPS_TIMER, gpio_totem); gps_init_ok = false; gps_uart.Stop(); GPS_UART_PWR_OFF; }
void SystemInit() { //bt reset default HIGH (bt in reset) //GpioSetInvert(bt_reset, ON); GpioWrite(bt_reset, HIGH); GpioSetDirection(bt_reset, OUTPUT); //bt shdn default HIGH (nrf off) GpioSetInvert(bt_shdn, ON); GpioWrite(bt_shdn, HIGH); GpioSetDirection(bt_shdn, OUTPUT); //button setup (High if pressed) GpioSetPull(user_button, gpio_pull_up); GpioSetInvert(user_button, ON); GpioSetDirection(user_button, INPUT); // }
LcdSpi* LcdOpen(Spi* s0) { LcdSpi *lcd; lcd = (LcdSpi*)malloc(sizeof(LcdSpi)); if (!lcd) { return NULL; } lcd->mS0 = s0; lcd->mRed = 0; lcd->mGreen = 0; lcd->mBlue = 0; // Export Kernel GPIO into Userspace GpioExport(PIN_LED_RED); GpioExport(PIN_LED_GREEN); GpioExport(PIN_LED_BLUE); GpioSetDirection(PIN_LED_RED, 1); GpioSetDirection(PIN_LED_GREEN, 1); GpioSetDirection(PIN_LED_BLUE, 1); return lcd; }
void io_init() { if (hw_revision == HW_REW_1504) { GpioSetDirection(IO1, OUTPUT); } if (hw_revision == HW_REW_1506) { GpioSetDirection(IO0, OUTPUT); GpioSetDirection(IO1, OUTPUT); GpioSetDirection(IO2, OUTPUT); GpioSetDirection(IO3, OUTPUT); GpioSetDirection(IO4, OUTPUT); } }
bool storage_init() { uint8_t res; GpioSetPull(SD_IN, gpio_pull_up); GpioSetDirection(SD_IN, INPUT); DEBUG("SD_IN %d\n", GpioRead(SD_IN)); if (!SD_CARD_DETECT) return false; //power spi & sdcard SD_EN_ON; SD_SPI_PWR_ON; DEBUG("Mounting SD card ... "); for (uint8_t i = 0; i < 5; i++) { //power spi & sdcard SD_EN_ON; SD_SPI_PWR_ON; res = f_mount(&FatFs, "", 1); /* Give a work area to the default drive */ DEBUG("%d ", i + 1); if (res == RES_OK) break; sd_spi_usart.Stop(); //power spi & sdcard SD_EN_OFF; SD_SPI_PWR_OFF; for (uint8_t j = 0; j < i +1; j++) _delay_ms(10); } if (res != RES_OK) { DEBUG("Error %02X\n", res); sd_spi_usart.Stop(); //power spi & sdcard SD_EN_OFF; SD_SPI_PWR_OFF; sd_avalible = false; return false; } DEBUG("OK\n"); uint32_t size; FATFS * FatFs1; res = f_getfree("", &size, &FatFs1); // DEBUG1("f_getfree res = %d, size = %lu MiB", res, size / 256); uint32_t sector_count; res = disk_ioctl(0, GET_SECTOR_COUNT, §or_count); // DEBUG1("GET_SECTOR_COUNT res = %d, size = %lu", res, sector_count); uint16_t sector_size; res = disk_ioctl(0, GET_SECTOR_SIZE, §or_size); // DEBUG1("GET_SECTOR_SIZE res = %d, size = %u", res, sector_size); storage_space = sector_count * sector_size; storage_free_space = size * 4 * 1024; DEBUG("Disk info\n"); DEBUG(" sector size %12u\n", sector_size); DEBUG(" sector count %12lu\n", sector_count); DEBUG(" total space %12lu\n", storage_space); DEBUG(" free space %12lu\n", storage_free_space); sd_avalible = true; return true; }
void fc_init() { DEBUG(" *** Flight computer init ***\n"); //load configuration cfg_load(); //start values eeprom_busy_wait(); active_page = eeprom_read_byte(&config.gui.last_page); fc.epoch_flight_start = 0; fc.autostart_state = false; fc.temp_step = 0; //init calculators vario_init(); audio_init(); gps_init(); if (fc.use_gps) gps_start(); bt_init(); // if (fc.use_flage & ENABLE_BT) // bt_module_init(); //VCC to baro, acc/mag gyro MEMS_POWER_ON; GpioSetDirection(IO0, OUTPUT); GpioWrite(IO0, HIGH); //init and test i2c if (!mems_i2c_init()) { DEBUG("ERROR I2C\n"); led_set(0xFF, 0, 0); } //Barometer ms5611.Init(&mems_i2c, MS5611_ADDRESS_CSB_LO); //Magnetometer + Accelerometer lsm303d_settings lsm_cfg; lsm_cfg.enabled = true; lsm_cfg.accOdr = lsm_acc_1600Hz; lsm_cfg.accScale = lsm_acc_16g; lsm_cfg.magOdr = lsm_mag_100Hz; lsm_cfg.magScale = lsm_mag_4g; lsm_cfg.magHiRes = true; lsm_cfg.tempEnable = false; //Gyro l3gd20_settings l3g_cfg; l3g_cfg.enabled = true; l3g_cfg.bw = l3g_50Hz; l3g_cfg.odr = l3g_760Hz; l3g_cfg.scale = l3g_2000dps; sht21_settings sht_cfg; sht_cfg.rh_enabled = true; sht_cfg.temp_enabled = true; //XXX: do self-test? lsm303d.Init(&mems_i2c, lsm_cfg); lsm303d.Start(); l3gd20.Init(&mems_i2c, l3g_cfg); l3gd20.Start(); sht21.Init(&mems_i2c, sht_cfg); //Measurement timer FC_MEAS_TIMER_PWR_ON; fc_meas_timer.Init(FC_MEAS_TIMER, timer_div256); //125 == 1ms fc_meas_timer.SetInterruptPriority(MEDIUM); fc_meas_timer.EnableInterrupts(timer_overflow | timer_compareA | timer_compareB | timer_compareC); fc_meas_timer.SetTop(125 * 10); // == 10ms fc_meas_timer.SetCompare(timer_A, 100); // == 0.64ms fc_meas_timer.SetCompare(timer_B, 430); // == 2.7ms fc_meas_timer.SetCompare(timer_C, 555); // == 3.7ms fc_meas_timer.Start(); DEBUG(" *** FC init done ***\n"); }