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

MNVolkov

Разработчик
Команда форума
Сообщения
295
Реакции
2,157
Баллы
463
Ваше "умное" устройство
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

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



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



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.
 
Последнее редактирование:

Archon

Модератор
Команда форума
Сообщения
525
Реакции
622
Баллы
133
Ваше "умное" устройство
Amazfit Bip
@josehhh, you can get it here. One is just lightened RES, and another has some ELFs included.
 

HOANG TUNG

Новичок
Сообщения
1
Реакции
0
Баллы
11
Ваше "умное" устройство
Amazfit Bip
@MNVolkov and other developers thank you for your great SDK !! Your work is amaizing !! I've prepared usefull application from Garmin Vivioactive HR CHART. It's measuring hr rate contantly for 1 min interval and showing results on the chart. There is also current, min and max values. @MNVolkov did you think about extend your SDK ?I think access to sensor values (accelerometer, barometer) and bt api for connection with smartphone will be enought for most developers.

Regards
Can you give me the link to download it ( I am so sorry because I can't add this function to my bip by myself ) . Thank you
 

Archon

Модератор
Команда форума
Сообщения
525
Реакции
622
Баллы
133
Ваше "умное" устройство
Amazfit Bip
@HOANG TUNG, the link to download what exactly? I didn't understand.
 

LORD

Главный модератор
Команда форума
Сообщения
449
Реакции
397
Баллы
78
Ваше "умное" устройство
Amazfit Bip
@Archon, he needs a link to the mentioned HR CHART.
 

erekoze

Местный
Сообщения
103
Реакции
208
Баллы
58
Ваше "умное" устройство
Amazfit Bip
Downloaded the latest version of BipCounter v.1.2

Instruction:
  1. Tap - increase the counter value.
  2. Button - exit.
  3. To reset, you need to exit and enter the application
What's new:
  1. The number of tapes is now displayed in the center with a three-digit number, in large print.
  2. Code abbreviated.
Comment:
  1. I did not implement swipe, as you can accidentally swipe and lose data. Exit and reset with just a button.
  2. I am enclosing the source code. Maybe someone will be useful for development ..
  3. I don’t see the point of making a Russian version, and so everything is clear ..
 

Вложения

erekoze

Местный
Сообщения
103
Реакции
208
Баллы
58
Ваше "умное" устройство
Amazfit Bip
Downloaded the latest version of BipCounter v.1.3 (EN)

Instruction:
Tap - increase the counter value.
Button - exit and reset.
To reset, you need to exit and enter the application
Swipe up - increase the counter value.
Swipe down - decrease the counter value.
 

Вложения

  •  Мне нравится
Реакции: be3

microxs

Новичок
Сообщения
5
Реакции
7
Баллы
8
Ваше "умное" устройство
Amazfit Bip
@MNVolkov and other developers thank you for your great SDK !! Your work is amaizing !! I've prepared usefull application from Garmin Vivioactive HR CHART. It's measuring hr rate contantly for 1 min interval and showing results on the chart. There is also current, min and max values. @MNVolkov did you think about extend your SDK ?I think access to sensor values (accelerometer, barometer) and bt api for connection with smartphone will be enought for most developers.

Regards
Can you give us the source code of hr_chart?

Thanks
 

microxs

Новичок
Сообщения
5
Реакции
7
Баллы
8
Ваше "умное" устройство
Amazfit Bip
Can someone explain to me why this code has a compilation error with int refresh as global before main.

#include <libbip.h>
int refresh=1500;

int main()
{
char crnd[14];
_sprintf(crnd, "Refresh = %.1f secs", (float)refresh/1000);
text_out_center(crnd, 90, 80);
}


1. test.c...OK
Total: 1
Assembly...arm-none-eabi-ld: test.o: in function `main':
test.c:(.text.startup.main+0x20): undefined reference to `__aeabi_f2d'
ERROR


And this almost identical code has no error? With int refresh as local in main. But refresh is unusable.

#include <libbip.h>

int main()
{
int refresh=1500;
char crnd[14];
_sprintf(crnd, "Refresh = %.1f secs", (float)refresh/1000);
text_out_center(crnd, 90, 80);
}
 

x27

Новичок
Сообщения
25
Реакции
39
Баллы
8
Ваше "умное" устройство
Amazfit Bip
#include <libbip.h>
int refresh;

int main()
{
char crnd[14];
refresh = 1500;
_sprintf(crnd, "Refresh = %.1f secs", (float)refresh/1000);
text_out_center(crnd, 90, 80);
}

worked :)

