Инструкция Bip | Application develop for BipOS ( SDK ) EN

MNVolkov

Разработчик
Команда форума
Сообщения
316
Реакции
2,324
Баллы
463
Ваше "умное" устройство
Amazfit Bip
Application develop for BipOS
Software Development Kit (SDK)

for MNVolkov BipOS

Intro
From version MNVolkov BipOS 0.5 the startup code of the applications is completely redisigned. Each application now is a separate file stored in resources. The executable file format is Arm-elf (or simply"elf"). The mod got a new name BipOS. When the MOD starts, resources are scanned for applications. Each firmware has a different amount of resources, and applications are always placed at the end. Therefore, the loader looks for resources by Elf signature starting with resource 930. Found applications are placed in the menu "Applications".
In order to improve overall convenience and reduce the number of incompatibilities designed firmware independent applications. So one and the same Calculator will work both on Latin 1.1.5.12 and not latin 1.1.2.05 with no changes (you only need to place it in the RES file of the corresponding version). Independence from the firmware managed through using of a universal library libbip.a which contains the addresses of the firmware functions. After loading the elf into RAM, the internal addresses of functions and variables are relocated, and library addresses of functions are changed to real addresses of functions in firmware.

Development environment
To develop applications, you will need a development environment and a compiler. As a development environment I use Notepad++ . Probably, you can configure Code:: Blocks or other IDE I did not get to this, postponed for the future. Installing a specialized IDE will certainly increase the usability of development. I will not dwell on the development environment.

Compiler
I use the GNU Embedded Toolchain for Arm to build the application. The following steps are required for installation:

  1. Download toolchain here:

    Пожалуйста войдите или зарегистрируйтесь для просмотра скрытого текста.


    Download the file gcc-arm-none-eabi-8-2019-q3-update-win32-sha2.exe ( or a more recent edition) with the following description: Windows 32-bit Installer (Signed for Windows 7 and later)
  2. You can set everything by default, at the end of the installation, set all the checkboxes
  3. It is recommend that you add to system PATH variable the path to the compiler bin folder
Library
The library includes both addresses of firmware functions and some functions that are written to facilitate the development of user applications, such as menu functions. The library must be unzipped to a folder at the same level as the application folders. The path to this folder will be specified in the build script.
У вас нет разрешения на просмотр содержимого!

Sample application
Specifically to facilitate the entry of prepared a sample application in C template_app. The functionality is simple: a working screen of the application is created, when you click in the center of the screen, the background color and labels are change.
You can use this example as a template. To do this, create a new application folder and copy the sample files to it. The name of the application folder in the build script is taken as the service name of the application.
The name displayed in the list of applications must be entered in the label.txt in this case after the name should not be any characters or line feed.
To build the application use .bat file. The build is starting by running the .bat file inside the folder without parameters. All compiler and linker parameters compatible with the BipOS loader are included in this script.
Sample application (with RU comments)
У вас нет разрешения на просмотр содержимого!

Sample application (with EN comments - thanx @Bugmenot1 )
У вас нет разрешения на просмотр содержимого!

Sources on GitHub

Пожалуйста войдите или зарегистрируйтесь для просмотра скрытого текста.



Пожалуйста войдите или зарегистрируйтесь для просмотра скрытого текста.



Description of App lifecycle
Translate from Russian by @CennoxX - Инструкция - Bip | Application develop for BipOS ( SDK ) EN

Build RES file and load into clock
To run the elf you need to load it in device. To do this, you need to put it in a RES file. To build RES files was developed a special program for PC (Win32) with which you can add to your existing RES file required applications. ResPack.exe is a console application to perform simple operations RES files Amazfit Bip: display content with brief information for each resource, unpacking raw data of resources, making alignment string resources version 61 and 69 to solve the disappearance of text when loading a custom resource and add any files to the resources.
To add application files to an existing RES file run from the command line:
Code:
Код:
ResPack -a <resulting_RES> <source_RES> <files which should be added>
Resulting RES file can be flashed by usual way, for example, with GadgetBridge. To update the data in memory, the clock must be restarted after the resource update. This can be done either through the settings menu by turning off and turning on the device.
У вас нет разрешения на просмотр содержимого!

Although the use of the BipOS loader significantly reduces "breaking" of your watch, you should still be careful. Consider the algorithms of your app, avoid infinite loops, avoid the writing in the memory area not specifically intended for use by your application, etc. Whatever you do, you do so at your own risk, no responsibility for the consequences of your actions is not responsible. This instruction is informational in nature, before performing any action you should be aware of all that you are going to do and what the consequences will come, take these likely consequences.


