diff --git a/src/config.h b/src/config.h index 982c2f1..9e26a3a 100644 --- a/src/config.h +++ b/src/config.h @@ -27,12 +27,11 @@ #define LILYGO_WATCH_2020_V1 //To use T-Watch2020, please uncomment this line #define LILYGO_WATCH_LVGL //To use LVGL, you need to enable the macro LVGL #define TWATCH_USE_PSRAM_ALLOC_LVGL - #define ENABLE_LVGL_FLUSH_DMA #include /* * firmeware version string */ - #define __FIRMWARE__ "2020082601" + #define __FIRMWARE__ "2020082603" #endif // _CONFIG_H diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index f69c8fb..4f51963 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -52,15 +52,12 @@ LV_IMG_DECLARE(bg2) */ void gui_setup(void) { - lv_coord_t hres = lv_disp_get_hor_res(NULL); - lv_coord_t vres = lv_disp_get_ver_res(NULL); - //Create wallpaper - lv_obj_t *img_bin = lv_img_create( lv_scr_act() , NULL); /*Create an image object*/ - lv_img_set_src(img_bin, &bg2 ); - lv_obj_set_width( img_bin, hres ); - lv_obj_set_height( img_bin, vres ); - lv_obj_align(img_bin, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_t *img_bin = lv_img_create( lv_scr_act() , NULL ); + lv_img_set_src( img_bin, &bg2 ); + lv_obj_set_width( img_bin, lv_disp_get_hor_res( NULL ) ); + lv_obj_set_height( img_bin, lv_disp_get_ver_res( NULL ) ); + lv_obj_align( img_bin, NULL, LV_ALIGN_CENTER, 0, 0 ); mainbar_setup(); /* add the four mainbar screens */ @@ -79,7 +76,7 @@ void gui_setup(void) update_tile_setup(); statusbar_setup(); - lv_disp_trig_activity(NULL); + lv_disp_trig_activity( NULL ); keyboard_setup(); diff --git a/src/gui/mainbar/setup_tile/battery_settings/battery_view.cpp b/src/gui/mainbar/setup_tile/battery_settings/battery_view.cpp index 2768ad0..24e42bd 100644 --- a/src/gui/mainbar/setup_tile/battery_settings/battery_view.cpp +++ b/src/gui/mainbar/setup_tile/battery_settings/battery_view.cpp @@ -196,10 +196,9 @@ static void exit_battery_view_event_cb( lv_obj_t * obj, lv_event_t event ) { void battery_view_update_task( lv_task_t *task ) { char temp[16]=""; - TTGOClass *ttgo = TTGOClass::getWatch(); - if ( pmu_get_battery_percent( ttgo ) >= 0 ) { - snprintf( temp, sizeof( temp ), "%0.1fmAh", ttgo->power->getCoulombData() ); + if ( pmu_get_battery_percent( ) >= 0 ) { + snprintf( temp, sizeof( temp ), "%0.1fmAh", pmu_get_coulumb_data() ); } else { snprintf( temp, sizeof( temp ), "unknown" ); @@ -211,19 +210,19 @@ void battery_view_update_task( lv_task_t *task ) { lv_label_set_text( battery_view_design_cap, temp ); lv_obj_align( battery_view_design_cap, lv_obj_get_parent( battery_view_design_cap ), LV_ALIGN_IN_RIGHT_MID, -5, 0 ); - snprintf( temp, sizeof( temp ), "%0.2fV", ttgo->power->getBattVoltage() / 1000 ); + snprintf( temp, sizeof( temp ), "%0.2fV", pmu_get_battery_voltage() / 1000 ); lv_label_set_text( battery_view_voltage, temp ); lv_obj_align( battery_view_voltage, lv_obj_get_parent( battery_view_voltage ), LV_ALIGN_IN_RIGHT_MID, -5, 0 ); - snprintf( temp, sizeof( temp ), "%0.1fmA", ttgo->power->getBattChargeCurrent() ); + snprintf( temp, sizeof( temp ), "%0.1fmA", pmu_get_battery_charge_current() ); lv_label_set_text( charge_view_current, temp ); lv_obj_align( charge_view_current, lv_obj_get_parent( charge_view_current ), LV_ALIGN_IN_RIGHT_MID, -5, 0 ); - snprintf( temp, sizeof( temp ), "%0.1fmA", ttgo->power->getBattDischargeCurrent() ); + snprintf( temp, sizeof( temp ), "%0.1fmA", pmu_get_battery_discharge_current() ); lv_label_set_text( discharge_view_current, temp ); lv_obj_align( discharge_view_current, lv_obj_get_parent( discharge_view_current ), LV_ALIGN_IN_RIGHT_MID, -5, 0 ); - snprintf( temp, sizeof( temp ), "%0.2fV", ttgo->power->getVbusVoltage() / 1000 ); + snprintf( temp, sizeof( temp ), "%0.2fV", pmu_get_vbus_voltage() / 1000 ); lv_label_set_text( vbus_view_voltage, temp ); lv_obj_align( vbus_view_voltage, lv_obj_get_parent( vbus_view_voltage ), LV_ALIGN_IN_RIGHT_MID, -5, 0 ); } diff --git a/src/gui/splashscreen.cpp b/src/gui/splashscreen.cpp index 3d423ee..2ed9a58 100644 --- a/src/gui/splashscreen.cpp +++ b/src/gui/splashscreen.cpp @@ -82,5 +82,6 @@ void splash_screen_stage_finish( TTGOClass *ttgo ) { delay(1); } lv_obj_del( preload ); + lv_obj_del( preload_label ); lv_task_handler(); } diff --git a/src/hardware/bma.cpp b/src/hardware/bma.cpp index 05d4ada..882451e 100644 --- a/src/hardware/bma.cpp +++ b/src/hardware/bma.cpp @@ -41,7 +41,8 @@ void IRAM_ATTR bma_irq( void ); /* * */ -void bma_setup( TTGOClass *ttgo ) { +void bma_setup( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); bma_event_handle = xEventGroupCreate(); @@ -120,7 +121,8 @@ void IRAM_ATTR bma_irq( void ) { /* * loop routine for handling IRQ in main loop */ -void bma_loop( TTGOClass *ttgo ) { +void bma_loop( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); /* * handle IRQ event */ diff --git a/src/hardware/bma.h b/src/hardware/bma.h index 2461966..cea869f 100644 --- a/src/hardware/bma.h +++ b/src/hardware/bma.h @@ -42,11 +42,11 @@ * * @param ttgo pointer to an TTGOClass */ - void bma_setup( TTGOClass *ttgo ); + void bma_setup( void ); /* * @brief loop function for activity measurement */ - void bma_loop( TTGOClass *ttgo ); + void bma_loop( void ); /* * @brief put bma into standby, depending on ther config */ diff --git a/src/hardware/driver/i2c_bus.cpp b/src/hardware/driver/i2c_bus.cpp new file mode 100644 index 0000000..1094477 --- /dev/null +++ b/src/hardware/driver/i2c_bus.cpp @@ -0,0 +1,94 @@ +#include "i2c_bus.h" +#include "Wire.h" +#include + +void I2C_Bus::scan(void) +{ + uint8_t err, addr; + int nDevices = 0; + for (addr = 1; addr < 127; addr++) { + _port->beginTransmission(addr); + err = _port->endTransmission(); + if (err == 0) { + Serial.print("I2C device found at address 0x"); + if (addr < 16) + Serial.print("0"); + Serial.print(addr, HEX); + Serial.println(" !"); + nDevices++; + } else if (err == 4) { + Serial.print("Unknow error at address 0x"); + if (addr < 16) + Serial.print("0"); + Serial.println(addr, HEX); + } + } + if (nDevices == 0) + Serial.println("No I2C devices found\n"); + else + Serial.println("done\n"); +} + + +uint16_t I2C_Bus::readBytes(uint8_t addr, uint8_t *data, uint16_t len, uint16_t delay_ms) +{ + uint16_t ret = 0; + xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY); + uint8_t cnt = _port->requestFrom(addr, (uint8_t)len, (uint8_t)1); + if (!cnt) { + ret = 1 << 13; + } + uint16_t index = 0; + while (_port->available()) { + if (index > len)return 1 << 14; + if (delay_ms)delay(delay_ms); + data[index++] = _port->read(); + } + xSemaphoreGiveRecursive(_i2c_mux); + return ret; +} + + +uint16_t I2C_Bus::readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len) +{ + uint16_t ret = 0; + xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY); + _port->beginTransmission(addr); + _port->write(reg); + _port->endTransmission(false); + uint8_t cnt = _port->requestFrom(addr, (uint8_t)len, (uint8_t)1); + if (!cnt) { + ret = 1 << 13; + } + uint16_t index = 0; + while (_port->available()) { + if (index > len)return 1 << 14; + data[index++] = _port->read(); + } + xSemaphoreGiveRecursive(_i2c_mux); + return ret; +} + +uint16_t I2C_Bus::writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len) +{ + uint16_t ret = 0; + xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY); + _port->beginTransmission(addr); + _port->write(reg); + for (uint16_t i = 0; i < len; i++) { + _port->write(data[i]); + } + ret = _port->endTransmission(); + xSemaphoreGiveRecursive(_i2c_mux); + return ret ? 1 << 12 : ret; +} + +bool I2C_Bus::deviceProbe(uint8_t addr) +{ + uint16_t ret = 0; + xSemaphoreTakeRecursive(_i2c_mux, portMAX_DELAY); + _port->beginTransmission(addr); + ret = _port->endTransmission(); + xSemaphoreGiveRecursive(_i2c_mux); + return (ret == 0); +} diff --git a/src/hardware/driver/i2c_bus.h b/src/hardware/driver/i2c_bus.h new file mode 100644 index 0000000..76bc381 --- /dev/null +++ b/src/hardware/driver/i2c_bus.h @@ -0,0 +1,26 @@ +#ifndef I2C_BUS_H + #define I2C_BUS_H + + #include + #include "freertos/FreeRTOS.h" + #include "freertos/semphr.h" + + class I2C_Bus { + public: + I2C_Bus(TwoWire &port = Wire, int sda = 21, int scl = 22) + { + _port = &port; + _port->begin(sda, scl); + _i2c_mux = xSemaphoreCreateRecursiveMutex(); + }; + void scan(); + uint16_t readBytes(uint8_t addr, uint8_t *data, uint16_t len, uint16_t delay_ms = 0); + uint16_t readBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len); + uint16_t writeBytes(uint8_t addr, uint8_t reg, uint8_t *data, uint16_t len); + bool deviceProbe(uint8_t addr); + private: + TwoWire *_port; + SemaphoreHandle_t _i2c_mux = NULL; + }; + +#endif // I2C_BUS_H \ No newline at end of file diff --git a/src/hardware/driver/rtc b/src/hardware/driver/rtc new file mode 100644 index 0000000..e69de29 diff --git a/src/hardware/pmu.cpp b/src/hardware/pmu.cpp index 573e6d1..4a2bbef 100644 --- a/src/hardware/pmu.cpp +++ b/src/hardware/pmu.cpp @@ -13,19 +13,19 @@ #include "gui/statusbar.h" EventGroupHandle_t pmu_event_handle = NULL; - void IRAM_ATTR pmu_irq( void ); - pmu_config_t pmu_config; /* * init the pmu: AXP202 */ -void pmu_setup( TTGOClass *ttgo ) { +void pmu_setup( void ) { pmu_event_handle = xEventGroupCreate(); pmu_read_config(); + TTGOClass *ttgo = TTGOClass::getWatch(); + // Turn on the IRQ used ttgo->power->adc1Enable( AXP202_BATT_VOL_ADC1 | AXP202_BATT_CUR_ADC1 | AXP202_VBUS_VOL_ADC1 | AXP202_VBUS_CUR_ADC1, AXP202_ON); ttgo->power->enableIRQ( AXP202_VBUS_REMOVED_IRQ | AXP202_VBUS_CONNECT_IRQ | AXP202_CHARGING_FINISHED_IRQ | AXP202_TIMER_TIMEOUT_IRQ, AXP202_ON ); @@ -249,10 +249,12 @@ void pmu_set_experimental_power_save( bool value ) { /* * loop routine for handling IRQ in main loop */ -void pmu_loop( TTGOClass *ttgo ) { +void pmu_loop( void ) { static uint64_t nextmillis = 0; bool updatetrigger = false; + TTGOClass *ttgo = TTGOClass::getWatch(); + /* * handle IRQ event */ @@ -294,13 +296,15 @@ void pmu_loop( TTGOClass *ttgo ) { if ( !powermgm_get_event( POWERMGM_STANDBY ) ) { if ( nextmillis < millis() || updatetrigger == true ) { nextmillis = millis() + 1000; - statusbar_update_battery( pmu_get_battery_percent( ttgo ), ttgo->power->isChargeing(), ttgo->power->isVBUSPlug() ); - blectl_update_battery( pmu_get_battery_percent( ttgo ), ttgo->power->isChargeing(), ttgo->power->isVBUSPlug() ); + statusbar_update_battery( pmu_get_battery_percent(), ttgo->power->isChargeing(), ttgo->power->isVBUSPlug() ); + blectl_update_battery( pmu_get_battery_percent(), ttgo->power->isChargeing(), ttgo->power->isVBUSPlug() ); } } } -int32_t pmu_get_battery_percent( TTGOClass *ttgo ) { +int32_t pmu_get_battery_percent( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); + if ( ttgo->power->getBattChargeCoulomb() < ttgo->power->getBattDischargeCoulomb() || ttgo->power->getBattVoltage() < 3200 ) { ttgo->power->ClearCoulombcounter(); } @@ -311,4 +315,29 @@ int32_t pmu_get_battery_percent( TTGOClass *ttgo ) { else { return( ttgo->power->getBattPercentage() ); } -} \ No newline at end of file +} + +float pmu_get_battery_voltage( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); + return( ttgo->power->getBattVoltage() ); +} + +float pmu_get_battery_charge_current( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); + return( ttgo->power->getBattChargeCurrent() ); +} + +float pmu_get_battery_discharge_current( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); + return( ttgo->power->getBattDischargeCurrent() ); +} + +float pmu_get_vbus_voltage( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); + return( ttgo->power->getVbusVoltage() ); +} + +float pmu_get_coulumb_data( void ) { + TTGOClass *ttgo = TTGOClass::getWatch(); + return( ttgo->power->getCoulombData() ); +} diff --git a/src/hardware/pmu.h b/src/hardware/pmu.h index ff4a74c..5458308 100644 --- a/src/hardware/pmu.h +++ b/src/hardware/pmu.h @@ -48,13 +48,13 @@ * * @param ttgo pointer to an TTGOClass */ - void pmu_setup( TTGOClass *ttgo ); + void pmu_setup( void ); /* * @brief pmu loop routine, call from powermgm. not for user use * * @param ttgo pointer to an TTGOClass */ - void pmu_loop( TTGOClass *ttgo ); + void pmu_loop( void ); /* * * @brief get the charge of battery in percent @@ -63,7 +63,7 @@ * * @return charge in percent or -1 if unknown */ - int32_t pmu_get_battery_percent( TTGOClass *ttgo ); + int32_t pmu_get_battery_percent( void ); /* * @brief set the axp202 in standby */ @@ -99,5 +99,10 @@ int32_t pmu_get_designed_battery_cap( void ); bool pmu_get_silence_wakeup( void ); void pmu_set_silence_wakeup( bool value ); + float pmu_get_battery_voltage( void ); + float pmu_get_battery_charge_current( void ); + float pmu_get_battery_discharge_current( void ); + float pmu_get_vbus_voltage( void ); + float pmu_get_coulumb_data( void ); #endif // _PMU_H \ No newline at end of file diff --git a/src/hardware/powermgm.cpp b/src/hardware/powermgm.cpp index 8965883..ba2d94f 100644 --- a/src/hardware/powermgm.cpp +++ b/src/hardware/powermgm.cpp @@ -48,23 +48,25 @@ portMUX_TYPE powermgmMux = portMUX_INITIALIZER_UNLOCKED; /* * */ -void powermgm_setup( TTGOClass *ttgo ) { +void powermgm_setup( void ) { powermgm_status = xEventGroupCreate(); - pmu_setup( ttgo ); - bma_setup( ttgo ); + pmu_setup(); + bma_setup(); wifictl_setup(); blectl_read_config(); - timesync_setup( ttgo ); - touch_setup( ttgo ); + timesync_setup(); + touch_setup(); sound_setup(); } /* * */ -void powermgm_loop( TTGOClass *ttgo ) { +void powermgm_loop( void ) { + + TTGOClass *ttgo = TTGOClass::getWatch(); // check if a button or doubleclick was release if( powermgm_get_event( POWERMGM_PMU_BUTTON | POWERMGM_BMA_DOUBLECLICK ) ) { @@ -162,12 +164,12 @@ void powermgm_loop( TTGOClass *ttgo ) { if ( powermgm_get_event( POWERMGM_STANDBY ) ) { vTaskDelay( 100 ); - pmu_loop( ttgo ); - bma_loop( ttgo ); + pmu_loop(); + bma_loop(); } else { - pmu_loop( ttgo ); - bma_loop( ttgo ); + pmu_loop(); + bma_loop(); display_loop( ttgo ); } } diff --git a/src/hardware/powermgm.h b/src/hardware/powermgm.h index abee090..6f5e3d6 100644 --- a/src/hardware/powermgm.h +++ b/src/hardware/powermgm.h @@ -38,13 +38,13 @@ * * @param ttgo pointer to an TTGOClass */ - void powermgm_setup( TTGOClass *ttgo ); + void powermgm_setup( void ); /* * @brief power managment loop routine, call from loop. not for user use * * @param ttgo pointer to an TTGOClass */ - void powermgm_loop( TTGOClass *ttgo ); + void powermgm_loop( void ); /* * @brief trigger a power managemt event * diff --git a/src/hardware/timesync.cpp b/src/hardware/timesync.cpp index 7d76af1..dfa6e7d 100644 --- a/src/hardware/timesync.cpp +++ b/src/hardware/timesync.cpp @@ -37,7 +37,7 @@ timesync_config_t timesync_config; void timesync_wifictl_event_cb( EventBits_t event, char* msg ); -void timesync_setup( TTGOClass *ttgo ) { +void timesync_setup( void ) { timesync_read_config(); time_event_handle = xEventGroupCreate(); diff --git a/src/hardware/timesync.h b/src/hardware/timesync.h index 3d76503..53af3e3 100644 --- a/src/hardware/timesync.h +++ b/src/hardware/timesync.h @@ -40,7 +40,7 @@ * * @param ttgo pointer to an TTGOClass */ - void timesync_setup( TTGOClass *ttgo ); + void timesync_setup( void ); /* * @brief save config for timesync to spiffs */ diff --git a/src/hardware/touch.cpp b/src/hardware/touch.cpp index 48aee7a..93cb916 100644 --- a/src/hardware/touch.cpp +++ b/src/hardware/touch.cpp @@ -29,13 +29,14 @@ lv_indev_t *touch_indev = NULL; static bool touch_read(lv_indev_drv_t * drv, lv_indev_data_t*data); static bool touch_getXY( int16_t &x, int16_t &y ); -void touch_setup( TTGOClass *ttgo ) { +void touch_setup( void ) { touch_indev = lv_indev_get_next( NULL ); touch_indev->driver.read_cb = touch_read; } static bool touch_getXY( int16_t &x, int16_t &y ) { + TTGOClass *ttgo = TTGOClass::getWatch(); TP_Point p; static bool touch_press = false; diff --git a/src/hardware/touch.h b/src/hardware/touch.h index 1c178b2..fd80e2c 100644 --- a/src/hardware/touch.h +++ b/src/hardware/touch.h @@ -29,6 +29,6 @@ * * @param ttgo pointer to an TTGOClass */ - void touch_setup( TTGOClass *ttgo ); + void touch_setup( void ); #endif // _TOUCH_H \ No newline at end of file diff --git a/src/my-ttgo-watch.ino b/src/my-ttgo-watch.ino index 1784b4d..eafdc80 100644 --- a/src/my-ttgo-watch.ino +++ b/src/my-ttgo-watch.ino @@ -74,7 +74,7 @@ void setup() ttgo->rtc->syncToSystem(); splash_screen_stage_update( "init powermgm", 60 ); - powermgm_setup( ttgo ); + powermgm_setup(); splash_screen_stage_update( "init gui", 80 ); gui_setup(); @@ -112,5 +112,5 @@ void loop() { delay(5); gui_loop( ttgo ); - powermgm_loop( ttgo ); + powermgm_loop(); } diff --git a/ttgo-t-watch2020_v1.ino.bin b/ttgo-t-watch2020_v1.ino.bin index ada9a65..8241e75 100644 Binary files a/ttgo-t-watch2020_v1.ino.bin and b/ttgo-t-watch2020_v1.ino.bin differ diff --git a/ttgo-t-watch2020_v1.version.json b/ttgo-t-watch2020_v1.version.json index c84f9d3..9efb366 100644 --- a/ttgo-t-watch2020_v1.version.json +++ b/ttgo-t-watch2020_v1.version.json @@ -1 +1 @@ -{"version":"2020082601","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"} +{"version":"2020082603","host":"http://www.neo-guerillaz.de","file":"ttgo-t-watch2020_v1.ino.bin"}