#include <libbip.h>
int refresh=1500;

int main()
{
char crnd[14];
_sprintf(crnd, "Refresh = %.1f secs", refresh/1000);
text_out_center(crnd, 90, 80);
}

worked :)

i think it's compiler jokes related with fpu support
 

microxs

Новичок
Сообщения
5
Реакции
7
Баллы
8
Ваше "умное" устройство
Amazfit Bip
#include <libbip.h>
int refresh;

int main()
{
char crnd[14];
refresh = 1500;
_sprintf(crnd, "Refresh = %.1f secs", (float)refresh/1000);
text_out_center(crnd, 90, 80);
}

worked :)

#include <libbip.h>
int refresh=1500;

int main()
{
char crnd[14];
_sprintf(crnd, "Refresh = %.1f secs", refresh/1000);
text_out_center(crnd, 90, 80);
}

worked :)

i think it's compiler jokes related with fpu support

Ok. But you need to add (float) or it will show 0.0. So with (float) it still does not compile:

#include <libbip.h>
int refresh=1500;

int main()
{
char crnd[14];
_sprintf(crnd, "Refresh = %.1f secs", (float)refresh/1000);
text_out_center(crnd, 90, 80);
}
 

trace

Разработчик
Команда форума
Сообщения
475
Реакции
1,294
Баллы
233
Ваше "умное" устройство
Amazfit Bip
Please, use BB-Tags [CОDE] ... your code here ... [/CODE] with your code for better view
 

MNVolkov

