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

MNVolkov

Разработчик
Команда форума
Сообщения
225
Реакции
1,618
Баллы
323
Ваше "умное" устройство
Amazfit Bip
  • Первое сообщение
  • #1
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

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



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



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

Новичок
Сообщения
25
Реакции
15
Баллы
8
Ваше "умное" устройство
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.
Very much appreciated. I was having a tough time understanding how it all worked.
Сообщения автоматически объединены:

@MNVolkov, I read the documentation, and it seems that you don't encourage running an application in the background. I was thinking of using

void vTaskDelay(int delay_ms);

and

int vibrate(int count, int on_ms, int off_ms);

To create a vibration every hour (like Casios that beep every hour). Do you see a way to create this? I assume I can't leave an applicaiton running after the main terminates, is that correct?
 
Последнее редактирование:

Archon

Друг форума
Сообщения
280
Реакции
279
Баллы
83
Ваше "умное" устройство
Amazfit Bip
@iwalton3, ok, here is it:

.fw file, firmware version, 3 matches:
31 2E 31 2E 32 2E 30 35 (1.1.2.05)

.fw file, resources version, 1 match:
97 FE 9D F8 00 00 29 (bold value is a version in HEX, the previous bytes are required just to identify the exact byte you need)

.res file, resources version, 1 match:
4E 45 52 45 53 29 (bold value is a version in HEX, it's the 6th byte from the beginning of the file; the position of this byte is common to all .res files)
 
Последнее редактирование:

iwalton3

Новичок
Сообщения
5
Реакции
4
Баллы
3
Ваше "умное" устройство
Amazfit Bip
I think that worked! Only time will tell, as it took about a day for Mi Fit to break it last time, but it is running with the reported versions increased on iOS. I've attached the custom firmware and instructions for anyone else on iOS that wants to try this. Of course, if there is a new update, you'll have to modify the firmware version again. The firmware must be identical to the current version, it can't just be higher.
 

Вложения

iwalton3

Новичок
Сообщения
5
Реакции
4
Баллы
3
Ваше "умное" устройство
Amazfit Bip
It got stuck on "Updating A-GPS..." again on iOS. The only way to get it out of it was flash the non-custom firmware. I suspect this A-GPS data gets flashed in the background by the Mi-Fit app daily, since it is time sensitive, and also that the 1.1.2.05 firmware doesn't deal with the data properly.
 

Archon

Друг форума
Сообщения
280
Реакции
279
Баллы
83
Ваше "умное" устройство
Amazfit Bip
@iwalton3, downgrading Mi Fit to 3.5.8 (or 3.5.9, perhaps) and disabling apps auto-update can help, I think. I use Mi Fit 3.5.8 with 1.1.2.05 firmware, and A-GPS updates without any issues. But yep, downgrading apps on iOS is rather tricky.
 

404AccNotFound

Новичок
Сообщения
3
Реакции
0
Баллы
1
Ваше "умное" устройство
Amazfit Bip
Hello,
Just extracted the stock Mili_chaohu.res file to see what is in it using ResPack.exe. Found a bunch of *.BMd files. What are they?
 

Pólux

Друг форума
Сообщения
17
Реакции
43
Баллы
13
Ваше "умное" устройство
Amazfit Bip

000edu

Участник
Сообщения
21
Реакции
101
Баллы
33
Ваше "умное" устройство
Amazfit Bip
@MNVolkov

Hi

First of all, congrats for your great work and thanks for sharing!

I want to keep screen alive even not touching it. Checking randdemo I think I have to use set_display_state_value() funtion.
Could you explain what exactly the set_display_state_value(int state_1, int state) function does? and possible values for state_1 and state?

Thanks
 

PRO100KBAC

Участник
Сообщения
98
Реакции
215
Баллы
38
Ваше "умное" устройство
Amazfit Bip
@MNVolkov

Hi

First of all, congrats for your great work and thanks for sharing!

I want to keep screen alive even not touching it. Checking randdemo I think I have to use set_display_state_value() funtion.
Could you explain what exactly the set_display_state_value(int state_1, int state) function does? and possible values for state_1 and state?

Thanks
You need to put this lines in your code(it doesn't allow to exit when inactive from the application)
set_display_state_value(8, 1);
set_display_state_value(2, 1);
set_display_state_value(4, 1);(it doesn't allow to turn off the backlight when inactive)
 

4ndru

Новичок
Сообщения
4
Реакции
0
Баллы
1
Ваше "умное" устройство
Amazfit Bip
If i want to compile a *.elf file I put in the gccvar.bat
Код:
ResPack -a flappy.res BipOS_0.5.1_ES.res Flappybird.elf
I get a message saying
Код:
Resource Packer (for Amazfit Bip) v.0.1 (C) Volkov Maxim 2019 <Maxim.N.Volkov@ya.ru>
Resource type: NERES
Resource version: 41
Resource count: 942
Adding files:
1       Flappybird.elf
start_offset=EDC
but nothing is created, any help?
 

LORD

Главный модератор
Команда форума
Сообщения
425
Реакции
372
Баллы
78
Ваше "умное" устройство
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).
To increase the firmware version and resources, follow this instruction: Инструкция - Bip | Завышение версии прошивки, ресурсов, шрифтов
 

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

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