void buttons_deinit() { GpioSetPull(SWITCH1, gpio_totem); // Middle need to be active to wake up the device // GpioSetPull(SWITCH2, gpio_totem); GpioSetPull(SWITCH3, gpio_totem); }
void buttons_init() { GpioSetPull(SWITCH1, gpio_pull_up); GpioSetInvert(SWITCH1, ON); GpioSetPull(SWITCH2, gpio_pull_up); GpioSetInvert(SWITCH2, ON); GpioSetPull(SWITCH3, gpio_pull_up); GpioSetInvert(SWITCH3, ON); GpioSetInterrupt(SWITCH1, gpio_interrupt0, gpio_bothedges); GpioSetInterrupt(SWITCH2, gpio_interrupt0, gpio_bothedges); GpioSetInterrupt(SWITCH3, gpio_interrupt0, gpio_bothedges); }
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 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 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); // }
void storage_deinit() { DEBUG("storage_deinit\n"); if (!sd_avalible) return; uint8_t res; res = f_mount(NULL, "", 1); //unmount sd_spi_usart.Stop(); sd_avalible = false; GpioSetPull(SD_IN, gpio_totem); //power spi & sdcard SD_EN_OFF; SD_SPI_PWR_OFF; }
void bt_stop() { bt_module_deinit(); GpioSetPull(BT_CTS, gpio_totem); }
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; }