void ICACHE_FLASH_ATTR user_init(void) { gpio_init(); gpio_output_set(0, 0, 0, 0xFFFFFFFF); //init software uart Softuart_SetPinRx(&softuart,13); Softuart_SetPinTx(&softuart,15); gpio_pin_wakeup_disable(); PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO12); UART_SetPrintPort(UART1); UartDev.data_bits = EIGHT_BITS; UartDev.parity = NONE_BITS; UartDev.stop_bits = ONE_STOP_BIT; uart_init(BIT_RATE_9600, BIT_RATE_115200); //clear noise uart0_sendStr("\r\n\r\n\r\n"); //wifi_set_phy_mode(3); system_phy_set_powerup_option(3); wifi_set_opmode(STATION_MODE); //Set station mode system_phy_set_max_tpw(82); //MAX POWERR! system_phy_set_tpw_via_vdd33(system_get_vdd33()); user_set_station_config(); os_timer_disarm(&init_timer); os_timer_setfn(&init_timer, (os_timer_func_t *)gps_uart_init, NULL); os_timer_arm(&init_timer, 1000, 0); }
STATIC mp_obj_t pyb_adc_read(mp_obj_t self_in) { pyb_adc_obj_t *adc = self_in; if (adc->isvdd) { return mp_obj_new_int(system_get_vdd33()); } else { return mp_obj_new_int(system_adc_read()); } }
// Lua: readvdd33() static int adc_readvdd33( lua_State* L ) { uint32_t vdd33 = 0; if(STATION_MODE == wifi_get_opmode()) { // Bug fix if (wifi_station_get_connect_status()!=0) { return luaL_error( L, "Can't read vdd33 while station is connected" ); } else { vdd33 = system_get_vdd33(); } } else { vdd33 = system_get_vdd33(); } lua_pushinteger(L, vdd33); return 1; }
//Read battery, enable PWM etc. void ICACHE_FLASH_ATTR io_init() { int x; //Between io_init_main and io_init, the firmware will re-initialize some gpios. Re-re-initialize them. gpioInit(); #if NEW_BUTTON //We can only measure the battery status with the nightlight feature on. Nightlight has to be done with pwm off. enableNightlight(1); os_delay_us(1000); x=system_adc_read(); //AD is 1024 at Tout=1V. There is an (800K+1M)/200K resistor divider to lower the battery voltage into that range. //This means that the Tout value of 1024 is reached at a voltage of 10 volt. batteryVoltageMv=(x*10000)/1024; //Okay, initialize PWM. io_pwm_init(); #else x=system_get_vdd33(); batteryVoltageMv=(x*1000)/1024; #endif os_printf("Battery: %d mv\n", batteryVoltageMv); }
// Lua: readvdd33() static int adc_readvdd33( lua_State* L ) { lua_pushinteger(L, system_get_vdd33 ()); return 1; }
uint32 user_GetBatteryVoltageMv() { int r=system_get_vdd33(); int mv=(r*1000)/1024; os_printf("BATTERY VAL: %d, raw %d\n", mv, r); return mv; }
uint16_t EspClass::getVcc(void) { return system_get_vdd33(); }