Разработчик
Команда форума
Сообщения
295
Реакции
2,157
Баллы
463
Ваше "умное" устройство
Amazfit Bip
undefined reference to `__aeabi_f2d'
You can use upgraded build.bat
Код:
@echo off
@setlocal EnableDelayedExpansion enableextensions
@cls
@cd %~dp0
@SET PROGRAM_NAME=%~dp0
@for /D %%a in ("%PROGRAM_NAME:~0,-1%.txt") do @SET PROGRAM_NAME=%%~na

@SET EABI=arm-none-eabi
@SET AS=%EABI%-as
@SET LD=%EABI%-ld
@SET OBJCOPY=%EABI%-objcopy
@SET GCC=%EABI%-gcc
@SET NM=%EABI%-nm

@SET LIB_BIP_PATH="..\libbip"
@SET LIB_BIP="%LIB_BIP_PATH%\libbip.a"

@SET GCC_OPT=-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=auto -fsingle-precision-constant -fno-math-errno -ffast-math
@SET GCC_OPT=%GCC_OPT% -I "%LIB_BIP_PATH%" -c -Os -Wa,-R -Wall -fpie -pie -fpic -mlittle-endian  -ffunction-sections -fdata-sections

@for /f "tokens=2 delims=[=]"  %%i in ('"!GCC! !GCC_OPT! -print-search-dirs"') do    SET LIB_SRCH=%%~i

set LIB_SRCH=!LIB_SRCH:;= -L !
    
@SET LD_OPT=-L!LIB_BIP_PATH! -L!LIB_SRCH! -EL -N -Os --cref -pie --gc-sections   

if exist label.txt (
set /p LABEL=< label.txt
) else (
SET LABEL = %PROGRAM_NAME%
)

@call :echoColor 0F "====================================" 1
@call :echoColor 0F "Наименование проекта: "
@echo %PROGRAM_NAME%
@call :echoColor 0F "Компилятор: "
@echo %COMPILER%
@call :echoColor 0F "====================================" 1
@echo.   

@call :echoColor 0F "Начинаем сборку..." 1
@SET PARTNAME=%PROGRAM_NAME%
@call :echoColor 0B "Компиляция "
@call :echoColor 0E "%PARTNAME%" 1

@SET n=1
@for  %%f in (*.c) do (
@    SET FILES_TO_COMPILE=!FILES_TO_COMPILE! %%~nf.o
@call :EchoN "%n%.    %%~nf.c"
!GCC! !GCC_OPT! -o %%~nf.o %%~nf.c
@if errorlevel 1 goto :error
@call :echoColor 0A "...OK" 1
@SET /a n=n+1)
@SET /a n=n-1
@call :echoColor 0B "Итого: "
@call :echoColor 0E "%n%" 1

@call :echoColor 0B "Сборка:"
@call :echoColor 07 "    ...создание elf файла"    1
%LD% %LD_OPT% -Map %PARTNAME%.map -o %PROGRAM_NAME%.elf %FILES_TO_COMPILE% -lbip -lgcc -lm -lc
@if errorlevel 1 goto :error

if exist label.txt (
@call :echoColor 07 "    ...название"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.label=label.txt
)

@call :EchoN "%PROGRAM_NAME%" > name.txt
@call :echoColor 07 "    ...elf_name"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.name=name.txt
if exist name.txt del name.txt
@if errorlevel 1 goto :error

if exist asset.res (
@call :echoColor 07 "    ...ресурсы"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.resources=asset.res
)

if exist settings.bin (
@call :echoColor 07 "    ...настройки"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.settings=settings.bin
)



@call :echoColor 0A "...OK" 1
@call :echoColor 0B "Сборка окончена." 1

:done_

@call :echoColor 0A "Готово." 1
pause
@goto :EOF

:error
@call :echoColor 4e ОШИБКА! 1
@endlocal & @SET ERROR=ERROR
@pause
@goto :EOF

::===========================================================
:: A function prints text in first parameter without CRLF
:EchoN
    
@    <nul set /p strTemp=%~1
@    exit /b 0
::===========================================================
::    Вывод заданной строки заданным цветом
::    3 параметр если не пустой задает перевод строки
::  0 = Черный     8 = Серый
::  1 = Синий     9 = Светло-синий
::  2 = Зеленый A = Светло-зеленый
::  3 = Голубой B = Светло-голубой
::  4 = Красный C = Светло-красный
::  5 = Лиловый D = Светло-лиловый
::  6 = Желтый     E = Светло-желтый
::  7 = Белый     F = Ярко-белый
:echoColor [Color] [Text] [\n]
 @ if not defined BS for /F "tokens=1 delims=#" %%i in ('"prompt #$H#& echo on& for %%j in (.) do rem"') do set "BS=%%i"
 @ if not exist foo set /p .=.<nul>foo
 @ set "regex=%~2" !
 @ set "regex=%regex:"="%"
 @ findstr /a:%1 /prc:"\." "%regex%\..\foo" nul
 @ set /p .=%BS%%BS%%BS%%BS%%BS%%BS%%BS%%BS%%BS%<nul
 @ if "%3" neq "" echo.
 @exit /b 0
::===========================================================
====================================================
 

microxs

Новичок
Сообщения
5
Реакции
7
Баллы
8
Ваше "умное" устройство
Amazfit Bip
You can use upgraded build.bat
Код:
@echo off
@setlocal EnableDelayedExpansion enableextensions
@cls
@cd %~dp0
@SET PROGRAM_NAME=%~dp0
@for /D %%a in ("%PROGRAM_NAME:~0,-1%.txt") do @SET PROGRAM_NAME=%%~na

@SET EABI=arm-none-eabi
@SET AS=%EABI%-as
@SET LD=%EABI%-ld
@SET OBJCOPY=%EABI%-objcopy
@SET GCC=%EABI%-gcc
@SET NM=%EABI%-nm

@SET LIB_BIP_PATH="..\libbip"
@SET LIB_BIP="%LIB_BIP_PATH%\libbip.a"

@SET GCC_OPT=-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=auto -fsingle-precision-constant -fno-math-errno -ffast-math
@SET GCC_OPT=%GCC_OPT% -I "%LIB_BIP_PATH%" -c -Os -Wa,-R -Wall -fpie -pie -fpic -mlittle-endian  -ffunction-sections -fdata-sections

@for /f "tokens=2 delims=[=]"  %%i in ('"!GCC! !GCC_OPT! -print-search-dirs"') do    SET LIB_SRCH=%%~i

set LIB_SRCH=!LIB_SRCH:;= -L !
   
@SET LD_OPT=-L!LIB_BIP_PATH! -L!LIB_SRCH! -EL -N -Os --cref -pie --gc-sections  

if exist label.txt (
set /p LABEL=< label.txt
) else (
SET LABEL = %PROGRAM_NAME%
)

@call :echoColor 0F "====================================" 1
@call :echoColor 0F "Наименование проекта: "
@echo %PROGRAM_NAME%
@call :echoColor 0F "Компилятор: "
@echo %COMPILER%
@call :echoColor 0F "====================================" 1
@echo.  

@call :echoColor 0F "Начинаем сборку..." 1
@SET PARTNAME=%PROGRAM_NAME%
@call :echoColor 0B "Компиляция "
@call :echoColor 0E "%PARTNAME%" 1

@SET n=1
@for  %%f in (*.c) do (
@    SET FILES_TO_COMPILE=!FILES_TO_COMPILE! %%~nf.o
@call :EchoN "%n%.    %%~nf.c"
!GCC! !GCC_OPT! -o %%~nf.o %%~nf.c
@if errorlevel 1 goto :error
@call :echoColor 0A "...OK" 1
@SET /a n=n+1)
@SET /a n=n-1
@call :echoColor 0B "Итого: "
@call :echoColor 0E "%n%" 1

@call :echoColor 0B "Сборка:"
@call :echoColor 07 "    ...создание elf файла"    1
%LD% %LD_OPT% -Map %PARTNAME%.map -o %PROGRAM_NAME%.elf %FILES_TO_COMPILE% -lbip -lgcc -lm -lc
@if errorlevel 1 goto :error

if exist label.txt (
@call :echoColor 07 "    ...название"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.label=label.txt
)

@call :EchoN "%PROGRAM_NAME%" > name.txt
@call :echoColor 07 "    ...elf_name"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.name=name.txt
if exist name.txt del name.txt
@if errorlevel 1 goto :error

if exist asset.res (
@call :echoColor 07 "    ...ресурсы"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.resources=asset.res
)

if exist settings.bin (
@call :echoColor 07 "    ...настройки"    1
%OBJCOPY%  %PROGRAM_NAME%.elf --add-section .elf.settings=settings.bin
)



@call :echoColor 0A "...OK" 1
@call :echoColor 0B "Сборка окончена." 1

:done_

@call :echoColor 0A "Готово." 1
pause
@goto :EOF

:error
@call :echoColor 4e ОШИБКА! 1
@endlocal & @SET ERROR=ERROR
@pause
@goto :EOF

::===========================================================
:: A function prints text in first parameter without CRLF
:EchoN
   
@    <nul set /p strTemp=%~1
@    exit /b 0
::===========================================================
::    Вывод заданной строки заданным цветом
::    3 параметр если не пустой задает перевод строки
::  0 = Черный     8 = Серый
::  1 = Синий     9 = Светло-синий
::  2 = Зеленый A = Светло-зеленый
::  3 = Голубой B = Светло-голубой
::  4 = Красный C = Светло-красный
::  5 = Лиловый D = Светло-лиловый
::  6 = Желтый     E = Светло-желтый
::  7 = Белый     F = Ярко-белый
:echoColor [Color] [Text] [\n]
@ if not defined BS for /F "tokens=1 delims=#" %%i in ('"prompt #$H#& echo on& for %%j in (.) do rem"') do set "BS=%%i"
@ if not exist foo set /p .=.<nul>foo
@ set "regex=%~2" !
@ set "regex=%regex:"="%"
@ findstr /a:%1 /prc:"\." "%regex%\..\foo" nul
@ set /p .=%BS%%BS%%BS%%BS%%BS%%BS%%BS%%BS%%BS%<nul
@ if "%3" neq "" echo.
@exit /b 0
::===========================================================
====================================================
It works. I can compile now. Thanks!
 

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

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