The development process is discussed in this topic.
 
Последнее редактирование:

totalnoob43

Новичок
Сообщения
29
Реакции
27
Баллы
13
Ваше "умное" устройство
Amazfit Bip
I had a look at the header files, I see that all the comments are in Russian. Would it be ok if I translated and uploaded them here?
 
  •  Мне нравится
Реакции: LORD

MNVolkov

Разработчик
Команда форума
Сообщения
316
Реакции
2,324
Баллы
463
Ваше "умное" устройство
Amazfit Bip
Ок, I will try to do it soon
 

Bugmenot1

Забаненный
Сообщения
12
Реакции
10
Баллы
43
Ваше "умное" устройство
Amazfit Bip
Обратите внимание, что если вы хотите заключить сделку с этим пользователем, он заблокирован.
I tried to translate the files, so you can take a look at them and correct wrong items.
 

Вложения

Czapla

Новичок
Сообщения
23
Реакции
11
Баллы
13
Ваше "умное" устройство
Amazfit Bip
Would you manage to create an application in which you can save a note in the res file, for example a timetable, and it was different for each day of the week?
 

jiri.forst

Новичок
Сообщения
1
Реакции
2
Баллы
13
Ваше "умное" устройство
Amazfit Bip
Would it be possible to upload this on GitHub? It would be great to have pull requests, issues etc.
 

totalnoob43

Новичок
Сообщения
29
Реакции
27
Баллы
13
Ваше "умное" устройство
Amazfit Bip
I tried to translate the files, so you can take a look at them and correct wrong items.
Just checked with my unfinished mess, it's more or less the same, good job!
Could you upload the translated res with all applications please or write a short how to use your template? Thank you very much
I too find the template a bit too short, I would like to see the code for the calendar and calculator to get a better idea, but I'll start working with what we have.
 

MNVolkov

Разработчик
Команда форума
Сообщения
316
Реакции
2,324
Баллы
463
Ваше "умное" устройство
Amazfit Bip
Would it be possible to upload this on GitHub? It would be great to have pull requests, issues etc.
I will try.
Just checked with my unfinished mess, it's more or less the same, good job!
I too find the template a bit too short, I would like to see the code for the calendar and calculator to get a better idea, but I'll start working with what we have.
Ok, I will share calendar sources here or github
 

MNVolkov

Разработчик
Команда форума
Сообщения
316
Реакции
2,324
Баллы
463
Ваше "умное" устройство
Amazfit Bip
Would it be possible to upload this on GitHub? It would be great to have pull requests, issues etc.
Calendar application source code on GitHub:

Пожалуйста войдите или зарегистрируйтесь для просмотра скрытого текста.


Template application source code on GitHub:

Пожалуйста войдите или зарегистрируйтесь для просмотра скрытого текста.

 

bugmenotnot

Забаненный
Сообщения
1
Реакции
2
Баллы
23
Обратите внимание, что если вы хотите заключить сделку с этим пользователем, он заблокирован.
Я прошу прощения за мой плохой русский, я носитель английского языка. Я пытаюсь создать метод для Linux, а не Windows. Можете ли вы поделиться ResPacker на Github? Я не уверен, как обрабатывается сжатие измененного файла ELF, и было бы очень полезно посмотреть, как это работает!
 

trace

Разработчик
Команда форума
Сообщения
495
Реакции
1,355
Баллы
233
Ваше "умное" устройство
Amazfit Bip

MNVolkov

Разработчик
Команда форума
Сообщения
316
Реакции
2,324
Баллы
463
Ваше "умное" устройство
Amazfit Bip
Последнее редактирование модератором:

iwalton3

Новичок
Сообщения
5
Реакции
5
Баллы
3
Ваше "умное" устройство
Amazfit Bip
I translated the libbip.h comments and the firmware patching script to English. I have also included instructions on how to defeat updates on platforms such as iOS where you need to keep the MiFit app installed. (You can flash firmware with AmazTools on iOS.)
 

Вложения

iwalton3

Новичок
Сообщения
5
Реакции
5
Баллы
3
Ваше "умное" устройство
Amazfit Bip
I was using the custom firmware for about a day and I started having problems with the MiFit app flashing updated resources to the device. (It also tried to update the A-GPS in the background, which was odd as that was already up to date.) It looks like the resources version is specified in the header of the resources file, but if you increase the version, you cannot use the custom firmware as that also checks the resources version and will refuse to start with the lower version. I suspect the solution would be to either patch the custom firmware to not care about the resources version, or to have it lie to the MiFit app that the version is up to date.

