Silicon Labs Page of 3 55
1 Version History ________ ________________________________________________________________ 5
2 Introduction ___________________________________________________________________________ 6
3 What is BGScript? ______________________________________________________________________ 7
3.1 BGScript Scripting Language ________________________________________________________ 7
3.2 BGScript vs. BGAPI ________________________________________________________________ 8
4 BGScript Syntax _______________________________________________________________________ 9
4.1 Comments _______________________________________________________________________ 9
4.2 Variables and Values _______________________________________________________________ 9
4.2.1 Values ____________________________________________________________________ 9
4.2.2 Variables __________________________________________________________________ 9
4.2.3 Global Variables ___________________________________________________________ 11
4.2.4 Constant Values ___________________________________________________________ 11
4.2.5 Buffers ___________________________________________________________________ 11
4.2.6 Strings ___________________________________________________________________ 12
4.2.7 Constant Strings ___________________________________________________________ 12
4.3 Expressions _____________________________________________________________________ 14
4.4 Commands ______________________________________________________________________ 15
4.4.1 event <event_name> (<event_parameters>) _____________________________________ 15
4.4.2 if <expression> then [else] end if _______________________________________________ 15
4.4.3 while <expression> end while _________________________________________________ 16
4.4.4 call <command name>(<command parameters>..)[(response parameters)] _____________ 16
4.4.5 let <variable> = <expression> _________________________________________________ 16
4.4.6 return ____________________________________________________________________ 17
4.4.7 sfloat(mantissa, exponent) ___________________________________________________ 17
4.4.8 float(mantissa, exponent) ____________________________________________________ 18
4.4.9 memcpy(destination, source, length) ___________________________________________ 18
4.4.10 memcmp(buffer1, buffer2, length) _____________________________________________ 18
4.4.11 memset(buffer, value, length) ________________________________________________ 19
4.5 Procedures ______________________________________________________________________ 20
4.6 Using multiple script files ___________________________________________________________ 21
4.6.1 import ___________________________________________________________________ 21
4.6.2 export ___________________________________________________________________ 21
5 BGScript Limitations ___________________________________________________________________ 23
5.1 32-bit resolution __________________________________________________________________ 23
5.2 Declaration required before use ______________________________________________________ 23
5.3 Reading internal temperature meter disabled IO interrupts _________________________________ 23
5.4 Writing data to an endpoint, which is not read ___________________________________________ 23
5.5 No interrupts on Port 2 _____________________________________________________________ 23
5.6 Performance _____________________________________________________________________ 23
5.7 RAM ___________________________________________________________________________ 23
5.8 Flash ___________________________________________________________________________ 24
5.9 Stack ___________________________________________________________________________ 24
5.9.1 Interface drivers ____________________________________________________________ 24
5.10 Debugging
_____________________________________________________________________ 24
6 Example BGscripts
____________________________________________________________________ 25
6.1 Basics
__________________________________________________________________________ 25
6.1.1 Catching system start-up _____________________________________________________ 25
6.1.2 Catching Bluetooth connection event
___________________________________________ 26
6.1.3 Catching Bluetooth disconnection event
_________________________________________ 27
6.2 Hardware interfaces
_______________________________________________________________ 28
6.2.1 ADC _____________________________________________________________________ 28
6.2.2 I2C ______________________________________________________________________ 30
6.2.3 GPIO ____________________________________________________________________ 31
6.2.4 SPI
______________________________________________________________________ 33
6.2.5
Generating PWM signals
____________________________________________________ 35
6.3 Timers
__________________________________________________________________________ 36
6.3.1 Continuous timer generated interrupt
____________________________________________ 36
6.3.2 Single timer generated interrupt
________________________________________________ 37