Thank you. Good afternoon. As Paul said, my name is Eric. Short version. McGeeck, I used
quite a few different systems over the years. However, I've only started doing embedded
software development less than a year ago. It started when Apple back in May published
the opening of the embedded Swift GitHub repository with the examples to go look at that.
So, if you want to talk embedded Swift, let's talk Swift. Swift was introduced in 2014.
First, as a successor to Objective C, for developing for the Apple platforms.
That very soon afterwards, it was made up in sales. It was available on Linux.
Nowadays, it's available on macOS, several folders of Linux, Windows.
It's used for scripting, for server-side development, for serverless function
implementation, or some of the talk this afternoon will be short. But in terms of embedded
systems, there was very little. There was just a few community project, but that's it.
So, why is that? Well, it's good embedded. Embedded systems are all over daily lives.
Yet it's quite difficult to find a definition. We might say that it's
dedicated hardware for specific functionality, yet it doesn't go well everything. So, in this case,
what we'll say is that it is also hardware is limited functionality. So, a Raspberry Pi,
or an Apple Watch, wouldn't qualify as embedded in this scope. So, let's further compare
and see the limitations and compare on our F52840, which is a mid-level microcontroll chip,
to an Apple Watch series zero. So, the original one from many 10 years ago.
If you look at the processor, we got a single core 30-to-bit versus a single core 64-bit,
no big deal. Clock speed, we're talking 64 megahertz versus 420 megahertz. So, we'll already see
an 8 times difference there. In terms of RAM, we're talking 266 kilo-bite versus 512 mega-bites.
So, that's 2,000 times difference. And in flash, we're talking 1 mega-bite versus 8 kilo-bite. So,
that's 8,000x. So, different beasts. So, we see that if we want to bring swift
to the limited systems, we need to reduce the runtime overhead, we need to reduce the
limited footprint and the total activity group code size. And so, embedded swift is Apple's
official answer to this problem. It's a subset of swift, not the dialect. So, it is swift,
but with some limitations. And basically, it adds a compilation mode that adds constraint
to achieve the way that you should go, is that I just mentioned. How does it do it? Well,
do you see basically everything that's dynamic at runtime? So, there is no dynamic reflection,
no existential types, the generic instantiation at runtime is not possible. Of course, no
objective to interrupt, but it is runtime and do dynamic code loading. Also, at runtime,
all I agree is quite minim, mostly concerned about memory, allocation and management. There is no need
to bundle the metadata either, because the runtime wouldn't use it. The swift style library
also has some limitations. So, no credible available in embedded space. And then the compiler
will perform aggressive debt code stripping. How does it look in practice? Well, we add
three flags to the combination first, the target, which brought are we compounding to,
then we enable the embedded feature, which is still experimental to this day, and we have
the WMO flag, which is for optimization. And as of 50, the manual puts it, so embedded swift
is a compilation mode that would, basically, as a sick compiler would do project, project,
produce object files that would later be linked with the rest of your code, so that would be
see assembly or the libraries that you're using. And that linking is done by the target to
be changed, so it's very little about embedded swift is concerned with the linking.
Enough talking, let's see that, let's get started. So, if you want to get started, you need to pick
a board, the embedded swift examples from Apple, Duke of the Civil Birds, with risk 5 or ARM architecture,
the help source and project on the panic played or the future zero, etc. Just pick one,
don't do as I did, and buy everything that's available, you just pick one of them.
For reasons that are not really relevant to this talk, I went with Nordics, so we connect this chip.
And then when you do that, I would recommend that the fourth thing you do is install the target
to change the target libraries without thinking about swift at this stage. So, just make sure that
you can compile and build and flush your board. In the case of the RF Connectors Decay,
this comes also with a handy video studio code extension. And so, use that and use some of their
examples and make sure that you can build and flush the board in this works. And then you can move
to the embedded swift examples. I would start from the repository that Apple published. You go
there and you find the project that is appropriate for your board. It is the help of the embedded
works of blinking and LED for the RF chip. And one of the fourth thing that you really will tell
you is to download the latest 90 tuition of swift. So, you go to the website and that's the same
side that I showed you, but there is a section below that says development snapshots and that's the
one you will want because the current mainstream doesn't yet flush the boards. And then you
follow the really file typing all the commands, making sure that you select the tool shown that
you just installed. And if everything goes well, you go to blinking LED. Hey! And so,
I don't know about you, but typing these kinds of commands in a terminal is not the ideal
development. So, one of the next step that I did was make sure that I set up a purple environment.
And there's a bit of jumping through hoops, but basically it's using the RF connected SDK
in the SDS code, the swift extension in the SDS code. And so, I can do code completion and I can
use a single click, build flash, and I can connect to the board and see the console logs of the board.
So, that makes for much easier experience. With that in place, we can start growing from the
embedics with the examples and creating a project from there. So, let's take a look at the embedics with
examples. It's time like a normal C file is the main function, etc. So, like swift files is the main
function, but then it got GPIO pink of your DTE LED zero, which is not really swift, which is
as it's coming from. Well, from the bridging header that's H, which is a stand-up C header,
header file, which is used by the swift C interrupt interrupt. So, and then we can see that it includes
the header files for the SDK. So, ZF here is a written-up and existing on which RF connect is based.
And we see the static variable declared in C, or LED zero, which basically represents the
beginning to which the LED is connected. So, that makes a bit more sense. But still, it doesn't
look very swift to me, that's just using swift as a blue curve to see. That's not what we want.
So, what we would like is encapsulate those sequels into a swift struct. So, that's what we do.
We just have an initializer. And as you can see, we are using some unsafe something,
unsafe portal, and there is a 10-F unsafe type in swift to do money and money management.
And when you do embedded system, you will need to get acquainted with those.
And then we have just a method to toggle the LED, and we can rewrite or main curve into
something that is much more swift. Once it is skipped, until now, is error management.
So, let's do that. We create a name to represent the L, and we make the initializer
throwing, and we get a compilation L. Fortunately, the compiler is quite explicit. It says that
we have a close, close, and close is the same as true, any L. Any is an extension,
an extension, an edge part, so we need to do something. 14 here, so we have 66 introduced the
type throw, so we just declare the type that we throw, and it fixes our issue. And you just keep
going like that, encapsulating what you need from the SDK. And until you get to something like this,
for instance, where we have a button that uses generic, generic specification that compiles down
us fine. We have a training trader to do the handler, and so we can we can go further like that.
And I did go a bit further, we said a project, there are all open source, so if you want to go
on GitHub, you can find the helpful for all of them, and you can explore what it is. So that's an
arch reactor. And contact each other there, please reach out, and you can also try to post
quite often on the board on the blog. Thank you very much.