I don't know enough about how to reverse or read the firmware though (the resources version is a single byte, so searching that in a hex editor is difficult), so for now I switched back to the stock firmware. If I was on Android, I could just use GadgetBridge, which won't try to flash firmware without asking. The firmware files I posted should still be useful though, as all of the comments in the libbip library and the calendar app are translated to English (via Google Translate).
 

Archon

Модератор
Команда форума
Сообщения
592
Реакции
722
Баллы
133
Ваше "умное" устройство
Amazfit Bip
@iwalton3, what's the version of custom firmware you used?
 

CennoxX

Новичок
Сообщения
4
Реакции
12
Баллы
13
Ваше "умное" устройство
Amazfit Bip
I've translated this short description of the operating system for the general understanding from @MNVolkov.

application screen life cycle
The watch operates under the control of an operating system with preemptive multitasking. This means several processes run simultaneously in the watch. All screens, all visible watch activity occurs in the DisplayTask process. A launched elf runs in the same process. In order to ensure smooth operation, without lags and deterioration of the battery power, it is necessary to fulfill the condition that all user functions should work as quickly as possible and return the control to the DisplayTask process as soon as possible. Furthermore, it is impossible to arrange an infinite loop in the main function (as in an Arduino).
The life cycle of the application screen begins with the transfer of the control to the function that creates the screen. It is called void show_screen (void * param0) (from now on function names of template_app.c are used). The function executes its actions and returns control to the process. The key action to create a screen is to call the reg_menu system function with a pointer to the struct regmenu_ screen. This structure contains pointers to functions handlers of system events, such as touchscreen events (presses, swipes), button presses, long button presses, triggering the screen timer, calling the screen after running the overlay screen.
There are two global variables temp_buf_1 and temp_buf_2 to store data of our application.
  • temp_buf_1
    Used only for temporary storage of data between screen callbacks, provided that the data in the pointer can easily be recreated by the show_menu_… function of the screen. They can be destroyed and the memory of this pointer can be freed at any time after a notification or call (reg_menu with the overlay 1 parameter). It can be used as display variable of the current screen, for example the cursor position, the animation number for the screen_job, etc.
  • temp_buf_2
    This can be used both to store data created in the show_menu _… function and transferred from the previous screen. It can be used to store data that this screen works with: editable alarm clock, typed text, etc. Here application data should be stored, including a pointer to the data of the running process. In general, the data that can be stored in temp_buf_1 could be stored here too if convenient.
Note that when the reg_menu system function is called, the memory is freed at both temp_buf_1 and temp_buf_2 pointers. This avoids memory leaks when switching between the different menu screens of the watch.

main function
The purpose of this function is only to transfer the control to the show_screen function with all saved parameters.

show_screen function
The purpose of the show_screen function is to prepare the screen data, allocate the necessary amounts of memory, build the graphic part, and set up all callbacks. This function is called in two cases:
1. If it is called from another screen, for example from the "Applications" menu. In this case, a pointer to the structure of a launched elf of the type Elf_proc_ is passed as the param0 parameter.
2. If it is called at the end of the running the overlay screen (for example because of an incoming call, a notification, a request to move, etc.). In this case, a pointer to the allocated memory of the screen is passed as the parameter, which is contained at the address temp_buf_2.

In the body of the show_screen function, it is necessary to set up the handlers for the created screen using the reg_menu function.

dispatch_func function
This function is the touchscreen event handler. It is called by the operating system each time one of the following events occurs: pressing on the screen, one of four swipes: up, down, left, right. The function parameter is a pointer to a filled data structure of the type struct gesture_. After processing the necessary rendering, you need to return. In the case of drawing graphic elements to the screen, it is necessary to copy them from the video memory to the display.

key_press_func function
This function is the same as dispatch_func but for the event of a short press on the side button. The function has no parameters.

long_key_press_func function
This function is the same as dispatch_func, but for the event of a long press on the side button. The function has no parameters.

screen_job function
This function is the screen timer handler. It is called after the time interval of the timer, whose duration is set by the set_update_period function. The screen_job function has no parameters. In case of drawing graphic elements to the screen, it is necessary to copy them from the video memory to the display.

All of the above is implemented in the example template_app. This example contains a minimal set of event handlers and is fully commented.
 

Пользователи, просматривающие эту тему

Сейчас на форуме нет ни одного пользователя.
Сверху Снизу